Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3346 was 3346, checked in by rgrieder, 16 years ago

Moved GraphicsManager and GUIManager to the core. Almost no actual code changes though, just moving (here was that Map-hack I had to move to GSGraphics).

  • Property svn:eol-style set to native
File size: 6.7 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:
[2896]25 *      Benjamin Knecht
[1661]26 *
27 */
28
[2896]29/**
[3196]30@file
31@brief
32    Implementation of Graphics GameState class.
[2896]33 */
34
[1661]35#include "GSGraphics.h"
36
[2710]37#include <boost/filesystem.hpp>
[1686]38#include <OgreRenderWindow.h>
[1661]39
[3327]40#include "util/Convert.h"
[2896]41#include "core/Clock.h"
[3327]42#include "core/CommandExecutor.h"
[1662]43#include "core/ConsoleCommand.h"
[2896]44#include "core/Core.h"
45#include "core/Game.h"
46#include "core/GameMode.h"
[3346]47#include "core/GraphicsManager.h"
48#include "core/GUIManager.h"
[1661]49#include "core/input/InputManager.h"
[1788]50#include "core/input/KeyBinder.h"
[3327]51#include "core/input/InputState.h"
[2087]52#include "core/Loader.h"
53#include "core/XMLFile.h"
[1661]54#include "overlays/console/InGameConsole.h"
[3196]55#include "sound/SoundManager.h"
[1686]56
[3346]57// HACK:
58#include "overlays/map/Map.h"
59
[1661]60namespace orxonox
61{
[3280]62    DeclareGameState(GSGraphics, "graphics", true, true);
[2896]63
[3280]64    GSGraphics::GSGraphics(const GameStateConstrParams& params)
65        : GameState(params)
[1661]66        , inputManager_(0)
67        , console_(0)
68        , guiManager_(0)
[2896]69        , graphicsManager_(0)
[3196]70        , soundManager_(0)
[1788]71        , masterKeyBinder_(0)
[2896]72        , masterInputState_(0)
[2087]73        , debugOverlay_(0)
[1661]74    {
75    }
76
77    GSGraphics::~GSGraphics()
78    {
79    }
80
[2896]81    /**
82    @brief
83        This function is called when we enter this game state.
84
85        Since graphics is very important for our game this function does quite a lot:
86        \li starts graphics manager
87        \li loads debug overlay
88        \li manages render window
89        \li creates input manager
90        \li loads master key bindings
[3196]91        \li loads the SoundManager
[2896]92        \li loads ingame console
93        \li loads GUI interface (GUIManager)
94        \li creates console command to toggle GUI
95    */
96    void GSGraphics::activate()
[1661]97    {
[3343]98        // Load OGRE, CEGUI and OIS
99        Core::getInstance().loadGraphics();
[1696]100
[3280]101        // Load OGRE including the render window
[2896]102        this->graphicsManager_ = new GraphicsManager();
[2710]103
[2087]104        // load debug overlay
105        COUT(3) << "Loading Debug Overlay..." << std::endl;
[2759]106        this->debugOverlay_ = new XMLFile((Core::getMediaPath() / "overlay" / "debug.oxo").string());
[2087]107        Loader::open(debugOverlay_);
[1686]108
[2896]109        // The render window width and height are used to set up the mouse movement.
110        size_t windowHnd = 0;
111        Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
112        renderWindow->getCustomAttribute("WINDOW", &windowHnd);
113
[1661]114        // Calls the InputManager which sets up the input devices.
[3327]115        inputManager_ = new InputManager(windowHnd);
[2896]116
117        // load master key bindings
[3327]118        masterInputState_ = InputManager::getInstance().createInputState("master", true);
[2103]119        masterKeyBinder_ = new KeyBinder();
[2710]120        masterKeyBinder_->loadBindings("masterKeybindings.ini");
[2896]121        masterInputState_->setKeyHandler(masterKeyBinder_);
[1661]122
[3196]123        // Load the SoundManager
124        soundManager_ = new SoundManager();
125
[1661]126        // Load the InGameConsole
127        console_ = new InGameConsole();
[3327]128        console_->initialise();
[1661]129
130        // load the CEGUI interface
[3338]131        guiManager_ = new GUIManager(renderWindow);
[1674]132
[2896]133        // add console command to toggle GUI
134        FunctorMember<GSGraphics>* functor = createFunctor(&GSGraphics::toggleGUI);
135        functor->setObject(this);
136        this->ccToggleGUI_ = createConsoleCommand(functor, "toggleGUI");
137        CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_);
138
139        // enable master input
[3327]140        InputManager::getInstance().enterState("master");
[1661]141    }
142
[2896]143    /**
144    @brief
145        This function is called when the game state is left
146
147        Created references, input states and console commands are deleted.
148    */
149    void GSGraphics::deactivate()
[1661]150    {
[2928]151/*
[2896]152        if (this->ccToggleGUI_)
153        {
154            delete this->ccToggleGUI_;
155            this->ccToggleGUI_ = 0;
156        }
[2928]157*/
[2662]158
[2896]159        masterInputState_->setHandler(0);
[3327]160        InputManager::getInstance().destroyState("master");
[2896]161        delete this->masterKeyBinder_;
[1878]162
[1662]163        delete this->guiManager_;
164        delete this->console_;
[1661]165
[2087]166        Loader::unload(this->debugOverlay_);
167        delete this->debugOverlay_;
168
[3196]169        delete this->soundManager_;
170
[2896]171        delete this->inputManager_;
172        this->inputManager_ = 0;
[2662]173
[3346]174        // HACK:
175        Map::hackDestroyMap();
176
[2896]177        delete graphicsManager_;
[1696]178
[3343]179        // Unload OGRE, CEGUI and OIS
180        Core::getInstance().loadGraphics();
[2896]181    }
[1824]182
[2896]183    /**
184    @brief
185        Toggles the visibility of the current GUI
[1824]186
[2896]187        This function just executes a Lua function in the main script of the GUI by accessing the GUIManager.
188        For more details on this function check out the Lua code.
189    */
190    void GSGraphics::toggleGUI()
191    {
[3280]192        GUIManager::getInstance().executeCode("toggleGUI()");
[1661]193    }
194
[1662]195    /**
[2662]196    @note
[1662]197        A note about the Ogre::FrameListener: Even though we don't use them,
198        they still get called. However, the delta times are not correct (except
199        for timeSinceLastFrame, which is the most important). A little research
200        as shown that there is probably only one FrameListener that doesn't even
201        need the time. So we shouldn't run into problems.
202    */
[2896]203    void GSGraphics::update(const Clock& time)
[1661]204    {
[2896]205        if (this->getActivity().topState)
[2087]206        {
[2896]207            // This state can not 'survive' on its own.
208            // Load a user interface therefore
209            Game::getInstance().requestState("mainMenu");
[2087]210        }
211
[2896]212        uint64_t timeBeforeTick = time.getRealMicroseconds();
[1661]213
[3084]214        this->inputManager_->update(time);
[2896]215        this->console_->update(time);
[1661]216
[2896]217        uint64_t timeAfterTick = time.getRealMicroseconds();
[1661]218
[2896]219        // Also add our tick time
220        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
[1661]221
[3084]222        // Process gui events
223        this->guiManager_->update(time);
[2896]224        // Render
225        this->graphicsManager_->update(time);
[1661]226    }
227}
Note: See TracBrowser for help on using the repository browser.