[7819] | 1 | /*! |
---|
| 2 | * @file cr_engine.h |
---|
| 3 | * @brief The collision reaction engine, defining generic collision reactions to collision events |
---|
[8190] | 4 | * |
---|
| 5 | * some parts of this module are tuned for efficiency. They are probably not self-explenatory anymore :D |
---|
| 6 | * - Collision/ CollisionEvent objects recycling: This class contains a class of precached objects of these types |
---|
| 7 | * they are used for fast registration of collision events: These objects can be get by the interface functions and |
---|
| 8 | * are returned after one cycle automaticly by reseting the cached lists to its initial state. So do not wonder :D |
---|
| 9 | */ |
---|
[7819] | 10 | |
---|
| 11 | #ifndef _CR_ENGINE_ |
---|
| 12 | #define _CR_ENGINE_ |
---|
| 13 | |
---|
| 14 | #include "base_object.h" |
---|
[8190] | 15 | |
---|
[7865] | 16 | #include <vector> |
---|
[7819] | 17 | |
---|
[7865] | 18 | class WorldEntity; |
---|
[7819] | 19 | |
---|
[10013] | 20 | |
---|
| 21 | namespace CoRe |
---|
[7839] | 22 | { |
---|
[10013] | 23 | class Collision; |
---|
| 24 | class CollisionEvent; |
---|
| 25 | class CollisionReaction; |
---|
[7865] | 26 | |
---|
[10013] | 27 | |
---|
| 28 | //! A default singleton class. |
---|
| 29 | class CREngine : public BaseObject |
---|
| 30 | { |
---|
| 31 | ObjectListDeclaration(CREngine); |
---|
| 32 | |
---|
| 33 | typedef std::vector<CollisionEvent*> CollisionEventVector; |
---|
| 34 | typedef std::vector<Collision*> CollisionVector; |
---|
| 35 | typedef std::vector<Collision*>::iterator CollisionIterator; |
---|
| 36 | typedef std::vector<CollisionEvent*>::iterator CollisionEventIterator; |
---|
| 37 | |
---|
| 38 | |
---|
[7927] | 39 | public: |
---|
[10013] | 40 | typedef enum ReactionType { |
---|
| 41 | CR_PHYSICS_MOMENTUM = 0, //!< physical reaction: conservervation of momentum |
---|
| 42 | CR_PHYSICS_STEP_BACK, //!< physical reaction: just go to the last position without collisions |
---|
| 43 | CR_PHYSICS_GROUND_WALK, //!< physical reaction: stand on the ground, no movement: simple normal force away from the gravity force |
---|
| 44 | CR_PHYSICS_FULL_WALK, //!< physical reaction: walking on the ground (inkl. hills etc) |
---|
| 45 | CR_PHYSICS_DAMAGE, //!< physical reaction: daling damage according to the object energy and their structural stability |
---|
[7839] | 46 | |
---|
[10013] | 47 | CR_OBJECT_DAMAGE, //!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.) |
---|
| 48 | CR_OBJECT_PICKUP, //!< object rection: calling the objects pickup functions, let them handle the collision (once!) |
---|
[7839] | 49 | |
---|
[10013] | 50 | CR_VERTEX_TRAFO, //!< vertex trafo: transforming the vertex according to the damage |
---|
[7839] | 51 | |
---|
[10013] | 52 | CR_SPECIAL_CALLBACK, //!< special: call a callback function |
---|
[7839] | 53 | |
---|
[10013] | 54 | CR_NUMBER |
---|
| 55 | }; |
---|
[7839] | 56 | |
---|
[10013] | 57 | typedef enum CollisionType { |
---|
| 58 | CR_COLLISION_TYPE_AXIS_X = 0, //!< collision on x axis |
---|
| 59 | CR_COLLISION_TYPE_AXIS_X_NEG, //!< collision on negative x axis |
---|
| 60 | CR_COLLISION_TYPE_AXIS_Y, //!< collision on y axis |
---|
| 61 | CR_COLLISION_TYPE_AXIS_Y_NEG, //!< collision on negative y axis |
---|
| 62 | CR_COLLISION_TYPE_AXIS_Z, //!< collision on z axis |
---|
| 63 | CR_COLLISION_TYPE_AXIS_Z_NEG, //!< collision on negative z axis |
---|
[10618] | 64 | CR_COLLISION_TYPE_WAY, //!< collision on the way from last to current position |
---|
[10013] | 65 | CR_COLLISION_TYPE_OBB, //!< object aligned bounding box collide |
---|
[7865] | 66 | |
---|
[10013] | 67 | CR_COLLISION_TYPE_NUMBER |
---|
| 68 | }; |
---|
[7819] | 69 | |
---|
[7865] | 70 | |
---|
[10013] | 71 | virtual ~CREngine(void); |
---|
[7819] | 72 | |
---|
[10013] | 73 | /** @returns a Pointer to the only object of this Class */ |
---|
| 74 | inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine(); return singletonRef; }; |
---|
[8190] | 75 | |
---|
[10013] | 76 | Collision* popCollisionObject(); |
---|
| 77 | CollisionEvent* popCollisionEventObject(); |
---|
[7839] | 78 | |
---|
[10013] | 79 | void handleCollisions(); |
---|
[7841] | 80 | |
---|
[10013] | 81 | void debug(); |
---|
[7839] | 82 | |
---|
| 83 | |
---|
[10013] | 84 | private: |
---|
| 85 | CREngine(); |
---|
| 86 | void init(); |
---|
[8190] | 87 | |
---|
[10013] | 88 | void reset(); |
---|
[8190] | 89 | |
---|
| 90 | |
---|
[10013] | 91 | private: |
---|
| 92 | static CREngine* singletonRef; //!< the reference to the CREngine object (singleton) |
---|
[7839] | 93 | |
---|
[10013] | 94 | CollisionVector collisionsUsed; //!< a list of used, cached collisions |
---|
| 95 | CollisionVector collisionsUnused; //!< a list of unused, cached collisions |
---|
[7927] | 96 | |
---|
[10013] | 97 | CollisionEventVector collisionEventsUsed; //!< a list of used, cached collision events |
---|
| 98 | CollisionEventVector collisionEventsUnused; //!< a list of unused, cached collision events |
---|
[8190] | 99 | |
---|
[10013] | 100 | CollisionReaction* _reactionList[CREngine::CR_NUMBER]; //!< the collision reaction list containing all reactions types |
---|
[7865] | 101 | |
---|
[8190] | 102 | |
---|
[10013] | 103 | }; |
---|
[8190] | 104 | |
---|
[10013] | 105 | } |
---|
[7819] | 106 | #endif /* _CR_ENGINE_ */ |
---|