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