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