Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9990 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
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{
[9869]27  ObjectListDeclaration(CREngine);
[7865]28
[7927]29  public:
[7839]30  typedef enum CRType {
[8190]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
[9235]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)
[8190]35    CR_PHYSICS_DAMAGE,            //!< physical reaction: daling damage according to the object energy and their structural stability
[7839]36
[8190]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!)
[7839]39
[8190]40    CR_VERTEX_TRAFO,              //!< vertex trafo: transforming the vertex according to the damage
[7839]41
[8190]42    CR_SPECIAL_CALLBACK,          //!< special: call a callback function
[7839]43
44    CR_NUMBER
45  };
46
[7927]47  virtual ~CREngine(void);
[7865]48
[7819]49  /** @returns a Pointer to the only object of this Class */
[8190]50  inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
[7819]51
[8190]52  void reset();
[7865]53
[7819]54
[8190]55  CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type);
56
[7839]57  bool unsubscribeReaction(CollisionHandle* collisionHandle);
58
[7841]59  void handleCollisions();
60
[7839]61  /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */
[8190]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; }
[7839]65
66
[8190]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
[7839]75private:
[8190]76  CREngine();
77  void init();
[7839]78
[8190]79  void flushCollisions();
[7927]80
[8190]81
[7865]82private:
[7839]83  std::vector<CollisionHandle*>       collisionHandles;         //!< list with the collision handles
[7865]84
[8190]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
[7843]91  static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
[7819]92};
93
94#endif /* _CR_ENGINE_ */
Note: See TracBrowser for help on using the repository browser.