/*! * @file cr_engine.h * @brief The collision reaction engine, defining generic collision reactions to collision events */ #ifndef _CR_ENGINE_ #define _CR_ENGINE_ #include "base_object.h" #include // FORWARD DECLARATION class CollisionHandle; class Collision; class WorldEntity; //! A default singleton class. class CREngine : public BaseObject { public: typedef enum CRType { CR_PHYSICS_MOMENTUM = 0, CR_PHYSICS_GROUND, CR_PHYSICS_GROUND_WALK, CR_OBJECT_DAMAGE, CR_OBJECT_PICKUP, CR_VERTEX_TRAFO, CR_SPECIAL_CALLBACK, CR_NUMBER }; virtual ~CREngine(void); /** @returns a Pointer to the only object of this Class */ inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine(); return singletonRef; }; void init(); void reset(); CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type); bool unsubscribeReaction(WorldEntity* worldEntity); bool unsubscribeReaction(CollisionHandle* collisionHandle); void handleCollisions(); /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */ inline Collision* popCollisionObject() { if(!this->cachedCollisions.empty()) { this->cachedCollisions.back(); this->cachedCollisions.pop_back();} else return NULL; } /** @param collision: returns the Collision object back to the cache list */ inline void pushCollisionObject(Collision* collision) { this->cachedCollisions.push_back(collision); } void debug(); private: CREngine(); private: std::vector collisionHandles; //!< list with the collision handles std::vector cachedCollisions; //!< a list of unused, cached collision events static CREngine* singletonRef; //!< the reference to the CREngine object (singleton) }; #endif /* _CR_ENGINE_ */