[Orxonox-commit 165] r2844 - in branches/gui/src: core network orxonox orxonox/gamestates orxonox/overlays/debug
rgrieder at orxonox.net
rgrieder at orxonox.net
Wed Mar 25 17:23:01 CET 2009
Author: rgrieder
Date: 2009-03-25 16:23:00 +0000 (Wed, 25 Mar 2009)
New Revision: 2844
Added:
branches/gui/src/core/Game.cc
branches/gui/src/core/Game.h
branches/gui/src/orxonox/Main.cc
Removed:
branches/gui/src/core/RootGameState.cc
branches/gui/src/core/RootGameState.h
branches/gui/src/orxonox/Game.cc
branches/gui/src/orxonox/Game.h
Modified:
branches/gui/src/core/CMakeLists.txt
branches/gui/src/core/CorePrereqs.h
branches/gui/src/core/GameState.cc
branches/gui/src/core/GameState.h
branches/gui/src/network/Server.h
branches/gui/src/orxonox/CMakeLists.txt
branches/gui/src/orxonox/OrxonoxPrereqs.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:
Implemented new GameState concept. It doesn't differ that much from the old one, but there's still lots of changes.
The most important change is that one GameState can occur multiple times in the hierarchy.
Short log:
- No RootGameState anymore. Simply the highest is root.
- Game::requestGameState(name) can refer to the parent, grandparent, great-grandparent, etc. or one of the children.
- Requested states are saved. So if you select "level", the next request (even right after the call) will be relative to "level"
- Game::popState() will simply unload the current one
- Re added Main.cc again because Game as well as GameState have been moved to the core
- Adapted all GameStates to the new system
Things should already work, except for network support because standalone only works with a little hack.
We can now start creating a better hierarchy.
Modified: branches/gui/src/core/CMakeLists.txt
===================================================================
--- branches/gui/src/core/CMakeLists.txt 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/core/CMakeLists.txt 2009-03-25 16:23:00 UTC (rev 2844)
@@ -23,12 +23,12 @@
ConfigValueContainer.cc
Core.cc
Event.cc
+ Game.cc
GameState.cc
Language.cc
LuaBind.cc
ObjectListBase.cc
OrxonoxClass.cc
- RootGameState.cc
# command
ArgumentCompletionFunctions.cc
Modified: branches/gui/src/core/CorePrereqs.h
===================================================================
--- branches/gui/src/core/CorePrereqs.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/core/CorePrereqs.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -165,8 +165,9 @@
class XMLPortParamContainer;
// game states
+ class Game;
class GameState;
- class RootGameState;
+ struct GameStateTreeNode;
// input
class BaseCommand;
Copied: branches/gui/src/core/Game.cc (from rev 2843, branches/gui/src/orxonox/Game.cc)
===================================================================
--- branches/gui/src/core/Game.cc (rev 0)
+++ branches/gui/src/core/Game.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -0,0 +1,408 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ at file
+ at brief
+ Implementation of the Game class.
+*/
+
+#include "Game.h"
+
+#include <exception>
+#include <cassert>
+
+#include "util/Debug.h"
+#include "util/Exception.h"
+#include "Clock.h"
+#include "CommandLine.h"
+#include "ConsoleCommand.h"
+#include "Core.h"
+#include "CoreIncludes.h"
+#include "ConfigValueIncludes.h"
+#include "GameState.h"
+
+namespace orxonox
+{
+ void stop_game()
+ {
+ Game::getInstance().stop();
+ }
+
+ struct _CoreExport GameStateTreeNode
+ {
+ GameState* state_;
+ GameStateTreeNode* parent_;
+ std::vector<GameStateTreeNode*> children_;
+ };
+
+ SetCommandLineArgument(state, "gui").shortcut("s");
+ SetCommandLineSwitch(startWithConsole);
+ SetConsoleCommandShortcutExternAlias(stop_game, "exit");
+
+ std::map<std::string, GameState*> Game::allStates_s;
+ Game* Game::singletonRef_s = 0;
+
+ /**
+ @brief
+ Non-initialising constructor.
+ */
+ Game::Game(int argc, char** argv)
+ {
+ assert(singletonRef_s == 0);
+ singletonRef_s = this;
+
+ this->rootStateNode_ = 0;
+ this->activeStateNode_ = 0;
+
+ 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();
+ }
+
+ /**
+ @brief
+ */
+ Game::~Game()
+ {
+ // Destroy pretty much everyhting left
+ delete this->core_;
+
+ // Delete all GameStates created by the macros
+ for (std::map<std::string, GameState*>::const_iterator it = allStates_s.begin(); it != allStates_s.end(); ++it)
+ delete it->second;
+
+ 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.
+ @note
+ We use the Ogre::Timer to measure time since it uses the most precise
+ method an any platform (however the windows timer lacks time when under
+ heavy kernel load!).
+ */
+ void Game::run()
+ {
+ // </EXPORT THIS>
+ this->setStateHierarchy(
+ "root"
+ " graphics"
+ " gui"
+ " standalone"
+ " level"
+ " server"
+ " level"
+ " client"
+ " level"
+ " dedicated"
+ " level"
+ " ioConsole"
+ );
+ // </EXPORT THIS>
+
+
+ // Always start with the root state
+ this->requestedStateNodes_.push_back(this->rootStateNode_);
+ this->activeStateNode_ = this->rootStateNode_;
+ this->loadState(this->rootStateNode_->state_);
+
+ // <EXPORT THIS>
+ if (CommandLine::getValue("startWithConsole").getBool())
+ {
+ // Start the game in the console
+ this->requestState("ioConsole");
+ }
+ else
+ {
+ // Start in GUI main menu
+ this->requestState("graphics");
+ this->requestState("gui");
+ }
+ // </EXPORT THIS>
+
+ this->gameClock_->capture(); // first delta time should be about 0 seconds
+ while (!this->abort_ && !this->activeStates_.empty())
+ {
+ this->gameClock_->capture();
+ uint64_t currentTime = this->gameClock_->getMicroseconds();
+
+ // STATISTICS
+ statisticsTickInfo tickInfo = {currentTime, 0};
+ statisticsTickTimes_.push_back(tickInfo);
+ this->periodTime_ += this->gameClock_->getDeltaTimeMicroseconds();
+
+ // UPDATE STATE STACK
+ while (this->requestedStateNodes_.size() > 1)
+ {
+ // Note: this->requestedStateNodes_.front() is the currently active state node
+ std::vector<GameStateTreeNode*>::iterator it = this->requestedStateNodes_.begin() + 1;
+ if (*it == this->activeStateNode_->parent_)
+ this->unloadState(this->activeStateNode_->state_);
+ else // has to be child
+ this->loadState((*it)->state_);
+ this->activeStateNode_ = *it;
+ this->requestedStateNodes_.erase(this->requestedStateNodes_.begin());
+ }
+
+ // UPDATE, bottom to top in the stack
+ for (std::vector<GameState*>::const_iterator it = this->activeStates_.begin();
+ it != this->activeStates_.end(); ++it)
+ (*it)->update(*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_;
+ }
+ }
+
+ // Unload all remaining states
+ while (!this->activeStates_.empty())
+ this->unloadState(this->activeStates_.back());
+ this->activeStateNode_ = 0;
+ this->requestedStateNodes_.clear();
+ }
+
+ void Game::stop()
+ {
+ this->abort_ = true;
+ }
+
+ void Game::addTickTime(uint32_t length)
+ {
+ assert(!this->statisticsTickTimes_.empty());
+ this->statisticsTickTimes_.back().tickLength += length;
+ this->periodTickTime_+=length;
+ }
+
+
+ /***** GameState related *****/
+
+ void Game::requestState(const std::string& name)
+ {
+ GameState* state = this->getState(name);
+ if (state == NULL || this->activeStateNode_ == NULL)
+ return;
+
+ GameStateTreeNode* requestedNode = 0;
+
+ // this->requestedStateNodes_.back() is the currently active state
+ GameStateTreeNode* lastRequestedNode = this->requestedStateNodes_.back();
+
+ // Already the active node?
+ if (state == lastRequestedNode->state_)
+ {
+ COUT(2) << "Warning: Requesting the currently active state! Ignoring." << std::endl;
+ return;
+ }
+
+ // Check children first
+ for (unsigned int i = 0; i < lastRequestedNode->children_.size(); ++i)
+ {
+ if (lastRequestedNode->children_[i]->state_ == state)
+ {
+ requestedNode = lastRequestedNode->children_[i];
+ break;
+ }
+ }
+
+ // Check parent and all its grand parents
+ GameStateTreeNode* currentNode = lastRequestedNode;
+ while (requestedNode == NULL && currentNode->parent_ != NULL)
+ {
+ if (currentNode->state_ == state)
+ requestedNode = currentNode;
+ currentNode = currentNode->parent_;
+ }
+
+ if (requestedNode == NULL)
+ COUT(1) << "Error: Requested GameState transition is not allowed. Ignoring." << std::endl;
+ else
+ this->requestedStateNodes_.push_back(requestedNode);
+ }
+
+ void Game::popState()
+ {
+ if (this->activeStateNode_ != NULL && this->requestedStateNodes_.back()->parent_)
+ this->requestState(this->requestedStateNodes_.back()->parent_->state_->getName());
+ else
+ COUT(2) << "Warning: Could not pop GameState. Ignoring." << std::endl;
+ }
+
+ GameState* Game::getState(const std::string& name)
+ {
+ std::map<std::string, GameState*>::const_iterator it = allStates_s.find(name);
+ if (it != allStates_s.end())
+ return it->second;
+ else
+ {
+ COUT(1) << "Error: Could not find GameState '" << name << "'. Ignoring." << std::endl;
+ return 0;
+ }
+ }
+
+ void Game::setStateHierarchy(const std::string& str)
+ {
+ // Split string into pieces of the form whitespacesText
+ std::vector<std::pair<std::string, unsigned> > stateStrings;
+ size_t pos = 0;
+ size_t startPos = 0;
+ while (pos < str.size())
+ {
+ unsigned indentation = 0;
+ while(pos < str.size() && str[pos] == ' ')
+ ++indentation, ++pos;
+ startPos = pos;
+ while(pos < str.size() && str[pos] != ' ')
+ ++pos;
+ stateStrings.push_back(std::pair<std::string, unsigned>(
+ str.substr(startPos, pos - startPos), indentation));
+ }
+ unsigned int currentLevel = 0;
+ GameStateTreeNode* currentNode = 0;
+ for (std::vector<std::pair<std::string, unsigned> >::const_iterator it = stateStrings.begin(); it != stateStrings.end(); ++it)
+ {
+ std::string newStateName = it->first;
+ unsigned newLevel = it->second;
+ GameState* newState = this->getState(newStateName);
+ if (!newState)
+ ThrowException(GameState, std::string("GameState with name '") + newStateName + "' not found!");
+ if (newLevel == 0)
+ {
+ // root
+ if (this->rootStateNode_ != NULL)
+ ThrowException(GameState, "No two root GameStates are allowed!");
+ GameStateTreeNode* newNode = new GameStateTreeNode;
+ newNode->state_ = newState;
+ newNode->parent_ = 0;
+ this->rootStateNode_ = newNode;
+ currentNode = this->rootStateNode_;
+ }
+ else if (currentNode)
+ {
+ GameStateTreeNode* newNode = new GameStateTreeNode;
+ newNode->state_ = newState;
+ if (newLevel < currentLevel)
+ {
+ // Get down the hierarchy
+ do
+ currentNode = currentNode->parent_;
+ while (newLevel < --currentLevel);
+ }
+ if (newLevel == currentLevel)
+ {
+ // same level
+ newNode->parent_ = currentNode->parent_;
+ newNode->parent_->children_.push_back(newNode);
+ }
+ else if (newLevel == currentLevel + 1)
+ {
+ // child
+ newNode->parent_ = currentNode;
+ currentNode->children_.push_back(newNode);
+ }
+ else
+ ThrowException(GameState, "Indentation error while parsing the hierarchy.");
+ currentNode = newNode;
+ currentLevel = newLevel;
+ }
+ else
+ {
+ ThrowException(GameState, "No root GameState specified!");
+ }
+ }
+ }
+
+ /*** Internal ***/
+
+ void Game::loadState(GameState* state)
+ {
+ state->activate();
+ this->activeStates_.push_back(state);
+ }
+
+ void Game::unloadState(orxonox::GameState* state)
+ {
+ state->deactivate();
+ this->activeStates_.pop_back();
+ }
+
+ /*static*/ bool Game::addGameState(GameState* state)
+ {
+ std::map<std::string, GameState*>::const_iterator it = allStates_s.find(state->getName());
+ if (it == allStates_s.end())
+ allStates_s[state->getName()] = state;
+ else
+ ThrowException(GameState, "Cannot add two GameStates with the same name to 'Game'.");
+
+ // just a required dummy return value
+ return true;
+ }
+}
Copied: branches/gui/src/core/Game.h (from rev 2843, branches/gui/src/orxonox/Game.h)
===================================================================
--- branches/gui/src/core/Game.h (rev 0)
+++ branches/gui/src/core/Game.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -0,0 +1,117 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ at file
+ at brief
+ Declaration of Game Singleton.
+ */
+
+#ifndef _Game_H__
+#define _Game_H__
+
+#include "CorePrereqs.h"
+#include <cassert>
+#include <list>
+#include <map>
+#include <vector>
+#include "OrxonoxClass.h"
+
+#define AddGameState(classname, name, ...) \
+ static bool bGameStateDummy_##classname##__LINE__ = orxonox::Game::addGameState(new classname(name, __VA_ARGS__))
+
+namespace orxonox
+{
+ /**
+ @brief
+ Main class responsible for running the game.
+ */
+ class _CoreExport Game : public OrxonoxClass
+ {
+ public:
+ Game(int argc, char** argv);
+ ~Game();
+ void setConfigValues();
+
+ void setStateHierarchy(const std::string& str);
+ GameState* getState(const std::string& name);
+
+ void run();
+ void stop();
+
+ void requestState(const std::string& name);
+ void popState();
+
+ float getAvgTickTime() { return this->avgTickTime_; }
+ float getAvgFPS() { return this->avgFPS_; }
+
+ void addTickTime(uint32_t length);
+
+ static bool addGameState(GameState* state);
+ 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
+
+ void loadState(GameState* state);
+ void unloadState(GameState* state);
+
+ std::vector<GameState*> activeStates_;
+ GameStateTreeNode* rootStateNode_;
+ GameStateTreeNode* activeStateNode_;
+ std::vector<GameStateTreeNode*> requestedStateNodes_;
+
+ Core* core_;
+ Clock* gameClock_;
+
+ 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 std::map<std::string, GameState*> allStates_s;
+ static Game* singletonRef_s; //!< Pointer to the Singleton
+ };
+}
+
+#endif /* _Game_H__ */
Modified: branches/gui/src/core/GameState.cc
===================================================================
--- branches/gui/src/core/GameState.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/core/GameState.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -33,8 +33,10 @@
*/
#include "GameState.h"
+#include <cassert>
#include "util/Debug.h"
#include "util/Exception.h"
+#include "Clock.h"
namespace orxonox
{
@@ -45,11 +47,9 @@
GameState::GameState(const std::string& name)
: name_(name)
, parent_(0)
- , activeChild_(0)
- //, bPausegetParent()(false)
{
- Operations temp = {false, false, false, false, false};
- this->operation_ = temp;
+ State temp = {false, false, false, false, false};
+ this->activity_ = temp;
}
/**
@@ -58,7 +58,7 @@
*/
GameState::~GameState()
{
- OrxAssert(this->operation_.active == false, "Deleting an active GameState is a very bad idea..");
+ OrxAssert(this->activity_.active == false, "Deleting an active GameState is a very bad idea..");
}
/**
@@ -70,39 +70,19 @@
*/
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, GameState*>::const_iterator it = state->allChildren_.begin();
- it != state->allChildren_.end(); ++it)
+ assert(state != NULL);
+
+ std::map<std::string, GameState*>::const_iterator it = this->children_.find(state->getName());
+ if (it == this->children_.end())
{
- if (this->getState(it->second->getName()))
- {
- ThrowException(GameState, "Cannot add a GameState to the hierarchy twice.");
- return;
- }
+ this->children_[state->getName()] = state;
+ // mark us as parent
+ state->setParent(this);
}
- if (this->getState(state->name_))
+ else
{
- ThrowException(GameState, "Cannot add a GameState to the hierarchy twice.");
- return;
+ ThrowException(GameState, "Cannot add two children with the same name");
}
- // Make sure we don't add a tree that already has an active state.
- if (state->getCurrentState())
- {
- ThrowException(GameState, "Cannot merge a tree that is already active.");
- return;
- }
-
- // merge the child's children into this tree
- 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
- this->grandchildAdded(state, state);
-
- // mark us as parent
- state->setParent(this);
}
/**
@@ -114,253 +94,40 @@
*/
void GameState::removeChild(GameState* state)
{
- std::map<GameState*, GameState*>::iterator it = this->grandchildrenToChildren_.find(state);
- if (it != this->grandchildrenToChildren_.end())
- {
- if (state->isInSubtree(getCurrentState()))
- {
- ThrowException(GameState, "Cannot remove an active game state child '"
- + state->getName() + "' from '" + name_ + "'.");
- //COUT(2) << "Warning: Cannot remove an active game state child '" << state->getName()
- // << "' from '" << name_ << "'." << std::endl;
- }
- else
- {
- for (std::map<GameState*, GameState*>::const_iterator it = state->grandchildrenToChildren_.begin();
- it != state->grandchildrenToChildren_.end(); ++it)
- this->grandchildRemoved(it->first);
- this->grandchildRemoved(state);
- }
- }
+ assert(state != NULL);
+
+ std::map<std::string, GameState*>::iterator it = this->children_.find(state->getName());
+ if (it != this->children_.end())
+ this->children_.erase(it);
else
{
ThrowException(GameState, "Game state '" + name_ + "' doesn't have a child named '"
+ state->getName() + "'.");
- //COUT(2) << "Warning: Game state '" << name_ << "' doesn't have a child named '"
- // << state->getName() << "'. Removal skipped." << std::endl;
}
}
- /**
- @brief
- Removes a child by name. This splits the tree in two parts,
- each of them functional on its own.
- @param state
- GameState by name
- */
-
- void GameState::removeChild(const std::string& name)
+ void GameState::activateInternal()
{
- GameState* state = getState(name);
- if (state)
- {
- removeChild(state);
- }
- else
- {
- ThrowException(GameState, "GameState '" + name + "' doesn't exist.");
- //COUT(2) << "Warning: GameState '" << name << "' doesn't exist." << std::endl;
- }
+ this->activity_.activating = true;
+ this->activate();
+ this->activity_.activating = false;
+ this->activity_.active = true;
}
- /**
- @brief
- Tells a state that one of its children has added a child. This is necessary
- to fill the internal maps correctly.
- @param child
- The child who notices this state.
- @param grandchild
- The child that has been added.
- */
- inline void GameState::grandchildAdded(GameState* child, GameState* grandchild)
+ void GameState::deactivateInternal()
{
- // fill the two maps correctly.
- this->allChildren_[grandchild->getName()] = grandchild;
- this->grandchildrenToChildren_[grandchild] = child;
- if (this->getParent())
- this->getParent()->grandchildAdded(this, grandchild);
+ this->activity_.active = false;
+ this->activity_.deactivating = true;
+ this->activate();
+ this->activity_.deactivating = false;
+ this->activity_.suspended = false;
+ this->activity_.updating = false;
}
- /**
- @brief
- Tells a state that one of its children has removed a child. This is necessary
- to fill the internal maps correctly.
- @param child
- The child who notices this state.
- @param grandchild
- The child that has been removed.
- */
- inline void GameState::grandchildRemoved(GameState* grandchild)
+ void GameState::updateInternal(const Clock& time)
{
- // adjust the two maps correctly.
- this->allChildren_.erase(grandchild->getName());
- this->grandchildrenToChildren_.erase(grandchild);
- if (this->getParent())
- this->getParent()->grandchildRemoved(grandchild);
+ this->activity_.updating = true;
+ this->update(time);
+ this->activity_.updating = false;
}
-
- /**
- @brief
- Checks whether a specific game states exists in the hierarchy.
- @remarks
- Remember that the every node has a map with all its child nodes.
- */
- GameState* GameState::getState(const std::string& 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, GameState*>::const_iterator it = this->allChildren_.find(name);
- return (it!= this->allChildren_.end() ? it->second : 0);
- }
- }
-
- /**
- @brief
- Returns the root node of the tree.
- */
- GameState* GameState::getRoot()
- {
- if (this->getParent())
- return this->getParent()->getRoot();
- else
- return this;
- }
-
- /**
- @brief
- Returns the current active state.
- @remarks
- Remember that the current active state is the one that does not
- have active children itself. Many states can be active at once.
- */
- GameState* GameState::getCurrentState()
- {
- if (this->operation_.active)
- {
- if (this->activeChild_)
- return this->activeChild_->getCurrentState();
- else
- return this;
- }
- else
- {
- if (this->getParent())
- return this->getParent()->getCurrentState();
- else
- return 0;
- }
- }
-
- /**
- @brief
- Determines whether 'state' is in this subtree, including this node.
- */
- bool GameState::isInSubtree(GameState* state) const
- {
- return (grandchildrenToChildren_.find(state) != grandchildrenToChildren_.end()
- || state == this);
- }
-
- /**
- @brief
- Makes a state transition according to the state tree. You can choose any state
- in the tree to do the call. The function finds the current state on its own.
- @param state
- The state to be entered, has to exist in the tree.
- */
- void GameState::requestState(const std::string& name)
- {
- assert(getRoot());
- getRoot()->requestState(name);
- }
-
- /**
- @brief
- 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 GameState::makeTransition(GameState* source, GameState* destination)
- {
- if (source == this->getParent())
- {
- // call is from the parent
- this->activate();
- }
- else if (source == 0)
- {
- // call was just started by root
- // don't do anyting yet
- }
- else
- {
- // call is from a child
- this->activeChild_ = 0;
- }
-
- if (destination == this)
- return;
-
- // Check for 'destination' in the children map first
- std::map<GameState*, GameState*>::const_iterator it
- = this->grandchildrenToChildren_.find(destination);
- if (it != this->grandchildrenToChildren_.end())
- {
- // child state. Don't use 'state', might be a grandchild!
- this->activeChild_ = it->second;
- it->second->makeTransition(this, destination);
- }
- else
- {
- // parent. We can be sure of this.
- assert(this->getParent() != 0);
-
- this->deactivate();
- this->getParent()->makeTransition(this, destination);
- }
- }
-
- /**
- @brief
- Activates the state. Only sets bActive_ to true and notifies the parent.
- */
- void GameState::activate()
- {
- this->operation_.active = true;
- this->operation_.entering = true;
- this->enter();
- this->operation_.entering = false;
- }
-
- /**
- Activates the state. Only sets bActive_ to false and notifies the parent.
- */
- void GameState::deactivate()
- {
- this->operation_.leaving = true;
- this->leave();
- this->operation_.leaving = false;
- this->operation_.active = false;
- }
-
- /**
- @brief
- Update method that calls ticked() with enclosed bRunning_ = true
- If there was a state transition request within ticked() then this
- method will transition in the end.
- @param dt Delta time
- @note
- This method is not virtual! You cannot override it therefore.
- */
- void GameState::tick(const Clock& time)
- {
- this->operation_.running = true;
- this->ticked(time);
- this->operation_.running = false;
- }
}
Modified: branches/gui/src/core/GameState.h
===================================================================
--- branches/gui/src/core/GameState.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/core/GameState.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -38,10 +38,8 @@
#include "CorePrereqs.h"
#include <string>
-#include <vector>
#include <map>
-#include <cassert>
-#include "Clock.h"
+#include "CorePrereqs.h"
namespace orxonox
{
@@ -61,8 +59,6 @@
*/
class _CoreExport GameState
{
- friend class RootGameState;
- // Hack
friend class Game;
public:
@@ -70,13 +66,13 @@
@brief
Gives information about what the GameState is currently doing
*/
- struct Operations
+ struct State
{
- unsigned active : 1;
- unsigned entering : 1;
- unsigned leaving : 1;
- unsigned running : 1;
- unsigned suspended : 1;
+ unsigned active : 1;
+ unsigned activating : 1;
+ unsigned deactivating : 1;
+ unsigned updating : 1;
+ unsigned suspended : 1;
};
public:
@@ -84,50 +80,28 @@
virtual ~GameState();
const std::string& getName() const { return name_; }
- const Operations getOperation() const { return this->operation_; }
- bool isInSubtree(GameState* state) const;
+ const State getActivity() const { return this->activity_; }
+ GameState* getParent() const { return this->parent_; }
- GameState* getState(const std::string& name);
- GameState* getRoot();
- //! Returns the currently active game state
- virtual GameState* getCurrentState();
-
- virtual void requestState(const std::string& name);
-
void addChild(GameState* state);
void removeChild(GameState* state);
- void removeChild(const std::string& name);
protected:
- virtual void enter() = 0;
- virtual void leave() = 0;
- virtual void ticked(const Clock& time) = 0;
+ virtual void activate() = 0;
+ virtual void deactivate() = 0;
+ virtual void update(const Clock& time) = 0;
- GameState* getActiveChild() { return this->activeChild_; }
-
- void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); }
-
- GameState* getParent() const { return this->parent_; }
+ private:
void setParent(GameState* state) { this->parent_ = state; }
+ void setActivity(State activity);
+ void activateInternal();
+ void deactivateInternal();
+ void updateInternal(const Clock& time);
- private:
- //! Performs a transition to 'destination'
- virtual void makeTransition(GameState* source, GameState* destination);
-
- void grandchildAdded(GameState* child, GameState* grandchild);
- void grandchildRemoved(GameState* grandchild);
-
- void tick(const Clock& time);
- void activate();
- void deactivate();
-
const std::string name_;
- Operations operation_;
+ State activity_;
GameState* parent_;
- GameState* activeChild_;
- //bool bPauseParent_;
- std::map<std::string, GameState*> allChildren_;
- std::map<GameState*, GameState*> grandchildrenToChildren_;
+ std::map<std::string, GameState*> children_;
};
}
Deleted: branches/gui/src/core/RootGameState.cc
===================================================================
--- branches/gui/src/core/RootGameState.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/core/RootGameState.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -1,118 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-#include "RootGameState.h"
-
-#include "util/Debug.h"
-#include "util/Exception.h"
-#include "Clock.h"
-
-namespace orxonox
-{
- RootGameState::RootGameState(const std::string& name)
- : GameState(name)
- , stateRequest_("")
- {
- }
-
- RootGameState::~RootGameState()
- {
- }
-
- /**
- @brief
- 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(GameState* source, GameState* destination)
- {
- if (source != 0)
- {
- // transition was not initiated by root itself
- this->activeChild_ = 0;
- }
-
- if (destination == this)
- {
- // this marks the end of the game.
- return;
- }
-
- // Check for 'destination' in the children map first
- std::map<GameState*, GameState*>::const_iterator it
- = this->grandchildrenToChildren_.find(destination);
- if (it != this->grandchildrenToChildren_.end())
- {
- OrxAssert(static_cast<GameState*>(it->second) != 0,
- "There was a mix with RootGameState and GameState, could not cast.");
- GameState* child = static_cast<GameState*>(it->second);
- // child state. Don't use 'state', might be a grandchild!
- this->activeChild_ = child;
- child->makeTransition(this, destination);
- }
- else
- {
- // root doesn't have a parent..
- OrxAssert(false, "GameState '" + destination->getName() + "' not found in children list of Root.");
- }
- }
-
- void RootGameState::gotoState(const std::string& name)
- {
- GameState* request = getState(name);
- if (request)
- {
- GameState* current = getCurrentState();
- if (current)
- {
- current->makeTransition(0, request);
- }
- else
- {
- // Root is not yet active. This is a violation.
- ThrowException(GameState, "Activate Root before requesting a state.");
- }
- }
- else
- {
- COUT(2) << "Warning: GameState '" << name << "' doesn't exist." << std::endl;
- }
- }
-
- /**
- @brief
- Makes a state transition according to the state tree. You can choose any state
- in the tree to do the call. The function finds the current state on its own.
- @param state
- The state to be entered, has to exist in the tree.
- */
- void RootGameState::requestState(const std::string& name)
- {
- this->stateRequest_ = name;
- }
-}
Deleted: branches/gui/src/core/RootGameState.h
===================================================================
--- branches/gui/src/core/RootGameState.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/core/RootGameState.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -1,56 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-#ifndef _RootGameState_H__
-#define _RootGameState_H__
-
-#include "CorePrereqs.h"
-#include "GameState.h"
-
-namespace orxonox
-{
- class _CoreExport RootGameState : public GameState
- {
- // Hack!
- friend class Game;
-
- public:
- RootGameState(const std::string& name);
- ~RootGameState();
-
- void requestState(const std::string& name);
-
- private:
- void makeTransition(GameState* source, GameState* destination);
- void gotoState(const std::string& name);
-
- std::string stateRequest_;
- };
-}
-
-#endif /* _RootGameState_H__ */
Modified: branches/gui/src/network/Server.h
===================================================================
--- branches/gui/src/network/Server.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/network/Server.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -52,7 +52,7 @@
{
const int CLIENTID_SERVER = 0;
const unsigned int NETWORK_FREQUENCY = 25;
- const float NETWORK_PERIOD = 1./NETWORK_FREQUENCY;
+ const float NETWORK_PERIOD = 1.f/NETWORK_FREQUENCY;
/**
* This class is the root class of the network module for a server.
Modified: branches/gui/src/orxonox/CMakeLists.txt
===================================================================
--- branches/gui/src/orxonox/CMakeLists.txt 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/CMakeLists.txt 2009-03-25 16:23:00 UTC (rev 2844)
@@ -19,9 +19,9 @@
SET_SOURCE_FILES(ORXONOX_SRC_FILES
CameraManager.cc
- Game.cc
GraphicsManager.cc
LevelManager.cc
+ Main.cc
PawnManager.cc
PlayerManager.cc
)
Deleted: branches/gui/src/orxonox/Game.cc
===================================================================
--- branches/gui/src/orxonox/Game.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/Game.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -1,228 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- at file
- at brief
- Implementation of the Game class.
-*/
-
-#include "OrxonoxStableHeaders.h"
-#include "Game.h"
-
-#include <exception>
-#include <cassert>
-
-#include "util/Debug.h"
-#include "util/Exception.h"
-#include "core/CommandLine.h"
-#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"
-#include "gamestates/GSStandalone.h"
-#include "gamestates/GSServer.h"
-#include "gamestates/GSClient.h"
-#include "gamestates/GSDedicated.h"
-#include "gamestates/GSGUI.h"
-#include "gamestates/GSIOConsole.h"
-
-/*
- at brief
- Main method. Game starts here (except for static initialisations).
-*/
-int main(int argc, char** argv)
-{
- {
- 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;
-}
-
-namespace orxonox
-{
- void stop_game()
- {
- Game::getInstance().stop();
- }
-
- SetCommandLineArgument(state, "gui").shortcut("s");
- SetConsoleCommandShortcutExternAlias(stop_game, "exit");
-
- Game* Game::singletonRef_s = 0;
-
- /**
- @brief
- Non-initialising constructor.
- */
- Game::Game(int argc, char** argv)
- {
- assert(singletonRef_s == 0);
- singletonRef_s = this;
-
- 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();
- }
-
- /**
- @brief
- */
- Game::~Game()
- {
- // Destroy pretty much everyhting left
- delete this->core_;
-
- 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.
- @note
- We use the Ogre::Timer to measure time since it uses the most precise
- method an any platform (however the windows timer lacks time when under
- heavy kernel load!).
- */
- void Game::run()
- {
- // create the gamestates
- GSRoot root;
- GSGraphics graphics;
- GSStandalone standalone;
- GSServer server;
- GSClient client;
- GSDedicated dedicated;
- GSGUI gui;
- GSIOConsole ioConsole;
-
- // make the hierarchy
- root.addChild(&graphics);
- graphics.addChild(&standalone);
- graphics.addChild(&server);
- graphics.addChild(&client);
- graphics.addChild(&gui);
- root.addChild(&ioConsole);
- root.addChild(&dedicated);
-
- root.activate();
-
- // 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_);
- }
-
- root.gotoState("root");
- root.deactivate();
- }
-
- void Game::stop()
- {
- this->abort_ = true;
- }
-
- void Game::addTickTime(uint32_t length)
- {
- assert(!this->statisticsTickTimes_.empty());
- this->statisticsTickTimes_.back().tickLength += length;
- this->periodTickTime_+=length;
- }
-}
Deleted: branches/gui/src/orxonox/Game.h
===================================================================
--- branches/gui/src/orxonox/Game.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/Game.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -1,97 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- at file
- at brief
- Declaration of Game Singleton.
- */
-
-#ifndef _Game_H__
-#define _Game_H__
-
-#include "OrxonoxPrereqs.h"
-#include <cassert>
-#include <list>
-#include "core/OrxonoxClass.h"
-
-namespace orxonox
-{
- /**
- @brief
- Main class responsible for running the 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_;
- Clock* gameClock_;
-
- 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
- };
-}
-
-#endif /* _Game_H__ */
Copied: branches/gui/src/orxonox/Main.cc (from rev 2801, branches/gui/src/orxonox/Main.cc)
===================================================================
--- branches/gui/src/orxonox/Main.cc (rev 0)
+++ branches/gui/src/orxonox/Main.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -0,0 +1,58 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+ /**
+ @file
+ @brief Entry point of the program.
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "OrxonoxConfig.h"
+
+#include "util/Debug.h"
+#include "core/Identifier.h"
+#include "core/Game.h"
+
+/*
+ at brief
+ Main method. Game starts here (except for static initialisations).
+*/
+int main(int argc, char** argv)
+{
+ {
+ orxonox::Game orxonox(argc, argv);
+ orxonox.run();
+ } // orxonox gets destroyed right 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;
+}
Modified: branches/gui/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- branches/gui/src/orxonox/OrxonoxPrereqs.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/OrxonoxPrereqs.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -76,9 +76,6 @@
//put here all existing munitionTypes
namespace MunitionType
{
-
-
-
enum Enum
{ laserGunMunition };
}
@@ -237,17 +234,6 @@
//gui
class GUIManager;
-
- // game states
- class GSRoot;
- class GSGraphics;
- class GSIO;
- class GSIOConsole;
- class GSLevel;
- class GSStandalone;
- class GSServer;
- class GSClient;
- class GSGUI;
}
namespace Ogre
Modified: branches/gui/src/orxonox/gamestates/GSClient.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSClient.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSClient.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -34,13 +34,16 @@
#include "core/CommandLine.h"
#include "core/Core.h"
#include "network/Client.h"
+#include "core/Game.h"
namespace orxonox
{
+ AddGameState(GSClient, "client");
+
SetCommandLineArgument(ip, "127.0.0.1").information("#.#.#.#");
- GSClient::GSClient()
- : GameState("client")
+ GSClient::GSClient(const std::string& name)
+ : GameState(name)
, client_(0)
{
}
@@ -49,7 +52,7 @@
{
}
- void GSClient::enter()
+ void GSClient::activate()
{
Core::setIsClient(true);
@@ -58,15 +61,11 @@
if(!client_->establishConnection())
ThrowException(InitialisationFailed, "Could not establish connection with server.");
- GSLevel::enter();
-
client_->update(Core::getGameClock());
}
- void GSClient::leave()
+ void GSClient::deactivate()
{
- GSLevel::leave();
-
client_->closeConnection();
// destroy client
@@ -75,11 +74,8 @@
Core::setIsClient(false);
}
- void GSClient::ticked(const Clock& time)
+ void GSClient::update(const Clock& time)
{
- GSLevel::ticked(time);
client_->update(time);
-
- this->tickChild(time);
}
}
Modified: branches/gui/src/orxonox/gamestates/GSClient.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSClient.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSClient.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -32,22 +32,20 @@
#include "OrxonoxPrereqs.h"
#include "core/GameState.h"
#include "network/NetworkPrereqs.h"
-#include "GSLevel.h"
namespace orxonox
{
- class _OrxonoxExport GSClient : public GameState, public GSLevel
+ class _OrxonoxExport GSClient : public GameState
{
public:
- GSClient();
+ GSClient(const std::string& name);
~GSClient();
+ void activate();
+ void deactivate();
+ void update(const Clock& time);
private:
- void enter();
- void leave();
- void ticked(const Clock& time);
-
Client* client_;
};
}
Modified: branches/gui/src/orxonox/gamestates/GSDedicated.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSDedicated.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSDedicated.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -36,11 +36,14 @@
#include "network/Server.h"
#include "objects/Tickable.h"
#include "util/Sleep.h"
+#include "core/Game.h"
namespace orxonox
{
- GSDedicated::GSDedicated()
- : GameState("dedicated")
+ AddGameState(GSDedicated, "dedicated");
+
+ GSDedicated::GSDedicated(const std::string& name)
+ : GameState(name)
, server_(0)
, timeSinceLastUpdate_(0)
{
@@ -50,29 +53,25 @@
{
}
- void GSDedicated::enter()
+ void GSDedicated::activate()
{
Core::setHasServer(true);
this->server_ = new Server(CommandLine::getValue("port"));
COUT(0) << "Loading scene in server mode" << std::endl;
- GSLevel::enter();
-
server_->open();
}
- void GSDedicated::leave()
+ void GSDedicated::deactivate()
{
- GSLevel::leave();
-
this->server_->close();
delete this->server_;
Core::setHasServer(false);
}
- void GSDedicated::ticked(const Clock& time)
+ void GSDedicated::update(const Clock& time)
{
// static float startTime = time.getSecondsPrecise();
// static int nrOfTicks = 0;
@@ -82,9 +81,7 @@
// ++nrOfTicks;
// COUT(0) << "estimated ticks/sec: " << nrOfTicks/(time.getSecondsPrecise()-startTime) << endl;
timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD;
- GSLevel::ticked(time);
server_->update(time);
- this->tickChild(time);
}
else
{
Modified: branches/gui/src/orxonox/gamestates/GSDedicated.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSDedicated.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSDedicated.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -32,23 +32,22 @@
#include "OrxonoxPrereqs.h"
#include "core/GameState.h"
#include "network/NetworkPrereqs.h"
-#include "GSLevel.h"
namespace orxonox
{
- class _OrxonoxExport GSDedicated : public GameState, public GSLevel
+ class _OrxonoxExport GSDedicated : public GameState
{
public:
- GSDedicated();
+ GSDedicated(const std::string& name);
~GSDedicated();
- private:
- void enter();
- void leave();
- void ticked(const Clock& time);
+ void activate();
+ void deactivate();
+ void update(const Clock& time);
- Server* server_;
- float timeSinceLastUpdate_;
+ private:
+ Server* server_;
+ float timeSinceLastUpdate_;
};
}
Modified: branches/gui/src/orxonox/gamestates/GSGUI.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSGUI.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSGUI.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -31,15 +31,19 @@
#include <OgreViewport.h>
#include "core/Clock.h"
+#include "core/ConsoleCommand.h"
#include "core/input/InputManager.h"
#include "core/input/SimpleInputState.h"
#include "gui/GUIManager.h"
#include "GraphicsManager.h"
+#include "core/Game.h"
namespace orxonox
{
- GSGUI::GSGUI()
- : GameState("gui")
+ AddGameState(GSGUI, "gui");
+
+ GSGUI::GSGUI(const std::string& name)
+ : GameState(name)
{
}
@@ -47,7 +51,7 @@
{
}
- void GSGUI::enter()
+ void GSGUI::activate()
{
guiManager_ = GUIManager::getInstancePtr();
@@ -55,18 +59,38 @@
//guiManager_->loadScene("MainMenu");
guiManager_->showGUI("MainMenu", 0);
GraphicsManager::getInstance().getViewport()->setCamera(guiManager_->getCamera());
+
+ {
+ // time factor console command
+ FunctorMember<GSGUI>* functor = createFunctor(&GSGUI::startGame);
+ functor->setObject(this);
+ this->ccStartGame_ = createConsoleCommand(functor, "startGame");
+ CommandExecutor::addConsoleCommandShortcut(this->ccStartGame_);
+ }
}
- void GSGUI::leave()
+ void GSGUI::deactivate()
{
+ if (this->ccStartGame_)
+ {
+ delete this->ccStartGame_;
+ this->ccStartGame_ = 0;
+ }
+
guiManager_->hideGUI();
}
- void GSGUI::ticked(const Clock& time)
+ void GSGUI::update(const Clock& time)
{
// tick CEGUI
guiManager_->update(time);
+ }
- this->tickChild(time);
+ void GSGUI::startGame()
+ {
+ // HACK - HACK
+ Game::getInstance().popState();
+ Game::getInstance().requestState("standalone");
+ Game::getInstance().requestState("level");
}
}
Modified: branches/gui/src/orxonox/gamestates/GSGUI.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSGUI.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSGUI.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -37,15 +37,20 @@
class _OrxonoxExport GSGUI : public GameState
{
public:
- GSGUI();
+ GSGUI(const std::string& name);
~GSGUI();
+ void activate();
+ void deactivate();
+ void update(const Clock& time);
+
+ void startGame();
+
private:
- void enter();
- void leave();
- void ticked(const Clock& time);
+ GUIManager* guiManager_;
- GUIManager* guiManager_;
+ // console commands
+ ConsoleCommand* ccStartGame_;
};
}
Modified: branches/gui/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSGraphics.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSGraphics.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -44,12 +44,14 @@
#include "overlays/console/InGameConsole.h"
#include "gui/GUIManager.h"
#include "GraphicsManager.h"
-#include "Game.h"
+#include "core/Game.h"
namespace orxonox
{
- GSGraphics::GSGraphics()
- : GameState("graphics")
+ AddGameState(GSGraphics, "graphics");
+
+ GSGraphics::GSGraphics(const std::string& name)
+ : GameState(name)
, inputManager_(0)
, console_(0)
, guiManager_(0)
@@ -59,7 +61,6 @@
, debugOverlay_(0)
{
RegisterRootObject(GSGraphics);
- setConfigValues();
}
GSGraphics::~GSGraphics()
@@ -70,8 +71,10 @@
{
}
- void GSGraphics::enter()
+ void GSGraphics::activate()
{
+ setConfigValues();
+
Core::setShowsGraphics(true);
// initialise graphics manager. Doesn't load the render window yet!
@@ -107,7 +110,7 @@
InputManager::getInstance().requestEnterState("master");
}
- void GSGraphics::leave()
+ void GSGraphics::deactivate()
{
if (Core::showsGraphics())
InputManager::getInstance().requestLeaveState("master");
@@ -145,13 +148,12 @@
as shown that there is probably only one FrameListener that doesn't even
need the time. So we shouldn't run into problems.
*/
- void GSGraphics::ticked(const Clock& time)
+ void GSGraphics::update(const Clock& time)
{
uint64_t timeBeforeTick = time.getRealMicroseconds();
this->inputManager_->update(time); // tick console
this->console_->update(time);
- this->tickChild(time);
uint64_t timeAfterTick = time.getRealMicroseconds();
Modified: branches/gui/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSGraphics.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSGraphics.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -31,31 +31,26 @@
#include "OrxonoxPrereqs.h"
#include "core/GameState.h"
-#include "core/OrxonoxClass.h"
#include "tools/WindowEventListener.h"
namespace orxonox
{
class _OrxonoxExport GSGraphics : public GameState, public WindowEventListener
{
- friend class ClassIdentifier<GSGraphics>;
-
public:
- GSGraphics();
+ GSGraphics(const std::string& name);
~GSGraphics();
-
- private: // functions
- void enter();
- void leave();
- void ticked(const Clock& time);
-
void setConfigValues();
+ void activate();
+ void deactivate();
+ void update(const Clock& time);
+
+ private:
// Window events from WindowEventListener
void windowResized(unsigned int newWidth, unsigned int newHeight);
void windowFocusChanged();
- private:
// managed singletons
InputManager* inputManager_;
InGameConsole* console_;
Modified: branches/gui/src/orxonox/gamestates/GSIOConsole.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSIOConsole.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSIOConsole.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -35,11 +35,14 @@
#include <OgreTimer.h>
#include "core/ConsoleCommand.h"
+#include "core/Game.h"
namespace orxonox
{
- GSIOConsole::GSIOConsole()
- : GameState("ioConsole")
+ AddGameState(GSIOConsole, "ioConsole");
+
+ GSIOConsole::GSIOConsole(const std::string& name)
+ : GameState(name)
{
}
@@ -47,20 +50,18 @@
{
}
- void GSIOConsole::enter()
+ void GSIOConsole::activate()
{
}
- void GSIOConsole::leave()
+ void GSIOConsole::deactivate()
{
}
- void GSIOConsole::ticked(const Clock& time)
+ void GSIOConsole::update(const Clock& time)
{
std::string command;
std::getline(std::cin, command);
CommandExecutor::execute(command, true);
-
- tickChild(time);
}
}
Modified: branches/gui/src/orxonox/gamestates/GSIOConsole.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSIOConsole.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSIOConsole.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -30,7 +30,6 @@
#define _GSIOConsole_H__
#include "OrxonoxPrereqs.h"
-#include <OgrePrerequisites.h>
#include "core/GameState.h"
namespace orxonox
@@ -38,13 +37,15 @@
class _OrxonoxExport GSIOConsole : public GameState
{
public:
- GSIOConsole();
+ GSIOConsole(const std::string& name);
~GSIOConsole();
+ void activate();
+ void deactivate();
+ void update(const Clock& time);
+
private:
- void enter();
- void leave();
- void ticked(const Clock& time);
+
};
}
Modified: branches/gui/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSLevel.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSLevel.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -46,14 +46,17 @@
#include "GraphicsManager.h"
#include "LevelManager.h"
#include "PlayerManager.h"
+#include "core/Game.h"
namespace orxonox
{
+ AddGameState(GSLevel, "level");
+
SetCommandLineArgument(level, "presentation.oxw").shortcut("l");
- GSLevel::GSLevel()
-// : GameState(name)
- : keyBinder_(0)
+ GSLevel::GSLevel(const std::string& name)
+ : GameState(name)
+ , keyBinder_(0)
, inputState_(0)
, radar_(0)
, startFile_(0)
@@ -64,8 +67,6 @@
this->ccKeybind_ = 0;
this->ccTkeybind_ = 0;
-
- setConfigValues();
}
GSLevel::~GSLevel()
@@ -77,8 +78,10 @@
SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
}
- void GSLevel::enter()
+ void GSLevel::activate()
{
+ setConfigValues();
+
if (Core::showsGraphics())
{
inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game");
@@ -125,7 +128,7 @@
}
}
- void GSLevel::leave()
+ void GSLevel::deactivate()
{
// destroy console commands
if (this->ccKeybind_)
@@ -187,9 +190,9 @@
}
}
- void GSLevel::ticked(const Clock& time)
+ void GSLevel::update(const Clock& time)
{
- // Commented by 1337: Temporarily moved to GSGraphics.
+ // Note: Temporarily moved to GSGraphics.
//// Call the scene objects
//for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
// it->tick(time.getDeltaTime() * this->timeFactor_);
@@ -232,7 +235,7 @@
@param command
Command string that can be executed by the CommandExecutor
OR: Internal string "KeybindBindingStringKeyName=" used for the second call to identify
- the key/button/axis that has been activated. This is configured above in enter().
+ the key/button/axis that has been activated. This is configured above in activate().
*/
void GSLevel::keybindInternal(const std::string& command, bool bTemporary)
{
Modified: branches/gui/src/orxonox/gamestates/GSLevel.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSLevel.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSLevel.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -30,26 +30,23 @@
#define _GSLevel_H__
#include "OrxonoxPrereqs.h"
-#include "core/GameState.h"
#include "core/OrxonoxClass.h"
+#include "core/GameState.h"
namespace orxonox
{
- class _OrxonoxExport GSLevel : public OrxonoxClass
+ class _OrxonoxExport GSLevel : public GameState, public OrxonoxClass
{
- friend class ClassIdentifier<GSLevel>;
public:
- GSLevel();
+ GSLevel(const std::string& name);
~GSLevel();
-
- // was private before (is public now because of console command in GSStandalone)
void setConfigValues();
- protected:
- void enter();
- void leave();
- void ticked(const Clock& time);
+ void activate();
+ void deactivate();
+ void update(const Clock& time);
+ protected:
void loadLevel();
void unloadLevel();
Modified: branches/gui/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSRoot.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSRoot.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -31,18 +31,20 @@
#include "util/Exception.h"
#include "util/Debug.h"
+#include "core/Clock.h"
#include "core/Core.h"
-#include "core/CoreIncludes.h"
#include "core/ConsoleCommand.h"
#include "tools/TimeFactorListener.h"
#include "tools/Timer.h"
#include "objects/Tickable.h"
-#include "Game.h"
+#include "core/Game.h"
namespace orxonox
{
- GSRoot::GSRoot()
- : RootGameState("root")
+ AddGameState(GSRoot, "root");
+
+ GSRoot::GSRoot(const std::string& name)
+ : GameState(name)
, timeFactor_(1.0f)
, bPaused_(false)
, timeFactorPauseBackup_(1.0f)
@@ -55,20 +57,12 @@
{
}
- void GSRoot::enter()
+ void GSRoot::activate()
{
// reset game speed to normal
timeFactor_ = 1.0f;
{
- // add console commands
- FunctorMember01<GameState, const std::string&>* functor = createFunctor(&GameState::requestState);
- functor->setObject(this);
- this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState");
- CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_);
- }
-
- {
// time factor console command
FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::setTimeFactor);
functor->setObject(this);
@@ -85,11 +79,8 @@
}
}
- void GSRoot::leave()
+ void GSRoot::deactivate()
{
- // destroy console commands
- delete this->ccSelectGameState_;
-
if (this->ccSetTimeFactor_)
{
delete this->ccSetTimeFactor_;
@@ -103,7 +94,7 @@
}
}
- void GSRoot::ticked(const Clock& time)
+ void GSRoot::update(const Clock& time)
{
uint64_t timeBeforeTick = time.getRealMicroseconds();
@@ -128,8 +119,6 @@
// Also add our tick time to the list in GSRoot
Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
-
- this->tickChild(time);
}
/**
Modified: branches/gui/src/orxonox/gamestates/GSRoot.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSRoot.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSRoot.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -30,23 +30,21 @@
#define _GSRoot_H__
#include "OrxonoxPrereqs.h"
-
-#include <list>
-#include "core/RootGameState.h"
+#include "core/GameState.h"
#include "core/OrxonoxClass.h"
namespace orxonox
{
- class _OrxonoxExport GSRoot : public RootGameState
+ class _OrxonoxExport GSRoot : public GameState
{
- friend class ClassIdentifier<GSRoot>;
-
public:
-
- public:
- GSRoot();
+ GSRoot(const std::string& name);
~GSRoot();
+ void activate();
+ void deactivate();
+ void update(const Clock& time);
+
// this has to be public because proteced triggers a bug in msvc
// when taking the function address.
void setTimeFactor(float factor);
@@ -54,16 +52,11 @@
float getTimeFactor() { return this->timeFactor_; }
private:
- void enter();
- void leave();
- void ticked(const Clock& time);
-
float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal.
bool bPaused_;
float timeFactorPauseBackup_;
// console commands
- ConsoleCommand* ccSelectGameState_;
ConsoleCommand* ccSetTimeFactor_;
ConsoleCommand* ccPause_;
};
Modified: branches/gui/src/orxonox/gamestates/GSServer.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSServer.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSServer.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -32,13 +32,16 @@
#include "core/CommandLine.h"
#include "core/Core.h"
#include "network/Server.h"
+#include "core/Game.h"
namespace orxonox
{
+ AddGameState(GSServer, "server");
+
SetCommandLineArgument(port, 55556).shortcut("p").information("0-65535");
- GSServer::GSServer()
- : GameState("server")
+ GSServer::GSServer(const std::string& name)
+ : GameState(name)
, server_(0)
{
}
@@ -47,32 +50,26 @@
{
}
- void GSServer::enter()
+ void GSServer::activate()
{
Core::setHasServer(true);
this->server_ = new Server(CommandLine::getValue("port"));
COUT(0) << "Loading scene in server mode" << std::endl;
- GSLevel::enter();
-
server_->open();
}
- void GSServer::leave()
+ void GSServer::deactivate()
{
- GSLevel::leave();
-
this->server_->close();
delete this->server_;
Core::setHasServer(false);
}
- void GSServer::ticked(const Clock& time)
+ void GSServer::update(const Clock& time)
{
- GSLevel::ticked(time);
server_->update(time);
- this->tickChild(time);
}
}
Modified: branches/gui/src/orxonox/gamestates/GSServer.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSServer.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSServer.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -32,22 +32,21 @@
#include "OrxonoxPrereqs.h"
#include "core/GameState.h"
#include "network/NetworkPrereqs.h"
-#include "GSLevel.h"
namespace orxonox
{
- class _OrxonoxExport GSServer : public GameState, public GSLevel
+ class _OrxonoxExport GSServer : public GameState
{
public:
- GSServer();
+ GSServer(const std::string& name);
~GSServer();
- private:
- void enter();
- void leave();
- void ticked(const Clock& time);
+ void activate();
+ void deactivate();
+ void update(const Clock& time);
- Server* server_;
+ private:
+ Server* server_;
};
}
Modified: branches/gui/src/orxonox/gamestates/GSStandalone.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSStandalone.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSStandalone.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -35,11 +35,14 @@
#include "core/ConsoleCommand.h"
#include "gui/GUIManager.h"
#include "GraphicsManager.h"
+#include "core/Game.h"
namespace orxonox
{
- GSStandalone::GSStandalone()
- : GameState("standalone")
+ AddGameState(GSStandalone, "standalone");
+
+ GSStandalone::GSStandalone(const std::string& name)
+ : GameState(name)
{
}
@@ -48,25 +51,21 @@
}
- void GSStandalone::enter()
+ void GSStandalone::activate()
{
Core::setIsStandalone(true);
- GSLevel::enter();
-
guiManager_ = GUIManager::getInstancePtr();
// not sure if necessary
// guiManager_->loadScene("IngameMenu");
}
- void GSStandalone::leave()
+ void GSStandalone::deactivate()
{
- GSLevel::leave();
-
Core::setIsStandalone(false);
}
- void GSStandalone::ticked(const Clock& time)
+ void GSStandalone::update(const Clock& time)
{
//Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();
//COUT(0) << "** " << viewport->getCamera()->getSceneManager() << std::endl;
@@ -76,8 +75,5 @@
// tick CEGUI
guiManager_->update(time);
-
- GSLevel::ticked(time);
- this->tickChild(time);
}
}
Modified: branches/gui/src/orxonox/gamestates/GSStandalone.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSStandalone.h 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/gamestates/GSStandalone.h 2009-03-25 16:23:00 UTC (rev 2844)
@@ -31,22 +31,21 @@
#include "OrxonoxPrereqs.h"
#include "core/GameState.h"
-#include "GSLevel.h"
namespace orxonox
{
- class _OrxonoxExport GSStandalone : public GameState, public GSLevel
+ class _OrxonoxExport GSStandalone : public GameState
{
public:
- GSStandalone();
+ GSStandalone(const std::string& name);
~GSStandalone();
- private:
- void enter();
- void leave();
- void ticked(const Clock& time);
+ void activate();
+ void deactivate();
+ void update(const Clock& time);
- GUIManager* guiManager_;
+ private:
+ GUIManager* guiManager_;
};
}
Modified: branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc
===================================================================
--- branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -31,7 +31,7 @@
#include <OgreTextAreaOverlayElement.h>
#include "util/Convert.h"
#include "core/CoreIncludes.h"
-#include "Game.h"
+#include "core/Game.h"
namespace orxonox
{
Modified: branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc
===================================================================
--- branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc 2009-03-25 15:34:40 UTC (rev 2843)
+++ branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc 2009-03-25 16:23:00 UTC (rev 2844)
@@ -31,7 +31,7 @@
#include <OgreTextAreaOverlayElement.h>
#include "core/CoreIncludes.h"
#include "util/Convert.h"
-#include "Game.h"
+#include "core/Game.h"
namespace orxonox
{
More information about the Orxonox-commit
mailing list