Changeset 10010 in orxonox.OLD for branches/coll_rect.merge/src/world_entities/world_entity.cc
- Timestamp:
- Dec 4, 2006, 4:39:45 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/coll_rect.merge/src/world_entities/world_entity.cc
r9869 r10010 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
Note: See TracChangeset
for help on using the changeset viewer.