Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9896 in orxonox.OLD for branches/coll_rect/src/world_entities


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

more design, thinner interface

Location:
branches/coll_rect/src/world_entities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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.