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