Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9896 in orxonox.OLD for branches


Ignore:
Timestamp:
Oct 20, 2006, 1:09:03 AM (18 years ago)
Author:
patrick
Message:

more design, thinner interface

Location:
branches/coll_rect/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/coll_rect/src/lib/collision_detection/aabb_tree_node.cc

    r9869 r9896  
    1717#include "aabb_tree_node.h"
    1818#include "aabb.h"
    19 
    2019#include "bv_tree.h"
     20
     21#include "collision_tube.h"
    2122
    2223#include "matrix.h"
     
    532533        (treeNode->nodeRight == NULL && treeNode->nodeLeft == NULL)) )
    533534    {
    534       nodeA->registerCollision(nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement);
     535      CoRe::CollisionTube::getInstance()->registerCollisionEvent( nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement);
    535536    }
    536537
  • branches/coll_rect/src/lib/collision_detection/obb_tree_node.cc

    r9869 r9896  
    1818#include "obb_tree.h"
    1919#include "obb.h"
     20
     21#include "collision_tube.h"
    2022
    2123#include "matrix.h"
     
    567569    {
    568570//       PRINTF(0)("----------------------------------------------\n\n\n\n\n\n--------------------------------\n\n\n");
    569       nodeA->registerCollision(nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement);
     571      CoRe::CollisionTube::getInstance()->registerCollisionEvent( nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement);
    570572    }
    571573
  • branches/coll_rect/src/lib/collision_reaction/collision_filter.cc

    r9895 r9896  
    2929#include "debug.h"
    3030
     31#include <vector>
     32
     33
    3134namespace CoRe
    3235{
     
    3841   * @todo this constructor is not jet implemented - do it
    3942  */
    40   CollisionFilter::CollisionFilter (WorldEntity* owner, CREngine::ReactionType type)
     43  CollisionFilter::CollisionFilter (WorldEntity* owner)
    4144  {
    4245    this->registerObject(this, CollisionFilter::_objectList);
    4346
    44     this->owner = owner;
    45     this->type = type;
     47    this->_owner = owner;
    4648
    47     this->bCollided = false;
    48     this->bDispatched = true;
    49 
    50     this->collisionReaction = NULL;
    51     this->bContinuousPoll = false;
    52     this->bStopOnFirstCollision = false;
    53 
    54 
    55     switch( type)
    56     {
    57         case CREngine::CR_PHYSICS_FULL_WALK:
    58         this->collisionReaction = new CRPhysicsFullWalk();
    59         this->bContinuousPoll = true;
    60         break;
    61         case CREngine::CR_PHYSICS_GROUND_WALK:
    62         this->collisionReaction = new CRPhysicsGroundWalk();
    63         this->bContinuousPoll = true;
    64         break;
    65         case CREngine::CR_OBJECT_DAMAGE:
    66         this->collisionReaction = new CRObjectDamage();
    67         this->bStopOnFirstCollision = true;
    68         break;
    69         default:
    70         break;
    71     };
     49    this->_bContinuousPoll = false;
     50    this->_bStopOnFirstCollision = false;
     51    this->_bReactive = false;
    7252  }
    7353
     
    7858  CollisionFilter::~CollisionFilter ()
    7959  {
    80     // delete what has to be deleted here
    81     if( this->collisionReaction != NULL)
    82       delete this->collisionReaction;
    83   }
    84 
    85   /**
    86    * restores the CollisionFilter to its initial state
    87    */
    88   void CollisionFilter::reset()
    89   {
    90     this->flushCollisions();
     60    this->unsubscribeReactions();
    9161  }
    9262
    9363
    9464  /**
    95    * add more filter targets to this collision handle
    96    *  @param classID the classid to look for
     65   * subscribe reaction
    9766   */
    98   void CollisionFilter::addTarget(const ClassID& target)
     67  void CollisionFilter::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1)
    9968  {
    100     // make sure there is no dublicate
    101     std::vector<ClassID>::iterator it = this->targetList.begin();
    102     for( ; it < this->targetList.end(); it++)
    103       if( (*it) == target)
    104         return;
     69    // check if its a valid type
     70    if( likely(this->validCRType( type)))
     71    {
     72      //check if this or any parent class isn't already registered
     73      std::vector<ClassID>::iterator it = this->_filters[type].begin();
     74      for(; it != this->_filters[type].end(); it++)
     75      {
     76        if( unlikely(*it == target1))
     77          return;
     78      }
    10579
    106 
    107     // add element
    108     this->targetList.push_back(target);
    109     PRINTF(5)("addTarget: %i \n", target.id());
     80      // so subscribe the reaction finaly
     81      this->_filters[type].push_back(target1);
     82      this->_bReactive = true;
     83    }
    11084  }
    11185
    11286
    11387  /**
    114    * handles the collisions and react according to algorithm
     88   * subscribe for a reaction
    11589   */
    116   void CollisionFilter::handleCollisions()
     90  void CollisionFilter::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2)
    11791  {
    118     // if continuous poll the reaction
    119     if( this->bContinuousPoll && !this->bCollided)
    120     {
    121       this->collisionReaction->update(this->owner);
    122       return;
    123     }
    124 
    125     // collision reaction calculations (for every collision there will be a reaction)
    126     std::vector<Collision*>::iterator it = this->collisionList.begin();
    127     for(; it < this->collisionList.end(); it++)
    128     {
    129       if( !(*it)->isDispatched())
    130       {
    131         this->collisionReaction->reactToCollision(*it);
    132         (*it)->flushCollisionEvents();
    133       }
    134     }
    135 
    136     // now set state to dispatched
    137     this->bDispatched = true;
    138     this->bCollided = false;
    139 
    140     this->flushCollisions();
     92    this->subscribeReaction(type, target1);
     93    this->subscribeReaction(type, target2);
    14194  }
    14295
    14396
    14497  /**
    145    * filter out the CollisionEvents that are not wanted
    146    *  @param collisionEvent the collision event to filter
     98   * subscribe for a reaction
    14799   */
    148   bool CollisionFilter::filterCollisionEvent(CollisionEvent* collisionEvent)
     100  void CollisionFilter::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
    149101  {
    150     std::vector<ClassID>::iterator it = this->targetList.begin();
    151     for(; it < this->targetList.end(); it++)
    152     {
    153       //     if(collisionEvent->getEntityB()->isA(CL_AIMING_SYSTEM) || collisionEvent->getEntityA()->isA(CL_AIMING_SYSTEM))
    154       //     {
    155       //        PRINTF(0)("I am: %s colliding with: %s\n", owner->getClassCName(), collisionEvent->getEntityB()->getClassCName(), *it);
    156       //        if( collisionEvent->getEntityA() == this->owner) {
    157       //          PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(),
    158       //          collisionEvent->getEntityB()->getClassCName(), *it);
    159       //          if( collisionEvent->getEntityB()->isA((ClassID)(*it))) {
    160       //            PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
    161       //            collisionEvent->getEntityB()->getClassCName(), *it);
    162       //             }
    163       //        }
    164       //        else {
    165       //          PRINTF(0)("I am not owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(),
    166       //          collisionEvent->getEntityB()->getClassCName(), *it);
    167       //          if( collisionEvent->getEntityA()->isA((ClassID)(*it))) {
    168       //            PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
    169       //            collisionEvent->getEntityA()->getClassCName(), *it);
    170       //             }
    171       //        }
    172       //
    173       //     }
     102    this->subscribeReaction(type, target1);
     103    this->subscribeReaction(type, target2);
     104    this->subscribeReaction(type, target3);
     105  }
    174106
    175       if( collisionEvent->getEntityA() == this->owner)
    176       {
    177         if( collisionEvent->getEntityB()->isA((*it)))
    178         {
    179           PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
    180                     collisionEvent->getEntityB()->getClassCName(), (*it).id());
    181           return true;
    182         }
    183       }
    184       else
    185       {
    186         if( collisionEvent->getEntityA()->isA((*it)))
    187         {
    188           PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
    189                     collisionEvent->getEntityA()->getClassCName(), (*it).id());
    190           return true;
    191         }
    192       }
    193     }
     107  /**
     108   * unsubscribe from a specific collision reaction
     109   */
     110  void CollisionFilter::unsubscribeReaction(CoRe::CREngine::ReactionType type)
     111  {
     112    if( likely(this->validCRType( type)))
     113      this->_filters[type].clear();
     114  }
    194115
    195     return false;
     116  /**
     117   * unsubscribe from all collision reactions
     118   */
     119  void CollisionFilter::unsubscribeReactions()
     120  {
     121    for(int i = 0; i < CREngine::CR_NUMBER; i++)
     122      this->_filters[i].clear();
    196123  }
    197124
    198125
     126
    199127  /**
    200    * filter Collisions that are not wanted to be reacted to
    201    *  @param collision the collision object to filter
     128   * tests if the owner WorldEntity is listening to collisions from another specif WorldEntity entity
     129   *  @param entity WorldEntity to test against
     130   *
     131   * This is the most important interface function of this class: it performs a check and returns true
     132   * if the WorldEntity entity is actualy responsive for a certain other WorldEntity
    202133   */
    203   bool CollisionFilter::filterCollision(Collision* collision)
     134  bool CollisionFilter::operator()(const WorldEntity* entity) const
    204135  {
    205     std::vector<ClassID>::iterator it = this->targetList.begin();
    206     for(; it < this->targetList.end(); it++)
     136    // if there are no installed criterions just ommit and
     137    if( this->bReactive())
     138      return false;
     139
     140    // goes through all registered filter criterions and looks for matches
     141    for( int i = 0; i < CREngine::CR_NUMBER; i++ )
    207142    {
    208 
    209       //     if(collision->getEntityB()->isA(CL_AIMING_SYSTEM) || collision->getEntityA()->isA(CL_AIMING_SYSTEM))
    210       //     {
    211       //       PRINTF(0)("Shared!!! I am: %s colliding with: %s\n", owner->getClassCName(), collision->getEntityB()->getClassCName(), *it);
    212       //       if( collision->getEntityA() == this->owner) {
    213       //         PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(),
    214       //         collision->getEntityB()->getClassCName(), *it);
    215       //         if( collision->getEntityB()->isA((ClassID)(*it))) {
    216       //           PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
    217       //           collision->getEntityB()->getClassCName(), *it);
    218       //         }
    219       //       }
    220       //       else {
    221       //         PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(),
    222       //         collision->getEntityB()->getClassCName(), *it);
    223       //         if( collision->getEntityA()->isA((ClassID)(*it))) {
    224       //           PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
    225       //           collision->getEntityA()->getClassCName(), *it);
    226       //         }
    227       //       }
    228       //     }
    229 
    230       if( collision->getEntityA() == this->owner)
    231       {
    232         if( collision->getEntityA()->isA(*it))
     143      std::vector<ClassID>::const_iterator it = this->_filters[i].begin();
     144      for(; it != this->_filters[i].end(); i++ )
     145        if( unlikely(entity->isA(*it)))
    233146          return true;
    234       }
    235       else
    236       {
    237         if( collision->getEntityB()->isA(*it))
    238           return true;
    239       }
    240147    }
    241148
  • branches/coll_rect/src/lib/collision_reaction/collision_filter.h

    r9895 r9896  
    11/*!
    2  * @file collision_handle.h
    3  * @brief Definition of a collision handle: used for accessing per world entity collision events and reactions
     2 * @file collision_filter.h
     3 * @brief Definition of a collision filter: checks if a certain WorldEntity is responsive for another WorldEntity
     4 *
    45*/
    56
     
    2425
    2526
    26   //! A class for defining collision reactions and storing events
     27  /**
     28   * A class for defining collision reactions and storing events (functional object)
     29   *
     30   * This class basically checks if the owner of this filter (a WorldEntity) is responsive for a certain other WorldEntity.
     31   * The check is performed via the operator() (therefore it's a functional objects). For each CollisionReaction there is a list
     32   * of WorldEntities (their ClassIDs) to which it listens to.
     33   */
    2734  class CollisionFilter : public BaseObject
    2835  {
    2936    ObjectListDeclaration(CollisionFilter);
    3037
     38
     39    /* Constructor/Deconstructors */
    3140  public:
    32     CollisionFilter(WorldEntity* owner, CREngine::ReactionType type);
     41    CollisionFilter(WorldEntity* owner);
    3342    virtual ~CollisionFilter();
    3443
    35     void reset();
    36 
    37     void addTarget(const ClassID& target);
    38 
    39     /** @returns true if regiestered some new collision events in this tick frame */
    40     inline bool isCollided() const { return this->bCollided; }
    41     /** @returns true if this collision handle has already been dispatched */
    42     inline bool isDispatched() const { return this->bDispatched; }
    43     /** @returns true if this handle should be pulled also if there are no collisions */
    44     inline bool isContinuousPoll() const { return this->bContinuousPoll; }
    45     /** @returns the type */
    46     inline CREngine::ReactionType getType() const { return this->type; }
    47 
    48     void handleCollisions();
     44  private:
     45    CollisionFilter(const CollisionFilter& collisionFilter) {}
     46    WorldEntity*                  _owner;                   //!< the worldenity this reaction will be applied on
    4947
    5048
    51   private:
    52     void flushCollisions();
    53     bool filterCollisionEvent(CollisionEvent* collisionEvent);
    54     bool filterCollision(Collision* collision);
     49    /* Defines Operators */
     50    bool operator()(const WorldEntity* entity) const;
    5551
    5652
     53    /* Collision Reaction subscription unsubscription Block */
     54  public:
     55    void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1);
     56    void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2);
     57    void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3);
     58
     59    void unsubscribeReaction(CoRe::CREngine::ReactionType type);
     60    void unsubscribeReactions();
    5761
    5862  private:
    59     WorldEntity*                  owner;                   //!< the worldenity this reaction will be applied on
    60     CREngine::ReactionType              type;                    //!< the reaction type
     63    std::vector<ClassID>          _filters[CREngine::CR_NUMBER];  //!< an array of filter targets: for each collision type a list of filter objects
    6164
    62     bool                          bContinuousPoll;         //!< if this is true
    63     bool                          bDispatched;             //!< true if this handle has already been dispatched
    64     bool                          bStopOnFirstCollision;   //!< true if the cd of this object should be terminated after one match
    65     bool                          bCollided;               //!< true if the CollsionHandle has registered some new collisions
    6665
    67     std::vector<Collision*>       collisionList;           //!< a list full of collisions
    68     std::vector<ClassID>          targetList;              //!< a list of target classes for filtering @TODO TAKE SET INSTEAD OF VECTOR HERE
     66    /* Misc State Informations */
     67  public:
     68    /** @returns true if this handle should be pulled also if there are no collisions, can also be set with this function (reference)*/
     69    inline bool& bContinousPoll() { return this->_bContinuousPoll; }
     70    /** @returns true if this filter should be pulled always */
     71    inline bool bContinousPoll() const { return this->_bContinuousPoll; }
     72    /** @returns true if this @param type Collision Reaction type is a valid number */
     73    inline bool validCRType(const CREngine::ReactionType& type) const {return (type >= 0 && type < CREngine::CR_NUMBER); }
     74    /** @returns true if this filter is reactive i.e. at least one filter criterion installed */
     75    inline bool bReactive() const { return this->_bReactive; }
    6976
    70     CollisionReaction*            collisionReaction;       //!< reference to the collision reaction object
     77  private:
     78    bool                          _bContinuousPoll;         //!< if this is true
     79    bool                          _bStopOnFirstCollision;   //!< true if the cd of this object should be terminated after one match
     80    bool                          _bReactive;               //!< true if this class has at least one filter criterion == one target
    7181
    7282  };
  • branches/coll_rect/src/lib/collision_reaction/collision_tube.cc

    r9893 r9896  
    3333
    3434  ObjectListDefinition(CollisionTube);
     35
     36  CollisionTube* CollisionTube::instance = NULL;
     37
    3538
    3639  /**
  • branches/coll_rect/src/lib/collision_reaction/collision_tube.h

    r9893 r9896  
    4848    ObjectListDeclaration(CollisionTube);
    4949
     50  public:
     51    virtual ~CollisionTube();
    5052
    51   public:
    52     CollisionTube();
    53     virtual ~CollisionTube();
     53    inline static CollisionTube* getInstance() { if( CollisionTube::instance != NULL) CollisionTube::instance = new CollisionTube(); return CollisionTube::instance; }
    5454
    5555    /** @returns true if at least one of both WorldEntities are subscribed for a collision check */
     
    6666
    6767  private:
     68    /* private std constructor since this is a singleton class */
     69    CollisionTube();
    6870    /* private copy constructor so this object can't be passed as a */
    6971    CollisionTube(const CollisionTube& tube) {}
     
    7375    std::vector<Collision*>        _collisionList;      //!< the list of collisions since the last processing
    7476
     77    static CollisionTube*          instance;            //!< the singleton instance
    7578  };
    7679
  • branches/coll_rect/src/lib/graphics/importer/bsp_manager.cc

    r9869 r9896  
    4646
    4747#include "aabb.h"
    48 #include "cr_defs.h"
     48#include "cr_engine.h"
     49#include "collision_tube.h"
    4950
    5051
     
    12151216  if( xCollisionForward)
    12161217  {
    1217     entity->registerCollision(COLLISION_TYPE_AXIS_X ,
     1218    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X ,
    12181219                              this->parent, entity,
    12191220                              Vector(testPlane->x, testPlane->y, testPlane->z),
     
    12541255  if( xCollisionBackward)
    12551256  {
    1256     entity->registerCollision(COLLISION_TYPE_AXIS_X_NEG ,
     1257    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X_NEG,
    12571258                              this->parent, entity,
    12581259                              Vector(testPlane->x, testPlane->y, testPlane->z),
     
    13501351  if( yCollisionUp)
    13511352  {
    1352     entity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent,
     1353    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y, this->parent,
    13531354                              entity,
    13541355                              Vector(testPlane->x, testPlane->y, testPlane->z),
     
    14031404  if( yCollisionDown)
    14041405  {
    1405     entity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent,
     1406    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , this->parent,
    14061407                              entity,
    14071408                              Vector(testPlane->x, testPlane->y, testPlane->z),
    14081409                              collPos, SolidFlag);
    14091410  }
    1410 
    1411 
    14121411}
    14131412
     
    14841483
    14851484  if( zCollisionRight) {
    1486     entity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent,
     1485    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z , this->parent,
    14871486                              entity,
    14881487                              Vector(testPlane->x, testPlane->y, testPlane->z),
     
    15231522
    15241523  if( zCollisionLeft) {
    1525     entity->registerCollision(COLLISION_TYPE_AXIS_Z_NEG , this->parent,
    1526                               entity,
    1527                               Vector(testPlane->x, testPlane->y, testPlane->z),
    1528                               collPos , SolidFlag);
     1524    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z_NEG , this->parent,
     1525                               entity,
     1526                               Vector(testPlane->x, testPlane->y, testPlane->z),
     1527                               collPos , SolidFlag);
    15291528  }
    15301529
  • branches/coll_rect/src/world_entities/world_entity.cc

    r9892 r9896  
    3535#include "camera.h"
    3636
    37 #include "collision_handle.h"
     37#include "collision_filter.h"
    3838#include "collision_event.h"
    3939#include "game_rules.h"
     
    5858 */
    5959WorldEntity::WorldEntity()
    60     : Synchronizeable()
     60  : Synchronizeable(), collisionFilter(this)
    6161{
    6262  this->registerObject(this, WorldEntity::_objectList);
     
    7878
    7979  // reset all collision handles to NULL == unsubscribed state
    80   for(int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i)
    81     this->collisionHandles[i] = NULL;
    8280  this->bReactive = false;
    8381  this->bOnGround = false;
     
    8886  this->toList(OM_NULL);
    8987
    90   registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) );
    91   modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) );
    92   scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) );
    93   list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) );
    94 
    95   health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) );
    96   healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) );
     88  this->registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) );
     89  this->modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) );
     90  this->scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) );
     91  this->list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) );
     92
     93  this->health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) );
     94  this->healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) );
    9795}
    9896
     
    115113    delete this->healthWidget;
    116114
    117   this->unsubscribeReaction();
     115  this->unsubscribeReactions();
    118116}
    119117
     
    304302void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1)
    305303{
    306   this->subscribeReaction(type);
    307 
    308   // add the target filter
    309   this->collisionHandles[type]->addTarget(target1);
     304  this->collisionFilter.subscribeReaction(type, target1);
    310305}
    311306
     
    318313void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2)
    319314{
    320   this->subscribeReaction(type);
    321 
    322   // add the target filter
    323   this->collisionHandles[type]->addTarget(target1);
    324   this->collisionHandles[type]->addTarget(target2);
     315  this->collisionFilter.subscribeReaction(type, target1, target2);
    325316}
    326317
     
    333324void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
    334325{
    335   this->subscribeReaction(type);
    336 
    337   // add the target filter
    338   this->collisionHandles[type]->addTarget(target1);
    339   this->collisionHandles[type]->addTarget(target2);
    340   this->collisionHandles[type]->addTarget(target3);
    341 }
    342 
    343 
    344 
    345 /**
    346  * subscribes this world entity to a collision reaction
    347  *  @param type the type of reaction to subscribe to
    348  *  @param nrOfTargets number of target filters
    349  *  @param ... the targets as classIDs
    350  */
    351 void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type)
    352 {
    353   if( this->collisionHandles[type] != NULL)
    354   {
    355     PRINTF(2)("Registering for a CollisionReaction already subscribed to! Skipping\n");
    356     return;
    357   }
    358 
    359   this->collisionHandles[type] = CoRe::CREngine::getInstance()->subscribeReaction(this, type);
    360 
    361   // now there is at least one collision reaction subscribed
    362   this->bReactive = true;
     326  this->collisionFilter.subscribeReaction(type, target1, target2, target3);
    363327}
    364328
     
    370334void WorldEntity::unsubscribeReaction(CoRe::CREngine::ReactionType type)
    371335{
    372   if( this->collisionHandles[type] == NULL)
    373     return;
    374 
    375   CoRe::CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]);
    376   this->collisionHandles[type] = NULL;
    377 
    378   // check if there is still any handler registered
    379   for(int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i)
    380   {
    381     if( this->collisionHandles[i] != NULL)
    382     {
    383       this->bReactive = true;
    384       return;
    385     }
    386   }
    387   this->bReactive = false;
     336  this->collisionFilter.unsubscribeReaction(type);
    388337}
    389338
     
    392341 * unsubscribes all collision reactions
    393342 */
    394 void WorldEntity::unsubscribeReaction()
    395 {
    396   for( int i = 0; i < CoRe::CREngine::CR_NUMBER; i++)
    397     this->unsubscribeReaction((CoRe::CREngine::ReactionType)i);
    398 
    399   // there are no reactions subscribed from now on
    400   this->bReactive = false;
    401 }
    402 
    403 
    404 /**
    405  * registers a new collision event to this world entity
    406  *  @param entityA entity of the collision
    407  *  @param entityB entity of the collision
    408  *  @param bvA colliding bounding volume of entityA
    409  *  @param bvB colliding bounding volume of entityA
    410  */
    411 bool WorldEntity::registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
    412 {
    413   PRINTF(5)("registering collision of type: %s vs %s\n", entityA->getClassCName(), entityB->getClassCName());
    414   // is there any handler listening?
    415   if( !this->bReactive)
    416     return false;
    417 
    418   // get a collision event
    419   CoRe::CollisionEvent* c = CoRe::CREngine::getInstance()->popCollisionEventObject();
    420   assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
    421 //  c->collide(COLLISION_TYPE_OBB, entityA, entityB, bvA, bvB);
    422 
    423   for( int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i)
    424     if( this->collisionHandles[i] != NULL)
    425       this->collisionHandles[i]->registerCollisionEvent(c);
    426   return true;
    427 }
    428 
    429 
    430 /**
    431  * registers a new collision event to this woeld entity
    432  *  @param entity the entity that collides
    433  *  @param plane it stands on
    434  *  @param position it collides on the plane
    435  */
    436 bool WorldEntity::registerCollision(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall)
    437 {
    438   // is there any handler listening?
    439   if( !this->bReactive)
    440     return false;
    441 
    442   // get a collision event
    443   CoRe::CollisionEvent* c = CoRe::CREngine::getInstance()->popCollisionEventObject();
    444   assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
    445 //  c->collide(type, entity, groundEntity, normal, position, bInWall);
    446 
    447   for( int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i)
    448     if( this->collisionHandles[i] != NULL)
    449       this->collisionHandles[i]->registerCollisionEvent(c);
    450   return true;
     343void WorldEntity::unsubscribeReactions()
     344{
     345  this->collisionFilter.unsubscribeReactions();
    451346}
    452347
  • branches/coll_rect/src/world_entities/world_entity.h

    r9892 r9896  
    1212
    1313#include "cr_engine.h"
     14#include "collision_filter.h"
    1415#include "object_manager.h"
    1516#include "glincl.h"
     
    2526namespace OrxSound { class SoundBuffer; class SoundSource; }
    2627namespace OrxGui { class GLGuiWidget; class GLGuiBar; class GLGuiEnergyWidget; };
    27 namespace CoRe { class CollisionHandle; class Collision; }
     28namespace CoRe { class Collision; }
    2829
    2930class BVTree;
     
    7677  inline AABB* getModelAABB() const { return (this->aabbNode)?this->aabbNode->getAABB():NULL;}
    7778
     79  virtual void hit(float damage, WorldEntity* killer);
     80
    7881
    7982  /* --- Collision Reaction Block --- */
    80   void subscribeReaction(CoRe::CREngine::ReactionType type);
    8183  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1);
    8284  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2);
     
    8486
    8587  void unsubscribeReaction(CoRe::CREngine::ReactionType type);
    86   void unsubscribeReaction();
    87 
    88   bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
    89   bool registerCollision(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall = false);
     88  void unsubscribeReactions();
     89
    9090  /** @return true if there is at least on collision reaction subscribed */
    9191  inline bool isReactive() const { return this->bReactive; }
    9292
    93   CoRe::CollisionHandle* getCollisionHandle(CoRe::CREngine::ReactionType type) const { return this->collisionHandles[type]; }
     93  const CoRe::CollisionFilter& getCollisionFilter(CoRe::CREngine::ReactionType type) const { return this->collisionFilter; }
    9494
    9595  /** @returns true if this entity is standing on ground (BSP model) */
     
    9797  /** @param flag: marks if this entity is standing on ground */
    9898  void setOnGround(bool flag) { this->bOnGround = flag; }
    99 
    100   virtual void hit(float damage, WorldEntity* killer);
    10199
    102100  virtual void destroy( WorldEntity* killer );
     
    193191
    194192  /* collision reaction stuff */
    195   CoRe::CollisionHandle*  collisionHandles[CoRe::CREngine::CR_NUMBER];  //!< the list of the collision reactions
    196   bool                    bReactive;                              //!< true if there is at least one collision reaction subscibed
     193  CoRe::CollisionFilter   collisionFilter;                 //!< filter for collision event filtering (not every entity listens to all collisions)
     194  bool                    bReactive;                       //!< true if there is at least one collision reaction subscibed
    197195
    198196
Note: See TracChangeset for help on using the changeset viewer.