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/ExtendedInputState.h" |
---|
42 | #include "core/Loader.h" |
---|
43 | #include "core/XMLFile.h" |
---|
44 | #include "overlays/console/InGameConsole.h" |
---|
45 | #include "gui/GUIManager.h" |
---|
46 | |
---|
47 | // for compatibility |
---|
48 | #include "GraphicsManager.h" |
---|
49 | |
---|
50 | namespace orxonox |
---|
51 | { |
---|
52 | GSGraphics::GSGraphics() |
---|
53 | : GameState<GSRoot>("graphics") |
---|
54 | , inputManager_(0) |
---|
55 | , console_(0) |
---|
56 | , guiManager_(0) |
---|
57 | , graphicsManager_(0) |
---|
58 | , masterKeyBinder_(0) |
---|
59 | , debugOverlay_(0) |
---|
60 | { |
---|
61 | RegisterRootObject(GSGraphics); |
---|
62 | setConfigValues(); |
---|
63 | } |
---|
64 | |
---|
65 | GSGraphics::~GSGraphics() |
---|
66 | { |
---|
67 | } |
---|
68 | |
---|
69 | void GSGraphics::setConfigValues() |
---|
70 | { |
---|
71 | } |
---|
72 | |
---|
73 | void GSGraphics::enter() |
---|
74 | { |
---|
75 | Core::setShowsGraphics(true); |
---|
76 | |
---|
77 | // initialise graphics engine. Doesn't load the render window yet! |
---|
78 | this->graphicsManager_ = new GraphicsManager(); |
---|
79 | this->graphicsManager_->initialise(); |
---|
80 | |
---|
81 | // load debug overlay |
---|
82 | COUT(3) << "Loading Debug Overlay..." << std::endl; |
---|
83 | this->debugOverlay_ = new XMLFile((Core::getMediaPath() / "overlay" / "debug.oxo").string()); |
---|
84 | Loader::open(debugOverlay_); |
---|
85 | |
---|
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(); |
---|
89 | size_t windowHnd = 0; |
---|
90 | Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow(); |
---|
91 | renderWindow->getCustomAttribute("WINDOW", &windowHnd); |
---|
92 | inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true); |
---|
93 | // Configure master input state with a KeyBinder |
---|
94 | masterKeyBinder_ = new KeyBinder(); |
---|
95 | masterKeyBinder_->loadBindings("masterKeybindings.ini"); |
---|
96 | inputManager_->getMasterInputState()->addKeyHandler(masterKeyBinder_); |
---|
97 | |
---|
98 | // Load the InGameConsole |
---|
99 | console_ = new InGameConsole(); |
---|
100 | console_->initialise(renderWindow->getWidth(), renderWindow->getHeight()); |
---|
101 | |
---|
102 | // load the CEGUI interface |
---|
103 | guiManager_ = new GUIManager(); |
---|
104 | guiManager_->initialise(renderWindow); |
---|
105 | } |
---|
106 | |
---|
107 | void GSGraphics::leave() |
---|
108 | { |
---|
109 | delete this->guiManager_; |
---|
110 | |
---|
111 | delete this->console_; |
---|
112 | |
---|
113 | //inputManager_->getMasterInputState()->removeKeyHandler(this->masterKeyBinder_); |
---|
114 | delete this->masterKeyBinder_; |
---|
115 | delete this->inputManager_; |
---|
116 | |
---|
117 | Loader::unload(this->debugOverlay_); |
---|
118 | delete this->debugOverlay_; |
---|
119 | |
---|
120 | delete graphicsManager_; |
---|
121 | } |
---|
122 | |
---|
123 | /** |
---|
124 | @note |
---|
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 | */ |
---|
131 | void GSGraphics::ticked(const Clock& time) |
---|
132 | { |
---|
133 | uint64_t timeBeforeTick = time.getRealMicroseconds(); |
---|
134 | |
---|
135 | this->inputManager_->update(time); // tick console |
---|
136 | this->console_->update(time); |
---|
137 | this->tickChild(time); |
---|
138 | |
---|
139 | uint64_t timeAfterTick = time.getRealMicroseconds(); |
---|
140 | |
---|
141 | // Also add our tick time to the list in GSRoot |
---|
142 | this->getParent()->addTickTime(timeAfterTick - timeBeforeTick); |
---|
143 | |
---|
144 | // Update statistics overlay. Note that the values only change periodically in GSRoot. |
---|
145 | GraphicsManager::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS()); |
---|
146 | GraphicsManager::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime()); |
---|
147 | |
---|
148 | this->graphicsManager_->update(time); |
---|
149 | } |
---|
150 | |
---|
151 | /** |
---|
152 | @brief |
---|
153 | Window has resized. |
---|
154 | @param rw |
---|
155 | The render window it occured in |
---|
156 | @note |
---|
157 | GraphicsManager has a render window stored itself. This is the same |
---|
158 | as rw. But we have to be careful when using multiple render windows! |
---|
159 | */ |
---|
160 | void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight) |
---|
161 | { |
---|
162 | // OIS needs this under linux even if we only use relative input measurement. |
---|
163 | if (this->inputManager_) |
---|
164 | this->inputManager_->setWindowExtents(newWidth, newHeight); |
---|
165 | } |
---|
166 | |
---|
167 | /** |
---|
168 | @brief |
---|
169 | Window focus has changed. |
---|
170 | @param rw |
---|
171 | The render window it occured in |
---|
172 | */ |
---|
173 | void GSGraphics::windowFocusChanged() |
---|
174 | { |
---|
175 | // instruct InputManager to clear the buffers (core library so we cannot use the interface) |
---|
176 | if (this->inputManager_) |
---|
177 | this->inputManager_->clearBuffers(); |
---|
178 | } |
---|
179 | |
---|
180 | } |
---|