- Timestamp:
- Dec 4, 2006, 2:24:40 PM (18 years ago)
- Location:
- branches/coll_rect/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/coll_rect/src/lib/collision_reaction/collision.h
r9988 r10006 71 71 /** @return Collision WorldEntity B */ 72 72 inline WorldEntity* getEntityB() const { return this->_entityB; } 73 inline bool match(const WorldEntity& entityA, WorldEntity& entityB) const {73 inline bool same(const WorldEntity& entityA, WorldEntity& entityB) const { 74 74 return ((this->_entityA == &entityA && this->_entityB == &entityB) || (this->_entityA == &entityB && this->_entityB == &entityA)); } 75 75 -
branches/coll_rect/src/lib/collision_reaction/collision_event.h
r9892 r10006 49 49 50 50 /** @return CollisionEvent WorldEntity A */ 51 inline WorldEntity* getEntityA() const 52 { 53 return this->entityA; 54 } 51 inline const WorldEntity* getEntityA() const { return this->entityA; } 55 52 /** @return CollisionEvent WorldEntity B */ 56 inline WorldEntity* getEntityB() const 57 { 58 return this->entityB; 59 } 53 inline const WorldEntity* getEntityB() const { return this->entityB; } 60 54 /** @return Bounding Volume from EntityA */ 61 inline BoundingVolume* getBVA() const 62 { 63 return this->bvA; 64 } 55 inline const BoundingVolume* getBVA() const { return this->bvA; } 65 56 /** @return Bounding Volume from EntityB */ 66 inline BoundingVolume* getBVB() const 67 { 68 return this->bvB; 69 } 57 inline const BoundingVolume* getBVB() const { return this->bvB; } 70 58 71 59 /** @return ground plane if collided with bsp model */ 72 inline Vector getGroundNormal() 73 { 74 return this->groundNormal; 75 } 60 inline const Vector& getGroundNormal() const { return this->groundNormal; } 76 61 77 62 /** @return position of the position, only accurate if this is a collision with the ground!!! */ 78 inline Vector getCollisionPosition() 79 { 80 return this->position; 81 } 63 inline const Vector& getCollisionPosition() const { return this->position; } 82 64 83 65 /** @return the type of the collision */ 84 inline int getType() 85 { 86 return this->collisionType; 87 } 66 inline int getType() const { return this->collisionType; } 88 67 89 68 /** @return true if the entity is in the wall */ 90 inline bool isInWall() 91 { 92 return this->bInWall; 93 } 69 inline bool isInWall() const { return this->bInWall; } 94 70 95 71 -
branches/coll_rect/src/lib/collision_reaction/collision_filter.cc
r9990 r10006 142 142 bool CollisionFilter::operator()(const WorldEntity& entity) const 143 143 { 144 // if there are no installed criterions just ommit and 145 if( this->isReactive()) 144 PRINTF(0)("operator()(const WorldEntity& entity)\n"); 145 146 // if there are no installed criterions just ommit and return 147 if( !this->isReactive()) 146 148 return false; 147 149 … … 149 151 for( int i = 0; i < CREngine::CR_NUMBER; i++ ) 150 152 { 151 std::vector<ClassID>::const_iterator it = this->_filters[i].begin(); 152 for(; it != this->_filters[i].end(); i++ ) 153 TargetIteratorConst it = this->_filters[i].begin(); 154 for(; it != this->_filters[i].end(); it++ ) 155 { 156 PRINTF(0)("[%i] check %s is a %s?\n", i, entity.getClassName().c_str(), (*it).name().c_str()); 153 157 if( unlikely(entity.isA(*it) ) ) 154 158 return true; 159 } 155 160 } 156 161 … … 168 173 bool CollisionFilter::operator()(const WorldEntity& entity, const CREngine::ReactionType type) const 169 174 { 175 assert(&entity != NULL); 176 177 PRINTF(0)("operator()(const WorldEntity& entity, const CREngine::ReactionType type)\n"); 170 178 // if there are no installed criterions just omit and return 171 179 if( !this->isReactive()) 172 180 return false; 173 181 182 174 183 // goes through all registered filter criterions and looks for matches 175 184 TargetIteratorConst it = this->_filters[type].begin(); 176 185 for(; it != this->_filters[type].end(); it++ ) 177 if( unlikely(entity.isA(*it))) 186 { 187 PRINTF(0)("size: %i - %s is a %s?\n", this->_filters[type].size(), entity.getClassName().c_str(), (*it).name().c_str()); 188 if( entity.isA(*it)) 178 189 return true; 190 } 179 191 180 192 return false; -
branches/coll_rect/src/lib/collision_reaction/collision_tube.cc
r9995 r10006 27 27 #include "cr_physics_full_walk.h" 28 28 29 #include "debug.h" 29 30 30 31 … … 52 53 CollisionTube::~CollisionTube () 53 54 { 55 this->reset(); 56 } 57 58 59 60 /** 61 * resets the collision tube after each collision detection cycle 62 */ 63 void CollisionTube::reset() 64 { 54 65 this->_collisionList.clear(); 66 } 67 68 69 /** 70 * gets the collision object useable for collision events registarations 71 * @param entityA collision partner 1 72 * @param entityB collision partner 2 73 * @return the collision object to be used 74 */ 75 Collision* CollisionTube::registerCollision(WorldEntity* entityA, WorldEntity* entityB) 76 { 77 assert( entityA != NULL && entityB != NULL); 78 79 Collision* collision = NULL; 80 if( !this->_collisionList.empty()) 81 collision = this->_collisionList.back(); 82 83 // check if there is already a collision defined between these objects or this is the first collision at all 84 if( collision == NULL || !collision->same(*entityA, *entityB)) 85 { 86 collision = CREngine::getInstance()->popCollisionObject(); 87 collision->collide( entityA, entityB); 88 this->_collisionList.push_back(collision); 89 } 90 91 return collision; 55 92 } 56 93 … … 67 104 void CollisionTube::registerCollisionEvent(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) 68 105 { 69 Collision* collision = NULL; 70 if( !this->_collisionList.empty()) 71 collision = this->_collisionList.back(); 72 73 // check if there is already a collision defined between these objects or this is the first collision at all 74 if( collision == NULL || !collision->match(*entityA, *entityB)) 75 { 76 collision = CREngine::getInstance()->popCollisionObject(); 77 collision->collide( entityA, entityB); 78 } 106 // first get a useable collision object 107 Collision* collision = this->registerCollision(entityA, entityB); 79 108 80 109 // now register the new collision event … … 95 124 */ 96 125 void CollisionTube::registerCollisionEvent(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity, 97 126 const Vector& normal, const Vector& position, bool bInWall) 98 127 { 99 // get last collision 100 Collision* collision = NULL; 101 if( !this->_collisionList.empty()) 102 collision = this->_collisionList.back(); 103 104 // check if there is already a collision defined between these objects 105 if( collision == NULL || !collision->match(*entity, *groundEntity)) 106 { 107 // get a new collision object 108 collision = CREngine::getInstance()->popCollisionObject(); 109 collision->collide( entity, groundEntity); 110 } 128 // first get a useable collision object 129 Collision* collision = this->registerCollision(entity, groundEntity); 111 130 112 131 // now register the new collision event -
branches/coll_rect/src/lib/collision_reaction/collision_tube.h
r9994 r10006 70 70 void registerCollisionEvent(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity, 71 71 const Vector& normal, const Vector& position, bool bInWall = false); 72 Collision* registerCollision(WorldEntity* entityA, WorldEntity* entityB); 73 74 void reset(); 72 75 73 76 /** @returns an iterator pointing to the beginning of the list */ -
branches/coll_rect/src/lib/collision_reaction/cr_engine.cc
r10000 r10006 66 66 PRINTF(0)("CollisionReaction Error: CollisionEvent cache size missmatch: %i of %i\n", this->collisionEventsUnused.size(), CR_MAX_COLLISION_EVENTS); 67 67 68 this-> flushCollisions();68 this->reset(); 69 69 70 70 CollisionIterator it1 = this->collisionsUnused.begin(); … … 121 121 return this->collisionsUsed.back(); 122 122 } 123 else return NULL; 123 else 124 { 125 PRINTF(0)("There is no Collision Object left in the precache table, fatal error will cause segfault, change CR_MAX_COLLISIONS\n"); 126 assert(false); 127 return NULL; 128 } 124 129 } 125 130 … … 136 141 return this->collisionEventsUsed.back(); 137 142 } 138 else return NULL; 143 else 144 { 145 PRINTF(0)("There is no Collision Object left in the precache table, fatal error will cause segfault, change CR_MAX_COLLISION_EVENTS\n"); 146 assert(false); 147 return NULL; 148 } 139 149 } 140 150 … … 147 157 // for all collisions: 148 158 CollisionIterator ci = CollisionTube::getInstance()->begin(); 149 for(; ci < CollisionTube::getInstance()->end(); ++ci)159 for(; ci < CollisionTube::getInstance()->end(); ci++) 150 160 { 151 161 for( int i = CREngine::CR_PHYSICS_MOMENTUM; i < CREngine::CR_NUMBER; i++) … … 153 163 if( _reactionList[i] == NULL) 154 164 continue; 165 166 assert((*ci)->getEntityA() != NULL && (*ci)->getEntityB() != NULL); 167 168 PRINTF(0)("CR CHECK: collision between: %s, %s\n", (*ci)->getEntityA()->getClassName().c_str(), (*ci)->getEntityB()->getClassName().c_str()); 155 169 156 170 // check if entity A or B is subscibed for this event … … 161 175 PRINTF(0)("react to %i\n", i); 162 176 } 163 164 (*ci)->reset();165 177 } 166 } 167 168 this->flushCollisions(); 178 (*ci)->reset(); 179 } 180 181 this->reset(); 169 182 } 170 183 … … 173 186 * flushes all the collision lists and puts them to their initial state 174 187 */ 175 void CREngine:: flushCollisions()188 void CREngine::reset() 176 189 { 177 190 CollisionIterator it1 = this->collisionsUsed.begin(); … … 185 198 this->collisionsUsed.clear(); 186 199 this->collisionEventsUsed.clear(); 200 201 CollisionTube::getInstance()->reset(); 187 202 } 188 203 -
branches/coll_rect/src/lib/collision_reaction/cr_engine.h
r9988 r10006 73 73 inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine(); return singletonRef; }; 74 74 75 76 75 Collision* popCollisionObject(); 77 76 CollisionEvent* popCollisionEventObject(); … … 86 85 void init(); 87 86 88 void flushCollisions();87 void reset(); 89 88 90 89 -
branches/coll_rect/src/lib/graphics/importer/bsp_manager.cc
r9896 r10006 1217 1217 { 1218 1218 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X , 1219 this->parent, entity,1219 entity, this->parent, 1220 1220 Vector(testPlane->x, testPlane->y, testPlane->z), 1221 1221 collPos, … … 1256 1256 { 1257 1257 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X_NEG, 1258 this->parent, entity,1258 entity, this->parent, 1259 1259 Vector(testPlane->x, testPlane->y, testPlane->z), 1260 1260 collPos, … … 1351 1351 if( yCollisionUp) 1352 1352 { 1353 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y, this->parent,1354 entity, 1353 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y, 1354 entity, this->parent, 1355 1355 Vector(testPlane->x, testPlane->y, testPlane->z), 1356 1356 collPos, SolidFlag); … … 1404 1404 if( yCollisionDown) 1405 1405 { 1406 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , this->parent,1407 entity, 1406 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , 1407 entity, this->parent, 1408 1408 Vector(testPlane->x, testPlane->y, testPlane->z), 1409 1409 collPos, SolidFlag); … … 1483 1483 1484 1484 if( zCollisionRight) { 1485 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z , this->parent,1486 entity, 1485 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z , 1486 entity, this->parent, 1487 1487 Vector(testPlane->x, testPlane->y, testPlane->z), 1488 1488 collPos , SolidFlag); … … 1522 1522 1523 1523 if( zCollisionLeft) { 1524 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z_NEG , this->parent,1525 entity, 1524 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z_NEG , 1525 entity, this->parent, 1526 1526 Vector(testPlane->x, testPlane->y, testPlane->z), 1527 1527 collPos , SolidFlag); -
branches/coll_rect/src/world_entities/world_entity.h
r9988 r10006 92 92 93 93 /** @param worldEntity the world entity to be checked @returns true if there is a collisionreaction registered for the worldEntity */ 94 inline bool isReactive( const WorldEntity& worldEntity) const { return this->_collisionFilter .isReactive() || (this->_collisionFilter(worldEntity)); }94 inline bool isReactive( const WorldEntity& worldEntity) const { return this->_collisionFilter(worldEntity); } 95 95 /** @param worldEntity the world entity to be checked @param type special reaction type @returns true if collision reaction reg. */ 96 96 inline bool isReactive( const WorldEntity& worldEntity, const CoRe::CREngine::ReactionType& type) const 97 { return this->_collisionFilter .isReactive() || (this->_collisionFilter(worldEntity, type)); }97 { return this->_collisionFilter(worldEntity, type); } 98 98 99 99
Note: See TracChangeset
for help on using the changeset viewer.