Changeset 9985 in orxonox.OLD for branches/coll_rect/src
- Timestamp:
- Dec 2, 2006, 4:28:11 PM (18 years ago)
- 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 27 27 Collision::Collision () 28 28 { 29 this-> flushCollisionEvents();29 this->reset(); 30 30 } 31 31 … … 39 39 40 40 /** 41 * flushes the CollisionEvent list41 * resets all variable states to initial values 42 42 */ 43 void Collision:: flushCollisionEvents()43 void Collision::reset() 44 44 { 45 45 this->_entityA = NULL; -
branches/coll_rect/src/lib/collision_reaction/collision.h
r9983 r9985 49 49 inline void registerCollisionEvent(CollisionEvent* event) { this->_collisionEvents.push_back(event); this->bDispatched = false;} 50 50 51 void flushCollisionEvents();51 void reset(); 52 52 53 53 -
branches/coll_rect/src/lib/collision_reaction/collision_tube.cc
r9983 r9985 44 44 { 45 45 this->registerObject(this, CollisionTube::_objectList); 46 47 48 // push the collision reaction object on the list in the right order49 // WARNING: do not mess with the order, it should be the same as in50 51 // physical reactions52 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 reactions58 this->_reactionList[CREngine::CR_OBJECT_DAMAGE] = new CRObjectDamage();59 this->_reactionList[CREngine::CR_OBJECT_PICKUP] = NULL;60 // misc reactions61 this->_reactionList[CREngine::CR_VERTEX_TRAFO] = NULL;62 this->_reactionList[CREngine::CR_SPECIAL_CALLBACK] = NULL;63 46 } 64 47 … … 131 114 132 115 133 /**134 * handles all collisions in registered in this tube135 */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 event145 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 159 116 }// namespace end 160 117 -
branches/coll_rect/src/lib/collision_reaction/collision_tube.h
r9983 r9985 68 68 const Vector& normal, const Vector& position, bool bInWall = false); 69 69 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(); } 71 74 72 75 73 76 private: 74 77 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 types76 78 77 79 -
branches/coll_rect/src/lib/collision_reaction/cr_engine.cc
r9984 r9985 63 63 64 64 this->reset(); 65 this->flushCollisions(); 65 66 66 std::vector<Collision*>::iteratorit1 = this->collisionsUnused.begin();67 CollisionList it1 = this->collisionsUnused.begin(); 67 68 for(; it1 < this->collisionsUnused.end(); it1++) 68 69 delete *it1; 69 std::vector<CollisionEvent*>::iteratorit2 = this->collisionEventsUnused.begin();70 CollisionEventList it2 = this->collisionEventsUnused.begin(); 70 71 for(; it2 < this->collisionEventsUnused.end(); it2++) 71 72 delete *it2; … … 75 76 } 76 77 78 77 79 /** 78 80 * inits the CREngine to a working state … … 80 82 void CREngine::init() 81 83 { 82 // create a list of Collision events (precaching) 84 // precaching: 85 // create a list of Collisions and CollisionEvents for fast object recycling purposes 83 86 for( int i = 0; i < CR_MAX_COLLISIONS; i++) 84 87 this->collisionsUnused.push_back(new Collision()); 85 88 for( int i = 0; i < CR_MAX_COLLISION_EVENTS; i++) 86 89 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; 87 106 } 88 107 … … 102 121 } 103 122 123 104 124 /** 105 125 * @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled … … 118 138 119 139 /** 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 141 141 */ 142 142 void CREngine::handleCollisions() 143 143 { 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 } 153 157 } 154 158 … … 159 163 void CREngine::flushCollisions() 160 164 { 161 std::vector<Collision*>::iterator it1 = this->collisionsUsed.begin();165 CollisionIterator it1 = this->collisionsUsed.begin(); 162 166 for(; it1 < this->collisionsUsed.end(); it1++) 163 167 this->collisionsUnused.push_back(*it1); 164 168 165 std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUsed.begin();169 CollisionEventIterator it2 = this->collisionEventsUsed.begin(); 166 170 for(; it2 < this->collisionEventsUsed.end(); it2++) 167 171 this->collisionEventsUnused.push_back(*it2); -
branches/coll_rect/src/lib/collision_reaction/cr_engine.h
r9984 r9985 29 29 ObjectListDeclaration(CREngine); 30 30 31 typedef std::vector<Collision*>::iterator CollisionIterator; 32 typedef std::vector<CollisionEvent*>::iterator CollisionEventIterator; 31 33 32 34 … … 70 72 Collision* popCollisionObject(); 71 73 CollisionEvent* popCollisionEventObject(); 72 void reset();73 74 74 75 void handleCollisions(); … … 85 86 86 87 private: 87 //std::vector<CollisionHandle*> collisionHandles; //!< list with the collision handles88 static CREngine* singletonRef; //!< the reference to the CREngine object (singleton) 88 89 89 90 std::vector<Collision*> collisionsUsed; //!< a list of used, cached collisions … … 93 94 std::vector<CollisionEvent*> collisionEventsUnused; //!< a list of unused, cached collision events 94 95 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 96 99 }; 97 100
Note: See TracChangeset
for help on using the changeset viewer.