Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/orxonox/gamestates/GSLevel.cc @ 5876

Last change on this file since 5876 was 5876, checked in by rgrieder, 15 years ago

Cleanup in the GameStates (also moved debug overlay to the GraphicsManager).

  • Property svn:eol-style set to native
File size: 5.0 KB
Line 
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 *      Fabian 'x3n' Landau
26 *      Benjamin Knecht
27 *
28 */
29
30#include "GSLevel.h"
31
32#include <OgreCompositorManager.h>
33
34#include "util/Clock.h"
35#include "core/input/InputManager.h"
36#include "core/input/InputState.h"
37#include "core/input/KeyBinderManager.h"
38#include "core/ConsoleCommand.h"
39#include "core/Game.h"
40#include "core/GameMode.h"
41#include "core/GUIManager.h"
42#include "core/Loader.h"
43#include "core/XMLFile.h"
44
45#include "LevelManager.h"
46#include "PlayerManager.h"
47
48namespace orxonox
49{
50    DeclareGameState(GSLevel, "level", false, false);
51
52    GSLevel::GSLevel(const GameStateInfo& info)
53        : GameState(info)
54        , gameInputState_(0)
55        , guiMouseOnlyInputState_(0)
56        , guiKeysOnlyInputState_(0)
57        , startFile_(0)
58    {
59    }
60
61    GSLevel::~GSLevel()
62    {
63    }
64
65    void GSLevel::activate()
66    {
67        if (GameMode::showsGraphics())
68        {
69            gameInputState_ = InputManager::getInstance().createInputState("game");
70            gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
71            KeyBinderManager::getInstance().setToDefault();
72
73            guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly");
74            guiMouseOnlyInputState_->setMouseHandler(GUIManager::getInstancePtr());
75
76            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
77            guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
78
79            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSLevel::showIngameGUI, this), "showIngameGUI"));
80        }
81
82        if (GameMode::isMaster())
83        {
84            this->loadLevel();
85        }
86
87        if (GameMode::showsGraphics())
88        {
89            // level is loaded: we can start capturing the input
90            InputManager::getInstance().enterState("game");
91           
92            // connect the HumanPlayer to the game
93            PlayerManager::getInstance().clientConnected(0);
94        }
95    }
96
97    void GSLevel::showIngameGUI(bool show)
98    {
99        if (show)
100        {
101            GUIManager::getInstance().showGUI("inGameTest");
102            GUIManager::getInstance().executeCode("showCursor()");
103            InputManager::getInstance().enterState("guiMouseOnly");
104        }
105        else
106        {
107            GUIManager::getInstance().executeCode("hideGUI(\"inGameTest\")");
108            GUIManager::getInstance().executeCode("hideCursor()");
109            InputManager::getInstance().leaveState("guiMouseOnly");
110        }
111    }
112
113    void GSLevel::deactivate()
114    {
115        if (GameMode::showsGraphics())
116        {
117            // disconnect the HumanPlayer
118            PlayerManager::getInstance().clientDisconnected(0);
119           
120            // unload all compositors (this is only necessary because we don't yet destroy all resources!)
121            Ogre::CompositorManager::getSingleton().removeAll();
122
123            InputManager::getInstance().leaveState("game");
124        }
125
126        if (GameMode::isMaster())
127            this->unloadLevel();
128
129        if (GameMode::showsGraphics())
130        {
131            gameInputState_->setHandler(0);
132            guiMouseOnlyInputState_->setHandler(0);
133            guiKeysOnlyInputState_->setHandler(0);
134            InputManager::getInstance().destroyState("game");
135            InputManager::getInstance().destroyState("guiKeysOnly");
136            InputManager::getInstance().destroyState("guiMouseOnly");
137        }
138    }
139
140    void GSLevel::update(const Clock& time)
141    {
142        // Note: Temporarily moved to GSRoot.
143        //// Call the scene objects
144        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
145        //    it->tick(time.getDeltaTime() * this->timeFactor_);
146    }
147
148    void GSLevel::loadLevel()
149    {
150        // call the loader
151        COUT(0) << "Loading level..." << std::endl;
152        startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel());
153        Loader::open(startFile_);
154    }
155
156    void GSLevel::unloadLevel()
157    {
158        Loader::unload(startFile_);
159        delete startFile_;
160    }
161}
Note: See TracBrowser for help on using the repository browser.