| [1853] | 1 |  | 
|---|
| [4010] | 2 |  | 
|---|
| [4555] | 3 | /* | 
|---|
| [1853] | 4 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
 | 5 |  | 
|---|
 | 6 |    Copyright (C) 2004 orx | 
|---|
 | 7 |  | 
|---|
 | 8 |    This program is free software; you can redistribute it and/or modify | 
|---|
 | 9 |    it under the terms of the GNU General Public License as published by | 
|---|
 | 10 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
 | 11 |    any later version. | 
|---|
| [1855] | 12 |  | 
|---|
 | 13 |    ### File Specific: | 
|---|
 | 14 |    main-programmer: Patrick Boenzli | 
|---|
| [2190] | 15 |    co-programmer: Christian Meyer | 
|---|
| [1853] | 16 | */ | 
|---|
 | 17 |  | 
|---|
| [3590] | 18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD | 
|---|
 | 19 |  | 
|---|
| [2190] | 20 | #include "world.h" | 
|---|
| [3608] | 21 |  | 
|---|
| [3620] | 22 |  | 
|---|
| [4347] | 23 | #include "state.h" | 
|---|
 | 24 |  | 
|---|
| [3608] | 25 | #include "p_node.h" | 
|---|
 | 26 | #include "null_parent.h" | 
|---|
| [4326] | 27 | #include "pilot_node.h" | 
|---|
| [3608] | 28 | #include "track_node.h" | 
|---|
| [2190] | 29 | #include "world_entity.h" | 
|---|
| [2036] | 30 | #include "player.h" | 
|---|
| [2190] | 31 | #include "camera.h" | 
|---|
| [2816] | 32 | #include "environment.h" | 
|---|
| [3419] | 33 | #include "skysphere.h" | 
|---|
| [3803] | 34 | #include "skybox.h" | 
|---|
| [3750] | 35 | #include "satellite.h" | 
|---|
| [4245] | 36 | #include "test_entity.h" | 
|---|
| [3608] | 37 | #include "terrain.h" | 
|---|
| [3436] | 38 | #include "light.h" | 
|---|
| [3790] | 39 | #include "text_engine.h" | 
|---|
| [4726] | 40 | #include "load_param.h" | 
|---|
| [3620] | 41 |  | 
|---|
| [3646] | 42 | #include "track_manager.h" | 
|---|
 | 43 | #include "garbage_collector.h" | 
|---|
| [4940] | 44 | #include "fast_factory.h" | 
|---|
| [3812] | 45 | #include "animation_player.h" | 
|---|
| [4176] | 46 | #include "particle_engine.h" | 
|---|
| [4245] | 47 | #include "graphics_engine.h" | 
|---|
| [4338] | 48 | #include "physics_engine.h" | 
|---|
| [4396] | 49 | #include "fields.h" | 
|---|
| [3646] | 50 |  | 
|---|
| [4488] | 51 | #include "md2Model.h" | 
|---|
 | 52 |  | 
|---|
| [3608] | 53 | #include "glmenu_imagescreen.h" | 
|---|
 | 54 | #include "list.h" | 
|---|
| [4010] | 55 | #include "game_loader.h" | 
|---|
| [2036] | 56 |  | 
|---|
| [3964] | 57 | #include "animation3d.h" | 
|---|
| [3608] | 58 |  | 
|---|
| [4010] | 59 | #include "substring.h" | 
|---|
| [3608] | 60 |  | 
|---|
| [4261] | 61 | #include "factory.h" | 
|---|
| [4245] | 62 |  | 
|---|
| [4287] | 63 | #include "projectile.h" | 
|---|
| [4405] | 64 | #include "event_handler.h" | 
|---|
| [4287] | 65 |  | 
|---|
| [4504] | 66 | #include "sound_engine.h" | 
|---|
| [4961] | 67 | #include "ogg_player.h" | 
|---|
| [4504] | 68 |  | 
|---|
| [4747] | 69 | #include "class_list.h" | 
|---|
 | 70 |  | 
|---|
| [4917] | 71 | #include "cd_engine.h" | 
|---|
| [4976] | 72 | #include "npc.h" | 
|---|
| [4820] | 73 |  | 
|---|
| [1856] | 74 | using namespace std; | 
|---|
| [1853] | 75 |  | 
|---|
| [4978] | 76 | //! This creates a Factory to fabricate a World | 
|---|
| [4010] | 77 | CREATE_FACTORY(World); | 
|---|
| [3620] | 78 |  | 
|---|
| [4261] | 79 | World::World(const TiXmlElement* root) | 
|---|
| [4010] | 80 | { | 
|---|
 | 81 |   this->constuctorInit("", -1); | 
|---|
| [4094] | 82 |   this->path = NULL; | 
|---|
| [4555] | 83 |  | 
|---|
| [4261] | 84 |   this->loadParams(root); | 
|---|
| [4010] | 85 | } | 
|---|
 | 86 |  | 
|---|
| [4555] | 87 | /** | 
|---|
| [4836] | 88 |   *  create a new World | 
|---|
| [4555] | 89 |  | 
|---|
| [2551] | 90 |     This creates a new empty world! | 
|---|
| [1858] | 91 | */ | 
|---|
| [4978] | 92 | World::World (const char* name) | 
|---|
| [1855] | 93 | { | 
|---|
| [4094] | 94 |   this->path = NULL; | 
|---|
| [4010] | 95 |   this->constuctorInit(name, -1); | 
|---|
| [3573] | 96 |   //NullParent* np = NullParent::getInstance(); | 
|---|
| [1855] | 97 | } | 
|---|
 | 98 |  | 
|---|
| [3449] | 99 | /** | 
|---|
| [4836] | 100 |  *  creates a new World... | 
|---|
 | 101 |  * @param worldID with this ID | 
|---|
| [3449] | 102 | */ | 
|---|
| [2636] | 103 | World::World (int worldID) | 
|---|
 | 104 | { | 
|---|
| [4094] | 105 |   this->path = NULL; | 
|---|
| [4010] | 106 |   this->constuctorInit(NULL, worldID); | 
|---|
| [2636] | 107 | } | 
|---|
 | 108 |  | 
|---|
| [4555] | 109 | /** | 
|---|
| [4838] | 110 |  *  remove the World from memory | 
|---|
| [4555] | 111 |  | 
|---|
| [3365] | 112 |     delete everything explicitly, that isn't contained in the parenting tree! | 
|---|
 | 113 |     things contained in the tree are deleted automaticaly | 
|---|
| [4838] | 114 |  */ | 
|---|
| [2190] | 115 | World::~World () | 
|---|
| [1872] | 116 | { | 
|---|
| [5098] | 117 |   delete Shell::getInstance(); | 
|---|
| [3546] | 118 |   PRINTF(3)("World::~World() - deleting current world\n"); | 
|---|
| [3677] | 119 |  | 
|---|
| [4978] | 120 |   // here everything that is alocated by the World is deleted | 
|---|
| [4837] | 121 |   delete this->entities; | 
|---|
| [4830] | 122 |   State::setWorldEntityList(NULL); | 
|---|
 | 123 |  | 
|---|
| [5115] | 124 |  | 
|---|
| [4735] | 125 |   delete LightManager::getInstance(); | 
|---|
| [4822] | 126 |   delete TrackManager::getInstance(); | 
|---|
 | 127 |   delete ParticleEngine::getInstance(); | 
|---|
| [4978] | 128 |   delete AnimationPlayer::getInstance(); // this should be at the end of the unloading sequence. | 
|---|
 | 129 |   delete PhysicsEngine::getInstance(); | 
|---|
| [4822] | 130 |  | 
|---|
| [4978] | 131 |   // external engines initialized by the orxonox-class get deleted | 
|---|
| [4504] | 132 |   SoundEngine::getInstance()->flushAllBuffers(); | 
|---|
| [4830] | 133 |   SoundEngine::getInstance()->flushAllSources(); | 
|---|
| [4979] | 134 |   FastFactory::flushAll(true); | 
|---|
| [4504] | 135 |  | 
|---|
| [5115] | 136 |  | 
|---|
| [4978] | 137 |   // erease everything that is left. | 
|---|
| [4870] | 138 |   delete NullParent::getInstance(); | 
|---|
| [4872] | 139 |  | 
|---|
| [4961] | 140 |  | 
|---|
| [4978] | 141 |   // unload the resources !! | 
|---|
| [5117] | 142 |   ResourceManager::getInstance()->unload(this->music); | 
|---|
| [4136] | 143 |   ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL); | 
|---|
| [1872] | 144 | } | 
|---|
| [1858] | 145 |  | 
|---|
| [3526] | 146 | /** | 
|---|
| [4978] | 147 |  * initializes the world. | 
|---|
 | 148 |  * @param name the name of the world | 
|---|
 | 149 |  * @param worldID the ID of this world | 
|---|
 | 150 |  * | 
|---|
 | 151 |  * set all stuff here that is world generic and does not use to much memory | 
|---|
 | 152 |  * because the real init() function StoryEntity::init() will be called | 
|---|
 | 153 |  * shortly before start of the game. | 
|---|
 | 154 |  * since all worlds are initiated/referenced before they will be started. | 
|---|
 | 155 |  * NO LEVEL LOADING HERE - NEVER! | 
|---|
| [3526] | 156 | */ | 
|---|
| [4978] | 157 | void World::constuctorInit(const char* name, int worldID) | 
|---|
| [3526] | 158 | { | 
|---|
| [4320] | 159 |   this->setClassID(CL_WORLD, "World"); | 
|---|
| [2636] | 160 |  | 
|---|
| [4978] | 161 |   this->setName(name); | 
|---|
| [3526] | 162 |   this->debugWorldNr = worldID; | 
|---|
| [4961] | 163 |  | 
|---|
 | 164 |   this->music = NULL; | 
|---|
| [3629] | 165 | } | 
|---|
| [3526] | 166 |  | 
|---|
| [4978] | 167 | /** | 
|---|
 | 168 |  * loads the parameters of a World from an XML-element | 
|---|
 | 169 |  * @param root the XML-element to load from | 
|---|
 | 170 |  */ | 
