[6352] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
| 13 | co-programmer: Christian Meyer |
---|
| 14 | co-programmer: Benjamin Grauer |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD |
---|
| 18 | |
---|
[6358] | 19 | #include "game_world.h" |
---|
[6402] | 20 | #include "game_world_data.h" |
---|
[6352] | 21 | |
---|
[7287] | 22 | #include "util/loading/resource_manager.h" |
---|
[6352] | 23 | #include "state.h" |
---|
[6404] | 24 | #include "class_list.h" |
---|
[6352] | 25 | |
---|
[7193] | 26 | #include "util/loading/game_loader.h" |
---|
[6404] | 27 | |
---|
[6352] | 28 | #include "player.h" |
---|
| 29 | #include "camera.h" |
---|
| 30 | #include "environment.h" |
---|
| 31 | #include "terrain.h" |
---|
[7287] | 32 | #include "test_entity.h" |
---|
| 33 | #include "terrain.h" |
---|
[6404] | 34 | #include "playable.h" |
---|
| 35 | |
---|
[6352] | 36 | #include "light.h" |
---|
[6404] | 37 | |
---|
[7193] | 38 | #include "util/loading/factory.h" |
---|
[7368] | 39 | #include "util/loading/load_param.h" |
---|
[6404] | 40 | #include "fast_factory.h" |
---|
| 41 | #include "shell_command.h" |
---|
[6352] | 42 | |
---|
| 43 | #include "graphics_engine.h" |
---|
[6404] | 44 | #include "event_handler.h" |
---|
| 45 | #include "sound_engine.h" |
---|
| 46 | #include "cd_engine.h" |
---|
| 47 | #include "network_manager.h" |
---|
[6352] | 48 | #include "physics_engine.h" |
---|
[7287] | 49 | #include "fields.h" |
---|
[6352] | 50 | |
---|
| 51 | #include "glmenu_imagescreen.h" |
---|
[6404] | 52 | #include "shell.h" |
---|
[6352] | 53 | |
---|
| 54 | #include "ogg_player.h" |
---|
[6404] | 55 | #include "shader.h" |
---|
[6352] | 56 | |
---|
[7369] | 57 | #include "animation_player.h" |
---|
| 58 | |
---|
[7035] | 59 | #include "game_rules.h" |
---|
[6352] | 60 | |
---|
[6404] | 61 | using namespace std; |
---|
[6352] | 62 | |
---|
| 63 | |
---|
[7412] | 64 | SHELL_COMMAND(speed, GameWorld, setSpeed) ->describe("set the Speed of the Level"); |
---|
| 65 | SHELL_COMMAND(playmode, GameWorld, setPlaymode) |
---|
| 66 | ->describe("Set the Playmode of the current Level") |
---|
| 67 | ->completionPlugin(0, OrxShell::CompletorStringArray(Playable::playmodeNames, Playable::PlaymodeCount)); |
---|
| 68 | |
---|
[7004] | 69 | SHELL_COMMAND_STATIC(togglePNodeVisibility, GameWorld, GameWorld::togglePNodeVisibility); |
---|
| 70 | SHELL_COMMAND_STATIC(toggleBVVisibility, GameWorld, GameWorld::toggleBVVisibility); |
---|
[6352] | 71 | |
---|
| 72 | |
---|
| 73 | |
---|
[6989] | 74 | GameWorld::GameWorld() |
---|
[6402] | 75 | : StoryEntity() |
---|
[6352] | 76 | { |
---|
[6368] | 77 | this->setClassID(CL_GAME_WORLD, "GameWorld"); |
---|
| 78 | this->setName("Preloaded World - no name yet"); |
---|
| 79 | |
---|
| 80 | this->gameTime = 0.0f; |
---|
[6370] | 81 | this->setSpeed(1.0f); |
---|
[6368] | 82 | this->shell = NULL; |
---|
| 83 | |
---|
| 84 | this->showPNodes = false; |
---|
| 85 | this->showBV = false; |
---|
| 86 | |
---|
[6845] | 87 | this->dataXML = NULL; |
---|
[7391] | 88 | this->gameRules = NULL; |
---|
[6352] | 89 | } |
---|
| 90 | |
---|
| 91 | /** |
---|
[6358] | 92 | * remove the GameWorld from memory |
---|
[6352] | 93 | * |
---|
| 94 | * delete everything explicitly, that isn't contained in the parenting tree! |
---|
| 95 | * things contained in the tree are deleted automaticaly |
---|
| 96 | */ |
---|
[6358] | 97 | GameWorld::~GameWorld () |
---|
[6352] | 98 | { |
---|
[6408] | 99 | PRINTF(4)("Deleted GameWorld\n"); |
---|
[7283] | 100 | |
---|
[6352] | 101 | } |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | /** |
---|
[6358] | 106 | * loads the parameters of a GameWorld from an XML-element |
---|
[6352] | 107 | * @param root the XML-element to load from |
---|
| 108 | */ |
---|
[6358] | 109 | void GameWorld::loadParams(const TiXmlElement* root) |
---|
[6352] | 110 | { |
---|
[6512] | 111 | StoryEntity::loadParams(root); |
---|
[6352] | 112 | |
---|
[6376] | 113 | PRINTF(4)("Loaded GameWorld specific stuff\n"); |
---|
[6352] | 114 | } |
---|
| 115 | |
---|
[6368] | 116 | |
---|
[6352] | 117 | /** |
---|
| 118 | * this is executed just before load |
---|
| 119 | * |
---|
| 120 | * since the load function sometimes needs data, that has been initialized |
---|
| 121 | * before the load and after the proceeding storyentity has finished |
---|
| 122 | */ |
---|
[6370] | 123 | ErrorMessage GameWorld::init() |
---|
[6352] | 124 | { |
---|
| 125 | /* init the world interface */ |
---|
[7374] | 126 | this->shell = new OrxShell::Shell(); |
---|
[6352] | 127 | |
---|
[6498] | 128 | State::setCurrentStoryEntity(dynamic_cast<StoryEntity*>(this)); |
---|
[6407] | 129 | this->dataTank->init(); |
---|
[7369] | 130 | |
---|
| 131 | /* initialize some engines and graphical elements */ |
---|
| 132 | AnimationPlayer::getInstance(); |
---|
| 133 | PhysicsEngine::getInstance(); |
---|
| 134 | |
---|
[6352] | 135 | } |
---|
| 136 | |
---|
[7288] | 137 | |
---|
[6352] | 138 | /** |
---|
[6358] | 139 | * loads the GameWorld by initializing all resources, and set their default values. |
---|
[6352] | 140 | */ |
---|
[6372] | 141 | ErrorMessage GameWorld::loadData() |
---|
[6352] | 142 | { |
---|
[6370] | 143 | this->displayLoadScreen(); |
---|
| 144 | |
---|
[6407] | 145 | PRINTF(0)("Loading the GameWorld\n"); |
---|
| 146 | |
---|
[7677] | 147 | PRINTF(3)("> Loading world: '%s'\n", getLoadFile().c_str()); |
---|
[6352] | 148 | TiXmlElement* element; |
---|
| 149 | GameLoader* loader = GameLoader::getInstance(); |
---|
| 150 | |
---|
[7221] | 151 | if( getLoadFile().empty()) |
---|
[6402] | 152 | { |
---|
[6634] | 153 | PRINTF(1)("GameWorld has no path specified for loading\n"); |
---|
[6402] | 154 | return (ErrorMessage){213,"Path not specified","GameWorld::load()"}; |
---|
| 155 | } |
---|
[6352] | 156 | |
---|
[7287] | 157 | TiXmlDocument* XMLDoc = new TiXmlDocument( getLoadFile()); |
---|
[6402] | 158 | // load the xml world file for further loading |
---|
[7287] | 159 | if( !XMLDoc->LoadFile()) |
---|
[6352] | 160 | { |
---|
[7287] | 161 | PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getLoadFile().c_str(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); |
---|
| 162 | delete XMLDoc; |
---|
[6358] | 163 | return (ErrorMessage){213,"XML File parsing error","GameWorld::load()"}; |
---|
[6352] | 164 | } |
---|
| 165 | // check basic validity |
---|
[7287] | 166 | TiXmlElement* root = XMLDoc->RootElement(); |
---|
[6352] | 167 | assert( root != NULL); |
---|
| 168 | if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile")) |
---|
| 169 | { |
---|
[6402] | 170 | // report an error |
---|
| 171 | PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n"); |
---|
[7287] | 172 | delete XMLDoc; |
---|
[6402] | 173 | return (ErrorMessage){213,"Path not a WorldDataFile","GameWorld::load()"}; |
---|
[6352] | 174 | } |
---|
[6402] | 175 | /* the whole loading process for the GameWorld */ |
---|
[6407] | 176 | this->dataTank->loadData(root); |
---|
[6845] | 177 | this->dataXML = (TiXmlElement*)root->Clone(); |
---|
[6352] | 178 | |
---|
[7287] | 179 | delete XMLDoc; |
---|
[6386] | 180 | this->releaseLoadScreen(); |
---|
[6352] | 181 | } |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | /** |
---|
[6387] | 185 | * unload the data of this GameWorld |
---|
| 186 | */ |
---|
| 187 | ErrorMessage GameWorld::unloadData() |
---|
| 188 | { |
---|
[7287] | 189 | PRINTF(3)("GameWorld::~GameWorld() - unloading the current GameWorld\n"); |
---|
[7370] | 190 | delete this->shell; |
---|
[6387] | 191 | |
---|
[6981] | 192 | this->dataTank->unloadData(); |
---|
| 193 | |
---|
[7369] | 194 | this->shell = NULL; |
---|
| 195 | delete AnimationPlayer::getInstance(); |
---|
| 196 | delete PhysicsEngine::getInstance(); |
---|
| 197 | |
---|
[6988] | 198 | State::setCurrentStoryEntity(NULL); |
---|
[6845] | 199 | if (this->dataXML) |
---|
| 200 | delete this->dataXML; |
---|
[6387] | 201 | } |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | /** |
---|
[6358] | 205 | * starts the GameWorld |
---|
[6352] | 206 | */ |
---|
[6387] | 207 | bool GameWorld::start() |
---|
[6352] | 208 | { |
---|
[7283] | 209 | this->bPaused = false; |
---|
| 210 | this->bRunning = true; |
---|
[6387] | 211 | |
---|
| 212 | this->run(); |
---|
[6352] | 213 | } |
---|
| 214 | |
---|
[6402] | 215 | |
---|
[6352] | 216 | /** |
---|
| 217 | * stops the world. |
---|
[6402] | 218 | */ |
---|
[6387] | 219 | bool GameWorld::stop() |
---|
[6352] | 220 | { |
---|
[6358] | 221 | PRINTF(3)("GameWorld::stop() - got stop signal\n"); |
---|
[7283] | 222 | this->bRunning = false; |
---|
[6352] | 223 | } |
---|
| 224 | |
---|
[6402] | 225 | |
---|
[6352] | 226 | /** |
---|
[6402] | 227 | * pauses the game |
---|
| 228 | */ |
---|
[6387] | 229 | bool GameWorld::pause() |
---|
[6352] | 230 | { |
---|
[7283] | 231 | this->bPaused = true; |
---|
[6352] | 232 | } |
---|
| 233 | |
---|
[6402] | 234 | |
---|
[6352] | 235 | /** |
---|
| 236 | * ends the pause Phase |
---|
[6409] | 237 | */ |
---|
[6387] | 238 | bool GameWorld::resume() |
---|
[6352] | 239 | { |
---|
[7283] | 240 | this->bPaused = false; |
---|
[6352] | 241 | } |
---|
| 242 | |
---|
| 243 | |
---|
| 244 | /** |
---|
[6402] | 245 | * main loop of the world: executing all world relevant function |
---|
| 246 | * |
---|
| 247 | * in this loop we synchronize (if networked), handle input events, give the heart-beat to |
---|
| 248 | * all other member-entities of the world (tick to player, enemies etc.), checking for |
---|
| 249 | * collisions drawing everything to the screen. |
---|
| 250 | */ |
---|
| 251 | void GameWorld::run() |
---|
[6352] | 252 | { |
---|
[6402] | 253 | PRINTF(3)("GameWorld::mainLoop() - Entering main loop\n"); |
---|
[6352] | 254 | |
---|
[7131] | 255 | // initialize Timing |
---|
| 256 | this->cycle = 0; |
---|
| 257 | for (unsigned int i = 0; i < TICK_SMOOTH_VALUE; i++) |
---|
[7132] | 258 | this->frameTimes[i] = 100; |
---|
[7131] | 259 | this->dtS = 0.0f; |
---|
| 260 | this->lastFrame = SDL_GetTicks (); |
---|
| 261 | |
---|
[7304] | 262 | if (this->dataTank->music != NULL) |
---|
| 263 | this->dataTank->music->play(); |
---|
| 264 | |
---|
[7283] | 265 | while( this->bRunning) /* @todo implement pause */ |
---|
[6402] | 266 | { |
---|
| 267 | /* process intput */ |
---|
| 268 | this->handleInput (); |
---|
[7322] | 269 | if( !this->bRunning) |
---|
| 270 | break; |
---|
[6386] | 271 | |
---|
[6402] | 272 | /* network synchronisation */ |
---|
| 273 | this->synchronize (); |
---|
| 274 | /* process time */ |
---|
| 275 | this->tick (); |
---|
| 276 | /* process collision */ |
---|
| 277 | this->collide (); |
---|
| 278 | /* update the state */ |
---|
| 279 | this->update (); |
---|
[7391] | 280 | /* check the game rules */ |
---|
| 281 | this->checkGameRules(); |
---|
[6402] | 282 | /* draw everything */ |
---|
| 283 | this->display (); |
---|
[7306] | 284 | |
---|
[6402] | 285 | } |
---|
| 286 | |
---|
[7330] | 287 | PRINTF(0)("GameWorld::mainLoop() - Exiting the main loop\n"); |
---|
[6352] | 288 | } |
---|
| 289 | |
---|
| 290 | |
---|
[7338] | 291 | void GameWorld::setPlaymode(Playable::Playmode playmode) |
---|
| 292 | { |
---|
| 293 | if (this->dataTank->localPlayer && |
---|
| 294 | this->dataTank->localPlayer->getPlayable() && |
---|
[7339] | 295 | this->dataTank->localPlayer->getPlayable()->setPlaymode(playmode)) |
---|
[7338] | 296 | { |
---|
[7412] | 297 | PRINTF(3)("Set Playmode to %d:%s\n", playmode, Playable::playmodeToString(playmode).c_str()); |
---|
[7338] | 298 | } |
---|
[7339] | 299 | else |
---|
| 300 | { |
---|
[7414] | 301 | PRINTF(1)("Unable to set Playmode %d:'%s'\n", playmode, Playable::playmodeToString(playmode).c_str()); |
---|
[7339] | 302 | } |
---|
[7338] | 303 | } |
---|
| 304 | |
---|
[7339] | 305 | void GameWorld::setPlaymode(const std::string& playmode) |
---|
| 306 | { |
---|
| 307 | this->setPlaymode(Playable::stringToPlaymode(playmode)); |
---|
| 308 | } |
---|
[7338] | 309 | |
---|
[6352] | 310 | /** |
---|
| 311 | * synchronize local data with remote data |
---|
| 312 | */ |
---|
[6358] | 313 | void GameWorld::synchronize () |
---|
[6402] | 314 | {} |
---|
[6352] | 315 | |
---|
| 316 | |
---|
| 317 | /** |
---|
| 318 | * run all input processing |
---|
| 319 | |
---|
| 320 | the command node is the central input event dispatcher. the node uses the even-queue from |
---|
| 321 | sdl and has its own event-passing-queue. |
---|
| 322 | */ |
---|
[6358] | 323 | void GameWorld::handleInput () |
---|
[6352] | 324 | { |
---|
| 325 | EventHandler::getInstance()->process(); |
---|
| 326 | } |
---|
| 327 | |
---|
[6402] | 328 | |
---|
| 329 | /** |
---|
[7370] | 330 | * @brief ticks a WorldEntity list |
---|
[6402] | 331 | * @param entityList list of the WorldEntities |
---|
| 332 | * @param dt time passed since last frame |
---|
| 333 | */ |
---|
[7370] | 334 | void GameWorld::tick(ObjectManager::EntityList entityList, float dt) |
---|
[6352] | 335 | { |
---|
[7370] | 336 | ObjectManager::EntityList::iterator entity, next; |
---|
[6710] | 337 | next = entityList.begin(); |
---|
| 338 | while (next != entityList.end()) |
---|
| 339 | { |
---|
| 340 | entity = next++; |
---|
[6352] | 341 | (*entity)->tick(dt); |
---|
[6710] | 342 | } |
---|
[6352] | 343 | } |
---|
| 344 | |
---|
[7131] | 345 | |
---|
[6352] | 346 | /** |
---|
| 347 | * advance the timeline |
---|
[6402] | 348 | * |
---|
| 349 | * this calculates the time used to process one frame (with all input handling, drawing, etc) |
---|
| 350 | * the time is mesured in ms and passed to all world-entities and other classes that need |
---|
| 351 | * a heart-beat. |
---|
| 352 | */ |
---|
[6358] | 353 | void GameWorld::tick () |
---|
[6352] | 354 | { |
---|
| 355 | Uint32 currentFrame = SDL_GetTicks(); |
---|
[6402] | 356 | |
---|
[7283] | 357 | if( !this->bPaused) |
---|
[6402] | 358 | { |
---|
[7131] | 359 | // CALCULATE FRAMERATE |
---|
| 360 | Uint32 frameTimesIndex; |
---|
| 361 | Uint32 getTicks; |
---|
| 362 | Uint32 i; |
---|
[6402] | 363 | |
---|
[7131] | 364 | frameTimesIndex = this->cycle % TICK_SMOOTH_VALUE; |
---|
| 365 | getTicks = SDL_GetTicks(); |
---|
| 366 | this->frameTimes[frameTimesIndex] = getTicks - this->lastFrame; |
---|
| 367 | this->lastFrame = getTicks; |
---|
[7132] | 368 | ++this->cycle; |
---|
[7131] | 369 | this->dtS = 0; |
---|
[7132] | 370 | for (i = 0; i < TICK_SMOOTH_VALUE; i++) |
---|
[7131] | 371 | this->dtS += this->frameTimes[i]; |
---|
[7132] | 372 | this->dtS = this->dtS / TICK_SMOOTH_VALUE / 1000.0f * speed; |
---|
[6352] | 373 | |
---|
[7131] | 374 | // TICK everything |
---|
[7370] | 375 | for (i = 0; i < this->dataTank->tickLists.size(); ++i) |
---|
| 376 | this->tick(this->dataTank->objectManager->getObjectList(this->dataTank->tickLists[i]), this->dtS); |
---|
[6352] | 377 | |
---|
[6402] | 378 | /* update tick the rest */ |
---|
[6407] | 379 | this->dataTank->localCamera->tick(this->dtS); |
---|
[6402] | 380 | AnimationPlayer::getInstance()->tick(this->dtS); |
---|
| 381 | PhysicsEngine::getInstance()->tick(this->dtS); |
---|
[6352] | 382 | |
---|
[6402] | 383 | GraphicsEngine::getInstance()->tick(this->dtS); |
---|
[7035] | 384 | |
---|
| 385 | if( likely(this->dataTank->gameRule != NULL)) |
---|
| 386 | this->dataTank->gameRule->tick(this->dtS); |
---|
[6402] | 387 | } |
---|
[6352] | 388 | this->lastFrame = currentFrame; |
---|
| 389 | } |
---|
| 390 | |
---|
| 391 | |
---|
| 392 | /** |
---|
| 393 | * this function gives the world a consistant state |
---|
[6402] | 394 | * |
---|
| 395 | * after ticking (updating the world state) this will give a constistant |
---|
| 396 | * state to the whole system. |
---|
| 397 | */ |
---|
[6358] | 398 | void GameWorld::update() |
---|
[6352] | 399 | { |
---|
| 400 | GraphicsEngine::getInstance()->update(this->dtS); |
---|
| 401 | PNode::getNullParent()->updateNode (this->dtS); |
---|
[7460] | 402 | OrxSound::SoundEngine::getInstance()->update(); |
---|
[6352] | 403 | } |
---|
| 404 | |
---|
| 405 | |
---|
[6402] | 406 | /** |
---|
| 407 | * kicks the CDEngine to detect the collisions between the object groups in the world |
---|
| 408 | */ |
---|
[6358] | 409 | void GameWorld::collide() |
---|
[6352] | 410 | { |
---|
[6407] | 411 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
[7004] | 412 | this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ)); |
---|
[6407] | 413 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), |
---|
[7004] | 414 | this->dataTank->objectManager->getObjectList(OM_GROUP_00_PROJ)); |
---|
[7078] | 415 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
[7288] | 416 | this->dataTank->objectManager->getObjectList(OM_GROUP_01)); |
---|
[6433] | 417 | |
---|
[7083] | 418 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
| 419 | this->dataTank->objectManager->getObjectList(OM_COMMON)); |
---|
[6433] | 420 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), |
---|
[6407] | 421 | this->dataTank->objectManager->getObjectList(OM_COMMON)); |
---|
[7083] | 422 | |
---|
[6352] | 423 | } |
---|
| 424 | |
---|
[7391] | 425 | |
---|
[6352] | 426 | /** |
---|
[7391] | 427 | * check the game rules: winning conditions, etc. |
---|
| 428 | * |
---|
| 429 | */ |
---|
| 430 | void GameWorld::checkGameRules() |
---|
| 431 | { |
---|
| 432 | if( this->gameRules) |
---|
| 433 | this->gameRules->tick(this->dtS); |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | |
---|
| 437 | /** |
---|
[6352] | 438 | * render the current frame |
---|
[6402] | 439 | * |
---|
| 440 | * clear all buffers and draw the world |
---|
| 441 | */ |
---|
[6358] | 442 | void GameWorld::display () |
---|
[6352] | 443 | { |
---|
| 444 | // clear buffer |
---|
| 445 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
| 446 | // draw world |
---|
| 447 | this->draw(); |
---|
| 448 | // flip buffers |
---|
| 449 | GraphicsEngine::swapBuffers(); |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | |
---|
| 453 | /** |
---|
[7370] | 454 | * @brief draws all entities in the list drawList |
---|
| 455 | * @param drawList the List of entities to draw. |
---|
[6352] | 456 | */ |
---|
[7370] | 457 | void GameWorld::drawEntityList(const ObjectManager::EntityList& drawList) const |
---|
| 458 | { |
---|
| 459 | ObjectManager::EntityList::const_iterator entity; |
---|
| 460 | for (entity = drawList.begin(); entity != drawList.end(); entity++) |
---|
| 461 | if ((*entity)->isVisible()) |
---|
| 462 | (*entity)->draw(); |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | /** |
---|
| 466 | * @brief runs through all entities calling their draw() methods |
---|
| 467 | */ |
---|
[6358] | 468 | void GameWorld::draw () |
---|
[6352] | 469 | { |
---|
| 470 | GraphicsEngine* engine = GraphicsEngine::getInstance(); |
---|
[6402] | 471 | |
---|
[6780] | 472 | // set camera |
---|
| 473 | this->dataTank->localCamera->apply (); |
---|
[7108] | 474 | this->dataTank->localCamera->project (); |
---|
| 475 | LightManager::getInstance()->draw(); |
---|
[6416] | 476 | |
---|
| 477 | /* draw all WorldEntiy groups */ |
---|
[7370] | 478 | for (unsigned int i = 0; i < this->dataTank->drawLists.size(); ++i) |
---|
| 479 | this->drawEntityList(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i])); |
---|
[6416] | 480 | |
---|
[6780] | 481 | |
---|
[6402] | 482 | if( unlikely( this->showBV)) |
---|
| 483 | { |
---|
| 484 | CDEngine* engine = CDEngine::getInstance(); |
---|
[7370] | 485 | for (unsigned int i = 0; i < this->dataTank->drawLists.size(); ++i) |
---|
| 486 | engine->drawBV(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i])); |
---|
[6402] | 487 | } |
---|
[6416] | 488 | |
---|
[6402] | 489 | if( unlikely(this->showPNodes)) |
---|
| 490 | PNode::getNullParent()->debugDraw(0); |
---|
| 491 | |
---|
[6780] | 492 | engine->draw(); |
---|
[7035] | 493 | |
---|
| 494 | // draw the game ruls |
---|
| 495 | if( likely(this->dataTank->gameRule != NULL)) |
---|
| 496 | this->dataTank->gameRule->draw(); |
---|
[6352] | 497 | } |
---|
| 498 | |
---|
| 499 | /** |
---|
[6402] | 500 | * shows the loading screen |
---|
| 501 | */ |
---|
| 502 | void GameWorld::displayLoadScreen () |
---|
[6387] | 503 | { |
---|
[6402] | 504 | PRINTF(3)("GameWorld::displayLoadScreen - start\n"); |
---|
[6407] | 505 | this->dataTank->glmis = new GLMenuImageScreen(); |
---|
| 506 | this->dataTank->glmis->setMaximum(8); |
---|
[6402] | 507 | PRINTF(3)("GameWorld::displayLoadScreen - end\n"); |
---|
[6387] | 508 | } |
---|
| 509 | |
---|
| 510 | |
---|
[6402] | 511 | /** |
---|
| 512 | * removes the loadscreen, and changes over to the game |
---|
| 513 | */ |
---|
| 514 | void GameWorld::releaseLoadScreen () |
---|
[6387] | 515 | { |
---|
[6402] | 516 | PRINTF(3)("GameWorld::releaseLoadScreen - start\n"); |
---|
[6407] | 517 | this->dataTank->glmis->setValue(this->dataTank->glmis->getMaximum()); |
---|
[6402] | 518 | PRINTF(3)("GameWorld::releaseLoadScreen - end\n"); |
---|
[6387] | 519 | } |
---|
| 520 | |
---|
[7004] | 521 | |
---|
| 522 | |
---|
| 523 | /** |
---|
| 524 | * @brief toggles the PNode visibility in the world (drawn as boxes) |
---|
| 525 | */ |
---|
| 526 | void GameWorld::togglePNodeVisibility() |
---|
| 527 | { |
---|
| 528 | if (State::getCurrentStoryEntity() != NULL && |
---|
| 529 | State::getCurrentStoryEntity()->isA(CL_GAME_WORLD)) |
---|
| 530 | { |
---|
| 531 | dynamic_cast<GameWorld*>(State::getCurrentStoryEntity())->showPNodes = !dynamic_cast<GameWorld*>(State::getCurrentStoryEntity())->showPNodes; |
---|
| 532 | } |
---|
| 533 | else |
---|
| 534 | PRINTF(2)("The Current Story entity is not a GameWorld\n"); |
---|
| 535 | }; |
---|
| 536 | |
---|
| 537 | |
---|
| 538 | /** |
---|
| 539 | * @brief toggles the bounding volume (BV) visibility |
---|
| 540 | */ |
---|
| 541 | void GameWorld::toggleBVVisibility() |
---|
| 542 | { |
---|
| 543 | if (State::getCurrentStoryEntity() != NULL && |
---|
| 544 | State::getCurrentStoryEntity()->isA(CL_GAME_WORLD)) |
---|
| 545 | { |
---|
| 546 | dynamic_cast<GameWorld*>(State::getCurrentStoryEntity())->showBV = !dynamic_cast<GameWorld*>(State::getCurrentStoryEntity())->showBV; |
---|
| 547 | } |
---|
| 548 | else |
---|
| 549 | PRINTF(2)("The Current Story entity is not a GameWorld\n"); |
---|
| 550 | }; |
---|
| 551 | |
---|