Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/lib/collision_reaction/cr_engine.h @ 8465

Last change on this file since 8465 was 8190, checked in by patrick, 19 years ago

trunk: merged the cr branche to trunk

File size: 3.8 KB
Line 
1/*!
2 * @file cr_engine.h
3 * @brief The collision reaction engine, defining generic collision reactions to collision events
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 */
10
11#ifndef _CR_ENGINE_
12#define _CR_ENGINE_
13
14#include "base_object.h"
15
16#include <vector>
17
18// FORWARD DECLARATION
19class CollisionHandle;
20class Collision;
21class CollisionEvent;
22class WorldEntity;
23
24//! A default singleton class.
25class CREngine : public BaseObject
26{
27
28  public:
29  typedef enum CRType {
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
35
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!)
38
39    CR_VERTEX_TRAFO,              //!< vertex trafo: transforming the vertex according to the damage
40
41    CR_SPECIAL_CALLBACK,          //!< special: call a callback function
42
43    CR_NUMBER
44  };
45
46  virtual ~CREngine(void);
47
48  /** @returns a Pointer to the only object of this Class */
49  inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
50
51  void reset();
52
53
54  CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type);
55
56  bool unsubscribeReaction(CollisionHandle* collisionHandle);
57
58  void handleCollisions();
59
60  /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */
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();
72
73
74private:
75  CREngine();
76  void init();
77
78  void flushCollisions();
79
80
81private:
82  std::vector<CollisionHandle*>       collisionHandles;         //!< list with the collision handles
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
89
90  static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
91};
92
93#endif /* _CR_ENGINE_ */
Note: See TracBrowser for help on using the repository browser.