Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7964 in orxonox.OLD


Ignore:
Timestamp:
May 30, 2006, 12:48:16 AM (18 years ago)
Author:
patrick
Message:

cr: deep structure with Collision and CollisionEvent created. list cleanup missing.

Location:
branches/cr/src/lib/collision_reaction
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/cr/src/lib/collision_reaction/collision.h

    r7959 r7964  
    88
    99#include "vector.h"
     10#include <vector>
    1011
    1112class WorldEntity;
     
    2526
    2627  /** @return Collision WorldEntity A */
    27   inline const WorldEntity* getEntityA() const { return this->entityA; }
     28  inline WorldEntity* getEntityA() const { return this->entityA; }
    2829  /** @return Collision WorldEntity B */
    29   inline const WorldEntity* getEntityB() const { return this->entityB; }
     30  inline WorldEntity* getEntityB() const { return this->entityB; }
    3031
    3132  /** registers a @param event CollisionEvent to take place */
  • branches/cr/src/lib/collision_reaction/collision_event.h

    r7959 r7964  
    2626
    2727  /** @return CollisionEvent WorldEntity A */
    28   inline const WorldEntity* getEntityA() const { return this->entityA; }
     28  inline WorldEntity* getEntityA() const { return this->entityA; }
    2929  /** @return CollisionEvent WorldEntity B */
    30   inline const WorldEntity* getEntityB() const { return this->entityB; }
     30  inline WorldEntity* getEntityB() const { return this->entityB; }
    3131  /** @return Bounding Volume from EntityA */
    32   inline const BoundingVolume* getBVA() const { return this->bvA; }
     32  inline BoundingVolume* getBVA() const { return this->bvA; }
    3333  /** @return Bounding Volume from EntityB */
    34   inline const BoundingVolume* getBVB() const { return this->bvB; }
     34  inline BoundingVolume* getBVB() const { return this->bvB; }
    3535
    3636
  • branches/cr/src/lib/collision_reaction/collision_handle.cc

    r7947 r7964  
    1818
    1919
    20 
     20#include "collision.h"
     21#include "collision_event.h"
    2122
    2223using namespace std;
     
    7576 *  @param collision the collision objects containing all collision informations
    7677 */
    77 void CollisionHandle::registerCollision(Collision* collision)
     78void CollisionHandle::registerCollisionEvent(CollisionEvent* collisionEvent)
    7879{
    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);
    8094}
    8195
     
    8599void CollisionHandle::flushCollisions()
    86100{
    87   std::vector<Collision*>::iterator it;
    88   for( it = this->collisionList.begin(); it != this->collisionList.end(); it++)
    89     CREngine::getInstance()->pushCollisionObject(*it);
    90101  this->collisionList.clear();
    91102}
  • branches/cr/src/lib/collision_reaction/collision_handle.h

    r7959 r7964  
    2929
    3030    void addTarget(long classID);
    31     void registerCollision(Collision* collision);
     31    void registerCollisionEvent(CollisionEvent* collisionEvent);
    3232    /** @returns true if regiestered some new collision events in this tick frame */
    3333    inline bool isCollided() const { return this->bCollided; }
  • branches/cr/src/lib/collision_reaction/cr_defs.h

    r7941 r7964  
    1111### File Specific:
    1212   main-programmer: Patrick Boenzli
    13    co-programmer: Christian Meyer
    1413*/
    1514
     
    2221#define _CR_DEFS_H
    2322
     23//!< the maximal number of touching objects (collisions) per frame
     24#define CR_MAX_COLLISIONS          500
    2425
    25 #define CR_MAX_COLLISIONS  1000
     26//!< the maximal number of bounding volumes collision events per frame
     27#define CR_MAX_COLLISION_EVENTS   3000
    2628
    2729
  • branches/cr/src/lib/collision_reaction/cr_engine.cc

    r7958 r7964  
    1919
    2020#include "collision.h"
     21#include "collision_event.h"
    2122#include "collision_handle.h"
    2223#include "cr_defs.h"
     
    5152  CREngine::singletonRef = NULL;
    5253
    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);
    5558
    5659  this->reset();
    5760
    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;
    6167
    62   this->cachedCollisions.clear();
     68  this->collisionsUnused.clear();
     69  this->collisionEventsUnused.clear();
    6370}
    6471
     
    7077  // create a list of Collision events (precaching)
    7178  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());
    7382}
    7483
  • branches/cr/src/lib/collision_reaction/cr_engine.h

    r7960 r7964  
    22 * @file cr_engine.h
    33 * @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 */
    510
    611#ifndef _CR_ENGINE_
     
    1419class CollisionHandle;
    1520class Collision;
     21class CollisionEvent;
    1622class WorldEntity;
    1723
     
    5157
    5258  /** @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; }
    5662
     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; }
    5767
    5868  void debug();
     
    7080  std::vector<Collision*>             collisionsUnused;         //!< a list of unused, cached collisions
    7181
    72   std::vector<Collision*>             collisionEventsUsed;      //!< a list of used, cached collision events
    73   std::vector<Collision*>             collisionEventsUnused;    //!< a list of unused, cached collision events
     82  std::vector<CollisionEvent*>        collisionEventsUsed;      //!< a list of used, cached collision events
     83  std::vector<CollisionEvent*>        collisionEventsUnused;    //!< a list of unused, cached collision events
    7484
    7585  static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
Note: See TracChangeset for help on using the changeset viewer.