Changeset 6387 in orxonox.OLD for branches/network/src/story_entities/game_world.cc
- Timestamp:
- Jan 2, 2006, 11:00:14 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/story_entities/game_world.cc
r6386 r6387 91 91 this->music = NULL; 92 92 this->shell = NULL; 93 this->localPlayer = NULL;94 this->localCamera = NULL;95 93 96 94 this->showPNodes = false; … … 98 96 99 97 this->path = NULL; 98 99 this->gameWorldData = new GameWorldData(); 100 100 } 101 101 … … 108 108 GameWorld::~GameWorld () 109 109 { 110 delete this->shell; 111 PRINTF(3)("GameWorld::~GameWorld() - deleting current world\n"); 112 113 delete this->localPlayer; 114 115 // delete all the initialized Engines. 116 FastFactory::flushAll(true); 117 delete LightManager::getInstance(); 118 delete ParticleEngine::getInstance(); 119 delete AnimationPlayer::getInstance(); 120 delete PhysicsEngine::getInstance(); 121 122 // external engines initialized by the orxonox-class get deleted 123 SoundEngine::getInstance()->flushAllBuffers(); 124 SoundEngine::getInstance()->flushAllSources(); 125 126 if (State::getObjectManager() == &this->objectManager) 127 State::setObjectManager(NULL); 128 // erease everything that is left. 129 delete PNode::getNullParent(); 130 131 //secondary cleanup of PNodes; 132 const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE); 133 if (nodeList != NULL) 134 while (!nodeList->empty()) 135 delete nodeList->front(); 136 137 Shader::suspendShader(); 138 139 // unload the resources !! 140 ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL); 110 if( this->gameWorldData) 111 delete this->gameWorldData; 141 112 } 142 113 … … 179 150 PhysicsEngine::getInstance(); 180 151 181 this-> localCamera = new Camera();182 this-> localCamera->setName ("GameWorld-Camera");183 184 State::setCamera(this-> localCamera, this->localCamera->getTarget());152 this->gameWorldData->localCamera = new Camera(); 153 this->gameWorldData->localCamera->setName ("GameWorld-Camera"); 154 155 State::setCamera(this->gameWorldData->localCamera, this->gameWorldData->localCamera->getTarget()); 185 156 186 157 GraphicsEngine::getInstance()->displayFPS(true); … … 240 211 } 241 212 242 //////////////// 243 // LOADSCREEN // 244 //////////////// 245 element = root->FirstChildElement("LoadScreen"); 246 if (element == NULL) 247 { 248 PRINTF(2)("no LoadScreen specified, loading default\n"); 249 250 glmis->setBackgroundImage("pictures/load_screen.jpg"); 251 this->glmis->setMaximum(8); 252 this->glmis->draw(); 253 } 254 else 255 { 256 this->glmis->loadParams(element); 257 this->glmis->draw(); 258 } 259 this->glmis->draw(); 260 261 //////////////////////// 262 // find WorldEntities // 263 //////////////////////// 264 265 element = root->FirstChildElement("WorldEntities"); 266 267 if( element == NULL) 268 { 269 PRINTF(1)("GameWorld is missing 'WorldEntities'\n"); 270 } 271 else 272 { 273 element = element->FirstChildElement(); 274 // load Players/Objects/Whatever 275 PRINTF(4)("Loading WorldEntities\n"); 276 while( element != NULL) 277 { 278 BaseObject* created = Factory::fabricate(element); 279 if( created != NULL ) 280 printf("Created a %s: %s\n", created->getClassName(), created->getName()); 281 282 283 //todo do this more elegant 284 if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) 285 this->sky = dynamic_cast<WorldEntity*>(created); 286 if( element->Value() != NULL && !strcmp( element->Value(), "Terrain")) 287 { 288 terrain = dynamic_cast<Terrain*>(created); 289 CDEngine::getInstance()->setTerrain(terrain); 290 } 291 element = element->NextSiblingElement(); 292 glmis->step(); //! @todo temporary 293 } 294 PRINTF(4)("Done loading WorldEntities\n"); 295 } 213 214 215 this->gameWorldData->loadGUI(root); 216 217 218 this->gameWorldData->loadWorldEntities(root); 296 219 297 220 ////////////////////////////// … … 310 233 311 234 312 // Create a Player 313 this->localPlayer = new Player(); 314 315 Playable* playable; 316 const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); 317 if (playableList != NULL) 318 { 319 playable = dynamic_cast<Playable*>(playableList->front()); 320 this->localPlayer->setControllable(playable); 321 } 235 322 236 323 237 324 238 // //localCamera->setParent(TrackNode::getInstance()); 325 239 // tn->addChild(this->localCamera); 326 localCamera->setClipRegion(1, 10000.0);240 this->gameWorldData->localCamera->setClipRegion(1, 10000.0); 327 241 // localCamera->lookAt(playable); 328 242 // this->localPlayer->setParentMode(PNODE_ALL); 329 if (this-> sky != NULL)330 { 331 this-> localCamera->addChild(sky);332 } 333 SoundEngine::getInstance()->setListener(this-> localCamera);243 if (this->gameWorldData->sky != NULL) 244 { 245 this->gameWorldData->localCamera->addChild(this->gameWorldData->sky); 246 } 247 SoundEngine::getInstance()->setListener(this->gameWorldData->localCamera); 334 248 335 249 /* some static stuff*/ … … 348 262 349 263 /** 264 * unload the data of this GameWorld 265 */ 266 ErrorMessage GameWorld::unloadData() 267 { 268 delete this->shell; 269 PRINTF(3)("GameWorld::~GameWorld() - unloading the current GameWorld\n"); 270 271 // delete all the initialized Engines. 272 FastFactory::flushAll(true); 273 delete LightManager::getInstance(); 274 delete ParticleEngine::getInstance(); 275 delete AnimationPlayer::getInstance(); 276 delete PhysicsEngine::getInstance(); 277 278 // external engines initialized by the orxonox-class get deleted 279 SoundEngine::getInstance()->flushAllBuffers(); 280 SoundEngine::getInstance()->flushAllSources(); 281 282 if (State::getObjectManager() == &this->objectManager) 283 State::setObjectManager(NULL); 284 // erease everything that is left. 285 delete PNode::getNullParent(); 286 287 //secondary cleanup of PNodes; 288 const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE); 289 if (nodeList != NULL) 290 while (!nodeList->empty()) 291 delete nodeList->front(); 292 293 Shader::suspendShader(); 294 295 // unload the resources !! 296 ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL); 297 } 298 299 300 /** 350 301 * starts the GameWorld 351 302 */ 352 ErrorMessageGameWorld::start()303 bool GameWorld::start() 353 304 { 354 305 this->isPaused = false; 355 306 this->isRunning = true; 356 this->mainLoop(); 307 308 this->run(); 357 309 } 358 310 … … 362 314 This happens, when the player decides to end the Level. 363 315 */ 364 ErrorMessageGameWorld::stop()316 bool GameWorld::stop() 365 317 { 366 318 PRINTF(3)("GameWorld::stop() - got stop signal\n"); … … 371 323 * pauses the Game 372 324 */ 373 ErrorMessageGameWorld::pause()325 bool GameWorld::pause() 374 326 { 375 327 this->isPaused = true; … … 379 331 * ends the pause Phase 380 332 */ 381 ErrorMessageGameWorld::resume()333 bool GameWorld::resume() 382 334 { 383 335 this->isPaused = false; … … 391 343 { 392 344 PRINTF(3)("GameWorld::displayLoadScreen - start\n"); 393 this->g lmis = new GLMenuImageScreen();394 this->g lmis->setMaximum(8);345 this->gameWorldData->glmis = new GLMenuImageScreen(); 346 this->gameWorldData->glmis->setMaximum(8); 395 347 PRINTF(3)("GameWorld::displayLoadScreen - end\n"); 396 348 } … … 405 357 { 406 358 PRINTF(3)("GameWorld::releaseLoadScreen - start\n"); 407 this->g lmis->setValue(this->glmis->getMaximum());359 this->gameWorldData->glmis->setValue(this->gameWorldData->glmis->getMaximum()); 408 360 PRINTF(3)("GameWorld::releaseLoadScreen - end\n"); 409 delete this->g lmis;361 delete this->gameWorldData->glmis; 410 362 } 411 363 … … 485 437 486 438 /* update tick the rest */ 487 this-> localCamera->tick(this->dtS);439 this->gameWorldData->localCamera->tick(this->dtS); 488 440 // tick the engines 489 441 AnimationPlayer::getInstance()->tick(this->dtS); … … 541 493 glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 542 494 // set camera 543 this-> localCamera->apply ();495 this->gameWorldData->localCamera->apply (); 544 496 // draw world 545 497 this->draw(); … … 600 552 * collisions drawing everything to the screen. 601 553 */ 602 void GameWorld:: mainLoop()554 void GameWorld::run() 603 555 { 604 556 this->lastFrame = SDL_GetTicks (); … … 659 611 } 660 612 613 614 615 616 617 618 619 GameWorldData::GameWorldData() 620 { 621 this->localPlayer = NULL; 622 this->localCamera = NULL; 623 624 this->glmis = NULL; 625 626 this->localCamera = NULL; 627 this->localPlayer = NULL; 628 this->sky = NULL; 629 this->terrain = NULL; 630 631 } 632 633 634 GameWorldData::~GameWorldData() 635 { 636 if( this->localPlayer) 637 delete this->localPlayer; 638 } 639 640 641 642 ErrorMessage GameWorldData::loadData(TiXmlElement* root) 643 {} 644 645 646 647 648 ErrorMessage GameWorldData::loadGUI(TiXmlElement* root) 649 { 650 //////////////// 651 // LOADSCREEN // 652 //////////////// 653 TiXmlElement* element = root->FirstChildElement("LoadScreen"); 654 if( element == NULL) 655 { 656 PRINTF(2)("no LoadScreen specified, loading default\n"); 657 658 glmis->setBackgroundImage("pictures/load_screen.jpg"); 659 this->glmis->setMaximum(8); 660 this->glmis->draw(); 661 } 662 else 663 { 664 this->glmis->loadParams(element); 665 this->glmis->draw(); 666 } 667 this->glmis->draw(); 668 669 } 670 671 672 ErrorMessage GameWorldData::loadWorldEntities(TiXmlElement* root) 673 { 674 //////////////////////// 675 // find WorldEntities // 676 //////////////////////// 677 678 TiXmlElement* element = root->FirstChildElement("WorldEntities"); 679 680 if( element == NULL) 681 { 682 PRINTF(1)("GameWorld is missing 'WorldEntities'\n"); 683 } 684 else 685 { 686 element = element->FirstChildElement(); 687 // load Players/Objects/Whatever 688 PRINTF(4)("Loading WorldEntities\n"); 689 while( element != NULL) 690 { 691 BaseObject* created = Factory::fabricate(element); 692 if( created != NULL ) 693 printf("Created a %s: %s\n", created->getClassName(), created->getName()); 694 695 696 //todo do this more elegant 697 if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) 698 this->sky = dynamic_cast<WorldEntity*>(created); 699 if( element->Value() != NULL && !strcmp( element->Value(), "Terrain")) 700 { 701 this->terrain = dynamic_cast<Terrain*>(created); 702 CDEngine::getInstance()->setTerrain(terrain); 703 } 704 element = element->NextSiblingElement(); 705 this->glmis->step(); //! @todo temporary 706 } 707 PRINTF(4)("Done loading WorldEntities\n"); 708 } 709 710 // Create a Player 711 this->localPlayer = new Player(); 712 713 Playable* playable; 714 const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); 715 if (playableList != NULL) 716 { 717 playable = dynamic_cast<Playable*>(playableList->front()); 718 this->localPlayer->setControllable(playable); 719 } 720 } 721 722 723 ErrorMessage GameWorldData::loadScene(TiXmlElement* root) 724 {} 725
Note: See TracChangeset
for help on using the changeset viewer.