Changeset 8190 in orxonox.OLD for trunk/src/lib/collision_reaction/cr_engine.h
- Timestamp:
- Jun 7, 2006, 3:00:01 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/collision_reaction/cr_engine.h
r8145 r8190 2 2 * @file cr_engine.h 3 3 * @brief The collision reaction engine, defining generic collision reactions to collision events 4 */ 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 */ 5 10 6 11 #ifndef _CR_ENGINE_ … … 8 13 9 14 #include "base_object.h" 10 #include <stdarg.h> 15 11 16 #include <vector> 12 17 … … 14 19 class CollisionHandle; 15 20 class Collision; 21 class CollisionEvent; 16 22 class WorldEntity; 17 23 … … 22 28 public: 23 29 typedef enum CRType { 24 CR_PHYSICS_MOMENTUM = 0, 25 CR_PHYSICS_GROUND, 26 CR_PHYSICS_GROUND_WALK, 30 CR_PHYSICS_MOMENTUM = 0, //!< physical reaction: conservervation of momentum 31 CR_PHYSICS_STEP_BACK, //!< physical reaction: just go to the last position without collisions 32 CR_PHYSICS_GROUND, //!< physical reaction: stand on the ground, no movement: simulating simple normal force away from the gravity force 33 CR_PHYSICS_GROUND_WALK, //!< physical reaction: walking on the ground (inkl. hills etc) 34 CR_PHYSICS_DAMAGE, //!< physical reaction: daling damage according to the object energy and their structural stability 27 35 28 CR_OBJECT_DAMAGE, 29 CR_OBJECT_PICKUP, 36 CR_OBJECT_DAMAGE, //!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.) 37 CR_OBJECT_PICKUP, //!< object rection: calling the objects pickup functions, let them handle the collision (once!) 30 38 31 CR_VERTEX_TRAFO, 39 CR_VERTEX_TRAFO, //!< vertex trafo: transforming the vertex according to the damage 32 40 33 CR_SPECIAL_CALLBACK, 41 CR_SPECIAL_CALLBACK, //!< special: call a callback function 34 42 35 43 CR_NUMBER … … 39 47 40 48 /** @returns a Pointer to the only object of this Class */ 41 inline static CREngine* getInstance(void) { if (!singletonRef) singletonRef = new CREngine(); return singletonRef; }; 49 inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine(); return singletonRef; }; 50 51 void reset(); 42 52 43 53 44 CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type , int nrOfTargets, ...);54 CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type); 45 55 46 bool unsubscribeReaction(WorldEntity* worldEntity);47 56 bool unsubscribeReaction(CollisionHandle* collisionHandle); 48 49 57 50 58 void handleCollisions(); 51 59 52 60 /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */ 53 inline Collision* getCollisionObject() { /* return the first element of the cache list*/ } 54 /** @param collision: returns the Collision object back to the cache list */ 55 inline void putCollisionObject(Collision* collision) { this->cachedCollisions.push_back(collision); } 61 inline Collision* popCollisionObject() { 62 if( !this->collisionsUnused.empty()) { 63 this->collisionsUsed.push_back(this->collisionsUnused.back()); this->collisionsUnused.pop_back(); return this->collisionsUsed.back(); } else return NULL; } 64 65 66 /** @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled */ 67 inline CollisionEvent* popCollisionEventObject() { 68 if( !this->collisionEventsUnused.empty()) { 69 this->collisionEventsUsed.push_back(this->collisionEventsUnused.back()); this->collisionEventsUnused.pop_back(); return this->collisionEventsUsed.back(); } else return NULL; } 70 71 void debug(); 56 72 57 73 58 74 private: 59 CREngine(void); 75 CREngine(); 76 void init(); 77 78 void flushCollisions(); 60 79 61 80 62 81 private: 63 82 std::vector<CollisionHandle*> collisionHandles; //!< list with the collision handles 64 std::vector<Collision*> cachedCollisions; //!< a list of unused, cached collision events 83 84 std::vector<Collision*> collisionsUsed; //!< a list of used, cached collisions 85 std::vector<Collision*> collisionsUnused; //!< a list of unused, cached collisions 86 87 std::vector<CollisionEvent*> collisionEventsUsed; //!< a list of used, cached collision events 88 std::vector<CollisionEvent*> collisionEventsUnused; //!< a list of unused, cached collision events 65 89 66 90 static CREngine* singletonRef; //!< the reference to the CREngine object (singleton)
Note: See TracChangeset
for help on using the changeset viewer.