Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

De initialisation bugfix in GSGraphics.

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