Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.