- Timestamp:
- May 30, 2006, 12:48:16 AM (19 years ago)
- Location:
- branches/cr/src/lib/collision_reaction
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/cr/src/lib/collision_reaction/collision.h
r7959 r7964 8 8 9 9 #include "vector.h" 10 #include <vector> 10 11 11 12 class WorldEntity; … … 25 26 26 27 /** @return Collision WorldEntity A */ 27 inline constWorldEntity* getEntityA() const { return this->entityA; }28 inline WorldEntity* getEntityA() const { return this->entityA; } 28 29 /** @return Collision WorldEntity B */ 29 inline constWorldEntity* getEntityB() const { return this->entityB; }30 inline WorldEntity* getEntityB() const { return this->entityB; } 30 31 31 32 /** registers a @param event CollisionEvent to take place */ -
branches/cr/src/lib/collision_reaction/collision_event.h
r7959 r7964 26 26 27 27 /** @return CollisionEvent WorldEntity A */ 28 inline constWorldEntity* getEntityA() const { return this->entityA; }28 inline WorldEntity* getEntityA() const { return this->entityA; } 29 29 /** @return CollisionEvent WorldEntity B */ 30 inline constWorldEntity* getEntityB() const { return this->entityB; }30 inline WorldEntity* getEntityB() const { return this->entityB; } 31 31 /** @return Bounding Volume from EntityA */ 32 inline constBoundingVolume* getBVA() const { return this->bvA; }32 inline BoundingVolume* getBVA() const { return this->bvA; } 33 33 /** @return Bounding Volume from EntityB */ 34 inline constBoundingVolume* getBVB() const { return this->bvB; }34 inline BoundingVolume* getBVB() const { return this->bvB; } 35 35 36 36 -
branches/cr/src/lib/collision_reaction/collision_handle.cc
r7947 r7964 18 18 19 19 20 20 #include "collision.h" 21 #include "collision_event.h" 21 22 22 23 using namespace std; … … 75 76 * @param collision the collision objects containing all collision informations 76 77 */ 77 void CollisionHandle::registerCollision (Collision* collision)78 void CollisionHandle::registerCollisionEvent(CollisionEvent* collisionEvent) 78 79 { 79 this->collisionList.push_back(collision); 80 // first element only 81 if( this->collisionList.empty()) 82 { 83 Collision* c = CREngine::getInstance()->popCollisionObject(); 84 c->collide(collisionEvent->getEntityA(), collisionEvent->getEntityB()); 85 this->collisionList.push_back(c); 86 } 87 if( ((this->collisionList.back())->getEntityA() == collisionEvent->getEntityA()) && 88 ((this->collisionList.back())->getEntityB() == collisionEvent->getEntityB())) 89 { 90 (this->collisionList.back())->registerCollisionEvent(collisionEvent); 91 } 92 93 //this->collisionList.push_back(collisionEvent); 80 94 } 81 95 … … 85 99 void CollisionHandle::flushCollisions() 86 100 { 87 std::vector<Collision*>::iterator it;88 for( it = this->collisionList.begin(); it != this->collisionList.end(); it++)89 CREngine::getInstance()->pushCollisionObject(*it);90 101 this->collisionList.clear(); 91 102 } -
branches/cr/src/lib/collision_reaction/collision_handle.h
r7959 r7964 29 29 30 30 void addTarget(long classID); 31 void registerCollision (Collision* collision);31 void registerCollisionEvent(CollisionEvent* collisionEvent); 32 32 /** @returns true if regiestered some new collision events in this tick frame */ 33 33 inline bool isCollided() const { return this->bCollided; } -
branches/cr/src/lib/collision_reaction/cr_defs.h
r7941 r7964 11 11 ### File Specific: 12 12 main-programmer: Patrick Boenzli 13 co-programmer: Christian Meyer14 13 */ 15 14 … … 22 21 #define _CR_DEFS_H 23 22 23 //!< the maximal number of touching objects (collisions) per frame 24 #define CR_MAX_COLLISIONS 500 24 25 25 #define CR_MAX_COLLISIONS 1000 26 //!< the maximal number of bounding volumes collision events per frame 27 #define CR_MAX_COLLISION_EVENTS 3000 26 28 27 29 -
branches/cr/src/lib/collision_reaction/cr_engine.cc
r7958 r7964 19 19 20 20 #include "collision.h" 21 #include "collision_event.h" 21 22 #include "collision_handle.h" 22 23 #include "cr_defs.h" … … 51 52 CREngine::singletonRef = NULL; 52 53 53 if( this->cachedCollisions.size() != CR_MAX_COLLISIONS) 54 PRINTF(0)("CollisionReaction Error: cache size missmatch: %i of %i\n", this->cachedCollisions.size(), CR_MAX_COLLISIONS); 54 if( this->collisionsUnused.size() != CR_MAX_COLLISIONS) 55 PRINTF(0)("CollisionReaction Error: Collision cache size missmatch: %i of %i\n", this->collisionsUnused.size(), CR_MAX_COLLISIONS); 56 if( this->collisionEventsUnused.size() != CR_MAX_COLLISION_EVENTS) 57 PRINTF(0)("CollisionReaction Error: CollisionEvent cache size missmatch: %i of %i\n", this->collisionEventsUnused.size(), CR_MAX_COLLISION_EVENTS); 55 58 56 59 this->reset(); 57 60 58 vector<Collision*>::iterator it = this->cachedCollisions.begin(); 59 for(; it < this->cachedCollisions.end(); it++) 60 delete *it; 61 vector<Collision*>::iterator it1 = this->collisionsUnused.begin(); 62 for(; it1 < this->collisionsUnused.end(); it1++) 63 delete *it1; 64 vector<CollisionEvent*>::iterator it2 = this->collisionEventsUnused.begin(); 65 for(; it2 < this->collisionEventsUnused.end(); it2++) 66 delete *it2; 61 67 62 this->cachedCollisions.clear(); 68 this->collisionsUnused.clear(); 69 this->collisionEventsUnused.clear(); 63 70 } 64 71 … … 70 77 // create a list of Collision events (precaching) 71 78 for( int i = 0; i < CR_MAX_COLLISIONS; i++) 72 this->cachedCollisions.push_back(new Collision()); 79 this->collisionsUnused.push_back(new Collision()); 80 for( int i = 0; i < CR_MAX_COLLISION_EVENTS; i++) 81 this->collisionEventsUnused.push_back(new CollisionEvent()); 73 82 } 74 83 -
branches/cr/src/lib/collision_reaction/cr_engine.h
r7960 r7964 2 2 * @file cr_engine.h 3 3 * @brief The collision reaction engine, defining generic collision reactions to collision events 4 */ 4 * 5 * some parts of this module are tuned for efficiency. They are probably not self-explenatory anymore :D 6 * - Collision/ CollisionEvent objects recycling: This class contains a class of precached objects of these types 7 * they are used for fast registration of collision events: These objects can be get by the interface functions and 8 * are returned after one cycle automaticly by reseting the cached lists to its initial state. So do not wonder :D 9 */ 5 10 6 11 #ifndef _CR_ENGINE_ … … 14 19 class CollisionHandle; 15 20 class Collision; 21 class CollisionEvent; 16 22 class WorldEntity; 17 23 … … 51 57 52 58 /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */ 53 inline Collision* popCollisionObject() { if(!this->collisionsUnused.empty()) { return this->collisionsUnused.back(); this->collisionsUnused.pop_back();} else return NULL; }54 /** @param collision: returns the Collision object back to the cache list */55 inline void pushCollisionObject(Collision* collision) { this->collisionsUsed.push_back(collision); }59 inline Collision* popCollisionObject() { 60 if( !this->collisionsUnused.empty()) { 61 this->collisionsUsed.push_back(this->collisionsUnused.back()); this->collisionsUnused.pop_back(); return this->collisionsUsed.back(); } else return NULL; } 56 62 63 /** @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled */ 64 inline CollisionEvent* popCollisionEventObject() { 65 if( !this->collisionEventsUnused.empty()) { 66 this->collisionEventsUsed.push_back(this->collisionEventsUnused.back()); this->collisionEventsUnused.pop_back(); return this->collisionEventsUsed.back(); } else return NULL; } 57 67 58 68 void debug(); … … 70 80 std::vector<Collision*> collisionsUnused; //!< a list of unused, cached collisions 71 81 72 std::vector<Collision *>collisionEventsUsed; //!< a list of used, cached collision events73 std::vector<Collision *>collisionEventsUnused; //!< a list of unused, cached collision events82 std::vector<CollisionEvent*> collisionEventsUsed; //!< a list of used, cached collision events 83 std::vector<CollisionEvent*> collisionEventsUnused; //!< a list of unused, cached collision events 74 84 75 85 static CREngine* singletonRef; //!< the reference to the CREngine object (singleton)
Note: See TracChangeset
for help on using the changeset viewer.