Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/orxonox/gamestates/GSGraphics.cc @ 5842

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

Moved GameStates back to the orxonox library. This resolves an issue at startup if the command line arguments contained errors. Furthermore you can now simply not build the modules folder and still get a working orxonox.

DELETE ALL "libgamestates*" FILES (esp. in the modules output folder) to avoid problems with duplicate libraries!!!

  • Property svn:eol-style set to native
File size: 5.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 *      Benjamin Knecht
26 *
27 */
28
29/**
30@file
31@brief
32    Implementation of Graphics GameState class.
33 */
34
35#include "GSGraphics.h"
36
37#include "util/Convert.h"
38#include "core/Clock.h"
39#include "core/CommandExecutor.h"
40#include "core/ConsoleCommand.h"
41#include "core/Game.h"
42#include "core/GUIManager.h"
43#include "core/input/InputManager.h"
44#include "core/input/KeyBinder.h"
45#include "core/input/InputState.h"
46#include "core/Loader.h"
47#include "core/XMLFile.h"
48#include "overlays/InGameConsole.h"
49#include "sound/SoundManager.h"
50
51// HACK:
52#include "overlays/Map.h"
53
54namespace orxonox
55{
56    DeclareGameState(GSGraphics, "graphics", false, true);
57
58    GSGraphics::GSGraphics(const GameStateInfo& info)
59        : GameState(info)
60        , console_(0)
61        , soundManager_(0)
62        , masterKeyBinder_(0)
63        , masterInputState_(0)
64        , debugOverlay_(0)
65    {
66        // load master key bindings
67        masterInputState_ = InputManager::getInstance().createInputState("master", true);
68        masterKeyBinder_ = new KeyBinder();
69        masterInputState_->setKeyHandler(masterKeyBinder_);
70    }
71
72    GSGraphics::~GSGraphics()
73    {
74        InputManager::getInstance().destroyState("master");
75        this->masterKeyBinder_->destroy();
76    }
77
78    /**
79    @brief
80        This function is called when we enter this game state.
81
82        Since graphics is very important for our game this function does quite a lot:
83        \li starts graphics manager
84        \li loads debug overlay
85        \li manages render window
86        \li creates input manager
87        \li loads master key bindings
88        \li loads the SoundManager
89        \li loads ingame console
90        \li loads GUI interface (GUIManager)
91        \li creates console command to toggle GUI
92    */
93    void GSGraphics::activate()
94    {
95        // load debug overlay
96        COUT(3) << "Loading Debug Overlay..." << std::endl;
97        this->debugOverlay_ = new XMLFile("debug.oxo");
98        Loader::open(debugOverlay_);
99
100        masterKeyBinder_->loadBindings("masterKeybindings.ini");
101
102        // Load the SoundManager
103        soundManager_ = new SoundManager();
104
105        // Load the InGameConsole
106        console_ = new InGameConsole();
107        console_->initialise();
108
109        // add console command to toggle GUI
110        this->ccToggleGUI_ = createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI");
111        CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_);
112
113        // enable master input
114        InputManager::getInstance().enterState("master");
115    }
116
117    /**
118    @brief
119        This function is called when the game state is left
120
121        Created references, input states and console commands are deleted.
122    */
123    void GSGraphics::deactivate()
124    {
125/*
126        if (this->ccToggleGUI_)
127        {
128            delete this->ccToggleGUI_;
129            this->ccToggleGUI_ = 0;
130        }
131*/
132
133        this->console_->destroy();
134
135        Loader::unload(this->debugOverlay_);
136        delete this->debugOverlay_;
137
138        this->soundManager_->destroy();
139
140        // HACK: (destroys a resource smart pointer)
141        Map::hackDestroyMap();
142    }
143
144    /**
145    @brief
146        Toggles the visibility of the current GUI
147
148        This function just executes a Lua function in the main script of the GUI by accessing the GUIManager.
149        For more details on this function check out the Lua code.
150    */
151    void GSGraphics::toggleGUI()
152    {
153        GUIManager::getInstance().executeCode("toggleGUI()");
154    }
155
156    /**
157    @note
158        A note about the Ogre::FrameListener: Even though we don't use them,
159        they still get called. However, the delta times are not correct (except
160        for timeSinceLastFrame, which is the most important). A little research
161        as shown that there is probably only one FrameListener that doesn't even
162        need the time. So we shouldn't run into problems.
163    */
164    void GSGraphics::update(const Clock& time)
165    {
166        if (this->getActivity().topState)
167        {
168            // This state can not 'survive' on its own.
169            // Load a user interface therefore
170            Game::getInstance().requestState("mainMenu");
171        }
172
173        this->console_->update(time);
174    }
175}
Note: See TracBrowser for help on using the repository browser.