[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 | { |
---|
[3546] | 117 | PRINTF(3)("World::~World() - deleting current world\n"); |
---|
[3677] | 118 | |
---|
[4726] | 119 | ParticleEngine::getInstance()->debug(); |
---|
| 120 | |
---|
[4978] | 121 | // here everything that is alocated by the World is deleted |
---|
[4837] | 122 | delete this->entities; |
---|
[4830] | 123 | State::setWorldEntityList(NULL); |
---|
| 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 |
---|
[3790] | 132 | TextEngine::getInstance()->flush(); |
---|
[4504] | 133 | SoundEngine::getInstance()->flushAllBuffers(); |
---|
[4830] | 134 | SoundEngine::getInstance()->flushAllSources(); |
---|
[4979] | 135 | FastFactory::flushAll(true); |
---|
[4504] | 136 | |
---|
[4978] | 137 | // erease everything that is left. |
---|
[4870] | 138 | delete NullParent::getInstance(); |
---|
[4872] | 139 | |
---|
[4961] | 140 | |
---|
[4978] | 141 | // unload the resources !! |
---|
[4961] | 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 */ |
---|
[4010] | 197 | |
---|
[4735] | 198 | LightManager::getInstance(); |
---|
[4978] | 199 | NullParent::getInstance (); |
---|
[3993] | 200 | |
---|
[4010] | 201 | AnimationPlayer::getInstance(); // initializes the animationPlayer |
---|
[4338] | 202 | PhysicsEngine::getInstance(); |
---|
[4010] | 203 | |
---|
[4015] | 204 | this->localCamera = new Camera(); |
---|
[4978] | 205 | this->localCamera->setName ("World-Camera"); |
---|
[4555] | 206 | |
---|
[4827] | 207 | State::setCamera(this->localCamera, this->localCamera->getTarget()); |
---|
[4347] | 208 | |
---|
[4245] | 209 | GraphicsEngine::getInstance()->displayFPS(true); |
---|
[4918] | 210 | |
---|
| 211 | CDEngine::getInstance()->setEntityList( this->entities); |
---|
[3526] | 212 | } |
---|
| 213 | |
---|
| 214 | |
---|
[3449] | 215 | /** |
---|
[4836] | 216 | * loads the World by initializing all resources, and set their default values. |
---|
[3449] | 217 | */ |
---|
[3459] | 218 | ErrorMessage World::load() |
---|
[4555] | 219 | { |
---|
[4104] | 220 | PRINTF(3)("> Loading world: '%s'\n", getPath()); |
---|
| 221 | TiXmlElement* element; |
---|
[4010] | 222 | GameLoader* loader = GameLoader::getInstance(); |
---|
[4555] | 223 | |
---|
[4010] | 224 | if( getPath() == NULL) |
---|
[2636] | 225 | { |
---|
[4104] | 226 | PRINTF(1)("World has no path specified for loading"); |
---|
[4324] | 227 | this->loadDebugWorld(this->getStoryID()); |
---|
[4010] | 228 | return (ErrorMessage){213,"Path not specified","World::load()"}; |
---|
| 229 | } |
---|
[4555] | 230 | |
---|
[4010] | 231 | TiXmlDocument* XMLDoc = new TiXmlDocument( path); |
---|
| 232 | // load the campaign document |
---|
[4555] | 233 | if( !XMLDoc->LoadFile()) |
---|
[4010] | 234 | { |
---|
| 235 | // report an error |
---|
[4104] | 236 | PRINTF(1)("loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); |
---|
[4010] | 237 | delete XMLDoc; |
---|
| 238 | return (ErrorMessage){213,"XML File parsing error","World::load()"}; |
---|
| 239 | } |
---|
[4555] | 240 | |
---|
[4010] | 241 | // check basic validity |
---|
| 242 | TiXmlElement* root = XMLDoc->RootElement(); |
---|
| 243 | assert( root != NULL); |
---|
[4555] | 244 | |
---|
[4010] | 245 | if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile")) |
---|
| 246 | { |
---|
| 247 | // report an error |
---|
[4104] | 248 | PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n"); |
---|
[4010] | 249 | delete XMLDoc; |
---|
| 250 | return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"}; |
---|
| 251 | } |
---|
[4555] | 252 | |
---|
[4010] | 253 | // load the parameters |
---|
| 254 | // name |
---|
| 255 | char* temp; |
---|
| 256 | const char* string = grabParameter( root, "name"); |
---|
| 257 | if( string == NULL) |
---|
| 258 | { |
---|
[4104] | 259 | PRINTF(2)("World is missing a proper 'name'\n"); |
---|
[4010] | 260 | string = "Unknown"; |
---|
| 261 | temp = new char[strlen(string + 2)]; |
---|
| 262 | strcpy( temp, string); |
---|
[4978] | 263 | this->setName(temp); |
---|
[4010] | 264 | } |
---|
| 265 | else |
---|
| 266 | { |
---|
| 267 | temp = new char[strlen(string + 2)]; |
---|
| 268 | strcpy( temp, string); |
---|
[4978] | 269 | this->setName(temp); |
---|
[4010] | 270 | } |
---|
[4978] | 271 | |
---|
[4104] | 272 | //////////////// |
---|
| 273 | // LOADSCREEN // |
---|
| 274 | //////////////// |
---|
| 275 | element = root->FirstChildElement("LoadScreen"); |
---|
| 276 | if (element == NULL) |
---|
| 277 | { |
---|
| 278 | PRINTF(2)("no LoadScreen specified, loading default\n"); |
---|
| 279 | |
---|
| 280 | glmis->setBackgroundImage("pictures/load_screen.jpg"); |
---|
| 281 | this->glmis->setMaximum(8); |
---|
| 282 | this->glmis->draw(); |
---|
| 283 | } |
---|
| 284 | else |
---|
| 285 | { |
---|
[4261] | 286 | this->glmis->loadParams(element); |
---|
[4104] | 287 | this->glmis->draw(); |
---|
| 288 | } |
---|
| 289 | this->glmis->draw(); |
---|
[4726] | 290 | |
---|
| 291 | //////////////////////// |
---|
| 292 | // find WorldEntities // |
---|
| 293 | //////////////////////// |
---|
| 294 | |
---|
[4104] | 295 | element = root->FirstChildElement("WorldEntities"); |
---|
[4555] | 296 | |
---|
[4010] | 297 | if( element == NULL) |
---|
| 298 | { |
---|
[4104] | 299 | PRINTF(1)("World is missing 'WorldEntities'\n"); |
---|
[4010] | 300 | } |
---|
| 301 | else |
---|
| 302 | { |
---|
| 303 | element = element->FirstChildElement(); |
---|
| 304 | // load Players/Objects/Whatever |
---|
[4104] | 305 | PRINTF(4)("Loading WorldEntities\n"); |
---|
[4010] | 306 | while( element != NULL) |
---|
[4555] | 307 | { |
---|
| 308 | WorldEntity* created = dynamic_cast<WorldEntity*>( loader->fabricate( element)); |
---|
| 309 | if( created != NULL) this->spawn( created); |
---|
| 310 | // if we load a 'Player' we use it as localPlayer |
---|
| 311 | //todo do this more elegant |
---|
[4919] | 312 | if( element->Value() != NULL && !strcmp( element->Value(), "Player")) |
---|
| 313 | { |
---|
| 314 | localPlayer = (Player*) created; |
---|
| 315 | CDEngine::getInstance()->setPlayer(localPlayer); |
---|
| 316 | } |
---|
[4555] | 317 | if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) sky = (SkyBox*) created; |
---|
[4918] | 318 | if( element->Value() != NULL && !strcmp( element->Value(), "Terrain")) |
---|
| 319 | { |
---|
| 320 | terrain = (Terrain*) created; |
---|
| 321 | CDEngine::getInstance()->setTerrain(terrain); |
---|
| 322 | } |
---|
[4555] | 323 | element = element->NextSiblingElement(); |
---|
[4836] | 324 | glmis->step(); //! @todo temporary |
---|
[4555] | 325 | } |
---|
[4104] | 326 | PRINTF(4)("Done loading WorldEntities\n"); |
---|
[4010] | 327 | } |
---|
[4555] | 328 | |
---|
[4726] | 329 | ////////////////////////////// |
---|
| 330 | // LOADING ADDITIONAL STUFF // |
---|
| 331 | ////////////////////////////// |
---|
| 332 | |
---|
[4735] | 333 | LoadParam<LightManager>(root, "LightManager", LightManager::getInstance(), &LightManager::loadParams); |
---|
| 334 | |
---|
[4726] | 335 | LoadParam<ParticleEngine>(root, "ParticleEngine", ParticleEngine::getInstance(), &ParticleEngine::loadParams); |
---|
[4730] | 336 | LoadParam<PhysicsEngine>(root, "PhysicsEngine", PhysicsEngine::getInstance(), &PhysicsEngine::loadParams); |
---|
[4726] | 337 | |
---|
[4010] | 338 | // find Track |
---|
[4222] | 339 | element = root->FirstChildElement( "Track"); |
---|
[4010] | 340 | if( element == NULL) |
---|
| 341 | { |
---|
[4228] | 342 | PRINTF(0)("World is missing a 'Track'\n"); |
---|
[4010] | 343 | } |
---|
| 344 | else |
---|
[4555] | 345 | { |
---|
[4010] | 346 | //load track |
---|
[4228] | 347 | PRINTF(4)("Loading Track\n"); |
---|
[4010] | 348 | |
---|
[4822] | 349 | TrackManager::getInstance()->loadParams( element); |
---|
| 350 | TrackManager::getInstance()->finalize(); |
---|
[4222] | 351 | } |
---|
[4555] | 352 | |
---|
[4010] | 353 | // free the XML data |
---|
[4015] | 354 | |
---|
[4010] | 355 | delete XMLDoc; |
---|
[4015] | 356 | /* GENERIC LOADING PROCESS FINISHED */ |
---|
[4555] | 357 | |
---|
[4010] | 358 | // bind input |
---|
[4822] | 359 | EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_UP); |
---|
| 360 | EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_DOWN); |
---|
| 361 | EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_LEFT); |
---|
| 362 | EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_RIGHT); |
---|
| 363 | EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_FIRE1); |
---|
| 364 | EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_NEXT_WEAPON); |
---|
| 365 | EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
[4555] | 366 | |
---|
[4010] | 367 | // bind camera |
---|
| 368 | //this->localCamera->bind (localPlayer); |
---|
[4969] | 369 | // this->localPlayer->addChild (this->localCamera); |
---|
[4245] | 370 | |
---|
[4555] | 371 | |
---|
[4822] | 372 | // TrackManager::getInstance()->setBindSlave(env); |
---|
| 373 | PNode* tn = TrackManager::getInstance()->getTrackNode(); |
---|
[4010] | 374 | tn->addChild(this->localPlayer); |
---|
[4555] | 375 | |
---|
[4010] | 376 | //localCamera->setParent(TrackNode::getInstance()); |
---|
| 377 | tn->addChild(this->localCamera); |
---|
| 378 | localCamera->lookAt(tn); |
---|
[4444] | 379 | localCamera->setParentMode(PNODE_MOVEMENT); |
---|
[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(); |
---|
| 417 | testEntity2->setAnim(RUN); |
---|
[4721] | 418 | testEntity2->setRelCoor(Vector(2400, 25, 260)); |
---|
[4488] | 419 | testEntity2->setRelDir(Quaternion(M_PI, Vector(0, 1, 0))); |
---|
| 420 | this->spawn(testEntity2); |
---|
| 421 | |
---|
[4721] | 422 | TestEntity* testEntity3 = new TestEntity(); |
---|
[4722] | 423 | testEntity3->setAnim(RUN); |
---|
[4721] | 424 | testEntity3->setRelCoor(Vector(2400, 25, 280)); |
---|
| 425 | testEntity3->setRelDir(Quaternion(M_PI, Vector(0, 1, 0))); |
---|
| 426 | this->spawn(testEntity3); |
---|
[4488] | 427 | |
---|
[4721] | 428 | TestEntity* testEntity4 = new TestEntity(); |
---|
| 429 | testEntity4->setAnim(RUN); |
---|
| 430 | testEntity4->setRelCoor(Vector(2430, 25, 250)); |
---|
| 431 | testEntity4->setRelDir(Quaternion(M_PI, Vector(0, 1, 0))); |
---|
| 432 | this->spawn(testEntity4); |
---|
[4574] | 433 | |
---|
[4721] | 434 | |
---|
[4730] | 435 | PhysicsEngine::getInstance()->debug(); |
---|
[4721] | 436 | |
---|
[4978] | 437 | |
---|
| 438 | |
---|
[4976] | 439 | for(int i = 0; i < 100; i++) |
---|
| 440 | { |
---|
| 441 | WorldEntity* tmp = new NPC(); |
---|
| 442 | tmp->setAbsCoor(((float)rand()/RAND_MAX) * 2000, 40+ (float)rand()/RAND_MAX*30, ((float)rand()/RAND_MAX -.5) *500); |
---|
| 443 | this->spawn(tmp); |
---|
[4747] | 444 | |
---|
[4976] | 445 | |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | |
---|
| 449 | |
---|
[4747] | 450 | ClassList::debug(); |
---|
[4961] | 451 | |
---|
| 452 | this->music = (OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL); |
---|
| 453 | music->playback(); |
---|
[4010] | 454 | } |
---|
[3365] | 455 | |
---|
[4245] | 456 | |
---|
[4324] | 457 | |
---|
[4326] | 458 | /** |
---|
[4978] | 459 | * creates a debug world: only for experimental stuff |
---|
[4326] | 460 | */ |
---|
[4010] | 461 | void World::loadDebugWorld(int worldID) |
---|
| 462 | { |
---|
| 463 | /*monitor progress*/ |
---|
| 464 | this->glmis->step(); |
---|
[4228] | 465 | // stuff beyond this point remains to be loaded properly |
---|
[3194] | 466 | |
---|
[4228] | 467 | // initializing the TrackManager |
---|
[4822] | 468 | TrackManager::getInstance()->addPointV(Vector(150, -35, 5)); |
---|
| 469 | TrackManager::getInstance()->addPointV(Vector(200,-35, 5)); |
---|
| 470 | TrackManager::getInstance()->addPointV(Vector(250, -35, 5)); |
---|
| 471 | TrackManager::getInstance()->addPointV(Vector(320,-33,-.55)); |
---|
| 472 | TrackManager::getInstance()->setDuration(1); |
---|
| 473 | TrackManager::getInstance()->setSavePoint(); |
---|
[4228] | 474 | |
---|
[4822] | 475 | TrackManager::getInstance()->addPointV(Vector(410, 0, 0)); |
---|
| 476 | TrackManager::getInstance()->addPointV(Vector(510, 20, -10)); |
---|
| 477 | TrackManager::getInstance()->addPointV(Vector(550, 20, -10)); |
---|
| 478 | TrackManager::getInstance()->addPointV(Vector(570, 20, -10)); |
---|
| 479 | TrackManager::getInstance()->setDuration(2); |
---|
[4555] | 480 | |
---|
[4822] | 481 | TrackManager::getInstance()->forkS("testFork1,testFork2"); |
---|
| 482 | TrackManager::getInstance()->workOnS("testFork1"); |
---|
| 483 | TrackManager::getInstance()->addPointV(Vector(640, 25, -30)); |
---|
| 484 | TrackManager::getInstance()->addPointV(Vector(700, 40, -120)); |
---|
| 485 | TrackManager::getInstance()->addPointV(Vector(800, 50, -150)); |
---|
| 486 | TrackManager::getInstance()->addPointV(Vector(900, 60, -100)); |
---|
| 487 | TrackManager::getInstance()->addPointV(Vector(900, 60, -70)); |
---|
| 488 | TrackManager::getInstance()->addPointV(Vector(990, 65, -15)); |
---|
| 489 | TrackManager::getInstance()->addPointV(Vector(1050, 65, -10)); |
---|
| 490 | TrackManager::getInstance()->addPointV(Vector(1100, 65, -20)); |
---|
| 491 | TrackManager::getInstance()->setDuration(4); |
---|
[4228] | 492 | |
---|
[4822] | 493 | TrackManager::getInstance()->workOnS("testFork2"); |
---|
| 494 | TrackManager::getInstance()->addPointV(Vector(640, 25, 20)); |
---|
| 495 | TrackManager::getInstance()->addPointV(Vector(670, 50, 120)); |
---|
| 496 | TrackManager::getInstance()->addPointV(Vector(700, 70, 80)); |
---|
| 497 | TrackManager::getInstance()->addPointV(Vector(800, 70, 65)); |
---|
| 498 | TrackManager::getInstance()->addPointV(Vector(850, 65, 65)); |
---|
| 499 | TrackManager::getInstance()->addPointV(Vector(920, 35, 40)); |
---|
| 500 | TrackManager::getInstance()->addPointV(Vector(945, 40, 40)); |
---|
| 501 | TrackManager::getInstance()->addPointV(Vector(970, 24, 40)); |
---|
| 502 | TrackManager::getInstance()->addPointV(Vector(1000, 40, -7)); |
---|
[4508] | 503 | |
---|
[4822] | 504 | TrackManager::getInstance()->setDuration(4); |
---|
[4555] | 505 | |
---|
| 506 | |
---|
[4822] | 507 | TrackManager::getInstance()->joinS("testFork1,testFork2"); |
---|
[4555] | 508 | |
---|
[4822] | 509 | TrackManager::getInstance()->addPointV(Vector(1200, 60, -50)); |
---|
| 510 | TrackManager::getInstance()->addPointV(Vector(1300, 50, -50)); |
---|
| 511 | TrackManager::getInstance()->addPointV(Vector(1400, 40, -50)); |
---|
| 512 | TrackManager::getInstance()->addPointV(Vector(1500, 40, -60)); |
---|
| 513 | TrackManager::getInstance()->addPointV(Vector(1600, 35, -55)); |
---|
| 514 | TrackManager::getInstance()->addPointV(Vector(1700, 45, -40)); |
---|
| 515 | TrackManager::getInstance()->addPointV(Vector(1750, 60, -40)); |
---|
| 516 | TrackManager::getInstance()->addPointV(Vector(1770, 80, -40)); |
---|
| 517 | TrackManager::getInstance()->addPointV(Vector(1800, 100, -40)); |
---|
| 518 | TrackManager::getInstance()->setDuration(10); |
---|
[4555] | 519 | |
---|
[4822] | 520 | TrackManager::getInstance()->finalize(); |
---|
[4228] | 521 | |
---|
[4555] | 522 | |
---|
[4010] | 523 | // LIGHT initialisation |
---|
[4735] | 524 | LightManager::getInstance()->setAmbientColor(.1,.1,.1); |
---|
[4736] | 525 | // LightManager::getInstance()->addLight(); |
---|
[4735] | 526 | LightManager::getInstance()->debug(); |
---|
[3368] | 527 | |
---|
[4010] | 528 | switch(this->debugWorldNr) |
---|
| 529 | { |
---|
| 530 | /* |
---|
[4555] | 531 | this loads the hard-coded debug world. this only for simplicity and will be |
---|
| 532 | removed by a reald world-loader, which interprets a world-file. |
---|
| 533 | if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and |
---|
| 534 | make whatever you want... |
---|
[4010] | 535 | */ |
---|
| 536 | case DEBUG_WORLD_0: |
---|
| 537 | { |
---|
[4735] | 538 | LightManager::getInstance()->getLight()->setAbsCoor(-5.0, 10.0, -40.0); |
---|
[4010] | 539 | |
---|
| 540 | |
---|
[4555] | 541 | this->localPlayer = new Player (); |
---|
| 542 | this->localPlayer->setName ("player"); |
---|
| 543 | this->spawn (this->localPlayer); |
---|
| 544 | this->localPlayer->setRelCoor(Vector(5,0,0)); |
---|
| 545 | /*monitor progress*/ |
---|
| 546 | this->glmis->step(); |
---|
[4010] | 547 | |
---|
[4418] | 548 | |
---|
[4822] | 549 | EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_FIRE1); |
---|
| 550 | EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_NEXT_WEAPON); |
---|
| 551 | EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
[4418] | 552 | |
---|
[4555] | 553 | /* |
---|
| 554 | Field* testField = new Gravity(); |
---|
| 555 | testField->setMagnitude(10); |
---|
| 556 | new PhysicsConnection(this->localPlayer, testField); |
---|
| 557 | */ |
---|
[4397] | 558 | |
---|
[4555] | 559 | // bind camera |
---|
| 560 | this->localCamera = new Camera(); |
---|
| 561 | this->localCamera->setName ("camera"); |
---|
| 562 | /*monitor progress*/ |
---|
| 563 | this->glmis->step(); |
---|
[2816] | 564 | |
---|
[3419] | 565 | |
---|
[4555] | 566 | // Create SkySphere |
---|
[4621] | 567 | this->sky = new Skysphere("pictures/sky-replace.jpg"); |
---|
| 568 | this->sky->setName("SkySphere"); |
---|
| 569 | this->spawn(this->sky); |
---|
[4555] | 570 | this->localCamera->addChild(this->sky); |
---|
| 571 | this->sky->setParentMode(PNODE_MOVEMENT); |
---|
| 572 | /*monitor progress*/ |
---|
| 573 | this->glmis->step(); |
---|
[3368] | 574 | |
---|
[3521] | 575 | |
---|
[4555] | 576 | terrain = new Terrain("worlds/newGround.obj"); |
---|
| 577 | terrain->setRelCoor(Vector(0,-10,0)); |
---|
| 578 | this->spawn(terrain); |
---|
| 579 | /*monitor progress*/ |
---|
| 580 | this->glmis->step(); |
---|
[2816] | 581 | |
---|
[4555] | 582 | this->pilotNode = new PilotNode(); |
---|
| 583 | this->spawn(this->pilotNode); |
---|
| 584 | this->pilotNode->setAbsCoor(Vector(150, -35, 5)); |
---|
| 585 | this->pilotNode->addChild(this->localPlayer); |
---|
| 586 | this->pilotNode->addChild(this->localCamera); |
---|
| 587 | this->localCamera->lookAt(this->localPlayer); |
---|
[4422] | 588 | |
---|
[4822] | 589 | EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_UP); |
---|
| 590 | EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_DOWN); |
---|
| 591 | EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_LEFT); |
---|
| 592 | EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_RIGHT); |
---|
| 593 | EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, EV_MOUSE_MOTION); |
---|
[4422] | 594 | |
---|
[4555] | 595 | /* |
---|
[4822] | 596 | PNode* tn = TrackManager::getInstance()->getTrackNode(); |
---|
[4555] | 597 | tn->addChild(this->localPlayer); |
---|
| 598 | this->localCamera->lookAt(tn); |
---|
| 599 | |
---|
| 600 | tn->addChild(this->localCamera); |
---|
| 601 | this->localPlayer->setParentMode(PNODE_ALL); |
---|
[4822] | 602 | TrackManager::getInstance()->condition(2, LEFTRIGHT, this->localPlayer); |
---|
[4555] | 603 | */ |
---|
| 604 | this->glmis->step(); |
---|
| 605 | break; |
---|
[4010] | 606 | } |
---|
| 607 | case DEBUG_WORLD_1: |
---|
| 608 | { |
---|
[3365] | 609 | |
---|
[4555] | 610 | break; |
---|
[4010] | 611 | } |
---|
| 612 | case DEBUG_WORLD_2: |
---|
| 613 | { |
---|
[3727] | 614 | |
---|
[4555] | 615 | break; |
---|
[4010] | 616 | } |
---|
| 617 | default: |
---|
[4324] | 618 | break; |
---|
[2636] | 619 | } |
---|
[4010] | 620 | } |
---|
[2636] | 621 | |
---|
[3459] | 622 | /** |
---|
[4836] | 623 | * initializes a new World shortly before start |
---|
[4978] | 624 | * |
---|
| 625 | * this is the function, that will be loaded shortly before the world is |
---|
| 626 | * started |
---|
[3459] | 627 | */ |
---|
| 628 | ErrorMessage World::init() |
---|
| 629 | { |
---|
| 630 | this->bPause = false; |
---|
[4326] | 631 | this->pilotNode = NULL; |
---|
[3459] | 632 | } |
---|
| 633 | |
---|
| 634 | |
---|
| 635 | /** |
---|
[4836] | 636 | * starts the World |
---|
[3459] | 637 | */ |
---|
| 638 | ErrorMessage World::start() |
---|
| 639 | { |
---|
[3546] | 640 | PRINTF(3)("World::start() - starting current World: nr %i\n", this->debugWorldNr); |
---|
[3459] | 641 | this->bQuitOrxonox = false; |
---|
| 642 | this->bQuitCurrentGame = false; |
---|
| 643 | this->mainLoop(); |
---|
| 644 | } |
---|
| 645 | |
---|
| 646 | /** |
---|
[4836] | 647 | * stops the world. |
---|
[3459] | 648 | |
---|
| 649 | This happens, when the player decides to end the Level. |
---|
| 650 | */ |
---|
| 651 | ErrorMessage World::stop() |
---|
| 652 | { |
---|
[3546] | 653 | PRINTF(3)("World::stop() - got stop signal\n"); |
---|
[3459] | 654 | this->bQuitCurrentGame = true; |
---|
| 655 | } |
---|
| 656 | |
---|
| 657 | /** |
---|
[4836] | 658 | * pauses the Game |
---|
[3459] | 659 | */ |
---|
| 660 | ErrorMessage World::pause() |
---|
| 661 | { |
---|
| 662 | this->isPaused = true; |
---|
| 663 | } |
---|
| 664 | |
---|
| 665 | /** |
---|
[4836] | 666 | * ends the pause Phase |
---|
[3459] | 667 | */ |
---|
| 668 | ErrorMessage World::resume() |
---|
| 669 | { |
---|
| 670 | this->isPaused = false; |
---|
| 671 | } |
---|
| 672 | |
---|
| 673 | /** |
---|
[4836] | 674 | * destroys the World |
---|
[3459] | 675 | */ |
---|
| 676 | ErrorMessage World::destroy() |
---|
| 677 | { |
---|
[3566] | 678 | |
---|
[3459] | 679 | } |
---|
| 680 | |
---|
| 681 | /** |
---|
[4836] | 682 | * shows the loading screen |
---|
[3459] | 683 | */ |
---|
| 684 | void World::displayLoadScreen () |
---|
| 685 | { |
---|
[4555] | 686 | PRINTF(3)("World::displayLoadScreen - start\n"); |
---|
| 687 | |
---|
| 688 | //GLMenuImageScreen* |
---|
[4099] | 689 | this->glmis = new GLMenuImageScreen(); |
---|
[3675] | 690 | this->glmis->setMaximum(8); |
---|
[4555] | 691 | |
---|
| 692 | PRINTF(3)("World::displayLoadScreen - end\n"); |
---|
[3459] | 693 | } |
---|
| 694 | |
---|
| 695 | /** |
---|
[4836] | 696 | * removes the loadscreen, and changes over to the game |
---|
[3459] | 697 | |
---|
[4836] | 698 | @todo take out the delay |
---|
[3459] | 699 | */ |
---|
| 700 | void World::releaseLoadScreen () |
---|
| 701 | { |
---|
[4555] | 702 | PRINTF(3)("World::releaseLoadScreen - start\n"); |
---|
[3459] | 703 | this->glmis->setValue(this->glmis->getMaximum()); |
---|
[4555] | 704 | PRINTF(3)("World::releaseLoadScreen - end\n"); |
---|
[4099] | 705 | delete this->glmis; |
---|
[3459] | 706 | } |
---|
| 707 | |
---|
| 708 | |
---|
[3620] | 709 | /** |
---|
[4836] | 710 | * gets the list of entities from the world |
---|
| 711 | * @returns entity list |
---|
[3620] | 712 | */ |
---|
| 713 | tList<WorldEntity>* World::getEntities() |
---|
| 714 | { |
---|
| 715 | return this->entities; |
---|
| 716 | } |
---|
| 717 | |
---|
| 718 | |
---|
[3646] | 719 | /** |
---|
[4836] | 720 | * this returns the current game time |
---|
| 721 | * @returns elapsed game time |
---|
[3646] | 722 | */ |
---|
| 723 | double World::getGameTime() |
---|
| 724 | { |
---|
| 725 | return this->gameTime; |
---|
| 726 | } |
---|
| 727 | |
---|
| 728 | |
---|
[4555] | 729 | /** |
---|
[4836] | 730 | * function to put your own debug stuff into it. it can display informations about |
---|
[3225] | 731 | the current class/procedure |
---|
| 732 | */ |
---|
[2640] | 733 | void World::debug() |
---|
| 734 | { |
---|
| 735 | } |
---|
[2636] | 736 | |
---|
[2640] | 737 | |
---|
[3449] | 738 | /** |
---|
[3225] | 739 | \brief main loop of the world: executing all world relevant function |
---|
| 740 | |
---|
| 741 | in this loop we synchronize (if networked), handle input events, give the heart-beat to |
---|
| 742 | all other member-entities of the world (tick to player, enemies etc.), checking for |
---|
| 743 | collisions drawing everything to the screen. |
---|
| 744 | */ |
---|
[2636] | 745 | void World::mainLoop() |
---|
| 746 | { |
---|
[3365] | 747 | this->lastFrame = SDL_GetTicks (); |
---|
[3546] | 748 | PRINTF(3)("World::mainLoop() - Entering main loop\n"); |
---|
[4836] | 749 | while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* @todo implement pause */ |
---|
[2551] | 750 | { |
---|
[4558] | 751 | ++this->cycle; |
---|
[3546] | 752 | PRINTF(3)("World::mainloop() - number of entities: %i\n", this->entities->getSize()); |
---|
[2636] | 753 | // Network |
---|
[3365] | 754 | this->synchronize (); |
---|
[2636] | 755 | // Process input |
---|
[3365] | 756 | this->handleInput (); |
---|
[3215] | 757 | if( this->bQuitCurrentGame || this->bQuitOrxonox) |
---|
[4555] | 758 | break; |
---|
[4921] | 759 | // Process collision |
---|
| 760 | this->collide (); |
---|
[2636] | 761 | // Process time |
---|
[3551] | 762 | this->tick (); |
---|
| 763 | // Update the state |
---|
[4555] | 764 | this->update (); |
---|
[2636] | 765 | // Draw |
---|
[3365] | 766 | this->display (); |
---|
[3548] | 767 | |
---|
[3565] | 768 | // for( int i = 0; i < 5000000; i++) {} |
---|
[4836] | 769 | /* @todo this is to slow down the program for openGl Software emulator computers, reimplement*/ |
---|
[2551] | 770 | } |
---|
[3546] | 771 | PRINTF(3)("World::mainLoop() - Exiting the main loop\n"); |
---|
[1899] | 772 | } |
---|
| 773 | |
---|
[3459] | 774 | |
---|
[2190] | 775 | /** |
---|
[4836] | 776 | * synchronize local data with remote data |
---|
[1855] | 777 | */ |
---|
[2636] | 778 | void World::synchronize () |
---|
[1855] | 779 | { |
---|
[2636] | 780 | // Get remote input |
---|
| 781 | // Update synchronizables |
---|
[1855] | 782 | } |
---|
[2636] | 783 | |
---|
[3459] | 784 | |
---|
[2636] | 785 | /** |
---|
[4836] | 786 | * run all input processing |
---|
[3225] | 787 | |
---|
| 788 | the command node is the central input event dispatcher. the node uses the even-queue from |
---|
| 789 | sdl and has its own event-passing-queue. |
---|
[2636] | 790 | */ |
---|
[3225] | 791 | void World::handleInput () |
---|
[2636] | 792 | { |
---|
| 793 | // localinput |
---|
[4407] | 794 | //CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
---|
| 795 | //cn->process(); |
---|
| 796 | |
---|
| 797 | EventHandler::getInstance()->process(); |
---|
| 798 | |
---|
[2636] | 799 | // remoteinput |
---|
| 800 | } |
---|
| 801 | |
---|
[3459] | 802 | |
---|
[2636] | 803 | /** |
---|
[4836] | 804 | * advance the timeline |
---|
[3225] | 805 | |
---|
| 806 | this calculates the time used to process one frame (with all input handling, drawing, etc) |
---|
| 807 | the time is mesured in ms and passed to all world-entities and other classes that need |
---|
| 808 | a heart-beat. |
---|
[2636] | 809 | */ |
---|
[3551] | 810 | void World::tick () |
---|
[2636] | 811 | { |
---|
| 812 | Uint32 currentFrame = SDL_GetTicks(); |
---|
| 813 | if(!this->bPause) |
---|
| 814 | { |
---|
[3644] | 815 | this->dt = currentFrame - this->lastFrame; |
---|
[4555] | 816 | |
---|
[4610] | 817 | if( this->dt > 10) |
---|
[4555] | 818 | { |
---|
| 819 | float fps = 1000/dt; |
---|
[3790] | 820 | |
---|
[4555] | 821 | // temporary, only for showing how fast the text-engine is |
---|
| 822 | char tmpChar[20]; |
---|
| 823 | sprintf(tmpChar, "fps: %4.0f", fps); |
---|
| 824 | } |
---|
[2636] | 825 | else |
---|
[4555] | 826 | { |
---|
| 827 | /* the frame-rate is limited to 100 frames per second, all other things are for |
---|
| 828 | nothing. |
---|
| 829 | */ |
---|
| 830 | PRINTF(2)("fps = 1000 - frame rate is adjusted\n"); |
---|
[4610] | 831 | SDL_Delay(10-dt); |
---|
[4555] | 832 | this->dt = 10; |
---|
| 833 | } |
---|
| 834 | |
---|
| 835 | this->dtS = (float)this->dt / 1000.0; |
---|
[4145] | 836 | this->gameTime += this->dtS; |
---|
[4833] | 837 | |
---|
[3654] | 838 | tIterator<WorldEntity>* iterator = this->entities->getIterator(); |
---|
| 839 | WorldEntity* entity = iterator->nextElement(); |
---|
[4555] | 840 | while( entity != NULL) |
---|
| 841 | { |
---|
| 842 | entity->tick (this->dtS); |
---|
| 843 | entity = iterator->nextElement(); |
---|
| 844 | } |
---|
[3654] | 845 | delete iterator; |
---|
[4010] | 846 | |
---|
[3459] | 847 | /* update tick the rest */ |
---|
[4959] | 848 | TrackManager::getInstance()->tick(this->dtS); |
---|
[4832] | 849 | this->localCamera->tick(this->dtS); |
---|
[4558] | 850 | // tick the engines |
---|
[4245] | 851 | AnimationPlayer::getInstance()->tick(this->dtS); |
---|
[4979] | 852 | // if (this->cycle > 5) |
---|
[4558] | 853 | PhysicsEngine::getInstance()->tick(this->dtS); |
---|
[4396] | 854 | |
---|
[4558] | 855 | ParticleEngine::getInstance()->tick(this->dtS); |
---|
| 856 | GarbageCollector::getInstance()->tick(this->dtS); |
---|
[4396] | 857 | |
---|
[4831] | 858 | |
---|
[4558] | 859 | /** actualy the Graphics Engine should tick the world not the other way around... |
---|
[4555] | 860 | but since we like the things not too complicated we got it this way around |
---|
| 861 | until there is need or time to do it the other way around. |
---|
[4836] | 862 | @todo: GraphicsEngine ticks world: separation of processes and data... |
---|
[4681] | 863 | |
---|
| 864 | bensch: in my opinion the GraphicsEngine could draw the world, but not tick it, |
---|
| 865 | beceause graphics have nothing(or at least not much) to do with Motion. |
---|
[4245] | 866 | */ |
---|
| 867 | GraphicsEngine::getInstance()->tick(this->dtS); |
---|
[2636] | 868 | } |
---|
| 869 | this->lastFrame = currentFrame; |
---|
| 870 | } |
---|
| 871 | |
---|
[3216] | 872 | |
---|
[2636] | 873 | /** |
---|
[4836] | 874 | * this function gives the world a consistant state |
---|
[3551] | 875 | |
---|
| 876 | after ticking (updating the world state) this will give a constistant |
---|
| 877 | state to the whole system. |
---|
| 878 | */ |
---|
| 879 | void World::update() |
---|
| 880 | { |
---|
[4822] | 881 | GarbageCollector::getInstance()->update(); |
---|
[4978] | 882 | NullParent::getInstance()->update (this->dtS); |
---|
[4504] | 883 | |
---|
| 884 | SoundEngine::getInstance()->update(); |
---|
[4978] | 885 | //music->update(); |
---|
[3551] | 886 | } |
---|
| 887 | |
---|
| 888 | |
---|
[4917] | 889 | void World::collide() |
---|
| 890 | { |
---|
[4918] | 891 | CDEngine::getInstance()->checkCollisions(); |
---|
[4917] | 892 | } |
---|
| 893 | |
---|
[3551] | 894 | /** |
---|
[4836] | 895 | * render the current frame |
---|
[4555] | 896 | |
---|
[3225] | 897 | clear all buffers and draw the world |
---|
[2636] | 898 | */ |
---|
| 899 | void World::display () |
---|
| 900 | { |
---|
| 901 | // clear buffer |
---|
| 902 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
| 903 | // set camera |
---|
| 904 | this->localCamera->apply (); |
---|
| 905 | // draw world |
---|
| 906 | this->draw(); |
---|
| 907 | // draw HUD |
---|
[4837] | 908 | /** @todo draw HUD */ |
---|
[2636] | 909 | // flip buffers |
---|
[4681] | 910 | GraphicsEngine::swapBuffers(); |
---|
[3365] | 911 | //SDL_Surface* screen = Orxonox::getInstance()->getScreen (); |
---|
| 912 | //SDL_Flip (screen); |
---|
[2636] | 913 | } |
---|
| 914 | |
---|
[2644] | 915 | |
---|
[3225] | 916 | /** |
---|
[4917] | 917 | * runs through all entities calling their draw() methods |
---|
| 918 | */ |
---|
| 919 | void World::draw () |
---|
| 920 | { |
---|
| 921 | /* draw entities */ |
---|
| 922 | WorldEntity* entity; |
---|
| 923 | glLoadIdentity(); |
---|
| 924 | //entity = this->entities->enumerate(); |
---|
| 925 | tIterator<WorldEntity>* iterator = this->entities->getIterator(); |
---|
| 926 | entity = iterator->nextElement(); |
---|
| 927 | while( entity != NULL ) |
---|
| 928 | { |
---|
| 929 | if( entity->isVisible() ) entity->draw(); |
---|
| 930 | //entity = this->entities->nextElement(); |
---|
| 931 | entity = iterator->nextElement(); |
---|
| 932 | } |
---|
| 933 | delete iterator; |
---|
| 934 | |
---|
| 935 | glCallList (objectList); |
---|
| 936 | |
---|
| 937 | ParticleEngine::getInstance()->draw(); |
---|
| 938 | |
---|
| 939 | GraphicsEngine::getInstance()->draw(); |
---|
| 940 | //TextEngine::getInstance()->draw(); |
---|
| 941 | } |
---|
| 942 | |
---|
| 943 | /** |
---|
[4836] | 944 | * add and spawn a new entity to this world |
---|
| 945 | * @param entity to be added |
---|
[3225] | 946 | */ |
---|
[2644] | 947 | void World::spawn(WorldEntity* entity) |
---|
| 948 | { |
---|
[3365] | 949 | this->entities->add (entity); |
---|
[3233] | 950 | entity->postSpawn (); |
---|
[2816] | 951 | } |
---|
| 952 | |
---|
| 953 | |
---|
[3225] | 954 | /** |
---|
[4836] | 955 | * add and spawn a new entity to this world |
---|
| 956 | * @param entity to be added |
---|
| 957 | * @param absCoor At what coordinates to add this entity. |
---|
| 958 | * @param absDir In which direction should it look. |
---|
[3225] | 959 | */ |
---|
[3365] | 960 | void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir) |
---|
[2816] | 961 | { |
---|
[3529] | 962 | this->entities->add (entity); |
---|
| 963 | |
---|
[3809] | 964 | entity->setAbsCoor (*absCoor); |
---|
| 965 | entity->setAbsDir (*absDir); |
---|
[3365] | 966 | |
---|
[3233] | 967 | entity->postSpawn (); |
---|
[2644] | 968 | } |
---|
[2816] | 969 | |
---|
| 970 | |
---|
[3521] | 971 | /** |
---|
[4836] | 972 | * add and spawn a new entity to this world |
---|
| 973 | * @param entity to be added |
---|
| 974 | * @param entity to be added to (PNode) |
---|
| 975 | * @param At what relative coordinates to add this entity. |
---|
| 976 | * @param In which relative direction should it look. |
---|
[3521] | 977 | */ |
---|
[4555] | 978 | void World::spawn(WorldEntity* entity, PNode* parentNode, |
---|
[4765] | 979 | Vector* relCoor, Quaternion* relDir) |
---|
[3521] | 980 | { |
---|
[4978] | 981 | NullParent::getInstance(); |
---|
[3529] | 982 | if( parentNode != NULL) |
---|
[3521] | 983 | { |
---|
| 984 | parentNode->addChild (entity); |
---|
[4555] | 985 | |
---|
[3809] | 986 | entity->setRelCoor (*relCoor); |
---|
| 987 | entity->setRelDir (*relDir); |
---|
[4555] | 988 | |
---|
[3521] | 989 | this->entities->add (entity); |
---|
[4555] | 990 | |
---|
[3521] | 991 | entity->postSpawn (); |
---|
| 992 | } |
---|
| 993 | } |
---|
| 994 | |
---|
| 995 | |
---|
| 996 | |
---|
[3449] | 997 | /** |
---|
[3225] | 998 | \brief commands that the world must catch |
---|
[4836] | 999 | @returns false if not used by the world |
---|
[3225] | 1000 | */ |
---|
[3216] | 1001 | bool World::command(Command* cmd) |
---|
| 1002 | { |
---|
[4091] | 1003 | if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW0)) this->localCamera->setViewMode(VIEW_NORMAL); |
---|
| 1004 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW1)) this->localCamera->setViewMode(VIEW_BEHIND); |
---|
| 1005 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW2)) this->localCamera->setViewMode(VIEW_FRONT); |
---|
| 1006 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW3)) this->localCamera->setViewMode(VIEW_LEFT); |
---|
| 1007 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW4)) this->localCamera->setViewMode(VIEW_RIGHT); |
---|
| 1008 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW5)) this->localCamera->setViewMode(VIEW_TOP); |
---|
[3216] | 1009 | return false; |
---|
| 1010 | } |
---|
[3365] | 1011 | |
---|
[4010] | 1012 | void World::setPath( const char* name) |
---|
| 1013 | { |
---|
[4094] | 1014 | if (this->path) |
---|
| 1015 | delete this->path; |
---|
| 1016 | if (ResourceManager::isFile(name)) |
---|
| 1017 | { |
---|
| 1018 | this->path = new char[strlen(name)+1]; |
---|
| 1019 | strcpy(this->path, name); |
---|
| 1020 | } |
---|
| 1021 | else |
---|
| 1022 | { |
---|
| 1023 | this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1]; |
---|
| 1024 | sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name); |
---|
| 1025 | } |
---|
[4010] | 1026 | } |
---|
| 1027 | |
---|
| 1028 | const char* World::getPath( void) |
---|
| 1029 | { |
---|
| 1030 | return path; |
---|
| 1031 | } |
---|