|---|
| [4261] | 171 | void World::loadParams(const TiXmlElement* root) | 
|---|
 | 172 | { | 
|---|
| [4600] | 173 |   PRINTF(4)("Creating a World\n"); | 
|---|
| [4261] | 174 |  | 
|---|
 | 175 |   LoadParam<World>(root, "identifier", this, &World::setStoryID) | 
|---|
 | 176 |     .describe("Sets the StoryID of this world"); | 
|---|
| [4834] | 177 |  | 
|---|
| [4261] | 178 |   LoadParam<World>(root, "nextid", this, &World::setNextStoryID) | 
|---|
 | 179 |     .describe("Sets the ID of the next world"); | 
|---|
| [4834] | 180 |  | 
|---|
| [4261] | 181 |   LoadParam<World>(root, "path", this, &World::setPath) | 
|---|
 | 182 |     .describe("The Filename of this World (relative from the data-dir)"); | 
|---|
 | 183 | } | 
|---|
 | 184 |  | 
|---|
| [3629] | 185 | /** | 
|---|
| [4978] | 186 |  * this is executed just before load | 
|---|
 | 187 |  * | 
|---|
 | 188 |  * since the load function sometimes needs data, that has been initialized | 
|---|
 | 189 |  * before the load and after the proceeding storyentity has finished | 
|---|
| [3629] | 190 | */ | 
|---|
 | 191 | ErrorMessage World::preLoad() | 
|---|
 | 192 | { | 
|---|
| [4829] | 193 |   State::setWorldEntityList(this->entities = new tList<WorldEntity>()); | 
|---|
 | 194 |   this->cycle = 0; | 
|---|
 | 195 |  | 
|---|
| [3620] | 196 |   /* init the world interface */ | 
|---|
| [5098] | 197 |   Shell::getInstance(); | 
|---|
| [4010] | 198 |  | 
|---|
| [4735] | 199 |   LightManager::getInstance(); | 
|---|
| [4978] | 200 |   NullParent::getInstance (); | 
|---|
| [3993] | 201 |  | 
|---|
| [4010] | 202 |   AnimationPlayer::getInstance(); // initializes the animationPlayer | 
|---|
| [4338] | 203 |   PhysicsEngine::getInstance(); | 
|---|
| [4010] | 204 |  | 
|---|
| [4015] | 205 |   this->localCamera = new Camera(); | 
|---|
| [4978] | 206 |   this->localCamera->setName ("World-Camera"); | 
|---|
| [4555] | 207 |  | 
|---|
| [4827] | 208 |   State::setCamera(this->localCamera, this->localCamera->getTarget()); | 
|---|
| [4347] | 209 |  | 
|---|
| [4245] | 210 |   GraphicsEngine::getInstance()->displayFPS(true); | 
|---|
| [4918] | 211 |  | 
|---|
 | 212 |   CDEngine::getInstance()->setEntityList( this->entities); | 
|---|
| [3526] | 213 | } | 
|---|
 | 214 |  | 
|---|
 | 215 |  | 
