Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10010 in orxonox.OLD for branches/coll_rect.merge/src/world_entities


Ignore:
Timestamp:
Dec 4, 2006, 4:39:45 PM (18 years ago)
Author:
patrick
Message:

merged the temp branch

Location:
branches/coll_rect.merge/src/world_entities
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/coll_rect.merge/src/world_entities/creatures/fps_player.cc

    r9869 r10010  
    167167
    168168    //subscribe to collision reaction
    169   this->subscribeReaction(CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID());
     169  this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID());
    170170
    171171  this->initWeapon = false;
  • branches/coll_rect.merge/src/world_entities/npcs/generic_npc.cc

    r9869 r10010  
    9696
    9797  // collision reaction registration
    98   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID());
     98  this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID());
    9999}
    100100
  • branches/coll_rect.merge/src/world_entities/weapons/aiming_system.cc

    r9869 r10010  
    6161
    6262  // registering default reactions:
    63   this->unsubscribeReaction(CREngine::CR_OBJECT_DAMAGE);
    64   this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, WorldEntity::staticClassID());
     63  this->unsubscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE);
     64  this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, WorldEntity::staticClassID());
    6565
    6666  this->range = 1000.0f;
  • branches/coll_rect.merge/src/world_entities/world_entity.cc

    r9869 r10010  
    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);
     
    7777  this->lastObjectListNumber = OM_INIT;
    7878
    79   // reset all collision handles to NULL == unsubscribed state
    80   for(int i = 0; i < CREngine::CR_NUMBER; ++i)
    81     this->collisionHandles[i] = NULL;
    82   this->bReactive = false;
    83   this->bOnGround = false;
     79  this->_bOnGround = false;
    8480
    8581  // registering default reactions:
    86   this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, /* WorldEntity::staticClassID(), */ Projectile::staticClassID());
     82  this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Projectile::staticClassID());
    8783
    8884  this->toList(OM_NULL);
    8985
    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 ) );
     86  this->registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) );
     87  this->modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) );
     88  this->scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) );
     89  this->list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) );
     90
     91  this->health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) );
     92  this->healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) );
    9793}
    9894
     
    115111    delete this->healthWidget;
    116112
    117   this->unsubscribeReaction();
     113  this->unsubscribeReactions();
    118114}
    119115
     
    302298 *  @param target1 a filter target (classID)
    303299 */
    304 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1)
    305 {
    306   this->subscribeReaction(type);
    307 
    308   // add the target filter
    309   this->collisionHandles[type]->addTarget(target1);
     300void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1)
     301{
     302  this->_collisionFilter.subscribeReaction(type, target1);
    310303}
    311304
     
    316309 *  @param target1 a filter target (classID)
    317310 */
    318 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2)
    319 {
    320   this->subscribeReaction(type);
    321 
    322   // add the target filter
    323   this->collisionHandles[type]->addTarget(target1);
    324   this->collisionHandles[type]->addTarget(target2);
     311void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2)
     312{
     313  this->_collisionFilter.subscribeReaction(type, target1, target2);
    325314}
    326315
     
    331320 *  @param target1 a filter target (classID)
    332321 */
    333 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
    334 {
    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  * subscribes this world entity to a collision reaction
    346  *  @param type the type of reaction to subscribe to
    347  *  @param target1 a filter target (classID)
    348  */
    349 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3, const ClassID& target4)
    350 {
    351   this->subscribeReaction(type);
    352 
    353   // add the target filter
    354   this->collisionHandles[type]->addTarget(target1);
    355   this->collisionHandles[type]->addTarget(target2);
    356   this->collisionHandles[type]->addTarget(target3);
    357   this->collisionHandles[type]->addTarget(target4);
    358 }
    359 
    360 
    361 /**
    362  * subscribes this world entity to a collision reaction
    363  *  @param type the type of reaction to subscribe to
    364  *  @param nrOfTargets number of target filters
    365  *  @param ... the targets as classIDs
    366  */
    367 void WorldEntity::subscribeReaction(CREngine::CRType type)
    368 {
    369   if( this->collisionHandles[type] != NULL)
    370   {
    371     PRINTF(2)("Registering for a CollisionReaction already subscribed to! Skipping\n");
    372     return;
    373   }
    374 
    375   this->collisionHandles[type] = CREngine::getInstance()->subscribeReaction(this, type);
    376 
    377   // now there is at least one collision reaction subscribed
    378   this->bReactive = true;
     322void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
     323{
     324  this->_collisionFilter.subscribeReaction(type, target1, target2, target3);
    379325}
    380326
     
    384330 *  @param type the reaction to unsubscribe
    385331 */
    386 void WorldEntity::unsubscribeReaction(CREngine::CRType type)
    387 {
    388   if( this->collisionHandles[type] == NULL)
    389     return;
    390 
    391   CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]);
    392   this->collisionHandles[type] = NULL;
    393 
    394   // check if there is still any handler registered
    395   for(int i = 0; i < CREngine::CR_NUMBER; ++i)
    396   {
    397     if( this->collisionHandles[i] != NULL)
    398     {
    399       this->bReactive = true;
    400       return;
    401     }
    402   }
    403   this->bReactive = false;
     332void WorldEntity::unsubscribeReaction(CoRe::CREngine::ReactionType type)
     333{
     334  this->_collisionFilter.unsubscribeReaction(type);
    404335}
    405336
     
    408339 * unsubscribes all collision reactions
    409340 */
    410 void WorldEntity::unsubscribeReaction()
    411 {
    412   for( int i = 0; i < CREngine::CR_NUMBER; i++)
    413     this->unsubscribeReaction((CREngine::CRType)i);
    414 
    415   // there are no reactions subscribed from now on
    416   this->bReactive = false;
    417 }
    418 
    419 
    420 /**
    421  * registers a new collision event to this world entity
    422  *  @param entityA entity of the collision
    423  *  @param entityB entity of the collision
    424  *  @param bvA colliding bounding volume of entityA
    425  *  @param bvB colliding bounding volume of entityA
    426  */
    427 bool WorldEntity::registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
    428 {
    429   PRINTF(5)("registering collision of type: %s vs %s\n", entityA->getClassCName(), entityB->getClassCName());
    430   // is there any handler listening?
    431   if( !this->bReactive)
    432     return false;
    433 
    434   // get a collision event
    435   CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
    436   assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
    437   c->collide(COLLISION_TYPE_OBB, entityA, entityB, bvA, bvB);
    438 
    439   for( int i = 0; i < CREngine::CR_NUMBER; ++i)
    440     if( this->collisionHandles[i] != NULL)
    441       this->collisionHandles[i]->registerCollisionEvent(c);
    442   return true;
    443 }
    444 
    445 
    446 /**
    447  * registers a new collision event to this woeld entity
    448  *  @param entity the entity that collides
    449  *  @param plane it stands on
    450  *  @param position it collides on the plane
    451  */
    452 bool WorldEntity::registerCollision(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall)
    453 {
    454   // is there any handler listening?
    455   if( !this->bReactive)
    456     return false;
    457 
    458   // get a collision event
    459   CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
    460   assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
    461   c->collide(type, entity, groundEntity, normal, position, bInWall);
    462 
    463   for( int i = 0; i < CREngine::CR_NUMBER; ++i)
    464     if( this->collisionHandles[i] != NULL)
    465       this->collisionHandles[i]->registerCollisionEvent(c);
    466   return true;
     341void WorldEntity::unsubscribeReactions()
     342{
     343  this->_collisionFilter.unsubscribeReactions();
    467344}
    468345
  • branches/coll_rect.merge/src/world_entities/world_entity.h

    r9869 r10010  
    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; };
     28namespace CoRe { class Collision; }
    2729
    2830class BVTree;
     
    3032class AABBTreeNode;
    3133class Model;
    32 class CollisionHandle;
    33 class Collision;
    34 
    35 
    36 //class CharacterAttributes;
    37 
    3834
    3935
     
    4238{
    4339  ObjectListDeclaration(WorldEntity);
     40
    4441public:
    4542  WorldEntity();
     
    5148  void loadModel2(const std::string& fileN, float scal = 1.0f){this->loadModel(fileN,scal,0,4);}
    5249  void setModel(Model* model, unsigned int modelNumber = 0);
    53 Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
     50  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
    5451
    5552  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
     
    7471  virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2);
    7572
    76 
    7773  /** @returns a reference to the obb tree of this worldentity */
    7874  inline BVTree* getOBBTree() const { return this->obbTree; };
     
    8177  inline AABB* getModelAABB() const { return (this->aabbNode)?this->aabbNode->getAABB():NULL;}
    8278
     79  virtual void hit(float damage, WorldEntity* killer);
     80
     81
    8382  /* --- Collision Reaction Block --- */
    84   void subscribeReaction(CREngine::CRType type);
    85   void subscribeReaction(CREngine::CRType type, const ClassID& target1);
    86   void subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2);
    87   void subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3);
    88   void subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3, const ClassID& target4);
    89 
    90   void unsubscribeReaction(CREngine::CRType type);
    91   void unsubscribeReaction();
    92 
    93   bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
    94   bool registerCollision(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall = false);
     83  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1);
     84  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2);
     85  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3);
     86
     87  void unsubscribeReaction(CoRe::CREngine::ReactionType type);
     88  void unsubscribeReactions();
     89
    9590  /** @return true if there is at least on collision reaction subscribed */
    96   inline bool isReactive() const { return this->bReactive; }
    97 
    98   CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; }
     91  inline bool isReactive() const { return this->_collisionFilter.isReactive(); }
     92
     93  /** @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(worldEntity); }
     95  /** @param worldEntity the world entity to be checked @param type special reaction type @returns true if collision reaction reg. */
     96  inline bool isReactive( const WorldEntity& worldEntity, const CoRe::CREngine::ReactionType& type) const
     97  { return this->_collisionFilter(worldEntity, type); }
     98
     99
     100  const CoRe::CollisionFilter& getCollisionFilter(CoRe::CREngine::ReactionType type) const { return this->_collisionFilter; }
    99101
    100102  /** @returns true if this entity is standing on ground (BSP model) */
    101   bool isOnGround() const { return this->bOnGround; }
     103  bool isOnGround() const { return this->_bOnGround; }
    102104  /** @param flag: marks if this entity is standing on ground */
    103   void setOnGround(bool flag) { this->bOnGround = flag; }
    104 
    105   virtual void hit(float damage, WorldEntity* killer);
     105  void setOnGround(bool flag) { this->_bOnGround = flag; }
    106106
    107107  virtual void destroy( WorldEntity* killer );
     
    128128
    129129  void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); }
    130 void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }
     130  void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }
    131131
    132132
    133133  /* --- Character Attribute Block --- */
    134134  /** @returns the scaling of the model */
    135 float getScaling(){return this->scaling;}
     135  float getScaling(){return this->scaling;}
    136136  /** @returns the damage dealt by this world entity */
    137137  float getDamage() const { return this->damage; }
     
    170170  void setHealthMax(float healthMax);
    171171  void createHealthWidget();
    172 
    173   //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
     172    //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
     173
     174
    174175private:
    175176  void updateHealthWidget();
     177
    176178
    177179private:
     
    195197  OM_LIST                 lastObjectListNumber;            //!< the last ObjectList from the ObjectManager this Entity was is in
    196198
    197 
    198 
     199  /* collision reaction stuff */
     200  CoRe::CollisionFilter   _collisionFilter;                //!< filter for collision event filtering (not every entity listens to all collisions)
     201  bool                    _bOnGround;                      //!< flag true if the object is on the ground
     202
     203  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
     204
     205  /* network help structures */
    199206  float                   scaling;                         //!< model's scaling factor
    200207  int                     scaling_handle;                  //!< handle for syncing var
     
    212219  int                     healthMax_handle;
    213220
    214   CollisionHandle*        collisionHandles[CREngine::CR_NUMBER];  //!< the list of the collision reactions
    215   bool                    bReactive;                              //!< true if there is at least one collision reaction subscibed
    216 
    217   PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
    218   bool                    bOnGround;                       //!< true if this entity is standing on the ground
     221
    219222
    220223protected:
Note: See TracChangeset for help on using the changeset viewer.