| [157] | 1 | /* | 
|---|
 | 2 |  *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
 | 3 |  * | 
|---|
 | 4 |  * | 
|---|
 | 5 |  *   License notice: | 
|---|
 | 6 |  * | 
|---|
 | 7 |  *   This program is free software: you can redistribute it and/or modify | 
|---|
 | 8 |  *   it under the terms of the GNU General Public License as published by | 
|---|
 | 9 |  *   the Free Software Foundation, either version 3 of the License, or | 
|---|
 | 10 |  *   (at your option) any later version. | 
|---|
 | 11 |  * | 
|---|
 | 12 |  *   This program is distributed in the hope that it will be useful, | 
|---|
 | 13 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
 | 14 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
 | 15 |  *   GNU General Public License for more details. | 
|---|
 | 16 |  * | 
|---|
 | 17 |  *   You should have received a copy of the GNU General Public License | 
|---|
 | 18 |  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
 | 19 |  * | 
|---|
 | 20 |  * | 
|---|
 | 21 |  *   Author: | 
|---|
 | 22 |  *      Reto Grieder | 
|---|
 | 23 |  *   Co-authors: | 
|---|
 | 24 |  *      ... | 
|---|
 | 25 |  * | 
|---|
 | 26 |  */ | 
|---|
 | 27 |  | 
|---|
| [159] | 28 | /** | 
|---|
 | 29 | * Basic part of the game. | 
|---|
 | 30 | * It sets up Ogre and most important of all: Orxonox is the master of the | 
|---|
 | 31 | * main loop and therefore time itself. | 
|---|
 | 32 | */ | 
|---|
| [157] | 33 |  | 
|---|
| [161] | 34 | #include "OgreRoot.h" | 
|---|
 | 35 | #include "OgreTimer.h" | 
|---|
 | 36 | #include "OgreWindowEventUtilities.h" | 
|---|
| [159] | 37 |  | 
|---|
| [161] | 38 | #include "ogre_control.h" | 
|---|
 | 39 | #include "run_manager.h" | 
|---|
| [157] | 40 | #include "orxonox.h" | 
|---|
 | 41 |  | 
|---|
 | 42 |  | 
|---|
| [169] | 43 | namespace orxonox { | 
|---|
| [159] | 44 |  | 
|---|
| [161] | 45 |   /** | 
|---|
 | 46 |   * Empty Constructor. | 
|---|
 | 47 |   */ | 
|---|
 | 48 |   Orxonox::Orxonox() | 
|---|
 | 49 |   { | 
|---|
 | 50 |   } | 
|---|
| [159] | 51 |  | 
|---|
 | 52 |  | 
|---|
| [161] | 53 |   /** | 
|---|
 | 54 |   * Empty Destructor. | 
|---|
 | 55 |   */ | 
|---|
 | 56 |   Orxonox::~Orxonox() | 
|---|
 | 57 |   { | 
|---|
 | 58 |   } | 
|---|
| [159] | 59 |  | 
|---|
| [157] | 60 |  | 
|---|
| [161] | 61 |   /** | 
|---|
 | 62 |   * Starts and runs the game | 
|---|
 | 63 |   */ | 
|---|
 | 64 |   void Orxonox::go(void) | 
|---|
 | 65 |   { | 
|---|
 | 66 |           if (!setup()) | 
|---|
 | 67 |                   return; | 
|---|
| [157] | 68 |  | 
|---|
| [161] | 69 |     timer_ = new Ogre::Timer(); | 
|---|
| [157] | 70 |  | 
|---|
| [161] | 71 |           unsigned long lastTime = timer_->getMilliseconds(); | 
|---|
| [157] | 72 |  | 
|---|
| [161] | 73 |           while (true) | 
|---|
 | 74 |           { | 
|---|
 | 75 |                   //Pump messages in all registered RenderWindow windows | 
|---|
 | 76 |       Ogre::WindowEventUtilities::messagePump(); | 
|---|
| [157] | 77 |  | 
|---|
| [161] | 78 |                   ogre_->getRoot()->renderOneFrame(); | 
|---|
| [157] | 79 |  | 
|---|
| [161] | 80 |                   if (!runMgr_->tick(timer_->getMilliseconds(), | 
|---|
 | 81 |               (timer_->getMilliseconds() - lastTime) / 1000.0)) | 
|---|
 | 82 |                           break; | 
|---|
 | 83 |                   lastTime = timer_->getMilliseconds(); | 
|---|
 | 84 |           } | 
|---|
| [157] | 85 |  | 
|---|
| [161] | 86 |           // clean up | 
|---|
 | 87 |           destroy(); | 
|---|
 | 88 |   } | 
|---|
| [157] | 89 |  | 
|---|
 | 90 |  | 
|---|
| [161] | 91 |   /** | 
|---|
 | 92 |   * Create render engine, render window and the Run manager. | 
|---|
 | 93 |   * @return False if failed. | 
|---|
 | 94 |   */ | 
|---|
 | 95 |   bool Orxonox::setup(void) | 
|---|
 | 96 |   { | 
|---|
 | 97 |           // create new 3D ogre render engine | 
|---|
 | 98 |           ogre_ = new OgreControl(); | 
|---|
 | 99 |           ogre_->initialise(); | 
|---|
| [157] | 100 |  | 
|---|
| [161] | 101 |           runMgr_ = new RunManager(ogre_); | 
|---|
| [157] | 102 |  | 
|---|
| [161] | 103 |           return true; | 
|---|
 | 104 |   } | 
|---|
| [157] | 105 |  | 
|---|
| [161] | 106 |  | 
|---|
 | 107 |   /** | 
|---|
 | 108 |   * Clean everything up. | 
|---|
 | 109 |   */ | 
|---|
 | 110 |   void Orxonox::destroy() | 
|---|
 | 111 |   { | 
|---|
 | 112 |           if (timer_) | 
|---|
 | 113 |                   delete timer_; | 
|---|
 | 114 |           if (runMgr_) | 
|---|
 | 115 |                   delete runMgr_; | 
|---|
 | 116 |           if (ogre_) | 
|---|
 | 117 |                   delete ogre_; | 
|---|
 | 118 |   } | 
|---|
 | 119 |  | 
|---|
| [157] | 120 | } | 
|---|