|---|
| [3449] | 216 | /** | 
|---|
| [4836] | 217 |  *  loads the World by initializing all resources, and set their default values. | 
|---|
| [3449] | 218 | */ | 
|---|
| [3459] | 219 | ErrorMessage World::load() | 
|---|
| [4555] | 220 | { | 
|---|
| [4104] | 221 |   PRINTF(3)("> Loading world: '%s'\n", getPath()); | 
|---|
 | 222 |   TiXmlElement* element; | 
|---|
| [4010] | 223 |   GameLoader* loader = GameLoader::getInstance(); | 
|---|
| [4555] | 224 |  | 
|---|
| [4010] | 225 |   if( getPath() == NULL) | 
|---|
| [2636] | 226 |     { | 
|---|
| [4104] | 227 |       PRINTF(1)("World has no path specified for loading"); | 
|---|
| [4324] | 228 |       this->loadDebugWorld(this->getStoryID()); | 
|---|
| [4010] | 229 |       return (ErrorMessage){213,"Path not specified","World::load()"}; | 
|---|
 | 230 |     } | 
|---|
| [4555] | 231 |  | 
|---|
| [4010] | 232 |   TiXmlDocument* XMLDoc = new TiXmlDocument( path); | 
|---|
 | 233 |   // load the campaign document | 
|---|
| [4555] | 234 |   if( !XMLDoc->LoadFile()) | 
|---|
| [4010] | 235 |   { | 
|---|
 | 236 |     // report an error | 
|---|
| [4104] | 237 |     PRINTF(1)("loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); | 
|---|
| [4010] | 238 |     delete XMLDoc; | 
|---|
 | 239 |     return (ErrorMessage){213,"XML File parsing error","World::load()"}; | 
|---|
 | 240 |   } | 
|---|
| [4555] | 241 |  | 
|---|
| [4010] | 242 |   // check basic validity | 
|---|
 | 243 |   TiXmlElement* root = XMLDoc->RootElement(); | 
|---|
 | 244 |   assert( root != NULL); | 
|---|
| [4555] | 245 |  | 
|---|
| [4010] | 246 |   if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile")) | 
|---|
 | 247 |     { | 
|---|
 | 248 |       // report an error | 
|---|
| [4104] | 249 |       PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n"); | 
|---|
| [4010] | 250 |       delete XMLDoc; | 
|---|
 | 251 |       return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"}; | 
|---|
 | 252 |     } | 
|---|
| [4555] | 253 |  | 
|---|
| [4010] | 254 |   // load the parameters | 
|---|
 | 255 |   // name | 
|---|
 | 256 |   char* temp; | 
|---|
 | 257 |   const char* string = grabParameter( root, "name"); | 
|---|
 | 258 |   if( string == NULL) | 
|---|
 | 259 |     { | 
|---|
| [4104] | 260 |       PRINTF(2)("World is missing a proper 'name'\n"); | 
|---|
| [4010] | 261 |       string = "Unknown"; | 
|---|
 | 262 |       temp = new char[strlen(string + 2)]; | 
|---|
 | 263 |       strcpy( temp, string); | 
|---|
| [4978] | 264 |       this->setName(temp); | 
|---|
| [4010] | 265 |     } | 
|---|
 | 266 |   else | 
|---|
 | 267 |     { | 
|---|
 | 268 |       temp = new char[strlen(string + 2)]; | 
|---|
 | 269 |       strcpy( temp, string); | 
|---|
| [4978] | 270 |       this->setName(temp); | 
|---|
| [4010] | 271 |     } | 
|---|
| [4978] | 272 |  | 
|---|
| [4104] | 273 |   //////////////// | 
|---|
 | 274 |   // LOADSCREEN // | 
|---|
 | 275 |   //////////////// | 
|---|
 | 276 |   element = root->FirstChildElement("LoadScreen"); | 
|---|
 | 277 |   if (element == NULL) | 
|---|
 | 278 |     { | 
|---|
 | 279 |       PRINTF(2)("no LoadScreen specified, loading default\n"); | 
|---|
 | 280 |  | 
|---|
 | 281 |       glmis->setBackgroundImage("pictures/load_screen.jpg"); | 
|---|
 | 282 |       this->glmis->setMaximum(8); | 
|---|
 | 283 |       this->glmis->draw(); | 
|---|
 | 284 |     } | 
|---|
 | 285 |   else | 
|---|
 | 286 |     { | 
|---|
| [4261] | 287 |       this->glmis->loadParams(element); | 
|---|
| [4104] | 288 |       this->glmis->draw(); | 
|---|
 | 289 |     } | 
|---|
 | 290 |   this->glmis->draw(); | 
|---|
| [4726] | 291 |  | 
|---|
 | 292 |   //////////////////////// | 
|---|
 | 293 |   // find WorldEntities // | 
|---|
 | 294 |   //////////////////////// | 
|---|
 | 295 |  | 
|---|
| [4104] | 296 |   element = root->FirstChildElement("WorldEntities"); | 
|---|
| [4555] | 297 |  | 
|---|
| [4010] | 298 |   if( element == NULL) | 
|---|
 | 299 |     { | 
|---|
| [4104] | 300 |       PRINTF(1)("World is missing 'WorldEntities'\n"); | 
|---|
| [4010] | 301 |     } | 
|---|
 | 302 |   else | 
|---|
 | 303 |     { | 
|---|
 | 304 |       element = element->FirstChildElement(); | 
|---|
 | 305 |       // load Players/Objects/Whatever | 
|---|
| [4104] | 306 |       PRINTF(4)("Loading WorldEntities\n"); | 
|---|
| [4010] | 307 |       while( element != NULL) | 
|---|
| [4555] | 308 |         { | 
|---|
 | 309 |           WorldEntity* created = dynamic_cast<WorldEntity*>( loader->fabricate( element)); | 
|---|
 | 310 |           if( created != NULL) this->spawn( created); | 
|---|
 | 311 |           // if we load a 'Player' we use it as localPlayer | 
|---|
 | 312 |           //todo do this more elegant | 
|---|
| [4919] | 313 |           if( element->Value() != NULL && !strcmp( element->Value(), "Player")) | 
|---|
 | 314 |           { | 
|---|
 | 315 |             localPlayer = (Player*) created; | 
|---|
 | 316 |             CDEngine::getInstance()->setPlayer(localPlayer); | 
|---|
 | 317 |           } | 
|---|
| [4555] | 318 |           if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) sky = (SkyBox*) created; | 
|---|
| [4918] | 319 |           if( element->Value() != NULL && !strcmp( element->Value(), "Terrain")) | 
|---|
 | 320 |           { | 
|---|
 | 321 |             terrain = (Terrain*) created; | 
|---|
 | 322 |             CDEngine::getInstance()->setTerrain(terrain); | 
|---|
 | 323 |           } | 
|---|
| [4555] | 324 |           element = element->NextSiblingElement(); | 
|---|
| [4836] | 325 |           glmis->step(); //! @todo temporary | 
|---|
| [4555] | 326 |         } | 
|---|
| [4104] | 327 |       PRINTF(4)("Done loading WorldEntities\n"); | 
|---|
| [4010] | 328 |     } | 
|---|
| [4555] | 329 |  | 
|---|
| [4726] | 330 |     ////////////////////////////// | 
|---|
 | 331 |     // LOADING ADDITIONAL STUFF // | 
|---|
 | 332 |     ////////////////////////////// | 
|---|
 | 333 |  | 
|---|
| [4735] | 334 |     LoadParam<LightManager>(root, "LightManager", LightManager::getInstance(), &LightManager::loadParams); | 
|---|
 | 335 |  | 
|---|
| [4726] | 336 |     LoadParam<ParticleEngine>(root, "ParticleEngine", ParticleEngine::getInstance(), &ParticleEngine::loadParams); | 
|---|
| [4730] | 337 |     LoadParam<PhysicsEngine>(root, "PhysicsEngine", PhysicsEngine::getInstance(), &PhysicsEngine::loadParams); | 
|---|
| [4726] | 338 |  | 
|---|
| [4010] | 339 |   // find Track | 
|---|
| [4222] | 340 |   element = root->FirstChildElement( "Track"); | 
|---|
| [4010] | 341 |   if( element == NULL) | 
|---|
 | 342 |     { | 
|---|
| [4228] | 343 |       PRINTF(0)("World is missing a 'Track'\n"); | 
|---|
| [4010] | 344 |     } | 
|---|
 | 345 |   else | 
|---|
| [4555] | 346 |     { | 
|---|
| [4010] | 347 |       //load track | 
|---|
| [4228] | 348 |       PRINTF(4)("Loading Track\n"); | 
|---|
| [4010] | 349 |  | 
|---|
| [4822] | 350 |       TrackManager::getInstance()->loadParams( element); | 
|---|
 | 351 |       TrackManager::getInstance()->finalize(); | 
|---|
| [4222] | 352 |     } | 
|---|
| [4555] | 353 |  | 
|---|
| [4010] | 354 |   // free the XML data | 
|---|
| [4015] | 355 |  | 
|---|
| [4010] | 356 |   delete XMLDoc; | 
|---|
| [4015] | 357 |   /* GENERIC LOADING PROCESS FINISHED */ | 
|---|
| [4555] | 358 |  | 
|---|
| [4010] | 359 |   // bind input | 
|---|
| [4822] | 360 |   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_UP); | 
|---|
 | 361 |   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_DOWN); | 
|---|
 | 362 |   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_LEFT); | 
|---|
 | 363 |   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_RIGHT); | 
|---|
 | 364 |   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_FIRE1); | 
|---|
 | 365 |   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_NEXT_WEAPON); | 
|---|
 | 366 |   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_PREVIOUS_WEAPON); | 
|---|
| [4555] | 367 |  | 
|---|
| [4010] | 368 |   // bind camera | 
|---|
 | 369 |   //this->localCamera->bind (localPlayer); | 
|---|
| [4969] | 370 |  // this->localPlayer->addChild (this->localCamera); | 
|---|
| [4245] | 371 |  | 
|---|
| [4555] | 372 |  | 
|---|
| [4822] | 373 |   //        TrackManager::getInstance()->setBindSlave(env); | 
|---|
 | 374 |   PNode* tn = TrackManager::getInstance()->getTrackNode(); | 
|---|
| [4010] | 375 |   tn->addChild(this->localPlayer); | 
|---|
| [4555] | 376 |  | 
|---|
| [4010] | 377 |   //localCamera->setParent(TrackNode::getInstance()); | 
|---|
 | 378 |   tn->addChild(this->localCamera); | 
|---|
 | 379 |   localCamera->lookAt(tn); | 
|---|
| [4620] | 380 |   localCamera->setClipRegion(1, 10000.0); | 
|---|
| [4444] | 381 |   this->localPlayer->setParentMode(PNODE_ALL); | 
|---|
| [4010] | 382 |   Vector* cameraOffset = new Vector (0, 5, -10); | 
|---|
| [4822] | 383 |   TrackManager::getInstance()->condition(1, LEFTRIGHT, this->localPlayer); | 
|---|
| [4501] | 384 |  | 
|---|
| [4015] | 385 |   this->sky->setParent(this->localCamera); | 
|---|
| [3368] | 386 |  | 
|---|
| [4010] | 387 |   // initialize debug coord system | 
|---|
 | 388 |   objectList = glGenLists(1); | 
|---|
 | 389 |   glNewList (objectList, GL_COMPILE); | 
|---|
| [4555] | 390 |  | 
|---|
| [4822] | 391 |   //TrackManager::getInstance()->drawGraph(.01); | 
|---|
 | 392 |   //TrackManager::getInstance()->debug(2); | 
|---|
| [4010] | 393 |   glEndList(); | 
|---|
| [3993] | 394 |  | 
|---|
| [4504] | 395 |   SoundEngine::getInstance()->setListener(this->localCamera); | 
|---|
| [4176] | 396 |  | 
|---|
| [4347] | 397 |  | 
|---|
| [4709] | 398 |  | 
|---|
| [4715] | 399 |   //////////// | 
|---|
 | 400 |   // STATIC // | 
|---|
 | 401 |   //////////// | 
|---|
 | 402 |  | 
