[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: |
---|
[1662] | 25 | * Fabian 'x3n' Landau |
---|
[2896] | 26 | * Benjamin Knecht |
---|
[1661] | 27 | * |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #include "GSLevel.h" |
---|
| 31 | |
---|
[5695] | 32 | #include <OgreCompositorManager.h> |
---|
| 33 | |
---|
[5855] | 34 | #include "util/Clock.h" |
---|
[1661] | 35 | #include "core/input/InputManager.h" |
---|
[3327] | 36 | #include "core/input/InputState.h" |
---|
[5863] | 37 | #include "core/input/KeyBinderManager.h" |
---|
[1887] | 38 | #include "core/ConsoleCommand.h" |
---|
[2896] | 39 | #include "core/Game.h" |
---|
| 40 | #include "core/GameMode.h" |
---|
[3370] | 41 | #include "core/GUIManager.h" |
---|
[3196] | 42 | #include "core/Loader.h" |
---|
| 43 | #include "core/XMLFile.h" |
---|
| 44 | |
---|
[2087] | 45 | #include "LevelManager.h" |
---|
[2662] | 46 | #include "PlayerManager.h" |
---|
[1661] | 47 | |
---|
| 48 | namespace orxonox |
---|
| 49 | { |
---|
[3370] | 50 | DeclareGameState(GSLevel, "level", false, false); |
---|
[1934] | 51 | |
---|
[3370] | 52 | GSLevel::GSLevel(const GameStateInfo& info) |
---|
| 53 | : GameState(info) |
---|
[2896] | 54 | , gameInputState_(0) |
---|
| 55 | , guiMouseOnlyInputState_(0) |
---|
| 56 | , guiKeysOnlyInputState_(0) |
---|
[5876] | 57 | , startFile_(0) |
---|
[1661] | 58 | { |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | GSLevel::~GSLevel() |
---|
| 62 | { |
---|
| 63 | } |
---|
| 64 | |
---|
[2896] | 65 | void GSLevel::activate() |
---|
[1661] | 66 | { |
---|
[2896] | 67 | if (GameMode::showsGraphics()) |
---|
[2087] | 68 | { |
---|
[3327] | 69 | gameInputState_ = InputManager::getInstance().createInputState("game"); |
---|
[5910] | 70 | gameInputState_->setMouseMode(MouseMode::Exclusive); |
---|
[5863] | 71 | gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler()); |
---|
| 72 | KeyBinderManager::getInstance().setToDefault(); |
---|
[1661] | 73 | |
---|
[3327] | 74 | guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly"); |
---|
[5910] | 75 | guiMouseOnlyInputState_->setMouseMode(MouseMode::Exclusive); |
---|
[2896] | 76 | guiMouseOnlyInputState_->setMouseHandler(GUIManager::getInstancePtr()); |
---|
| 77 | |
---|
[3327] | 78 | guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly"); |
---|
[2896] | 79 | guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr()); |
---|
[5876] | 80 | |
---|
| 81 | CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSLevel::showIngameGUI, this), "showIngameGUI")); |
---|
[2087] | 82 | } |
---|
[1662] | 83 | |
---|
[2896] | 84 | if (GameMode::isMaster()) |
---|
[2087] | 85 | { |
---|
| 86 | this->loadLevel(); |
---|
| 87 | } |
---|
[1755] | 88 | |
---|
[2896] | 89 | if (GameMode::showsGraphics()) |
---|
[2087] | 90 | { |
---|
| 91 | // level is loaded: we can start capturing the input |
---|
[3327] | 92 | InputManager::getInstance().enterState("game"); |
---|
[5820] | 93 | |
---|
| 94 | // connect the HumanPlayer to the game |
---|
[5850] | 95 | PlayerManager::getInstance().clientConnected(0); |
---|
[2087] | 96 | } |
---|
[2662] | 97 | } |
---|
[2087] | 98 | |
---|
[2896] | 99 | void GSLevel::showIngameGUI(bool show) |
---|
[2662] | 100 | { |
---|
[2896] | 101 | if (show) |
---|
| 102 | { |
---|
[6024] | 103 | GUIManager::showGUI("inGameTest"); |
---|
[2896] | 104 | } |
---|
| 105 | else |
---|
| 106 | { |
---|
[6024] | 107 | GUIManager::hideGUI("inGameTest"); |
---|
[2896] | 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | void GSLevel::deactivate() |
---|
| 112 | { |
---|
[5695] | 113 | if (GameMode::showsGraphics()) |
---|
| 114 | { |
---|
[5832] | 115 | // disconnect the HumanPlayer |
---|
[5850] | 116 | PlayerManager::getInstance().clientDisconnected(0); |
---|
[5832] | 117 | |
---|
[5695] | 118 | // unload all compositors (this is only necessary because we don't yet destroy all resources!) |
---|
| 119 | Ogre::CompositorManager::getSingleton().removeAll(); |
---|
[2896] | 120 | |
---|
[3327] | 121 | InputManager::getInstance().leaveState("game"); |
---|
[5820] | 122 | } |
---|
[1662] | 123 | |
---|
[2896] | 124 | if (GameMode::isMaster()) |
---|
[2087] | 125 | this->unloadLevel(); |
---|
[1662] | 126 | |
---|
[2896] | 127 | if (GameMode::showsGraphics()) |
---|
[2087] | 128 | { |
---|
[2896] | 129 | gameInputState_->setHandler(0); |
---|
| 130 | guiMouseOnlyInputState_->setHandler(0); |
---|
| 131 | guiKeysOnlyInputState_->setHandler(0); |
---|
[3327] | 132 | InputManager::getInstance().destroyState("game"); |
---|
[5818] | 133 | InputManager::getInstance().destroyState("guiKeysOnly"); |
---|
| 134 | InputManager::getInstance().destroyState("guiMouseOnly"); |
---|
[2087] | 135 | } |
---|
[1661] | 136 | } |
---|
| 137 | |
---|
[2896] | 138 | void GSLevel::update(const Clock& time) |
---|
[1661] | 139 | { |
---|
[5876] | 140 | // Note: Temporarily moved to GSRoot. |
---|
[2087] | 141 | //// Call the scene objects |
---|
| 142 | //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) |
---|
| 143 | // it->tick(time.getDeltaTime() * this->timeFactor_); |
---|
[1661] | 144 | } |
---|
| 145 | |
---|
[1670] | 146 | void GSLevel::loadLevel() |
---|
| 147 | { |
---|
[5922] | 148 | for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it) |
---|
| 149 | this->staticObjects_.insert(*it); |
---|
| 150 | |
---|
[1670] | 151 | // call the loader |
---|
| 152 | COUT(0) << "Loading level..." << std::endl; |
---|
[5876] | 153 | startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel()); |
---|
| 154 | Loader::open(startFile_); |
---|
[1670] | 155 | } |
---|
| 156 | |
---|
| 157 | void GSLevel::unloadLevel() |
---|
| 158 | { |
---|
[5876] | 159 | Loader::unload(startFile_); |
---|
| 160 | delete startFile_; |
---|
[5922] | 161 | |
---|
| 162 | COUT(3) << "Unloaded level. Remaining objects:" << std::endl; |
---|
| 163 | unsigned int i = 0; |
---|
| 164 | for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it) |
---|
| 165 | { |
---|
| 166 | std::set<BaseObject*>::const_iterator find = this->staticObjects_.find(*it); |
---|
| 167 | if (find == this->staticObjects_.end()) |
---|
| 168 | { |
---|
| 169 | COUT(3) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << ")" << std::endl; |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | COUT(3) << i << " objects remaining."; |
---|
| 173 | if (i == 0) |
---|
| 174 | COUT(3) << " Well done!" << std::endl; |
---|
| 175 | else |
---|
| 176 | COUT(3) << " Try harder!" << std::endl; |
---|
[1670] | 177 | } |
---|
[1661] | 178 | } |
---|