Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/buildsystem3/src/orxonox/gamestates/GSLevel.cc @ 2685

Last change on this file since 2685 was 2685, checked in by rgrieder, 15 years ago

Fixed install target:

  • log and config file go a to separate folder each
  • The SignalHandler crash log is now "orxonox_crash.log" to avoid opening the file twice which might result in problems
  • moved tcl scripts to media/tcl8.#/ as a temporary solution. I've also created a ticket to fix this.
  • UPDATE YOUR MEDIA REPOSITORY
  • orxonox.log pre-main gets written to either %TEMP% (windows) or /tmp (Unix) and when the path was set, the content is copied.
  • removed Settings class and moved media path to Core
  • media, log and config path are now all in Core where only the media path can be configured via ini file or command line
  • Core::isDevBuild() tells whether we are running in the build or the installation directory (determined by the presence of "orxonox_dev_build.kepp_me" in the binary dir)
  • renamed Settings::getDataPath to Core::getMediaPath
  • Property svn:eol-style set to native
File size: 9.1 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 "core/XMLFile.h"
37#include "core/CommandExecutor.h"
38#include "core/ConsoleCommand.h"
39#include "core/CommandLine.h"
40#include "core/ConfigValueIncludes.h"
41#include "core/CoreIncludes.h"
42#include "core/Core.h"
43#include "objects/Tickable.h"
44#include "objects/Radar.h"
45#include "CameraManager.h"
46#include "LevelManager.h"
47#include "PlayerManager.h"
48
49namespace orxonox
50{
51    SetCommandLineArgument(level, "presentation.oxw").shortcut("l");
52
53    GSLevel::GSLevel()
54//        : GameState<GSGraphics>(name)
55        : keyBinder_(0)
56        , inputState_(0)
57        , radar_(0)
58        , startFile_(0)
59        , cameraManager_(0)
60        , levelManager_(0)
61    {
62        RegisterObject(GSLevel);
63
64        this->ccKeybind_ = 0;
65        this->ccTkeybind_ = 0;
66
67        setConfigValues();
68    }
69
70    GSLevel::~GSLevel()
71    {
72    }
73
74    void GSLevel::setConfigValues()
75    {
76        SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
77        SetConfigValue(defaultKeybindings_, "def_keybindings.ini")
78            .description("Filename of default keybindings.");
79    }
80
81    void GSLevel::enter(Ogre::Viewport* viewport)
82    {
83        if (Core::showsGraphics())
84        {
85            inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
86            keyBinder_ = new KeyBinder();
87            keyBinder_->loadBindings("keybindings.ini", defaultKeybindings_);
88            inputState_->setHandler(keyBinder_);
89
90            // create the global CameraManager
91            assert(viewport);
92            this->cameraManager_ = new CameraManager(viewport);
93
94            // Start the Radar
95            this->radar_ = new Radar();
96        }
97
98        this->playerManager_ = new PlayerManager();
99
100        if (Core::isMaster())
101        {
102            // create the global LevelManager
103            this->levelManager_ = new LevelManager();
104
105            this->loadLevel();
106        }
107
108        if (Core::showsGraphics())
109        {
110            // TODO: insert slomo console command with
111            // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false);
112
113            // keybind console command
114            FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
115            functor1->setObject(this);
116            ccKeybind_ = createConsoleCommand(functor1, "keybind");
117            CommandExecutor::addConsoleCommandShortcut(ccKeybind_);
118            FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind);
119            functor2->setObject(this);
120            ccTkeybind_ = createConsoleCommand(functor2, "tkeybind");
121            CommandExecutor::addConsoleCommandShortcut(ccTkeybind_);
122            // set our console command as callback for the key detector
123            InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
124
125            // level is loaded: we can start capturing the input
126            InputManager::getInstance().requestEnterState("game");
127        }
128    }
129
130    void GSLevel::leave()
131    {
132        // destroy console commands
133        if (this->ccKeybind_)
134        {
135            delete this->ccKeybind_;
136            this->ccKeybind_ = 0;
137        }
138        if (this->ccTkeybind_)
139        {
140            delete this->ccTkeybind_;
141            this->ccTkeybind_ = 0;
142        }
143
144        // this call will delete every BaseObject!
145        // But currently this will call methods of objects that exist no more
146        // The only 'memory leak' is the ParticleSpawer. They would be deleted here
147        // and call a sceneNode method that has already been destroy by the corresponding space ship.
148        //Loader::close();
149
150        if (Core::showsGraphics())
151            InputManager::getInstance().requestLeaveState("game");
152
153        if (Core::isMaster())
154            this->unloadLevel();
155
156        if (this->radar_)
157        {
158            delete this->radar_;
159            this->radar_ = 0;
160        }
161
162        if (this->cameraManager_)
163        {
164            delete this->cameraManager_;
165            this->cameraManager_ = 0;
166        }
167
168        if (this->levelManager_)
169        {
170            delete this->levelManager_;
171            this->levelManager_ = 0;
172        }
173
174        if (this->playerManager_)
175        {
176            delete this->playerManager_;
177            this->playerManager_ = 0;
178        }
179
180        if (Core::showsGraphics())
181        {
182            inputState_->setHandler(0);
183            InputManager::getInstance().requestDestroyState("game");
184            if (this->keyBinder_)
185            {
186                delete this->keyBinder_;
187                this->keyBinder_ = 0;
188            }
189        }
190    }
191
192    void GSLevel::ticked(const Clock& time)
193    {
194        // Commented by 1337: Temporarily moved to GSGraphics.
195        //// Call the scene objects
196        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
197        //    it->tick(time.getDeltaTime() * this->timeFactor_);
198    }
199
200    void GSLevel::loadLevel()
201    {
202        // call the loader
203        COUT(0) << "Loading level..." << std::endl;
204        std::string levelName;
205        CommandLine::getValue("level", &levelName);
206        startFile_ = new XMLFile(Core::getMediaPath() + std::string("levels/") + levelName);
207        Loader::open(startFile_);
208    }
209
210    void GSLevel::unloadLevel()
211    {
212        //////////////////////////////////////////////////////////////////////////////////////////
213        // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO //
214        //////////////////////////////////////////////////////////////////////////////////////////
215        // Loader::unload(startFile_); // TODO: REACTIVATE THIS IF LOADER::UNLOAD WORKS PROPERLY /
216        //////////////////////////////////////////////////////////////////////////////////////////
217
218        delete this->startFile_;
219    }
220
221    void GSLevel::keybind(const std::string &command)
222    {
223        this->keybindInternal(command, false);
224    }
225
226    void GSLevel::tkeybind(const std::string &command)
227    {
228        this->keybindInternal(command, true);
229    }
230
231    /**
232    @brief
233        Assigns a command string to a key/button/axis. The name is determined via KeyDetector.
234    @param command
235        Command string that can be executed by the CommandExecutor
236        OR: Internal string "KeybindBindingStringKeyName=" used for the second call to identify
237        the key/button/axis that has been activated. This is configured above in enter().
238    */
239    void GSLevel::keybindInternal(const std::string& command, bool bTemporary)
240    {
241        if (Core::showsGraphics())
242        {
243            static std::string bindingString = "";
244            static bool bTemporarySaved = false;
245            static bool bound = true;
246            // note: We use a long name to make 'sure' that the user doesn't use it accidentally.
247            // Howerver there will be no real issue if it happens anyway.
248            if (command.find(keyDetectorCallbackCode_) != 0)
249            {
250                if (bound)
251                {
252                    COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
253                    InputManager::getInstance().requestEnterState("detector");
254                    bindingString = command;
255                    bTemporarySaved = bTemporary;
256                    bound = false;
257                }
258                //else:  We're still in a keybind command. ignore this call.
259            }
260            else
261            {
262                if (!bound)
263                {
264                    // user has pressed the key
265                    std::string name = command.substr(this->keyDetectorCallbackCode_.size());
266                    COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl;
267                    this->keyBinder_->setBinding(bindingString, name, bTemporarySaved);
268                    InputManager::getInstance().requestLeaveState("detector");
269                    bound = true;
270                }
271                // else: A key was pressed within the same tick, ignore it.
272            }
273        }
274    }
275}
Note: See TracBrowser for help on using the repository browser.