Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cr/src/lib/collision_reaction/cr_engine.h @ 7966

Last change on this file since 7966 was 7966, checked in by patrick, 18 years ago

cr: collision registration processes

File size: 2.9 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,
31    CR_PHYSICS_GROUND,
32    CR_PHYSICS_GROUND_WALK,
33
34    CR_OBJECT_DAMAGE,
35    CR_OBJECT_PICKUP,
36
37    CR_VERTEX_TRAFO,
38
39    CR_SPECIAL_CALLBACK,
40
41    CR_NUMBER
42  };
43
44  virtual ~CREngine(void);
45
46  /** @returns a Pointer to the only object of this Class */
47  inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
48
49  void reset();
50
51
52  CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type);
53
54  bool unsubscribeReaction(CollisionHandle* collisionHandle);
55
56  void handleCollisions();
57
58  /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */
59  inline Collision* popCollisionObject() {
60    if( !this->collisionsUnused.empty()) {
61      this->collisionsUsed.push_back(this->collisionsUnused.back()); this->collisionsUnused.pop_back(); return this->collisionsUsed.back(); } else return NULL; }
62
63  /** @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled */
64  inline CollisionEvent* popCollisionEventObject() {
65    if( !this->collisionEventsUnused.empty()) {
66      this->collisionEventsUsed.push_back(this->collisionEventsUnused.back()); this->collisionEventsUnused.pop_back(); return this->collisionEventsUsed.back(); } else return NULL; }
67
68  void debug();
69
70
71private:
72  CREngine();
73  void init();
74
75  void flushCollisions();
76
77
78private:
79  std::vector<CollisionHandle*>       collisionHandles;         //!< list with the collision handles
80
81  std::vector<Collision*>             collisionsUsed;           //!< a list of used, cached collisions
82  std::vector<Collision*>             collisionsUnused;         //!< a list of unused, cached collisions
83
84  std::vector<CollisionEvent*>        collisionEventsUsed;      //!< a list of used, cached collision events
85  std::vector<CollisionEvent*>        collisionEventsUnused;    //!< a list of unused, cached collision events
86
87  static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
88};
89
90#endif /* _CR_ENGINE_ */
Note: See TracBrowser for help on using the repository browser.