|---|
| [4730] | 403 |   Gravity* test = new Gravity(); | 
|---|
| [4715] | 404 |  | 
|---|
| [4709] | 405 |   // SYSTEM TRAILING THE PLAYER | 
|---|
| [4347] | 406 |   // Creating a Test Particle System | 
|---|
| [4430] | 407 |  | 
|---|
| [4730] | 408 |   //new PhysicsConnection(system, gravity); | 
|---|
| [4397] | 409 |   //    new PhysicsConnection(this->localPlayer, gravity); | 
|---|
| [4347] | 410 |  | 
|---|
| [4721] | 411 | //   TestEntity* testEntity = new TestEntity(); | 
|---|
 | 412 | //   testEntity->setRelCoor(Vector(570, 10, -15)); | 
|---|
 | 413 | //   testEntity->setRelDir(Quaternion(M_PI, Vector(0, 1, 0))); | 
|---|
 | 414 | //   this->spawn(testEntity); | 
|---|
| [4397] | 415 |  | 
|---|
| [4488] | 416 |   TestEntity* testEntity2 = new TestEntity(); | 
|---|
| [5085] | 417 |   testEntity2->setAnim(STAND); | 
|---|
| [5087] | 418 |   testEntity2->setRelCoor(Vector(2400.0, 10.0, -30.0)); | 
|---|
| [4488] | 419 |   testEntity2->setRelDir(Quaternion(M_PI, Vector(0, 1, 0))); | 
|---|
| [5087] | 420 |   //testEntity2->setParent(this->localPlayer); | 
|---|
| [4488] | 421 |   this->spawn(testEntity2); | 
|---|
 | 422 |  | 
|---|
| [4721] | 423 |   TestEntity* testEntity3 = new TestEntity(); | 
|---|
| [5087] | 424 |   testEntity3->setAnim(BOOM); | 
|---|
 | 425 |   testEntity3->setRelCoor(Vector(2450.0, 10.0, -40.0)); | 
|---|
| [4721] | 426 |   testEntity3->setRelDir(Quaternion(M_PI, Vector(0, 1, 0))); | 
|---|
 | 427 |   this->spawn(testEntity3); | 
|---|
| [4488] | 428 |  | 
|---|
| [4721] | 429 |   TestEntity* testEntity4 = new TestEntity(); | 
|---|
| [5087] | 430 |   testEntity4->setAnim(FLIP); | 
|---|
 | 431 |   testEntity4->setRelCoor(Vector(2500.0, 10.0, -22.0)); | 
|---|
| [4721] | 432 |   testEntity4->setRelDir(Quaternion(M_PI, Vector(0, 1, 0))); | 
|---|
 | 433 |   this->spawn(testEntity4); | 
|---|
| [4574] | 434 |  | 
|---|
| [5087] | 435 |   TestEntity* testEntity5 = new TestEntity(); | 
|---|
 | 436 |   testEntity5->setAnim(WAVE); | 
|---|
 | 437 |   testEntity5->setRelCoor(Vector(2420.0, 10.0, -50.0)); | 
|---|
 | 438 |   testEntity5->setRelDir(Quaternion(M_PI, Vector(0, 1, 0))); | 
|---|
 | 439 |   this->spawn(testEntity5); | 
|---|
| [4721] | 440 |  | 
|---|
| [5087] | 441 |   TestEntity* testEntity6 = new TestEntity(); | 
|---|
 | 442 |   testEntity6->setAnim(WAVE); | 
|---|
 | 443 |   testEntity6->setRelCoor(Vector(2420.0, 10.0, -20.0)); | 
|---|
 | 444 |   testEntity6->setRelDir(Quaternion(M_PI, Vector(0, 1, 0))); | 
|---|
 | 445 |   this->spawn(testEntity6); | 
|---|
 | 446 |  | 
|---|
 | 447 |   TestEntity* testEntity7 = new TestEntity(); | 
|---|
 | 448 |   testEntity7->setAnim(WAVE); | 
|---|
 | 449 |   testEntity7->setRelCoor(Vector(2500.0, 10.0, -50.0)); | 
|---|
 | 450 |   testEntity7->setRelDir(Quaternion(M_PI, Vector(0, 1, 0))); | 
|---|
 | 451 |   this->spawn(testEntity7); | 
|---|
 | 452 |  | 
|---|
 | 453 |  | 
|---|
 | 454 |  | 
|---|
| [4730] | 455 |   PhysicsEngine::getInstance()->debug(); | 
|---|
| [4721] | 456 |  | 
|---|
| [4978] | 457 |  | 
|---|
 | 458 |  | 
|---|
| [4976] | 459 |   for(int i = 0; i < 100; i++) | 
|---|
 | 460 |   { | 
|---|
 | 461 |     WorldEntity* tmp = new NPC(); | 
|---|
| [5049] | 462 |     char npcChar[10]; | 
|---|
 | 463 |     sprintf (npcChar, "NPC_%d", i); | 
|---|
 | 464 |     tmp->setName(npcChar); | 
|---|
| [4986] | 465 |     tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *100); | 
|---|
| [4976] | 466 |     this->spawn(tmp); | 
|---|
| [4747] | 467 |  | 
|---|
| [4976] | 468 |  | 
|---|
 | 469 |   } | 
|---|
 | 470 |  | 
|---|
 | 471 |  | 
|---|
 | 472 |  | 
|---|
| [4747] | 473 |   ClassList::debug(); | 
|---|
| [4961] | 474 |  | 
|---|
 | 475 |   this->music = (OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL); | 
|---|
 | 476 |   music->playback(); | 
