Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Moving game clock from Core to Game.
Other small fixes.

  • Property svn:eol-style set to native
File size: 6.0 KB
Line 
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
32#include <boost/filesystem.hpp>
33#include <OgreRenderWindow.h>
34
35#include "util/Debug.h"
36#include "core/ConfigValueIncludes.h"
37#include "core/CoreIncludes.h"
38#include "core/Core.h"
39#include "core/input/InputManager.h"
40#include "core/input/KeyBinder.h"
41#include "core/input/SimpleInputState.h"
42#include "core/Loader.h"
43#include "core/XMLFile.h"
44#include "overlays/console/InGameConsole.h"
45#include "gui/GUIManager.h"
46#include "GraphicsManager.h"
47#include "core/Game.h"
48
49namespace orxonox
50{
51    AddGameState(GSGraphics, "graphics");
52
53    GSGraphics::GSGraphics(const std::string& name)
54        : GameState(name)
55        , inputManager_(0)
56        , console_(0)
57        , guiManager_(0)
58        , graphicsManager_(0)
59        , masterKeyBinder_(0)
60        , masterInputState_(0)
61        , debugOverlay_(0)
62    {
63        RegisterRootObject(GSGraphics);
64    }
65
66    GSGraphics::~GSGraphics()
67    {
68    }
69
70    void GSGraphics::setConfigValues()
71    {
72    }
73
74    void GSGraphics::activate()
75    {
76        setConfigValues();
77
78        Core::setShowsGraphics(true);
79
80        // initialise graphics manager. Doesn't load the render window yet!
81        this->graphicsManager_ = new GraphicsManager();
82        this->graphicsManager_->initialise();
83
84        // load debug overlay
85        COUT(3) << "Loading Debug Overlay..." << std::endl;
86        this->debugOverlay_ = new XMLFile((Core::getMediaPath() / "overlay" / "debug.oxo").string());
87        Loader::open(debugOverlay_);
88
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();
92        size_t windowHnd = 0;
93        Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
94        renderWindow->getCustomAttribute("WINDOW", &windowHnd);
95        inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true);
96
97        masterInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("master", true);
98        masterKeyBinder_ = new KeyBinder();
99        masterKeyBinder_->loadBindings("masterKeybindings.ini");
100        masterInputState_->setKeyHandler(masterKeyBinder_);
101
102        // Load the InGameConsole
103        console_ = new InGameConsole();
104        console_->initialise(renderWindow->getWidth(), renderWindow->getHeight());
105
106        // load the CEGUI interface
107        guiManager_ = new GUIManager();
108        guiManager_->initialise(renderWindow);
109
110        InputManager::getInstance().requestEnterState("master");
111    }
112
113    void GSGraphics::deactivate()
114    {
115        InputManager::getInstance().requestLeaveState("master");
116
117        delete this->guiManager_;
118
119        delete this->console_;
120
121        //inputManager_->getMasterInputState()->removeKeyHandler(this->masterKeyBinder_);
122        delete this->masterKeyBinder_;
123        delete this->inputManager_;
124
125        Loader::unload(this->debugOverlay_);
126        delete this->debugOverlay_;
127
128        delete graphicsManager_;
129
130        masterInputState_->setHandler(0);
131        InputManager::getInstance().requestDestroyState("master");
132        if (this->masterKeyBinder_)
133        {
134            delete this->masterKeyBinder_;
135            this->masterKeyBinder_ = 0;
136        }
137
138        Core::setShowsGraphics(false);
139    }
140
141    /**
142    @note
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    */
149    void GSGraphics::update(const Clock& time)
150    {
151        uint64_t timeBeforeTick = time.getRealMicroseconds();
152
153        this->inputManager_->update(time);        // tick console
154        this->console_->update(time);
155
156        uint64_t timeAfterTick = time.getRealMicroseconds();
157
158        // Also add our tick time
159        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
160
161        this->graphicsManager_->update(time);
162    }
163
164    /**
165    @brief
166        Window has resized.
167    @param rw
168        The render window it occured in
169    @note
170        GraphicsManager has a render window stored itself. This is the same
171        as rw. But we have to be careful when using multiple render windows!
172    */
173    void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight)
174    {
175        // OIS needs this under linux even if we only use relative input measurement.
176        if (this->inputManager_)
177            this->inputManager_->setWindowExtents(newWidth, newHeight);
178    }
179
180    /**
181    @brief
182        Window focus has changed.
183    @param rw
184        The render window it occured in
185    */
186    void GSGraphics::windowFocusChanged()
187    {
188        // instruct InputManager to clear the buffers (core library so we cannot use the interface)
189        if (this->inputManager_)
190            this->inputManager_->clearBuffers();
191    }
192
193}
Note: See TracBrowser for help on using the repository browser.