[Orxonox-commit 725] r3255 - in branches/core4/src: core core/input orxonox orxonox/gamestates

rgrieder at orxonox.net rgrieder at orxonox.net
Mon Jun 29 23:59:29 CEST 2009


Author: rgrieder
Date: 2009-06-29 23:59:29 +0200 (Mon, 29 Jun 2009)
New Revision: 3255

Modified:
   branches/core4/src/core/CommandLine.cc
   branches/core4/src/core/CommandLine.h
   branches/core4/src/core/Core.cc
   branches/core4/src/core/input/InputManager.cc
   branches/core4/src/orxonox/LevelManager.cc
   branches/core4/src/orxonox/gamestates/GSClient.cc
   branches/core4/src/orxonox/gamestates/GSRoot.cc
   branches/core4/src/orxonox/gamestates/GSServer.cc
Log:
#298: Improved usage dialogue creation and the information itself.

Modified: branches/core4/src/core/CommandLine.cc
===================================================================
--- branches/core4/src/core/CommandLine.cc	2009-06-29 20:01:38 UTC (rev 3254)
+++ branches/core4/src/core/CommandLine.cc	2009-06-29 21:59:29 UTC (rev 3255)
@@ -28,6 +28,7 @@
 
 #include "CommandLine.h"
 
+#include <sstream>
 #include <boost/filesystem.hpp>
 
 #include "util/Convert.h"
@@ -230,7 +231,7 @@
         catch (const ArgumentException& ex)
         {
             COUT(0) << "Could not parse command line (including additional files): " << ex.what() << std::endl;
-            COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
+            COUT(0) << CommandLine::getUsageInformation() << std::endl;
             throw GeneralException("");
         }
     }
@@ -271,14 +272,38 @@
 
     std::string CommandLine::getUsageInformation()
     {
-        CommandLine* inst = &_getInstance();
-        std::string infoStr;
-        for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst->cmdLineArgs_.begin();
-            it != inst->cmdLineArgs_.end(); ++it)
+        CommandLine& 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)
         {
-            infoStr += "[--" + it->second->getName() + " " + it->second->getInformation() + "] ";
+            maxNameSize = std::max(it->second->getName().size(), maxNameSize);
         }
