| [1661] | 1 | /* |
|---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
|---|
| 3 | * > www.orxonox.net < |
|---|
| 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: |
|---|
| 23 | * Reto Grieder |
|---|
| 24 | * Co-authors: |
|---|
| [1662] | 25 | * Fabian 'x3n' Landau |
|---|
| [1661] | 26 | * |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | #include "OrxonoxStableHeaders.h" |
|---|
| 30 | #include "GSLevel.h" |
|---|
| 31 | |
|---|
| [1686] | 32 | #include <OgreSceneManager.h> |
|---|
| 33 | #include <OgreRoot.h> |
|---|
| [1661] | 34 | #include "core/input/InputManager.h" |
|---|
| 35 | #include "core/input/SimpleInputState.h" |
|---|
| 36 | #include "core/input/KeyBinder.h" |
|---|
| [1662] | 37 | #include "core/Loader.h" |
|---|
| 38 | #include "objects/Backlight.h" |
|---|
| [1694] | 39 | #include "objects/Tickable.h" |
|---|
| [1696] | 40 | #include "tools/Timer.h" |
|---|
| [1662] | 41 | #include "tools/ParticleInterface.h" |
|---|
| [1670] | 42 | #include "Settings.h" |
|---|
| [1662] | 43 | #include "Radar.h" |
|---|
| 44 | #include "GraphicsEngine.h" |
|---|
| [1661] | 45 | |
|---|
| 46 | namespace orxonox |
|---|
| 47 | { |
|---|
| [1670] | 48 | GSLevel::GSLevel(const std::string& name) |
|---|
| [1689] | 49 | : GameState<GSGraphics>(name) |
|---|
| [1674] | 50 | , timeFactor_(1.0f) |
|---|
| [1686] | 51 | , sceneManager_(0) |
|---|
| [1662] | 52 | , keyBinder_(0) |
|---|
| [1670] | 53 | , inputState_(0) |
|---|
| [1662] | 54 | , radar_(0) |
|---|
| 55 | , startLevel_(0) |
|---|
| 56 | , hud_(0) |
|---|
| [1661] | 57 | { |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | GSLevel::~GSLevel() |
|---|
| 61 | { |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | void GSLevel::enter() |
|---|
| 65 | { |
|---|
| [1670] | 66 | inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20); |
|---|
| [1662] | 67 | keyBinder_ = new KeyBinder(); |
|---|
| 68 | keyBinder_->loadBindings(); |
|---|
| [1670] | 69 | inputState_->setHandler(keyBinder_); |
|---|
| [1661] | 70 | |
|---|
| [1662] | 71 | // create Ogre SceneManager for the level |
|---|
| [1688] | 72 | this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager"); |
|---|
| [1686] | 73 | COUT(4) << "Created SceneManager: " << sceneManager_->getName() << std::endl; |
|---|
| [1688] | 74 | |
|---|
| 75 | // temporary hack |
|---|
| [1686] | 76 | GraphicsEngine::getInstance().setLevelSceneManager(this->sceneManager_); |
|---|
| [1662] | 77 | |
|---|
| 78 | // Start the Radar |
|---|
| 79 | this->radar_ = new Radar(); |
|---|
| 80 | |
|---|
| 81 | // Load the HUD |
|---|
| 82 | COUT(3) << "Orxonox: Loading HUD" << std::endl; |
|---|
| 83 | hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo"); |
|---|
| 84 | Loader::load(hud_); |
|---|
| [1674] | 85 | |
|---|
| 86 | // reset game speed to normal |
|---|
| 87 | timeFactor_ = 1.0f; |
|---|
| [1755] | 88 | |
|---|
| 89 | // TODO: insert slomo console command with |
|---|
| 90 | // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false); |
|---|
| [1661] | 91 | } |
|---|
| 92 | |
|---|
| 93 | void GSLevel::leave() |
|---|
| 94 | { |
|---|
| [1662] | 95 | Loader::unload(hud_); |
|---|
| 96 | delete this->hud_; |
|---|
| 97 | |
|---|
| 98 | // this call will delete every BaseObject! |
|---|
| 99 | // But currently this will call methods of objects that exist no more |
|---|
| 100 | // The only 'memory leak' is the ParticleSpawer. They would be deleted here |
|---|
| 101 | // and call a sceneNode method that has already been destroy by the corresponding space ship. |
|---|
| 102 | //Loader::close(); |
|---|
| 103 | |
|---|
| 104 | delete this->radar_; |
|---|
| 105 | |
|---|
| [1688] | 106 | Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_); |
|---|
| [1662] | 107 | |
|---|
| [1670] | 108 | inputState_->setHandler(0); |
|---|
| 109 | InputManager::getInstance().requestDestroyState("game"); |
|---|
| [1662] | 110 | delete this->keyBinder_; |
|---|
| [1661] | 111 | } |
|---|
| 112 | |
|---|
| [1674] | 113 | void GSLevel::ticked(const Clock& time) |
|---|
| [1661] | 114 | { |
|---|
| 115 | // Call those objects that need the real time |
|---|
| [1755] | 116 | for (ObjectList<TickableReal>::iterator it = ObjectList<TickableReal>::begin(); it; ++it) |
|---|
| [1674] | 117 | it->tick(time.getDeltaTime()); |
|---|
| [1661] | 118 | // Call the scene objects |
|---|
| [1755] | 119 | for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) |
|---|
| [1674] | 120 | it->tick(time.getDeltaTime() * this->timeFactor_); |
|---|
| [1696] | 121 | |
|---|
| [1755] | 122 | for (ObjectList<TimerBase>::iterator it = ObjectList<TimerBase>::begin(); it; ++it) |
|---|
| [1696] | 123 | it->tick(time); |
|---|
| [1661] | 124 | } |
|---|
| 125 | |
|---|
| 126 | /** |
|---|
| 127 | @brief |
|---|
| 128 | Changes the speed of Orxonox |
|---|
| 129 | */ |
|---|
| [1662] | 130 | void GSLevel::setTimeFactor(float factor) |
|---|
| 131 | { |
|---|
| [1674] | 132 | float change = factor / this->timeFactor_; |
|---|
| 133 | this->timeFactor_ = factor; |
|---|
| [1755] | 134 | for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it) |
|---|
| [1662] | 135 | it->setSpeedFactor(it->getSpeedFactor() * change); |
|---|
| [1661] | 136 | |
|---|
| [1755] | 137 | for (ObjectList<Backlight>::iterator it = ObjectList<Backlight>::begin(); it; ++it) |
|---|
| [1674] | 138 | it->setTimeFactor(timeFactor_); |
|---|
| [1662] | 139 | } |
|---|
| [1670] | 140 | |
|---|
| 141 | void GSLevel::loadLevel() |
|---|
| 142 | { |
|---|
| 143 | // call the loader |
|---|
| 144 | COUT(0) << "Loading level..." << std::endl; |
|---|
| 145 | startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw"); |
|---|
| 146 | Loader::open(startLevel_); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | void GSLevel::unloadLevel() |
|---|
| 150 | { |
|---|
| 151 | Loader::unload(startLevel_); |
|---|
| 152 | delete this->startLevel_; |
|---|
| 153 | } |
|---|
| [1661] | 154 | } |
|---|