Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2816 was 2816, checked in by rgrieder, 15 years ago

Upgrade number two for the InputManager: An InputState can have two new properties. You can tell it to always receive input, no matter what the input stack actually is. Secondly there is a 'transparent' option to be kind of invisible to the other states. I have found no use yet, but three more lines weren't a big deal ;)
This change ultimately supersedes the need for a master InputState.

  • Property svn:eol-style set to native
File size: 6.3 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:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "GSGraphics.h"
31
[2710]32#include <boost/filesystem.hpp>
[1686]33#include <OgreRenderWindow.h>
[1661]34
[1755]35#include "util/Debug.h"
[1662]36#include "core/ConfigValueIncludes.h"
[1686]37#include "core/CoreIncludes.h"
[2087]38#include "core/Core.h"
[1661]39#include "core/input/InputManager.h"
[1788]40#include "core/input/KeyBinder.h"
[2816]41#include "core/input/SimpleInputState.h"
[2087]42#include "core/Loader.h"
43#include "core/XMLFile.h"
[1661]44#include "overlays/console/InGameConsole.h"
45#include "gui/GUIManager.h"
[1686]46
47// for compatibility
[2801]48#include "GraphicsManager.h"
[1661]49
50namespace orxonox
51{
52    GSGraphics::GSGraphics()
[1689]53        : GameState<GSRoot>("graphics")
[1661]54        , inputManager_(0)
55        , console_(0)
56        , guiManager_(0)
[2801]57        , graphicsManager_(0)
[1788]58        , masterKeyBinder_(0)
[2816]59        , masterInputState_(0)
[2087]60        , debugOverlay_(0)
[1661]61    {
[1686]62        RegisterRootObject(GSGraphics);
[1891]63        setConfigValues();
[1661]64    }
65
66    GSGraphics::~GSGraphics()
67    {
68    }
69
70    void GSGraphics::setConfigValues()
71    {
72    }
73
74    void GSGraphics::enter()
75    {
[2087]76        Core::setShowsGraphics(true);
[1696]77
[2805]78        // initialise graphics manager. Doesn't load the render window yet!
[2801]79        this->graphicsManager_ = new GraphicsManager();
80        this->graphicsManager_->initialise();
[1674]81
[2087]82        // load debug overlay
83        COUT(3) << "Loading Debug Overlay..." << std::endl;
[2759]84        this->debugOverlay_ = new XMLFile((Core::getMediaPath() / "overlay" / "debug.oxo").string());
[2087]85        Loader::open(debugOverlay_);
[1686]86
[1661]87        // Calls the InputManager which sets up the input devices.
88        // The render window width and height are used to set up the mouse movement.
89        inputManager_ = new InputManager();
[1686]90        size_t windowHnd = 0;
[2801]91        Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
92        renderWindow->getCustomAttribute("WINDOW", &windowHnd);
93        inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true);
[2816]94
95        masterInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("master", true);
[2103]96        masterKeyBinder_ = new KeyBinder();
[2710]97        masterKeyBinder_->loadBindings("masterKeybindings.ini");
[2816]98        masterInputState_->setKeyHandler(masterKeyBinder_);
[1661]99
100        // Load the InGameConsole
101        console_ = new InGameConsole();
[2801]102        console_->initialise(renderWindow->getWidth(), renderWindow->getHeight());
[1661]103
104        // load the CEGUI interface
105        guiManager_ = new GUIManager();
[2801]106        guiManager_->initialise(renderWindow);
[2816]107
108        InputManager::getInstance().requestEnterState("master");
[1661]109    }
110
111    void GSGraphics::leave()
112    {
[2816]113        if (Core::showsGraphics())
114            InputManager::getInstance().requestLeaveState("master");
115
[1662]116        delete this->guiManager_;
[1661]117
[1662]118        delete this->console_;
[1661]119
[1788]120        //inputManager_->getMasterInputState()->removeKeyHandler(this->masterKeyBinder_);
[2103]121        delete this->masterKeyBinder_;
[1662]122        delete this->inputManager_;
123
[2087]124        Loader::unload(this->debugOverlay_);
125        delete this->debugOverlay_;
126
[2801]127        delete graphicsManager_;
[2816]128
129        if (Core::showsGraphics())
130        {
131            masterInputState_->setHandler(0);
132            InputManager::getInstance().requestDestroyState("master");
133            if (this->masterKeyBinder_)
134            {
135                delete this->masterKeyBinder_;
136                this->masterKeyBinder_ = 0;
137            }
138        }
[1661]139    }
140
[1662]141    /**
[2662]142    @note
[1662]143        A note about the Ogre::FrameListener: Even though we don't use them,
144        they still get called. However, the delta times are not correct (except
145        for timeSinceLastFrame, which is the most important). A little research
146        as shown that there is probably only one FrameListener that doesn't even
147        need the time. So we shouldn't run into problems.
148    */
[1674]149    void GSGraphics::ticked(const Clock& time)
[1661]150    {
[2662]151        uint64_t timeBeforeTick = time.getRealMicroseconds();
152
[2801]153        this->inputManager_->update(time);        // tick console
[2800]154        this->console_->update(time);
[1674]155        this->tickChild(time);
[2087]156
[2662]157        uint64_t timeAfterTick = time.getRealMicroseconds();
[1661]158
[2662]159        // Also add our tick time to the list in GSRoot
160        this->getParent()->addTickTime(timeAfterTick - timeBeforeTick);
[1661]161
[2662]162        // Update statistics overlay. Note that the values only change periodically in GSRoot.
[2801]163        GraphicsManager::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS());
164        GraphicsManager::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime());
[1661]165
[2801]166        this->graphicsManager_->update(time);
[1661]167    }
[1686]168
[1891]169    /**
170    @brief
[1686]171        Window has resized.
172    @param rw
173        The render window it occured in
174    @note
[2801]175        GraphicsManager has a render window stored itself. This is the same
[1686]176        as rw. But we have to be careful when using multiple render windows!
177    */
[2801]178    void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight)
[1686]179    {
[2087]180        // OIS needs this under linux even if we only use relative input measurement.
181        if (this->inputManager_)
[2801]182            this->inputManager_->setWindowExtents(newWidth, newHeight);
[1686]183    }
184
185    /**
186    @brief
187        Window focus has changed.
188    @param rw
189        The render window it occured in
190    */
[2801]191    void GSGraphics::windowFocusChanged()
[1686]192    {
[1878]193        // instruct InputManager to clear the buffers (core library so we cannot use the interface)
[2087]194        if (this->inputManager_)
195            this->inputManager_->clearBuffers();
[1686]196    }
197
[1661]198}
Note: See TracBrowser for help on using the repository browser.