Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/orxonox/gamestates/GSLevel.cc @ 1672

Last change on this file since 1672 was 1672, checked in by rgrieder, 16 years ago
  • Changed GameState so that the new RootGameState can override 2 virtual methods
  • added RootGameState that takes care of state transitions (can only happen between ticks)
  • moved main loop to GSRoot instead of GSGraphics
  • network GameStates not yet finished
  • GraphicsEngine not yet merged into GSGraphics
  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
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 "core/input/InputManager.h"
33#include "core/input/SimpleInputState.h"
34#include "core/input/KeyBinder.h"
35#include "core/Loader.h"
36#include "objects/Backlight.h"
37#include "tools/ParticleInterface.h"
38#include "Settings.h"
39#include "Radar.h"
40#include "GraphicsEngine.h"
41
42namespace orxonox
43{
44    GSLevel::GSLevel(const std::string& name)
45        : GameState(name)
46        , timefactor_(1.0f)
47        , keyBinder_(0)
48        , inputState_(0)
49        , radar_(0)
50        , startLevel_(0)
51        , hud_(0)
52    {
53    }
54
55    GSLevel::~GSLevel()
56    {
57    }
58
59    void GSLevel::enter()
60    {
61        inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
62        keyBinder_ = new KeyBinder();
63        keyBinder_->loadBindings();
64        inputState_->setHandler(keyBinder_);
65
66        // create Ogre SceneManager for the level
67        GraphicsEngine::getInstance().createNewScene();
68
69        // Start the Radar
70        this->radar_ = new Radar();
71
72        // Load the HUD
73        COUT(3) << "Orxonox: Loading HUD" << std::endl;
74        hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo");
75        Loader::load(hud_);
76    }
77
78    void GSLevel::leave()
79    {
80        Loader::unload(hud_);
81        delete this->hud_;
82
83        // this call will delete every BaseObject!
84        // But currently this will call methods of objects that exist no more
85        // The only 'memory leak' is the ParticleSpawer. They would be deleted here
86        // and call a sceneNode method that has already been destroy by the corresponding space ship.
87        //Loader::close();
88
89        delete this->radar_;
90
91        // TODO: delete SceneManager
92
93        inputState_->setHandler(0);
94        InputManager::getInstance().requestDestroyState("game");
95        delete this->keyBinder_;
96    }
97
98    void GSLevel::ticked(float dt, uint64_t time)
99    {
100        // Call those objects that need the real time
101        for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
102            it->tick(dt);
103        // Call the scene objects
104        for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
105            it->tick(dt * this->timefactor_);
106    }
107
108    /**
109    @brief
110        Changes the speed of Orxonox
111    */
112    void GSLevel::setTimeFactor(float factor)
113    {
114        float change = factor / this->timefactor_;
115        this->timefactor_ = factor;
116        for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it)
117            it->setSpeedFactor(it->getSpeedFactor() * change);
118
119        for (Iterator<Backlight> it = ObjectList<Backlight>::begin(); it; ++it)
120            it->setTimeFactor(timefactor_);
121    }
122
123    void GSLevel::loadLevel()
124    {
125        // call the loader
126        COUT(0) << "Loading level..." << std::endl;
127        startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw");
128        Loader::open(startLevel_);
129    }
130
131    void GSLevel::unloadLevel()
132    {
133        Loader::unload(startLevel_);
134        delete this->startLevel_;
135    }
136}
Note: See TracBrowser for help on using the repository browser.