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