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
RevLine 
[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
32#include "core/input/InputManager.h"
33#include "core/input/SimpleInputState.h"
34#include "core/input/KeyBinder.h"
[1662]35#include "core/Loader.h"
[2087]36#include "core/XMLFile.h"
[1887]37#include "core/CommandExecutor.h"
38#include "core/ConsoleCommand.h"
[1934]39#include "core/CommandLine.h"
[1887]40#include "core/ConfigValueIncludes.h"
41#include "core/CoreIncludes.h"
[2087]42#include "core/Core.h"
[1694]43#include "objects/Tickable.h"
[1819]44#include "objects/Radar.h"
[2087]45#include "CameraManager.h"
46#include "LevelManager.h"
[2662]47#include "PlayerManager.h"
[1661]48
49namespace orxonox
50{
[2662]51    SetCommandLineArgument(level, "presentation.oxw").shortcut("l");
[1934]52
[2087]53    GSLevel::GSLevel()
54//        : GameState<GSGraphics>(name)
[2662]55        : keyBinder_(0)
[1670]56        , inputState_(0)
[1662]57        , radar_(0)
[2087]58        , startFile_(0)
59        , cameraManager_(0)
60        , levelManager_(0)
[1661]61    {
[1887]62        RegisterObject(GSLevel);
[2662]63
64        this->ccKeybind_ = 0;
65        this->ccTkeybind_ = 0;
66
[1887]67        setConfigValues();
[1661]68    }
69
70    GSLevel::~GSLevel()
71    {
72    }
73
[1887]74    void GSLevel::setConfigValues()
75    {
76        SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
[2103]77        SetConfigValue(defaultKeybindings_, "def_keybindings.ini")
78            .description("Filename of default keybindings.");
[1887]79    }
80
[2087]81    void GSLevel::enter(Ogre::Viewport* viewport)
[1661]82    {
[2087]83        if (Core::showsGraphics())
84        {
85            inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
86            keyBinder_ = new KeyBinder();
[2103]87            keyBinder_->loadBindings("keybindings.ini", defaultKeybindings_);
[2087]88            inputState_->setHandler(keyBinder_);
[1661]89
[2087]90            // create the global CameraManager
91            assert(viewport);
92            this->cameraManager_ = new CameraManager(viewport);
[1688]93
[2087]94            // Start the Radar
95            this->radar_ = new Radar();
96        }
[1662]97
[2662]98        this->playerManager_ = new PlayerManager();
99
[2087]100        if (Core::isMaster())
101        {
102            // create the global LevelManager
103            this->levelManager_ = new LevelManager();
[1662]104
[2087]105            this->loadLevel();
106        }
[1755]107
[2087]108        if (Core::showsGraphics())
109        {
110            // TODO: insert slomo console command with
111            // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false);
[1887]112
[2087]113            // keybind console command
114            FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
115            functor1->setObject(this);
[2662]116            ccKeybind_ = createConsoleCommand(functor1, "keybind");
117            CommandExecutor::addConsoleCommandShortcut(ccKeybind_);
[2087]118            FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind);
119            functor2->setObject(this);
[2662]120            ccTkeybind_ = createConsoleCommand(functor2, "tkeybind");
121            CommandExecutor::addConsoleCommandShortcut(ccTkeybind_);
[2087]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        }
[2662]128    }
[2087]129
[2662]130    void GSLevel::leave()
131    {
132        // destroy console commands
133        if (this->ccKeybind_)
[2087]134        {
[2662]135            delete this->ccKeybind_;
136            this->ccKeybind_ = 0;
[2087]137        }
[2662]138        if (this->ccTkeybind_)
139        {
140            delete this->ccTkeybind_;
141            this->ccTkeybind_ = 0;
142        }
[1661]143
[1662]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
[2087]150        if (Core::showsGraphics())
151            InputManager::getInstance().requestLeaveState("game");
[1662]152
[2087]153        if (Core::isMaster())
154            this->unloadLevel();
[1662]155
[2087]156        if (this->radar_)
[2662]157        {
[2087]158            delete this->radar_;
[2662]159            this->radar_ = 0;
160        }
[2087]161
162        if (this->cameraManager_)
[2662]163        {
[2087]164            delete this->cameraManager_;
[2662]165            this->cameraManager_ = 0;
166        }
[2087]167
168        if (this->levelManager_)
[2662]169        {
[2087]170            delete this->levelManager_;
[2662]171            this->levelManager_ = 0;
172        }
[2087]173
[2662]174        if (this->playerManager_)
175        {
176            delete this->playerManager_;
177            this->playerManager_ = 0;
178        }
179
[2087]180        if (Core::showsGraphics())
181        {
182            inputState_->setHandler(0);
183            InputManager::getInstance().requestDestroyState("game");
184            if (this->keyBinder_)
[2662]185            {
[2087]186                delete this->keyBinder_;
[2662]187                this->keyBinder_ = 0;
188            }
[2087]189        }
[1661]190    }
191
[1674]192    void GSLevel::ticked(const Clock& time)
[1661]193    {
[2087]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_);
[1661]198    }
199
[1670]200    void GSLevel::loadLevel()
201    {
202        // call the loader
203        COUT(0) << "Loading level..." << std::endl;
[1934]204        std::string levelName;
205        CommandLine::getValue("level", &levelName);
[2685]206        startFile_ = new XMLFile(Core::getMediaPath() + std::string("levels/") + levelName);
[2087]207        Loader::open(startFile_);
[1670]208    }
209
210    void GSLevel::unloadLevel()
211    {
[2087]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_;
[1670]219    }
[1887]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    {
[2087]241        if (Core::showsGraphics())
[1887]242        {
[2087]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)
[1887]249            {
[2087]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.
[1887]259            }
[2087]260            else
[1887]261            {
[2087]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.
[1887]272            }
273        }
274    }
[1661]275}
Note: See TracBrowser for help on using the repository browser.