Changeset 6358 in orxonox.OLD for branches/network/src
- Timestamp:
- Dec 30, 2005, 10:49:00 PM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/defs/class_id.h
r6341 r6358 147 147 // StoryEntities (range from 0x00000100 to 0x000001ff) 148 148 CL_CAMPAIGN = 0x00000101, 149 CL_WORLD = 0x00000102, 150 149 CL_GAME_WORLD = 0x00000102, 150 CL_SINGLE_PLAYER_WORLD = 0x00000103, 151 CL_MULTI_PLAYER_WORLD = 0x00000104, 151 152 152 153 // WorldEntities (range from 0x00000200 to 0x000004ff) -
branches/network/src/story_entities/game_world.cc
r6352 r6358 17 17 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD 18 18 19 #include " world.h"19 #include "game_world.h" 20 20 21 21 #include "shell_command.h" … … 70 70 71 71 72 SHELL_COMMAND(speed, World, setSpeed);73 SHELL_COMMAND(togglePNodeVisibility, World, togglePNodeVisibility);74 SHELL_COMMAND(toggleBVVisibility, World, toggleBVVisibility);72 SHELL_COMMAND(speed, GameWorld, setSpeed); 73 SHELL_COMMAND(togglePNodeVisibility, GameWorld, togglePNodeVisibility); 74 SHELL_COMMAND(toggleBVVisibility, GameWorld, toggleBVVisibility); 75 75 76 76 using namespace std; 77 77 78 //! This creates a Factory to fabricate a World 79 CREATE_FACTORY(World, CL_WORLD); 80 81 World::World(const TiXmlElement* root) 78 //! This creates a Factory to fabricate a GameWorld 79 CREATE_FACTORY(GameWorld, CL_GAME_WORLD); 80 81 82 83 GameWorld::GameWorld(const TiXmlElement* root) 82 84 { 83 85 this->constuctorInit("", -1); … … 88 90 89 91 /** 90 * remove the World from memory92 * remove the GameWorld from memory 91 93 * 92 94 * delete everything explicitly, that isn't contained in the parenting tree! 93 95 * things contained in the tree are deleted automaticaly 94 96 */ 95 World::~World ()97 GameWorld::~GameWorld () 96 98 { 97 99 delete this->shell; 98 PRINTF(3)(" World::~World() - deleting current world\n");100 PRINTF(3)("GameWorld::~GameWorld() - deleting current world\n"); 99 101 100 102 delete this->localPlayer; … … 129 131 130 132 /** 131 * initializes the world.133 * initializes the world. 132 134 * @param name the name of the world 133 135 * @param worldID the ID of this world … … 139 141 * NO LEVEL LOADING HERE - NEVER! 140 142 */ 141 void World::constuctorInit(const char* name, int worldID)142 { 143 this->setClassID(CL_ WORLD, "World");143 void GameWorld::constuctorInit(const char* name, int worldID) 144 { 145 this->setClassID(CL_GAME_WORLD, "GameWorld"); 144 146 145 147 this->setName(name); … … 156 158 157 159 /** 158 * loads the parameters of a World from an XML-element160 * loads the parameters of a GameWorld from an XML-element 159 161 * @param root the XML-element to load from 160 162 */ 161 void World::loadParams(const TiXmlElement* root)162 { 163 PRINTF(4)("Creating a World\n");164 165 LoadParam(root, "identifier", this, World, setStoryID)163 void GameWorld::loadParams(const TiXmlElement* root) 164 { 165 PRINTF(4)("Creating a GameWorld\n"); 166 167 LoadParam(root, "identifier", this, GameWorld, setStoryID) 166 168 .describe("Sets the StoryID of this world"); 167 169 168 LoadParam(root, "nextid", this, World, setNextStoryID)170 LoadParam(root, "nextid", this, GameWorld, setNextStoryID) 169 171 .describe("Sets the ID of the next world"); 170 172 171 LoadParam(root, "path", this, World, setPath)172 .describe("The Filename of this World (relative from the data-dir)");173 LoadParam(root, "path", this, GameWorld, setPath) 174 .describe("The Filename of this GameWorld (relative from the data-dir)"); 173 175 } 174 176 … … 179 181 * before the load and after the proceeding storyentity has finished 180 182 */ 181 ErrorMessage World::preLoad()183 ErrorMessage GameWorld::preLoad() 182 184 { 183 185 State::setObjectManager(&this->objectManager); … … 195 197 196 198 this->localCamera = new Camera(); 197 this->localCamera->setName (" World-Camera");199 this->localCamera->setName ("GameWorld-Camera"); 198 200 199 201 State::setCamera(this->localCamera, this->localCamera->getTarget()); … … 205 207 206 208 /** 207 * loads the World by initializing all resources, and set their default values.209 * loads the GameWorld by initializing all resources, and set their default values. 208 210 */ 209 ErrorMessage World::load()211 ErrorMessage GameWorld::load() 210 212 { 211 213 PRINTF(3)("> Loading world: '%s'\n", getPath()); … … 215 217 if( getPath() == NULL) 216 218 { 217 PRINTF(1)(" World has no path specified for loading");218 return (ErrorMessage){213,"Path not specified"," World::load()"};219 PRINTF(1)("GameWorld has no path specified for loading"); 220 return (ErrorMessage){213,"Path not specified","GameWorld::load()"}; 219 221 } 220 222 … … 226 228 PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getPath(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 227 229 delete XMLDoc; 228 return (ErrorMessage){213,"XML File parsing error"," World::load()"};230 return (ErrorMessage){213,"XML File parsing error","GameWorld::load()"}; 229 231 } 230 232 … … 238 240 PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n"); 239 241 delete XMLDoc; 240 return (ErrorMessage){213,"Path not a WorldDataFile"," World::load()"};242 return (ErrorMessage){213,"Path not a WorldDataFile","GameWorld::load()"}; 241 243 } 242 244 … … 246 248 if( string == NULL) 247 249 { 248 PRINTF(2)(" World is missing a proper 'name'\n");250 PRINTF(2)("GameWorld is missing a proper 'name'\n"); 249 251 this->setName("Unknown"); 250 252 } … … 281 283 if( element == NULL) 282 284 { 283 PRINTF(1)(" World is missing 'WorldEntities'\n");285 PRINTF(1)("GameWorld is missing 'WorldEntities'\n"); 284 286 } 285 287 else … … 353 355 SoundEngine::getInstance()->setListener(this->localCamera); 354 356 355 356 357 //////////// 358 // STATIC // 359 //////////// 360 361 362 // TestEntity* testEntity = new TestEntity(); 363 // testEntity->setRelCoor(Vector(570, 10, -15)); 364 // testEntity->setRelDir(Quaternion(M_PI, Vector(0, 1, 0))); 365 // this->spawn(testEntity); 366 367 for(int i = 0; i < 100; i++) 368 { 369 WorldEntity* tmp = new NPCTest1(); 370 char npcChar[10]; 371 sprintf (npcChar, "NPC_%d", i); 372 tmp->setName(npcChar); 373 tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30); 374 this->spawn(tmp); 375 } 357 /* some static stuff*/ 376 358 377 359 this->music = NULL; … … 380 362 } 381 363 382 ErrorMessage World::postLoad()364 ErrorMessage GameWorld::postLoad() 383 365 { 384 366 this->releaseLoadScreen(); … … 387 369 388 370 /** 389 * initializes a new World shortly before start371 * initializes a new GameWorld shortly before start 390 372 * 391 373 * this is the function, that will be loaded shortly before the world is 392 374 * started 393 375 */ 394 ErrorMessage World::preStart()376 ErrorMessage GameWorld::preStart() 395 377 { 396 378 this->bPause = false; … … 403 385 404 386 /** 405 * starts the World387 * starts the GameWorld 406 388 */ 407 ErrorMessage World::start()389 ErrorMessage GameWorld::start() 408 390 { 409 391 this->bQuitWorld = false; … … 416 398 This happens, when the player decides to end the Level. 417 399 */ 418 ErrorMessage World::stop()419 { 420 PRINTF(3)(" World::stop() - got stop signal\n");400 ErrorMessage GameWorld::stop() 401 { 402 PRINTF(3)("GameWorld::stop() - got stop signal\n"); 421 403 this->bQuitWorld= true; 422 404 } … … 425 407 * pauses the Game 426 408 */ 427 ErrorMessage World::pause()409 ErrorMessage GameWorld::pause() 428 410 { 429 411 this->isPaused = true; … … 433 415 * ends the pause Phase 434 416 */ 435 ErrorMessage World::resume()417 ErrorMessage GameWorld::resume() 436 418 { 437 419 this->isPaused = false; … … 439 421 440 422 /** 441 * destroys the World442 */ 443 ErrorMessage World::destroy()423 * destroys the GameWorld 424 */ 425 ErrorMessage GameWorld::destroy() 444 426 { 445 427 … … 449 431 * shows the loading screen 450 432 */ 451 void World::displayLoadScreen ()452 { 453 PRINTF(3)(" World::displayLoadScreen - start\n");433 void GameWorld::displayLoadScreen () 434 { 435 PRINTF(3)("GameWorld::displayLoadScreen - start\n"); 454 436 455 437 //GLMenuImageScreen* … … 457 439 this->glmis->setMaximum(8); 458 440 459 PRINTF(3)(" World::displayLoadScreen - end\n");441 PRINTF(3)("GameWorld::displayLoadScreen - end\n"); 460 442 } 461 443 … … 465 447 * @todo take out the delay 466 448 */ 467 void World::releaseLoadScreen ()468 { 469 PRINTF(3)(" World::releaseLoadScreen - start\n");449 void GameWorld::releaseLoadScreen () 450 { 451 PRINTF(3)("GameWorld::releaseLoadScreen - start\n"); 470 452 this->glmis->setValue(this->glmis->getMaximum()); 471 PRINTF(3)(" World::releaseLoadScreen - end\n");453 PRINTF(3)("GameWorld::releaseLoadScreen - end\n"); 472 454 delete this->glmis; 473 455 } … … 478 460 * @returns elapsed game time 479 461 */ 480 double World::getGameTime()462 double GameWorld::getGameTime() 481 463 { 482 464 return this->gameTime; … … 488 470 * synchronize local data with remote data 489 471 */ 490 void World::synchronize ()472 void GameWorld::synchronize () 491 473 { 492 474 // Get remote input … … 502 484 sdl and has its own event-passing-queue. 503 485 */ 504 void World::handleInput ()486 void GameWorld::handleInput () 505 487 { 506 488 EventHandler::getInstance()->process(); … … 509 491 } 510 492 511 void World::tick(std::list<WorldEntity*> entityList, float dt)493 void GameWorld::tick(std::list<WorldEntity*> entityList, float dt) 512 494 { 513 495 std::list<WorldEntity*>::iterator entity; … … 524 506 a heart-beat. 525 507 */ 526 void World::tick ()508 void GameWorld::tick () 527 509 { 528 510 Uint32 currentFrame = SDL_GetTicks(); … … 588 570 state to the whole system. 589 571 */ 590 void World::update()572 void GameWorld::update() 591 573 { 592 574 GraphicsEngine::getInstance()->update(this->dtS); … … 597 579 598 580 599 void World::collide()581 void GameWorld::collide() 600 582 { 601 583 CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_00), … … 610 592 clear all buffers and draw the world 611 593 */ 612 void World::display ()594 void GameWorld::display () 613 595 { 614 596 // clear buffer … … 630 612 * runs through all entities calling their draw() methods 631 613 */ 632 void World::draw ()614 void GameWorld::draw () 633 615 { 634 616 GraphicsEngine* engine = GraphicsEngine::getInstance(); … … 674 656 * collisions drawing everything to the screen. 675 657 */ 676 void World::mainLoop()658 void GameWorld::mainLoop() 677 659 { 678 660 this->lastFrame = SDL_GetTicks (); 679 PRINTF(3)(" World::mainLoop() - Entering main loop\n");661 PRINTF(3)("GameWorld::mainLoop() - Entering main loop\n"); 680 662 681 663 while(!this->bQuitWorld) /* @todo implement pause */ … … 698 680 } 699 681 700 PRINTF(3)(" World::mainLoop() - Exiting the main loop\n");682 PRINTF(3)("GameWorld::mainLoop() - Exiting the main loop\n"); 701 683 } 702 684 … … 707 689 * @param entity to be added 708 690 */ 709 void World::spawn(WorldEntity* entity)691 void GameWorld::spawn(WorldEntity* entity) 710 692 { 711 693 // this->entities->add (entity); … … 713 695 } 714 696 715 void World::setPath( const char* name)697 void GameWorld::setPath( const char* name) 716 698 { 717 699 if (this->path) … … 729 711 } 730 712 731 const char* World::getPath( void)713 const char* GameWorld::getPath( void) 732 714 { 733 715 return path; -
branches/network/src/story_entities/game_world.h
r6352 r6358 38 38 39 39 /* classes from story-entity */ 40 virtualErrorMessage preLoad();41 virtualErrorMessage load ();42 virtualErrorMessage postLoad();40 ErrorMessage preLoad(); 41 ErrorMessage load (); 42 ErrorMessage postLoad(); 43 43 44 44 virtual ErrorMessage preStart(); … … 92 92 bool showBV; //!< if the Bounding Volumes should be visible. 93 93 94 GLMenuImageScreen* glmis; //!< The Level-Loader Display 95 94 96 /* world timing */ 95 97 Uint32 lastFrame; //!< last time of frame … … 103 105 ObjectManager objectManager; //!< The ObjectManager of this GameWorld. 104 106 107 /* external modules interfaces */ 108 Shell* shell; 109 OggPlayer* music; 105 110 106 111 /* important entities */ -
branches/network/src/story_entities/multi_player_world.cc
r6355 r6358 11 11 ### File Specific: 12 12 main-programmer: Patrick Boenzli 13 co-programmer: Christian Meyer14 co-programmer: Benjamin Grauer15 13 */ 16 14 17 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD 18 16 19 #include " network_world.h"17 #include "multi_player_world.h" 20 18 21 #include "shell_command.h"22 #include "resource_manager.h"23 19 #include "state.h" 20 #include "class_list.h" 24 21 25 #include "p_node.h"26 #include "world_entity.h"27 #include "player.h"28 #include "camera.h"29 #include "environment.h"30 #include "terrain.h"31 32 #include "test_entity.h"33 #include "terrain.h"34 #include "light.h"35 22 #include "load_param.h" 36 #include "shell.h"37 38 23 #include "fast_factory.h" 39 #include "animation_player.h"40 #include "particle_engine.h"41 #include "graphics_engine.h"42 #include "physics_engine.h"43 #include "fields.h"44 45 #include "md2Model.h"46 47 #include "glmenu_imagescreen.h"48 #include "game_loader.h"49 50 #include "animation3d.h"51 52 #include "substring.h"53 54 24 #include "factory.h" 55 25 56 #include "weapons/projectile.h"57 #include "event_handler.h"58 #include "sound_engine.h"59 #include "ogg_player.h"60 61 #include "class_list.h"62 63 #include "cd_engine.h"64 #include "npcs/npc_test1.h"65 #include "shader.h"66 67 #include "playable.h"68 #include "network_manager.h"69 #include "network_game_manager.h"70 #include "playable.h"71 26 72 27 73 SHELL_COMMAND(speed, NetworkWorld, setSpeed); 74 SHELL_COMMAND(togglePNodeVisibility, NetworkWorld, togglePNodeVisibility); 75 SHELL_COMMAND(toggleBVVisibility, NetworkWorld, toggleBVVisibility); 28 29 SHELL_COMMAND(speed, MultiPlayerWorld, setSpeed); 30 SHELL_COMMAND(togglePNodeVisibility, MultiPlayerWorld, togglePNodeVisibility); 31 SHELL_COMMAND(toggleBVVisibility, MultiPlayerWorld, toggleBVVisibility); 76 32 77 33 using namespace std; 78 34 79 //! This creates a Factory to fabricate a NetworkWorld80 CREATE_FACTORY( NetworkWorld, CL_WORLD);35 //! This creates a Factory to fabricate a MultiPlayerWorld 36 CREATE_FACTORY(MultiPlayerWorld, CL_WORLD); 81 37 82 NetworkWorld::NetworkWorld(const TiXmlElement* root)38 MultiPlayerWorld::MultiPlayerWorld(const TiXmlElement* root) 83 39 { 84 40 this->constuctorInit("", -1); … … 89 45 90 46 /** 91 * remove the NetworkWorld from memory47 * remove the MultiPlayerWorld from memory 92 48 * 93 49 * delete everything explicitly, that isn't contained in the parenting tree! 94 50 * things contained in the tree are deleted automaticaly 95 51 */ 96 NetworkWorld::~NetworkWorld ()52 MultiPlayerWorld::~MultiPlayerWorld () 97 53 { 98 54 delete this->shell; 99 PRINTF(3)(" NetworkWorld::~NetworkWorld() - deleting current world\n");55 PRINTF(3)("MultiPlayerWorld::~MultiPlayerWorld() - deleting current world\n"); 100 56 101 57 delete this->localPlayer; … … 140 96 * NO LEVEL LOADING HERE - NEVER! 141 97 */ 142 void NetworkWorld::constuctorInit(const char* name, int worldID)98 void MultiPlayerWorld::constuctorInit(const char* name, int worldID) 143 99 { 144 this->setClassID(CL_WORLD, " NetworkWorld");100 this->setClassID(CL_WORLD, "MultiPlayerWorld"); 145 101 PRINTF(0)("START\n"); 146 102 … … 157 113 } 158 114 115 159 116 /** 160 * loads the parameters of a NetworkWorld from an XML-element117 * loads the parameters of a MultiPlayerWorld from an XML-element 161 118 * @param root the XML-element to load from 162 119 */ 163 void NetworkWorld::loadParams(const TiXmlElement* root)120 void MultiPlayerWorld::loadParams(const TiXmlElement* root) 164 121 { 165 PRINTF(4)("Creating a NetworkWorld\n");122 static_cast<GameWorld*>(this)->loadParams(root); 166 123 167 LoadParam(root, "identifier", this, NetworkWorld, setStoryID)168 .describe("Sets the StoryID of this world"); 124 PRINTF(4)("Creating a MultiPlayerWorld\n"); 125 } 169 126 170 LoadParam(root, "nextid", this, NetworkWorld, setNextStoryID)171 .describe("Sets the ID of the next world");172 127 173 LoadParam(root, "path", this, NetworkWorld, setPath)174 .describe("The Filename of this NetworkWorld (relative from the data-dir)");175 }176 128 177 129 /** … … 180 132 * since the load function sometimes needs data, that has been initialized 181 133 * before the load and after the proceeding storyentity has finished 182 */183 ErrorMessage NetworkWorld::preLoad()134 */ 135 ErrorMessage GameWorld::preLoad() 184 136 { 185 State::setObjectManager(&this->objectManager); 186 this->cycle = 0; 137 static_cast<GameWorld*>(this)->preLoad(); 187 138 188 /* init the world interface */ 189 this->shell = new Shell(); 190 191 LightManager::getInstance(); 192 PNode::getNullParent(); 193 194 AnimationPlayer::getInstance(); // initializes the animationPlayer 195 ParticleEngine::getInstance(); 196 PhysicsEngine::getInstance(); 197 198 this->localCamera = new Camera(); 199 this->localCamera->setName ("NetworkWorld-Camera"); 200 201 State::setCamera(this->localCamera, this->localCamera->getTarget()); 202 203 GraphicsEngine::getInstance()->displayFPS(true); 204 this->displayLoadScreen(); 139 /* the the single player specific stuff */ 205 140 } 206 141 207 142 208 143 /** 209 * loads the NetworkWorld by initializing all resources, and set their default values.144 * loads the GameWorld by initializing all resources, and set their default values. 210 145 */ 211 ErrorMessage NetworkWorld::load()146 ErrorMessage GameWorld::load() 212 147 { 213 PRINTF(3)("> Loading world: '%s'\n", getPath()); 214 TiXmlElement* element; 215 GameLoader* loader = GameLoader::getInstance(); 148 static_cast<GameWorld*>(this)->load(); 216 149 217 if( getPath() == NULL) 218 { 219 PRINTF(1)("World has no path specified for loading"); 220 return (ErrorMessage){213,"Path not specified","World::load()"}; 221 } 150 /* the the single player specific stuff here */ 222 151 223 TiXmlDocument* XMLDoc = new TiXmlDocument( getPath()); 224 // load the campaign document 225 if( !XMLDoc->LoadFile()) 152 /* some static world entities */ 153 for(int i = 0; i < 100; i++) 226 154 { 227 // report an error 228 PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getPath(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 229 delete XMLDoc; 230 return (ErrorMessage){213,"XML File parsing error","NetworkWorld::load()"}; 155 WorldEntity* tmp = new NPCTest1(); 156 char npcChar[10]; 157 sprintf (npcChar, "NPC_%d", i); 158 tmp->setName(npcChar); 159 tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30); 160 this->spawn(tmp); 231 161 } 232 233 // check basic validity234 TiXmlElement* root = XMLDoc->RootElement();235 assert( root != NULL);236 237 if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile"))238 {239 // report an error240 PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");241 delete XMLDoc;242 return (ErrorMessage){213,"Path not a WorldDataFile","NetworkWorld::load()"};243 }244 245 246 // load the parameters247 // name248 const char* string = grabParameter( root, "name");249 if( string == NULL)250 {251 PRINTF(2)("World is missing a proper 'name'\n");252 this->setName("Unknown");253 }254 else255 {256 this->setName(string);257 }258 259 260 ////////////////261 // LOADSCREEN //262 ////////////////263 element = root->FirstChildElement("LoadScreen");264 if (element == NULL)265 {266 PRINTF(2)("no LoadScreen specified, loading default\n");267 268 glmis->setBackgroundImage("pictures/load_screen.jpg");269 this->glmis->setMaximum(8);270 this->glmis->draw();271 }272 else273 {274 this->glmis->loadParams(element);275 this->glmis->draw();276 }277 this->glmis->draw();278 279 280 281 ////////////////////////////282 // Loading Spawning Point //283 ////////////////////////////284 element = root->FirstChildElement("SpawningPoints");285 if( element == NULL)286 {287 PRINTF(1)("NetworkWorld is missing 'SpawningPoints'\n");288 }289 else290 {291 element = element->FirstChildElement();292 // load Players/Objects/Whatever293 PRINTF(4)("Loading Spawning Points\n");294 while( element != NULL)295 {296 BaseObject* created = Factory::fabricate(element);297 if( created != NULL )298 {299 // if(created->isA(CL_SPAWNING_POINT))300 // this->spawn(dynamic_cast<WorldEntity*>(created));301 printf("Created a Spawning Point %s: %s\n", created->getClassName(), created->getName());302 }303 304 305 element = element->NextSiblingElement();306 glmis->step(); //! @todo temporary307 }308 PRINTF(4)("Done loading NetworkWorldEntities\n");309 }310 311 312 ////////////////////////313 // find WorldEntities //314 ////////////////////////315 element = root->FirstChildElement("WorldEntities");316 if( element == NULL)317 {318 PRINTF(1)("NetworkWorld is missing 'WorldEntities'\n");319 }320 else321 {322 element = element->FirstChildElement();323 // load Players/Objects/Whatever324 PRINTF(4)("Loading NetworkWorldEntities\n");325 while( element != NULL)326 {327 if( NetworkManager::getInstance()->isGameServer())328 {329 330 BaseObject* created = NetworkGameManager::getInstance()->createEntity(element);331 if( created != NULL )332 {333 // if(created->isA(CL_WORLD_ENTITY))334 // this->spawn(dynamic_cast<WorldEntity*>(created));335 printf("Created a %s: %s\n", created->getClassName(), created->getName());336 }337 else338 PRINTF(1)("NetworkWorld: could not create this entity\n");339 340 // if we load a 'Player' we use it as localPlayer341 342 343 //todo do this more elegant344 if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))345 sky = dynamic_cast<WorldEntity*>(created);346 if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))347 {348 terrain = dynamic_cast<Terrain*>(created);349 CDEngine::getInstance()->setTerrain(terrain);350 351 }352 353 }354 else if( /* !strcmp( element->Value(), "SkyBox") || */ /* !strcmp( element->Value(), "Terrain") || */ !strcmp( element->Value(), "SpaceShip"))355 {356 BaseObject* created = Factory::fabricate(element);357 if( created != NULL )358 {359 // if(created->isA(CL_WORLD_ENTITY))360 // this->spawn(dynamic_cast<WorldEntity*>(created));361 printf("Created a %s: %s\n", created->getClassName(), created->getName());362 }363 else364 PRINTF(1)("NetworkWorld: could not create this entity\n");365 366 // if we load a 'Player' we use it as localPlayer367 368 369 //todo do this more elegant370 if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))371 sky = dynamic_cast<WorldEntity*>(created);372 if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))373 {374 terrain = dynamic_cast<Terrain*>(created);375 CDEngine::getInstance()->setTerrain(terrain);376 }377 }378 element = element->NextSiblingElement();379 glmis->step(); //! @todo temporary380 PRINTF(4)("Done loading NetworkWorldEntities\n");381 }382 }383 384 385 //////////////////////////////386 // LOADING ADDITIONAL STUFF //387 //////////////////////////////388 389 LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams);390 391 LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);392 // LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams);393 394 // free the XML data395 396 delete XMLDoc;397 /* GENERIC LOADING PROCESS FINISHED */398 399 400 // Create a Player401 this->localPlayer = new Player();402 403 Playable* playable;404 const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);405 if (playableList != NULL)406 {407 playable = dynamic_cast<Playable*>(playableList->front());408 this->localPlayer->setControllable(playable);409 }410 411 412 // //localCamera->setParent(TrackNode::getInstance());413 // tn->addChild(this->localCamera);414 localCamera->setClipRegion(1, 10000.0);415 // localCamera->lookAt(playable);416 // this->localPlayer->setParentMode(PNODE_ALL);417 if (this->sky != NULL)418 {419 this->localCamera->addChild(sky);420 }421 SoundEngine::getInstance()->setListener(this->localCamera);422 423 424 425 ////////////426 // STATIC //427 ////////////428 429 430 // TestEntity* testEntity = new TestEntity();431 // testEntity->setRelCoor(Vector(570, 10, -15));432 // testEntity->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));433 // this->spawn(testEntity);434 435 // for(int i = 0; i < 100; i++)436 // {437 // WorldEntity* tmp = NetworkGameManager::;438 // char npcChar[10];439 // sprintf (npcChar, "NPC_%d", i);440 // tmp->setName(npcChar);441 // tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);442 // this->spawn(tmp);443 // }444 445 this->music = NULL;446 //(OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL);447 //music->playback();448 }449 450 ErrorMessage NetworkWorld::postLoad()451 {452 /*monitor progress*/453 this->glmis->step();454 // stuff beyond this point remains to be loaded properly455 456 // LIGHT initialisation457 LightManager::getInstance()->setAmbientColor(.1,.1,.1);458 // LightManager::getInstance()->addLight();459 LightManager::getInstance()->debug();460 461 this->releaseLoadScreen();462 162 } 463 163 464 164 465 165 /** 466 * initializes a new NetworkWorld shortly before start 467 * 468 * this is the function, that will be loaded shortly before the world is 469 * started 470 */ 471 ErrorMessage NetworkWorld::preStart() 166 * post loads the GameWorld by initializing all resources, and set their default values. 167 */ 168 ErrorMessage GameWorld::postLoad() 472 169 { 473 this->bPause = false;170 static_cast<GameWorld*>(this)->postLoad(); 474 171 475 /* update the object position before game start - so there are no wrong coordinates used in the first processing */ 476 PNode::getNullParent()->updateNode (0.001f); 477 PNode::getNullParent()->updateNode (0.001f); 172 /* the single player specific stuff here */ 478 173 } 479 174 480 481 /**482 * starts the NetworkWorld483 */484 ErrorMessage NetworkWorld::start()485 {486 this->bQuitWorld = false;487 this->mainLoop();488 }489 490 /**491 * stops the world.492 493 This happens, when the player decides to end the Level.494 */495 ErrorMessage NetworkWorld::stop()496 {497 PRINTF(3)("NetworkWorld::stop() - got stop signal\n");498 this->bQuitWorld= true;499 }500 501 /**502 * pauses the Game503 */504 ErrorMessage NetworkWorld::pause()505 {506 this->isPaused = true;507 }508 509 /**510 * ends the pause Phase511 */512 ErrorMessage NetworkWorld::resume()513 {514 this->isPaused = false;515 }516 517 /**518 * destroys the NetworkWorld519 */520 ErrorMessage NetworkWorld::destroy()521 {522 523 }524 525 /**526 * shows the loading screen527 */528 void NetworkWorld::displayLoadScreen ()529 {530 PRINTF(3)("NetworkWorld::displayLoadScreen - start\n");531 532 //GLMenuImageScreen*533 this->glmis = new GLMenuImageScreen();534 this->glmis->setMaximum(8);535 536 PRINTF(3)("NetworkWorld::displayLoadScreen - end\n");537 }538 539 /**540 * @brief removes the loadscreen, and changes over to the game541 *542 * @todo take out the delay543 */544 void NetworkWorld::releaseLoadScreen ()545 {546 PRINTF(3)("NetworkWorld::releaseLoadScreen - start\n");547 this->glmis->setValue(this->glmis->getMaximum());548 PRINTF(3)("NetworkWorld::releaseLoadScreen - end\n");549 delete this->glmis;550 }551 552 553 /**554 * this returns the current game time555 * @returns elapsed game time556 */557 double NetworkWorld::getGameTime()558 {559 return this->gameTime;560 }561 562 /**563 \brief main loop of the world: executing all world relevant function564 in this loop we synchronize (if networked), handle input events, give the heart-beat to565 all other member-entities of the world (tick to player, enemies etc.), checking for566 collisions drawing everything to the screen.567 */568 void NetworkWorld::mainLoop()569 {570 this->lastFrame = SDL_GetTicks ();571 PRINTF(3)("World::mainLoop() - Entering main loop\n");572 573 while(!this->bQuitWorld) /* @todo implement pause */574 {575 ++this->cycle;576 // Network577 this->synchronize ();578 // Process input579 this->handleInput ();580 if( this->bQuitWorld)581 break;582 // Process time583 this->tick ();584 // Process collision585 this->collide ();586 // Update the state587 this->update ();588 // Draw589 this->display ();590 }591 592 PRINTF(3)("NetworkWorld::mainLoop() - Exiting the main loop\n");593 }594 595 596 /**597 * synchronize local data with remote data598 */599 void NetworkWorld::synchronize ()600 {601 // Get remote input602 // Update synchronizables603 NetworkManager::getInstance()->synchronize();604 }605 606 607 /**608 * run all input processing609 610 the command node is the central input event dispatcher. the node uses the even-queue from611 sdl and has its own event-passing-queue.612 */613 void NetworkWorld::handleInput ()614 {615 EventHandler::getInstance()->process();616 617 // remoteinput618 }619 620 void NetworkWorld::tick(std::list<WorldEntity*> entityList, float dt)621 {622 std::list<WorldEntity*>::iterator entity;623 for (entity = entityList.begin(); entity != entityList.end(); entity++)624 (*entity)->tick(dt);625 626 }627 628 /**629 * advance the timeline630 631 this calculates the time used to process one frame (with all input handling, drawing, etc)632 the time is mesured in ms and passed to all world-entities and other classes that need633 a heart-beat.634 */635 void NetworkWorld::tick ()636 {637 Uint32 currentFrame = SDL_GetTicks();638 if(!this->bPause)639 {640 this->dt = currentFrame - this->lastFrame;641 642 if( this->dt > 10)643 {644 float fps = 1000/dt;645 646 // temporary, only for showing how fast the text-engine is647 char tmpChar[20];648 sprintf(tmpChar, "fps: %4.0f", fps);649 }650 else651 {652 /* the frame-rate is limited to 100 frames per second, all other things are for653 nothing.654 */655 PRINTF(3)("fps = 1000 - frame rate is adjusted\n");656 SDL_Delay(10-dt);657 this->dt = 10;658 }659 660 this->dtS = (float)this->dt / 1000.0 * this->speed;661 this->gameTime += this->dtS;662 663 this->tick(this->objectManager.getObjectList(OM_DEAD_TICK), this->dtS);664 this->tick(this->objectManager.getObjectList(OM_COMMON), this->dtS);665 this->tick(this->objectManager.getObjectList(OM_GROUP_00), this->dtS);666 this->tick(this->objectManager.getObjectList(OM_GROUP_01), this->dtS);667 this->tick(this->objectManager.getObjectList(OM_GROUP_01_PROJ), this->dtS);668 669 /* update tick the rest */670 this->localCamera->tick(this->dtS);671 // tick the engines672 AnimationPlayer::getInstance()->tick(this->dtS);673 // if (this->cycle > 5)674 PhysicsEngine::getInstance()->tick(this->dtS);675 676 ParticleEngine::getInstance()->tick(this->dtS);677 678 679 /** actualy the Graphics Engine should tick the world not the other way around...680 but since we like the things not too complicated we got it this way around681 until there is need or time to do it the other way around.682 @todo: GraphicsEngine ticks world: separation of processes and data...683 684 bensch: in my opinion the GraphicsEngine could draw the world, but not tick it,685 beceause graphics have nothing(or at least not much) to do with Motion.686 */687 GraphicsEngine::getInstance()->tick(this->dtS);688 }689 this->lastFrame = currentFrame;690 }691 692 693 /**694 * this function gives the world a consistant state695 696 after ticking (updating the world state) this will give a constistant697 state to the whole system.698 */699 void NetworkWorld::update()700 {701 GraphicsEngine::getInstance()->update(this->dtS);702 PNode::getNullParent()->updateNode (this->dtS);703 SoundEngine::getInstance()->update();704 //music->update();705 }706 707 708 void NetworkWorld::collide()709 {710 CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_00),711 this->objectManager.getObjectList(OM_GROUP_01_PROJ));712 CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_01),713 this->objectManager.getObjectList(OM_COMMON));714 }715 716 /**717 * render the current frame718 719 clear all buffers and draw the world720 */721 void NetworkWorld::display ()722 {723 // clear buffer724 glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);725 // set camera726 this->localCamera->apply ();727 // draw world728 this->draw();729 // draw HUD730 /** @todo draw HUD */731 // flip buffers732 GraphicsEngine::swapBuffers();733 //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();734 //SDL_Flip (screen);735 }736 737 738 /**739 * runs through all entities calling their draw() methods740 */741 void NetworkWorld::draw ()742 {743 GraphicsEngine* engine = GraphicsEngine::getInstance();744 engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));745 engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON));746 engine->draw(State::getObjectManager()->getObjectList(OM_COMMON));747 engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_00));748 engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01));749 engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));750 751 if( unlikely( this->showBV)) // to draw the bounding boxes of the objects at level 2 for debug purp752 {753 CDEngine* engine = CDEngine::getInstance();754 engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));755 engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON));756 engine->drawBV(State::getObjectManager()->getObjectList(OM_COMMON));757 engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_00));758 engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01));759 engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));760 }761 762 // {763 // if( entity->isVisible() ) entity->draw();764 //FIXME765 // entity = iterator->nextElement();766 // }767 768 ParticleEngine::getInstance()->draw();769 770 if (unlikely(this->showPNodes))771 PNode::getNullParent()->debugDraw(0);772 773 engine->draw();774 //TextEngine::getInstance()->draw();775 }776 777 void NetworkWorld::setPath( const char* name)778 {779 if (this->path)780 delete this->path;781 if (ResourceManager::isFile(name))782 {783 this->path = new char[strlen(name)+1];784 strcpy(this->path, name);785 }786 else787 {788 this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1];789 sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name);790 }791 }792 793 const char* NetworkWorld::getPath( void)794 {795 return path;796 } -
branches/network/src/story_entities/single_player_world.cc
r6354 r6358 11 11 ### File Specific: 12 12 main-programmer: Patrick Boenzli 13 co-programmer: Christian Meyer14 co-programmer: Benjamin Grauer15 13 */ 16 14 17 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD 18 16 19 #include " world.h"17 #include "single_player_world.h" 20 18 21 #include "shell_command.h"22 #include "resource_manager.h"23 19 #include "state.h" 20 #include "class_list.h" 24 21 25 #include "p_node.h"26 #include "world_entity.h"27 #include "player.h"28 #include "camera.h"29 #include "environment.h"30 #include "terrain.h"31 32 #include "test_entity.h"33 #include "terrain.h"34 #include "light.h"35 22 #include "load_param.h" 36 #include "shell.h"37 38 23 #include "fast_factory.h" 39 #include "animation_player.h"40 #include "particle_engine.h"41 #include "graphics_engine.h"42 #include "physics_engine.h"43 #include "fields.h"44 45 #include "md2Model.h"46 47 #include "glmenu_imagescreen.h"48 #include "game_loader.h"49 50 #include "animation3d.h"51 52 #include "substring.h"53 54 24 #include "factory.h" 55 25 56 #include "weapons/projectile.h"57 #include "event_handler.h"58 #include "sound_engine.h"59 #include "ogg_player.h"60 26 61 #include "class_list.h"62 63 #include "cd_engine.h"64 #include "npcs/npc_test1.h"65 #include "shader.h"66 67 #include "playable.h"68 #include "network_manager.h"69 #include "playable.h"70 71 72 SHELL_COMMAND(speed, World, setSpeed);73 SHELL_COMMAND(togglePNodeVisibility, World, togglePNodeVisibility);74 SHELL_COMMAND(toggleBVVisibility, World, toggleBVVisibility);75 27 76 28 using namespace std; 77 29 78 //! This creates a Factory to fabricate a World79 CREATE_FACTORY( World, CL_WORLD);30 //! This creates a Factory to fabricate a SinglePlayerWorld 31 CREATE_FACTORY(SinglePlayerSinglePlayerWorld, CL_SINGLE_PLAYER_WORLD); 80 32 81 World::World(const TiXmlElement* root) 33 34 35 SinglePlayerWorld::SinglePlayerWorld(const TiXmlElement* root) 36 : GameWorld(root) 82 37 { 83 this->constuctorInit("", -1);84 this->path = NULL;85 86 38 this->loadParams(root); 87 39 } 88 40 41 89 42 /** 90 * remove the World from memory43 * remove the SinglePlayerWorld from memory 91 44 * 92 45 * delete everything explicitly, that isn't contained in the parenting tree! 93 46 * things contained in the tree are deleted automaticaly 94 47 */ 95 World::~World ()48 SinglePlayerWorld::~SinglePlayerWorld () 96 49 { 97 delete this->shell;98 PRINTF(3)("World::~World() - deleting current world\n"); 50 PRINTF(3)("SinglePlayerWorld::~SinglePlayerWorld() - deleting current world\n"); 51 } 99 52 100 delete this->localPlayer;101 102 // delete all the initialized Engines.103 FastFactory::flushAll(true);104 delete LightManager::getInstance();105 delete ParticleEngine::getInstance();106 delete AnimationPlayer::getInstance();107 delete PhysicsEngine::getInstance();108 109 // external engines initialized by the orxonox-class get deleted110 SoundEngine::getInstance()->flushAllBuffers();111 SoundEngine::getInstance()->flushAllSources();112 113 if (State::getObjectManager() == &this->objectManager)114 State::setObjectManager(NULL);115 // erease everything that is left.116 delete PNode::getNullParent();117 118 //secondary cleanup of PNodes;119 const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);120 if (nodeList != NULL)121 while (!nodeList->empty())122 delete nodeList->front();123 124 Shader::suspendShader();125 126 // unload the resources !!127 ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);128 }129 53 130 54 /** … … 139 63 * NO LEVEL LOADING HERE - NEVER! 140 64 */ 141 void World::constuctorInit(const char* name, int worldID)65 void SinglePlayerWorld::constuctorInit(const char* name, int worldID) 142 66 { 143 this->setClassID(CL_WORLD, "World"); 67 this->setClassID(CL_SINGLE_PLAYER_WORLD, "SinglePlayerSinglePlayerWorld"); 68 this->setName(name); 144 69 145 this->setName(name);146 70 this->gameTime = 0.0f; 147 71 this->setSpeed(1.0); … … 155 79 } 156 80 81 157 82 /** 158 * loads the parameters of a World from an XML-element83 * loads the parameters of a SinglePlayerWorld from an XML-element 159 84 * @param root the XML-element to load from 160 85 */ 161 void World::loadParams(const TiXmlElement* root)86 void SinglePlayerWorld::loadParams(const TiXmlElement* root) 162 87 { 163 PRINTF(4)("Creating a World\n");88 static_cast<GameWorld*>(this)->loadParams(root); 164 89 165 LoadParam(root, "identifier", this, World, setStoryID)166 .describe("Sets the StoryID of this world"); 90 PRINTF(4)("Creating a SinglePlayerWorld\n"); 91 } 167 92 168 LoadParam(root, "nextid", this, World, setNextStoryID)169 .describe("Sets the ID of the next world");170 93 171 LoadParam(root, "path", this, World, setPath)172 .describe("The Filename of this World (relative from the data-dir)");173 }174 94 175 95 /** … … 178 98 * since the load function sometimes needs data, that has been initialized 179 99 * before the load and after the proceeding storyentity has finished 180 */181 ErrorMessage World::preLoad()100 */ 101 ErrorMessage GameWorld::preLoad() 182 102 { 183 State::setObjectManager(&this->objectManager); 184 this->cycle = 0; 103 static_cast<GameWorld*>(this)->preLoad(); 185 104 186 /* init the world interface */ 187 this->shell = new Shell(); 188 189 LightManager::getInstance(); 190 PNode::getNullParent(); 191 192 AnimationPlayer::getInstance(); // initializes the animationPlayer 193 ParticleEngine::getInstance(); 194 PhysicsEngine::getInstance(); 195 196 this->localCamera = new Camera(); 197 this->localCamera->setName ("World-Camera"); 198 199 State::setCamera(this->localCamera, this->localCamera->getTarget()); 200 201 GraphicsEngine::getInstance()->displayFPS(true); 202 this->displayLoadScreen(); 105 /* the the single player specific stuff */ 203 106 } 204 107 205 108 206 109 /** 207 * loads the World by initializing all resources, and set their default values.110 * loads the GameWorld by initializing all resources, and set their default values. 208 111 */ 209 ErrorMessage World::load()112 ErrorMessage GameWorld::load() 210 113 { 211 PRINTF(3)("> Loading world: '%s'\n", getPath()); 212 TiXmlElement* element; 213 GameLoader* loader = GameLoader::getInstance(); 114 static_cast<GameWorld*>(this)->load(); 214 115 215 if( getPath() == NULL) 216 { 217 PRINTF(1)("World has no path specified for loading"); 218 return (ErrorMessage){213,"Path not specified","World::load()"}; 219 } 116 /* the the single player specific stuff here */ 220 117 221 TiXmlDocument* XMLDoc = new TiXmlDocument( getPath()); 222 // load the campaign document 223 if( !XMLDoc->LoadFile()) 224 { 225 // report an error 226 PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getPath(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 227 delete XMLDoc; 228 return (ErrorMessage){213,"XML File parsing error","World::load()"}; 229 } 230 231 // check basic validity 232 TiXmlElement* root = XMLDoc->RootElement(); 233 assert( root != NULL); 234 235 if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile")) 236 { 237 // report an error 238 PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n"); 239 delete XMLDoc; 240 return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"}; 241 } 242 243 // load the parameters 244 // name 245 const char* string = grabParameter( root, "name"); 246 if( string == NULL) 247 { 248 PRINTF(2)("World is missing a proper 'name'\n"); 249 this->setName("Unknown"); 250 } 251 else 252 { 253 this->setName(string); 254 } 255 256 //////////////// 257 // LOADSCREEN // 258 //////////////// 259 element = root->FirstChildElement("LoadScreen"); 260 if (element == NULL) 261 { 262 PRINTF(2)("no LoadScreen specified, loading default\n"); 263 264 glmis->setBackgroundImage("pictures/load_screen.jpg"); 265 this->glmis->setMaximum(8); 266 this->glmis->draw(); 267 } 268 else 269 { 270 this->glmis->loadParams(element); 271 this->glmis->draw(); 272 } 273 this->glmis->draw(); 274 275 //////////////////////// 276 // find WorldEntities // 277 //////////////////////// 278 279 element = root->FirstChildElement("WorldEntities"); 280 281 if( element == NULL) 282 { 283 PRINTF(1)("World is missing 'WorldEntities'\n"); 284 } 285 else 286 { 287 element = element->FirstChildElement(); 288 // load Players/Objects/Whatever 289 PRINTF(4)("Loading WorldEntities\n"); 290 while( element != NULL) 291 { 292 BaseObject* created = Factory::fabricate(element); 293 if( created != NULL ) 294 { 295 if(created->isA(CL_WORLD_ENTITY)) 296 this->spawn(dynamic_cast<WorldEntity*>(created)); 297 printf("Created a %s: %s\n", created->getClassName(), created->getName()); 298 } 299 300 // if we load a 'Player' we use it as localPlayer 301 302 303 //todo do this more elegant 304 if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) 305 this->sky = dynamic_cast<WorldEntity*>(created); 306 if( element->Value() != NULL && !strcmp( element->Value(), "Terrain")) 307 { 308 terrain = dynamic_cast<Terrain*>(created); 309 CDEngine::getInstance()->setTerrain(terrain); 310 } 311 element = element->NextSiblingElement(); 312 glmis->step(); //! @todo temporary 313 } 314 PRINTF(4)("Done loading WorldEntities\n"); 315 } 316 317 ////////////////////////////// 318 // LOADING ADDITIONAL STUFF // 319 ////////////////////////////// 320 321 LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams); 322 323 LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams); 324 // LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams); 325 326 // free the XML data 327 328 delete XMLDoc; 329 /* GENERIC LOADING PROCESS FINISHED */ 330 331 332 // Create a Player 333 this->localPlayer = new Player(); 334 335 Playable* playable; 336 const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); 337 if (playableList != NULL) 338 { 339 playable = dynamic_cast<Playable*>(playableList->front()); 340 this->localPlayer->setControllable(playable); 341 } 342 343 344 // //localCamera->setParent(TrackNode::getInstance()); 345 // tn->addChild(this->localCamera); 346 localCamera->setClipRegion(1, 10000.0); 347 // localCamera->lookAt(playable); 348 // this->localPlayer->setParentMode(PNODE_ALL); 349 if (this->sky != NULL) 350 { 351 this->localCamera->addChild(sky); 352 } 353 SoundEngine::getInstance()->setListener(this->localCamera); 354 355 356 357 //////////// 358 // STATIC // 359 //////////// 360 361 362 // TestEntity* testEntity = new TestEntity(); 363 // testEntity->setRelCoor(Vector(570, 10, -15)); 364 // testEntity->setRelDir(Quaternion(M_PI, Vector(0, 1, 0))); 365 // this->spawn(testEntity); 366 118 /* some static world entities */ 367 119 for(int i = 0; i < 100; i++) 368 120 { … … 370 122 char npcChar[10]; 371 123 sprintf (npcChar, "NPC_%d", i); 372 124 tmp->setName(npcChar); 373 125 tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30); 374 126 this->spawn(tmp); 375 127 } 376 377 this->music = NULL;378 //(OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL);379 //music->playback();380 }381 382 ErrorMessage World::postLoad()383 {384 this->releaseLoadScreen();385 128 } 386 129 387 130 388 131 /** 389 * initializes a new World shortly before start 390 * 391 * this is the function, that will be loaded shortly before the world is 392 * started 393 */ 394 ErrorMessage World::preStart() 132 * post loads the GameWorld by initializing all resources, and set their default values. 133 */ 134 ErrorMessage GameWorld::postLoad() 395 135 { 396 this->bPause = false;136 static_cast<GameWorld*>(this)->postLoad(); 397 137 398 /* update the object position before game start - so there are no wrong coordinates used in the first processing */ 399 PNode::getNullParent()->updateNode (0.001f); 400 PNode::getNullParent()->updateNode (0.001f); 138 /* the single player specific stuff here */ 401 139 } 402 403 404 /**405 * starts the World406 */407 ErrorMessage World::start()408 {409 this->bQuitWorld = false;410 this->mainLoop();411 }412 413 /**414 * stops the world.415 416 This happens, when the player decides to end the Level.417 */418 ErrorMessage World::stop()419 {420 PRINTF(3)("World::stop() - got stop signal\n");421 this->bQuitWorld= true;422 }423 424 /**425 * pauses the Game426 */427 ErrorMessage World::pause()428 {429 this->isPaused = true;430 }431 432 /**433 * ends the pause Phase434 */435 ErrorMessage World::resume()436 {437 this->isPaused = false;438 }439 440 /**441 * destroys the World442 */443 ErrorMessage World::destroy()444 {445 446 }447 448 /**449 * shows the loading screen450 */451 void World::displayLoadScreen ()452 {453 PRINTF(3)("World::displayLoadScreen - start\n");454 455 //GLMenuImageScreen*456 this->glmis = new GLMenuImageScreen();457 this->glmis->setMaximum(8);458 459 PRINTF(3)("World::displayLoadScreen - end\n");460 }461 462 /**463 * @brief removes the loadscreen, and changes over to the game464 *465 * @todo take out the delay466 */467 void World::releaseLoadScreen ()468 {469 PRINTF(3)("World::releaseLoadScreen - start\n");470 this->glmis->setValue(this->glmis->getMaximum());471 PRINTF(3)("World::releaseLoadScreen - end\n");472 delete this->glmis;473 }474 475 476 /**477 * this returns the current game time478 * @returns elapsed game time479 */480 double World::getGameTime()481 {482 return this->gameTime;483 }484 485 486 487 /**488 * synchronize local data with remote data489 */490 void World::synchronize ()491 {492 // Get remote input493 // Update synchronizables494 /* NetworkManager::getInstance()->synchronize();*/495 }496 497 498 /**499 * run all input processing500 501 the command node is the central input event dispatcher. the node uses the even-queue from502 sdl and has its own event-passing-queue.503 */504 void World::handleInput ()505 {506 EventHandler::getInstance()->process();507 508 // remoteinput509 }510 511 void World::tick(std::list<WorldEntity*> entityList, float dt)512 {513 std::list<WorldEntity*>::iterator entity;514 for (entity = entityList.begin(); entity != entityList.end(); entity++)515 (*entity)->tick(dt);516 517 }518 519 /**520 * advance the timeline521 522 this calculates the time used to process one frame (with all input handling, drawing, etc)523 the time is mesured in ms and passed to all world-entities and other classes that need524 a heart-beat.525 */526 void World::tick ()527 {528 Uint32 currentFrame = SDL_GetTicks();529 if(!this->bPause)530 {531 this->dt = currentFrame - this->lastFrame;532 533 if( this->dt > 10)534 {535 float fps = 1000/dt;536 537 // temporary, only for showing how fast the text-engine is538 char tmpChar[20];539 sprintf(tmpChar, "fps: %4.0f", fps);540 }541 else542 {543 /* the frame-rate is limited to 100 frames per second, all other things are for544 nothing.545 */546 PRINTF(3)("fps = 1000 - frame rate is adjusted\n");547 SDL_Delay(10-dt);548 this->dt = 10;549 }550 551 this->dtS = (float)this->dt / 1000.0 * this->speed;552 this->gameTime += this->dtS;553 554 this->tick(this->objectManager.getObjectList(OM_DEAD_TICK), this->dtS);555 this->tick(this->objectManager.getObjectList(OM_COMMON), this->dtS);556 this->tick(this->objectManager.getObjectList(OM_GROUP_00), this->dtS);557 this->tick(this->objectManager.getObjectList(OM_GROUP_01), this->dtS);558 this->tick(this->objectManager.getObjectList(OM_GROUP_01_PROJ), this->dtS);559 560 /* update tick the rest */561 this->localCamera->tick(this->dtS);562 // tick the engines563 AnimationPlayer::getInstance()->tick(this->dtS);564 // if (this->cycle > 5)565 PhysicsEngine::getInstance()->tick(this->dtS);566 567 ParticleEngine::getInstance()->tick(this->dtS);568 569 570 /** actualy the Graphics Engine should tick the world not the other way around...571 but since we like the things not too complicated we got it this way around572 until there is need or time to do it the other way around.573 @todo: GraphicsEngine ticks world: separation of processes and data...574 575 bensch: in my opinion the GraphicsEngine could draw the world, but not tick it,576 beceause graphics have nothing(or at least not much) to do with Motion.577 */578 GraphicsEngine::getInstance()->tick(this->dtS);579 }580 this->lastFrame = currentFrame;581 }582 583 584 /**585 * this function gives the world a consistant state586 587 after ticking (updating the world state) this will give a constistant588 state to the whole system.589 */590 void World::update()591 {592 GraphicsEngine::getInstance()->update(this->dtS);593 PNode::getNullParent()->updateNode (this->dtS);594 SoundEngine::getInstance()->update();595 //music->update();596 }597 598 599 void World::collide()600 {601 CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_00),602 this->objectManager.getObjectList(OM_GROUP_01_PROJ));603 CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_01),604 this->objectManager.getObjectList(OM_COMMON));605 }606 607 /**608 * render the current frame609 610 clear all buffers and draw the world611 */612 void World::display ()613 {614 // clear buffer615 glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);616 // set camera617 this->localCamera->apply ();618 // draw world619 this->draw();620 // draw HUD621 /** @todo draw HUD */622 // flip buffers623 GraphicsEngine::swapBuffers();624 //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();625 //SDL_Flip (screen);626 }627 628 629 /**630 * runs through all entities calling their draw() methods631 */632 void World::draw ()633 {634 GraphicsEngine* engine = GraphicsEngine::getInstance();635 engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));636 engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON));637 engine->draw(State::getObjectManager()->getObjectList(OM_COMMON));638 engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_00));639 engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01));640 engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));641 642 if( unlikely( this->showBV)) // to draw the bounding boxes of the objects at level 2 for debug purp643 {644 CDEngine* engine = CDEngine::getInstance();645 engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));646 engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON));647 engine->drawBV(State::getObjectManager()->getObjectList(OM_COMMON));648 engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_00));649 engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01));650 engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));651 }652 653 // {654 // if( entity->isVisible() ) entity->draw();655 //FIXME656 // entity = iterator->nextElement();657 // }658 659 ParticleEngine::getInstance()->draw();660 661 if (unlikely(this->showPNodes))662 PNode::getNullParent()->debugDraw(0);663 664 engine->draw();665 //TextEngine::getInstance()->draw();666 }667 668 669 /**670 * \brief main loop of the world: executing all world relevant function671 *672 * in this loop we synchronize (if networked), handle input events, give the heart-beat to673 * all other member-entities of the world (tick to player, enemies etc.), checking for674 * collisions drawing everything to the screen.675 */676 void World::mainLoop()677 {678 this->lastFrame = SDL_GetTicks ();679 PRINTF(3)("World::mainLoop() - Entering main loop\n");680 681 while(!this->bQuitWorld) /* @todo implement pause */682 {683 ++this->cycle;684 // Network685 this->synchronize ();686 // Process input687 this->handleInput ();688 if( this->bQuitWorld)689 break;690 // Process time691 this->tick ();692 // Process collision693 this->collide ();694 // Update the state695 this->update ();696 // Draw697 this->display ();698 }699 700 PRINTF(3)("World::mainLoop() - Exiting the main loop\n");701 }702 703 704 705 /**706 * add and spawn a new entity to this world707 * @param entity to be added708 */709 void World::spawn(WorldEntity* entity)710 {711 // this->entities->add (entity);712 entity->postSpawn ();713 }714 715 void World::setPath( const char* name)716 {717 if (this->path)718 delete this->path;719 if (ResourceManager::isFile(name))720 {721 this->path = new char[strlen(name)+1];722 strcpy(this->path, name);723 }724 else725 {726 this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1];727 sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name);728 }729 }730 731 const char* World::getPath( void)732 {733 return path;734 } -
branches/network/src/story_entities/single_player_world.h
r6355 r6358 33 33 void loadParams(const TiXmlElement* root); 34 34 35 36 /* classes from story-entity */ 37 virtual ErrorMessage preLoad(); 38 virtual ErrorMessage load (); 39 virtual ErrorMessage postLoad(); 40 41 virtual ErrorMessage preStart(); 42 virtual ErrorMessage start (); 43 virtual ErrorMessage stop (); 44 virtual ErrorMessage pause (); 45 virtual ErrorMessage resume (); 46 virtual ErrorMessage destroy (); 47 48 virtual void displayLoadScreen(); 49 virtual void releaseLoadScreen(); 50 51 /* interface to world */ 52 virtual void spawn (WorldEntity* entity); 53 54 55 protected: 56 virtual void constuctorInit(const char* name, int worldID); 57 58 /* world - running functions */ 59 virtual void mainLoop (); 60 61 virtual void synchronize (); 62 virtual void handleInput (); 63 virtual void tick (std::list<WorldEntity*> worldEntity, float dt); 64 virtual void tick (); 65 virtual void update (); 66 virtual void collide (); 67 virtual void draw (); 68 virtual void display (); 69 70 virtual void debug (); 71 72 73 private: 74 /* external modules interfaces */ 75 Shell* shell; 76 OggPlayer* music; 77 78 GLMenuImageScreen* glmis; //!< The Level-Loader Display 35 ErrorMessage preLoad(); 36 ErrorMessage load (); 37 ErrorMessage postLoad(); 79 38 80 39 };
Note: See TracChangeset
for help on using the changeset viewer.