[Orxonox-commit 1122] r5843 - in code/branches/core5/src: libraries/core orxonox
rgrieder at orxonox.net
rgrieder at orxonox.net
Wed Sep 30 20:42:45 CEST 2009
Author: rgrieder
Date: 2009-09-30 20:42:45 +0200 (Wed, 30 Sep 2009)
New Revision: 5843
Modified:
code/branches/core5/src/libraries/core/Game.cc
code/branches/core5/src/libraries/core/Game.h
code/branches/core5/src/orxonox/Main.cc
Log:
Added comma operator in the GameState hierarchy parser: Use "standalone,client,server" and the whole underlaying tree will be used for all three states. See Main.cc
Modified: code/branches/core5/src/libraries/core/Game.cc
===================================================================
--- code/branches/core5/src/libraries/core/Game.cc 2009-09-30 16:13:09 UTC (rev 5842)
+++ code/branches/core5/src/libraries/core/Game.cc 2009-09-30 18:42:45 UTC (rev 5843)
@@ -456,12 +456,12 @@
void Game::setStateHierarchy(const std::string& str)
{
// Split string into pieces of the form whitespacesText
- std::vector<std::pair<std::string, unsigned> > stateStrings;
+ std::vector<std::pair<std::string, int> > stateStrings;
size_t pos = 0;
size_t startPos = 0;
while (pos < str.size())
{
- unsigned indentation = 0;
+ int indentation = 0;
while(pos < str.size() && str[pos] == ' ')
++indentation, ++pos;
startPos = pos;
@@ -469,40 +469,48 @@
++pos;
stateStrings.push_back(std::make_pair(str.substr(startPos, pos - startPos), indentation));
}
- unsigned int currentLevel = 0;
- shared_ptr<GameStateTreeNode> currentNode = this->rootStateNode_;
- for (std::vector<std::pair<std::string, unsigned> >::const_iterator it = stateStrings.begin(); it != stateStrings.end(); ++it)
+ if (stateStrings.empty())
+ ThrowException(GameState, "Emtpy GameState hierarchy provided, terminating.");
+ // Add element with large identation to detect the last with just an iterator
+ stateStrings.push_back(std::make_pair("", -1));
+
+ // Parse elements recursively
+ parseStates(stateStrings.begin(), this->rootStateNode_);
+ }
+
+ /*** Internal ***/
+
+ void Game::parseStates(std::vector<std::pair<std::string, int> >::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode)
+ {
+ SubString tokens(it->first, ",");
+ std::vector<std::pair<std::string, int> >::const_iterator startIt = it;
+
+ for (unsigned int i = 0; i < tokens.size(); ++i)
{
- std::string newStateName = it->first;
- unsigned newLevel = it->second + 1; // empty root is 0
- if (!this->checkState(newStateName))
- ThrowException(GameState, "GameState with name '" << newStateName << "' not found!");
- if (newStateName == this->rootStateNode_->name_)
+ it = startIt; // Reset iterator to the beginning of the sub tree
+ if (!this->checkState(tokens[i]))
+ ThrowException(GameState, "GameState with name '" << tokens[i] << "' not found!");
+ if (tokens[i] == this->rootStateNode_->name_)
ThrowException(GameState, "You shouldn't use 'emptyRootGameState' in the hierarchy...");
- shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode);
- newNode->name_ = newStateName;
+ shared_ptr<GameStateTreeNode> node(new GameStateTreeNode());
+ node->name_ = tokens[i];
+ node->parent_ = currentNode;
+ currentNode->children_.push_back(node);
- if (newLevel <= currentLevel)
+ int currentLevel = it->second;
+ ++it;
+ while (it->second != -1)
{
- do
- currentNode = currentNode->parent_.lock();
- while (newLevel <= --currentLevel);
+ if (it->second <= currentLevel)
+ break;
+ else if (it->second == currentLevel + 1)
+ parseStates(it, node);
+ else
+ ThrowException(GameState, "Indentation error while parsing the hierarchy.");
}
- if (newLevel == currentLevel + 1)
- {
- // Add the child
- newNode->parent_ = currentNode;
- currentNode->children_.push_back(newNode);
- }
- else
- ThrowException(GameState, "Indentation error while parsing the hierarchy.");
- currentNode = newNode;
- currentLevel = newLevel;
}
}
- /*** Internal ***/
-
void Game::loadGraphics()
{
if (!GameMode::bShowsGraphics_s)
Modified: code/branches/core5/src/libraries/core/Game.h
===================================================================
--- code/branches/core5/src/libraries/core/Game.h 2009-09-30 16:13:09 UTC (rev 5842)
+++ code/branches/core5/src/libraries/core/Game.h 2009-09-30 18:42:45 UTC (rev 5843)
@@ -142,6 +142,7 @@
void loadGraphics();
void unloadGraphics();
+ void parseStates(std::vector<std::pair<std::string, int> >::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode);
bool checkState(const std::string& name) const;
void loadState(const std::string& name);
void unloadState(const std::string& name);
Modified: code/branches/core5/src/orxonox/Main.cc
===================================================================
--- code/branches/core5/src/orxonox/Main.cc 2009-09-30 16:13:09 UTC (rev 5842)
+++ code/branches/core5/src/orxonox/Main.cc 2009-09-30 18:42:45 UTC (rev 5843)
@@ -30,13 +30,11 @@
/**
@file
@brief
- The main function of Orxonox.
+ The main function of Orxonox (but not the entry point of the program!)
*/
#include "OrxonoxPrereqs.h"
-#include "SpecialConfig.h"
-#include "util/Exception.h"
#include "core/CommandLine.h"
#include "core/Game.h"
#include "core/LuaState.h"
@@ -56,7 +54,7 @@
{
/**
@brief
- Main method. Game starts here (except for static initialisations).
+ Starting point of orxonox (however not the entry point of the program!)
*/
int main(const std::string& strCmdLine)
{
@@ -66,12 +64,8 @@
"root"
" graphics"
" mainMenu"
- " standalone"
+ " standalone,server,client"
" level"
- " server"
- " level"
- " client"
- " level"
" dedicated"
" level"
" ioConsole"
More information about the Orxonox-commit
mailing list