Changeset 3238 in orxonox.OLD for orxonox/branches/sound/src/world.cc
- Timestamp:
- Dec 20, 2004, 2:42:54 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/sound/src/world.cc
r2644 r3238 22 22 #include "command_node.h" 23 23 #include "camera.h" 24 #include "environment.h" 24 25 25 26 using namespace std; … … 35 36 this->worldName = name; 36 37 this->debugWorldNr = -1; 37 this->entities = new List<WorldEntity>();38 this->entities = new tList<WorldEntity>(); 38 39 } 39 40 … … 42 43 this->debugWorldNr = worldID; 43 44 this->worldName = NULL; 44 this->entities = new List<WorldEntity>();45 this->entities = new tList<WorldEntity>(); 45 46 } 46 47 … … 50 51 World::~World () 51 52 { 52 Orxonox *orx = Orxonox::getInstance(); 53 orx->get_localinput()->unbind (this->localPlayer); 53 printf("World::~World() - deleting current world\n"); 54 CommandNode* cn = Orxonox::getInstance()->getLocalInput(); 55 cn->unbind(this->localPlayer); 56 cn->reset(); 57 this->localCamera->destroy(); 58 59 WorldEntity* entity = entities->enumerate(); 60 while( entity != NULL ) 61 { 62 entity->destroy(); 63 entity = entities->nextElement(); 64 } 65 this->entities->destroy(); 66 54 67 delete this->entities; 55 68 delete this->localCamera; 56 } 57 58 59 /** 60 \brief initialize the world before use. 61 */ 62 Error World::init() 69 /* this->localPlayer hasn't to be deleted explicitly, it is 70 contained in entities*/ 71 } 72 73 74 ErrorMessage World::init() 63 75 { 64 76 this->bPause = false; 65 } 66 67 Error World::start() 68 { 77 CommandNode* cn = Orxonox::getInstance()->getLocalInput(); 78 cn->addToWorld(this); 79 cn->enable(true); 80 } 81 82 ErrorMessage World::start() 83 { 84 printf("World::start() - starting current World: nr %i\n", this->debugWorldNr); 85 this->bQuitOrxonox = false; 86 this->bQuitCurrentGame = false; 69 87 this->mainLoop(); 70 88 } 71 89 72 Error World::stop() 73 { 90 ErrorMessage World::stop() 91 { 92 printf("World::stop() - got stop signal\n"); 74 93 this->bQuitCurrentGame = true; 75 this->localCamera->setWorld(NULL); 76 this->~World(); 77 } 78 79 Error World::pause() 94 } 95 96 ErrorMessage World::pause() 80 97 { 81 98 this->isPaused = true; 82 99 } 83 100 84 Error World::resume()101 ErrorMessage World::resume() 85 102 { 86 103 this->isPaused = false; 87 104 } 88 105 106 void World::destroy() 107 { 108 109 } 110 89 111 void World::load() 90 112 { … … 93 115 switch(this->debugWorldNr) 94 116 { 117 /* 118 this loads the hard-coded debug world. this only for simplicity and will be 119 removed by a reald world-loader, which interprets a world-file. 120 if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and 121 make whatever you want... 122 */ 95 123 case DEBUG_WORLD_0: 96 124 { … … 98 126 this->pathnodes = new Vector[6]; 99 127 this->pathnodes[0] = Vector(0, 0, 0); 100 this->pathnodes[1] = Vector( -100, 40, 0);101 this->pathnodes[2] = Vector(-100, 140, 0);102 this->pathnodes[3] = Vector(0, 180, 0);103 this->pathnodes[4] = Vector(100, 140, 0);104 this->pathnodes[5] = Vector(100, 40, 0);128 this->pathnodes[1] = Vector(1000, 0, 0); 129 // this->pathnodes[2] = Vector(-100, 140, 0); 130 // this->pathnodes[3] = Vector(0, 180, 0); 131 // this->pathnodes[4] = Vector(100, 140, 0); 132 // this->pathnodes[5] = Vector(100, 40, 0); 105 133 106 134 // create the tracks 107 this->tracklen = 6;108 this->track = new Track[ 6];135 this->tracklen = 2; 136 this->track = new Track[2]; 109 137 for( int i = 0; i < this->tracklen; i++) 110 138 { 111 139 this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]); 112 140 } 113 141 // !\todo old track-system has to be removed 142 114 143 // create a player 115 //WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>();116 144 WorldEntity* myPlayer = new Player(); 117 145 this->spawn(myPlayer); … … 120 148 // bind input 121 149 Orxonox *orx = Orxonox::getInstance(); 122 orx->get _localinput()->bind (myPlayer);150 orx->getLocalInput()->bind (myPlayer); 123 151 124 152 // bind camera 125 153 this->localCamera = new Camera(this); 126 154 this->getCamera()->bind (myPlayer); 155 156 Placement* plc = new Placement; 157 plc->r = Vector(100, 10, 10); 158 plc->w = Quaternion(); 159 WorldEntity* env = new Environment(); 160 this->spawn(env, plc); 161 127 162 break; 128 163 } … … 145 180 this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]); 146 181 } 147 182 148 183 // create a player 149 //WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>();150 184 WorldEntity* myPlayer = new Player(); 151 185 this->spawn(myPlayer); 152 this->localPlayer = myPlayer; 186 this->localPlayer = myPlayer; 153 187 154 188 // bind input 155 189 Orxonox *orx = Orxonox::getInstance(); 156 orx->get _localinput()->bind (myPlayer);190 orx->getLocalInput()->bind (myPlayer); 157 191 158 192 // bind camera … … 169 203 170 204 } 205 206 // initialize debug coord system 207 objectList = glGenLists(1); 208 glNewList (objectList, GL_COMPILE); 209 glLoadIdentity(); 210 glColor3f(1.0,0,0); 211 glBegin(GL_QUADS); 212 213 int sizeX = 100; 214 int sizeY = 80; 215 float length = 1000; 216 float width = 200; 217 float widthX = float (length /sizeX); 218 float widthY = float (width /sizeY); 219 220 float height [sizeX][sizeY]; 221 Vector normal_vectors[sizeX][sizeY]; 222 223 224 for ( int i = 0; i<sizeX-1; i+=1) 225 for (int j = 0; j<sizeY-1;j+=1) 226 //height[i][j] = rand()/20046 + (j-25)*(j-25)/30; 227 #ifdef __WIN32__ 228 height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5; 229 #else 230 height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5; 231 #endif 232 233 //Die Hügel ein wenig glätten 234 for (int h=1; h<2;h++) 235 for (int i=1;i<sizeX-2 ;i+=1 ) 236 for(int j=1;j<sizeY-2;j+=1) 237 height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4; 238 239 //Berechnung von normalen Vektoren 240 241 for(int i=1;i<sizeX-2;i+=1) 242 for(int j=1;j<sizeY-2 ;j+=1) 243 { 244 Vector v1 = Vector (widthX*(1), widthY*(j) , height[i][j]); 245 Vector v2 = Vector (widthX*(i-1), widthY*(j) , height[i-1][j]); 246 Vector v3 = Vector (widthX*(i), widthY*(j+1), height[i][j+1]); 247 Vector v4 = Vector (widthX*(i+1), widthY*(j), height[i+1][j]); 248 Vector v5 = Vector (widthX*(i), widthY*(j-1), height[i][j-1]); 249 250 Vector c1 = v2 - v1; 251 Vector c2 = v3 - v1; 252 Vector c3= v4 - v1; 253 Vector c4 = v5 - v1; 254 Vector zero = Vector (0,0,0); 255 normal_vectors[i][j]=c1.cross(v4-v2)+c2.cross(v1-v3)+c3.cross(v2-v4)+c4.cross(v3-v1); 256 normal_vectors[i][j].normalize(); 257 } 258 259 int snowheight=3; 260 for ( int i = 0; i<sizeX; i+=1) 261 for (int j = 0; j<sizeY;j+=1) 262 { 263 Vector v1 = Vector (widthX*(i), widthY*(j) -width/2, height[i][j]-20 ); 264 Vector v2 = Vector (widthX*(i+1), widthY*(j) -width/2, height[i+1][j]-20); 265 Vector v3 = Vector (widthX*(i+1), widthY*(j+1)-width/2, height[i+1][j+1]-20); 266 Vector v4 = Vector (widthX*(i), widthY*(j+1)-width/2, height[i][j+1]-20); 267 float a[3]; 268 if(height[i][j]<snowheight){ 269 a[0]=0; 270 a[1]=1.0-height[i][j]/10-.3; 271 a[2]=0; 272 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 273 } 274 else{ 275 a[0]=1.0; 276 a[1]=1.0; 277 a[2]=1.0; 278 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 279 280 } 281 glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z); 282 glVertex3f(v1.x, v1.y, v1.z); 283 if(height[i+1][j]<snowheight){ 284 a[0]=0; 285 a[1] =1.0-height[i+1][j]/10-.3; 286 a[2]=0; 287 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 288 } 289 else{ 290 a[0]=1.0; 291 a[1]=1.0; 292 a[2]=1.0; 293 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 294 295 } 296 glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z); 297 glVertex3f(v2.x, v2.y, v2.z); 298 if(height[i+1][j+1]<snowheight){ 299 a[0]=0; 300 a[1] =1.0-height[i+1][j+1]/10-.3; 301 a[2]=0; 302 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 303 } 304 else{ 305 a[0]=1.0; 306 a[1]=1.0; 307 a[2]=1.0; 308 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 309 310 311 } 312 glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z); 313 glVertex3f(v3.x, v3.y, v3.z); 314 if(height[i][j+1]<snowheight){ 315 a[0]=0; 316 a[1] =1.0-height[i+1][j+1]/10-.3; 317 a[2]=0; 318 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 319 } 320 else{ 321 a[0]=1.0; 322 a[1]=1.0; 323 a[2]=1.0; 324 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 325 } 326 glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z); 327 glVertex3f(v4.x, v4.y, v4.z); 328 329 } 330 glEnd(); 331 /* 332 glBegin(GL_LINES); 333 for( float x = -128.0; x < 128.0; x += 25.0) 334 { 335 for( float y = -128.0; y < 128.0; y += 25.0) 336 { 337 glColor3f(1,0,0); 338 glVertex3f(x,y,-128.0); 339 glVertex3f(x,y,0.0); 340 glColor3f(0.5,0,0); 341 glVertex3f(x,y,0.0); 342 glVertex3f(x,y,128.0); 343 } 344 } 345 for( float y = -128.0; y < 128.0; y += 25.0) 346 { 347 for( float z = -128.0; z < 128.0; z += 25.0) 348 { 349 glColor3f(0,1,0); 350 glVertex3f(-128.0,y,z); 351 glVertex3f(0.0,y,z); 352 glColor3f(0,0.5,0); 353 glVertex3f(0.0,y,z); 354 glVertex3f(128.0,y,z); 355 } 356 } 357 for( float x = -128.0; x < 128.0; x += 25.0) 358 { 359 for( float z = -128.0; z < 128.0; z += 25.0) 360 { 361 glColor3f(0,0,1); 362 glVertex3f(x,-128.0,z); 363 glVertex3f(x,0.0,z); 364 glColor3f(0,0,0.5); 365 glVertex3f(x,0.0,z); 366 glVertex3f(x,128.0,z); 367 } 368 369 } 370 */ 371 //draw track 372 glBegin(GL_LINES); 373 glColor3f(0,1,1); 374 for( int i = 0; i < tracklen; i++) 375 { 376 glVertex3f(pathnodes[i].x,pathnodes[i].y,pathnodes[i].z); 377 glVertex3f(pathnodes[(i+1)%tracklen].x,pathnodes[(i+1)%tracklen].y,pathnodes[(i+1)%tracklen].z); 378 } 379 glEnd(); 380 glEndList(); 171 381 } 172 382 … … 181 391 void World::collide () 182 392 { 183 List<WorldEntity> *a, *b; 393 /* 394 List *a, *b; 184 395 WorldEntity *aobj, *bobj; 185 186 a = entities ->get_next();396 397 a = entities; 187 398 188 399 while( a != NULL) 189 400 { 190 aobj = a-> get_object();401 aobj = a->nextElement(); 191 402 if( aobj->bCollide && aobj->collisioncluster != NULL) 192 403 { 193 b = a-> get_next();404 b = a->nextElement(); 194 405 while( b != NULL ) 195 406 { 196 bobj = b-> get_object();407 bobj = b->nextElement(); 197 408 if( bobj->bCollide && bobj->collisioncluster != NULL ) 198 409 { … … 206 417 } 207 418 } 208 b = b-> get_next();419 b = b->nextElement(); 209 420 } 210 421 } 211 a = a->get_next(); 212 } 422 a = a->enumerate(); 423 } 424 */ 213 425 } 214 426 … … 221 433 222 434 // draw entities 223 List<WorldEntity> *l;224 435 WorldEntity* entity; 225 436 226 l = entities->get_next();227 while( l!= NULL )437 entity = this->entities->enumerate(); 438 while( entity != NULL ) 228 439 { 229 entity = l->get_object();230 440 if( entity->bDraw ) entity->draw(); 231 l = l->get_next();441 entity = this->entities->nextElement(); 232 442 } 233 443 234 444 235 445 // draw debug coord system 236 glLoadIdentity(); 237 238 239 glBegin(GL_LINES); 240 241 for( float x = -128.0; x < 128.0; x += 25.0) 242 { 243 for( float y = -128.0; y < 128.0; y += 25.0) 244 { 245 glColor3f(1,0,0); 246 glVertex3f(x,y,-128.0); 247 glVertex3f(x,y,0.0); 248 glColor3f(0.5,0,0); 249 glVertex3f(x,y,0.0); 250 glVertex3f(x,y,128.0); 251 } 252 } 253 for( float y = -128.0; y < 128.0; y += 25.0) 254 { 255 for( float z = -128.0; z < 128.0; z += 25.0) 256 { 257 glColor3f(0,1,0); 258 glVertex3f(-128.0,y,z); 259 glVertex3f(0.0,y,z); 260 glColor3f(0,0.5,0); 261 glVertex3f(0.0,y,z); 262 glVertex3f(128.0,y,z); 263 } 264 } 265 for( float x = -128.0; x < 128.0; x += 25.0) 266 { 267 for( float z = -128.0; z < 128.0; z += 25.0) 268 { 269 glColor3f(0,0,1); 270 glVertex3f(x,-128.0,z); 271 glVertex3f(x,0.0,z); 272 glColor3f(0,0,0.5); 273 glVertex3f(x,0.0,z); 274 glVertex3f(x,128.0,z); 275 } 276 277 } 278 279 //draw track 280 glColor3f(0,1,1); 281 for( int i = 0; i < tracklen; i++) 282 { 283 glVertex3f(pathnodes[i].x,pathnodes[i].y,pathnodes[i].z); 284 glVertex3f(pathnodes[(i+1)%tracklen].x,pathnodes[(i+1)%tracklen].y,pathnodes[(i+1)%tracklen].z); 285 } 286 glEnd(); 446 glCallList (objectList); 447 448 287 449 } 288 450 … … 297 459 void World::update () 298 460 { 299 List<WorldEntity> *l;461 //List<WorldEntity> *l; 300 462 WorldEntity* entity; 301 463 Location* loc; … … 303 465 Uint32 t; 304 466 305 l = entities->get_next(); 306 while( l != NULL ) 467 // l = entities->enumerate(); 468 entity = this->entities->enumerate(); 469 while( entity != NULL ) 307 470 { 308 entity = l->get_object(); 471 309 472 310 473 if( !entity->isFree() ) 311 474 { 312 loc = entity->get _location();313 plc = entity->get _placement();475 loc = entity->getLocation(); 476 plc = entity->getPlacement(); 314 477 t = loc->part; 315 478 … … 318 481 { 319 482 printf("An entity is out of the game area\n"); 320 entity->left _world ();483 entity->leftWorld (); 321 484 } 322 485 else 323 486 { 324 while( track[t].map _coords( loc, plc) )487 while( track[t].mapCoords( loc, plc) ) 325 488 { 326 track[t].post _leave (entity);489 track[t].postLeave (entity); 327 490 if( loc->part >= tracklen ) 328 491 { 329 492 printf("An entity has left the game area\n"); 330 entity->left _world ();493 entity->leftWorld (); 331 494 break; 332 495 } 333 track[loc->part].post _enter (entity);496 track[loc->part].postEnter (entity); 334 497 } 335 498 } … … 337 500 else 338 501 { 339 /* TO DO: implement check whether this particular free entity502 /* \todo: implement check whether this particular free entity 340 503 is out of the game area 341 TO DO: call function to notify the entity that it left504 \todo: call function to notify the entity that it left 342 505 the game area 343 506 */ 344 507 } 345 508 346 l = l->get_next();509 entity = entities->nextElement(); 347 510 } 348 511 … … 353 516 \param deltaT: the time passed since the last frame in milliseconds 354 517 */ 355 void World::time _slice (Uint32 deltaT)356 { 357 List<WorldEntity> *l;518 void World::timeSlice (Uint32 deltaT) 519 { 520 //List<WorldEntity> *l; 358 521 WorldEntity* entity; 359 float seconds = deltaT; 360 361 seconds /= 1000; 362 363 l = entities->get_next(); 364 while( l != NULL) 522 float seconds = deltaT / 1000.0; 523 524 entity = entities->enumerate(); 525 while( entity != NULL) 365 526 { 366 entity = l->get_object();367 527 entity->tick (seconds); 368 l = l->get_next();369 } 370 371 for( int i = 0; i < tracklen; i++) track[i].tick (seconds);528 entity = entities->nextElement(); 529 } 530 531 //for( int i = 0; i < tracklen; i++) track[i].tick (seconds); 372 532 } 373 533 … … 387 547 Camera Placement 388 548 */ 389 void World::calc _camera_pos (Location* loc, Placement* plc)390 { 391 track[loc->part].map _camera (loc, plc);549 void World::calcCameraPos (Location* loc, Placement* plc) 550 { 551 track[loc->part].mapCamera (loc, plc); 392 552 } 393 553 … … 403 563 } 404 564 565 566 567 /** 568 \brief function to put your own debug stuff into it. it can display informations about 569 the current class/procedure 570 */ 405 571 void World::debug() 406 572 { 407 List<WorldEntity> *l;573 //List<WorldEntity> *l; 408 574 WorldEntity* entity; 409 575 410 576 printf("counting all entities\n"); 411 l = entities->get_next(); 412 while( l != NULL ) 577 printf("World::debug() - enumerate()\n"); 578 entity = entities->enumerate(); 579 while( entity != NULL ) 413 580 { 414 entity = l->get_object();415 581 if( entity->bDraw ) printf("got an entity\n"); 416 l = l->get_next(); 417 } 418 } 419 420 582 entity = entities->nextElement(); 583 } 584 } 585 586 587 /* 588 \brief main loop of the world: executing all world relevant function 589 590 in this loop we synchronize (if networked), handle input events, give the heart-beat to 591 all other member-entities of the world (tick to player, enemies etc.), checking for 592 collisions drawing everything to the screen. 593 */ 421 594 void World::mainLoop() 422 595 { 423 596 this->lastFrame = SDL_GetTicks(); 424 this->bQuitOrxonox = false; 425 this->bQuitCurrentGame = false; 426 printf("World|Entering main loop\n"); 427 while(!this->bQuitOrxonox && !this->bQuitCurrentGame) /* pause pause pause ?!?!?*/ 428 { 429 //debug routine 430 //debug(); 597 printf("World::mainLoop() - Entering main loop\n"); 598 while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */ 599 { 431 600 // Network 432 601 synchronize(); 433 602 // Process input 434 handle_input(); 603 handleInput(); 604 if( this->bQuitCurrentGame || this->bQuitOrxonox) 605 { 606 printf("World::mainLoop() - leaving loop earlier...\n"); 607 break; 608 } 435 609 // Process time 436 time _slice();610 timeSlice(); 437 611 // Process collision 438 612 collision(); 439 613 // Draw 440 614 display(); 441 } 442 printf("World|Exiting the main loop\n"); 615 616 for(int i = 0; i < 10000000; i++) {} 617 } 618 printf("World::mainLoop() - Exiting the main loop\n"); 443 619 } 444 620 … … 454 630 /** 455 631 \brief run all input processing 456 */ 457 void World::handle_input () 632 633 the command node is the central input event dispatcher. the node uses the even-queue from 634 sdl and has its own event-passing-queue. 635 */ 636 void World::handleInput () 458 637 { 459 638 // localinput 460 Orxonox::getInstance()->get_localinput()->process(); 639 CommandNode* cn = Orxonox::getInstance()->getLocalInput(); 640 cn->process(); 461 641 // remoteinput 462 642 } … … 464 644 /** 465 645 \brief advance the timeline 466 */ 467 void World::time_slice () 646 647 this calculates the time used to process one frame (with all input handling, drawing, etc) 648 the time is mesured in ms and passed to all world-entities and other classes that need 649 a heart-beat. 650 */ 651 void World::timeSlice () 468 652 { 469 653 Uint32 currentFrame = SDL_GetTicks(); … … 471 655 { 472 656 Uint32 dt = currentFrame - this->lastFrame; 473 /*657 474 658 if(dt > 0) 475 659 { … … 479 663 else 480 664 { 481 printf("fps = 1000\n"); 482 } 483 */ 484 this->time_slice (dt); 665 /* the frame-rate is limited to 100 frames per second, all other things are for 666 nothing. 667 */ 668 printf("fps = 1000 - frame rate is adjusted\n"); 669 SDL_Delay(10); 670 dt = 10; 671 } 672 this->timeSlice (dt); 485 673 this->update (); 486 this->localCamera->time _slice(dt);674 this->localCamera->timeSlice(dt); 487 675 } 488 676 this->lastFrame = currentFrame; 489 677 } 490 678 679 491 680 /** 492 681 \brief compute collision detection … … 497 686 } 498 687 499 /** 500 \brief handle keyboard commands that are not meant for WorldEntities 501 \param cmd: the command to handle 502 \return true if the command was handled by the system or false if it may be passed to the WorldEntities 503 */ 504 bool World::system_command (Command* cmd) 505 { 506 if( !strcmp( cmd->cmd, "quit")) 507 { 508 if( !cmd->bUp) this->bQuitOrxonox = true; 509 return true; 510 } 511 return false; 512 } 513 514 /** 515 \brief render the current frame 688 689 /** 690 \brief render the current frame 691 692 clear all buffers and draw the world 516 693 */ 517 694 void World::display () … … 528 705 } 529 706 707 /** 708 \brief give back active camera 709 710 this passes back the actualy active camera 711 \todo ability to define more than one camera or camera-places 712 */ 530 713 Camera* World::getCamera() 531 714 { … … 534 717 535 718 719 /** 720 \brief add and spawn a new entity to this world 721 \param entity to be added 722 */ 536 723 void World::spawn(WorldEntity* entity) 537 724 { … … 539 726 Location* loc = NULL; 540 727 WorldEntity* owner; 541 //T* entity = new T(); 542 entities->add (entity, LIST_ADD_NEXT); 543 //if( loc == NULL) 544 //{ 545 zeroloc.dist = 0; 546 zeroloc.part = 0; 547 zeroloc.pos = Vector(); 548 zeroloc.rot = Quaternion(); 549 loc = &zeroloc; 550 //} 728 729 entities->add (entity); 730 zeroloc.dist = 0; 731 zeroloc.part = 0; 732 zeroloc.pos = Vector(); 733 zeroloc.rot = Quaternion(); 734 loc = &zeroloc; 551 735 entity->init (loc, owner); 552 736 if (entity->bFree) 553 737 { 554 this->track[loc->part].map_coords( loc, entity->get_placement()); 555 } 556 entity->post_spawn (); 738 this->track[loc->part].mapCoords( loc, entity->getPlacement()); 739 } 740 entity->postSpawn (); 741 } 742 743 744 /** 745 \brief add and spawn a new entity to this world 746 \param entity to be added 747 \param location where to add 748 */ 749 void World::spawn(WorldEntity* entity, Location* loc) 750 { 751 Location zeroLoc; 752 WorldEntity* owner; 753 this->entities->add (entity); 754 if( loc == NULL) 755 { 756 zeroLoc.dist = 0; 757 zeroLoc.part = 0; 758 zeroLoc.pos = Vector(); 759 zeroLoc.rot = Quaternion(); 760 loc = &zeroLoc; 761 } 762 entity->init (loc, owner); 763 if (entity->bFree) 764 { 765 this->track[loc->part].mapCoords( loc, entity->getPlacement()); 766 } 767 entity->postSpawn (); 557 768 //return entity; 558 769 } 770 771 772 /** 773 \brief add and spawn a new entity to this world 774 \param entity to be added 775 \param place where to be added 776 */ 777 void World::spawn(WorldEntity* entity, Placement* plc) 778 { 779 Placement zeroPlc; 780 WorldEntity* owner; 781 if( plc == NULL) 782 { 783 zeroPlc.r = Vector(); 784 zeroPlc.w = Quaternion(); 785 plc = &zeroPlc; 786 } 787 this->entities->add (entity); 788 entity->init (plc, owner); 789 entity->postSpawn (); 790 //return entity; 791 } 792 793 794 /* 795 \brief commands that the world must catch 796 \returns false if not used by the world 797 */ 798 bool World::command(Command* cmd) 799 { 800 return false; 801 }
Note: See TracChangeset
for help on using the changeset viewer.