[Orxonox-commit 832] r3349 - in branches/resource/src: core orxonox/gamestates orxonox/objects/quest
rgrieder at orxonox.net
rgrieder at orxonox.net
Sat Jul 25 14:14:05 CEST 2009
Author: rgrieder
Date: 2009-07-25 14:14:05 +0200 (Sat, 25 Jul 2009)
New Revision: 3349
Modified:
branches/resource/src/core/Core.cc
branches/resource/src/core/Core.h
branches/resource/src/core/Game.cc
branches/resource/src/core/Game.h
branches/resource/src/core/GraphicsManager.cc
branches/resource/src/orxonox/gamestates/GSGraphics.cc
branches/resource/src/orxonox/gamestates/GSGraphics.h
branches/resource/src/orxonox/gamestates/GSRoot.cc
branches/resource/src/orxonox/objects/quest/QuestListener.cc
branches/resource/src/orxonox/objects/quest/QuestManager.cc
Log:
Moved InputManager, GUIManager and GraphicsManager handling from GSGraphics to Core.
Modified: branches/resource/src/core/Core.cc
===================================================================
--- branches/resource/src/core/Core.cc 2009-07-24 23:14:30 UTC (rev 3348)
+++ branches/resource/src/core/Core.cc 2009-07-25 12:14:05 UTC (rev 3349)
@@ -40,6 +40,7 @@
#include <cstdlib>
#include <cstdio>
#include <boost/filesystem.hpp>
+#include <OgreRenderWindow.h>
#ifdef ORXONOX_PLATFORM_WINDOWS
# ifndef WIN32_LEAN_AND_MEAN
@@ -68,12 +69,15 @@
#include "CoreIncludes.h"
#include "Factory.h"
#include "GameMode.h"
+#include "GraphicsManager.h"
+#include "GUIManager.h"
#include "Identifier.h"
#include "Language.h"
#include "LuaBind.h"
#include "Shell.h"
#include "TclBind.h"
#include "TclThreadManager.h"
+#include "input/InputManager.h"
namespace orxonox
{
@@ -345,6 +349,20 @@
if (bGraphicsLoaded_)
return;
+ // Load OGRE including the render window
+ this->graphicsManager_ = new GraphicsManager();
+
+ // The render window width and height are used to set up the mouse movement.
+ size_t windowHnd = 0;
+ Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
+ renderWindow->getCustomAttribute("WINDOW", &windowHnd);
+
+ // Calls the InputManager which sets up the input devices.
+ inputManager_ = new InputManager(windowHnd);
+
+ // load the CEGUI interface
+ guiManager_ = new GUIManager(renderWindow);
+
GameMode::setShowsGraphics(true);
bGraphicsLoaded_ = true;
}
@@ -354,6 +372,10 @@
if (!bGraphicsLoaded_)
return;
+ delete this->guiManager_;
+ delete this->inputManager_;
+ delete graphicsManager_;
+
bGraphicsLoaded_ = false;
GameMode::setShowsGraphics(false);
}
@@ -645,8 +667,49 @@
}
}
- void Core::update(const Clock& time)
+ bool Core::preUpdate(const Clock& time) throw()
{
- this->tclThreadManager_->update(time);
+ std::string exceptionMessage;
+ try
+ {
+ // process input events
+ this->inputManager_->update(time);
+ // process gui events
+ this->guiManager_->update(time);
+ // process thread commands
+ this->tclThreadManager_->update(time);
+ }
+ catch (const std::exception& ex)
+ { exceptionMessage = ex.what(); }
+ catch (...)
+ { exceptionMessage = "Unknown exception"; }
+ if (!exceptionMessage.empty())
+ {
+ COUT(0) << "An exception occurred in the Core preUpdate: " << exceptionMessage << std::endl;
+ COUT(0) << "This should really never happen! Closing the program." << std::endl;
+ return false;
+ }
+ return true;
}
+
+ bool Core::postUpdate(const Clock& time) throw()
+ {
+ std::string exceptionMessage;
+ try
+ {
+ // Render (doesn't throw)
+ this->graphicsManager_->update(time);
+ }
+ catch (const std::exception& ex)
+ { exceptionMessage = ex.what(); }
+ catch (...)
+ { exceptionMessage = "Unknown exception"; }
+ if (!exceptionMessage.empty())
+ {
+ COUT(0) << "An exception occurred in the Core postUpdate: " << exceptionMessage << std::endl;
+ COUT(0) << "This should really never happen! Closing the program." << std::endl;
+ return false;
+ }
+ return true;
+ }
}
Modified: branches/resource/src/core/Core.h
===================================================================
--- branches/resource/src/core/Core.h 2009-07-24 23:14:30 UTC (rev 3348)
+++ branches/resource/src/core/Core.h 2009-07-25 12:14:05 UTC (rev 3349)
@@ -70,7 +70,8 @@
void setConfigValues();
- void update(const Clock& time);
+ bool preUpdate(const Clock& time) throw();
+ bool postUpdate(const Clock& time) throw();
void loadGraphics();
void unloadGraphics();
@@ -118,6 +119,10 @@
SignalHandler* signalHandler_;
TclBind* tclBind_;
TclThreadManager* tclThreadManager_;
+ // graphical
+ InputManager* inputManager_; //!< Interface to OIS
+ GUIManager* guiManager_; //!< Interface to GUI
+ GraphicsManager* graphicsManager_; //!< Interface to OGRE
bool bDevRun_; //!< True for runs in the build directory (not installed)
bool bGraphicsLoaded_;
Modified: branches/resource/src/core/Game.cc
===================================================================
--- branches/resource/src/core/Game.cc 2009-07-24 23:14:30 UTC (rev 3348)
+++ branches/resource/src/core/Game.cc 2009-07-25 12:14:05 UTC (rev 3349)
@@ -244,25 +244,9 @@
this->requestedStateNodes_.erase(this->requestedStateNodes_.begin());
}
- // UPDATE, Core first
- bool threwException = false;
- try
+ // UPDATE, Core preUpdate (doesn't throw)
+ if (!this->core_->preUpdate(*this->gameClock_))
{
- this->core_->update(*this->gameClock_);
- }
- catch (const std::exception& ex)
- {
- threwException = true;
- COUT(0) << "Exception while ticking the Core: " << ex.what() << std::endl;
- }
- catch (...)
- {
- threwException = true;
- }
- if (threwException)
- {
- COUT(0) << "An exception occured while ticking the Core. This should really never happen!" << std::endl;
- COUT(0) << "Closing the program." << std::endl;
this->stop();
break;
}
@@ -272,29 +256,25 @@
for (std::vector<GameState*>::const_iterator it = this->activeStates_.begin() + 1;
it != this->activeStates_.end(); ++it)
{
- bool threwException = false;
+ std::string exceptionMessage;
try
{
// Add tick time for most of the states
uint64_t timeBeforeTick;
- if (!(*it)->ignoreTickTime())
+ if ((*it)->ignoreTickTime())
timeBeforeTick = this->gameClock_->getRealMicroseconds();
(*it)->update(*this->gameClock_);
- if (!(*it)->ignoreTickTime())
- this->addTickTime(static_cast<uint32_t>(this->gameClock_->getRealMicroseconds() - timeBeforeTick));
+ if ((*it)->ignoreTickTime())
+ this->subtractTickTime(static_cast<int32_t>(this->gameClock_->getRealMicroseconds() - timeBeforeTick));
}
catch (const std::exception& ex)
- {
- threwException = true;
- COUT(0) << "Exception while ticking: " << ex.what() << std::endl;
- }
+ { exceptionMessage = ex.what(); }
catch (...)
+ { exceptionMessage = "Unknown exception"; }
+ if (!exceptionMessage.empty())
{
- threwException = true;
- }
- if (threwException)
- {
- COUT(1) << "An exception occured while ticking GameState '" << (*it)->getName() << "'. This should really never happen!" << std::endl;
+ COUT(1) << "An exception occurred while updating '" << (*it)->getName() << "': " << exceptionMessage << std::endl;
+ COUT(1) << "This should really never happen!" << std::endl;
COUT(1) << "Unloading all GameStates depending on the one that crashed." << std::endl;
if ((*it)->getParent() != NULL)
this->requestState((*it)->getParent()->getName());
@@ -305,6 +285,13 @@
}
+ // UPDATE, Core postUpdate (doesn't throw)
+ if (!this->core_->postUpdate(*this->gameClock_))
+ {
+ this->stop();
+ break;
+ }
+
// STATISTICS
if (this->periodTime_ > this->configuration_->statisticsRefreshCycle_)
{
@@ -343,11 +330,11 @@
this->bAbort_ = true;
}
- void Game::addTickTime(uint32_t length)
+ void Game::subtractTickTime(int32_t length)
{
assert(!this->statisticsTickTimes_.empty());
- this->statisticsTickTimes_.back().tickLength += length;
- this->periodTickTime_+=length;
+ this->statisticsTickTimes_.back().tickLength -= length;
+ this->periodTickTime_ -= length;
}
Modified: branches/resource/src/core/Game.h
===================================================================
--- branches/resource/src/core/Game.h 2009-07-24 23:14:30 UTC (rev 3348)
+++ branches/resource/src/core/Game.h 2009-07-25 12:14:05 UTC (rev 3349)
@@ -85,7 +85,7 @@
float getAvgTickTime() { return this->avgTickTime_; }
float getAvgFPS() { return this->avgFPS_; }
- void addTickTime(uint32_t length);
+ void subtractTickTime(int32_t length);
template <class T>
static bool declareGameState(const std::string& className, const std::string& stateName, bool bIgnoreTickTime, bool bConsoleMode);
Modified: branches/resource/src/core/GraphicsManager.cc
===================================================================
--- branches/resource/src/core/GraphicsManager.cc 2009-07-24 23:14:30 UTC (rev 3348)
+++ branches/resource/src/core/GraphicsManager.cc 2009-07-25 12:14:05 UTC (rev 3349)
@@ -195,9 +195,16 @@
// (probably only necessary on windows)
this->renderWindow_->setActive(true);
- // render
+ // Time before rendering
+ uint64_t timeBeforeTick = time.getRealMicroseconds();
+
+ // Render frame
ogreRoot_->_updateAllRenderTargets();
+ uint64_t timeAfterTick = time.getRealMicroseconds();
+ // Subtract the time used for rendering from the tick time counter
+ Game::getInstance().subtractTickTime(timeAfterTick - timeBeforeTick);
+
// again, just to be sure OGRE works fine
ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
}
Modified: branches/resource/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- branches/resource/src/orxonox/gamestates/GSGraphics.cc 2009-07-24 23:14:30 UTC (rev 3348)
+++ branches/resource/src/orxonox/gamestates/GSGraphics.cc 2009-07-25 12:14:05 UTC (rev 3349)
@@ -34,17 +34,12 @@
#include "GSGraphics.h"
-#include <boost/filesystem.hpp>
-#include <OgreRenderWindow.h>
-
#include "util/Convert.h"
#include "core/Clock.h"
#include "core/CommandExecutor.h"
#include "core/ConsoleCommand.h"
#include "core/Core.h"
#include "core/Game.h"
-#include "core/GameMode.h"
-#include "core/GraphicsManager.h"
#include "core/GUIManager.h"
#include "core/input/InputManager.h"
#include "core/input/KeyBinder.h"
@@ -59,14 +54,11 @@
namespace orxonox
{
- DeclareGameState(GSGraphics, "graphics", true, true);
+ DeclareGameState(GSGraphics, "graphics", false, true);
GSGraphics::GSGraphics(const GameStateConstrParams& params)
: GameState(params)
- , inputManager_(0)
, console_(0)
- , guiManager_(0)
- , graphicsManager_(0)
, soundManager_(0)
, masterKeyBinder_(0)
, masterInputState_(0)
@@ -98,22 +90,10 @@
// Load OGRE, CEGUI and OIS
Core::getInstance().loadGraphics();
- // Load OGRE including the render window
- this->graphicsManager_ = new GraphicsManager();
-
// load debug overlay
COUT(3) << "Loading Debug Overlay..." << std::endl;
- this->debugOverlay_ = new XMLFile((Core::getMediaPath() / "overlay" / "debug.oxo").string());
+ this->debugOverlay_ = new XMLFile(Core::getMediaPathString() + "overlay/debug.oxo");
Loader::open(debugOverlay_);
-
- // The render window width and height are used to set up the mouse movement.
- size_t windowHnd = 0;
- Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
- renderWindow->getCustomAttribute("WINDOW", &windowHnd);
-
- // Calls the InputManager which sets up the input devices.
- inputManager_ = new InputManager(windowHnd);
-
// load master key bindings
masterInputState_ = InputManager::getInstance().createInputState("master", true);
masterKeyBinder_ = new KeyBinder();
@@ -127,9 +107,6 @@
console_ = new InGameConsole();
console_->initialise();
- // load the CEGUI interface
- guiManager_ = new GUIManager(renderWindow);
-
// add console command to toggle GUI
FunctorMember<GSGraphics>* functor = createFunctor(&GSGraphics::toggleGUI);
functor->setObject(this);
@@ -160,7 +137,6 @@
InputManager::getInstance().destroyState("master");
delete this->masterKeyBinder_;
- delete this->guiManager_;
delete this->console_;
Loader::unload(this->debugOverlay_);
@@ -168,14 +144,9 @@
delete this->soundManager_;
- delete this->inputManager_;
- this->inputManager_ = 0;
-
- // HACK:
+ // HACK: (destroys a resource smart pointer)
Map::hackDestroyMap();
- delete graphicsManager_;
-
// Unload OGRE, CEGUI and OIS
Core::getInstance().loadGraphics();
}
@@ -209,19 +180,6 @@
Game::getInstance().requestState("mainMenu");
}
- uint64_t timeBeforeTick = time.getRealMicroseconds();
-
- this->inputManager_->update(time);
this->console_->update(time);
-
- uint64_t timeAfterTick = time.getRealMicroseconds();
-
- // Also add our tick time
- Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
-
- // Process gui events
- this->guiManager_->update(time);
- // Render
- this->graphicsManager_->update(time);
}
}
Modified: branches/resource/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- branches/resource/src/orxonox/gamestates/GSGraphics.h 2009-07-24 23:14:30 UTC (rev 3348)
+++ branches/resource/src/orxonox/gamestates/GSGraphics.h 2009-07-25 12:14:05 UTC (rev 3349)
@@ -60,10 +60,7 @@
private:
// managed singletons
- InputManager* inputManager_; //!< Reference to input management
InGameConsole* console_;
- GUIManager* guiManager_; //!< Interface to GUI
- GraphicsManager* graphicsManager_; //!< Interface to Ogre
SoundManager* soundManager_; //!< Keeps track of SoundBase objects
KeyBinder* masterKeyBinder_; //!< Key binder for master key bindings
Modified: branches/resource/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- branches/resource/src/orxonox/gamestates/GSRoot.cc 2009-07-24 23:14:30 UTC (rev 3348)
+++ branches/resource/src/orxonox/gamestates/GSRoot.cc 2009-07-25 12:14:05 UTC (rev 3349)
@@ -44,7 +44,7 @@
namespace orxonox
{
- DeclareGameState(GSRoot, "root", true, false);
+ DeclareGameState(GSRoot, "root", false, false);
SetCommandLineSwitch(console).information("Start in console mode (text IO only)");
// Shortcuts for easy direct loading
SetCommandLineSwitch(server).information("Start in server mode");
@@ -154,8 +154,6 @@
Game::getInstance().requestState("ioConsole");
}
- uint64_t timeBeforeTick = time.getRealMicroseconds();
-
for (ObjectList<TimerBase>::iterator it = ObjectList<TimerBase>::begin(); it; ++it)
it->tick(time);
@@ -170,11 +168,6 @@
for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
it->tick(leveldt * this->timeFactor_);
/*** HACK *** HACK ***/
-
- uint64_t timeAfterTick = time.getRealMicroseconds();
-
- // Also add our tick time
- Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
}
/**
Modified: branches/resource/src/orxonox/objects/quest/QuestListener.cc
===================================================================
--- branches/resource/src/orxonox/objects/quest/QuestListener.cc 2009-07-24 23:14:30 UTC (rev 3348)
+++ branches/resource/src/orxonox/objects/quest/QuestListener.cc 2009-07-25 12:14:05 UTC (rev 3349)
@@ -80,7 +80,7 @@
/**
@brief
- Makes all QuestListener in the list aware that a certain status change has occured and executes them if the status change affects them.
+ Makes all QuestListener in the list aware that a certain status change has occurred and executes them if the status change affects them.
@param listeners
The list of QuestListeners that have to be made aware of the status change.
@param status
@@ -181,7 +181,7 @@
}
else
{
- COUT(1) << "An unforseen, never to happen, Error has occured. This is impossible!" << std::endl;
+ COUT(1) << "An unforseen, never to happen, Error has occurred. This is impossible!" << std::endl;
return "";
}
}
Modified: branches/resource/src/orxonox/objects/quest/QuestManager.cc
===================================================================
--- branches/resource/src/orxonox/objects/quest/QuestManager.cc 2009-07-24 23:14:30 UTC (rev 3348)
+++ branches/resource/src/orxonox/objects/quest/QuestManager.cc 2009-07-25 12:14:05 UTC (rev 3349)
@@ -322,7 +322,7 @@
else
{
container->status = "";
- COUT(1) << "An error occured. A Quest of un-specified status wanted to be displayed." << std::endl;
+ COUT(1) << "An error occurred. A Quest of un-specified status wanted to be displayed." << std::endl;
}
std::list<Quest*> quests = quest->getSubQuestList();
More information about the Orxonox-commit
mailing list