|---|
| [4010] | 477 | } | 
|---|
| [3365] | 478 |  | 
|---|
| [4245] | 479 |  | 
|---|
| [4324] | 480 |  | 
|---|
| [4326] | 481 | /** | 
|---|
| [4978] | 482 |  * creates a debug world: only for experimental stuff | 
|---|
| [4326] | 483 | */ | 
|---|
| [4010] | 484 | void World::loadDebugWorld(int worldID) | 
|---|
 | 485 | { | 
|---|
 | 486 |   /*monitor progress*/ | 
|---|
 | 487 |   this->glmis->step(); | 
|---|
| [4228] | 488 |   // stuff beyond this point remains to be loaded properly | 
|---|
| [3194] | 489 |  | 
|---|
| [4228] | 490 |   // initializing the TrackManager | 
|---|
| [4822] | 491 |   TrackManager::getInstance()->addPointV(Vector(150, -35, 5)); | 
|---|
 | 492 |   TrackManager::getInstance()->addPointV(Vector(200,-35, 5)); | 
|---|
 | 493 |   TrackManager::getInstance()->addPointV(Vector(250, -35, 5)); | 
|---|
 | 494 |   TrackManager::getInstance()->addPointV(Vector(320,-33,-.55)); | 
|---|
 | 495 |   TrackManager::getInstance()->setDuration(1); | 
|---|
 | 496 |   TrackManager::getInstance()->setSavePoint(); | 
|---|
| [4228] | 497 |  | 
|---|
| [4822] | 498 |   TrackManager::getInstance()->addPointV(Vector(410, 0, 0)); | 
|---|
 | 499 |   TrackManager::getInstance()->addPointV(Vector(510, 20, -10)); | 
|---|
 | 500 |   TrackManager::getInstance()->addPointV(Vector(550, 20, -10)); | 
|---|
 | 501 |   TrackManager::getInstance()->addPointV(Vector(570, 20, -10)); | 
|---|
 | 502 |   TrackManager::getInstance()->setDuration(2); | 
|---|
| [4555] | 503 |  | 
|---|
| [4822] | 504 |   TrackManager::getInstance()->forkS("testFork1,testFork2"); | 
|---|
 | 505 |   TrackManager::getInstance()->workOnS("testFork1"); | 
|---|
 | 506 |   TrackManager::getInstance()->addPointV(Vector(640, 25, -30)); | 
|---|
 | 507 |   TrackManager::getInstance()->addPointV(Vector(700, 40, -120)); | 
|---|
 | 508 |   TrackManager::getInstance()->addPointV(Vector(800, 50, -150)); | 
|---|
 | 509 |   TrackManager::getInstance()->addPointV(Vector(900, 60, -100)); | 
|---|
 | 510 |   TrackManager::getInstance()->addPointV(Vector(900, 60, -70)); | 
|---|
 | 511 |   TrackManager::getInstance()->addPointV(Vector(990, 65, -15)); | 
|---|
 | 512 |   TrackManager::getInstance()->addPointV(Vector(1050, 65, -10)); | 
|---|
 | 513 |   TrackManager::getInstance()->addPointV(Vector(1100, 65, -20)); | 
|---|
 | 514 |   TrackManager::getInstance()->setDuration(4); | 
|---|
| [4228] | 515 |  | 
|---|
| [4822] | 516 |   TrackManager::getInstance()->workOnS("testFork2"); | 
|---|
 | 517 |   TrackManager::getInstance()->addPointV(Vector(640, 25, 20)); | 
|---|
 | 518 |   TrackManager::getInstance()->addPointV(Vector(670, 50, 120)); | 
|---|
 | 519 |   TrackManager::getInstance()->addPointV(Vector(700, 70, 80)); | 
|---|
 | 520 |   TrackManager::getInstance()->addPointV(Vector(800, 70, 65)); | 
|---|
 | 521 |   TrackManager::getInstance()->addPointV(Vector(850, 65, 65)); | 
|---|
 | 522 |   TrackManager::getInstance()->addPointV(Vector(920, 35, 40)); | 
|---|
 | 523 |   TrackManager::getInstance()->addPointV(Vector(945, 40, 40)); | 
|---|
 | 524 |   TrackManager::getInstance()->addPointV(Vector(970, 24, 40)); | 
|---|
 | 525 |   TrackManager::getInstance()->addPointV(Vector(1000, 40, -7)); | 
|---|
| [4508] | 526 |  | 
|---|
| [4822] | 527 |   TrackManager::getInstance()->setDuration(4); | 
|---|
| [4555] | 528 |  | 
|---|
 | 529 |  | 
|---|
| [4822] | 530 |   TrackManager::getInstance()->joinS("testFork1,testFork2"); | 
|---|
| [4555] | 531 |  | 
|---|
| [4822] | 532 |   TrackManager::getInstance()->addPointV(Vector(1200, 60, -50)); | 
|---|
 | 533 |   TrackManager::getInstance()->addPointV(Vector(1300, 50, -50)); | 
|---|
 | 534 |   TrackManager::getInstance()->addPointV(Vector(1400, 40, -50)); | 
|---|
 | 535 |   TrackManager::getInstance()->addPointV(Vector(1500, 40, -60)); | 
|---|
 | 536 |   TrackManager::getInstance()->addPointV(Vector(1600, 35, -55)); | 
|---|
 | 537 |   TrackManager::getInstance()->addPointV(Vector(1700, 45, -40)); | 
|---|
 | 538 |   TrackManager::getInstance()->addPointV(Vector(1750, 60, -40)); | 
|---|
 | 539 |   TrackManager::getInstance()->addPointV(Vector(1770, 80, -40)); | 
|---|
 | 540 |   TrackManager::getInstance()->addPointV(Vector(1800, 100, -40)); | 
|---|
 | 541 |   TrackManager::getInstance()->setDuration(10); | 
|---|
| [4555] | 542 |  | 
|---|
| [4822] | 543 |   TrackManager::getInstance()->finalize(); | 
|---|
| [4228] | 544 |  | 
|---|
| [4555] | 545 |  | 
|---|
| [4010] | 546 |   // LIGHT initialisation | 
|---|
| [4735] | 547 |   LightManager::getInstance()->setAmbientColor(.1,.1,.1); | 
|---|
| [4736] | 548 | //  LightManager::getInstance()->addLight(); | 
|---|
| [4735] | 549 |   LightManager::getInstance()->debug(); | 
|---|
| [3368] | 550 |  | 
|---|
| [4010] | 551 |   switch(this->debugWorldNr) | 
|---|
 | 552 |     { | 
|---|
 | 553 |       /* | 
|---|
| [4555] | 554 |         this loads the hard-coded debug world. this only for simplicity and will be | 
|---|
 | 555 |         removed by a reald world-loader, which interprets a world-file. | 
|---|
 | 556 |         if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and | 
|---|
 | 557 |         make whatever you want... | 
|---|
| [4010] | 558 |       */ | 
|---|
 | 559 |     case DEBUG_WORLD_0: | 
|---|
 | 560 |       { | 
|---|
| [4735] | 561 |         LightManager::getInstance()->getLight()->setAbsCoor(-5.0, 10.0, -40.0); | 
|---|
| [4010] | 562 |  | 
|---|
 | 563 |  | 
|---|
| [4555] | 564 |         this->localPlayer = new Player (); | 
|---|
 | 565 |         this->localPlayer->setName ("player"); | 
|---|
 | 566 |         this->spawn (this->localPlayer); | 
|---|
 | 567 |         this->localPlayer->setRelCoor(Vector(5,0,0)); | 
|---|
 | 568 |         /*monitor progress*/ | 
|---|
 | 569 |         this->glmis->step(); | 
|---|
| [4010] | 570 |  | 
|---|
| [4418] | 571 |  | 
|---|
| [4822] | 572 |         EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_FIRE1); | 
|---|
 | 573 |         EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_NEXT_WEAPON); | 
|---|
 | 574 |         EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_PREVIOUS_WEAPON); | 
|---|
| [4418] | 575 |  | 
|---|
| [4555] | 576 |         /* | 
|---|
 | 577 |         Field* testField = new Gravity(); | 
|---|
 | 578 |         testField->setMagnitude(10); | 
|---|
 | 579 |         new PhysicsConnection(this->localPlayer, testField); | 
|---|
 | 580 |         */ | 
|---|
| [4397] | 581 |  | 
|---|
| [4555] | 582 |         // bind camera | 
|---|
 | 583 |         this->localCamera = new Camera(); | 
|---|
 | 584 |         this->localCamera->setName ("camera"); | 
|---|
 | 585 |         /*monitor progress*/ | 
|---|
 | 586 |         this->glmis->step(); | 
|---|
| [2816] | 587 |  | 
|---|
| [3419] | 588 |  | 
|---|
| [4555] | 589 |         // Create SkySphere | 
|---|
| [4621] | 590 |         this->sky = new Skysphere("pictures/sky-replace.jpg"); | 
|---|
 | 591 |         this->sky->setName("SkySphere"); | 
|---|
 | 592 |         this->spawn(this->sky); | 
|---|
| [4555] | 593 |         this->localCamera->addChild(this->sky); | 
|---|
 | 594 |         this->sky->setParentMode(PNODE_MOVEMENT); | 
|---|
 | 595 |         /*monitor progress*/ | 
|---|
 | 596 |         this->glmis->step(); | 
|---|
| [3368] | 597 |  | 
|---|
| [3521] | 598 |  | 
|---|
| [4555] | 599 |         terrain = new Terrain("worlds/newGround.obj"); | 
|---|
 | 600 |         terrain->setRelCoor(Vector(0,-10,0)); | 
|---|
 | 601 |         this->spawn(terrain); | 
|---|
 | 602 |         /*monitor progress*/ | 
|---|
 | 603 |         this->glmis->step(); | 
|---|
| [2816] | 604 |  | 
|---|
| [4555] | 605 |         this->pilotNode = new PilotNode(); | 
|---|
 | 606 |         this->spawn(this->pilotNode); | 
|---|
 | 607 |         this->pilotNode->setAbsCoor(Vector(150, -35, 5)); | 
|---|
 | 608 |         this->pilotNode->addChild(this->localPlayer); | 
|---|
 | 609 |         this->pilotNode->addChild(this->localCamera); | 
|---|
 | 610 |         this->localCamera->lookAt(this->localPlayer); | 
|---|
| [4422] | 611 |  | 
|---|
| [4822] | 612 |         EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_UP); | 
|---|
 | 613 |         EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_DOWN); | 
|---|
 | 614 |         EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_LEFT); | 
|---|
 | 615 |         EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_RIGHT); | 
|---|
 | 616 |         EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, EV_MOUSE_MOTION); | 
|---|
| [4422] | 617 |  | 
|---|
| [4555] | 618 |         /* | 
|---|
| [4822] | 619 |         PNode* tn = TrackManager::getInstance()->getTrackNode(); | 
|---|
| [4555] | 620 |         tn->addChild(this->localPlayer); | 
|---|
 | 621 |         this->localCamera->lookAt(tn); | 
|---|
 | 622 |  | 
|---|
 | 623 |         tn->addChild(this->localCamera); | 
|---|
 | 624 |         this->localPlayer->setParentMode(PNODE_ALL); | 
|---|
| [4822] | 625 |         TrackManager::getInstance()->condition(2, LEFTRIGHT, this->localPlayer); | 
|---|
| [4555] | 626 |         */ | 
|---|
 | 627 |         this->glmis->step(); | 
|---|
 | 628 |         break; | 
|---|
| [4010] | 629 |       } | 
|---|
 | 630 |     case DEBUG_WORLD_1: | 
|---|
 | 631 |       { | 
|---|
| [3365] | 632 |  | 
|---|
| [4555] | 633 |         break; | 
|---|
| [4010] | 634 |       } | 
|---|
 | 635 |     case DEBUG_WORLD_2: | 
