Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10006 in orxonox.OLD for branches/coll_rect


Ignore:
Timestamp:
Dec 4, 2006, 2:24:40 PM (18 years ago)
Author:
patrick
Message:

removed many very heavy segfaults

Location:
branches/coll_rect/src
Files:
9 edited

Legend:

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

    r9988 r10006  
    7171    /** @return Collision WorldEntity B */
    7272    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 {
    7474      return ((this->_entityA == &entityA && this->_entityB == &entityB) || (this->_entityA == &entityB && this->_entityB == &entityA)); }
    7575
  • branches/coll_rect/src/lib/collision_reaction/collision_event.h

    r9892 r10006  
    4949
    5050    /** @return CollisionEvent WorldEntity A */
    51     inline WorldEntity* getEntityA() const
    52     {
    53       return this->entityA;
    54     }
     51    inline const WorldEntity* getEntityA() const  { return this->entityA; }
    5552    /** @return CollisionEvent WorldEntity B */
    56     inline WorldEntity* getEntityB() const
    57     {
    58       return this->entityB;
    59     }
     53    inline const WorldEntity* getEntityB() const  { return this->entityB; }
    6054    /** @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; }
    6556    /** @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;  }
    7058
    7159    /** @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; }
    7661
    7762    /** @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;  }
    8264
    8365    /** @return the type of the collision */
    84     inline int getType()
    85     {
    86       return this->collisionType;
    87     }
     66    inline int getType() const  {  return this->collisionType;  }
    8867
    8968    /** @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;  }
    9470
    9571
  • branches/coll_rect/src/lib/collision_reaction/collision_filter.cc

    r9990 r10006  
    142142  bool CollisionFilter::operator()(const WorldEntity& entity) const
    143143  {
    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())
    146148      return false;
    147149
     
    149151    for( int i = 0; i < CREngine::CR_NUMBER; i++ )
    150152    {
    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());
    153157        if( unlikely(entity.isA(*it) ) )
    154158          return true;
     159      }
    155160    }
    156161
     
    168173  bool CollisionFilter::operator()(const WorldEntity& entity, const CREngine::ReactionType type) const
    169174  {
     175    assert(&entity != NULL);
     176
     177    PRINTF(0)("operator()(const WorldEntity& entity, const CREngine::ReactionType type)\n");
    170178    // if there are no installed criterions just omit and return
    171179    if( !this->isReactive())
    172180      return false;
    173181
     182
    174183    // goes through all registered filter criterions and looks for matches
    175184    TargetIteratorConst it = this->_filters[type].begin();
    176185    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))
    178189        return true;
     190    }
    179191
    180192    return false;
  • branches/coll_rect/src/lib/collision_reaction/collision_tube.cc

    r9995 r10006  
    2727#include "cr_physics_full_walk.h"
    2828
     29#include "debug.h"
    2930
    3031
     
    5253  CollisionTube::~CollisionTube ()
    5354  {
     55    this->reset();
     56  }
     57
     58
     59
     60  /**
     61   * resets the collision tube after each collision detection cycle
     62   */
     63  void CollisionTube::reset()
     64  {
    5465    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;
    5592  }
    5693
     
    67104  void CollisionTube::registerCollisionEvent(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
    68105  {
    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);
    79108
    80109    // now register the new collision event
     
    95124   */
    96125  void CollisionTube::registerCollisionEvent(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity,
    97                               const Vector& normal, const Vector& position, bool bInWall)
     126      const Vector& normal, const Vector& position, bool bInWall)
    98127  {
    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);
    111130
    112131    // now register the new collision event
  • branches/coll_rect/src/lib/collision_reaction/collision_tube.h

    r9994 r10006  
    7070    void registerCollisionEvent(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity,
    7171                                const Vector& normal, const Vector& position, bool bInWall = false);
     72    Collision* registerCollision(WorldEntity* entityA, WorldEntity* entityB);
     73
     74    void reset();
    7275
    7376    /** @returns an iterator pointing to the beginning of the list */
  • branches/coll_rect/src/lib/collision_reaction/cr_engine.cc

    r10000 r10006  
    6666      PRINTF(0)("CollisionReaction Error: CollisionEvent cache size missmatch: %i of %i\n", this->collisionEventsUnused.size(), CR_MAX_COLLISION_EVENTS);
    6767
    68     this->flushCollisions();
     68    this->reset();
    6969
    7070    CollisionIterator it1 = this->collisionsUnused.begin();
     
    121121      return this->collisionsUsed.back();
    122122    }
    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    }
    124129  }
    125130
     
    136141      return this->collisionEventsUsed.back();
    137142    }
    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    }
    139149  }
    140150
     
    147157    // for all collisions:
    148158    CollisionIterator ci = CollisionTube::getInstance()->begin();
    149     for(; ci < CollisionTube::getInstance()->end(); ++ci)
     159    for(; ci < CollisionTube::getInstance()->end(); ci++)
    150160    {
    151161      for( int i = CREngine::CR_PHYSICS_MOMENTUM; i < CREngine::CR_NUMBER; i++)
     
    153163        if( _reactionList[i] == NULL)
    154164          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());
    155169
    156170        // check if entity A or B is subscibed for this event
     
    161175          PRINTF(0)("react to %i\n", i);
    162176        }
    163 
    164         (*ci)->reset();
    165177      }
    166     }
    167 
    168     this->flushCollisions();
     178      (*ci)->reset();
     179    }
     180
     181    this->reset();
    169182  }
    170183
     
    173186   * flushes all the collision lists and puts them to their initial state
    174187   */
    175   void CREngine::flushCollisions()
     188  void CREngine::reset()
    176189  {
    177190    CollisionIterator it1 = this->collisionsUsed.begin();
     
    185198    this->collisionsUsed.clear();
    186199    this->collisionEventsUsed.clear();
     200
     201    CollisionTube::getInstance()->reset();
    187202  }
    188203
  • branches/coll_rect/src/lib/collision_reaction/cr_engine.h

    r9988 r10006  
    7373    inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
    7474
    75 
    7675    Collision* popCollisionObject();
    7776    CollisionEvent* popCollisionEventObject();
     
    8685    void init();
    8786
    88     void flushCollisions();
     87    void reset();
    8988
    9089
  • branches/coll_rect/src/lib/graphics/importer/bsp_manager.cc

    r9896 r10006  
    12171217  {
    12181218    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X ,
    1219                               this->parent, entity,
     1219                              entity, this->parent,
    12201220                              Vector(testPlane->x, testPlane->y, testPlane->z),
    12211221                              collPos,
     
    12561256  {
    12571257    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X_NEG,
    1258                               this->parent, entity,
     1258                              entity, this->parent,
    12591259                              Vector(testPlane->x, testPlane->y, testPlane->z),
    12601260                              collPos,
     
    13511351  if( yCollisionUp)
    13521352  {
    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,
    13551355                              Vector(testPlane->x, testPlane->y, testPlane->z),
    13561356                              collPos, SolidFlag);
     
    14041404  if( yCollisionDown)
    14051405  {
    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,
    14081408                              Vector(testPlane->x, testPlane->y, testPlane->z),
    14091409                              collPos, SolidFlag);
     
    14831483
    14841484  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,
    14871487                              Vector(testPlane->x, testPlane->y, testPlane->z),
    14881488                              collPos , SolidFlag);
     
    15221522
    15231523  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,
    15261526                               Vector(testPlane->x, testPlane->y, testPlane->z),
    15271527                               collPos , SolidFlag);
  • branches/coll_rect/src/world_entities/world_entity.h

    r9988 r10006  
    9292
    9393  /** @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); }
    9595  /** @param worldEntity the world entity to be checked @param type special reaction type @returns true if collision reaction reg. */
    9696  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); }
    9898
    9999
Note: See TracChangeset for help on using the changeset viewer.