Rev | Line | |
---|
[7819] | 1 | /*! |
---|
| 2 | * @file cr_engine.h |
---|
| 3 | * @brief The collision reaction engine, defining generic collision reactions to collision events |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | #ifndef _CR_ENGINE_ |
---|
| 7 | #define _CR_ENGINE_ |
---|
| 8 | |
---|
| 9 | #include "base_object.h" |
---|
[7937] | 10 | |
---|
[7865] | 11 | #include <vector> |
---|
[7819] | 12 | |
---|
| 13 | // FORWARD DECLARATION |
---|
[7839] | 14 | class CollisionHandle; |
---|
| 15 | class Collision; |
---|
[7865] | 16 | class WorldEntity; |
---|
[7819] | 17 | |
---|
| 18 | //! A default singleton class. |
---|
[7839] | 19 | class CREngine : public BaseObject |
---|
| 20 | { |
---|
[7865] | 21 | |
---|
[7927] | 22 | public: |
---|
[7839] | 23 | typedef enum CRType { |
---|
[7927] | 24 | CR_PHYSICS_MOMENTUM = 0, |
---|
| 25 | CR_PHYSICS_GROUND, |
---|
| 26 | CR_PHYSICS_GROUND_WALK, |
---|
[7839] | 27 | |
---|
| 28 | CR_OBJECT_DAMAGE, |
---|
| 29 | CR_OBJECT_PICKUP, |
---|
| 30 | |
---|
| 31 | CR_VERTEX_TRAFO, |
---|
| 32 | |
---|
[7927] | 33 | CR_SPECIAL_CALLBACK, |
---|
[7839] | 34 | |
---|
| 35 | CR_NUMBER |
---|
| 36 | }; |
---|
| 37 | |
---|
[7927] | 38 | virtual ~CREngine(void); |
---|
[7865] | 39 | |
---|
[7819] | 40 | /** @returns a Pointer to the only object of this Class */ |
---|
[7937] | 41 | inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine(); return singletonRef; }; |
---|
[7819] | 42 | |
---|
[7940] | 43 | void init(); |
---|
| 44 | void reset(); |
---|
| 45 | |
---|
| 46 | |
---|
[7932] | 47 | CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type); |
---|
[7865] | 48 | |
---|
[7839] | 49 | bool unsubscribeReaction(WorldEntity* worldEntity); |
---|
| 50 | bool unsubscribeReaction(CollisionHandle* collisionHandle); |
---|
| 51 | |
---|
[7841] | 52 | void handleCollisions(); |
---|
| 53 | |
---|
[7839] | 54 | /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */ |
---|
[7944] | 55 | inline Collision* popCollisionObject() { if(!this->cachedCollisions.empty()) { this->cachedCollisions.back(); this->cachedCollisions.pop_back();} else return NULL; } |
---|
[7839] | 56 | /** @param collision: returns the Collision object back to the cache list */ |
---|
[7944] | 57 | inline void pushCollisionObject(Collision* collision) { this->cachedCollisions.push_back(collision); } |
---|
[7839] | 58 | |
---|
| 59 | |
---|
[7933] | 60 | void debug(); |
---|
| 61 | |
---|
[7839] | 62 | private: |
---|
[7937] | 63 | CREngine(); |
---|
[7839] | 64 | |
---|
[7927] | 65 | |
---|
[7865] | 66 | private: |
---|
[7839] | 67 | std::vector<CollisionHandle*> collisionHandles; //!< list with the collision handles |
---|
| 68 | std::vector<Collision*> cachedCollisions; //!< a list of unused, cached collision events |
---|
[7865] | 69 | |
---|
[7843] | 70 | static CREngine* singletonRef; //!< the reference to the CREngine object (singleton) |
---|
[7819] | 71 | }; |
---|
| 72 | |
---|
| 73 | #endif /* _CR_ENGINE_ */ |
---|
Note: See
TracBrowser
for help on using the repository browser.