|---|
 | 636 |       { | 
|---|
| [3727] | 637 |  | 
|---|
| [4555] | 638 |         break; | 
|---|
| [4010] | 639 |       } | 
|---|
 | 640 |     default: | 
|---|
| [4324] | 641 |       break; | 
|---|
| [2636] | 642 |     } | 
|---|
| [4010] | 643 | } | 
|---|
| [2636] | 644 |  | 
|---|
| [3459] | 645 | /** | 
|---|
| [4836] | 646 |  *  initializes a new World shortly before start | 
|---|
| [4978] | 647 |  * | 
|---|
 | 648 |  * this is the function, that will be loaded shortly before the world is | 
|---|
 | 649 |  * started | 
|---|
| [3459] | 650 | */ | 
|---|
 | 651 | ErrorMessage World::init() | 
|---|
 | 652 | { | 
|---|
 | 653 |   this->bPause = false; | 
|---|
| [4326] | 654 |   this->pilotNode = NULL; | 
|---|
| [5051] | 655 |  | 
|---|
 | 656 |   /* update the object position before game start - so there are no wrong coordinates used in the first processing */ | 
|---|
 | 657 |   NullParent::getInstance()->update (0.001f); | 
|---|
 | 658 |   NullParent::getInstance()->update (0.001f); | 
|---|
| [5084] | 659 |  | 
|---|
| [3459] | 660 | } | 
|---|
 | 661 |  | 
|---|
 | 662 |  | 
|---|
 | 663 | /** | 
|---|
| [4836] | 664 |  *  starts the World | 
|---|
| [3459] | 665 | */ | 
|---|
 | 666 | ErrorMessage World::start() | 
|---|
 | 667 | { | 
|---|
| [3546] | 668 |   PRINTF(3)("World::start() - starting current World: nr %i\n", this->debugWorldNr); | 
|---|
| [3459] | 669 |   this->bQuitOrxonox = false; | 
|---|
 | 670 |   this->bQuitCurrentGame = false; | 
|---|
 | 671 |   this->mainLoop(); | 
|---|
 | 672 | } | 
|---|
 | 673 |  | 
|---|
 | 674 | /** | 
|---|
| [4836] | 675 |  *  stops the world. | 
|---|
| [3459] | 676 |  | 
|---|
 | 677 |    This happens, when the player decides to end the Level. | 
|---|
 | 678 | */ | 
|---|
 | 679 | ErrorMessage World::stop() | 
|---|
 | 680 | { | 
|---|
| [3546] | 681 |   PRINTF(3)("World::stop() - got stop signal\n"); | 
|---|
| [3459] | 682 |   this->bQuitCurrentGame = true; | 
|---|
 | 683 | } | 
|---|
 | 684 |  | 
|---|
 | 685 | /** | 
|---|
| [4836] | 686 |  *  pauses the Game | 
|---|
| [3459] | 687 | */ | 
|---|
 | 688 | ErrorMessage World::pause() | 
|---|
 | 689 | { | 
|---|
 | 690 |   this->isPaused = true; | 
|---|
 | 691 | } | 
|---|
 | 692 |  | 
|---|
 | 693 | /** | 
|---|
| [4836] | 694 |  *  ends the pause Phase | 
|---|
| [3459] | 695 | */ | 
|---|
 | 696 | ErrorMessage World::resume() | 
|---|
 | 697 | { | 
|---|
 | 698 |   this->isPaused = false; | 
|---|
 | 699 | } | 
|---|
 | 700 |  | 
|---|
 | 701 | /** | 
|---|
| [4836] | 702 |  *  destroys the World | 
|---|
| [3459] | 703 | */ | 
|---|
 | 704 | ErrorMessage World::destroy() | 
|---|
 | 705 | { | 
|---|
| [3566] | 706 |  | 
|---|
| [3459] | 707 | } | 
|---|
 | 708 |  | 
|---|
 | 709 | /** | 
|---|
| [4836] | 710 |  *  shows the loading screen | 
|---|
| [3459] | 711 | */ | 
|---|
 | 712 | void World::displayLoadScreen () | 
|---|
 | 713 | { | 
|---|
| [4555] | 714 |   PRINTF(3)("World::displayLoadScreen - start\n"); | 
|---|
 | 715 |  | 
|---|
 | 716 |   //GLMenuImageScreen* | 
|---|
| [4099] | 717 |   this->glmis = new GLMenuImageScreen(); | 
|---|
| [3675] | 718 |   this->glmis->setMaximum(8); | 
|---|
| [4555] | 719 |  | 
|---|
 | 720 |   PRINTF(3)("World::displayLoadScreen - end\n"); | 
|---|
| [3459] | 721 | } | 
|---|
 | 722 |  | 
|---|
 | 723 | /** | 
|---|
| [4836] | 724 |  *  removes the loadscreen, and changes over to the game | 
|---|
| [3459] | 725 |  | 
|---|
| [4836] | 726 |    @todo take out the delay | 
|---|
| [3459] | 727 | */ | 
|---|
 | 728 | void World::releaseLoadScreen () | 
|---|
 | 729 | { | 
|---|
| [4555] | 730 |   PRINTF(3)("World::releaseLoadScreen - start\n"); | 
|---|
| [3459] | 731 |   this->glmis->setValue(this->glmis->getMaximum()); | 
|---|
| [4555] | 732 |   PRINTF(3)("World::releaseLoadScreen - end\n"); | 
|---|
| [4099] | 733 |   delete this->glmis; | 
|---|
| [3459] | 734 | } | 
|---|
 | 735 |  | 
|---|
 | 736 |  | 
|---|
| [3620] | 737 | /** | 
|---|
| [4836] | 738 |  *  gets the list of entities from the world | 
|---|
 | 739 |  * @returns entity list | 
|---|
| [3620] | 740 | */ | 
|---|
 | 741 | tList<WorldEntity>* World::getEntities() | 
|---|
 | 742 | { | 
|---|
 | 743 |   return this->entities; | 
|---|
 | 744 | } | 
|---|
 | 745 |  | 
|---|
 | 746 |  | 
|---|
| [3646] | 747 | /** | 
|---|
| [4836] | 748 |  *  this returns the current game time | 
|---|
 | 749 |  * @returns elapsed game time | 
|---|
| [3646] | 750 | */ | 
|---|
 | 751 | double World::getGameTime() | 
|---|
 | 752 | { | 
|---|
 | 753 |   return this->gameTime; | 
|---|
 | 754 | } | 
|---|
 | 755 |  | 
|---|
 | 756 |  | 
|---|
| [4555] | 757 | /** | 
|---|
| [4836] | 758 |  *  function to put your own debug stuff into it. it can display informations about | 
|---|
| [3225] | 759 |    the current class/procedure | 
|---|
 | 760 | */ | 
|---|
| [2640] | 761 | void World::debug() | 
|---|
 | 762 | { | 
|---|
| [5115] | 763 |   PRINTF(0)("Printing out the List of alive WorldEntities:\n"); | 
|---|
 | 764 |   tIterator<WorldEntity>* iterator = this->entities->getIterator(); | 
|---|
 | 765 |   WorldEntity* entity = iterator->firstElement(); | 
|---|
 | 766 |   while( entity != NULL) | 
|---|
 | 767 |   { | 
|---|
 | 768 |     PRINTF(0)("%s::%s\n", entity->getClassName(), entity->getName()); | 
|---|
 | 769 |     entity = iterator->nextElement(); | 
|---|
 | 770 |   } | 
|---|
 | 771 |   delete iterator; | 
|---|
| [2640] | 772 | } | 
|---|
| [2636] | 773 |  | 
|---|
| [2640] | 774 |  | 
|---|
| [3449] | 775 | /** | 
|---|
| [3225] | 776 |   \brief main loop of the world: executing all world relevant function | 
|---|
 | 777 |  | 
|---|
 | 778 |   in this loop we synchronize (if networked), handle input events, give the heart-beat to | 
|---|
 | 779 |   all other member-entities of the world (tick to player, enemies etc.), checking for | 
|---|
 | 780 |   collisions drawing everything to the screen. | 
|---|
 | 781 | */ | 
