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