-        return infoStr;
+
+        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() != "")
+                infoStr << " [-" << it->second->getShortcut() << "] ";
+            else
+                infoStr << "      ";
+            infoStr << "--" << it->second->getName() << " ";
+            if (it->second->getValue().getType() != MT_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();
     }
 
     /**

Modified: branches/core4/src/core/CommandLine.h
===================================================================
--- branches/core4/src/core/CommandLine.h	2009-06-29 20:01:38 UTC (rev 3254)
+++ branches/core4/src/core/CommandLine.h	2009-06-29 21:59:29 UTC (rev 3255)
@@ -79,7 +79,7 @@
         const std::string& getName() const { return name_; }
 
         //! Returns the shortcut (example: "-p 22" for "--port 22") of the argument.
-        //! Evaluates to "" if none there is none.
+        //! 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)
@@ -212,6 +212,9 @@
     {
         OrxAssert(!_getInstance().existsArgument(name),
             "Cannot add a command line argument with name '" + name + "' twice.");
+        OrxAssert(MultiType(defaultValue).getType() != MT_bool || MultiType(defaultValue).getBool() != 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));
     }

Modified: branches/core4/src/core/Core.cc
===================================================================
--- branches/core4/src/core/Core.cc	2009-06-29 20:01:38 UTC (rev 3254)
+++ branches/core4/src/core/Core.cc	2009-06-29 21:59:29 UTC (rev 3255)
@@ -79,10 +79,12 @@
     //! Static pointer to the singleton
     Core* Core::singletonRef_s  = 0;
 
-    SetCommandLineArgument(mediaPath, "").information("PATH");
-    SetCommandLineOnlyArgument(writingPathSuffix, "").information("DIR");
-    SetCommandLineArgument(settingsFile, "orxonox.ini");
-    SetCommandLineArgument(limitToCPU, 0).information("0: off | #cpu");
+    SetCommandLineArgument(mediaPath, "").information("Path to the media/data files");
+    SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
+    SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
+#ifdef ORXONOX_PLATFORM_WINDOWS
+    SetCommandLineArgument(limitToCPU, 0).information("Limits the program to one cpu/core (1, 2, 3, etc.). 0 turns it off (default)");
+#endif
 
     /**
     @brief
@@ -262,12 +264,14 @@
         // Parse additional options file now that we know its path
         CommandLine::parseFile();
 
+#ifdef ORXONOX_PLATFORM_WINDOWS
         // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
         // do this after ogre has initialised. Somehow Ogre changes the settings again (not through
         // the timer though).
         int limitToCPU = CommandLine::getValue("limitToCPU");
         if (limitToCPU > 0)
             setThreadAffinity(static_cast<unsigned int>(limitToCPU));
+#endif
 
         // Manage ini files and set the default settings file (usually orxonox.ini)
         this->configFileManager_ = new ConfigFileManager();
@@ -422,10 +426,11 @@
     */
     void Core::setThreadAffinity(int limitToCPU)
     {
+#ifdef ORXONOX_PLATFORM_WINDOWS
+
         if (limitToCPU <= 0)
             return;
 
-#ifdef ORXONOX_PLATFORM_WINDOWS
         unsigned int coreNr = limitToCPU - 1;
         // Get the current process core mask
         DWORD procMask;

Modified: branches/core4/src/core/input/InputManager.cc
===================================================================
--- branches/core4/src/core/input/InputManager.cc	2009-06-29 20:01:38 UTC (rev 3254)
+++ branches/core4/src/core/input/InputManager.cc	2009-06-29 21:59:29 UTC (rev 3255)
@@ -69,7 +69,7 @@
     SetConsoleCommand(InputManager, grabMouse, true);
     SetConsoleCommand(InputManager, ungrabMouse, true);
 #endif
-    SetCommandLineSwitch(keyboard_no_grab);
+    SetCommandLineSwitch(keyboard_no_grab).information("Whether not to exclusively grab the keyboard");
 
     EmptyHandler InputManager::EMPTY_HANDLER;
     InputManager* InputManager::singletonRef_s = 0;

Modified: branches/core4/src/orxonox/LevelManager.cc
===================================================================
--- branches/core4/src/orxonox/LevelManager.cc	2009-06-29 20:01:38 UTC (rev 3254)
+++ branches/core4/src/orxonox/LevelManager.cc	2009-06-29 21:59:29 UTC (rev 3255)
@@ -39,7 +39,7 @@
 
 namespace orxonox
 {
-    SetCommandLineArgument(level, "").shortcut("l");
+    SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
 
     LevelManager* LevelManager::singletonRef_s = 0;
 
@@ -54,7 +54,7 @@
         // check override
         if (!CommandLine::getArgument("level")->hasDefaultValue())
         {
-            ModifyConfigValue(defaultLevelName_, tset, CommandLine::getValue("mediaPath").getString());
+            ModifyConfigValue(defaultLevelName_, tset, CommandLine::getValue("level").getString());
         }
     }
 

Modified: branches/core4/src/orxonox/gamestates/GSClient.cc
===================================================================
--- branches/core4/src/orxonox/gamestates/GSClient.cc	2009-06-29 20:01:38 UTC (rev 3254)
+++ branches/core4/src/orxonox/gamestates/GSClient.cc	2009-06-29 21:59:29 UTC (rev 3255)
@@ -39,7 +39,7 @@
 {
     DeclareGameState(GSClient, "client", false, true);
 
-    SetCommandLineArgument(ip, "127.0.0.1").information("#.#.#.#");
+    SetCommandLineArgument(ip, "127.0.0.1").information("Sever IP as strin in the form #.#.#.#");
 
     GSClient::GSClient(const GameStateConstrParams& params)
         : GameState(params)

Modified: branches/core4/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- branches/core4/src/orxonox/gamestates/GSRoot.cc	2009-06-29 20:01:38 UTC (rev 3254)
+++ branches/core4/src/orxonox/gamestates/GSRoot.cc	2009-06-29 21:59:29 UTC (rev 3255)
@@ -41,12 +41,12 @@
 namespace orxonox
 {
     DeclareGameState(GSRoot, "root", true, false);
-    SetCommandLineSwitch(console);
+    SetCommandLineSwitch(console).information("Start in console mode (text IO only)");
     // Shortcuts for easy direct loading
-    SetCommandLineSwitch(server);
-    SetCommandLineSwitch(client);
-    SetCommandLineSwitch(dedicated);
-    SetCommandLineSwitch(standalone);
+    SetCommandLineSwitch(server).information("Start in server mode");
+    SetCommandLineSwitch(client).information("Start in client mode");
+    SetCommandLineSwitch(dedicated).information("Start in dedicated server mode");
+    SetCommandLineSwitch(standalone).information("Start in standalone mode");
 
     GSRoot::GSRoot(const GameStateConstrParams& params)
         : GameState(params)

Modified: branches/core4/src/orxonox/gamestates/GSServer.cc
===================================================================
--- branches/core4/src/orxonox/gamestates/GSServer.cc	2009-06-29 20:01:38 UTC (rev 3254)
+++ branches/core4/src/orxonox/gamestates/GSServer.cc	2009-06-29 21:59:29 UTC (rev 3255)
@@ -38,7 +38,7 @@
 {
     DeclareGameState(GSServer, "server", false, true);
 
-    SetCommandLineArgument(port, 55556).shortcut("p").information("0-65535");
+    SetCommandLineArgument(port, 55556).shortcut("p").information("Network communication port to be used 0-65535 (default: 55556)");
 
     GSServer::GSServer(const GameStateConstrParams& params)
         : GameState(params)




More information about the Orxonox-commit mailing list