Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/resource/src/orxonox/gamestates/GSGraphics.cc @ 3349

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

Moved InputManager, GUIManager and GraphicsManager handling from GSGraphics to Core.

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