Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/orxonox/gamestates/GSGraphics.cc @ 2850

Last change on this file since 2850 was 2850, checked in by rgrieder, 15 years ago
  • Started working on cleaning up the GameState mess ;)
  • Cleaned out GUIManager
  • Renamed GSGUI to GSMainMenu
  • "—state blah" has been changed to —server, —client, —standalone, —dedicated
  • —console starts the game in the console (no level loading there yet, but "loadMenu")
  • adjusted run scripts
  • Property svn:eol-style set to native
File size: 5.8 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 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "GSGraphics.h"
31
32#include <boost/filesystem.hpp>
33#include <OgreRenderWindow.h>
34
35#include "util/Debug.h"
36#include "core/ConfigValueIncludes.h"
37#include "core/Clock.h"
38#include "core/Core.h"
39#include "core/CoreIncludes.h"
40#include "core/Game.h"
41#include "core/GameMode.h"
42#include "core/input/InputManager.h"
43#include "core/input/KeyBinder.h"
44#include "core/input/SimpleInputState.h"
45#include "core/Loader.h"
46#include "core/XMLFile.h"
47#include "overlays/console/InGameConsole.h"
48#include "gui/GUIManager.h"
49#include "GraphicsManager.h"
50
51namespace orxonox
52{
53    AddGameState(GSGraphics, "graphics");
54
55    GSGraphics::GSGraphics(const std::string& name)
56        : GameState(name)
57        , inputManager_(0)
58        , console_(0)
59        , guiManager_(0)
60        , graphicsManager_(0)
61        , masterKeyBinder_(0)
62        , masterInputState_(0)
63        , debugOverlay_(0)
64    {
65        RegisterRootObject(GSGraphics);
66    }
67
68    GSGraphics::~GSGraphics()
69    {
70    }
71
72    void GSGraphics::setConfigValues()
73    {
74    }
75
76    void GSGraphics::activate()
77    {
78        GameMode::setShowsGraphics(true);
79
80        setConfigValues();
81
82        // initialise graphics manager. Doesn't load the render window yet!
83        this->graphicsManager_ = new GraphicsManager();
84        this->graphicsManager_->initialise();
85
86        // load debug overlay
87        COUT(3) << "Loading Debug Overlay..." << std::endl;
88        this->debugOverlay_ = new XMLFile((Core::getMediaPath() / "overlay" / "debug.oxo").string());
89        Loader::open(debugOverlay_);
90
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();
94        size_t windowHnd = 0;
95        Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
96        renderWindow->getCustomAttribute("WINDOW", &windowHnd);
97        inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true);
98
99        masterInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("master", true);
100        masterKeyBinder_ = new KeyBinder();
101        masterKeyBinder_->loadBindings("masterKeybindings.ini");
102        masterInputState_->setKeyHandler(masterKeyBinder_);
103
104        // Load the InGameConsole
105        console_ = new InGameConsole();
106        console_->initialise(renderWindow->getWidth(), renderWindow->getHeight());
107
108        // load the CEGUI interface
109        guiManager_ = new GUIManager();
110        guiManager_->initialise(renderWindow);
111
112        InputManager::getInstance().requestEnterState("master");
113    }
114
115    void GSGraphics::deactivate()
116    {
117        masterInputState_->setHandler(0);
118        InputManager::getInstance().requestDestroyState("master");
119        delete this->masterKeyBinder_;
120
121        delete this->guiManager_;
122        delete this->console_;
123
124        Loader::unload(this->debugOverlay_);
125        delete this->debugOverlay_;
126
127        delete this->inputManager_;
128        this->inputManager_ = 0;
129
130        delete graphicsManager_;
131
132        GameMode::setShowsGraphics(false);
133    }
134
135    /**
136    @note
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    */
143    void GSGraphics::update(const Clock& time)
144    {
145        uint64_t timeBeforeTick = time.getRealMicroseconds();
146
147        this->inputManager_->update(time);        // tick console
148        this->console_->update(time);
149        this->guiManager_->update(time);
150
151        uint64_t timeAfterTick = time.getRealMicroseconds();
152
153        // Also add our tick time
154        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
155
156        // Render
157        this->graphicsManager_->update(time);
158    }
159
160    /**
161    @brief
162        Window has resized.
163    @param rw
164        The render window it occured in
165    @note
166        GraphicsManager has a render window stored itself. This is the same
167        as rw. But we have to be careful when using multiple render windows!
168    */
169    void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight)
170    {
171        // OIS needs this under linux even if we only use relative input measurement.
172        if (this->inputManager_)
173            this->inputManager_->setWindowExtents(newWidth, newHeight);
174    }
175
176    /**
177    @brief
178        Window focus has changed.
179    @param rw
180        The render window it occured in
181    */
182    void GSGraphics::windowFocusChanged()
183    {
184        // instruct InputManager to clear the buffers (core library so we cannot use the interface)
185        if (this->inputManager_)
186            this->inputManager_->clearBuffers();
187    }
188
189}
Note: See TracBrowser for help on using the repository browser.