Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8190 in orxonox.OLD for trunk/src/world_entities


Ignore:
Timestamp:
Jun 7, 2006, 3:00:01 PM (19 years ago)
Author:
patrick
Message:

trunk: merged the cr branche to trunk

Location:
trunk/src/world_entities
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/projectiles/projectile.cc

    r7460 r8190  
    3838  this->target = NULL;
    3939  this->removeNode();
     40
     41  /* character attributes */
     42  this->setHealth(1.0f);
     43  this->setDamage(100.0f); // default damage of a projectile set to 100.0 damage points
    4044
    4145  this->explosionBuffer = NULL;
  • trunk/src/world_entities/world_entity.cc

    r8186 r8190  
    3232#include "camera.h"
    3333
    34 #include "cr_engine.h"
    3534#include "collision_handle.h"
     35#include "collision_event.h"
     36
     37#include <stdarg.h>
    3638
    3739
     
    5961  this->healthMax = 1.0f;
    6062  this->health = 1.0f;
     63  this->damage = 0.0f; // no damage dealt by a default entity
    6164  this->scaling = 1.0f;
    6265
     
    6871  this->objectListIterator = NULL;
    6972
     73  // reset all collision handles to NULL == unsubscribed state
     74  for(int i = 0; i < CREngine::CR_NUMBER; ++i)
     75    this->collisionHandles[i] = NULL;
     76  this->bReactive = false;
     77
     78  // registering default reactions:
     79  this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, CL_WORLD_ENTITY);
     80  this->subscribeReaction(CREngine::CR_PHYSICS_GROUND, CL_TERRAIN);
     81
    7082  this->toList(OM_NULL);
    7183
     
    91103  if (this->healthWidget != NULL)
    92104    delete this->healthWidget;
     105
     106  this->unsubscribeReaction();
    93107}
    94108
     
    249263 * subscribes this world entity to a collision reaction
    250264 *  @param type the type of reaction to subscribe to
     265 *  @param target1 a filter target (classID)
     266 */
     267void WorldEntity::subscribeReaction(CREngine::CRType type, long target1)
     268{
     269  this->subscribeReaction(type);
     270
     271  // add the target filter
     272  this->collisionHandles[type]->addTarget(target1);
     273}
     274
     275
     276/**
     277 * subscribes this world entity to a collision reaction
     278 *  @param type the type of reaction to subscribe to
     279 *  @param target1 a filter target (classID)
     280 */
     281void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2)
     282{
     283  this->subscribeReaction(type);
     284
     285  // add the target filter
     286  this->collisionHandles[type]->addTarget(target1);
     287  this->collisionHandles[type]->addTarget(target2);
     288}
     289
     290
     291/**
     292 * subscribes this world entity to a collision reaction
     293 *  @param type the type of reaction to subscribe to
     294 *  @param target1 a filter target (classID)
     295 */
     296void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2, long target3)
     297{
     298  this->subscribeReaction(type);
     299
     300  // add the target filter
     301  this->collisionHandles[type]->addTarget(target1);
     302  this->collisionHandles[type]->addTarget(target2);
     303  this->collisionHandles[type]->addTarget(target3);
     304}
     305
     306
     307/**
     308 * subscribes this world entity to a collision reaction
     309 *  @param type the type of reaction to subscribe to
     310 *  @param target1 a filter target (classID)
     311 */
     312void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4)
     313{
     314  this->subscribeReaction(type);
     315
     316  // add the target filter
     317  this->collisionHandles[type]->addTarget(target1);
     318  this->collisionHandles[type]->addTarget(target2);
     319  this->collisionHandles[type]->addTarget(target3);
     320  this->collisionHandles[type]->addTarget(target4);
     321}
     322
     323
     324/**
     325 * subscribes this world entity to a collision reaction
     326 *  @param type the type of reaction to subscribe to
    251327 *  @param nrOfTargets number of target filters
    252328 *  @param ... the targets as classIDs
    253329 */
    254 void WorldEntity::subscribeReaction(CREngine::CRType type, int nrOfTargets, ...)
    255 {}
     330void WorldEntity::subscribeReaction(CREngine::CRType type)
     331{
     332  if( this->collisionHandles[type] != NULL)  {
     333    PRINTF(2)("Registering for a CollisionReaction already subscribed to! Skipping\n");
     334    return;
     335  }
     336
     337  this->collisionHandles[type] = CREngine::getInstance()->subscribeReaction(this, type);
     338
     339  // now there is at least one collision reaction subscribed
     340  this->bReactive = true;
     341}
     342
     343
     344/**
     345 * unsubscribes a specific reaction from the worldentity
     346 *  @param type the reaction to unsubscribe
     347 */
     348void WorldEntity::unsubscribeReaction(CREngine::CRType type)
     349{
     350  if( this->collisionHandles[type] == NULL)
     351    return;
     352
     353  CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]);
     354  this->collisionHandles[type] = NULL;
     355
     356  // check if there is still any handler registered
     357  for(int i = 0; i < CREngine::CR_NUMBER; ++i)
     358  {
     359    if( this->collisionHandles[i] != NULL)
     360    {
     361      this->bReactive = true;
     362      return;
     363    }
     364  }
     365  this->bReactive = false;
     366}
     367
     368
     369/**
     370 * unsubscribes all collision reactions
     371 */
     372void WorldEntity::unsubscribeReaction()
     373{
     374  for( int i = 0; i < CREngine::CR_NUMBER; i++)
     375    this->unsubscribeReaction((CREngine::CRType)i);
     376
     377  // there are no reactions subscribed from now on
     378  this->bReactive = false;
     379}
     380
     381
     382/**
     383 * registers a new collision event to this world entity
     384 *  @param entityA entity of the collision
     385 *  @param entityB entity of the collision
     386 *  @param bvA colliding bounding volume of entityA
     387 *  @param bvB colliding bounding volume of entityA
     388 */
     389bool WorldEntity::registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
     390{
     391  // is there any handler listening?
     392  if( !this->bReactive)
     393    return false;
     394
     395  // get a collision event
     396  CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
     397  assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
     398  c->collide(entityA, entityB, bvA, bvB);
     399
     400  for( int i = 0; i < CREngine::CR_NUMBER; ++i)
     401    if( this->collisionHandles[i] != NULL)
     402      this->collisionHandles[i]->registerCollisionEvent(c);
     403}
     404
     405
     406/**
     407 * registers a new collision event to this woeld entity
     408 *  @param entity the entity that collides
     409 *  @param plane it stands on
     410 *  @param position it collides on the plane
     411 */
     412bool WorldEntity::registerCollision(WorldEntity* entity, Plane* plane, Vector position)
     413{
     414  // is there any handler listening?
     415  if( !this->bReactive)
     416    return false;
     417
     418  // get a collision event
     419  CollisionEvent* c = 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(entity, plane, position);
     422
     423  for( int i = 0; i < CREngine::CR_NUMBER; ++i)
     424    if( this->collisionHandles[i] != NULL)
     425      this->collisionHandles[i]->registerCollisionEvent(c);
     426}
    256427
    257428
     
    324495void WorldEntity::collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2)
    325496{
    326  
     497
    327498  // PRINTF(0)("BSP_GROUND: Player collides \n", this->getClassName() );
    328  
     499
    329500  Vector v = this->getAbsDirX();
    330501  v.x *= 10;
     
    332503  v.z *= 10;
    333504  Vector u = this->getAbsDirY();
    334  
     505
    335506  if(feet.x == (u.x+this->getAbsCoor().x) &&  feet.y == u.y +this->getAbsCoor().y && feet.z == this->getAbsCoor().z)
    336507  {
    337    
     508
    338509  this->setAbsCoor(ray_2 - v);
    339510  }
     
    342513    if(ray_1.x == this->getAbsCoor().x + v.x && ray_1.y == this->getAbsCoor().y + v.y + 0.1 && ray_1.z ==this->getAbsCoor().z + v.z)
    343514    {
    344       this->setAbsCoor(feet -u ); 
    345     }
    346      
    347     this->setAbsCoor(ray_2 - v); 
    348    
     515      this->setAbsCoor(feet -u );
     516    }
     517
     518    this->setAbsCoor(ray_2 - v);
     519
    349520  }
    350521}
  • trunk/src/world_entities/world_entity.h

    r8186 r8190  
    1515#include "glincl.h"
    1616#include <vector>
    17 #include <stdarg.h>
     17
     18#include "physics_interface.h"
    1819
    1920
     
    2425
    2526class BVTree;
     27class BoundingVolume;
    2628class Model;
    2729class CollisionHandle;
     30class Collision;
     31class Plane;
    2832
    2933
     
    7276
    7377  /* --- Collision Reaction Block --- */
    74   void subscribeReaction(CREngine::CRType type, int nrOfTargets, ...);
     78  void subscribeReaction(CREngine::CRType type);
     79  void subscribeReaction(CREngine::CRType type, long target1);
     80  void subscribeReaction(CREngine::CRType type, long target1, long target2);
     81  void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3);
     82  void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4);
     83
     84  void unsubscribeReaction(CREngine::CRType type);
     85  void unsubscribeReaction();
     86
     87  bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
     88  bool registerCollision(WorldEntity* entity, Plane* plane, Vector position);
     89  /** @return true if there is at least on collision reaction subscribed */
     90  inline bool isReactive() const { return this->bReactive; }
     91
     92  CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; }
    7593
    7694
     
    98116
    99117  /* --- Character Attribute Block --- */
     118  /** @returns the damage dealt by this world entity */
     119  float getDamage() const { return this->damage; }
     120  /** sets the damage dealt to @param damage damage per second */
     121  void setDamage(float damage) { this->damage = damage; }
    100122  /** @returns the Energy of the entity */
    101123  float getHealth() const { return this->health; };
     
    107129  OrxGui::GLGuiWidget* getHealthWidget();
    108130  bool hasHealthWidget() const { return this->healthWidget; };
    109  
     131
    110132  virtual void varChangeHandler( std::list<int> & id );
     133
     134
     135  //FIXME: the PhysicsInterface and the whole PEngine should probably be reviewed. Here its just used to store the vars
     136  /* --- Physics Interface --- */
     137  inline PhysicsInterface getPhysicsInterface() const { return this->physicsInterface; }
     138  inline float getMass() const { return this->physicsInterface.getMass(); }
     139  inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); }
     140
    111141
    112142  /* --- Misc Stuff Block --- */
     
    128158private:
    129159  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
     160  float                   damage;             //!< the damage dealt to other objects by colliding.
    130161  float                   health;             //!< The Energy of this Entity, if the Entity has any energy at all.
    131162  float                   healthMax;          //!< The Maximal energy this entity can take.
     
    140171  bool                    bVisible;           //!< If it should be visible.
    141172
    142   OM_LIST                           objectListNumber;   //!< The ObjectList from ObjectManager this Entity is in.
    143   ObjectManager::EntityList::iterator objectListIterator; //!< The iterator position of this Entity in the given list of the ObjectManager.
     173  OM_LIST                 objectListNumber;                //!< The ObjectList from ObjectManager this Entity is in.
     174  ObjectManager::EntityList::iterator objectListIterator;  //!< The iterator position of this Entity in the given list of the ObjectManager.
    144175
    145  
    146   //network stuff
    147  
    148   float       scaling;                         //!< model's scaling factor
    149   int         scaling_handle;                  //!< handle for syncing var
    150  
    151   std::string modelFileName;                  //!< model's file name
    152   int         modelFileName_handle;           //!< handle for syncing var
    153   CollisionHandle**       collisionHandles;
    154176
     177
     178  float                   scaling;                         //!< model's scaling factor
     179  int                     scaling_handle;                  //!< handle for syncing var
     180
     181  std::string             modelFileName;                   //!< model's file name
     182  int                     modelFileName_handle;            //!< handle for syncing var
     183
     184  CollisionHandle*        collisionHandles[CREngine::CR_NUMBER];  //!< the list of the collision reactions
     185  bool                    bReactive;                              //!< true if there is at least one collision reaction subscibed
     186
     187  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
    155188
    156189};
Note: See TracChangeset for help on using the changeset viewer.