Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/collision_reaction/cr_engine.h @ 9744

Last change on this file since 9744 was 9235, checked in by bensch, 18 years ago

merged the presentation back

File size: 3.8 KB
RevLine 
[7819]1/*!
2 * @file cr_engine.h
3 * @brief The collision reaction engine, defining generic collision reactions to collision events
[8190]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"
[8190]15
[7865]16#include <vector>
[7819]17
18// FORWARD DECLARATION
[7839]19class CollisionHandle;
20class Collision;
[8190]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 {
[8190]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
[9235]32    CR_PHYSICS_GROUND_WALK,       //!< physical reaction: stand on the ground, no movement: simulating simple normal force away from the gravity force
33    CR_PHYSICS_FULL_WALK,         //!< physical reaction: walking on the ground (inkl. hills etc)
[8190]34    CR_PHYSICS_DAMAGE,            //!< physical reaction: daling damage according to the object energy and their structural stability
[7839]35
[8190]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!)
[7839]38
[8190]39    CR_VERTEX_TRAFO,              //!< vertex trafo: transforming the vertex according to the damage
[7839]40
[8190]41    CR_SPECIAL_CALLBACK,          //!< special: call a callback function
[7839]42
43    CR_NUMBER
44  };
45
[7927]46  virtual ~CREngine(void);
[7865]47
[7819]48  /** @returns a Pointer to the only object of this Class */
[8190]49  inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
[7819]50
[8190]51  void reset();
[7865]52
[7819]53
[8190]54  CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type);
55
[7839]56  bool unsubscribeReaction(CollisionHandle* collisionHandle);
57
[7841]58  void handleCollisions();
59
[7839]60  /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */
[8190]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; }
[7839]64
65
[8190]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
[7839]74private:
[8190]75  CREngine();
76  void init();
[7839]77
[8190]78  void flushCollisions();
[7927]79
[8190]80
[7865]81private:
[7839]82  std::vector<CollisionHandle*>       collisionHandles;         //!< list with the collision handles
[7865]83
[8190]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
[7843]90  static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
[7819]91};
92
93#endif /* _CR_ENGINE_ */
Note: See TracBrowser for help on using the repository browser.