Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1663 was 1663, checked in by rgrieder, 16 years ago

Added CommandLine class.
You can now call SetCommandLineArgument like SetConsoleCommand and hereby define a new command line argument. They are passed in main() and then they can be accessed by commandLine::getCommandLineArgument().

  • Property svn:eol-style set to native
File size: 4.7 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/ConsoleCommand.h"
33#include "core/input/InputManager.h"
34#include "core/input/SimpleInputState.h"
35#include "core/input/KeyBinder.h"
36#include "core/Loader.h"
37#include "core/CommandLine.h"
38#include "overlays/console/InGameConsole.h"
39#include "gui/GUIManager.h"
40#include "objects/Backlight.h"
41#include "tools/ParticleInterface.h"
42#include "Radar.h"
43#include "Settings.h"
44#include "GraphicsEngine.h"
45
46namespace orxonox
47{
48    SetCommandLineArgument(port, 55556).setShortcut("p");
49    SetCommandLineArgument(ip, std::string("127.0.0.0"));
50
51    GSLevel::GSLevel()
52        : GameState("level")
53        , timefactor_(1.0f)
54        , keyBinder_(0)
55        , radar_(0)
56        , startLevel_(0)
57        , hud_(0)
58    {
59    }
60
61    GSLevel::~GSLevel()
62    {
63    }
64
65    void GSLevel::enter()
66    {
67        keyBinder_ = new KeyBinder();
68        keyBinder_->loadBindings();
69        InputManager::getInstance().createInputState<SimpleInputState>("game", 20)->setHandler(keyBinder_);
70
71        // create Ogre SceneManager for the level
72        GraphicsEngine::getInstance().createNewScene();
73
74        // Start the Radar
75        this->radar_ = new Radar();
76
77        // Load the HUD
78        COUT(3) << "Orxonox: Loading HUD" << std::endl;
79        hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo");
80        Loader::load(hud_);
81
82        // call the loader
83        COUT(0) << "Loading level..." << std::endl;
84        startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw");
85        Loader::open(startLevel_);
86
87        // add console commands
88        FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
89        functor->setObject(this);
90        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor"));
91
92        // level is loaded: we can start capturing the input
93        InputManager::getInstance().requestEnterState("game");
94    }
95
96    void GSLevel::leave()
97    {
98        InputManager::getInstance().requestLeaveState("game");
99
100        // TODO: Remove and destroy console command
101
102        Loader::unload(startLevel_);
103        delete this->startLevel_;
104
105        Loader::unload(hud_);
106        delete this->hud_;
107
108        // this call will delete every BaseObject!
109        // But currently this will call methods of objects that exist no more
110        // The only 'memory leak' is the ParticleSpawer. They would be deleted here
111        // and call a sceneNode method that has already been destroy by the corresponding space ship.
112        //Loader::close();
113
114        delete this->radar_;
115
116        // TODO: delete SceneManager
117
118        InputManager::getInstance().destroyState("game");
119        delete this->keyBinder_;
120    }
121
122    bool GSLevel::tick(float dt)
123    {
124        // Call those objects that need the real time
125        for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
126            it->tick(dt);
127        // Call the scene objects
128        for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
129            it->tick(dt * this->timefactor_);
130
131        // TODO: split file into server/client/standalone
132        // call server/client with normal dt
133        //if (client_g)
134        //    client_g->tick(dt * this->timefactor_);
135        //if (server_g)
136        //    server_g->tick(dt * this->timefactor_);
137
138        return true;
139    }
140
141    /**
142    @brief
143        Changes the speed of Orxonox
144    */
145    void GSLevel::setTimeFactor(float factor)
146    {
147        float change = factor / this->timefactor_;
148        this->timefactor_ = factor;
149        for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it)
150            it->setSpeedFactor(it->getSpeedFactor() * change);
151
152        for (Iterator<Backlight> it = ObjectList<Backlight>::begin(); it; ++it)
153            it->setTimeFactor(timefactor_);
154    }
155}
Note: See TracBrowser for help on using the repository browser.