[Orxonox-commit 124] r2817 - in branches/gui/src: core orxonox orxonox/gamestates orxonox/overlays/debug
rgrieder at orxonox.net
rgrieder at orxonox.net
Sat Mar 21 22:17:59 CET 2009
Author: rgrieder
Date: 2009-03-21 21:17:59 +0000 (Sat, 21 Mar 2009)
New Revision: 2817
Modified:
branches/gui/src/core/CorePrereqs.h
branches/gui/src/core/GameState.cc
branches/gui/src/core/GameState.h
branches/gui/src/core/RootGameState.cc
branches/gui/src/core/RootGameState.h
branches/gui/src/orxonox/Game.cc
branches/gui/src/orxonox/Game.h
branches/gui/src/orxonox/GraphicsManager.h
branches/gui/src/orxonox/gamestates/GSClient.cc
branches/gui/src/orxonox/gamestates/GSClient.h
branches/gui/src/orxonox/gamestates/GSDedicated.cc
branches/gui/src/orxonox/gamestates/GSDedicated.h
branches/gui/src/orxonox/gamestates/GSGUI.cc
branches/gui/src/orxonox/gamestates/GSGUI.h
branches/gui/src/orxonox/gamestates/GSGraphics.cc
branches/gui/src/orxonox/gamestates/GSGraphics.h
branches/gui/src/orxonox/gamestates/GSIOConsole.cc
branches/gui/src/orxonox/gamestates/GSIOConsole.h
branches/gui/src/orxonox/gamestates/GSLevel.cc
branches/gui/src/orxonox/gamestates/GSLevel.h
branches/gui/src/orxonox/gamestates/GSRoot.cc
branches/gui/src/orxonox/gamestates/GSRoot.h
branches/gui/src/orxonox/gamestates/GSServer.cc
branches/gui/src/orxonox/gamestates/GSServer.h
branches/gui/src/orxonox/gamestates/GSStandalone.cc
branches/gui/src/orxonox/gamestates/GSStandalone.h
branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc
branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc
Log:
Removed GameState template and renamed GameStateBase to GameState.
Moved statistics stuff (fps and tick time) to Game and removed the remaining hacks in GSGraphics and GSRoot.
Modified: branches/gui/src/core/CorePrereqs.h
===================================================================
--- branches/gui/src/core/CorePrereqs.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/core/CorePrereqs.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -165,8 +165,6 @@
class XMLPortParamContainer;
// game states
- class GameStateBase;
- template <class ParentType>
class GameState;
class RootGameState;
Modified: branches/gui/src/core/GameState.cc
===================================================================
--- branches/gui/src/core/GameState.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/core/GameState.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -29,7 +29,7 @@
/**
@file
@brief
- Implementation of GameStateBase class.
+ Implementation of GameState class.
*/
#include "GameState.h"
@@ -42,9 +42,9 @@
@brief
Constructor only initialises variables and sets the name permanently.
*/
- GameStateBase::GameStateBase(const std::string& name)
+ GameState::GameState(const std::string& name)
: name_(name)
- //, parent_(0)
+ , parent_(0)
, activeChild_(0)
//, bPausegetParent()(false)
{
@@ -56,7 +56,7 @@
@brief
Destructor only checks that we don't delete an active state.
*/
- GameStateBase::~GameStateBase()
+ GameState::~GameState()
{
OrxAssert(this->operation_.active == false, "Deleting an active GameState is a very bad idea..");
}
@@ -68,12 +68,12 @@
@param state
The state to be added.
*/
- void GameStateBase::addChild(GameStateBase* state)
+ void GameState::addChild(GameState* state)
{
if (!state)
return;
// check if the state/tree to be added has states in it that already exist in this tree.
- for (std::map<std::string, GameStateBase*>::const_iterator it = state->allChildren_.begin();
+ for (std::map<std::string, GameState*>::const_iterator it = state->allChildren_.begin();
it != state->allChildren_.end(); ++it)
{
if (this->getState(it->second->getName()))
@@ -95,7 +95,7 @@
}
// merge the child's children into this tree
- for (std::map<std::string, GameStateBase*>::const_iterator it = state->allChildren_.begin();
+ for (std::map<std::string, GameState*>::const_iterator it = state->allChildren_.begin();
it != state->allChildren_.end(); ++it)
this->grandchildAdded(state, it->second);
// merge 'state' into this tree
@@ -112,9 +112,9 @@
@param state
GameState by instance pointer
*/
- void GameStateBase::removeChild(GameStateBase* state)
+ void GameState::removeChild(GameState* state)
{
- std::map<GameStateBase*, GameStateBase*>::iterator it = this->grandchildrenToChildren_.find(state);
+ std::map<GameState*, GameState*>::iterator it = this->grandchildrenToChildren_.find(state);
if (it != this->grandchildrenToChildren_.end())
{
if (state->isInSubtree(getCurrentState()))
@@ -126,7 +126,7 @@
}
else
{
- for (std::map<GameStateBase*, GameStateBase*>::const_iterator it = state->grandchildrenToChildren_.begin();
+ for (std::map<GameState*, GameState*>::const_iterator it = state->grandchildrenToChildren_.begin();
it != state->grandchildrenToChildren_.end(); ++it)
this->grandchildRemoved(it->first);
this->grandchildRemoved(state);
@@ -149,9 +149,9 @@
GameState by name
*/
- void GameStateBase::removeChild(const std::string& name)
+ void GameState::removeChild(const std::string& name)
{
- GameStateBase* state = getState(name);
+ GameState* state = getState(name);
if (state)
{
removeChild(state);
@@ -172,13 +172,13 @@
@param grandchild
The child that has been added.
*/
- inline void GameStateBase::grandchildAdded(GameStateBase* child, GameStateBase* grandchild)
+ inline void GameState::grandchildAdded(GameState* child, GameState* grandchild)
{
// fill the two maps correctly.
this->allChildren_[grandchild->getName()] = grandchild;
this->grandchildrenToChildren_[grandchild] = child;
- if (this->getParentAsBase())
- this->getParentAsBase()->grandchildAdded(this, grandchild);
+ if (this->getParent())
+ this->getParent()->grandchildAdded(this, grandchild);
}
/**
@@ -190,13 +190,13 @@
@param grandchild
The child that has been removed.
*/
- inline void GameStateBase::grandchildRemoved(GameStateBase* grandchild)
+ inline void GameState::grandchildRemoved(GameState* grandchild)
{
// adjust the two maps correctly.
this->allChildren_.erase(grandchild->getName());
this->grandchildrenToChildren_.erase(grandchild);
- if (this->getParentAsBase())
- this->getParentAsBase()->grandchildRemoved(grandchild);
+ if (this->getParent())
+ this->getParent()->grandchildRemoved(grandchild);
}
/**
@@ -205,17 +205,17 @@
@remarks
Remember that the every node has a map with all its child nodes.
*/
- GameStateBase* GameStateBase::getState(const std::string& name)
+ GameState* GameState::getState(const std::string& name)
{
- if (this->getParentAsBase())
- return this->getParentAsBase()->getState(name);
+ if (this->getParent())
+ return this->getParent()->getState(name);
else
{
// The map only contains children, so check ourself first
if (name == this->name_)
return this;
// Search in the map. If there is no entry, we can be sure the state doesn't exist.
- std::map<std::string, GameStateBase*>::const_iterator it = this->allChildren_.find(name);
+ std::map<std::string, GameState*>::const_iterator it = this->allChildren_.find(name);
return (it!= this->allChildren_.end() ? it->second : 0);
}
}
@@ -224,10 +224,10 @@
@brief
Returns the root node of the tree.
*/
- GameStateBase* GameStateBase::getRoot()
+ GameState* GameState::getRoot()
{
- if (this->getParentAsBase())
- return this->getParentAsBase()->getRoot();
+ if (this->getParent())
+ return this->getParent()->getRoot();
else
return this;
}
@@ -239,7 +239,7 @@
Remember that the current active state is the one that does not
have active children itself. Many states can be active at once.
*/
- GameStateBase* GameStateBase::getCurrentState()
+ GameState* GameState::getCurrentState()
{
if (this->operation_.active)
{
@@ -250,8 +250,8 @@
}
else
{
- if (this->getParentAsBase())
- return this->getParentAsBase()->getCurrentState();
+ if (this->getParent())
+ return this->getParent()->getCurrentState();
else
return 0;
}
@@ -261,7 +261,7 @@
@brief
Determines whether 'state' is in this subtree, including this node.
*/
- bool GameStateBase::isInSubtree(GameStateBase* state) const
+ bool GameState::isInSubtree(GameState* state) const
{
return (grandchildrenToChildren_.find(state) != grandchildrenToChildren_.end()
|| state == this);
@@ -274,7 +274,7 @@
@param state
The state to be entered, has to exist in the tree.
*/
- void GameStateBase::requestState(const std::string& name)
+ void GameState::requestState(const std::string& name)
{
assert(getRoot());
getRoot()->requestState(name);
@@ -285,9 +285,9 @@
Internal method that actually makes the state transition. Since it is internal,
the method can assume certain things to be granted (like 'this' is always active).
*/
- void GameStateBase::makeTransition(GameStateBase* source, GameStateBase* destination)
+ void GameState::makeTransition(GameState* source, GameState* destination)
{
- if (source == this->getParentAsBase())
+ if (source == this->getParent())
{
// call is from the parent
this->activate();
@@ -307,7 +307,7 @@
return;
// Check for 'destination' in the children map first
- std::map<GameStateBase*, GameStateBase*>::const_iterator it
+ std::map<GameState*, GameState*>::const_iterator it
= this->grandchildrenToChildren_.find(destination);
if (it != this->grandchildrenToChildren_.end())
{
@@ -318,10 +318,10 @@
else
{
// parent. We can be sure of this.
- assert(this->getParentAsBase() != 0);
+ assert(this->getParent() != 0);
this->deactivate();
- this->getParentAsBase()->makeTransition(this, destination);
+ this->getParent()->makeTransition(this, destination);
}
}
@@ -329,7 +329,7 @@
@brief
Activates the state. Only sets bActive_ to true and notifies the parent.
*/
- void GameStateBase::activate()
+ void GameState::activate()
{
this->operation_.active = true;
this->operation_.entering = true;
@@ -340,7 +340,7 @@
/**
Activates the state. Only sets bActive_ to false and notifies the parent.
*/
- void GameStateBase::deactivate()
+ void GameState::deactivate()
{
this->operation_.leaving = true;
this->leave();
@@ -357,7 +357,7 @@
@note
This method is not virtual! You cannot override it therefore.
*/
- void GameStateBase::tick(const Clock& time)
+ void GameState::tick(const Clock& time)
{
this->operation_.running = true;
this->ticked(time);
Modified: branches/gui/src/core/GameState.h
===================================================================
--- branches/gui/src/core/GameState.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/core/GameState.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -59,11 +59,9 @@
An example: Foo is a grandchildren of Bar and Foofoo is the Foo's parent.
Then Bar stores Foo in map by its name. The other one then maps Foo to Foofoo.
*/
- class _CoreExport GameStateBase
+ class _CoreExport GameState
{
friend class RootGameState;
- template <class ParentType>
- friend class GameState;
// Hack
friend class Game;
@@ -82,21 +80,22 @@
};
public:
- virtual ~GameStateBase();
+ GameState(const std::string& name);
+ virtual ~GameState();
const std::string& getName() const { return name_; }
const Operations getOperation() const { return this->operation_; }
- bool isInSubtree(GameStateBase* state) const;
+ bool isInSubtree(GameState* state) const;
- GameStateBase* getState(const std::string& name);
- GameStateBase* getRoot();
+ GameState* getState(const std::string& name);
+ GameState* getRoot();
//! Returns the currently active game state
- virtual GameStateBase* getCurrentState();
+ virtual GameState* getCurrentState();
virtual void requestState(const std::string& name);
- void addChild(GameStateBase* state);
- void removeChild(GameStateBase* state);
+ void addChild(GameState* state);
+ void removeChild(GameState* state);
void removeChild(const std::string& name);
protected:
@@ -104,23 +103,19 @@
virtual void leave() = 0;
virtual void ticked(const Clock& time) = 0;
- GameStateBase* getActiveChild() { return this->activeChild_; }
+ GameState* getActiveChild() { return this->activeChild_; }
void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); }
- virtual GameStateBase* getParentAsBase() const = 0;
- virtual void setParent(GameStateBase* state) = 0;
+ GameState* getParent() const { return this->parent_; }
+ void setParent(GameState* state) { this->parent_ = state; }
private:
- // Making the constructor private ensures that game states
- // are always derivates of GameState<T>. Note the friend declaration above.
- GameStateBase(const std::string& name);
-
//! Performs a transition to 'destination'
- virtual void makeTransition(GameStateBase* source, GameStateBase* destination);
+ virtual void makeTransition(GameState* source, GameState* destination);
- void grandchildAdded(GameStateBase* child, GameStateBase* grandchild);
- void grandchildRemoved(GameStateBase* grandchild);
+ void grandchildAdded(GameState* child, GameState* grandchild);
+ void grandchildRemoved(GameState* grandchild);
void tick(const Clock& time);
void activate();
@@ -128,39 +123,12 @@
const std::string name_;
Operations operation_;
- GameStateBase* activeChild_;
+ GameState* parent_;
+ GameState* activeChild_;
//bool bPauseParent_;
- std::map<std::string, GameStateBase*> allChildren_;
- std::map<GameStateBase*, GameStateBase*> grandchildrenToChildren_;
+ std::map<std::string, GameState*> allChildren_;
+ std::map<GameState*, GameState*> grandchildrenToChildren_;
};
-
-
- template <class ParentType>
- class GameState : public GameStateBase
- {
- public:
- GameState(const std::string& name)
- : GameStateBase(name)
- , parent_(0)
- { }
- virtual ~GameState() { }
-
- GameStateBase* getParentAsBase() const
- { return parent_; }
-
- ParentType* getParent() const
- { return parent_; }
-
- protected:
- void setParent(GameStateBase* state)
- {
- assert(dynamic_cast<ParentType*>(state) != 0);
- this->parent_ = dynamic_cast<ParentType*>(state);
- }
-
- private:
- ParentType* parent_;
- };
}
#endif /* _GameState_H__ */
Modified: branches/gui/src/core/RootGameState.cc
===================================================================
--- branches/gui/src/core/RootGameState.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/core/RootGameState.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -35,7 +35,7 @@
namespace orxonox
{
RootGameState::RootGameState(const std::string& name)
- : GameState<GameStateBase>(name)
+ : GameState(name)
, stateRequest_("")
{
}
@@ -49,7 +49,7 @@
Internal method that actually makes the state transition. Since it is internal,
the method can assume certain things to be granted (like 'this' is always active).
*/
- void RootGameState::makeTransition(GameStateBase* source, GameStateBase* destination)
+ void RootGameState::makeTransition(GameState* source, GameState* destination)
{
if (source != 0)
{
@@ -64,13 +64,13 @@
}
// Check for 'destination' in the children map first
- std::map<GameStateBase*, GameStateBase*>::const_iterator it
+ std::map<GameState*, GameState*>::const_iterator it
= this->grandchildrenToChildren_.find(destination);
if (it != this->grandchildrenToChildren_.end())
{
- OrxAssert(static_cast<GameStateBase*>(it->second) != 0,
+ OrxAssert(static_cast<GameState*>(it->second) != 0,
"There was a mix with RootGameState and GameState, could not cast.");
- GameStateBase* child = static_cast<GameStateBase*>(it->second);
+ GameState* child = static_cast<GameState*>(it->second);
// child state. Don't use 'state', might be a grandchild!
this->activeChild_ = child;
child->makeTransition(this, destination);
@@ -84,10 +84,10 @@
void RootGameState::gotoState(const std::string& name)
{
- GameStateBase* request = getState(name);
+ GameState* request = getState(name);
if (request)
{
- GameStateBase* current = getCurrentState();
+ GameState* current = getCurrentState();
if (current)
{
current->makeTransition(0, request);
Modified: branches/gui/src/core/RootGameState.h
===================================================================
--- branches/gui/src/core/RootGameState.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/core/RootGameState.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -34,7 +34,7 @@
namespace orxonox
{
- class _CoreExport RootGameState : public GameState<GameStateBase>
+ class _CoreExport RootGameState : public GameState
{
// Hack!
friend class Game;
@@ -46,7 +46,7 @@
void requestState(const std::string& name);
private:
- void makeTransition(GameStateBase* source, GameStateBase* destination);
+ void makeTransition(GameState* source, GameState* destination);
void gotoState(const std::string& name);
std::string stateRequest_;
Modified: branches/gui/src/orxonox/Game.cc
===================================================================
--- branches/gui/src/orxonox/Game.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/Game.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -44,6 +44,8 @@
#include "core/ConsoleCommand.h"
#include "core/Core.h"
#include "core/Identifier.h"
+#include "core/CoreIncludes.h"
+#include "core/ConfigValueIncludes.h"
#include "gamestates/GSRoot.h"
#include "gamestates/GSGraphics.h"
@@ -60,8 +62,16 @@
*/
int main(int argc, char** argv)
{
- orxonox::Game orxonox(argc, argv);
- orxonox.run();
+ {
+ orxonox::Game orxonox(argc, argv);
+ orxonox.run();
+ // objects gets destroyed here!
+ }
+
+ // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
+ // Needs to be done after Game destructor because of ~OrxonoxClass
+ orxonox::Identifier::destroyAllIdentifiers();
+
return 0;
}
@@ -88,8 +98,19 @@
this->abort_ = false;
+ // reset statistics
+ this->statisticsStartTime_ = 0;
+ this->statisticsTickTimes_.clear();
+ this->periodTickTime_ = 0;
+ this->periodTime_ = 0;
+ this->avgFPS_ = 0.0f;
+ this->avgTickTime_ = 0.0f;
+
this->core_ = new orxonox::Core();
this->gameClock_ = this->core_->initialise(argc, argv);
+
+ RegisterRootObject(Game);
+ this->setConfigValues();
}
/**
@@ -100,14 +121,18 @@
// Destroy pretty much everyhting left
delete this->core_;
- // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
- // Needs to be done after 'delete core' because of ~OrxonoxClass
- orxonox::Identifier::destroyAllIdentifiers();
-
assert(singletonRef_s);
singletonRef_s = 0;
}
+ void Game::setConfigValues()
+ {
+ SetConfigValue(statisticsRefreshCycle_, 250000)
+ .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
+ SetConfigValue(statisticsAvgLength_, 1000000)
+ .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
+ }
+
/**
@brief
Main loop of the orxonox game.
@@ -142,12 +167,45 @@
// get initial state from command line
root.gotoState(CommandLine::getValue("state"));
+ this->gameClock_->capture(); // first delta time should be about 0 seconds
while (!this->abort_)
{
this->gameClock_->capture();
+ uint64_t currentTime = this->gameClock_->getMicroseconds();
+ // STATISTICS
+ statisticsTickInfo tickInfo = {currentTime, 0};
+ statisticsTickTimes_.push_back(tickInfo);
+ this->periodTime_ += this->gameClock_->getDeltaTimeMicroseconds();
+
+ // UPDATE
root.tick(*this->gameClock_);
+ // STATISTICS
+ if (this->periodTime_ > statisticsRefreshCycle_)
+ {
+ std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
+ assert(it != this->statisticsTickTimes_.end());
+ int64_t lastTime = currentTime - this->statisticsAvgLength_;
+ if ((int64_t)it->tickTime < lastTime)
+ {
+ do
+ {
+ assert(this->periodTickTime_ > it->tickLength);
+ this->periodTickTime_ -= it->tickLength;
+ ++it;
+ assert(it != this->statisticsTickTimes_.end());
+ } while ((int64_t)it->tickTime < lastTime);
+ this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it);
+ }
+
+ uint32_t framesPerPeriod = this->statisticsTickTimes_.size();
+ this->avgFPS_ = (float)framesPerPeriod / (currentTime - this->statisticsTickTimes_.front().tickTime) * 1000000.0;
+ this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0;
+
+ this->periodTime_ -= this->statisticsRefreshCycle_;
+ }
+
if (root.stateRequest_ != "")
root.gotoState(root.stateRequest_);
}
@@ -160,4 +218,11 @@
{
this->abort_ = true;
}
+
+ void Game::addTickTime(uint32_t length)
+ {
+ assert(!this->statisticsTickTimes_.empty());
+ this->statisticsTickTimes_.back().tickLength += length;
+ this->periodTickTime_+=length;
+ }
}
Modified: branches/gui/src/orxonox/Game.h
===================================================================
--- branches/gui/src/orxonox/Game.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/Game.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -37,7 +37,8 @@
#include "OrxonoxPrereqs.h"
#include <cassert>
-#include "core/CorePrereqs.h"
+#include <list>
+#include "core/OrxonoxClass.h"
namespace orxonox
{
@@ -45,18 +46,30 @@
@brief
Main class responsible for running the game.
*/
- class _OrxonoxExport Game
+ class _OrxonoxExport Game : public OrxonoxClass
{
public:
Game(int argc, char** argv);
~Game();
+ void setConfigValues();
void run();
void stop();
+ float getAvgTickTime() { return this->avgTickTime_; }
+ float getAvgFPS() { return this->avgFPS_; }
+
+ void addTickTime(uint32_t length);
+
static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
private:
+ struct statisticsTickInfo
+ {
+ uint64_t tickTime;
+ uint32_t tickLength;
+ };
+
Game(Game&); // don't mess with singletons
Core* core_;
@@ -64,6 +77,19 @@
bool abort_;
+ // variables for time statistics
+ uint64_t statisticsStartTime_;
+ std::list<statisticsTickInfo>
+ statisticsTickTimes_;
+ uint32_t periodTime_;
+ uint32_t periodTickTime_;
+ float avgFPS_;
+ float avgTickTime_;
+
+ // config values
+ unsigned int statisticsRefreshCycle_;
+ unsigned int statisticsAvgLength_;
+
static Game* singletonRef_s; //!< Pointer to the Singleton
};
}
Modified: branches/gui/src/orxonox/GraphicsManager.h
===================================================================
--- branches/gui/src/orxonox/GraphicsManager.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/GraphicsManager.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -65,13 +65,6 @@
inline unsigned int getDetailLevelParticle() const
{ return this->detailLevelParticle_; }
- // <HACK>
- float getAverageFramesPerSecond() const { return this->avgFramesPerSecond_; }
- float getAverageTickTime() const { return this->avgTickTime_; }
- void setAverageTickTime(float tickTime) { this->avgTickTime_ = tickTime; }
- void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; }
- // </HACK>
-
inline void setViewport(Ogre::Viewport* viewport)
{ this->viewport_ = viewport; }
inline Ogre::Viewport* getViewport() const
Modified: branches/gui/src/orxonox/gamestates/GSClient.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSClient.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSClient.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -40,7 +40,7 @@
SetCommandLineArgument(ip, "127.0.0.1").information("#.#.#.#");
GSClient::GSClient()
- : GameState<GSGraphics>("client")
+ : GameState("client")
, client_(0)
{
}
Modified: branches/gui/src/orxonox/gamestates/GSClient.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSClient.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSClient.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -30,13 +30,13 @@
#define _GSClient_H__
#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
#include "network/NetworkPrereqs.h"
#include "GSLevel.h"
-#include "GSGraphics.h"
namespace orxonox
{
- class _OrxonoxExport GSClient : public GameState<GSGraphics>, public GSLevel
+ class _OrxonoxExport GSClient : public GameState, public GSLevel
{
public:
GSClient();
Modified: branches/gui/src/orxonox/gamestates/GSDedicated.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSDedicated.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSDedicated.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -40,7 +40,7 @@
namespace orxonox
{
GSDedicated::GSDedicated()
- : GameState<GSRoot>("dedicated")
+ : GameState("dedicated")
, server_(0)
, timeSinceLastUpdate_(0)
{
Modified: branches/gui/src/orxonox/gamestates/GSDedicated.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSDedicated.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSDedicated.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -30,13 +30,13 @@
#define _GSDedicated_H__
#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
#include "network/NetworkPrereqs.h"
#include "GSLevel.h"
-#include "GSRoot.h"
namespace orxonox
{
- class _OrxonoxExport GSDedicated : public GameState<GSRoot>, public GSLevel
+ class _OrxonoxExport GSDedicated : public GameState, public GSLevel
{
public:
GSDedicated();
Modified: branches/gui/src/orxonox/gamestates/GSGUI.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSGUI.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSGUI.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -39,7 +39,7 @@
namespace orxonox
{
GSGUI::GSGUI()
- : GameState<GSGraphics>("gui")
+ : GameState("gui")
{
}
Modified: branches/gui/src/orxonox/gamestates/GSGUI.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSGUI.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSGUI.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -31,11 +31,10 @@
#include "OrxonoxPrereqs.h"
#include "core/GameState.h"
-#include "GSGraphics.h"
namespace orxonox
{
- class _OrxonoxExport GSGUI : public GameState<GSGraphics>
+ class _OrxonoxExport GSGUI : public GameState
{
public:
GSGUI();
Modified: branches/gui/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSGraphics.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSGraphics.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -43,14 +43,13 @@
#include "core/XMLFile.h"
#include "overlays/console/InGameConsole.h"
#include "gui/GUIManager.h"
-
-// for compatibility
#include "GraphicsManager.h"
+#include "Game.h"
namespace orxonox
{
GSGraphics::GSGraphics()
- : GameState<GSRoot>("graphics")
+ : GameState("graphics")
, inputManager_(0)
, console_(0)
, guiManager_(0)
@@ -156,13 +155,9 @@
uint64_t timeAfterTick = time.getRealMicroseconds();
- // Also add our tick time to the list in GSRoot
- this->getParent()->addTickTime(timeAfterTick - timeBeforeTick);
+ // Also add our tick time
+ Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
- // Update statistics overlay. Note that the values only change periodically in GSRoot.
- GraphicsManager::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS());
- GraphicsManager::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime());
-
this->graphicsManager_->update(time);
}
Modified: branches/gui/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSGraphics.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSGraphics.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -33,11 +33,10 @@
#include "core/GameState.h"
#include "core/OrxonoxClass.h"
#include "tools/WindowEventListener.h"
-#include "GSRoot.h"
namespace orxonox
{
- class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public WindowEventListener
+ class _OrxonoxExport GSGraphics : public GameState, public WindowEventListener
{
friend class ClassIdentifier<GSGraphics>;
Modified: branches/gui/src/orxonox/gamestates/GSIOConsole.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSIOConsole.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSIOConsole.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -39,7 +39,7 @@
namespace orxonox
{
GSIOConsole::GSIOConsole()
- : GameState<GSRoot>("ioConsole")
+ : GameState("ioConsole")
{
}
Modified: branches/gui/src/orxonox/gamestates/GSIOConsole.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSIOConsole.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSIOConsole.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -32,11 +32,10 @@
#include "OrxonoxPrereqs.h"
#include <OgrePrerequisites.h>
#include "core/GameState.h"
-#include "GSRoot.h"
namespace orxonox
{
- class _OrxonoxExport GSIOConsole : public GameState<GSRoot>
+ class _OrxonoxExport GSIOConsole : public GameState
{
public:
GSIOConsole();
Modified: branches/gui/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSLevel.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSLevel.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -52,7 +52,7 @@
SetCommandLineArgument(level, "presentation.oxw").shortcut("l");
GSLevel::GSLevel()
-// : GameState<GSGraphics>(name)
+// : GameState(name)
: keyBinder_(0)
, inputState_(0)
, radar_(0)
Modified: branches/gui/src/orxonox/gamestates/GSLevel.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSLevel.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSLevel.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -30,6 +30,7 @@
#define _GSLevel_H__
#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
#include "core/OrxonoxClass.h"
namespace orxonox
Modified: branches/gui/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSRoot.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSRoot.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -32,11 +32,11 @@
#include "util/Exception.h"
#include "util/Debug.h"
#include "core/Core.h"
-#include "core/ConfigValueIncludes.h"
#include "core/CoreIncludes.h"
#include "core/ConsoleCommand.h"
#include "tools/Timer.h"
#include "objects/Tickable.h"
+#include "Game.h"
namespace orxonox
{
@@ -46,9 +46,6 @@
, bPaused_(false)
, timeFactorPauseBackup_(1.0f)
{
- RegisterRootObject(GSRoot);
- setConfigValues();
-
this->ccSetTimeFactor_ = 0;
this->ccPause_ = 0;
}
@@ -57,29 +54,14 @@
{
}
- void GSRoot::setConfigValues()
- {
- SetConfigValue(statisticsRefreshCycle_, 250000)
- .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
- SetConfigValue(statisticsAvgLength_, 1000000)
- .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
- }
-
void GSRoot::enter()
{
// reset game speed to normal
timeFactor_ = 1.0f;
- // reset frame counter
- this->statisticsStartTime_ = 0;
- this->statisticsTickTimes_.clear();
- this->periodTickTime_ = 0;
- this->avgFPS_ = 0.0f;
- this->avgTickTime_ = 0.0f;
-
{
// add console commands
- FunctorMember01<GameStateBase, const std::string&>* functor = createFunctor(&GameStateBase::requestState);
+ FunctorMember01<GameState, const std::string&>* functor = createFunctor(&GameState::requestState);
functor->setObject(this);
this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState");
CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_);
@@ -143,40 +125,10 @@
uint64_t timeAfterTick = time.getRealMicroseconds();
- // STATISTICS
- assert(timeAfterTick - timeBeforeTick >= 0 );
- statisticsTickInfo tickInfo = {timeAfterTick, timeAfterTick - timeBeforeTick};
- statisticsTickTimes_.push_back(tickInfo);
- assert(statisticsTickTimes_.back().tickLength==tickInfo.tickLength);
- this->periodTickTime_ += tickInfo.tickLength;
+ // Also add our tick time to the list in GSRoot
+ Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
- // Ticks GSGraphics or GSDedicated
this->tickChild(time);
-
- if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_)
- {
- std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
- assert(it != this->statisticsTickTimes_.end());
- int64_t lastTime = timeAfterTick - statisticsAvgLength_;
- if ((int64_t)it->tickTime < lastTime)
- {
- do
- {
- assert(this->periodTickTime_ > it->tickLength);
- this->periodTickTime_ -= it->tickLength;
- ++it;
- assert(it != this->statisticsTickTimes_.end());
- } while ((int64_t)it->tickTime < lastTime);
- this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it);
- }
-
- uint32_t framesPerPeriod = this->statisticsTickTimes_.size();
- this->avgFPS_ = (float)framesPerPeriod / (timeAfterTick - this->statisticsTickTimes_.front().tickTime) * 1000000.0;
- this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0;
-
- statisticsStartTime_ = timeAfterTick;
- }
-
}
/**
Modified: branches/gui/src/orxonox/gamestates/GSRoot.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSRoot.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSRoot.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -37,16 +37,11 @@
namespace orxonox
{
- class _OrxonoxExport GSRoot : public RootGameState, public OrxonoxClass
+ class _OrxonoxExport GSRoot : public RootGameState
{
friend class ClassIdentifier<GSRoot>;
public:
- struct statisticsTickInfo
- {
- uint64_t tickTime;
- uint32_t tickLength;
- };
public:
GSRoot();
@@ -58,36 +53,15 @@
void pause();
float getTimeFactor() { return this->timeFactor_; }
- float getAvgTickTime() { return this->avgTickTime_; }
- float getAvgFPS() { return this->avgFPS_; }
-
- inline void addTickTime(uint32_t length)
- { assert(!this->statisticsTickTimes_.empty()); this->statisticsTickTimes_.back().tickLength += length;
- this->periodTickTime_+=length; }
-
private:
void enter();
void leave();
void ticked(const Clock& time);
- void setConfigValues();
-
float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal.
bool bPaused_;
float timeFactorPauseBackup_;
- // variables for time statistics
- uint64_t statisticsStartTime_;
- std::list<statisticsTickInfo>
- statisticsTickTimes_;
- uint32_t periodTickTime_;
- float avgFPS_;
- float avgTickTime_;
-
- // config values
- unsigned int statisticsRefreshCycle_;
- unsigned int statisticsAvgLength_;
-
// console commands
ConsoleCommand* ccSelectGameState_;
ConsoleCommand* ccSetTimeFactor_;
Modified: branches/gui/src/orxonox/gamestates/GSServer.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSServer.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSServer.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -38,7 +38,7 @@
SetCommandLineArgument(port, 55556).shortcut("p").information("0-65535");
GSServer::GSServer()
- : GameState<GSGraphics>("server")
+ : GameState("server")
, server_(0)
{
}
Modified: branches/gui/src/orxonox/gamestates/GSServer.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSServer.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSServer.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -30,13 +30,13 @@
#define _GSServer_H__
#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
#include "network/NetworkPrereqs.h"
#include "GSLevel.h"
-#include "GSGraphics.h"
namespace orxonox
{
- class _OrxonoxExport GSServer : public GameState<GSGraphics>, public GSLevel
+ class _OrxonoxExport GSServer : public GameState, public GSLevel
{
public:
GSServer();
Modified: branches/gui/src/orxonox/gamestates/GSStandalone.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSStandalone.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSStandalone.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -39,7 +39,7 @@
namespace orxonox
{
GSStandalone::GSStandalone()
- : GameState<GSGraphics>("standalone")
+ : GameState("standalone")
{
}
Modified: branches/gui/src/orxonox/gamestates/GSStandalone.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSStandalone.h 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/gamestates/GSStandalone.h 2009-03-21 21:17:59 UTC (rev 2817)
@@ -30,12 +30,12 @@
#define _GSStandalone_H__
#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
#include "GSLevel.h"
-#include "GSGraphics.h"
namespace orxonox
{
- class _OrxonoxExport GSStandalone : public GameState<GSGraphics>, public GSLevel
+ class _OrxonoxExport GSStandalone : public GameState, public GSLevel
{
public:
GSStandalone();
Modified: branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc
===================================================================
--- branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -29,9 +29,9 @@
#include "OrxonoxStableHeaders.h"
#include "DebugFPSText.h"
#include <OgreTextAreaOverlayElement.h>
+#include "util/Convert.h"
#include "core/CoreIncludes.h"
-#include "GraphicsManager.h"
-#include "util/Convert.h"
+#include "Game.h"
namespace orxonox
{
@@ -50,7 +50,7 @@
{
SUPER(DebugFPSText, tick, dt);
- float fps = GraphicsManager::getInstance().getAverageFramesPerSecond();
+ float fps = Game::getInstance().getAvgFPS();
this->setCaption(convertToString(fps));
}
}
Modified: branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc
===================================================================
--- branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc 2009-03-21 19:47:11 UTC (rev 2816)
+++ branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc 2009-03-21 21:17:59 UTC (rev 2817)
@@ -31,7 +31,7 @@
#include <OgreTextAreaOverlayElement.h>
#include "core/CoreIncludes.h"
#include "util/Convert.h"
-#include "GraphicsManager.h"
+#include "Game.h"
namespace orxonox
{
@@ -50,7 +50,7 @@
{
SUPER(DebugRTRText, tick, dt);
- float rtr = GraphicsManager::getInstance().getAverageTickTime();
+ float rtr = Game::getInstance().getAvgTickTime();
this->setCaption(convertToString(rtr));
}
}
More information about the Orxonox-commit
mailing list