|---|
| [2636] | 782 | void World::mainLoop() | 
|---|
 | 783 | { | 
|---|
| [3365] | 784 |   this->lastFrame = SDL_GetTicks (); | 
|---|
| [3546] | 785 |   PRINTF(3)("World::mainLoop() - Entering main loop\n"); | 
|---|
| [5045] | 786 |  | 
|---|
| [4836] | 787 |   while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* @todo implement pause */ | 
|---|
| [2551] | 788 |     { | 
|---|
| [4558] | 789 |       ++this->cycle; | 
|---|
| [5048] | 790 |       PRINTF(4)("World::mainloop() - number of entities: %i\n", this->entities->getSize()); | 
|---|
| [2636] | 791 |       // Network | 
|---|
| [3365] | 792 |       this->synchronize (); | 
|---|
| [2636] | 793 |       // Process input | 
|---|
| [3365] | 794 |       this->handleInput (); | 
|---|
| [3215] | 795 |       if( this->bQuitCurrentGame || this->bQuitOrxonox) | 
|---|
| [4555] | 796 |           break; | 
|---|
| [2636] | 797 |       // Process time | 
|---|
| [3551] | 798 |       this->tick (); | 
|---|
| [5045] | 799 |       // Process collision | 
|---|
 | 800 |       this->collide (); | 
|---|
| [3551] | 801 |       // Update the state | 
|---|
| [4555] | 802 |       this->update (); | 
|---|
| [2636] | 803 |       // Draw | 
|---|
| [3365] | 804 |       this->display (); | 
|---|
| [5045] | 805 |     } | 
|---|
| [3548] | 806 |  | 
|---|
| [3546] | 807 |   PRINTF(3)("World::mainLoop() - Exiting the main loop\n"); | 
|---|
| [1899] | 808 | } | 
|---|
 | 809 |  | 
|---|
| [3459] | 810 |  | 
|---|
| [2190] | 811 | /** | 
|---|
| [4836] | 812 |  *  synchronize local data with remote data | 
|---|
| [1855] | 813 | */ | 
|---|
| [2636] | 814 | void World::synchronize () | 
|---|
| [1855] | 815 | { | 
|---|
| [2636] | 816 |   // Get remote input | 
|---|
 | 817 |   // Update synchronizables | 
|---|
| [1855] | 818 | } | 
|---|
| [2636] | 819 |  | 
|---|
| [3459] | 820 |  | 
|---|
| [2636] | 821 | /** | 
|---|
| [4836] | 822 |  *  run all input processing | 
|---|
| [3225] | 823 |  | 
|---|
 | 824 |    the command node is the central input event dispatcher. the node uses the even-queue from | 
|---|
 | 825 |    sdl and has its own event-passing-queue. | 
|---|
| [2636] | 826 | */ | 
|---|
| [3225] | 827 | void World::handleInput () | 
|---|
| [2636] | 828 | { | 
|---|
 | 829 |   // localinput | 
|---|
| [4407] | 830 |   //CommandNode* cn = Orxonox::getInstance()->getLocalInput(); | 
|---|
 | 831 |   //cn->process(); | 
|---|
 | 832 |  | 
|---|
 | 833 |   EventHandler::getInstance()->process(); | 
|---|
 | 834 |  | 
|---|
| [2636] | 835 |   // remoteinput | 
|---|
 | 836 | } | 
|---|
 | 837 |  | 
|---|
| [3459] | 838 |  | 
|---|
| [2636] | 839 | /** | 
|---|
| [4836] | 840 |  *  advance the timeline | 
|---|
| [3225] | 841 |  | 
|---|
 | 842 |    this calculates the time used to process one frame (with all input handling, drawing, etc) | 
|---|
 | 843 |    the time is mesured in ms and passed to all world-entities and other classes that need | 
|---|
 | 844 |    a heart-beat. | 
|---|
| [2636] | 845 | */ | 
|---|
| [3551] | 846 | void World::tick () | 
|---|
| [2636] | 847 | { | 
|---|
 | 848 |   Uint32 currentFrame = SDL_GetTicks(); | 
|---|
 | 849 |   if(!this->bPause) | 
|---|
 | 850 |     { | 
|---|
| [3644] | 851 |       this->dt = currentFrame - this->lastFrame; | 
|---|
| [4555] | 852 |  | 
|---|
| [4610] | 853 |       if( this->dt > 10) | 
|---|
| [4555] | 854 |         { | 
|---|
 | 855 |           float fps = 1000/dt; | 
|---|
| [3790] | 856 |  | 
|---|
| [4555] | 857 |           // temporary, only for showing how fast the text-engine is | 
|---|
 | 858 |           char tmpChar[20]; | 
|---|
 | 859 |           sprintf(tmpChar, "fps: %4.0f", fps); | 
|---|
 | 860 |         } | 
|---|
| [2636] | 861 |       else | 
|---|
| [4555] | 862 |         { | 
|---|
 | 863 |           /* the frame-rate is limited to 100 frames per second, all other things are for | 
|---|
 | 864 |              nothing. | 
|---|
 | 865 |           */ | 
|---|
| [5048] | 866 |           PRINTF(3)("fps = 1000 - frame rate is adjusted\n"); | 
|---|
| [4610] | 867 |           SDL_Delay(10-dt); | 
|---|
| [4555] | 868 |           this->dt = 10; | 
|---|
 | 869 |         } | 
|---|
 | 870 |  | 
|---|
 | 871 |       this->dtS = (float)this->dt / 1000.0; | 
|---|
| [4145] | 872 |       this->gameTime += this->dtS; | 
|---|
| [4833] | 873 |  | 
|---|
| [3654] | 874 |       tIterator<WorldEntity>* iterator = this->entities->getIterator(); | 
|---|
| [5115] | 875 |       WorldEntity* entity = iterator->firstElement(); | 
|---|
| [4555] | 876 |       while( entity != NULL) | 
|---|
 | 877 |         { | 
|---|
 | 878 |           entity->tick (this->dtS); | 
|---|
 | 879 |           entity = iterator->nextElement(); | 
|---|
 | 880 |         } | 
|---|
| [3654] | 881 |       delete iterator; | 
|---|
| [4010] | 882 |  | 
|---|
| [3459] | 883 |       /* update tick the rest */ | 
|---|
| [4959] | 884 |       TrackManager::getInstance()->tick(this->dtS); | 
|---|
| [4832] | 885 |       this->localCamera->tick(this->dtS); | 
|---|
| [4558] | 886 |       // tick the engines | 
|---|
| [4245] | 887 |       AnimationPlayer::getInstance()->tick(this->dtS); | 
|---|
| [4979] | 888 | //      if (this->cycle > 5) | 
|---|
| [4558] | 889 |         PhysicsEngine::getInstance()->tick(this->dtS); | 
|---|
| [4396] | 890 |  | 
|---|
| [4558] | 891 |       ParticleEngine::getInstance()->tick(this->dtS); | 
|---|
 | 892 |       GarbageCollector::getInstance()->tick(this->dtS); | 
|---|
| [4396] | 893 |  | 
|---|
| [4831] | 894 |  | 
|---|
| [4558] | 895 |       /** actualy the Graphics Engine should tick the world not the other way around... | 
|---|
| [4555] | 896 |          but since we like the things not too complicated we got it this way around | 
|---|
 | 897 |          until there is need or time to do it the other way around. | 
|---|
| [4836] | 898 |          @todo: GraphicsEngine ticks world: separation of processes and data... | 
|---|
| [4681] | 899 |  | 
|---|
 | 900 |         bensch: in my opinion the GraphicsEngine could draw the world, but not tick it, | 
|---|
 | 901 |          beceause graphics have nothing(or at least not much) to do with Motion. | 
|---|
| [4245] | 902 |       */ | 
|---|
 | 903 |       GraphicsEngine::getInstance()->tick(this->dtS); | 
|---|
| [2636] | 904 |     } | 
|---|
 | 905 |   this->lastFrame = currentFrame; | 
|---|
 | 906 | } | 
|---|
 | 907 |  | 
|---|
| [3216] | 908 |  | 
|---|
| [2636] | 909 | /** | 
|---|
| [4836] | 910 |  *  this function gives the world a consistant state | 
|---|
| [3551] | 911 |  | 
|---|
 | 912 |    after ticking (updating the world state) this will give a constistant | 
|---|
 | 913 |    state to the whole system. | 
|---|
 | 914 | */ | 
|---|
 | 915 | void World::update() | 
|---|
 | 916 | { | 
|---|
| [4822] | 917 |   GarbageCollector::getInstance()->update(); | 
|---|
| [4978] | 918 |   NullParent::getInstance()->update (this->dtS); | 
|---|
| [5084] | 919 |   GraphicsEngine::getInstance()->update(this->dtS); | 
|---|
| [4504] | 920 |  | 
|---|
 | 921 |   SoundEngine::getInstance()->update(); | 
|---|
| [4978] | 922 |   //music->update(); | 
|---|
| [3551] | 923 | } | 
|---|
 | 924 |  | 
