Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7945 in orxonox.OLD for branches/cr/src


Ignore:
Timestamp:
May 29, 2006, 12:48:21 AM (18 years ago)
Author:
patrick
Message:

cr: collision objects handling

Location:
branches/cr/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/cr/src/lib/collision_reaction/collision_handle.cc

    r7933 r7945  
    7272}
    7373
     74/**
     75 * flushes the collision list
     76 */
     77void CollisionHandle::flushCollisions()
     78{
     79  std::vector<Collision*>::iterator it;
     80  for( it = this->collisionList.begin(); it != this->collisionList.end(); it++)
     81    CREngine::getInstance()->pushCollisionObject(*it);
     82  this->collisionList.clear();
     83}
    7484
     85
     86/**
     87 * handles the collisions and react according to algorithm
     88 */
     89void CollisionHandle::handleCollisions()
     90{
     91
     92  // collision reaction calculations
     93
     94  // now set state to dispatched
     95  this->bDispatched = true;
     96  this->flushCollisions();
     97}
  • branches/cr/src/lib/collision_reaction/collision_handle.h

    r7934 r7945  
    2020
    2121//! A class for defining collision reactions and storing events
    22 class CollisionHandle : public BaseObject {
     22class CollisionHandle : public BaseObject
     23{
    2324
    24  public:
    25   CollisionHandle(WorldEntity* owner, CREngine::CRType type);
    26   virtual ~CollisionHandle();
     25  public:
     26    CollisionHandle(WorldEntity* owner, CREngine::CRType type);
     27    virtual ~CollisionHandle();
    2728
    2829
    29   void addTarget(long classID);
     30    void addTarget(long classID);
    3031
    31   void registerCollision(Collision* collision);
     32    void registerCollision(Collision* collision);
    3233
    33   void handleCollisions();
    34   void flushCollsions();
     34    void handleCollisions();
    3535
    3636
    37  private:
    38    WorldEntity*                  owner;                   //!< the worldenity this reaction will be applied on
    39    CREngine::CRType              type;                    //!< the reaction type
     37  private:
     38    void flushCollisions();
    4039
    41    bool                          bDispatched;             //!< true if this handle has already been dispatched
    42    bool                          bStopOnFirstCollision;   //!< true if the cd of this object should be terminated after one match
    4340
    44    std::vector<Collision*>       collisionList;           //!< a list full of collisions
    45    std::vector<long>             targetList;              //!< a list of target classes for filtering
     41  private:
     42    WorldEntity*                  owner;                   //!< the worldenity this reaction will be applied on
     43    CREngine::CRType              type;                    //!< the reaction type
     44
     45    bool                          bDispatched;             //!< true if this handle has already been dispatched
     46    bool                          bStopOnFirstCollision;   //!< true if the cd of this object should be terminated after one match
     47
     48    std::vector<Collision*>       collisionList;           //!< a list full of collisions
     49    std::vector<long>             targetList;              //!< a list of target classes for filtering
    4650
    4751};
  • branches/cr/src/lib/collision_reaction/cr_engine.cc

    r7944 r7945  
    1919
    2020#include "collision.h"
     21#include "collision_handle.h"
    2122#include "cr_defs.h"
    2223
     
    5152}
    5253
    53 
     54/**
     55 * inits the CREngine to a working state
     56 */
    5457void CREngine::init()
    5558{
     
    6265
    6366void CREngine::reset()
    64 {}
     67{
     68  // first clear all CollisionHandles
     69  std::vector<CollisionHandle*>::iterator it;
     70  for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)
     71    delete *it;
     72  this->collisionHandles.clear();
     73}
    6574
    6675
     
    7281CollisionHandle* CREngine::subscribeReaction(WorldEntity* owner, CRType type)
    7382{
     83  CollisionHandle* ch = new CollisionHandle(owner, type);
     84  this->collisionHandles.push_back(ch);
     85}
    7486
    75 }
    7687
    7788bool CREngine::unsubscribeReaction(WorldEntity* worldEntity)
  • branches/cr/src/lib/collision_reaction/cr_engine.h

    r7944 r7945  
    4141  inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
    4242
    43   void init();
    4443  void reset();
    4544
     
    6059  void debug();
    6160
     61
    6262private:
    6363  CREngine();
     64  void init();
    6465
    6566
  • branches/cr/src/world_entities/world_entity.cc

    r7944 r7945  
    3333
    3434#include "collision_handle.h"
     35#include "collision.h"
    3536
    3637#include <stdarg.h>
     
    6869  this->objectListNumber = OM_INIT;
    6970  this->objectListIterator = NULL;
     71
     72  // reset all collision handles to NULL == unsubscribed state
     73  for(int i = 0; i < CREngine::CR_NUMBER; ++i)
     74    this->collisionHandles[i] = NULL;
    7075
    7176  this->toList(OM_NULL);
     
    242247void WorldEntity::subscribeReaction(CREngine::CRType type, int nrOfTargets, long target...)
    243248{
     249  if( this->collisionHandles[type] != NULL)  {
     250    PRINTF(2)("Registering for a CollisionReaction already subscribed to! Skipping\n");
     251    return;
     252  }
    244253
    245254  this->collisionHandles[type] = CREngine::getInstance()->subscribeReaction(this, type);
     
    257266 *  @param collisionEvent the event
    258267 */
    259 void WorldEntity::registerCollision(WorldEntity* entityA, WorldEntity* entityB, BouningVolume* bvA, BoundingVolume* bvB)
     268bool WorldEntity::registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
    260269{
    261270  // create a collision event
  • branches/cr/src/world_entities/world_entity.h

    r7944 r7945  
    7171  /* --- Collision Reaction Block --- */
    7272  void subscribeReaction(CREngine::CRType type, int nrOfTargets, long target, ...);
    73   void registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
     73  bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
    7474
    7575
Note: See TracChangeset for help on using the changeset viewer.