[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" |
---|
[2816] | 41 | #include "core/input/SimpleInputState.h" |
---|
[2087] | 42 | #include "core/Loader.h" |
---|
| 43 | #include "core/XMLFile.h" |
---|
[1661] | 44 | #include "overlays/console/InGameConsole.h" |
---|
| 45 | #include "gui/GUIManager.h" |
---|
[2801] | 46 | #include "GraphicsManager.h" |
---|
[2817] | 47 | #include "Game.h" |
---|
[1661] | 48 | |
---|
| 49 | namespace orxonox |
---|
| 50 | { |
---|
| 51 | GSGraphics::GSGraphics() |
---|
[2817] | 52 | : GameState("graphics") |
---|
[1661] | 53 | , inputManager_(0) |
---|
| 54 | , console_(0) |
---|
| 55 | , guiManager_(0) |
---|
[2801] | 56 | , graphicsManager_(0) |
---|
[1788] | 57 | , masterKeyBinder_(0) |
---|
[2816] | 58 | , masterInputState_(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 | |
---|
[2805] | 77 | // initialise graphics manager. 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); |
---|
[2816] | 93 | |
---|
| 94 | masterInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("master", true); |
---|
[2103] | 95 | masterKeyBinder_ = new KeyBinder(); |
---|
[2710] | 96 | masterKeyBinder_->loadBindings("masterKeybindings.ini"); |
---|
[2816] | 97 | masterInputState_->setKeyHandler(masterKeyBinder_); |
---|
[1661] | 98 | |
---|
| 99 | // Load the InGameConsole |
---|
| 100 | console_ = new InGameConsole(); |
---|
[2801] | 101 | console_->initialise(renderWindow->getWidth(), renderWindow->getHeight()); |
---|
[1661] | 102 | |
---|
| 103 | // load the CEGUI interface |
---|
| 104 | guiManager_ = new GUIManager(); |
---|
[2801] | 105 | guiManager_->initialise(renderWindow); |
---|
[2816] | 106 | |
---|
| 107 | InputManager::getInstance().requestEnterState("master"); |
---|
[1661] | 108 | } |
---|
| 109 | |
---|
| 110 | void GSGraphics::leave() |
---|
| 111 | { |
---|
[2816] | 112 | if (Core::showsGraphics()) |
---|
| 113 | InputManager::getInstance().requestLeaveState("master"); |
---|
| 114 | |
---|
[1662] | 115 | delete this->guiManager_; |
---|
[1661] | 116 | |
---|
[1662] | 117 | delete this->console_; |
---|
[1661] | 118 | |
---|
[1788] | 119 | //inputManager_->getMasterInputState()->removeKeyHandler(this->masterKeyBinder_); |
---|
[2103] | 120 | delete this->masterKeyBinder_; |
---|
[1662] | 121 | delete this->inputManager_; |
---|
| 122 | |
---|
[2087] | 123 | Loader::unload(this->debugOverlay_); |
---|
| 124 | delete this->debugOverlay_; |
---|
| 125 | |
---|
[2801] | 126 | delete graphicsManager_; |
---|
[2816] | 127 | |
---|
| 128 | if (Core::showsGraphics()) |
---|
| 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 | } |
---|
[1661] | 138 | } |
---|
| 139 | |
---|
[1662] | 140 | /** |
---|
[2662] | 141 | @note |
---|
[1662] | 142 | A note about the Ogre::FrameListener: Even though we don't use them, |
---|
| 143 | they still get called. However, the delta times are not correct (except |
---|
| 144 | for timeSinceLastFrame, which is the most important). A little research |
---|
| 145 | as shown that there is probably only one FrameListener that doesn't even |
---|
| 146 | need the time. So we shouldn't run into problems. |
---|
| 147 | */ |
---|
[1674] | 148 | void GSGraphics::ticked(const Clock& time) |
---|
[1661] | 149 | { |
---|
[2662] | 150 | uint64_t timeBeforeTick = time.getRealMicroseconds(); |
---|
| 151 | |
---|
[2801] | 152 | this->inputManager_->update(time); // tick console |
---|
[2800] | 153 | this->console_->update(time); |
---|
[1674] | 154 | this->tickChild(time); |
---|
[2087] | 155 | |
---|
[2662] | 156 | uint64_t timeAfterTick = time.getRealMicroseconds(); |
---|
[1661] | 157 | |
---|
[2817] | 158 | // Also add our tick time |
---|
| 159 | Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick); |
---|
[1661] | 160 | |
---|
[2801] | 161 | this->graphicsManager_->update(time); |
---|
[1661] | 162 | } |
---|
[1686] | 163 | |
---|
[1891] | 164 | /** |
---|
| 165 | @brief |
---|
[1686] | 166 | Window has resized. |
---|
| 167 | @param rw |
---|
| 168 | The render window it occured in |
---|
| 169 | @note |
---|
[2801] | 170 | GraphicsManager has a render window stored itself. This is the same |
---|
[1686] | 171 | as rw. But we have to be careful when using multiple render windows! |
---|
| 172 | */ |
---|
[2801] | 173 | void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight) |
---|
[1686] | 174 | { |
---|
[2087] | 175 | // OIS needs this under linux even if we only use relative input measurement. |
---|
| 176 | if (this->inputManager_) |
---|
[2801] | 177 | this->inputManager_->setWindowExtents(newWidth, newHeight); |
---|
[1686] | 178 | } |
---|
| 179 | |
---|
| 180 | /** |
---|
| 181 | @brief |
---|
| 182 | Window focus has changed. |
---|
| 183 | @param rw |
---|
| 184 | The render window it occured in |
---|
| 185 | */ |
---|
[2801] | 186 | void GSGraphics::windowFocusChanged() |
---|
[1686] | 187 | { |
---|
[1878] | 188 | // instruct InputManager to clear the buffers (core library so we cannot use the interface) |
---|
[2087] | 189 | if (this->inputManager_) |
---|
| 190 | this->inputManager_->clearBuffers(); |
---|
[1686] | 191 | } |
---|
| 192 | |
---|
[1661] | 193 | } |
---|