Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Moved Clock from core to util (used in Scope anyway).

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