Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8190 in orxonox.OLD for trunk/src/lib/collision_reaction/cr_engine.h


Ignore:
Timestamp:
Jun 7, 2006, 3:00:01 PM (19 years ago)
Author:
patrick
Message:

trunk: merged the cr branche to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/collision_reaction/cr_engine.h

    r8145 r8190  
    22 * @file cr_engine.h
    33 * @brief The collision reaction engine, defining generic collision reactions to collision events
    4 */
     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 */
    510
    611#ifndef _CR_ENGINE_
     
    813
    914#include "base_object.h"
    10 #include <stdarg.h>
     15
    1116#include <vector>
    1217
     
    1419class CollisionHandle;
    1520class Collision;
     21class CollisionEvent;
    1622class WorldEntity;
    1723
     
    2228  public:
    2329  typedef enum CRType {
    24     CR_PHYSICS_MOMENTUM   = 0,
    25     CR_PHYSICS_GROUND,
    26     CR_PHYSICS_GROUND_WALK,
     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
     32    CR_PHYSICS_GROUND,            //!< physical reaction: stand on the ground, no movement: simulating simple normal force away from the gravity force
     33    CR_PHYSICS_GROUND_WALK,       //!< physical reaction: walking on the ground (inkl. hills etc)
     34    CR_PHYSICS_DAMAGE,            //!< physical reaction: daling damage according to the object energy and their structural stability
    2735
    28     CR_OBJECT_DAMAGE,
    29     CR_OBJECT_PICKUP,
     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!)
    3038
    31     CR_VERTEX_TRAFO,
     39    CR_VERTEX_TRAFO,              //!< vertex trafo: transforming the vertex according to the damage
    3240
    33     CR_SPECIAL_CALLBACK,
     41    CR_SPECIAL_CALLBACK,          //!< special: call a callback function
    3442
    3543    CR_NUMBER
     
    3947
    4048  /** @returns a Pointer to the only object of this Class */
    41   inline static CREngine* getInstance(void) { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
     49  inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
     50
     51  void reset();
    4252
    4353
    44   CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type, int nrOfTargets, ...);
     54  CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type);
    4555
    46   bool unsubscribeReaction(WorldEntity* worldEntity);
    4756  bool unsubscribeReaction(CollisionHandle* collisionHandle);
    48 
    4957
    5058  void handleCollisions();
    5159
    5260  /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */
    53   inline Collision* getCollisionObject() { /* return the first element of the cache list*/ }
    54   /** @param collision: returns the Collision object back to the cache list */
    55   inline void putCollisionObject(Collision* collision) { this->cachedCollisions.push_back(collision); }
     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; }
     64
     65
     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();
    5672
    5773
    5874private:
    59   CREngine(void);
     75  CREngine();
     76  void init();
     77
     78  void flushCollisions();
    6079
    6180
    6281private:
    6382  std::vector<CollisionHandle*>       collisionHandles;         //!< list with the collision handles
    64   std::vector<Collision*>             cachedCollisions;         //!< a list of unused, cached collision events
     83
     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
    6589
    6690  static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
Note: See TracChangeset for help on using the changeset viewer.