[1038] | 1 | /* |
---|
[1293] | 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1056] | 3 | * > www.orxonox.net < |
---|
[1038] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
[1535] | 23 | * Reto Grieder |
---|
| 24 | * Co-authors: |
---|
[1038] | 25 | * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file |
---|
| 31 | @brief Orxonox Main Class |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | // Precompiled Headers |
---|
| 35 | #include "OrxonoxStableHeaders.h" |
---|
[1039] | 36 | #include "Orxonox.h" |
---|
[1038] | 37 | |
---|
| 38 | //****** STD ******* |
---|
| 39 | #include <deque> |
---|
| 40 | |
---|
| 41 | //****** OGRE ****** |
---|
| 42 | #include <OgreFrameListener.h> |
---|
| 43 | #include <OgreOverlay.h> |
---|
| 44 | #include <OgreOverlayManager.h> |
---|
| 45 | #include <OgreRoot.h> |
---|
| 46 | #include <OgreTimer.h> |
---|
| 47 | #include <OgreWindowEventUtilities.h> |
---|
| 48 | |
---|
| 49 | //***** ORXONOX **** |
---|
| 50 | // util |
---|
| 51 | //#include "util/Sleep.h" |
---|
| 52 | #include "util/ArgReader.h" |
---|
| 53 | |
---|
[1293] | 54 | // core |
---|
[1054] | 55 | #include "core/ConfigFileManager.h" |
---|
[1293] | 56 | #include "core/ConsoleCommand.h" |
---|
[1038] | 57 | #include "core/Debug.h" |
---|
| 58 | #include "core/Loader.h" |
---|
[1535] | 59 | #include "core/input/InputManager.h" |
---|
[1293] | 60 | #include "core/TclBind.h" |
---|
[1535] | 61 | #include "core/Core.h" |
---|
[1038] | 62 | |
---|
| 63 | // audio |
---|
| 64 | #include "audio/AudioManager.h" |
---|
| 65 | |
---|
| 66 | // network |
---|
| 67 | #include "network/Server.h" |
---|
| 68 | #include "network/Client.h" |
---|
| 69 | |
---|
| 70 | // objects and tools |
---|
[1625] | 71 | #include "overlays/OverlayGroup.h" |
---|
| 72 | #include "overlays/console/InGameConsole.h" |
---|
[1535] | 73 | #include "objects/Tickable.h" |
---|
[1608] | 74 | #include "objects/Backlight.h" |
---|
[1563] | 75 | #include "tools/ParticleInterface.h" |
---|
[1038] | 76 | |
---|
[1502] | 77 | #include "GraphicsEngine.h" |
---|
[1535] | 78 | #include "Settings.h" |
---|
[1625] | 79 | #include "Radar.h" |
---|
[1502] | 80 | |
---|
[1038] | 81 | // globals for the server or client |
---|
[1577] | 82 | static network::Client *client_g = 0; |
---|
| 83 | static network::Server *server_g = 0; |
---|
[1038] | 84 | |
---|
| 85 | namespace orxonox |
---|
[1293] | 86 | { |
---|
[1502] | 87 | SetConsoleCommandShortcut(Orxonox, exit).setKeybindMode(KeybindMode::OnPress); |
---|
| 88 | SetConsoleCommandShortcut(Orxonox, slomo).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false); |
---|
| 89 | SetConsoleCommandShortcut(Orxonox, setTimeFactor).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0); |
---|
[1505] | 90 | |
---|
[1038] | 91 | /** |
---|
| 92 | @brief Reference to the only instance of the class. |
---|
| 93 | */ |
---|
| 94 | Orxonox *Orxonox::singletonRef_s = 0; |
---|
| 95 | |
---|
| 96 | /** |
---|
[1293] | 97 | * Create a new instance of Orxonox. Avoid doing any actual work here. |
---|
[1038] | 98 | */ |
---|
[1625] | 99 | Orxonox::Orxonox() |
---|
| 100 | : ogre_(0) |
---|
| 101 | , startLevel_(0) |
---|
| 102 | , hud_(0) |
---|
| 103 | , radar_(0) |
---|
| 104 | //, auMan_(0) |
---|
| 105 | , timer_(0) |
---|
| 106 | , bAbort_(false) |
---|
| 107 | , timefactor_(1.0f) |
---|
| 108 | , mode_(STANDALONE) |
---|
| 109 | , serverIp_("") |
---|
| 110 | , serverPort_(NETWORK_PORT) |
---|
[1038] | 111 | { |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /** |
---|
[1293] | 115 | * Destruct Orxonox. |
---|
[1038] | 116 | */ |
---|
| 117 | Orxonox::~Orxonox() |
---|
| 118 | { |
---|
| 119 | // keep in mind: the order of deletion is very important! |
---|
[1625] | 120 | Loader::unload(startLevel_); |
---|
| 121 | if (this->startLevel_) |
---|
| 122 | delete this->startLevel_; |
---|
| 123 | |
---|
| 124 | Loader::unload(hud_); |
---|
| 125 | if (this->hud_) |
---|
| 126 | delete this->hud_; |
---|
| 127 | |
---|
| 128 | if (this->radar_) |
---|
| 129 | delete this->radar_; |
---|
| 130 | |
---|
[1038] | 131 | Loader::close(); |
---|
[1293] | 132 | //if (this->auMan_) |
---|
| 133 | // delete this->auMan_; |
---|
[1577] | 134 | InGameConsole::getInstance().destroy(); |
---|
[1038] | 135 | if (this->timer_) |
---|
| 136 | delete this->timer_; |
---|
[1625] | 137 | InputManager::destroy(); |
---|
[1038] | 138 | GraphicsEngine::getSingleton().destroy(); |
---|
| 139 | |
---|
[1293] | 140 | if (network::Client::getSingleton()) |
---|
| 141 | network::Client::destroySingleton(); |
---|
[1038] | 142 | if (server_g) |
---|
[1534] | 143 | delete network::Server::getSingleton(); |
---|
[1038] | 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | /** |
---|
| 148 | Asks the mainloop nicely to abort. |
---|
| 149 | */ |
---|
| 150 | void Orxonox::abortRequest() |
---|
| 151 | { |
---|
[1293] | 152 | COUT(3) << "Orxonox: Abort requested." << std::endl; |
---|
[1038] | 153 | bAbort_ = true; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | /** |
---|
[1293] | 157 | * @return singleton reference |
---|
[1038] | 158 | */ |
---|
| 159 | Orxonox* Orxonox::getSingleton() |
---|
| 160 | { |
---|
| 161 | if (!singletonRef_s) |
---|
| 162 | singletonRef_s = new Orxonox(); |
---|
| 163 | return singletonRef_s; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | /** |
---|
| 167 | @brief Destroys the Orxonox singleton. |
---|
| 168 | */ |
---|
| 169 | void Orxonox::destroySingleton() |
---|
| 170 | { |
---|
| 171 | if (singletonRef_s) |
---|
| 172 | delete singletonRef_s; |
---|
| 173 | singletonRef_s = 0; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | /** |
---|
[1563] | 177 | @brief Changes the speed of Orxonox |
---|
| 178 | */ |
---|
| 179 | void Orxonox::setTimeFactor(float factor) |
---|
| 180 | { |
---|
| 181 | float change = factor / Orxonox::getSingleton()->getTimeFactor(); |
---|
| 182 | Orxonox::getSingleton()->timefactor_ = factor; |
---|
| 183 | for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it) |
---|
| 184 | it->setSpeedFactor(it->getSpeedFactor() * change); |
---|
[1608] | 185 | |
---|
| 186 | for (Iterator<Backlight> it = ObjectList<Backlight>::begin(); it; ++it) |
---|
| 187 | it->setTimeFactor(Orxonox::getSingleton()->getTimeFactor()); |
---|
[1563] | 188 | } |
---|
| 189 | |
---|
| 190 | /** |
---|
[1038] | 191 | * initialization of Orxonox object |
---|
| 192 | * @param argc argument counter |
---|
| 193 | * @param argv list of argumenst |
---|
| 194 | * @param path path to config (in home dir or something) |
---|
| 195 | */ |
---|
[1535] | 196 | bool Orxonox::init(int argc, char **argv) |
---|
[1038] | 197 | { |
---|
[1535] | 198 | #ifdef _DEBUG |
---|
| 199 | ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox_d.ini"); |
---|
| 200 | #else |
---|
| 201 | ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); |
---|
| 202 | #endif |
---|
| 203 | Factory::createClassHierarchy(); |
---|
| 204 | |
---|
[1038] | 205 | std::string mode; |
---|
[1535] | 206 | std::string tempDataPath; |
---|
[1038] | 207 | |
---|
| 208 | ArgReader ar(argc, argv); |
---|
[1535] | 209 | ar.checkArgument("mode", &mode, false); |
---|
| 210 | ar.checkArgument("data", &tempDataPath, false); |
---|
| 211 | ar.checkArgument("ip", &serverIp_, false); |
---|
| 212 | ar.checkArgument("port", &serverPort_, false); |
---|
[1293] | 213 | if(ar.errorHandling()) |
---|
[1535] | 214 | { |
---|
| 215 | COUT(1) << "Error while parsing command line arguments" << std::endl; |
---|
| 216 | COUT(1) << ar.getErrorString(); |
---|
| 217 | COUT(0) << "Usage:" << std::endl << "orxonox [mode client|server|dedicated|standalone] " |
---|
| 218 | << "[--data PATH] [--ip IP] [--port PORT]" << std::endl; |
---|
[1293] | 219 | return false; |
---|
[1535] | 220 | } |
---|
[1293] | 221 | |
---|
| 222 | if (mode == "client") |
---|
[1038] | 223 | mode_ = CLIENT; |
---|
[1293] | 224 | else if (mode == "server") |
---|
[1038] | 225 | mode_ = SERVER; |
---|
[1502] | 226 | else if (mode == "dedicated") |
---|
| 227 | mode_ = DEDICATED; |
---|
[1293] | 228 | else |
---|
| 229 | { |
---|
[1535] | 230 | if (mode == "") |
---|
| 231 | mode = "standalone"; |
---|
| 232 | if (mode != "standalone") |
---|
| 233 | { |
---|
| 234 | COUT(2) << "Warning: mode \"" << mode << "\" doesn't exist. " |
---|
| 235 | << "Defaulting to standalone" << std::endl; |
---|
| 236 | mode = "standalone"; |
---|
| 237 | } |
---|
[1038] | 238 | mode_ = STANDALONE; |
---|
| 239 | } |
---|
[1293] | 240 | COUT(3) << "Orxonox: Mode is " << mode << "." << std::endl; |
---|
[1038] | 241 | |
---|
[1535] | 242 | if (tempDataPath != "") |
---|
| 243 | { |
---|
| 244 | if (tempDataPath[tempDataPath.size() - 1] != '/') |
---|
| 245 | tempDataPath += "/"; |
---|
| 246 | Settings::tsetDataPath(tempDataPath); |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | // initialise TCL |
---|
| 250 | TclBind::getInstance().setDataPath(Settings::getDataPath()); |
---|
| 251 | |
---|
[1293] | 252 | //if (mode_ == DEDICATED) |
---|
| 253 | // TODO: decide what to do here |
---|
| 254 | //else |
---|
[1052] | 255 | |
---|
[1293] | 256 | // for playable server, client and standalone, the startup |
---|
| 257 | // procedure until the GUI is identical |
---|
[1052] | 258 | |
---|
[1293] | 259 | ogre_ = &GraphicsEngine::getSingleton(); |
---|
[1535] | 260 | if (!ogre_->setup()) // creates ogre root and other essentials |
---|
[1293] | 261 | return false; |
---|
[1052] | 262 | |
---|
[1293] | 263 | return true; |
---|
[1038] | 264 | } |
---|
[1052] | 265 | |
---|
[1038] | 266 | /** |
---|
| 267 | * start modules |
---|
| 268 | */ |
---|
[1293] | 269 | bool Orxonox::start() |
---|
[1038] | 270 | { |
---|
[1502] | 271 | if (mode_ == DEDICATED) |
---|
| 272 | { |
---|
| 273 | // do something else |
---|
| 274 | } |
---|
| 275 | else |
---|
| 276 | { // not dedicated server |
---|
| 277 | if (!ogre_->loadRenderer()) // creates the render window |
---|
| 278 | return false; |
---|
[1293] | 279 | |
---|
[1577] | 280 | // TODO: Spread this so that this call only initialises things needed for the Console |
---|
| 281 | if (!ogre_->initialiseResources()) |
---|
| 282 | return false; |
---|
| 283 | |
---|
| 284 | // Load the InGameConsole |
---|
| 285 | InGameConsole::getInstance().initialise(); |
---|
| 286 | |
---|
[1502] | 287 | // Calls the InputManager which sets up the input devices. |
---|
| 288 | // The render window width and height are used to set up the mouse movement. |
---|
| 289 | if (!InputManager::initialise(ogre_->getWindowHandle(), |
---|
| 290 | ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true)) |
---|
| 291 | return false; |
---|
[1293] | 292 | |
---|
[1502] | 293 | // TOOD: load the GUI here |
---|
| 294 | // set InputManager to GUI mode |
---|
| 295 | InputManager::setInputState(InputManager::IS_GUI); |
---|
| 296 | // TODO: run GUI here |
---|
[1293] | 297 | |
---|
[1502] | 298 | // The following lines depend very much on the GUI output, so they're probably misplaced here.. |
---|
[1293] | 299 | |
---|
[1502] | 300 | InputManager::setInputState(InputManager::IS_NONE); |
---|
[1293] | 301 | |
---|
[1502] | 302 | // create Ogre SceneManager |
---|
| 303 | ogre_->createNewScene(); |
---|
[1293] | 304 | |
---|
[1502] | 305 | if (!loadPlayground()) |
---|
| 306 | return false; |
---|
| 307 | } |
---|
[1293] | 308 | |
---|
| 309 | switch (mode_) |
---|
| 310 | { |
---|
| 311 | case SERVER: |
---|
| 312 | if (!serverLoad()) |
---|
| 313 | return false; |
---|
| 314 | break; |
---|
[1038] | 315 | case CLIENT: |
---|
[1293] | 316 | if (!clientLoad()) |
---|
| 317 | return false; |
---|
[1038] | 318 | break; |
---|
[1502] | 319 | case DEDICATED: |
---|
| 320 | if (!serverLoad()) |
---|
| 321 | return false; |
---|
| 322 | break; |
---|
[1038] | 323 | default: |
---|
[1293] | 324 | if (!standaloneLoad()) |
---|
| 325 | return false; |
---|
[1038] | 326 | } |
---|
[1293] | 327 | |
---|
| 328 | InputManager::setInputState(InputManager::IS_NORMAL); |
---|
| 329 | |
---|
| 330 | return startRenderLoop(); |
---|
[1038] | 331 | } |
---|
[1052] | 332 | |
---|
[1293] | 333 | /** |
---|
| 334 | * Loads everything in the scene except for the actual objects. |
---|
[1577] | 335 | * This includes HUD, audio.. |
---|
[1293] | 336 | */ |
---|
| 337 | bool Orxonox::loadPlayground() |
---|
| 338 | { |
---|
[1502] | 339 | // Init audio |
---|
[1293] | 340 | //auMan_ = new audio::AudioManager(); |
---|
| 341 | //auMan_->ambientAdd("a1"); |
---|
| 342 | //auMan_->ambientAdd("a2"); |
---|
| 343 | //auMan_->ambientAdd("a3"); |
---|
| 344 | //auMan->ambientAdd("ambient1"); |
---|
| 345 | //auMan_->ambientStart(); |
---|
[1052] | 346 | |
---|
[1293] | 347 | // Load the HUD |
---|
[1625] | 348 | COUT(3) << "Orxonox: Loading HUD" << std::endl; |
---|
| 349 | hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo"); |
---|
| 350 | Loader::load(hud_); |
---|
[1577] | 351 | |
---|
[1625] | 352 | // Start the Radar |
---|
| 353 | this->radar_ = new Radar(); |
---|
| 354 | |
---|
[1293] | 355 | return true; |
---|
| 356 | } |
---|
[1052] | 357 | |
---|
[1293] | 358 | /** |
---|
| 359 | * Level loading method for server mode. |
---|
| 360 | */ |
---|
| 361 | bool Orxonox::serverLoad() |
---|
| 362 | { |
---|
[1577] | 363 | COUT(0) << "Loading level in server mode" << std::endl; |
---|
[1052] | 364 | |
---|
[1534] | 365 | //server_g = new network::Server(serverPort_); |
---|
| 366 | server_g = network::Server::createSingleton(serverPort_); |
---|
[1052] | 367 | |
---|
[1293] | 368 | if (!loadScene()) |
---|
| 369 | return false; |
---|
[1052] | 370 | |
---|
[1038] | 371 | server_g->open(); |
---|
[1052] | 372 | |
---|
[1293] | 373 | return true; |
---|
[1038] | 374 | } |
---|
[1052] | 375 | |
---|
[1293] | 376 | /** |
---|
| 377 | * Level loading method for client mode. |
---|
| 378 | */ |
---|
| 379 | bool Orxonox::clientLoad() |
---|
| 380 | { |
---|
[1577] | 381 | COUT(0) << "Loading level in client mode" << std::endl;\ |
---|
[1052] | 382 | |
---|
[1293] | 383 | if (serverIp_.compare("") == 0) |
---|
| 384 | client_g = network::Client::createSingleton(); |
---|
| 385 | else |
---|
| 386 | |
---|
[1502] | 387 | client_g = network::Client::createSingleton(serverIp_, serverPort_); |
---|
| 388 | |
---|
| 389 | if(!client_g->establishConnection()) |
---|
| 390 | return false; |
---|
[1293] | 391 | client_g->tick(0); |
---|
| 392 | |
---|
| 393 | return true; |
---|
[1038] | 394 | } |
---|
| 395 | |
---|
[1293] | 396 | /** |
---|
| 397 | * Level loading method for standalone mode. |
---|
| 398 | */ |
---|
| 399 | bool Orxonox::standaloneLoad() |
---|
[1038] | 400 | { |
---|
[1577] | 401 | COUT(0) << "Loading level in standalone mode" << std::endl; |
---|
[1038] | 402 | |
---|
[1293] | 403 | if (!loadScene()) |
---|
| 404 | return false; |
---|
[1038] | 405 | |
---|
[1293] | 406 | return true; |
---|
[1038] | 407 | } |
---|
| 408 | |
---|
| 409 | /** |
---|
[1293] | 410 | * Helper method to load a level. |
---|
| 411 | */ |
---|
| 412 | bool Orxonox::loadScene() |
---|
[1038] | 413 | { |
---|
[1625] | 414 | startLevel_ = new Level("levels/sample.oxw"); |
---|
| 415 | Loader::open(startLevel_); |
---|
[1563] | 416 | |
---|
[1293] | 417 | return true; |
---|
[1038] | 418 | } |
---|
| 419 | |
---|
[1293] | 420 | |
---|
[1038] | 421 | /** |
---|
| 422 | Main loop of the orxonox game. |
---|
| 423 | About the loop: The design is almost exactly like the one in ogre, so that |
---|
| 424 | if any part of ogre registers a framelisteners, it will still behave |
---|
| 425 | correctly. Furthermore the time smoothing feature from ogre has been |
---|
| 426 | implemented too. If turned on (see orxonox constructor), it will calculate |
---|
| 427 | the dt_n by means of the recent most dt_n-1, dt_n-2, etc. |
---|
| 428 | */ |
---|
[1293] | 429 | bool Orxonox::startRenderLoop() |
---|
[1038] | 430 | { |
---|
| 431 | // first check whether ogre root object has been created |
---|
| 432 | if (Ogre::Root::getSingletonPtr() == 0) |
---|
| 433 | { |
---|
[1293] | 434 | COUT(2) << "Orxonox Error: Could not start rendering. No Ogre root object found" << std::endl; |
---|
| 435 | return false; |
---|
[1038] | 436 | } |
---|
[1120] | 437 | Ogre::Root& ogreRoot = Ogre::Root::getSingleton(); |
---|
[1038] | 438 | |
---|
[1120] | 439 | |
---|
[1038] | 440 | // use the ogre timer class to measure time. |
---|
| 441 | if (!timer_) |
---|
| 442 | timer_ = new Ogre::Timer(); |
---|
| 443 | |
---|
[1625] | 444 | unsigned long frameCount = 0; |
---|
| 445 | |
---|
| 446 | // TODO: this would very well fit into a configValue |
---|
| 447 | const unsigned long refreshTime = 200000; |
---|
| 448 | unsigned long refreshStartTime = 0; |
---|
| 449 | unsigned long tickTime = 0; |
---|
| 450 | unsigned long oldFrameCount = 0; |
---|
[1502] | 451 | |
---|
[1625] | 452 | unsigned long timeBeforeTick = 0; |
---|
| 453 | unsigned long timeBeforeTickOld = 0; |
---|
| 454 | unsigned long timeAfterTick = 0; |
---|
[1563] | 455 | |
---|
[1625] | 456 | COUT(3) << "Orxonox: Starting the main loop." << std::endl; |
---|
[1502] | 457 | |
---|
[1625] | 458 | timer_->reset(); |
---|
[1502] | 459 | while (!bAbort_) |
---|
| 460 | { |
---|
[1038] | 461 | // get current time |
---|
[1625] | 462 | timeBeforeTickOld = timeBeforeTick; |
---|
| 463 | timeBeforeTick = timer_->getMicroseconds(); |
---|
| 464 | float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0; |
---|
[1038] | 465 | |
---|
| 466 | |
---|
[1625] | 467 | // tick the core (needs real time for input and tcl thread management) |
---|
| 468 | Core::tick(dt); |
---|
[1038] | 469 | |
---|
[1502] | 470 | // Call those objects that need the real time |
---|
| 471 | for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) |
---|
[1625] | 472 | it->tick(dt); |
---|
[1502] | 473 | // Call the scene objects |
---|
[1092] | 474 | for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) |
---|
[1625] | 475 | it->tick(dt * this->timefactor_); |
---|
| 476 | |
---|
| 477 | // call server/client with normal dt |
---|
[1535] | 478 | if (client_g) |
---|
[1625] | 479 | client_g->tick(dt * this->timefactor_); |
---|
[1535] | 480 | if (server_g) |
---|
[1625] | 481 | server_g->tick(dt * this->timefactor_); |
---|
[1038] | 482 | |
---|
[1625] | 483 | |
---|
| 484 | // get current time once again |
---|
| 485 | timeAfterTick = timer_->getMicroseconds(); |
---|
| 486 | |
---|
| 487 | tickTime += timeAfterTick - timeBeforeTick; |
---|
| 488 | if (timeAfterTick > refreshStartTime + refreshTime) |
---|
| 489 | { |
---|
| 490 | GraphicsEngine::getSingleton().setAverageTickTime( |
---|
| 491 | (float)tickTime * 0.001 / (frameCount - oldFrameCount)); |
---|
| 492 | GraphicsEngine::getSingleton().setAverageFramesPerSecond( |
---|
| 493 | (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0); |
---|
| 494 | oldFrameCount = frameCount; |
---|
| 495 | tickTime = 0; |
---|
| 496 | refreshStartTime = timeAfterTick; |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | |
---|
[1038] | 500 | // don't forget to call _fireFrameStarted in ogre to make sure |
---|
| 501 | // everything goes smoothly |
---|
[1625] | 502 | Ogre::FrameEvent evt; |
---|
| 503 | evt.timeSinceLastFrame = dt; |
---|
| 504 | evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway |
---|
[1120] | 505 | ogreRoot._fireFrameStarted(evt); |
---|
[1038] | 506 | |
---|
[1502] | 507 | if (mode_ != DEDICATED) |
---|
| 508 | { |
---|
| 509 | // Pump messages in all registered RenderWindows |
---|
| 510 | // This calls the WindowEventListener objects. |
---|
| 511 | Ogre::WindowEventUtilities::messagePump(); |
---|
[1625] | 512 | // make sure the window stays active even when not focused |
---|
| 513 | // (probably only necessary on windows) |
---|
| 514 | GraphicsEngine::getSingleton().setWindowActivity(true); |
---|
[1502] | 515 | |
---|
| 516 | // render |
---|
| 517 | ogreRoot._updateAllRenderTargets(); |
---|
| 518 | } |
---|
| 519 | |
---|
[1625] | 520 | // again, just to be sure ogre works fine |
---|
| 521 | ogreRoot._fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted |
---|
[1038] | 522 | |
---|
[1625] | 523 | ++frameCount; |
---|
[1502] | 524 | } |
---|
[1293] | 525 | |
---|
[1502] | 526 | if (mode_ == CLIENT) |
---|
[1293] | 527 | network::Client::getSingleton()->closeConnection(); |
---|
[1502] | 528 | else if (mode_ == SERVER) |
---|
[1293] | 529 | server_g->close(); |
---|
[1502] | 530 | |
---|
[1293] | 531 | return true; |
---|
[1038] | 532 | } |
---|
| 533 | } |
---|