Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Deleting console commands currently seems to be a rather bad idea (though on by box the console still worked, including tab completion).
—> Commented all the temporary console commands in the GameStates until we have a proper solution.

  • 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    {
[2928]158/*
[2896]159        if (this->ccToggleGUI_)
160        {
161            delete this->ccToggleGUI_;
162            this->ccToggleGUI_ = 0;
163        }
[2928]164*/
[2662]165
[2896]166        masterInputState_->setHandler(0);
167        InputManager::getInstance().requestDestroyState("master");
168        delete this->masterKeyBinder_;
[1878]169
[1662]170        delete this->guiManager_;
171        delete this->console_;
[1661]172
[2087]173        Loader::unload(this->debugOverlay_);
174        delete this->debugOverlay_;
175
[2896]176        delete this->inputManager_;
177        this->inputManager_ = 0;
[2662]178
[2896]179        delete graphicsManager_;
[1696]180
[2896]181        GameMode::setShowsGraphics(false);
182    }
[1824]183
[2896]184    /**
185    @brief
186        Toggles the visibility of the current GUI
[1824]187
[2896]188        This function just executes a Lua function in the main script of the GUI by accessing the GUIManager.
189        For more details on this function check out the Lua code.
190    */
191    void GSGraphics::toggleGUI()
192    {
193            GUIManager::getInstance().executeCode("toggleGUI()");
[1661]194    }
195
[1662]196    /**
[2662]197    @note
[1662]198        A note about the Ogre::FrameListener: Even though we don't use them,
199        they still get called. However, the delta times are not correct (except
200        for timeSinceLastFrame, which is the most important). A little research
201        as shown that there is probably only one FrameListener that doesn't even
202        need the time. So we shouldn't run into problems.
203    */
[2896]204    void GSGraphics::update(const Clock& time)
[1661]205    {
[2896]206        if (this->getActivity().topState)
[2087]207        {
[2896]208            // This state can not 'survive' on its own.
209            // Load a user interface therefore
210            Game::getInstance().requestState("mainMenu");
[2087]211        }
212
[2896]213        uint64_t timeBeforeTick = time.getRealMicroseconds();
[1661]214
[2896]215        this->inputManager_->update(time);        // tick console
216        this->console_->update(time);
217        this->guiManager_->update(time);
[1661]218
[2896]219        uint64_t timeAfterTick = time.getRealMicroseconds();
[1661]220
[2896]221        // Also add our tick time
222        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
[1661]223
[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.