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