Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9985 in orxonox.OLD


Ignore:
Timestamp:
Dec 2, 2006, 4:28:11 PM (17 years ago)
Author:
patrick
Message:

giving the crengine the ability to check for collisions itself, collision tube only used as container

Location:
branches/coll_rect/src/lib/collision_reaction
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/coll_rect/src/lib/collision_reaction/collision.cc

    r9983 r9985  
    2727  Collision::Collision ()
    2828  {
    29     this->flushCollisionEvents();
     29    this->reset();
    3030  }
    3131
     
    3939
    4040  /**
    41    * flushes the CollisionEvent list
     41   * resets all variable states to initial values
    4242   */
    43   void Collision::flushCollisionEvents()
     43  void Collision::reset()
    4444  {
    4545    this->_entityA = NULL;
  • branches/coll_rect/src/lib/collision_reaction/collision.h

    r9983 r9985  
    4949    inline void registerCollisionEvent(CollisionEvent* event) { this->_collisionEvents.push_back(event); this->bDispatched = false;}
    5050
    51     void flushCollisionEvents();
     51    void reset();
    5252
    5353
  • branches/coll_rect/src/lib/collision_reaction/collision_tube.cc

    r9983 r9985  
    4444  {
    4545    this->registerObject(this, CollisionTube::_objectList);
    46 
    47 
    48     // push the collision reaction object on the list in the right order
    49     // WARNING: do not mess with the order, it should be the same as in
    50 
    51     // physical reactions
    52     this->_reactionList[CREngine::CR_PHYSICS_MOMENTUM]      = NULL;
    53     this->_reactionList[CREngine::CR_PHYSICS_STEP_BACK]     = NULL;
    54     this->_reactionList[CREngine::CR_PHYSICS_GROUND_WALK]   = new CRPhysicsGroundWalk();
    55     this->_reactionList[CREngine::CR_PHYSICS_FULL_WALK]     = new CRPhysicsFullWalk();
    56     this->_reactionList[CREngine::CR_PHYSICS_DAMAGE]        = NULL;
    57     // object based reactions
    58     this->_reactionList[CREngine::CR_OBJECT_DAMAGE]         = new CRObjectDamage();
    59     this->_reactionList[CREngine::CR_OBJECT_PICKUP]         = NULL;
    60     // misc reactions
    61     this->_reactionList[CREngine::CR_VERTEX_TRAFO]          = NULL;
    62     this->_reactionList[CREngine::CR_SPECIAL_CALLBACK]      = NULL;
    6346  }
    6447
     
    131114
    132115
    133   /**
    134    * handles all collisions in registered in this tube
    135    */
    136   void CollisionTube::handleCollisions()
    137   {
    138     // for all collisions:
    139     CollisionIterator ci = this->_collisionList.begin();
    140     for(; ci < this->_collisionList.end(); ++ci)
    141     {
    142       for( int i = CREngine::CR_PHYSICS_MOMENTUM; i < CREngine::CR_NUBER; i++)
    143       {
    144         // check if entity A or B is subscibed for this event
    145         if( (*ci)->getEntityA()->bReactibe((*it)->getEnityB(), i) || (*ci)->getEntityB()->bReactibe((*it)->getEnityA(), i))
    146           (*ci)->reactToCollision(*ci);
    147 
    148         (*ci)->flushCollisionEvents();
    149       }
    150     }
    151   }
    152 
    153 
    154 
    155 
    156 
    157 
    158 
    159116}// namespace end
    160117
  • branches/coll_rect/src/lib/collision_reaction/collision_tube.h

    r9983 r9985  
    6868                                const Vector& normal, const Vector& position, bool bInWall = false);
    6969
    70     void handleCollisions();
     70    /** @returns an iterator pointing to the beginning of the list */
     71    CollisionIterator& begin() const { return this->_collisionList.begin(); }
     72    /** @returns an iterator pointing to the end of the list */
     73    CollisionIterator& end()   const { return this->_collisionList.end(); }
    7174
    7275
    7376  private:
    7477    std::vector<Collision*>         _collisionList;                      //!< the list of collisions since the last processing
    75     CollisionReaction*              _reactionList[CREngine::CR_NUMBER];  //!< the collision reaction list containing all reactions types
    7678
    7779
  • branches/coll_rect/src/lib/collision_reaction/cr_engine.cc

    r9984 r9985  
    6363
    6464    this->reset();
     65    this->flushCollisions();
    6566
    66     std::vector<Collision*>::iterator it1 = this->collisionsUnused.begin();
     67    CollisionList it1 = this->collisionsUnused.begin();
    6768    for(; it1 < this->collisionsUnused.end(); it1++)
    6869      delete *it1;
    69     std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUnused.begin();
     70    CollisionEventList it2 = this->collisionEventsUnused.begin();
    7071    for(; it2 < this->collisionEventsUnused.end(); it2++)
    7172      delete *it2;
     
    7576  }
    7677
     78
    7779  /**
    7880   * inits the CREngine to a working state
     
    8082  void CREngine::init()
    8183  {
    82     // create a list of Collision events (precaching)
     84    // precaching:
     85    // create a list of Collisions and CollisionEvents for fast object recycling purposes
    8386    for( int i = 0; i < CR_MAX_COLLISIONS; i++)
    8487      this->collisionsUnused.push_back(new Collision());
    8588    for( int i = 0; i < CR_MAX_COLLISION_EVENTS; i++)
    8689      this->collisionEventsUnused.push_back(new CollisionEvent());
     90
     91
     92    // push the collision reaction object on the list in the right order
     93
     94    // physical reactions
     95    this->_reactionList[CREngine::CR_PHYSICS_MOMENTUM]      = NULL;
     96    this->_reactionList[CREngine::CR_PHYSICS_STEP_BACK]     = NULL;
     97    this->_reactionList[CREngine::CR_PHYSICS_GROUND_WALK]   = new CRPhysicsGroundWalk();
     98    this->_reactionList[CREngine::CR_PHYSICS_FULL_WALK]     = new CRPhysicsFullWalk();
     99    this->_reactionList[CREngine::CR_PHYSICS_DAMAGE]        = NULL;
     100    // object based reactions
     101    this->_reactionList[CREngine::CR_OBJECT_DAMAGE]         = new CRObjectDamage();
     102    this->_reactionList[CREngine::CR_OBJECT_PICKUP]         = NULL;
     103    // misc reactions
     104    this->_reactionList[CREngine::CR_VERTEX_TRAFO]          = NULL;
     105    this->_reactionList[CREngine::CR_SPECIAL_CALLBACK]      = NULL;
    87106  }
    88107
     
    102121  }
    103122
     123
    104124  /**
    105125   * @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled
     
    118138
    119139  /**
    120    * flushes the CollisionHandles and restores the CREngine to the initial state
    121    */
    122   void CREngine::reset()
    123   {
    124 //     // first clear all CollisionHandles
    125 //     std::vector<CollisionHandle*>::iterator it = this->collisionHandles.begin();
    126 //     for(; it < this->collisionHandles.end(); it++)
    127 //     {
    128 //       (*it)->reset();
    129 //       delete *it;
    130 //     }
    131 //
    132 //     this->collisionHandles.clear();
    133   }
    134 
    135 
    136 
    137 
    138 
    139   /**
    140    * processes the collisions by calling the EventHandlers
     140   * handles all collisions in registered in this tube
    141141   */
    142142  void CREngine::handleCollisions()
    143143  {
    144 //     std::vector<CollisionHandle*>::iterator it;
    145 //     for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)
    146 //     {
    147 //       if( !(*it)->isDispatched() || (*it)->isContinuousPoll())  //does it have any collisions to report at all
    148 //       {
    149 //         (*it)->handleCollisions();
    150 //       }
    151 //     }
    152 //     this->flushCollisions();
     144    // for all collisions:
     145    CollisionIterator ci = CollisionTube::getInstance()->begin();
     146    for(; ci < CollisionTube::getInstance()->end(); ++ci)
     147    {
     148      for( int i = CREngine::CR_PHYSICS_MOMENTUM; i < CREngine::CR_NUBER; i++)
     149      {
     150        // check if entity A or B is subscibed for this event
     151        if( (*ci)->getEntityA()->bReactibe((*it)->getEnityB(), i) || (*ci)->getEntityB()->bReactibe((*it)->getEnityA(), i))
     152          (*ci)->reactToCollision(*ci);
     153
     154        (*ci)->reset();
     155      }
     156    }
    153157  }
    154158
     
    159163  void CREngine::flushCollisions()
    160164  {
    161     std::vector<Collision*>::iterator it1 = this->collisionsUsed.begin();
     165    CollisionIterator it1 = this->collisionsUsed.begin();
    162166    for(; it1 < this->collisionsUsed.end(); it1++)
    163167      this->collisionsUnused.push_back(*it1);
    164168
    165     std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUsed.begin();
     169    CollisionEventIterator it2 = this->collisionEventsUsed.begin();
    166170    for(; it2 < this->collisionEventsUsed.end(); it2++)
    167171      this->collisionEventsUnused.push_back(*it2);
  • branches/coll_rect/src/lib/collision_reaction/cr_engine.h

    r9984 r9985  
    2929    ObjectListDeclaration(CREngine);
    3030
     31    typedef std::vector<Collision*>::iterator        CollisionIterator;
     32    typedef std::vector<CollisionEvent*>::iterator   CollisionEventIterator;
    3133
    3234
     
    7072    Collision* popCollisionObject();
    7173    CollisionEvent* popCollisionEventObject();
    72     void reset();
    7374
    7475    void handleCollisions();
     
    8586
    8687  private:
    87     //std::vector<CollisionHandle*>       collisionHandles;         //!< list with the collision handles
     88    static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
    8889
    8990    std::vector<Collision*>             collisionsUsed;           //!< a list of used, cached collisions
     
    9394    std::vector<CollisionEvent*>        collisionEventsUnused;    //!< a list of unused, cached collision events
    9495
    95     static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
     96    CollisionReaction*                  _reactionList[CREngine::CR_NUMBER];  //!< the collision reaction list containing all reactions types
     97
     98
    9699  };
    97100
Note: See TracChangeset for help on using the changeset viewer.