[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: |
---|
[2896] | 25 | * Benjamin Knecht |
---|
[1661] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[2896] | 29 | /** |
---|
[3196] | 30 | @file |
---|
| 31 | @brief |
---|
| 32 | Implementation of Graphics GameState class. |
---|
[2896] | 33 | */ |
---|
| 34 | |
---|
[1661] | 35 | #include "GSGraphics.h" |
---|
| 36 | |
---|
[3327] | 37 | #include "util/Convert.h" |
---|
[2896] | 38 | #include "core/Clock.h" |
---|
[3327] | 39 | #include "core/CommandExecutor.h" |
---|
[1662] | 40 | #include "core/ConsoleCommand.h" |
---|
[2896] | 41 | #include "core/Core.h" |
---|
| 42 | #include "core/Game.h" |
---|
[3370] | 43 | #include "core/GUIManager.h" |
---|
[1661] | 44 | #include "core/input/InputManager.h" |
---|
[1788] | 45 | #include "core/input/KeyBinder.h" |
---|
[3327] | 46 | #include "core/input/InputState.h" |
---|
[2087] | 47 | #include "core/Loader.h" |
---|
| 48 | #include "core/XMLFile.h" |
---|
[1661] | 49 | #include "overlays/console/InGameConsole.h" |
---|
[3196] | 50 | #include "sound/SoundManager.h" |
---|
[1686] | 51 | |
---|
[3370] | 52 | // HACK: |
---|
| 53 | #include "overlays/map/Map.h" |
---|
| 54 | |
---|
[1661] | 55 | namespace orxonox |
---|
| 56 | { |
---|
[3370] | 57 | DeclareGameState(GSGraphics, "graphics", false, true); |
---|
[2896] | 58 | |
---|
[3370] | 59 | GSGraphics::GSGraphics(const GameStateInfo& info) |
---|
| 60 | : GameState(info) |
---|
[1661] | 61 | , console_(0) |
---|
[3196] | 62 | , soundManager_(0) |
---|
[1788] | 63 | , masterKeyBinder_(0) |
---|
[2896] | 64 | , masterInputState_(0) |
---|
[2087] | 65 | , debugOverlay_(0) |
---|
[1661] | 66 | { |
---|
[3370] | 67 | // load master key bindings |
---|
| 68 | masterInputState_ = InputManager::getInstance().createInputState("master", true); |
---|
| 69 | masterKeyBinder_ = new KeyBinder(); |
---|
| 70 | masterInputState_->setKeyHandler(masterKeyBinder_); |
---|
[1661] | 71 | } |
---|
| 72 | |
---|
| 73 | GSGraphics::~GSGraphics() |
---|
| 74 | { |
---|
[3370] | 75 | InputManager::getInstance().destroyState("master"); |
---|
| 76 | delete this->masterKeyBinder_; |
---|
[1661] | 77 | } |
---|
| 78 | |
---|
[2896] | 79 | /** |
---|
| 80 | @brief |
---|
| 81 | This function is called when we enter this game state. |
---|
| 82 | |
---|
| 83 | Since graphics is very important for our game this function does quite a lot: |
---|
| 84 | \li starts graphics manager |
---|
| 85 | \li loads debug overlay |
---|
| 86 | \li manages render window |
---|
| 87 | \li creates input manager |
---|
| 88 | \li loads master key bindings |
---|
[3196] | 89 | \li loads the SoundManager |
---|
[2896] | 90 | \li loads ingame console |
---|
| 91 | \li loads GUI interface (GUIManager) |
---|
| 92 | \li creates console command to toggle GUI |
---|
| 93 | */ |
---|
| 94 | void GSGraphics::activate() |
---|
[1661] | 95 | { |
---|
[2087] | 96 | // load debug overlay |
---|
| 97 | COUT(3) << "Loading Debug Overlay..." << std::endl; |
---|
[5654] | 98 | this->debugOverlay_ = new XMLFile("debug.oxo"); |
---|
[2087] | 99 | Loader::open(debugOverlay_); |
---|
[1686] | 100 | |
---|
[2710] | 101 | masterKeyBinder_->loadBindings("masterKeybindings.ini"); |
---|
[1661] | 102 | |
---|
[3196] | 103 | // Load the SoundManager |
---|
| 104 | soundManager_ = new SoundManager(); |
---|
| 105 | |
---|
[1661] | 106 | // Load the InGameConsole |
---|
| 107 | console_ = new InGameConsole(); |
---|
[3327] | 108 | console_->initialise(); |
---|
[1661] | 109 | |
---|
[2896] | 110 | // add console command to toggle GUI |
---|
| 111 | FunctorMember<GSGraphics>* functor = createFunctor(&GSGraphics::toggleGUI); |
---|
| 112 | functor->setObject(this); |
---|
| 113 | this->ccToggleGUI_ = createConsoleCommand(functor, "toggleGUI"); |
---|
| 114 | CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_); |
---|
| 115 | |
---|
| 116 | // enable master input |
---|
[3327] | 117 | InputManager::getInstance().enterState("master"); |
---|
[1661] | 118 | } |
---|
| 119 | |
---|
[2896] | 120 | /** |
---|
| 121 | @brief |
---|
| 122 | This function is called when the game state is left |
---|
| 123 | |
---|
| 124 | Created references, input states and console commands are deleted. |
---|
| 125 | */ |
---|
| 126 | void GSGraphics::deactivate() |
---|
[1661] | 127 | { |
---|
[2928] | 128 | /* |
---|
[2896] | 129 | if (this->ccToggleGUI_) |
---|
| 130 | { |
---|
| 131 | delete this->ccToggleGUI_; |
---|
| 132 | this->ccToggleGUI_ = 0; |
---|
| 133 | } |
---|
[2928] | 134 | */ |
---|
[2662] | 135 | |
---|
[1662] | 136 | delete this->console_; |
---|
[1661] | 137 | |
---|
[2087] | 138 | Loader::unload(this->debugOverlay_); |
---|
| 139 | delete this->debugOverlay_; |
---|
| 140 | |
---|
[3196] | 141 | delete this->soundManager_; |
---|
| 142 | |
---|
[3370] | 143 | // HACK: (destroys a resource smart pointer) |
---|
| 144 | Map::hackDestroyMap(); |
---|
[2896] | 145 | } |
---|
[1824] | 146 | |
---|
[2896] | 147 | /** |
---|
| 148 | @brief |
---|
| 149 | Toggles the visibility of the current GUI |
---|
[1824] | 150 | |
---|
[2896] | 151 | This function just executes a Lua function in the main script of the GUI by accessing the GUIManager. |
---|
| 152 | For more details on this function check out the Lua code. |
---|
| 153 | */ |
---|
| 154 | void GSGraphics::toggleGUI() |
---|
| 155 | { |
---|
[3280] | 156 | GUIManager::getInstance().executeCode("toggleGUI()"); |
---|
[1661] | 157 | } |
---|
| 158 | |
---|
[1662] | 159 | /** |
---|
[2662] | 160 | @note |
---|
[1662] | 161 | A note about the Ogre::FrameListener: Even though we don't use them, |
---|
| 162 | they still get called. However, the delta times are not correct (except |
---|
| 163 | for timeSinceLastFrame, which is the most important). A little research |
---|
| 164 | as shown that there is probably only one FrameListener that doesn't even |
---|
| 165 | need the time. So we shouldn't run into problems. |
---|
| 166 | */ |
---|
[2896] | 167 | void GSGraphics::update(const Clock& time) |
---|
[1661] | 168 | { |
---|
[2896] | 169 | if (this->getActivity().topState) |
---|
[2087] | 170 | { |
---|
[2896] | 171 | // This state can not 'survive' on its own. |
---|
| 172 | // Load a user interface therefore |
---|
| 173 | Game::getInstance().requestState("mainMenu"); |
---|
[2087] | 174 | } |
---|
| 175 | |
---|
[2896] | 176 | this->console_->update(time); |
---|
[1661] | 177 | } |
---|
| 178 | } |
---|