Changeset 9896 in orxonox.OLD for branches/coll_rect/src/world_entities
- Timestamp:
- Oct 20, 2006, 1:09:03 AM (18 years ago)
- 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 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); … … 78 78 79 79 // reset all collision handles to NULL == unsubscribed state 80 for(int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i)81 this->collisionHandles[i] = NULL;82 80 this->bReactive = false; 83 81 this->bOnGround = false; … … 88 86 this->toList(OM_NULL); 89 87 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 ) ); 97 95 } 98 96 … … 115 113 delete this->healthWidget; 116 114 117 this->unsubscribeReaction ();115 this->unsubscribeReactions(); 118 116 } 119 117 … … 304 302 void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1) 305 303 { 306 this->subscribeReaction(type); 307 308 // add the target filter 309 this->collisionHandles[type]->addTarget(target1); 304 this->collisionFilter.subscribeReaction(type, target1); 310 305 } 311 306 … … 318 313 void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2) 319 314 { 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); 325 316 } 326 317 … … 333 324 void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3) 334 325 { 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); 363 327 } 364 328 … … 370 334 void WorldEntity::unsubscribeReaction(CoRe::CREngine::ReactionType type) 371 335 { 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); 388 337 } 389 338 … … 392 341 * unsubscribes all collision reactions 393 342 */ 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; 343 void WorldEntity::unsubscribeReactions() 344 { 345 this->collisionFilter.unsubscribeReactions(); 451 346 } 452 347 -
branches/coll_rect/src/world_entities/world_entity.h
r9892 r9896 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; }; 27 namespace CoRe { class Collision Handle; class Collision; }28 namespace CoRe { class Collision; } 28 29 29 30 class BVTree; … … 76 77 inline AABB* getModelAABB() const { return (this->aabbNode)?this->aabbNode->getAABB():NULL;} 77 78 79 virtual void hit(float damage, WorldEntity* killer); 80 78 81 79 82 /* --- Collision Reaction Block --- */ 80 void subscribeReaction(CoRe::CREngine::ReactionType type);81 83 void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1); 82 84 void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2); … … 84 86 85 87 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 90 90 /** @return true if there is at least on collision reaction subscribed */ 91 91 inline bool isReactive() const { return this->bReactive; } 92 92 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; } 94 94 95 95 /** @returns true if this entity is standing on ground (BSP model) */ … … 97 97 /** @param flag: marks if this entity is standing on ground */ 98 98 void setOnGround(bool flag) { this->bOnGround = flag; } 99 100 virtual void hit(float damage, WorldEntity* killer);101 99 102 100 virtual void destroy( WorldEntity* killer ); … … 193 191 194 192 /* collision reaction stuff */ 195 CoRe::Collision Handle* collisionHandles[CoRe::CREngine::CR_NUMBER]; //!< the list of the collision reactions196 bool bReactive; 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 197 195 198 196
Note: See TracChangeset
for help on using the changeset viewer.