Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Removed old msvc specific support for precompiled header files.

  • 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 "GSGraphics.h"
35
[2710]36#include <boost/filesystem.hpp>
[1686]37#include <OgreRenderWindow.h>
[1661]38
[1755]39#include "util/Debug.h"
[2896]40#include "core/ConfigValueIncludes.h"
41#include "core/Clock.h"
[1662]42#include "core/ConsoleCommand.h"
[2896]43#include "core/Core.h"
[1686]44#include "core/CoreIncludes.h"
[2896]45#include "core/Game.h"
46#include "core/GameMode.h"
[1661]47#include "core/input/InputManager.h"
[1788]48#include "core/input/KeyBinder.h"
[2896]49#include "core/input/SimpleInputState.h"
[2087]50#include "core/Loader.h"
51#include "core/XMLFile.h"
[1661]52#include "overlays/console/InGameConsole.h"
53#include "gui/GUIManager.h"
[2896]54#include "GraphicsManager.h"
[1686]55
[1661]56namespace orxonox
57{
[3084]58    AddGameState(GSGraphics, "graphics", false);
[2896]59
[3084]60    GSGraphics::GSGraphics(const std::string& name, bool countTickTime)
61        : GameState(name, countTickTime)
[1661]62        , inputManager_(0)
63        , console_(0)
64        , guiManager_(0)
[2896]65        , graphicsManager_(0)
[1788]66        , masterKeyBinder_(0)
[2896]67        , masterInputState_(0)
[2087]68        , debugOverlay_(0)
[1661]69    {
[1686]70        RegisterRootObject(GSGraphics);
[1661]71    }
72
73    GSGraphics::~GSGraphics()
74    {
75    }
76
[2896]77    /**
78    @brief
79        this function does nothing
80
81        Indeed. Here goes nothing.
82    */
[1661]83    void GSGraphics::setConfigValues()
84    {
85    }
86
[2896]87    /**
88    @brief
89        This function is called when we enter this game state.
90
91        Since graphics is very important for our game this function does quite a lot:
92        \li starts graphics manager
93        \li loads debug overlay
94        \li manages render window
95        \li creates input manager
96        \li loads master key bindings
97        \li loads ingame console
98        \li loads GUI interface (GUIManager)
99        \li creates console command to toggle GUI
100    */
101    void GSGraphics::activate()
[1661]102    {
[2896]103        GameMode::setShowsGraphics(true);
[1696]104
[2896]105        setConfigValues();
[1674]106
[2896]107        // initialise graphics manager. Doesn't load the render window yet!
108        this->graphicsManager_ = new GraphicsManager();
109        this->graphicsManager_->initialise();
[2710]110
[2087]111        // load debug overlay
112        COUT(3) << "Loading Debug Overlay..." << std::endl;
[2759]113        this->debugOverlay_ = new XMLFile((Core::getMediaPath() / "overlay" / "debug.oxo").string());
[2087]114        Loader::open(debugOverlay_);
[1686]115
[2896]116        // The render window width and height are used to set up the mouse movement.
117        size_t windowHnd = 0;
118        Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
119        renderWindow->getCustomAttribute("WINDOW", &windowHnd);
120
[1661]121        // Calls the InputManager which sets up the input devices.
122        inputManager_ = new InputManager();
[2896]123        inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true);
124
125        // load master key bindings
126        masterInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("master", true);
[2103]127        masterKeyBinder_ = new KeyBinder();
[2710]128        masterKeyBinder_->loadBindings("masterKeybindings.ini");
[2896]129        masterInputState_->setKeyHandler(masterKeyBinder_);
[1661]130
131        // Load the InGameConsole
132        console_ = new InGameConsole();
[2896]133        console_->initialise(renderWindow->getWidth(), renderWindow->getHeight());
[1661]134
135        // load the CEGUI interface
136        guiManager_ = new GUIManager();
[2896]137        guiManager_->initialise(renderWindow);
[1674]138
[2896]139        // add console command to toggle GUI
140        FunctorMember<GSGraphics>* functor = createFunctor(&GSGraphics::toggleGUI);
141        functor->setObject(this);
142        this->ccToggleGUI_ = createConsoleCommand(functor, "toggleGUI");
143        CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_);
144
145        // enable master input
146        InputManager::getInstance().requestEnterState("master");
[1661]147    }
148
[2896]149    /**
150    @brief
151        This function is called when the game state is left
152
153        Created references, input states and console commands are deleted.
154    */
155    void GSGraphics::deactivate()
[1661]156    {
[2928]157/*
[2896]158        if (this->ccToggleGUI_)
159        {
160            delete this->ccToggleGUI_;
161            this->ccToggleGUI_ = 0;
162        }
[2928]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
[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    }
[1686]227
[1891]228    /**
229    @brief
[1686]230        Window has resized.
231    @param rw
232        The render window it occured in
233    @note
[2896]234        GraphicsManager has a render window stored itself. This is the same
[1686]235        as rw. But we have to be careful when using multiple render windows!
236    */
[2896]237    void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight)
[1686]238    {
[2087]239        // OIS needs this under linux even if we only use relative input measurement.
240        if (this->inputManager_)
[2896]241            this->inputManager_->setWindowExtents(newWidth, newHeight);
[1686]242    }
243
244    /**
245    @brief
246        Window focus has changed.
247    @param rw
248        The render window it occured in
249    */
[2896]250    void GSGraphics::windowFocusChanged()
[1686]251    {
[1878]252        // instruct InputManager to clear the buffers (core library so we cannot use the interface)
[2087]253        if (this->inputManager_)
254            this->inputManager_->clearBuffers();
[1686]255    }
256
[1661]257}
Note: See TracBrowser for help on using the repository browser.