Changeset 2707 in orxonox.OLD for orxonox/branches/buerli/src/world.cc
- Timestamp:
- Nov 3, 2004, 12:29:03 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/buerli/src/world.cc
r2551 r2707 31 31 This creates a new empty world! 32 32 */ 33 World::World () 34 { 35 entities = new List<WorldEntity>(); 33 World::World (char* name) 34 { 35 this->worldName = name; 36 this->debugWorldNr = -1; 37 this->entities = new List<WorldEntity>(); 38 } 39 40 World::World (int worldID) 41 { 42 this->debugWorldNr = worldID; 43 this->worldName = NULL; 44 this->entities = new List<WorldEntity>(); 36 45 } 37 46 … … 41 50 World::~World () 42 51 { 43 unload (); 44 delete entities; 45 } 52 Orxonox *orx = Orxonox::getInstance(); 53 orx->get_localinput()->unbind (this->localPlayer); 54 delete this->entities; 55 delete this->localCamera; 56 } 57 58 59 /** 60 \brief initialize the world before use. 61 */ 62 Error World::init() 63 { 64 this->bPause = false; 65 } 66 67 Error World::start() 68 { 69 this->mainLoop(); 70 } 71 72 Error World::stop() 73 { 74 this->bQuitCurrentGame = true; 75 this->localCamera->setWorld(NULL); 76 this->~World(); 77 } 78 79 Error World::pause() 80 { 81 this->isPaused = true; 82 } 83 84 Error World::resume() 85 { 86 this->isPaused = false; 87 } 88 89 void World::load() 90 { 91 if(this->debugWorldNr != -1) 92 { 93 switch(this->debugWorldNr) 94 { 95 case DEBUG_WORLD_0: 96 { 97 // create some path nodes 98 this->pathnodes = new Vector[6]; 99 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); 105 106 // create the tracks 107 this->tracklen = 6; 108 this->track = new Track[6]; 109 for( int i = 0; i < this->tracklen; i++) 110 { 111 this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]); 112 } 113 114 // create a player 115 //WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>(); 116 WorldEntity* myPlayer = new Player(); 117 this->spawn(myPlayer); 118 this->localPlayer = myPlayer; 119 120 // bind input 121 Orxonox *orx = Orxonox::getInstance(); 122 orx->get_localinput()->bind (myPlayer); 123 124 // bind camera 125 this->localCamera = new Camera(this); 126 this->getCamera()->bind (myPlayer); 127 break; 128 } 129 case DEBUG_WORLD_1: 130 { 131 // create some path nodes 132 this->pathnodes = new Vector[6]; 133 this->pathnodes[0] = Vector(0, 0, 0); 134 this->pathnodes[1] = Vector(20, 10, 10); 135 this->pathnodes[2] = Vector(40, 0, 10); 136 this->pathnodes[3] = Vector(60, 10, 0); 137 this->pathnodes[4] = Vector(80, 20, 10); 138 this->pathnodes[5] = Vector(30, 50, 0); 139 140 // create the tracks 141 this->tracklen = 6; 142 this->track = new Track[6]; 143 for( int i = 0; i < this->tracklen; i++) 144 { 145 this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]); 146 } 147 148 // create a player 149 //WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>(); 150 WorldEntity* myPlayer = new Player(); 151 this->spawn(myPlayer); 152 this->localPlayer = myPlayer; 153 154 // bind input 155 Orxonox *orx = Orxonox::getInstance(); 156 orx->get_localinput()->bind (myPlayer); 157 158 // bind camera 159 this->localCamera = new Camera(this); 160 this->getCamera()->bind (myPlayer); 161 break; 162 } 163 default: 164 printf("World::load() - no world with ID %i found", this->debugWorldNr ); 165 } 166 } 167 else if(this->worldName != NULL) 168 { 169 170 } 171 } 172 46 173 47 174 /** … … 254 381 } 255 382 256 /** 257 \brief loads a simple level for testing purposes 258 */ 259 void World::load_debug_level() 260 { 261 // create some path nodes 262 pathnodes = new Vector[6]; 263 pathnodes[0] = Vector(0, 0, 0); 264 pathnodes[1] = Vector(-100, 40, 0); 265 pathnodes[2] = Vector(-100, 140, 0); 266 pathnodes[3] = Vector(0, 180, 0); 267 pathnodes[4] = Vector(100, 140, 0); 268 pathnodes[5] = Vector(100, 40, 0); 269 270 // create the tracks 271 tracklen = 6; 272 track = new Track[6]; 273 for( int i = 0; i < tracklen; i++) 274 { 275 track[i] = Track( i, (i+1)%tracklen, &pathnodes[i], &pathnodes[(i+1)%tracklen]); 276 } 277 278 // create a player 279 WorldEntity* myPlayer = (WorldEntity*) spawn<Player>(); 280 281 // bind input 282 Orxonox *orx = Orxonox::getInstance(); 283 orx->get_localinput()->bind (myPlayer); 284 285 // bind camera 286 orx->get_camera()->bind (myPlayer); 287 } 383 288 384 289 385 /** … … 295 391 track[loc->part].map_camera (loc, plc); 296 392 } 393 394 395 void World::setTrackLen(Uint32 len) 396 { 397 this->tracklen = len; 398 } 399 400 int World::getTrackLen() 401 { 402 return this->tracklen; 403 } 404 405 void World::debug() 406 { 407 List<WorldEntity> *l; 408 WorldEntity* entity; 409 410 printf("counting all entities\n"); 411 l = entities->get_next(); 412 while( l != NULL ) 413 { 414 entity = l->get_object(); 415 if( entity->bDraw ) printf("got an entity\n"); 416 l = l->get_next(); 417 } 418 } 419 420 421 void World::mainLoop() 422 { 423 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(); 431 // Network 432 synchronize(); 433 // Process input 434 handle_input(); 435 // Process time 436 time_slice(); 437 // Process collision 438 collision(); 439 // Draw 440 display(); 441 } 442 printf("World|Exiting the main loop\n"); 443 } 444 445 /** 446 \brief synchronize local data with remote data 447 */ 448 void World::synchronize () 449 { 450 // Get remote input 451 // Update synchronizables 452 } 453 454 /** 455 \brief run all input processing 456 */ 457 void World::handle_input () 458 { 459 // localinput 460 Orxonox::getInstance()->get_localinput()->process(); 461 // remoteinput 462 } 463 464 /** 465 \brief advance the timeline 466 */ 467 void World::time_slice () 468 { 469 Uint32 currentFrame = SDL_GetTicks(); 470 if(!this->bPause) 471 { 472 Uint32 dt = currentFrame - this->lastFrame; 473 /* 474 if(dt > 0) 475 { 476 float fps = 1000/dt; 477 printf("fps = %f\n", fps); 478 } 479 else 480 { 481 printf("fps = 1000\n"); 482 } 483 */ 484 this->time_slice (dt); 485 this->update (); 486 this->localCamera->time_slice (dt); 487 } 488 this->lastFrame = currentFrame; 489 } 490 491 /** 492 \brief compute collision detection 493 */ 494 void World::collision () 495 { 496 this->collide (); 497 } 498 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 516 */ 517 void World::display () 518 { 519 // clear buffer 520 glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 521 // set camera 522 this->localCamera->apply (); 523 // draw world 524 this->draw(); 525 // draw HUD 526 // flip buffers 527 SDL_GL_SwapBuffers(); 528 } 529 530 Camera* World::getCamera() 531 { 532 return this->localCamera; 533 } 534 535 536 void World::spawn(WorldEntity* entity) 537 { 538 Location zeroloc; 539 Location* loc = NULL; 540 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 //} 551 entity->init (loc, owner); 552 if (entity->bFree) 553 { 554 this->track[loc->part].map_coords( loc, entity->get_placement()); 555 } 556 entity->post_spawn (); 557 //return entity; 558 }
Note: See TracChangeset
for help on using the changeset viewer.