Changeset 9889 in orxonox.OLD for branches/coll_rect/src/lib/collision_reaction/cr_engine.h
- Timestamp:
- Oct 13, 2006, 3:57:44 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/coll_rect/src/lib/collision_reaction/cr_engine.h
r9869 r9889 16 16 #include <vector> 17 17 18 // FORWARD DECLARATION19 class CollisionHandle;20 class Collision;21 class CollisionEvent;22 18 class WorldEntity; 23 19 24 //! A default singleton class. 25 class CREngine : public BaseObject 20 21 namespace CoRe 26 22 { 27 ObjectListDeclaration(CREngine); 23 class CollisionHandle; 24 class Collision; 25 class CollisionEvent; 26 27 //! A default singleton class. 28 class CREngine : public BaseObject 29 { 30 ObjectListDeclaration(CREngine); 28 31 29 32 public: 30 typedef enum CRType {31 CR_PHYSICS_MOMENTUM = 0, //!< physical reaction: conservervation of momentum32 CR_PHYSICS_STEP_BACK, //!< physical reaction: just go to the last position without collisions33 CR_PHYSICS_GROUND_WALK, //!< physical reaction: stand on the ground, no movement: simulating simple normal force away from the gravity force34 CR_PHYSICS_FULL_WALK, //!< physical reaction: walking on the ground (inkl. hills etc)35 CR_PHYSICS_DAMAGE, //!< physical reaction: daling damage according to the object energy and their structural stability33 typedef enum CRType { 34 CR_PHYSICS_MOMENTUM = 0, //!< physical reaction: conservervation of momentum 35 CR_PHYSICS_STEP_BACK, //!< physical reaction: just go to the last position without collisions 36 CR_PHYSICS_GROUND_WALK, //!< physical reaction: stand on the ground, no movement: simulating simple normal force away from the gravity force 37 CR_PHYSICS_FULL_WALK, //!< physical reaction: walking on the ground (inkl. hills etc) 38 CR_PHYSICS_DAMAGE, //!< physical reaction: daling damage according to the object energy and their structural stability 36 39 37 CR_OBJECT_DAMAGE, //!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.)38 CR_OBJECT_PICKUP, //!< object rection: calling the objects pickup functions, let them handle the collision (once!)40 CR_OBJECT_DAMAGE, //!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.) 41 CR_OBJECT_PICKUP, //!< object rection: calling the objects pickup functions, let them handle the collision (once!) 39 42 40 CR_VERTEX_TRAFO, //!< vertex trafo: transforming the vertex according to the damage43 CR_VERTEX_TRAFO, //!< vertex trafo: transforming the vertex according to the damage 41 44 42 CR_SPECIAL_CALLBACK, //!< special: call a callback function45 CR_SPECIAL_CALLBACK, //!< special: call a callback function 43 46 44 CR_NUMBER 47 CR_NUMBER 48 }; 49 50 virtual ~CREngine(void); 51 52 /** @returns a Pointer to the only object of this Class */ 53 inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine(); return singletonRef; }; 54 55 void reset(); 56 57 58 CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type); 59 60 bool unsubscribeReaction(CollisionHandle* collisionHandle); 61 62 void handleCollisions(); 63 64 /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */ 65 inline Collision* popCollisionObject() 66 { 67 if( !this->collisionsUnused.empty()) 68 { 69 this->collisionsUsed.push_back(this->collisionsUnused.back()); this->collisionsUnused.pop_back(); return this->collisionsUsed.back(); 70 } 71 else return NULL; 72 } 73 74 75 /** @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled */ 76 inline CollisionEvent* popCollisionEventObject() 77 { 78 if( !this->collisionEventsUnused.empty()) 79 { 80 this->collisionEventsUsed.push_back(this->collisionEventsUnused.back()); this->collisionEventsUnused.pop_back(); return this->collisionEventsUsed.back(); 81 } 82 else return NULL; 83 } 84 85 void debug(); 86 87 88 private: 89 CREngine(); 90 void init(); 91 92 void flushCollisions(); 93 94 95 private: 96 std::vector<CollisionHandle*> collisionHandles; //!< list with the collision handles 97 98 std::vector<Collision*> collisionsUsed; //!< a list of used, cached collisions 99 std::vector<Collision*> collisionsUnused; //!< a list of unused, cached collisions 100 101 std::vector<CollisionEvent*> collisionEventsUsed; //!< a list of used, cached collision events 102 std::vector<CollisionEvent*> collisionEventsUnused; //!< a list of unused, cached collision events 103 104 static CREngine* singletonRef; //!< the reference to the CREngine object (singleton) 45 105 }; 46 106 47 virtual ~CREngine(void); 48 49 /** @returns a Pointer to the only object of this Class */ 50 inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine(); return singletonRef; }; 51 52 void reset(); 53 54 55 CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type); 56 57 bool unsubscribeReaction(CollisionHandle* collisionHandle); 58 59 void handleCollisions(); 60 61 /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */ 62 inline Collision* popCollisionObject() { 63 if( !this->collisionsUnused.empty()) { 64 this->collisionsUsed.push_back(this->collisionsUnused.back()); this->collisionsUnused.pop_back(); return this->collisionsUsed.back(); } else return NULL; } 65 66 67 /** @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled */ 68 inline CollisionEvent* popCollisionEventObject() { 69 if( !this->collisionEventsUnused.empty()) { 70 this->collisionEventsUsed.push_back(this->collisionEventsUnused.back()); this->collisionEventsUnused.pop_back(); return this->collisionEventsUsed.back(); } else return NULL; } 71 72 void debug(); 73 74 75 private: 76 CREngine(); 77 void init(); 78 79 void flushCollisions(); 80 81 82 private: 83 std::vector<CollisionHandle*> collisionHandles; //!< list with the collision handles 84 85 std::vector<Collision*> collisionsUsed; //!< a list of used, cached collisions 86 std::vector<Collision*> collisionsUnused; //!< a list of unused, cached collisions 87 88 std::vector<CollisionEvent*> collisionEventsUsed; //!< a list of used, cached collision events 89 std::vector<CollisionEvent*> collisionEventsUnused; //!< a list of unused, cached collision events 90 91 static CREngine* singletonRef; //!< the reference to the CREngine object (singleton) 92 }; 93 107 } 94 108 #endif /* _CR_ENGINE_ */
Note: See TracChangeset
for help on using the changeset viewer.