Changeset 3746 in orxonox.OLD for orxonox/branches/levelloader/src/story_entities/world.cc
- Timestamp:
- Apr 7, 2005, 3:54:49 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/levelloader/src/story_entities/world.cc
r3606 r3746 18 18 19 19 #include "world.h" 20 #include "world_entity.h" 21 #include "track_manager.h" 22 #include "player.h" 23 #include "command_node.h" 24 #include "camera.h" 25 #include "environment.h" 26 #include "primitive.h" 20 21 #include "orxonox.h" 22 27 23 #include "p_node.h" 28 24 #include "null_parent.h" 29 25 #include "helper_parent.h" 26 #include "track_node.h" 27 #include "world_entity.h" 28 #include "player.h" 29 #include "camera.h" 30 #include "environment.h" 31 #include "skysphere.h" 32 #include "terrain.h" 33 #include "light.h" 34 35 #include "track_manager.h" 36 #include "garbage_collector.h" 37 #include "simple_animation.h" 38 39 #include "command_node.h" 30 40 #include "glmenu_imagescreen.h" 31 #include "skysphere.h"32 #include "light.h"33 41 #include "fontset.h" 42 #include "list.h" 34 43 #include "factory.h" 35 44 #include "game_loader.h" … … 37 46 #include "terrain.h" 38 47 48 49 39 50 using namespace std; 40 51 41 52 CREATE_FACTORY(World); 53 54 WorldInterface* WorldInterface::singletonRef = 0; 55 56 57 /** 58 \brief private constructor because of singleton 59 */ 60 WorldInterface::WorldInterface() 61 { 62 this->worldIsInitialized = false; 63 this->worldReference = NULL; 64 } 65 66 /** 67 \brief public deconstructor 68 */ 69 WorldInterface::~WorldInterface() 70 { 71 this->singletonRef = NULL; 72 this->worldIsInitialized = false; 73 this->worldReference = NULL; 74 } 75 76 /** 77 \brief gets the singleton instance 78 \returns singleton instance 79 */ 80 WorldInterface* WorldInterface::getInstance() 81 { 82 if( singletonRef == NULL) 83 singletonRef = new WorldInterface(); 84 return singletonRef; 85 } 86 87 88 /** 89 \brief initializes the interface 90 \param reference to the world 91 92 if the worldinterface is not initilizes, there wont be any 93 useable interface 94 */ 95 void WorldInterface::init(World* world) 96 { 97 this->worldReference = world; 98 if( world != NULL) 99 { 100 this->worldIsInitialized = true; 101 PRINTF(3)("WorldInterface up and running\n"); 102 } 103 } 104 105 106 /** 107 \brief gets the entity list from the world 108 \return entity list 109 */ 110 tList<WorldEntity>* WorldInterface::getEntityList() 111 { 112 if( this->worldIsInitialized) 113 return this->worldReference->getEntities(); 114 PRINT(1)("Someone tried to use the WorldInterface before it has been initizlized! this can result in SEGFAULTs!\n"); 115 return NULL; 116 } 117 118 42 119 43 120 World::World( TiXmlElement* root) … … 110 187 cn->reset(); 111 188 189 ResourceManager::getInstance()->debug(); 190 ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL); 191 ResourceManager::getInstance()->debug(); 192 193 delete WorldInterface::getInstance(); 194 112 195 delete this->nullParent; 113 196 delete this->entities; … … 116 199 if( this->worldName) delete this->worldName; 117 200 if( this->path) delete this->path; 118 } 119 120 /** 121 \brief initializes a new World 201 202 //delete garbagecollecor 203 //delete animator 204 } 205 206 /** 207 \brief initializes the world. 208 209 set all stuff here that is world generic and does not use to much memory 210 because the real init() function StoryEntity::init() will be called 211 shortly before start of the game. 212 since all worlds are initiated/referenced before they will be started. 213 NO LEVEL LOADING HERE - NEVER! 122 214 */ 123 215 void World::init(char* name, int worldID) … … 128 220 this->debugWorldNr = worldID; 129 221 this->entities = new tList<WorldEntity>(); 130 131 // Enable default GL stuff 132 glEnable(GL_DEPTH_TEST); 133 222 } 223 224 225 /** 226 \brief this is executed before load 227 228 since the load function sometimes needs data, that has been init before 229 the load and after the proceeding storyentity has finished 230 */ 231 ErrorMessage World::preLoad() 232 { 233 /* init the world interface */ 234 WorldInterface* wi = WorldInterface::getInstance(); 235 wi->init(this); 236 this->garbageCollector = GarbageCollector::getInstance(); 237 this->simpleAnimation = SimpleAnimation::getInstance(); 134 238 } 135 239 … … 153 257 // load the campaign document 154 258 if( !XMLDoc->LoadFile()) 259 this->glmis->step(); 155 260 156 261 { … … 257 362 258 363 // bind camera 259 this->localCamera = new Camera( this);364 this->localCamera = new Camera(); 260 365 this->localCamera->setName ("camera"); 261 this->localCamera->bind (localPlayer);366 //this->localCamera->bind (localPlayer); 262 367 this->localPlayer->addChild (this->localCamera); 263 368 … … 267 372 /*monitor progress*/ 268 373 // this->glmis->step(); 374 375 // LIGHT initialisation 376 lightMan = LightManager::getInstance(); 377 lightMan->setAmbientColor(.1,.1,.1); 378 lightMan->addLight(); 379 // lightMan->setAttenuation(1.0, .01, 0.0); 380 // lightMan->setDiffuseColor(1,1,1); 381 // lightMan->addLight(1); 382 // lightMan->setPosition(20, 10, -20); 383 // lightMan->setDiffuseColor(0,0,0); 384 lightMan->debug(); 385 lightMan->setPosition(-5.0, 10.0, -40.0); 386 269 387 270 388 // Create SkySphere … … 274 392 this->skySphere->setMode(PNODE_MOVEMENT); 275 393 276 /*monitor progress*/ 277 // this->glmis->step(); 278 279 // trackManager->setBindSlave(env); 394 395 // trackManager->setBindSlave(env); 396 PNode* tn = trackManager->getTrackNode(); 397 tn->addChild(this->localPlayer); 398 399 //localCamera->setParent(TrackNode::getInstance()); 400 tn->addChild(this->localCamera); 401 // localCamera->lookAt(tn); 402 this->localPlayer->setMode(PNODE_ALL); 403 //Vector* cameraOffset = new Vector (0, 5, -10); 404 //trackManager->condition(2, LEFTRIGHT, this->localPlayer); 280 405 281 406 // initialize debug coord system … … 290 415 terrain->setRelCoor(new Vector(0,-10,0)); 291 416 this->spawn(terrain); 292 293 } 294 295 /** 296 \brief initializes a new World 417 } 418 419 420 /** 421 \brief initializes a new World shortly before start 422 423 this is the function, that will be loaded shortly before the world is 424 started 297 425 */ 298 426 ErrorMessage World::init() … … 302 430 cn->addToWorld(this); 303 431 cn->enable(true); 304 305 432 PRINTF0("> Done Loading world: '%s'\n", getPath()); 306 433 } … … 363 490 this->glmis = GLMenuImageScreen::getInstance(); 364 491 this->glmis->init(); 365 this->glmis->setMaximum( 10);492 this->glmis->setMaximum(8); 366 493 this->glmis->draw(); 367 494 … … 378 505 PRINTF(3)("World::releaseLoadScreen - start\n"); 379 506 this->glmis->setValue(this->glmis->getMaximum()); 380 SDL_Delay(500);507 //SDL_Delay(500); 381 508 PRINTF(3)("World::releaseLoadScreen - end\n"); 509 } 510 511 512 /** 513 \brief gets the list of entities from the world 514 \returns entity list 515 */ 516 tList<WorldEntity>* World::getEntities() 517 { 518 return this->entities; 519 } 520 521 522 /** 523 \brief this returns the current game time 524 \returns elapsed game time 525 */ 526 double World::getGameTime() 527 { 528 return this->gameTime; 382 529 } 383 530 … … 435 582 glLoadIdentity(); 436 583 437 entity = this->entities->enumerate(); 584 //entity = this->entities->enumerate(); 585 tIterator<WorldEntity>* iterator = this->entities->getIterator(); 586 entity = iterator->nextElement(); 438 587 while( entity != NULL ) 439 588 { 440 589 if( entity->bDraw ) entity->draw(); 441 entity = this->entities->nextElement(); 442 } 590 //entity = this->entities->nextElement(); 591 entity = iterator->nextElement(); 592 } 593 delete iterator; 443 594 444 595 glCallList (objectList); … … 477 628 p4->debug (); 478 629 479 p1->update ( );630 p1->update (0); 480 631 481 632 printf ("World::debug() - update\n"); … … 486 637 487 638 p2->shiftCoor (new Vector(-1, -1, -1)); 488 p1->update ( );639 p1->update (0); 489 640 490 641 p1->debug (); … … 496 647 497 648 498 p1->update ( );649 p1->update (0); 499 650 500 651 p1->debug (); … … 593 744 if(!this->bPause) 594 745 { 595 Uint32dt = currentFrame - this->lastFrame;746 this->dt = currentFrame - this->lastFrame; 596 747 597 if( dt > 0)748 if( this->dt > 0) 598 749 { 599 750 float fps = 1000/dt; … … 607 758 PRINTF(2)("fps = 1000 - frame rate is adjusted\n"); 608 759 SDL_Delay(10); 609 dt = 10;760 this->dt = 10; 610 761 } 611 762 //this->timeSlice (dt); 612 763 613 764 /* function to let all entities tick (iterate through list) */ 614 WorldEntity* entity; 615 float seconds = dt / 1000.0; 616 assert( this->nullParent != NULL); 617 entity = entities->enumerate(); 765 float seconds = this->dt / 1000.0; 766 this->gameTime += seconds; 767 //entity = entities->enumerate(); 768 tIterator<WorldEntity>* iterator = this->entities->getIterator(); 769 WorldEntity* entity = iterator->nextElement(); 618 770 while( entity != NULL) 619 771 { 620 772 entity->tick (seconds); 621 entity = entities->nextElement(); 622 } 773 entity = iterator->nextElement(); 774 } 775 delete iterator; 776 //skySphere->updatePosition(localCamera->absCoordinate); 777 623 778 /* update tick the rest */ 779 this->trackManager->tick(this->dt); 624 780 assert( this->localCamera != NULL); 625 781 assert( this->trackManager != NULL); 626 this->localCamera->tick( dt);627 628 this-> trackManager->tick(dt);782 this->localCamera->tick(this->dt); 783 this->garbageCollector->tick(seconds); 784 this->simpleAnimation->tick(seconds); 629 785 } 630 786 this->lastFrame = currentFrame; … … 640 796 void World::update() 641 797 { 642 this->nullParent->update (); 798 this->garbageCollector->update(); 799 this->nullParent->update (dt); 643 800 } 644 801 … … 728 885 bool World::command(Command* cmd) 729 886 { 887 if( !strcmp( cmd->cmd, "view0")) this->localCamera->setViewMode(VIEW_NORMAL); 888 else if( !strcmp( cmd->cmd, "view1")) this->localCamera->setViewMode(VIEW_BEHIND); 889 else if( !strcmp( cmd->cmd, "view2")) this->localCamera->setViewMode(VIEW_FRONT); 890 else if( !strcmp( cmd->cmd, "view3")) this->localCamera->setViewMode(VIEW_LEFT); 891 else if( !strcmp( cmd->cmd, "view4")) this->localCamera->setViewMode(VIEW_RIGHT); 892 else if( !strcmp( cmd->cmd, "view5")) this->localCamera->setViewMode(VIEW_TOP); 893 730 894 return false; 731 895 }
Note: See TracChangeset
for help on using the changeset viewer.