Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/lib/collision_reaction/cr_engine.h @ 10101

Last change on this file since 10101 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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  ObjectListDeclaration(CREngine);
28
29  public:
30  typedef enum CRType {
31    CR_PHYSICS_MOMENTUM   = 0,    //!< physical reaction: conservervation of momentum
32    CR_PHYSICS_STEP_BACK,         //!< physical reaction: just go to the last position without collisions
33    CR_PHYSICS_GROUND_WALK,       //!< physical reaction: stand on the ground, no movement: simulating simple normal force away from the gravity force
34    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 stability
36
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!)
39
40    CR_VERTEX_TRAFO,              //!< vertex trafo: transforming the vertex according to the damage
41
42    CR_SPECIAL_CALLBACK,          //!< special: call a callback function
43
44    CR_NUMBER
45  };
46
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
75private:
76  CREngine();
77  void init();
78
79  void flushCollisions();
80
81
82private:
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
94#endif /* _CR_ENGINE_ */
Note: See TracBrowser for help on using the repository browser.