[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" |
---|
[7919] | 27 | #include "util/timer.h" |
---|
[6404] | 28 | |
---|
[6352] | 29 | #include "player.h" |
---|
| 30 | #include "camera.h" |
---|
| 31 | #include "environment.h" |
---|
| 32 | #include "terrain.h" |
---|
[7287] | 33 | #include "test_entity.h" |
---|
| 34 | #include "terrain.h" |
---|
[6404] | 35 | #include "playable.h" |
---|
[7785] | 36 | #include "environments/mapped_water.h" |
---|
[6404] | 37 | |
---|
[6352] | 38 | #include "light.h" |
---|
[6404] | 39 | |
---|
[7193] | 40 | #include "util/loading/factory.h" |
---|
[7368] | 41 | #include "util/loading/load_param.h" |
---|
[6404] | 42 | #include "fast_factory.h" |
---|
| 43 | #include "shell_command.h" |
---|
[6352] | 44 | |
---|
| 45 | #include "graphics_engine.h" |
---|
[7810] | 46 | #include "effects/atmospheric_engine.h" |
---|
[6404] | 47 | #include "event_handler.h" |
---|
| 48 | #include "sound_engine.h" |
---|
| 49 | #include "cd_engine.h" |
---|
| 50 | #include "network_manager.h" |
---|
[6352] | 51 | #include "physics_engine.h" |
---|
[7287] | 52 | #include "fields.h" |
---|
[6352] | 53 | |
---|
| 54 | #include "glmenu_imagescreen.h" |
---|
[6404] | 55 | #include "shell.h" |
---|
[6352] | 56 | |
---|
| 57 | #include "ogg_player.h" |
---|
[6404] | 58 | #include "shader.h" |
---|
[6352] | 59 | |
---|
[7369] | 60 | #include "animation_player.h" |
---|
| 61 | |
---|
[7035] | 62 | #include "game_rules.h" |
---|
[6352] | 63 | |
---|
[6404] | 64 | using namespace std; |
---|
[6352] | 65 | |
---|
[9110] | 66 | #include "script_class.h" |
---|
| 67 | CREATE_SCRIPTABLE_CLASS(GameWorld, CL_GAME_WORLD, |
---|
| 68 | addMethod("setPlaymode", ExecutorLua1<GameWorld,const std::string&>(&GameWorld::setPlaymode)) |
---|
| 69 | ); |
---|
[6352] | 70 | |
---|
[7412] | 71 | SHELL_COMMAND(speed, GameWorld, setSpeed) ->describe("set the Speed of the Level"); |
---|
| 72 | SHELL_COMMAND(playmode, GameWorld, setPlaymode) |
---|
[7723] | 73 | ->describe("Set the Playmode of the current Level") |
---|
| 74 | ->completionPlugin(0, OrxShell::CompletorStringArray(Playable::playmodeNames, Playable::PlaymodeCount)); |
---|
[7412] | 75 | |
---|
[7739] | 76 | SHELL_COMMAND(togglePNodeVisibility, GameWorld, togglePNodeVisibility); |
---|
| 77 | SHELL_COMMAND(showBVLevel, GameWorld, toggleBVVisibility); |
---|
[6352] | 78 | |
---|
| 79 | |
---|
| 80 | |
---|
[6989] | 81 | GameWorld::GameWorld() |
---|
[6402] | 82 | : StoryEntity() |
---|
[6352] | 83 | { |
---|
[6368] | 84 | this->setClassID(CL_GAME_WORLD, "GameWorld"); |
---|
| 85 | this->setName("Preloaded World - no name yet"); |
---|
| 86 | |
---|
| 87 | this->gameTime = 0.0f; |
---|
[6370] | 88 | this->setSpeed(1.0f); |
---|
[6368] | 89 | this->shell = NULL; |
---|
| 90 | |
---|
| 91 | this->showPNodes = false; |
---|
| 92 | this->showBV = false; |
---|
[7739] | 93 | this->showBVLevel = 3; |
---|
[6368] | 94 | |
---|
[6845] | 95 | this->dataXML = NULL; |
---|
[7391] | 96 | this->gameRules = NULL; |
---|
[6352] | 97 | } |
---|
| 98 | |
---|
| 99 | /** |
---|
[6358] | 100 | * remove the GameWorld from memory |
---|
[6352] | 101 | * |
---|
| 102 | * delete everything explicitly, that isn't contained in the parenting tree! |
---|
| 103 | * things contained in the tree are deleted automaticaly |
---|
| 104 | */ |
---|
[6358] | 105 | GameWorld::~GameWorld () |
---|
[6352] | 106 | { |
---|
[6408] | 107 | PRINTF(4)("Deleted GameWorld\n"); |
---|
[7283] | 108 | |
---|
[6352] | 109 | } |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | /** |
---|
[6358] | 114 | * loads the parameters of a GameWorld from an XML-element |
---|
[6352] | 115 | * @param root the XML-element to load from |
---|
| 116 | */ |
---|
[6358] | 117 | void GameWorld::loadParams(const TiXmlElement* root) |
---|
[6352] | 118 | { |
---|
[6512] | 119 | StoryEntity::loadParams(root); |
---|
[6352] | 120 | |
---|
[6376] | 121 | PRINTF(4)("Loaded GameWorld specific stuff\n"); |
---|
[6352] | 122 | } |
---|
| 123 | |
---|
[6368] | 124 | |
---|
[6352] | 125 | /** |
---|
| 126 | * this is executed just before load |
---|
| 127 | * |
---|
| 128 | * since the load function sometimes needs data, that has been initialized |
---|
| 129 | * before the load and after the proceeding storyentity has finished |
---|
| 130 | */ |
---|
[6370] | 131 | ErrorMessage GameWorld::init() |
---|
[6352] | 132 | { |
---|
| 133 | /* init the world interface */ |
---|
[7374] | 134 | this->shell = new OrxShell::Shell(); |
---|
[6352] | 135 | |
---|
[6498] | 136 | State::setCurrentStoryEntity(dynamic_cast<StoryEntity*>(this)); |
---|
[6407] | 137 | this->dataTank->init(); |
---|
[7369] | 138 | |
---|
| 139 | /* initialize some engines and graphical elements */ |
---|
| 140 | AnimationPlayer::getInstance(); |
---|
| 141 | PhysicsEngine::getInstance(); |
---|
[8190] | 142 | CREngine::getInstance(); |
---|
[8408] | 143 | |
---|
| 144 | State::setScriptManager(&this->scriptManager); |
---|
| 145 | |
---|
[8717] | 146 | return ErrorMessage(); |
---|
[6352] | 147 | } |
---|
| 148 | |
---|
| 149 | /** |
---|
[6358] | 150 | * loads the GameWorld by initializing all resources, and set their default values. |
---|
[6352] | 151 | */ |
---|
[6372] | 152 | ErrorMessage GameWorld::loadData() |
---|
[6352] | 153 | { |
---|
[8408] | 154 | this->displayLoadScreen(); State::setScriptManager(&this->scriptManager); |
---|
[6370] | 155 | |
---|
[8408] | 156 | |
---|
[6407] | 157 | PRINTF(0)("Loading the GameWorld\n"); |
---|
| 158 | |
---|
[7677] | 159 | PRINTF(3)("> Loading world: '%s'\n", getLoadFile().c_str()); |
---|
[8717] | 160 | // TiXmlElement* element; |
---|
| 161 | // GameLoader* loader = GameLoader::getInstance(); |
---|
[6352] | 162 | |
---|
[7221] | 163 | if( getLoadFile().empty()) |
---|
[6402] | 164 | { |
---|
[6634] | 165 | PRINTF(1)("GameWorld has no path specified for loading\n"); |
---|
[8717] | 166 | return (ErrorMessage(213,"Path not specified","GameWorld::load()")); |
---|
[6402] | 167 | } |
---|
[6352] | 168 | |
---|
[7287] | 169 | TiXmlDocument* XMLDoc = new TiXmlDocument( getLoadFile()); |
---|
[6402] | 170 | // load the xml world file for further loading |
---|
[7287] | 171 | if( !XMLDoc->LoadFile()) |
---|
[6352] | 172 | { |
---|
[7287] | 173 | PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getLoadFile().c_str(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); |
---|
| 174 | delete XMLDoc; |
---|
[8717] | 175 | return ErrorMessage(213,"XML File parsing error","GameWorld::load()"); |
---|
[6352] | 176 | } |
---|
| 177 | // check basic validity |
---|
[7287] | 178 | TiXmlElement* root = XMLDoc->RootElement(); |
---|
[6352] | 179 | assert( root != NULL); |
---|
| 180 | if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile")) |
---|
| 181 | { |
---|
[6402] | 182 | // report an error |
---|
| 183 | PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n"); |
---|
[7287] | 184 | delete XMLDoc; |
---|
[8717] | 185 | return ErrorMessage(213,"Path not a WorldDataFile","GameWorld::load()"); |
---|
[6352] | 186 | } |
---|
[6402] | 187 | /* the whole loading process for the GameWorld */ |
---|
[6407] | 188 | this->dataTank->loadData(root); |
---|
[6845] | 189 | this->dataXML = (TiXmlElement*)root->Clone(); |
---|
[6352] | 190 | |
---|
[8408] | 191 | //remove this after finished testing !!!! |
---|
[8711] | 192 | //Object* obj= new Object(); |
---|
| 193 | //obj->setName("Obj"); |
---|
| 194 | //Account* a = new Account(); |
---|
| 195 | //a->setName("a"); |
---|
| 196 | //Account *b = new Account(30); |
---|
| 197 | //b->setName("b"); |
---|
[8717] | 198 | |
---|
[8740] | 199 | |
---|
[8271] | 200 | LoadParamXML(root, "ScriptManager", &this->scriptManager, ScriptManager, loadParams); |
---|
| 201 | |
---|
[7287] | 202 | delete XMLDoc; |
---|
[6386] | 203 | this->releaseLoadScreen(); |
---|
[8717] | 204 | |
---|
| 205 | return ErrorMessage(); |
---|
[6352] | 206 | } |
---|
| 207 | |
---|
| 208 | |
---|
| 209 | /** |
---|
[6387] | 210 | * unload the data of this GameWorld |
---|
| 211 | */ |
---|
| 212 | ErrorMessage GameWorld::unloadData() |
---|
| 213 | { |
---|
[8271] | 214 | |
---|
[7287] | 215 | PRINTF(3)("GameWorld::~GameWorld() - unloading the current GameWorld\n"); |
---|
[8271] | 216 | this->scriptManager.flush(); |
---|
| 217 | |
---|
[7370] | 218 | delete this->shell; |
---|
[6387] | 219 | |
---|
[6981] | 220 | this->dataTank->unloadData(); |
---|
| 221 | |
---|
[7369] | 222 | this->shell = NULL; |
---|
| 223 | delete AnimationPlayer::getInstance(); |
---|
| 224 | delete PhysicsEngine::getInstance(); |
---|
[8190] | 225 | delete CREngine::getInstance(); |
---|
[7369] | 226 | |
---|
[6988] | 227 | State::setCurrentStoryEntity(NULL); |
---|
[6845] | 228 | if (this->dataXML) |
---|
| 229 | delete this->dataXML; |
---|
[8717] | 230 | |
---|
| 231 | return ErrorMessage(); |
---|
[6387] | 232 | } |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | /** |
---|
[6358] | 236 | * starts the GameWorld |
---|
[6352] | 237 | */ |
---|
[6387] | 238 | bool GameWorld::start() |
---|
[6352] | 239 | { |
---|
[7283] | 240 | this->bPaused = false; |
---|
| 241 | this->bRunning = true; |
---|
[8408] | 242 | State::setScriptManager(&this->scriptManager); //make sure we have the right script manager |
---|
[6387] | 243 | this->run(); |
---|
[8717] | 244 | |
---|
| 245 | return true; |
---|
[6352] | 246 | } |
---|
| 247 | |
---|
[6402] | 248 | |
---|
[6352] | 249 | /** |
---|
| 250 | * stops the world. |
---|
[6402] | 251 | */ |
---|
[6387] | 252 | bool GameWorld::stop() |
---|
[6352] | 253 | { |
---|
[6358] | 254 | PRINTF(3)("GameWorld::stop() - got stop signal\n"); |
---|
[8408] | 255 | State::setScriptManager(NULL); |
---|
[8717] | 256 | return (this->bRunning = false); |
---|
[6352] | 257 | } |
---|
| 258 | |
---|
[6402] | 259 | |
---|
[6352] | 260 | /** |
---|
[6402] | 261 | * pauses the game |
---|
| 262 | */ |
---|
[6387] | 263 | bool GameWorld::pause() |
---|
[6352] | 264 | { |
---|
[8717] | 265 | return (this->bPaused = true); |
---|
[6352] | 266 | } |
---|
| 267 | |
---|
[6402] | 268 | |
---|
[6352] | 269 | /** |
---|
| 270 | * ends the pause Phase |
---|
[6409] | 271 | */ |
---|
[6387] | 272 | bool GameWorld::resume() |
---|
[6352] | 273 | { |
---|
[8717] | 274 | return(this->bPaused = false); |
---|
[6352] | 275 | } |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | /** |
---|
[6402] | 279 | * main loop of the world: executing all world relevant function |
---|
| 280 | * |
---|
| 281 | * in this loop we synchronize (if networked), handle input events, give the heart-beat to |
---|
| 282 | * all other member-entities of the world (tick to player, enemies etc.), checking for |
---|
| 283 | * collisions drawing everything to the screen. |
---|
| 284 | */ |
---|
| 285 | void GameWorld::run() |
---|
[6352] | 286 | { |
---|
[6402] | 287 | PRINTF(3)("GameWorld::mainLoop() - Entering main loop\n"); |
---|
[6352] | 288 | |
---|
[7131] | 289 | // initialize Timing |
---|
| 290 | this->cycle = 0; |
---|
| 291 | for (unsigned int i = 0; i < TICK_SMOOTH_VALUE; i++) |
---|
[7919] | 292 | this->frameTimes[i] = 0.01f; |
---|
[7131] | 293 | this->dtS = 0.0f; |
---|
[7919] | 294 | this->lastFrame = Timer::getNow(); |
---|
[7131] | 295 | |
---|
[7304] | 296 | if (this->dataTank->music != NULL) |
---|
| 297 | this->dataTank->music->play(); |
---|
| 298 | |
---|
[7283] | 299 | while( this->bRunning) /* @todo implement pause */ |
---|
[6402] | 300 | { |
---|
| 301 | /* process intput */ |
---|
| 302 | this->handleInput (); |
---|
[7322] | 303 | if( !this->bRunning) |
---|
| 304 | break; |
---|
[6386] | 305 | |
---|
[6402] | 306 | /* network synchronisation */ |
---|
| 307 | this->synchronize (); |
---|
| 308 | /* process time */ |
---|
| 309 | this->tick (); |
---|
[8490] | 310 | |
---|
[8740] | 311 | |
---|
[8724] | 312 | /* update the state */ |
---|
[8740] | 313 | //this->update (); /// LESS REDUNDANCY. |
---|
[9027] | 314 | // PNode::getNullParent()->updateNode(this->dtS); |
---|
[9061] | 315 | PNode::getNullParent()->updateNode(this->dtS); |
---|
[8724] | 316 | |
---|
[8190] | 317 | /* collision detection */ |
---|
| 318 | this->collisionDetection (); |
---|
| 319 | /* collision reaction */ |
---|
| 320 | this->collisionReaction (); |
---|
[8490] | 321 | |
---|
[8724] | 322 | /* check the game rules */ |
---|
| 323 | this->checkGameRules(); |
---|
[8740] | 324 | |
---|
[6402] | 325 | /* update the state */ |
---|
| 326 | this->update (); |
---|
| 327 | /* draw everything */ |
---|
| 328 | this->display (); |
---|
[7306] | 329 | |
---|
[6402] | 330 | } |
---|
| 331 | |
---|
[7330] | 332 | PRINTF(0)("GameWorld::mainLoop() - Exiting the main loop\n"); |
---|
[6352] | 333 | } |
---|
| 334 | |
---|
| 335 | |
---|
[7338] | 336 | void GameWorld::setPlaymode(Playable::Playmode playmode) |
---|
| 337 | { |
---|
| 338 | if (this->dataTank->localPlayer && |
---|
| 339 | this->dataTank->localPlayer->getPlayable() && |
---|
[7339] | 340 | this->dataTank->localPlayer->getPlayable()->setPlaymode(playmode)) |
---|
[7338] | 341 | { |
---|
[9110] | 342 | PRINTF(4)("Set Playmode to %d:%s\n", playmode, Playable::playmodeToString(playmode).c_str()); |
---|
[7338] | 343 | } |
---|
[7339] | 344 | else |
---|
| 345 | { |
---|
[9110] | 346 | PRINTF(2)("Unable to set Playmode %d:'%s'\n", playmode, Playable::playmodeToString(playmode).c_str()); |
---|
[7339] | 347 | } |
---|
[7338] | 348 | } |
---|
| 349 | |
---|
[7339] | 350 | void GameWorld::setPlaymode(const std::string& playmode) |
---|
| 351 | { |
---|
| 352 | this->setPlaymode(Playable::stringToPlaymode(playmode)); |
---|
| 353 | } |
---|
[7338] | 354 | |
---|
[6352] | 355 | /** |
---|
| 356 | * synchronize local data with remote data |
---|
| 357 | */ |
---|
[6358] | 358 | void GameWorld::synchronize () |
---|
[6402] | 359 | {} |
---|
[6352] | 360 | |
---|
| 361 | |
---|
| 362 | /** |
---|
| 363 | * run all input processing |
---|
| 364 | |
---|
| 365 | the command node is the central input event dispatcher. the node uses the even-queue from |
---|
| 366 | sdl and has its own event-passing-queue. |
---|
| 367 | */ |
---|
[6358] | 368 | void GameWorld::handleInput () |
---|
[6352] | 369 | { |
---|
| 370 | EventHandler::getInstance()->process(); |
---|
| 371 | } |
---|
| 372 | |
---|
[6402] | 373 | |
---|
| 374 | /** |
---|
[7370] | 375 | * @brief ticks a WorldEntity list |
---|
[6402] | 376 | * @param entityList list of the WorldEntities |
---|
| 377 | * @param dt time passed since last frame |
---|
| 378 | */ |
---|
[7370] | 379 | void GameWorld::tick(ObjectManager::EntityList entityList, float dt) |
---|
[6352] | 380 | { |
---|
[7370] | 381 | ObjectManager::EntityList::iterator entity, next; |
---|
[6710] | 382 | next = entityList.begin(); |
---|
| 383 | while (next != entityList.end()) |
---|
| 384 | { |
---|
| 385 | entity = next++; |
---|
[6352] | 386 | (*entity)->tick(dt); |
---|
[6710] | 387 | } |
---|
[6352] | 388 | } |
---|
| 389 | |
---|
[7131] | 390 | |
---|
[6352] | 391 | /** |
---|
| 392 | * advance the timeline |
---|
[6402] | 393 | * |
---|
| 394 | * this calculates the time used to process one frame (with all input handling, drawing, etc) |
---|
| 395 | * the time is mesured in ms and passed to all world-entities and other classes that need |
---|
| 396 | * a heart-beat. |
---|
| 397 | */ |
---|
[6358] | 398 | void GameWorld::tick () |
---|
[6352] | 399 | { |
---|
[7283] | 400 | if( !this->bPaused) |
---|
[6402] | 401 | { |
---|
[7131] | 402 | // CALCULATE FRAMERATE |
---|
| 403 | Uint32 frameTimesIndex; |
---|
| 404 | Uint32 i; |
---|
[7919] | 405 | double currentFrame = Timer::getNow(); |
---|
[6402] | 406 | |
---|
[7131] | 407 | frameTimesIndex = this->cycle % TICK_SMOOTH_VALUE; |
---|
[7919] | 408 | this->frameTimes[frameTimesIndex] = currentFrame - this->lastFrame; |
---|
| 409 | this->lastFrame = currentFrame; |
---|
[7132] | 410 | ++this->cycle; |
---|
[7919] | 411 | this->dtS = 0.0; |
---|
[7132] | 412 | for (i = 0; i < TICK_SMOOTH_VALUE; i++) |
---|
[7131] | 413 | this->dtS += this->frameTimes[i]; |
---|
[7919] | 414 | this->dtS = this->dtS / TICK_SMOOTH_VALUE * speed; |
---|
[6352] | 415 | |
---|
[7131] | 416 | // TICK everything |
---|
[7370] | 417 | for (i = 0; i < this->dataTank->tickLists.size(); ++i) |
---|
| 418 | this->tick(this->dataTank->objectManager->getObjectList(this->dataTank->tickLists[i]), this->dtS); |
---|
[6352] | 419 | |
---|
[6402] | 420 | /* update tick the rest */ |
---|
[6407] | 421 | this->dataTank->localCamera->tick(this->dtS); |
---|
[6402] | 422 | AnimationPlayer::getInstance()->tick(this->dtS); |
---|
| 423 | PhysicsEngine::getInstance()->tick(this->dtS); |
---|
[6352] | 424 | |
---|
[6402] | 425 | GraphicsEngine::getInstance()->tick(this->dtS); |
---|
[7810] | 426 | AtmosphericEngine::getInstance()->tick(this->dtS); |
---|
[7035] | 427 | |
---|
| 428 | if( likely(this->dataTank->gameRule != NULL)) |
---|
| 429 | this->dataTank->gameRule->tick(this->dtS); |
---|
[8717] | 430 | |
---|
[6402] | 431 | } |
---|
[6352] | 432 | } |
---|
| 433 | |
---|
| 434 | |
---|
| 435 | /** |
---|
| 436 | * this function gives the world a consistant state |
---|
[6402] | 437 | * |
---|
| 438 | * after ticking (updating the world state) this will give a constistant |
---|
| 439 | * state to the whole system. |
---|
| 440 | */ |
---|
[6358] | 441 | void GameWorld::update() |
---|
[6352] | 442 | { |
---|
| 443 | PNode::getNullParent()->updateNode (this->dtS); |
---|
[7460] | 444 | OrxSound::SoundEngine::getInstance()->update(); |
---|
[8740] | 445 | |
---|
| 446 | this->applyCameraSettings(); |
---|
[7871] | 447 | GraphicsEngine::getInstance()->update(this->dtS); |
---|
[6352] | 448 | } |
---|
| 449 | |
---|
| 450 | |
---|
[6402] | 451 | /** |
---|
| 452 | * kicks the CDEngine to detect the collisions between the object groups in the world |
---|
| 453 | */ |
---|
[8190] | 454 | void GameWorld::collisionDetection() |
---|
[6352] | 455 | { |
---|
[8490] | 456 | // object-object collision detection |
---|
[6407] | 457 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
[7004] | 458 | this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ)); |
---|
[6407] | 459 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), |
---|
[7004] | 460 | this->dataTank->objectManager->getObjectList(OM_GROUP_00_PROJ)); |
---|
[7078] | 461 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
[7288] | 462 | this->dataTank->objectManager->getObjectList(OM_GROUP_01)); |
---|
[6433] | 463 | |
---|
[7083] | 464 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
| 465 | this->dataTank->objectManager->getObjectList(OM_COMMON)); |
---|
[6433] | 466 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), |
---|
[6407] | 467 | this->dataTank->objectManager->getObjectList(OM_COMMON)); |
---|
[7083] | 468 | |
---|
[8490] | 469 | // ground collision detection: BSP Model |
---|
| 470 | CDEngine::getInstance()->checkCollisionGround(this->dataTank->objectManager->getObjectList(OM_GROUP_00)); |
---|
| 471 | CDEngine::getInstance()->checkCollisionGround(this->dataTank->objectManager->getObjectList(OM_GROUP_01)); |
---|
[6352] | 472 | } |
---|
| 473 | |
---|
[7391] | 474 | |
---|
[8190] | 475 | void GameWorld::collisionReaction() |
---|
| 476 | { |
---|
| 477 | CREngine::getInstance()->handleCollisions(); |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | |
---|
[6352] | 481 | /** |
---|
[7391] | 482 | * check the game rules: winning conditions, etc. |
---|
| 483 | * |
---|
| 484 | */ |
---|
| 485 | void GameWorld::checkGameRules() |
---|
| 486 | { |
---|
| 487 | if( this->gameRules) |
---|
| 488 | this->gameRules->tick(this->dtS); |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | |
---|
| 492 | /** |
---|
[6352] | 493 | * render the current frame |
---|
[6402] | 494 | * |
---|
| 495 | * clear all buffers and draw the world |
---|
| 496 | */ |
---|
[6358] | 497 | void GameWorld::display () |
---|
[6352] | 498 | { |
---|
[7785] | 499 | // render the reflection texture |
---|
| 500 | this->renderPassReflection(); |
---|
| 501 | // redner the refraction texture |
---|
| 502 | this->renderPassRefraction(); |
---|
| 503 | // render all |
---|
| 504 | this->renderPassAll(); |
---|
| 505 | |
---|
[6352] | 506 | // flip buffers |
---|
| 507 | GraphicsEngine::swapBuffers(); |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | |
---|
| 511 | /** |
---|
[7370] | 512 | * @brief draws all entities in the list drawList |
---|
| 513 | * @param drawList the List of entities to draw. |
---|
[6352] | 514 | */ |
---|
[7370] | 515 | void GameWorld::drawEntityList(const ObjectManager::EntityList& drawList) const |
---|
| 516 | { |
---|
| 517 | ObjectManager::EntityList::const_iterator entity; |
---|
| 518 | for (entity = drawList.begin(); entity != drawList.end(); entity++) |
---|
| 519 | if ((*entity)->isVisible()) |
---|
| 520 | (*entity)->draw(); |
---|
| 521 | } |
---|
| 522 | |
---|
[7785] | 523 | |
---|
[8740] | 524 | void GameWorld::applyCameraSettings() |
---|
| 525 | { |
---|
| 526 | this->dataTank->localCamera->apply (); |
---|
| 527 | this->dataTank->localCamera->project (); |
---|
| 528 | GraphicsEngine::storeMatrices(); |
---|
| 529 | } |
---|
[7785] | 530 | |
---|
[8740] | 531 | |
---|
| 532 | |
---|
[7370] | 533 | /** |
---|
[7785] | 534 | * reflection rendering for water surfaces |
---|
[7370] | 535 | */ |
---|
[7785] | 536 | void GameWorld::renderPassReflection() |
---|
[6352] | 537 | { |
---|
[7785] | 538 | // clear buffer |
---|
| 539 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
[8740] | 540 | // glLoadIdentity(); |
---|
[7785] | 541 | |
---|
| 542 | const std::list<BaseObject*>* reflectedWaters; |
---|
| 543 | MappedWater* mw; |
---|
| 544 | |
---|
| 545 | if( (reflectedWaters = ClassList::getList(CL_MAPPED_WATER)) != NULL) |
---|
| 546 | { |
---|
| 547 | std::list<BaseObject*>::const_iterator it; |
---|
| 548 | for (it = reflectedWaters->begin(); it != reflectedWaters->end(); it++) |
---|
| 549 | { |
---|
| 550 | mw = dynamic_cast<MappedWater*>(*it); |
---|
| 551 | |
---|
| 552 | //camera and light |
---|
[8740] | 553 | //this->dataTank->localCamera->apply (); |
---|
| 554 | //this->dataTank->localCamera->project (); |
---|
[8312] | 555 | |
---|
[7785] | 556 | LightManager::getInstance()->draw(); |
---|
[8312] | 557 | |
---|
| 558 | |
---|
| 559 | // prepare for reflection rendering |
---|
| 560 | mw->activateReflection(); |
---|
| 561 | |
---|
[7785] | 562 | // draw everything to be included in the reflection |
---|
[8037] | 563 | this->drawEntityList(State::getObjectManager()->getReflectionList()); |
---|
| 564 | // for (unsigned int i = 0; i < this->dataTank->drawLists.size(); ++i) |
---|
| 565 | // this->drawEntityList(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i])); |
---|
[7785] | 566 | |
---|
| 567 | // clean up from reflection rendering |
---|
| 568 | mw->deactivateReflection(); |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | |
---|
| 575 | /** |
---|
| 576 | * refraction rendering for water surfaces |
---|
| 577 | */ |
---|
| 578 | void GameWorld::renderPassRefraction() |
---|
[8037] | 579 | { |
---|
| 580 | // clear buffer |
---|
| 581 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
[8740] | 582 | //glLoadIdentity(); |
---|
[7785] | 583 | |
---|
[8037] | 584 | const std::list<BaseObject*>* reflectedWaters; |
---|
| 585 | MappedWater* mw; |
---|
| 586 | |
---|
| 587 | if( (reflectedWaters = ClassList::getList(CL_MAPPED_WATER)) != NULL) |
---|
| 588 | { |
---|
| 589 | std::list<BaseObject*>::const_iterator it; |
---|
| 590 | for (it = reflectedWaters->begin(); it != reflectedWaters->end(); it++) |
---|
| 591 | { |
---|
| 592 | mw = dynamic_cast<MappedWater*>(*it); |
---|
| 593 | |
---|
[8312] | 594 | //camera and light |
---|
[8740] | 595 | //this->dataTank->localCamera->apply (); |
---|
| 596 | //this->dataTank->localCamera->project (); |
---|
[8037] | 597 | // prepare for reflection rendering |
---|
| 598 | mw->activateRefraction(); |
---|
| 599 | |
---|
[8312] | 600 | |
---|
[8037] | 601 | LightManager::getInstance()->draw(); |
---|
| 602 | // draw everything to be included in the reflection |
---|
| 603 | this->drawEntityList(State::getObjectManager()->getReflectionList()); |
---|
| 604 | // for (unsigned int i = 0; i < this->dataTank->drawLists.size(); ++i) |
---|
| 605 | // this->drawEntityList(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i])); |
---|
| 606 | |
---|
| 607 | // clean up from reflection rendering |
---|
| 608 | mw->deactivateRefraction(); |
---|
| 609 | } |
---|
| 610 | } |
---|
| 611 | } |
---|
| 612 | |
---|
| 613 | |
---|
[7785] | 614 | /** |
---|
| 615 | * this render pass renders the whole wolrd |
---|
| 616 | */ |
---|
| 617 | void GameWorld::renderPassAll() |
---|
| 618 | { |
---|
| 619 | // clear buffer |
---|
| 620 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
[6352] | 621 | GraphicsEngine* engine = GraphicsEngine::getInstance(); |
---|
[6402] | 622 | |
---|
[7919] | 623 | |
---|
[8740] | 624 | // glEnable(GL_DEPTH_TEST); |
---|
| 625 | // glEnable(GL_LIGHTING); |
---|
[7919] | 626 | |
---|
[8740] | 627 | // set Lighting |
---|
[7108] | 628 | LightManager::getInstance()->draw(); |
---|
[6416] | 629 | |
---|
[8740] | 630 | /* Draw the BackGround */ |
---|
[7840] | 631 | this->drawEntityList(State::getObjectManager()->getObjectList(OM_BACKGROUND)); |
---|
| 632 | engine->drawBackgroundElements(); |
---|
| 633 | |
---|
[6416] | 634 | /* draw all WorldEntiy groups */ |
---|
[7370] | 635 | for (unsigned int i = 0; i < this->dataTank->drawLists.size(); ++i) |
---|
[7723] | 636 | this->drawEntityList(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i])); |
---|
[6416] | 637 | |
---|
[8255] | 638 | AtmosphericEngine::getInstance()->draw(); |
---|
[8408] | 639 | |
---|
[6402] | 640 | if( unlikely( this->showBV)) |
---|
| 641 | { |
---|
| 642 | CDEngine* engine = CDEngine::getInstance(); |
---|
[7370] | 643 | for (unsigned int i = 0; i < this->dataTank->drawLists.size(); ++i) |
---|
[7739] | 644 | engine->drawBV(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i]), this->showBVLevel); |
---|
[6402] | 645 | } |
---|
[6416] | 646 | |
---|
[6402] | 647 | if( unlikely(this->showPNodes)) |
---|
| 648 | PNode::getNullParent()->debugDraw(0); |
---|
| 649 | |
---|
[6780] | 650 | engine->draw(); |
---|
[7035] | 651 | |
---|
| 652 | // draw the game ruls |
---|
| 653 | if( likely(this->dataTank->gameRule != NULL)) |
---|
| 654 | this->dataTank->gameRule->draw(); |
---|
[6352] | 655 | } |
---|
| 656 | |
---|
[7785] | 657 | |
---|
[6352] | 658 | /** |
---|
[6402] | 659 | * shows the loading screen |
---|
| 660 | */ |
---|
| 661 | void GameWorld::displayLoadScreen () |
---|
[6387] | 662 | { |
---|
[6402] | 663 | PRINTF(3)("GameWorld::displayLoadScreen - start\n"); |
---|
[6407] | 664 | this->dataTank->glmis = new GLMenuImageScreen(); |
---|
| 665 | this->dataTank->glmis->setMaximum(8); |
---|
[6402] | 666 | PRINTF(3)("GameWorld::displayLoadScreen - end\n"); |
---|
[6387] | 667 | } |
---|
| 668 | |
---|
| 669 | |
---|
[6402] | 670 | /** |
---|
| 671 | * removes the loadscreen, and changes over to the game |
---|
| 672 | */ |
---|
| 673 | void GameWorld::releaseLoadScreen () |
---|
[6387] | 674 | { |
---|
[6402] | 675 | PRINTF(3)("GameWorld::releaseLoadScreen - start\n"); |
---|
[6407] | 676 | this->dataTank->glmis->setValue(this->dataTank->glmis->getMaximum()); |
---|
[6402] | 677 | PRINTF(3)("GameWorld::releaseLoadScreen - end\n"); |
---|
[6387] | 678 | } |
---|
| 679 | |
---|
[7004] | 680 | |
---|
| 681 | |
---|
| 682 | /** |
---|
| 683 | * @brief toggles the PNode visibility in the world (drawn as boxes) |
---|
| 684 | */ |
---|
| 685 | void GameWorld::togglePNodeVisibility() |
---|
| 686 | { |
---|
[7723] | 687 | this->showPNodes = !this->showPNodes; |
---|
[7004] | 688 | }; |
---|
| 689 | |
---|
| 690 | |
---|
| 691 | /** |
---|
| 692 | * @brief toggles the bounding volume (BV) visibility |
---|
| 693 | */ |
---|
[7739] | 694 | void GameWorld::toggleBVVisibility(int level) |
---|
[7004] | 695 | { |
---|
[7739] | 696 | if( level < 1) |
---|
| 697 | this->showBV = false; |
---|
| 698 | else |
---|
| 699 | { |
---|
| 700 | this->showBV = true; |
---|
| 701 | this->showBVLevel = level; |
---|
| 702 | } |
---|
| 703 | |
---|
[7004] | 704 | }; |
---|
| 705 | |
---|