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
RevLine 
[7819]1/*!
2 * @file cr_engine.h
3 * @brief The collision reaction engine, defining generic collision reactions to collision events
[7964]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 */
[7819]10
11#ifndef _CR_ENGINE_
12#define _CR_ENGINE_
13
14#include "base_object.h"
[7937]15
[7865]16#include <vector>
[7819]17
18// FORWARD DECLARATION
[7839]19class CollisionHandle;
20class Collision;
[7964]21class CollisionEvent;
[7865]22class WorldEntity;
[7819]23
24//! A default singleton class.
[7839]25class CREngine : public BaseObject
26{
[7865]27
[7927]28  public:
[7839]29  typedef enum CRType {
[7927]30    CR_PHYSICS_MOMENTUM   = 0,
31    CR_PHYSICS_GROUND,
32    CR_PHYSICS_GROUND_WALK,
[7839]33
34    CR_OBJECT_DAMAGE,
35    CR_OBJECT_PICKUP,
36
37    CR_VERTEX_TRAFO,
38
[7927]39    CR_SPECIAL_CALLBACK,
[7839]40
41    CR_NUMBER
42  };
43
[7927]44  virtual ~CREngine(void);
[7865]45
[7819]46  /** @returns a Pointer to the only object of this Class */
[7937]47  inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
[7819]48
[7940]49  void reset();
50
51
[7932]52  CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type);
[7865]53
[7839]54  bool unsubscribeReaction(CollisionHandle* collisionHandle);
55
[7841]56  void handleCollisions();
57
[7839]58  /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */
[7964]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; }
[7839]62
[7964]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; }
[7839]67
[7933]68  void debug();
69
[7945]70
[7839]71private:
[7937]72  CREngine();
[7945]73  void init();
[7839]74
[7966]75  void flushCollisions();
[7927]76
[7966]77
[7865]78private:
[7839]79  std::vector<CollisionHandle*>       collisionHandles;         //!< list with the collision handles
[7865]80
[7960]81  std::vector<Collision*>             collisionsUsed;           //!< a list of used, cached collisions
82  std::vector<Collision*>             collisionsUnused;         //!< a list of unused, cached collisions
83
[7964]84  std::vector<CollisionEvent*>        collisionEventsUsed;      //!< a list of used, cached collision events
85  std::vector<CollisionEvent*>        collisionEventsUnused;    //!< a list of unused, cached collision events
[7960]86
[7843]87  static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
[7819]88};
89
90#endif /* _CR_ENGINE_ */
Note: See TracBrowser for help on using the repository browser.