Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Move graphic related content of GSGraphics to GraphicsManager which originally was GraphisEngine (but since we don't have an engine of our own, I renamed it).
Reduced OgreWindowEventUtilities.h dependency from GraphisManager.h (includes windows.h).

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