Changeset 10013 in orxonox.OLD for trunk/src/world_entities
- Timestamp:
- Dec 4, 2006, 6:42:46 PM (18 years ago)
- Location:
- trunk/src/world_entities
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/creatures/fps_player.cc
r9869 r10013 167 167 168 168 //subscribe to collision reaction 169 this->subscribeReaction(C REngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID());169 this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID()); 170 170 171 171 this->initWeapon = false; -
trunk/src/world_entities/npcs/attractor_mine.cc
r9869 r10013 62 62 63 63 this->setDamage(30.0f); 64 this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Playable::staticClassID()); 64 65 65 66 -
trunk/src/world_entities/npcs/generic_npc.cc
r9869 r10013 96 96 97 97 // collision reaction registration 98 this->subscribeReaction(C REngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID());98 this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID()); 99 99 } 100 100 -
trunk/src/world_entities/projectiles/projectile.cc
r9869 r10013 23 23 #include "model.h" 24 24 #include "sound/resource_sound_buffer.h" 25 #include "playable.h" 25 26 26 27 #include "debug.h" … … 43 44 this->setHealth(1.0f); 44 45 this->setDamage(1.0f); // default damage of a projectile set to 100.0 damage points 46 this->subscribeReaction( CoRe::CREngine::CR_PHYSICS_FULL_WALK, Playable::staticClassID()); 45 47 46 48 //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); -
trunk/src/world_entities/space_ships/spacecraft_2d.cc
r9869 r10013 221 221 registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); 222 222 223 223 this->setDamage( 1000.0f); 224 this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, WorldEntity::staticClassID()); 224 225 225 226 } -
trunk/src/world_entities/weapons/aiming_system.cc
r9869 r10013 61 61 62 62 // registering default reactions: 63 this->unsubscribeReaction(C REngine::CR_OBJECT_DAMAGE);64 this->subscribeReaction(C REngine::CR_OBJECT_DAMAGE, WorldEntity::staticClassID());63 this->unsubscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE); 64 this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, WorldEntity::staticClassID()); 65 65 66 66 this->range = 1000.0f; -
trunk/src/world_entities/world_entity.cc
r9869 r10013 35 35 #include "camera.h" 36 36 37 #include "collision_ handle.h"37 #include "collision_filter.h" 38 38 #include "collision_event.h" 39 39 #include "game_rules.h" … … 58 58 */ 59 59 WorldEntity::WorldEntity() 60 : Synchronizeable()60 : Synchronizeable(), _collisionFilter(this) 61 61 { 62 62 this->registerObject(this, WorldEntity::_objectList); … … 77 77 this->lastObjectListNumber = OM_INIT; 78 78 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; 84 80 85 81 // registering default reactions: 86 this->subscribeReaction(C REngine::CR_OBJECT_DAMAGE, /* WorldEntity::staticClassID(), */Projectile::staticClassID());82 this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Projectile::staticClassID()); 87 83 88 84 this->toList(OM_NULL); 89 85 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 ) ); 97 93 } 98 94 … … 115 111 delete this->healthWidget; 116 112 117 this->unsubscribeReaction ();113 this->unsubscribeReactions(); 118 114 } 119 115 … … 302 298 * @param target1 a filter target (classID) 303 299 */ 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); 300 void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1) 301 { 302 this->_collisionFilter.subscribeReaction(type, target1); 310 303 } 311 304 … … 316 309 * @param target1 a filter target (classID) 317 310 */ 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); 311 void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2) 312 { 313 this->_collisionFilter.subscribeReaction(type, target1, target2); 325 314 } 326 315 … … 331 320 * @param target1 a filter target (classID) 332 321 */ 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; 322 void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3) 323 { 324 this->_collisionFilter.subscribeReaction(type, target1, target2, target3); 379 325 } 380 326 … … 384 330 * @param type the reaction to unsubscribe 385 331 */ 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; 332 void WorldEntity::unsubscribeReaction(CoRe::CREngine::ReactionType type) 333 { 334 this->_collisionFilter.unsubscribeReaction(type); 404 335 } 405 336 … … 408 339 * unsubscribes all collision reactions 409 340 */ 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; 341 void WorldEntity::unsubscribeReactions() 342 { 343 this->_collisionFilter.unsubscribeReactions(); 467 344 } 468 345 -
trunk/src/world_entities/world_entity.h
r9869 r10013 12 12 13 13 #include "cr_engine.h" 14 #include "collision_filter.h" 14 15 #include "object_manager.h" 15 16 #include "glincl.h" … … 25 26 namespace OrxSound { class SoundBuffer; class SoundSource; } 26 27 namespace OrxGui { class GLGuiWidget; class GLGuiBar; class GLGuiEnergyWidget; }; 28 namespace CoRe { class Collision; } 27 29 28 30 class BVTree; … … 30 32 class AABBTreeNode; 31 33 class Model; 32 class CollisionHandle;33 class Collision;34 35 36 //class CharacterAttributes;37 38 34 39 35 … … 42 38 { 43 39 ObjectListDeclaration(WorldEntity); 40 44 41 public: 45 42 WorldEntity(); … … 51 48 void loadModel2(const std::string& fileN, float scal = 1.0f){this->loadModel(fileN,scal,0,4);} 52 49 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; }; 54 51 55 52 inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; } … … 74 71 virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2); 75 72 76 77 73 /** @returns a reference to the obb tree of this worldentity */ 78 74 inline BVTree* getOBBTree() const { return this->obbTree; }; … … 81 77 inline AABB* getModelAABB() const { return (this->aabbNode)?this->aabbNode->getAABB():NULL;} 82 78 79 virtual void hit(float damage, WorldEntity* killer); 80 81 83 82 /* --- 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 95 90 /** @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; } 99 101 100 102 /** @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; } 102 104 /** @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; } 106 106 107 107 virtual void destroy( WorldEntity* killer ); … … 128 128 129 129 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); } 131 131 132 132 133 133 /* --- Character Attribute Block --- */ 134 134 /** @returns the scaling of the model */ 135 float getScaling(){return this->scaling;}135 float getScaling(){return this->scaling;} 136 136 /** @returns the damage dealt by this world entity */ 137 137 float getDamage() const { return this->damage; } … … 170 170 void setHealthMax(float healthMax); 171 171 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 174 175 private: 175 176 void updateHealthWidget(); 177 176 178 177 179 private: … … 195 197 OM_LIST lastObjectListNumber; //!< the last ObjectList from the ObjectManager this Entity was is in 196 198 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 */ 199 206 float scaling; //!< model's scaling factor 200 207 int scaling_handle; //!< handle for syncing var … … 212 219 int healthMax_handle; 213 220 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 219 222 220 223 protected:
Note: See TracChangeset
for help on using the changeset viewer.