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