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