Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Exported showsGraphics, etc. to a new class named GameMode in the core.

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