Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gamestates3/src/orxonox/gamestates/GSLevel.cc @ 10241

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

Merged gamestates2 branch back to trunk.
This brings in some heavy changes in the GUI framework.
It should also fix problems with triggered asserts in the InputManager.

Note: PickupInventory does not seem to work —> Segfault when showing because before, the owner in GUIOverlay::setGUIName is already NULL.
I haven't tested it before, so I can't tell whether it's my changes.

  • Property svn:eol-style set to native
File size: 5.3 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        , bShowIngameGUI_(false)
59    {
60    }
61
62    GSLevel::~GSLevel()
63    {
64    }
65
66    void GSLevel::activate()
67    {
68        if (GameMode::showsGraphics())
69        {
70            gameInputState_ = InputManager::getInstance().createInputState("game");
71            gameInputState_->setMouseExclusive(TriBool::True);
72            gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
73            KeyBinderManager::getInstance().setToDefault();
74
75            guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly");
76            guiMouseOnlyInputState_->setMouseExclusive(TriBool::True);
77            guiMouseOnlyInputState_->setMouseHandler(&GUIManager::getInstance());
78
79            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
80            guiKeysOnlyInputState_->setKeyHandler(&GUIManager::getInstance());
81        }
82
83        if (GameMode::isMaster())
84        {
85            this->loadLevel();
86        }
87
88        if (GameMode::showsGraphics())
89        {
90            // level is loaded: we can start capturing the input
91            InputManager::getInstance().enterState("game");
92
93            // connect the HumanPlayer to the game
94            PlayerManager::getInstance().clientConnected(0);
95        }
96    }
97
98    void GSLevel::deactivate()
99    {
100        if (GameMode::showsGraphics())
101        {
102            // unload all compositors (this is only necessary because we don't yet destroy all resources!)
103            Ogre::CompositorManager::getSingleton().removeAll();
104
105            InputManager::getInstance().leaveState("game");
106        }
107
108        // disconnect all HumanPlayers
109        PlayerManager::getInstance().disconnectAllClients();
110
111        if (GameMode::isMaster())
112            this->unloadLevel();
113
114        if (GameMode::showsGraphics())
115        {
116            gameInputState_->setHandler(0);
117            guiMouseOnlyInputState_->setHandler(0);
118            guiKeysOnlyInputState_->setHandler(0);
119            InputManager::getInstance().destroyState("game");
120            InputManager::getInstance().destroyState("guiKeysOnly");
121            InputManager::getInstance().destroyState("guiMouseOnly");
122        }
123    }
124
125    void GSLevel::update(const Clock& time)
126    {
127        // Note: Temporarily moved to GSRoot.
128        //// Call the scene objects
129        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
130        //    it->tick(time.getDeltaTime() * this->timeFactor_);
131    }
132
133    void GSLevel::loadLevel()
134    {
135        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
136            this->staticObjects_.insert(*it);
137
138        // call the loader
139        COUT(0) << "Loading level..." << std::endl;
140        startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel());
141        Loader::open(startFile_);
142    }
143
144    void GSLevel::unloadLevel()
145    {
146        Loader::unload(startFile_);
147        delete startFile_;
148
149        COUT(3) << "Unloaded level. Remaining objects:" << std::endl;
150        unsigned int i = 0;
151        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
152        {
153            std::set<BaseObject*>::const_iterator find = this->staticObjects_.find(*it);
154            if (find == this->staticObjects_.end())
155            {
156                COUT(3) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << ')' << std::endl;
157            }
158        }
159        COUT(3) << i << " objects remaining.";
160        if (i == 0)
161            COUT(3) << " Well done!" << std::endl;
162        else
163            COUT(3) << " Try harder!" << std::endl;
164    }
165}
Note: See TracBrowser for help on using the repository browser.