[Orxonox-commit 2719] r7424 - in sandbox_qt: doc/api src/libraries/core src/orxonox
rgrieder at orxonox.net
rgrieder at orxonox.net
Sun Sep 12 14:48:11 CEST 2010
Author: rgrieder
Date: 2010-09-12 14:48:11 +0200 (Sun, 12 Sep 2010)
New Revision: 7424
Added:
sandbox_qt/src/libraries/core/CommandLineParser.cc
sandbox_qt/src/libraries/core/CommandLineParser.h
Removed:
sandbox_qt/src/libraries/core/Game.cc
sandbox_qt/src/libraries/core/Game.h
Modified:
sandbox_qt/doc/api/CMakeLists.txt
sandbox_qt/src/libraries/core/CMakeLists.txt
sandbox_qt/src/libraries/core/Core.cc
sandbox_qt/src/libraries/core/Core.h
sandbox_qt/src/orxonox/Main.cc
Log:
Added CommandlineParser again and adjusted it to work with QVariant instead of MultiType.
Also removed obsolete Game class.
Modified: sandbox_qt/doc/api/CMakeLists.txt
===================================================================
--- sandbox_qt/doc/api/CMakeLists.txt 2010-09-12 11:39:02 UTC (rev 7423)
+++ sandbox_qt/doc/api/CMakeLists.txt 2010-09-12 12:48:11 UTC (rev 7424)
@@ -54,7 +54,7 @@
ADD_CUSTOM_COMMAND(
OUTPUT ${INTERNAL_DOCFILE}
COMMAND orxonox-main
- ARGS --noIOConsole --generateDoc ${INTERNAL_DOCFILE}
+ ARGS --generateDoc ${INTERNAL_DOCFILE}
WORKING_DIRECTORY ${_working_dir}
COMMENT "Generating additional Doxygen documentation from Orxonox executable"
)
Modified: sandbox_qt/src/libraries/core/CMakeLists.txt
===================================================================
--- sandbox_qt/src/libraries/core/CMakeLists.txt 2010-09-12 11:39:02 UTC (rev 7423)
+++ sandbox_qt/src/libraries/core/CMakeLists.txt 2010-09-12 12:48:11 UTC (rev 7424)
@@ -18,8 +18,8 @@
#
SET_SOURCE_FILES(CORE_SRC_FILES
+ CommandlineParser.cc
Core.cc
- Game.cc
PathConfig.cc
)
Copied: sandbox_qt/src/libraries/core/CommandLineParser.cc (from rev 7418, sandbox_qt/src/libraries/core/CommandLineParser.cc)
===================================================================
--- sandbox_qt/src/libraries/core/CommandLineParser.cc (rev 0)
+++ sandbox_qt/src/libraries/core/CommandLineParser.cc 2010-09-12 12:48:11 UTC (rev 7424)
@@ -0,0 +1,382 @@
+/*
+ * 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 "CommandLineParser.h"
+
+#include <algorithm>
+#include <sstream>
+
+//#include "util/Convert.h"
+#include "util/Debug.h"
+#include "util/Exception.h"
+#include "util/StringUtils.h"
+#include "util/SubString.h"
+#include "PathConfig.h"
+
+namespace orxonox
+{
+ SetCommandLineOnlyArgument(optionsFile, "start.ini").shortcut("o");
+
+ /**
+ @brief
+ Parses a value string for a command line argument.
+ It simply uses convertValue(Output, Input) to do that.
+ Bools are treated specially. That is necessary
+ so that you can have simple command line switches.
+ */
+ void CommandLineArgument::parse(const std::string& value, bool bParsingFile)
+ {
+ if (bParsingFile && this->bCommandLineOnly_)
+ ThrowException(Argument, "Command line argument '" + getName() + "' is not allowed in files.");
+ if (value_.type() == QVariant::Bool)
+ {
+ // Command line switch activated
+ this->bHasDefaultValue_ = false;
+ this->value_ = true;
+ }
+ else
+ {
+ QVariant temp(QString::fromStdString(value));
+ if (!temp.convert(value_.type()))
+ ThrowException(Argument, "Could not read command line argument '" + getName() + "'.");
+ else
+ {
+ this->bHasDefaultValue_ = false;
+ this->value_ = temp;
+ }
+ }
+ }
+
+
+ /**
+ @brief
+ Destructor destroys all CommandLineArguments with it.
+ */
+ CommandLineParser::~CommandLineParser()
+ {
+ CommandLineParser::destroyAllArguments();
+ }
+
+ /**
+ @brief
+ Returns a unique instance (Meyers Singleton).
+ */
+ CommandLineParser& CommandLineParser::_getInstance()
+ {
+ static CommandLineParser instance;
+ return instance;
+ }
+
+ /**
+ @brief
+ Destroys all command line arguments. This should be called at the end
+ of main. Do not use before that.
+ */
+ void CommandLineParser::destroyAllArguments()
+ {
+ for (std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.begin();
+ it != _getInstance().cmdLineArgs_.end(); ++it)
+ delete it->second;
+ _getInstance().cmdLineArgs_.clear();
+ }
+
+ /**
+ @brief
+ Reads the command line parses the values of each argument.
+ It is then stored in the corresponding CommandLineArgument.
+ @note
+ The reason that you have to provide the string to be parsed as
+ space separted list is because of argc and argv. If you only have
+ a whole string, simply use getAllStrings() of SubString.
+ @param arguments
+ Vector of space separated strings.
+ @param bParsingFile
+ Parsing a file or the command line itself
+ */
+ void CommandLineParser::_parse(const std::vector<std::string>& arguments, bool bParsingFile)
+ {
+ try
+ {
+ // why this? See bFirstTimeParse_ declaration.
+ if (bFirstTimeParse_)
+ {
+ // first shove all the shortcuts in a map
+ for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin();
+ it != cmdLineArgs_.end(); ++it)
+ {
+ OrxAssert(cmdLineArgsShortcut_.find(it->second->getShortcut()) == cmdLineArgsShortcut_.end(),
+ "Cannot have two command line shortcut with the same name.");
+ if (!it->second->getShortcut().empty())
+ cmdLineArgsShortcut_[it->second->getShortcut()] = it->second;
+ }
+ bFirstTimeParse_ = false;
+ }
+
+ std::string name;
+ std::string shortcut;
+ std::string value;
+ for (unsigned int i = 0; i < arguments.size(); ++i)
+ {
+ if (arguments[i].size() != 0)
+ {
+ // sure not ""
+ if (arguments[i][0] == '-')
+ {
+ // start with "-"
+ if (arguments[i].size() == 1)
+ {
+ // argument[i] is "-", probably a minus sign
+ value += "- ";
+ }
+ else if (arguments[i][1] <= 57 && arguments[i][1] >= 48)
+ {
+ // negative number as a value
+ value += arguments[i] + ' ';
+ }
+ else
+ {
+ // can be shortcut or full name argument
+
+ // save old data first
+ value = removeTrailingWhitespaces(value);
+ if (!name.empty())
+ {
+ checkFullArgument(name, value, bParsingFile);
+ name.clear();
+ assert(shortcut.empty());
+ }
+ else if (!shortcut.empty())
+ {
+ checkShortcut(shortcut, value, bParsingFile);
+ shortcut.clear();
+ assert(name.empty());
+ }
+
+ if (arguments[i][1] == '-')
+ {
+ // full name argument with "--name"
+ name = arguments[i].substr(2);
+ }
+ else
+ {
+ // shortcut with "-s"
+ shortcut = arguments[i].substr(1);
+ }
+
+ // reset value string
+ value.clear();
+ }
+ }
+ else
+ {
+ // value string
+
+ if (name.empty() && shortcut.empty())
+ {
+ ThrowException(Argument, "Expected \"-\" or \"-\" in command line arguments.\n");
+ }
+
+ // Concatenate strings as long as there's no new argument by "-" or "--"
+ value += arguments[i] + ' ';
+ }
+ }
+ }
+
+ // parse last argument
+ value = removeTrailingWhitespaces(value);
+ if (!name.empty())
+ {
+ checkFullArgument(name, value, bParsingFile);
+ assert(shortcut.empty());
+ }
+ else if (!shortcut.empty())
+ {
+ checkShortcut(shortcut, value, bParsingFile);
+ assert(name.empty());
+ }
+ }
+ catch (const ArgumentException& ex)
+ {
+ COUT(0) << "Could not parse command line (including additional files): " << ex.what() << std::endl;
+ COUT(0) << CommandLineParser::getUsageInformation() << std::endl;
+ throw GeneralException("");
+ }
+ }
+
+ /**
+ @brief
+ Parses an argument based on its full name.
+ @param name
+ Full name of the argument
+ @param value
+ String containing the value
+ @param bParsingFile
+ Parsing a file or the command line itself
+ */
+ void CommandLineParser::checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile)
+ {
+ std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.find(name);
+ if (it == cmdLineArgs_.end())
+ ThrowException(Argument, "Command line argument '" + name + "' does not exist.");
+
+ it->second->parse(value, bParsingFile);
+ }
+
+ /**
+ @brief
+ Parses an argument based on its shortcut.
+ @param shortcut
+ Shortcut to the argument
+ @param value
+ String containing the value
+ @param bParsingFile
+ Parsing a file or the command line itself
+ */
+ void CommandLineParser::checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile)
+ {
+ std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgsShortcut_.find(shortcut);
+ if (it == cmdLineArgsShortcut_.end())
+ ThrowException(Argument, "Command line shortcut '" + shortcut + "' does not exist.");
+
+ it->second->parse(value, bParsingFile);
+ }
+
+ std::string CommandLineParser::getUsageInformation()
+ {
+ CommandLineParser& inst = _getInstance();
+ std::ostringstream infoStr;
+
+ // determine maximum name size
+ size_t maxNameSize = 0;
+ for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst.cmdLineArgs_.begin();
+ it != inst.cmdLineArgs_.end(); ++it)
+ {
+ maxNameSize = std::max(it->second->getName().size(), maxNameSize);
+ }
+
+ infoStr << std::endl;
+ infoStr << "Usage: orxonox [options]" << std::endl;
+ infoStr << "Available options:" << std::endl;
+
+ for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst.cmdLineArgs_.begin();
+ it != inst.cmdLineArgs_.end(); ++it)
+ {
+ if (!it->second->getShortcut().empty())
+ infoStr << " [-" << it->second->getShortcut() << "] ";
+ else
+ infoStr << " ";
+ infoStr << "--" << it->second->getName() << ' ';
+ if (it->second->getValue().type() != QVariant::Bool)
+ infoStr << "ARG ";
+ else
+ infoStr << " ";
+ // fill with the necessary amount of blanks
+ infoStr << std::string(maxNameSize - it->second->getName().size(), ' ');
+ infoStr << ": " << it->second->getInformation();
+ infoStr << std::endl;
+ }
+ return infoStr.str();
+ }
+
+ void CommandLineParser::generateDoc(std::ofstream& file)
+ {
+ file << "/** @page cmdargspage Command Line Arguments Reference" << endl;
+ file << " @verbatim"; /*no endl*/
+ file << getUsageInformation(); /*no endl*/
+ file << " @endverbatim" << endl;
+ file << "*/" << endl;
+ }
+
+ /**
+ @brief
+ Retrieves a CommandLineArgument.
+ The method throws an exception if 'name' was not found or the value could not be converted.
+ @note
+ You should of course not call this method before the command line has been parsed.
+ */
+ const CommandLineArgument* CommandLineParser::getArgument(const std::string& name)
+ {
+ std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name);
+ if (it == _getInstance().cmdLineArgs_.end())
+ {
+ ThrowException(Argument, "Could find command line argument '" + name + "'.");
+ }
+ else
+ {
+ return it->second;
+ }
+ }
+
+ /**
+ @brief
+ Parses only the command line for CommandLineArguments.
+ */
+ void CommandLineParser::_parseCommandLine(const std::string& cmdLine)
+ {
+ std::vector<std::string> args;
+ SubString tokens(cmdLine, " ", " ", false, '\\', true, '"', true, '\0', '\0', false);
+ for (unsigned i = 0; i < tokens.size(); ++i)
+ args.push_back(tokens[i]);
+ this->_parse(args, false);
+ }
+
+ /**
+ @brief
+ Parses start.ini (or the file specified with --optionsFile) for CommandLineArguments.
+ */
+ void CommandLineParser::_parseFile()
+ {
+ const std::string& filename = CommandLineParser::getValue("optionsFile").toString().toStdString();
+
+ // look for additional arguments in given file or start.ini as default
+ // They will not overwrite the arguments given directly
+ std::ifstream file;
+ file.open((PathConfig::getConfigPathString() + filename).c_str());
+ std::vector<std::string> args;
+ if (file)
+ {
+ while (!file.eof())
+ {
+ std::string line;
+ std::getline(file, line);
+ line = removeTrailingWhitespaces(line);
+ //if (!(line[0] == '#' || line[0] == '%'))
+ //{
+ SubString tokens(line, " ", " ", false, '\\', true, '"', true, '\0', '\0', false, '#');
+ for (unsigned i = 0; i < tokens.size(); ++i)
+ if (tokens[i][0] != '#')
+ args.push_back(tokens[i]);
+ //args.insert(args.end(), tokens.getAllStrings().begin(), tokens.getAllStrings().end());
+ //}
+ }
+ file.close();
+ }
+
+ _parse(args, true);
+ }
+}
Copied: sandbox_qt/src/libraries/core/CommandLineParser.h (from rev 7418, sandbox_qt/src/libraries/core/CommandLineParser.h)
===================================================================
--- sandbox_qt/src/libraries/core/CommandLineParser.h (rev 0)
+++ sandbox_qt/src/libraries/core/CommandLineParser.h 2010-09-12 12:48:11 UTC (rev 7424)
@@ -0,0 +1,240 @@
+/*
+ * 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:
+ * ...
+ *
+ */
+
+/**
+ @defgroup CmdArgs Commandline arguments
+ @ingroup Config
+ @brief For a reference of all commandline arguments see @ref cmdargspage
+*/
+
+/**
+ @file
+ @ingroup Config CmdArgs
+ @brief Declaration of CommandLineParser and CommandLineArgument, definition of the SetCommandLineArgument() macros.
+*/
+
+#ifndef _CommandLine_H__
+#define _CommandLine_H__
+
+#include "CorePrereqs.h"
+
+#include <fstream>
+#include <map>
+#include <QVariant>
+#include "util/OrxAssert.h"
+
+#define SetCommandLineArgument(name, defaultValue) \
+ orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
+ = orxonox::CommandLineParser::addArgument(#name, defaultValue, false)
+#define SetCommandLineOnlyArgument(name, defaultValue) \
+ orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
+ = orxonox::CommandLineParser::addArgument(#name, defaultValue, true)
+#define SetCommandLineSwitch(name) \
+ orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
+ = orxonox::CommandLineParser::addArgument(#name, false, false)
+#define SetCommandLineOnlySwitch(name) \
+ orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
+ = orxonox::CommandLineParser::addArgument(#name, false, true)
+
+
+namespace orxonox
+{
+ /**
+ @brief
+ Container class for a command line argument of any type supported by QVariant.
+
+ Whenever you want to have an option specified by a command line switch,
+ you need to first define it with SetCommandLineArgument(name, defaultValue).
+ It is then added to a map and possibly changed when the command line is being parsed.
+ If the option was not given, you can detect this by asking hasDefaultValue().
+
+ There is a possibility to define a short cut so you can write "-p 20" instead of "--port 20".
+ Note the difference between "-" and "--"!
+ Also, there is no restriction to the number of strings you add after --name.
+ So "--startVector {2, 4, 5}" is perfectly legal.
+
+ Retrieving an argument is possible with the getCommandLineArgument function of the
+ CommandLineParser class. It is a Singleton, but the public interface is static.
+ */
+ class _CoreExport CommandLineArgument
+ {
+ friend class CommandLineParser;
+
+ public:
+ //! Tells whether the value has been changed by the command line.
+ bool hasDefaultValue() const { return bHasDefaultValue_; }
+ //! Returns the name of the argument.
+ const std::string& getName() const { return name_; }
+
+ //! Returns the shortcut (example: "-p 22" for "--port 22") of the argument.
+ //! Evaluates to "" if there is none.
+ const std::string& getShortcut() const { return shortcut_; }
+ //! Sets the shortcut for the argument
+ CommandLineArgument& shortcut(const std::string& shortcut)
+ { this->shortcut_ = shortcut; return *this; }
+
+ //! Returns the usage information
+ const std::string& getInformation() const { return this->usageInformation_; }
+ //! Sets the option information when displaying orxonox usage.
+ CommandLineArgument& information(const std::string& usage)
+ { this->usageInformation_ = usage; return *this; }
+
+ //! Returns the actual value of the argument. Can be equal to default value.
+ QVariant getValue() const { return value_; }
+ //! Returns the given default value as type T.
+ QVariant getDefaultValue() const { return defaultValue_; }
+
+ private:
+ //! Constructor initialises both value_ and defaultValue_ with defaultValue.
+ CommandLineArgument(const std::string& name, const QVariant& defaultValue, bool bCommandLineOnly)
+ : bHasDefaultValue_(true)
+ , name_(name)
+ , value_(defaultValue)
+ , defaultValue_(defaultValue)
+ , bCommandLineOnly_(bCommandLineOnly)
+ { }
+
+ //! Undefined copy constructor
+ CommandLineArgument(const CommandLineArgument& instance);
+ ~CommandLineArgument() { }
+
+ //! Parses the value string of a command line argument.
+ void parse(const std::string& value, bool bParsingFile);
+
+ //! Tells whether the value has been changed by the command line.
+ bool bHasDefaultValue_;
+
+ private:
+ std::string name_; //!< Name of the argument
+ std::string shortcut_; //!< Shortcut of the argument. @see getShortcut().
+ std::string usageInformation_; //!< Tells about the usage of this parameter
+
+ QVariant value_; //!< The actual value
+ QVariant defaultValue_; //!< Default value. Should not be changed.
+ bool bCommandLineOnly_; //!< Whether you cannot specify the value in a text file
+ };
+
+
+ /**
+ @brief
+ Global interface to command line options.
+ Allows to add and retrieve command line arguments. Also does the parsing.
+ @note
+ Internally it is a Singleton, but the public interface is static.
+ @see
+ CommandLineArgument
+ */
+ class _CoreExport CommandLineParser
+ {
+ public:
+
+ //! Parse redirection to internal member method.
+ static void parseCommandLine(const std::string& cmdLine) { _getInstance()._parseCommandLine(cmdLine); }
+ static void parseFile() { _getInstance()._parseFile(); }
+
+ static std::string getUsageInformation();
+
+ static const CommandLineArgument* getArgument(const std::string& name);
+ //! Writes the argument value in the given parameter.
+ template <class T>
+ static void getValue(const std::string& name, T* value)
+ { *value = (T)(getArgument(name)->getValue()); }
+ static QVariant getValue(const std::string& name)
+ { return getArgument(name)->getValue(); }
+ template <class T>
+ static CommandLineArgument& addArgument(const std::string& name, T defaultValue, bool bCommandLineOnly);
+
+ static bool existsArgument(const std::string& name)
+ {
+ std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name);
+ return !(it == _getInstance().cmdLineArgs_.end());
+ }
+
+ static void destroyAllArguments();
+
+ static void generateDoc(std::ofstream& file);
+
+ private:
+ //! Constructor initialises bFirstTimeParse_ with true.
+ CommandLineParser() : bFirstTimeParse_(true) { }
+ //! Undefined copy constructor
+ CommandLineParser(const CommandLineParser& instance);
+ ~CommandLineParser();
+
+ static CommandLineParser& _getInstance();
+
+ void _parseCommandLine(const std::string& cmdLine);
+ void _parseFile();
+ void _parse(const std::vector<std::string>& arguments, bool bParsingFile);
+ void checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile);
+ void checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile);
+
+ /**
+ Tells whether we parsed for the first time. The CommmandLineArguments are added before main().
+ So when we call parse() the first time, we need to create a map with all shortcuts since these
+ get added after addCommandLineArgument().
+ */
+ bool bFirstTimeParse_;
+
+ //! Holds all pointers to the arguments and serves as a search map by name.
+ std::map<std::string, CommandLineArgument*> cmdLineArgs_;
+ //! Search map by shortcut for the arguments.
+ std::map<std::string, CommandLineArgument*> cmdLineArgsShortcut_;
+ };
+
+ template <>
+ inline void CommandLineParser::getValue<std::string>(const std::string& name, std::string* value)
+ {
+ *value = getArgument(name)->getValue().toString().toStdString();
+ }
+
+ /**
+ @brief
+ Adds a new CommandLineArgument to the internal map.
+ Note that only such arguments are actually valid.
+ @param name
+ Name of the argument. Shortcut can be added later.
+ @param defaultValue
+ Default value that is used when argument was not given.
+ @param bCommandLineOnly
+ Parsing a file or the command line itself
+ */
+ template <class T>
+ CommandLineArgument& CommandLineParser::addArgument(const std::string& name, T defaultValue, bool bCommandLineOnly)
+ {
+ OrxAssert(!_getInstance().existsArgument(name),
+ "Cannot add a command line argument with name '" + name + "' twice.");
+ OrxAssert(QVariant(defaultValue).type() != QVariant::Bool || QVariant(defaultValue).toBool() != true,
+ "Boolean command line arguments with positive default values are not supported." << std::endl
+ << "Please use SetCommandLineSwitch and adjust your argument: " << name);
+
+ return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue, bCommandLineOnly));
+ }
+}
+
+#endif /* _CommandLine_H__ */
Modified: sandbox_qt/src/libraries/core/Core.cc
===================================================================
--- sandbox_qt/src/libraries/core/Core.cc 2010-09-12 11:39:02 UTC (rev 7423)
+++ sandbox_qt/src/libraries/core/Core.cc 2010-09-12 12:48:11 UTC (rev 7424)
@@ -52,39 +52,51 @@
#include "util/Debug.h"
#include "util/Exception.h"
#include "PathConfig.h"
+#include "CommandLineParser.h"
namespace orxonox
{
//! Static pointer to the singleton
Core* Core::singletonPtr_s = 0;
+ SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+ SetCommandLineArgument(limitToCPU, 1).information("Limits the program to one CPU/core (1, 2, 3, etc.). Default is the first core (faster than off)");
+#endif
+
Core::Core(const std::string& cmdLine)
{
// Set the hard coded fixed paths
this->pathConfig_.reset(new PathConfig());
+ // Parse command line arguments
+ CommandLineParser::parseCommandLine(cmdLine);
+
// Set configurable paths like log, config and media
this->pathConfig_->setConfigurablePaths();
// Set the correct log path. Before this call, /tmp (Unix) or %TEMP% (Windows) was used
OutputHandler::getInstance().setLogPath(PathConfig::getLogPathString());
+ // Parse additional options file now that we know its path
+ CommandLineParser::parseFile();
+
#ifdef ORXONOX_PLATFORM_WINDOWS
// limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
- int limitToCPU = 0;//CommandLineParser::getValue("limitToCPU");
+ int limitToCPU = CommandLineParser::getValue("limitToCPU").toInt();
if (limitToCPU > 0)
setThreadAffinity(static_cast<unsigned int>(limitToCPU));
#endif
// Generate documentation instead of normal run?
- std::string docFilename;
- //CommandLineParser::getValue("generateDoc", &docFilename);
+ std::string docFilename = CommandLineParser::getValue("generateDoc").toString().toStdString();
if (!docFilename.empty())
{
std::ofstream docFile(docFilename.c_str());
if (docFile.is_open())
{
- //CommandLineParser::generateDoc(docFile);
+ CommandLineParser::generateDoc(docFile);
docFile.close();
}
else
Modified: sandbox_qt/src/libraries/core/Core.h
===================================================================
--- sandbox_qt/src/libraries/core/Core.h 2010-09-12 11:39:02 UTC (rev 7423)
+++ sandbox_qt/src/libraries/core/Core.h 2010-09-12 12:48:11 UTC (rev 7424)
@@ -82,8 +82,6 @@
void initRandomNumberGenerator();
- void update() {}
-
void setThreadAffinity(int limitToCPU);
// MANAGED SINGLETONS/OBJECTS
// Mind the order for the destruction!
Deleted: sandbox_qt/src/libraries/core/Game.cc
===================================================================
--- sandbox_qt/src/libraries/core/Game.cc 2010-09-12 11:39:02 UTC (rev 7423)
+++ sandbox_qt/src/libraries/core/Game.cc 2010-09-12 12:48:11 UTC (rev 7424)
@@ -1,100 +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 "Game.h"
-
-#include <exception>
-
-#include "util/Debug.h"
-#include "util/Exception.h"
-#include "util/Sleep.h"
-#include "Core.h"
-
-namespace orxonox
-{
- Game* Game::singletonPtr_s = 0;
-
- Game::Game(const std::string& cmdLine)
- {
- this->bAbort_ = false;
-
- // Create the Core
- this->core_.reset(new Core(cmdLine));
- }
-
- /**
- @brief
- All destruction code is handled by QScopedPointers.
- */
- Game::~Game()
- {
- }
-
- 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.");
- SetConfigValue(fpsLimit_, 50)
- .description("Sets the desired frame rate (0 for no limit).");
- */
- }
-
- /**
- @brief
- Main loop of the orxonox game.
- */
- void Game::run()
- {
- while (!this->bAbort_)
- {
- try
- { this->core_->update(); }
- catch (...)
- {
- COUT(0) << "An exception occurred in the Core postUpdate: " << Exception::handleMessage() << std::endl;
- COUT(0) << "This should really never happen! Closing the program." << std::endl;
- this->stop();
- break;
- }
- }
- }
-
- void Game::stop()
- {
- this->bAbort_ = true;
- }
-}
Deleted: sandbox_qt/src/libraries/core/Game.h
===================================================================
--- sandbox_qt/src/libraries/core/Game.h 2010-09-12 11:39:02 UTC (rev 7423)
+++ sandbox_qt/src/libraries/core/Game.h 2010-09-12 12:48:11 UTC (rev 7424)
@@ -1,76 +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 ingroup Management CoreGame
- at brief
- Declaration of Game Singleton which is responsible for running the game.
- */
-
-#ifndef _Game_H__
-#define _Game_H__
-
-#include "CorePrereqs.h"
-
-#include <string>
-#include <QScopedPointer>
-#include "util/Singleton.h"
-
-namespace orxonox
-{
- /**
- @brief
- Main class responsible for running the game.
- @remark
- You should only create this singleton once because it owns the Core class! (see remark there)
- */
- class _CoreExport Game : public Singleton<Game>
- {
- friend class Singleton<Game>;
-
- public:
- Game(const std::string& cmdLine);
- ~Game();
-
- void setConfigValues();
-
- void run();
- void stop();
-
- private:
- Game(Game&); // don't mess with singletons
-
- QScopedPointer<Core> core_;
- bool bAbort_;
-
- static Game* singletonPtr_s; //!< Pointer to the Singleton
- };
-}
-
-#endif /* _Game_H__ */
Modified: sandbox_qt/src/orxonox/Main.cc
===================================================================
--- sandbox_qt/src/orxonox/Main.cc 2010-09-12 11:39:02 UTC (rev 7423)
+++ sandbox_qt/src/orxonox/Main.cc 2010-09-12 12:48:11 UTC (rev 7424)
@@ -38,11 +38,16 @@
#include <QApplication>
#include <QCoreApplication>
-#include "core/Game.h"
+#include "util/Debug.h"
+#include "core/CommandlineParser.h"
+#include "core/Core.h"
#include "Main.h"
namespace orxonox
{
+ SetCommandLineArgument(generateDoc, "")
+ .information("Generates a Doxygen file from things like SetConsoleCommand");
+
/**
@brief
Starting point of orxonox (however not the entry point of the program!)
@@ -51,13 +56,18 @@
{
QApplication app(argc, argv);
+ QStringList arguments = QCoreApplication::arguments();
+ if (!arguments.value(0).isEmpty() && arguments.value(0)[0] != '-')
+ arguments.pop_front(); // Remove application path
+ Core core(arguments.join(" ").toStdString());
+
QCoreApplication::setOrganizationName("");
QCoreApplication::setOrganizationDomain("");
QCoreApplication::setApplicationName("");
- //if (CommandLineParser::getValue("generateDoc").getString().empty())
-
- return app.exec();
- //return 0;
+ if (CommandLineParser::getValue("generateDoc").toString().isEmpty())
+ return app.exec();
+ else
+ return 0;
}
}
More information about the Orxonox-commit
mailing list