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