Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/orxonox/gamestates/GSGraphics.cc @ 2992

Last change on this file since 2992 was 2875, checked in by bknecht, 16 years ago

(Doxygen) Documentation added for GUIManager and some GameState classes.

  • Property svn:eol-style set to native
File size: 7.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:
[2875]25 *      Benjamin Knecht
[1661]26 *
27 */
28
[2875]29/**
30    @file
31    @brief Implementation of Graphics GameState class.
32 */
33
[1661]34#include "OrxonoxStableHeaders.h"
35#include "GSGraphics.h"
36
[2710]37#include <boost/filesystem.hpp>
[1686]38#include <OgreRenderWindow.h>
[1661]39
[1755]40#include "util/Debug.h"
[1662]41#include "core/ConfigValueIncludes.h"
[2850]42#include "core/Clock.h"
[2869]43#include "core/ConsoleCommand.h"
[2847]44#include "core/Core.h"
[1686]45#include "core/CoreIncludes.h"
[2847]46#include "core/Game.h"
[2848]47#include "core/GameMode.h"
[1661]48#include "core/input/InputManager.h"
[1788]49#include "core/input/KeyBinder.h"
[2816]50#include "core/input/SimpleInputState.h"
[2087]51#include "core/Loader.h"
52#include "core/XMLFile.h"
[1661]53#include "overlays/console/InGameConsole.h"
54#include "gui/GUIManager.h"
[2801]55#include "GraphicsManager.h"
[1661]56
57namespace orxonox
58{
[2844]59    AddGameState(GSGraphics, "graphics");
60
61    GSGraphics::GSGraphics(const std::string& name)
62        : GameState(name)
[1661]63        , inputManager_(0)
64        , console_(0)
65        , guiManager_(0)
[2801]66        , graphicsManager_(0)
[1788]67        , masterKeyBinder_(0)
[2816]68        , masterInputState_(0)
[2087]69        , debugOverlay_(0)
[1661]70    {
[1686]71        RegisterRootObject(GSGraphics);
[1661]72    }
73
74    GSGraphics::~GSGraphics()
75    {
76    }
77
[2875]78    /**
79    @brief
80        this function does nothing
81
82        Indeed. Here goes nothing.
83    */
[1661]84    void GSGraphics::setConfigValues()
85    {
86    }
87
[2875]88    /**
89    @brief
90        This function is called when we enter this game state.
91
92        Since graphics is very important for our game this function does quite a lot:
93        \li starts graphics manager
94        \li loads debug overlay
95        \li manages render window
96        \li creates input manager
97        \li loads master key bindings
98        \li loads ingame console
99        \li loads GUI interface (GUIManager)
100        \li creates console command to toggle GUI
101    */
[2844]102    void GSGraphics::activate()
[1661]103    {
[2848]104        GameMode::setShowsGraphics(true);
[2847]105
[2844]106        setConfigValues();
107
[2805]108        // initialise graphics manager. Doesn't load the render window yet!
[2801]109        this->graphicsManager_ = new GraphicsManager();
110        this->graphicsManager_->initialise();
[1674]111
[2087]112        // load debug overlay
113        COUT(3) << "Loading Debug Overlay..." << std::endl;
[2759]114        this->debugOverlay_ = new XMLFile((Core::getMediaPath() / "overlay" / "debug.oxo").string());
[2087]115        Loader::open(debugOverlay_);
[1686]116
[1661]117        // The render window width and height are used to set up the mouse movement.
[1686]118        size_t windowHnd = 0;
[2801]119        Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
120        renderWindow->getCustomAttribute("WINDOW", &windowHnd);
[2875]121
122        // Calls the InputManager which sets up the input devices.
123        inputManager_ = new InputManager();
[2801]124        inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true);
[2816]125
[2875]126        // load master key bindings
[2816]127        masterInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("master", true);
[2103]128        masterKeyBinder_ = new KeyBinder();
[2710]129        masterKeyBinder_->loadBindings("masterKeybindings.ini");
[2816]130        masterInputState_->setKeyHandler(masterKeyBinder_);
[1661]131
132        // Load the InGameConsole
133        console_ = new InGameConsole();
[2801]134        console_->initialise(renderWindow->getWidth(), renderWindow->getHeight());
[1661]135
136        // load the CEGUI interface
137        guiManager_ = new GUIManager();
[2801]138        guiManager_->initialise(renderWindow);
[2816]139
[2875]140        // add console command to toggle GUI
[2869]141        FunctorMember<GSGraphics>* functor = createFunctor(&GSGraphics::toggleGUI);
142        functor->setObject(this);
143        this->ccToggleGUI_ = createConsoleCommand(functor, "toggleGUI");
144        CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_);
145
[2875]146        // enable master input
[2816]147        InputManager::getInstance().requestEnterState("master");
[1661]148    }
149
[2875]150    /**
151    @brief
152        This function is called when the game state is left
153
154        Created references, input states and console commands are deleted.
155    */
[2844]156    void GSGraphics::deactivate()
[1661]157    {
[2869]158
159        if (this->ccToggleGUI_)
160        {
161            delete this->ccToggleGUI_;
162            this->ccToggleGUI_ = 0;
163        }
164
[2847]165        masterInputState_->setHandler(0);
166        InputManager::getInstance().requestDestroyState("master");
167        delete this->masterKeyBinder_;
[2816]168
[1662]169        delete this->guiManager_;
170        delete this->console_;
[1661]171
[2087]172        Loader::unload(this->debugOverlay_);
173        delete this->debugOverlay_;
174
[2847]175        delete this->inputManager_;
176        this->inputManager_ = 0;
177
[2801]178        delete graphicsManager_;
[2816]179
[2848]180        GameMode::setShowsGraphics(false);
[1661]181    }
182
[2875]183    /**
184    @brief
185        Toggles the visibility of the current GUI
186
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    */
[2869]190    void GSGraphics::toggleGUI()
191    {
192            GUIManager::getInstance().executeCode("toggleGUI()");
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    */
[2844]203    void GSGraphics::update(const Clock& time)
[1661]204    {
[2854]205        if (this->getActivity().topState)
206        {
207            // This state can not 'survive' on its own.
208            // Load a user interface therefore
209            Game::getInstance().requestState("mainMenu");
210        }
211
[2662]212        uint64_t timeBeforeTick = time.getRealMicroseconds();
213
[2801]214        this->inputManager_->update(time);        // tick console
[2800]215        this->console_->update(time);
[2850]216        this->guiManager_->update(time);
[2087]217
[2662]218        uint64_t timeAfterTick = time.getRealMicroseconds();
[1661]219
[2817]220        // Also add our tick time
221        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
[1661]222
[2850]223        // Render
[2801]224        this->graphicsManager_->update(time);
[1661]225    }
[1686]226
[1891]227    /**
228    @brief
[1686]229        Window has resized.
230    @param rw
231        The render window it occured in
232    @note
[2801]233        GraphicsManager has a render window stored itself. This is the same
[1686]234        as rw. But we have to be careful when using multiple render windows!
235    */
[2801]236    void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight)
[1686]237    {
[2087]238        // OIS needs this under linux even if we only use relative input measurement.
239        if (this->inputManager_)
[2801]240            this->inputManager_->setWindowExtents(newWidth, newHeight);
[1686]241    }
242
243    /**
244    @brief
245        Window focus has changed.
246    @param rw
247        The render window it occured in
248    */
[2801]249    void GSGraphics::windowFocusChanged()
[1686]250    {
[1878]251        // instruct InputManager to clear the buffers (core library so we cannot use the interface)
[2087]252        if (this->inputManager_)
253            this->inputManager_->clearBuffers();
[1686]254    }
255
[1661]256}
Note: See TracBrowser for help on using the repository browser.