|---|
 | 925 |  | 
|---|
| [4917] | 926 | void World::collide() | 
|---|
 | 927 | { | 
|---|
| [4918] | 928 |   CDEngine::getInstance()->checkCollisions(); | 
|---|
| [4917] | 929 | } | 
|---|
 | 930 |  | 
|---|
| [3551] | 931 | /** | 
|---|
| [4836] | 932 |  *  render the current frame | 
|---|
| [4555] | 933 |  | 
|---|
| [3225] | 934 |    clear all buffers and draw the world | 
|---|
| [2636] | 935 | */ | 
|---|
 | 936 | void World::display () | 
|---|
 | 937 | { | 
|---|
 | 938 |   // clear buffer | 
|---|
 | 939 |   glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); | 
|---|
 | 940 |   // set camera | 
|---|
 | 941 |   this->localCamera->apply (); | 
|---|
 | 942 |   // draw world | 
|---|
 | 943 |   this->draw(); | 
|---|
 | 944 |   // draw HUD | 
|---|
| [4837] | 945 |   /** @todo draw HUD */ | 
|---|
| [2636] | 946 |   // flip buffers | 
|---|
| [4681] | 947 |   GraphicsEngine::swapBuffers(); | 
|---|
| [3365] | 948 |   //SDL_Surface* screen = Orxonox::getInstance()->getScreen (); | 
|---|
 | 949 |   //SDL_Flip (screen); | 
|---|
| [2636] | 950 | } | 
|---|
 | 951 |  | 
|---|
| [2644] | 952 |  | 
|---|
| [3225] | 953 | /** | 
|---|
| [4917] | 954 |  *  runs through all entities calling their draw() methods | 
|---|
 | 955 |  */ | 
|---|
 | 956 | void World::draw () | 
|---|
 | 957 | { | 
|---|
 | 958 |   /* draw entities */ | 
|---|
 | 959 |   WorldEntity* entity; | 
|---|
 | 960 |   glLoadIdentity(); | 
|---|
 | 961 |   tIterator<WorldEntity>* iterator = this->entities->getIterator(); | 
|---|
| [5115] | 962 |   entity = iterator->firstElement(); | 
|---|
| [4917] | 963 |   while( entity != NULL ) | 
|---|
 | 964 |   { | 
|---|
| [5055] | 965 |     if( entity->isVisible() ) entity->draw(); | 
|---|
 | 966 |     //entity->drawBVTree(2, 226);  // to draw the bounding boxes of the objects at level 2 for debug purp | 
|---|
| [4917] | 967 |     entity = iterator->nextElement(); | 
|---|
 | 968 |   } | 
|---|
 | 969 |   delete iterator; | 
|---|
 | 970 |  | 
|---|
 | 971 |   glCallList (objectList); | 
|---|
 | 972 |  | 
|---|
 | 973 |   ParticleEngine::getInstance()->draw(); | 
|---|
 | 974 |  | 
|---|
 | 975 |   GraphicsEngine::getInstance()->draw(); | 
|---|
 | 976 |   //TextEngine::getInstance()->draw(); | 
|---|
 | 977 | } | 
|---|
 | 978 |  | 
|---|
 | 979 | /** | 
|---|
| [4836] | 980 |  *  add and spawn a new entity to this world | 
|---|
 | 981 |  * @param entity to be added | 
|---|
| [3225] | 982 | */ | 
|---|
| [2644] | 983 | void World::spawn(WorldEntity* entity) | 
|---|
 | 984 | { | 
|---|
| [3365] | 985 |   this->entities->add (entity); | 
|---|
| [3233] | 986 |   entity->postSpawn (); | 
|---|
| [2816] | 987 | } | 
|---|
 | 988 |  | 
|---|
 | 989 |  | 
|---|
| [3225] | 990 | /** | 
|---|
| [4836] | 991 |  *  add and spawn a new entity to this world | 
|---|
 | 992 |  * @param entity to be added | 
|---|
 | 993 |  * @param absCoor At what coordinates to add this entity. | 
|---|
 | 994 |  * @param absDir In which direction should it look. | 
|---|
| [3225] | 995 | */ | 
|---|
| [3365] | 996 | void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir) | 
|---|
| [2816] | 997 | { | 
|---|
| [3529] | 998 |   this->entities->add (entity); | 
|---|
 | 999 |  | 
|---|
| [3809] | 1000 |   entity->setAbsCoor (*absCoor); | 
|---|
 | 1001 |   entity->setAbsDir (*absDir); | 
|---|
| [3365] | 1002 |  | 
|---|
| [3233] | 1003 |   entity->postSpawn (); | 
|---|
| [2644] | 1004 | } | 
|---|
| [2816] | 1005 |  | 
|---|
 | 1006 |  | 
|---|
| [3521] | 1007 | /** | 
|---|
| [4836] | 1008 |  *  add and spawn a new entity to this world | 
|---|
 | 1009 |  * @param entity to be added | 
|---|
 | 1010 |  * @param entity to be added to (PNode) | 
|---|
 | 1011 |  * @param At what relative  coordinates to add this entity. | 
|---|
 | 1012 |  * @param In which relative direction should it look. | 
|---|
| [3521] | 1013 | */ | 
|---|
| [4555] | 1014 | void World::spawn(WorldEntity* entity, PNode* parentNode, | 
|---|
| [4765] | 1015 |                   Vector* relCoor, Quaternion* relDir) | 
|---|
| [3521] | 1016 | { | 
|---|
| [4978] | 1017 |   NullParent::getInstance(); | 
|---|
| [3529] | 1018 |   if( parentNode != NULL) | 
|---|
| [3521] | 1019 |     { | 
|---|
 | 1020 |       parentNode->addChild (entity); | 
|---|
| [4555] | 1021 |  | 
|---|
| [3809] | 1022 |       entity->setRelCoor (*relCoor); | 
|---|
 | 1023 |       entity->setRelDir (*relDir); | 
|---|
| [4555] | 1024 |  | 
|---|
| [3521] | 1025 |       this->entities->add (entity); | 
|---|
| [4555] | 1026 |  | 
|---|
| [3521] | 1027 |       entity->postSpawn (); | 
|---|
 | 1028 |     } | 
|---|
 | 1029 | } | 
|---|
 | 1030 |  | 
|---|
 | 1031 |  | 
|---|
 | 1032 |  | 
|---|
| [3449] | 1033 | /** | 
|---|
| [3225] | 1034 |   \brief commands that the world must catch | 
|---|
| [4836] | 1035 |   @returns false if not used by the world | 
|---|
| [3225] | 1036 | */ | 
|---|
| [3216] | 1037 | bool World::command(Command* cmd) | 
|---|
 | 1038 | { | 
|---|
| [4091] | 1039 |   if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW0)) this->localCamera->setViewMode(VIEW_NORMAL); | 
|---|
 | 1040 |   else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW1)) this->localCamera->setViewMode(VIEW_BEHIND); | 
|---|
 | 1041 |   else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW2)) this->localCamera->setViewMode(VIEW_FRONT); | 
|---|
 | 1042 |   else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW3)) this->localCamera->setViewMode(VIEW_LEFT); | 
|---|
 | 1043 |   else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW4)) this->localCamera->setViewMode(VIEW_RIGHT); | 
|---|
 | 1044 |   else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW5)) this->localCamera->setViewMode(VIEW_TOP); | 
|---|
| [3216] | 1045 |   return false; | 
|---|
 | 1046 | } | 
|---|
| [3365] | 1047 |  | 
|---|
| [4010] | 1048 | void World::setPath( const char* name) | 
|---|
 | 1049 | { | 
|---|
| [4094] | 1050 |   if (this->path) | 
|---|
 | 1051 |     delete this->path; | 
|---|
 | 1052 |   if (ResourceManager::isFile(name)) | 
|---|
 | 1053 |   { | 
|---|
 | 1054 |     this->path = new char[strlen(name)+1]; | 
|---|
 | 1055 |     strcpy(this->path, name); | 
|---|
 | 1056 |   } | 
|---|
 | 1057 |   else | 
|---|
 | 1058 |     { | 
|---|
 | 1059 |       this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1]; | 
|---|
 | 1060 |       sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name); | 
|---|
 | 1061 |     } | 
|---|
| [4010] | 1062 | } | 
|---|
 | 1063 |  | 
|---|
 | 1064 | const char* World::getPath( void) | 
|---|
 | 1065 | { | 
|---|
 | 1066 |   return path; | 
|---|
 | 1067 | } | 
|---|