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