Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/gamestates/GSGraphics.cc @ 2917

Last change on this file since 2917 was 2896, checked in by landauf, 16 years ago

Merged gui branch back to trunk.

I did 2 small changes in IngameManager.cc on line 777 and 888 (yes, really), because const_reverse_iterator strangely doesn't work on MinGW.

  • 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:
[2896]25 *      Benjamin Knecht
[1661]26 *
27 */
28
[2896]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"
[2896]41#include "core/ConfigValueIncludes.h"
42#include "core/Clock.h"
[1662]43#include "core/ConsoleCommand.h"
[2896]44#include "core/Core.h"
[1686]45#include "core/CoreIncludes.h"
[2896]46#include "core/Game.h"
47#include "core/GameMode.h"
[1661]48#include "core/input/InputManager.h"
[1788]49#include "core/input/KeyBinder.h"
[2896]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"
[2896]55#include "GraphicsManager.h"
[1686]56
[1661]57namespace orxonox
58{
[2896]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)
[2896]66        , graphicsManager_(0)
[1788]67        , masterKeyBinder_(0)
[2896]68        , masterInputState_(0)
[2087]69        , debugOverlay_(0)
[1661]70    {
[1686]71        RegisterRootObject(GSGraphics);
[1661]72    }
73
74    GSGraphics::~GSGraphics()
75    {
76    }
77
[2896]78    /**
79    @brief
80        this function does nothing
81
82        Indeed. Here goes nothing.
83    */
[1661]84    void GSGraphics::setConfigValues()
85    {
86    }
87
[2896]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    */
102    void GSGraphics::activate()
[1661]103    {
[2896]104        GameMode::setShowsGraphics(true);
[1696]105
[2896]106        setConfigValues();
[1674]107
[2896]108        // initialise graphics manager. Doesn't load the render window yet!
109        this->graphicsManager_ = new GraphicsManager();
110        this->graphicsManager_->initialise();
[2710]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
[2896]117        // The render window width and height are used to set up the mouse movement.
118        size_t windowHnd = 0;
119        Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
120        renderWindow->getCustomAttribute("WINDOW", &windowHnd);
121
[1661]122        // Calls the InputManager which sets up the input devices.
123        inputManager_ = new InputManager();
[2896]124        inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true);
125
126        // load master key bindings
127        masterInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("master", true);
[2103]128        masterKeyBinder_ = new KeyBinder();
[2710]129        masterKeyBinder_->loadBindings("masterKeybindings.ini");
[2896]130        masterInputState_->setKeyHandler(masterKeyBinder_);
[1661]131
132        // Load the InGameConsole
133        console_ = new InGameConsole();
[2896]134        console_->initialise(renderWindow->getWidth(), renderWindow->getHeight());
[1661]135
136        // load the CEGUI interface
137        guiManager_ = new GUIManager();
[2896]138        guiManager_->initialise(renderWindow);
[1674]139
[2896]140        // add console command to toggle GUI
141        FunctorMember<GSGraphics>* functor = createFunctor(&GSGraphics::toggleGUI);
142        functor->setObject(this);
143        this->ccToggleGUI_ = createConsoleCommand(functor, "toggleGUI");
144        CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_);
145
146        // enable master input
147        InputManager::getInstance().requestEnterState("master");
[1661]148    }
149
[2896]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    */
156    void GSGraphics::deactivate()
[1661]157    {
[1824]158
[2896]159        if (this->ccToggleGUI_)
160        {
161            delete this->ccToggleGUI_;
162            this->ccToggleGUI_ = 0;
163        }
[2662]164
[2896]165        masterInputState_->setHandler(0);
166        InputManager::getInstance().requestDestroyState("master");
167        delete this->masterKeyBinder_;
[1878]168
[1662]169        delete this->guiManager_;
170        delete this->console_;
[1661]171
[2087]172        Loader::unload(this->debugOverlay_);
173        delete this->debugOverlay_;
174
[2896]175        delete this->inputManager_;
176        this->inputManager_ = 0;
[2662]177
[2896]178        delete graphicsManager_;
[1696]179
[2896]180        GameMode::setShowsGraphics(false);
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    {
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
[2896]214        this->inputManager_->update(time);        // tick console
215        this->console_->update(time);
216        this->guiManager_->update(time);
[1661]217
[2896]218        uint64_t timeAfterTick = time.getRealMicroseconds();
[1661]219
[2896]220        // Also add our tick time
221        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
[1661]222
[2896]223        // Render
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
[2896]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    */
[2896]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_)
[2896]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    */
[2896]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.