Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3255


Ignore:
Timestamp:
Jun 29, 2009, 11:59:29 PM (15 years ago)
Author:
rgrieder
Message:

#298: Improved usage dialogue creation and the information itself.

Location:
code/branches/core4/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core4/src/core/CommandLine.cc

    r3250 r3255  
    2929#include "CommandLine.h"
    3030
     31#include <sstream>
    3132#include <boost/filesystem.hpp>
    3233
     
    231232        {
    232233            COUT(0) << "Could not parse command line (including additional files): " << ex.what() << std::endl;
    233             COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
     234            COUT(0) << CommandLine::getUsageInformation() << std::endl;
    234235            throw GeneralException("");
    235236        }
     
    272273    std::string CommandLine::getUsageInformation()
    273274    {
    274         CommandLine* inst = &_getInstance();
    275         std::string infoStr;
    276         for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst->cmdLineArgs_.begin();
    277             it != inst->cmdLineArgs_.end(); ++it)
    278         {
    279             infoStr += "[--" + it->second->getName() + " " + it->second->getInformation() + "] ";
    280         }
    281         return infoStr;
     275        CommandLine& inst = _getInstance();
     276        std::ostringstream infoStr;
     277
     278        // determine maximum name size
     279        size_t maxNameSize = 0;
     280        for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst.cmdLineArgs_.begin();
     281            it != inst.cmdLineArgs_.end(); ++it)
     282        {
     283            maxNameSize = std::max(it->second->getName().size(), maxNameSize);
     284        }
     285
     286        infoStr << "Usage: orxonox [options]" << std::endl;
     287        infoStr << "Available options:" << std::endl;
     288
     289        for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst.cmdLineArgs_.begin();
     290            it != inst.cmdLineArgs_.end(); ++it)
     291        {
     292            if (it->second->getShortcut() != "")
     293                infoStr << " [-" << it->second->getShortcut() << "] ";
     294            else
     295                infoStr << "      ";
     296            infoStr << "--" << it->second->getName() << " ";
     297            if (it->second->getValue().getType() != MT_bool)
     298                infoStr << "ARG ";
     299            else
     300                infoStr << "    ";
     301            // fill with the necessary amount of blanks
     302            infoStr << std::string(maxNameSize - it->second->getName().size(), ' ');
     303            infoStr << ": " << it->second->getInformation();
     304            infoStr << std::endl;
     305        }
     306        return infoStr.str();
    282307    }
    283308
  • code/branches/core4/src/core/CommandLine.h

    r3246 r3255  
    8080
    8181        //! Returns the shortcut (example: "-p 22" for "--port 22") of the argument.
    82         //! Evaluates to "" if none there is none.
     82        //! Evaluates to "" if there is none.
    8383        const std::string& getShortcut() const { return shortcut_; }
    8484        //! Sets the shortcut for the argument
     
    213213        OrxAssert(!_getInstance().existsArgument(name),
    214214            "Cannot add a command line argument with name '" + name + "' twice.");
     215        OrxAssert(MultiType(defaultValue).getType() != MT_bool || MultiType(defaultValue).getBool() != true,
     216               "Boolean command line arguments with positive default values are not supported." << std::endl
     217            << "Please use SetCommandLineSwitch and adjust your argument: " << name);
    215218
    216219        return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue, bCommandLineOnly));
  • code/branches/core4/src/core/Core.cc

    r3253 r3255  
    8080    Core* Core::singletonRef_s  = 0;
    8181
    82     SetCommandLineArgument(mediaPath, "").information("PATH");
    83     SetCommandLineOnlyArgument(writingPathSuffix, "").information("DIR");
    84     SetCommandLineArgument(settingsFile, "orxonox.ini");
    85     SetCommandLineArgument(limitToCPU, 0).information("0: off | #cpu");
     82    SetCommandLineArgument(mediaPath, "").information("Path to the media/data files");
     83    SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
     84    SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
     85#ifdef ORXONOX_PLATFORM_WINDOWS
     86    SetCommandLineArgument(limitToCPU, 0).information("Limits the program to one cpu/core (1, 2, 3, etc.). 0 turns it off (default)");
     87#endif
    8688
    8789    /**
     
    263265        CommandLine::parseFile();
    264266
     267#ifdef ORXONOX_PLATFORM_WINDOWS
    265268        // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
    266269        // do this after ogre has initialised. Somehow Ogre changes the settings again (not through
     
    269272        if (limitToCPU > 0)
    270273            setThreadAffinity(static_cast<unsigned int>(limitToCPU));
     274#endif
    271275
    272276        // Manage ini files and set the default settings file (usually orxonox.ini)
     
    423427    void Core::setThreadAffinity(int limitToCPU)
    424428    {
     429#ifdef ORXONOX_PLATFORM_WINDOWS
     430
    425431        if (limitToCPU <= 0)
    426432            return;
    427433
    428 #ifdef ORXONOX_PLATFORM_WINDOWS
    429434        unsigned int coreNr = limitToCPU - 1;
    430435        // Get the current process core mask
  • code/branches/core4/src/core/input/InputManager.cc

    r3237 r3255  
    7070    SetConsoleCommand(InputManager, ungrabMouse, true);
    7171#endif
    72     SetCommandLineSwitch(keyboard_no_grab);
     72    SetCommandLineSwitch(keyboard_no_grab).information("Whether not to exclusively grab the keyboard");
    7373
    7474    EmptyHandler InputManager::EMPTY_HANDLER;
  • code/branches/core4/src/orxonox/LevelManager.cc

    r3249 r3255  
    4040namespace orxonox
    4141{
    42     SetCommandLineArgument(level, "").shortcut("l");
     42    SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
    4343
    4444    LevelManager* LevelManager::singletonRef_s = 0;
     
    5555        if (!CommandLine::getArgument("level")->hasDefaultValue())
    5656        {
    57             ModifyConfigValue(defaultLevelName_, tset, CommandLine::getValue("mediaPath").getString());
     57            ModifyConfigValue(defaultLevelName_, tset, CommandLine::getValue("level").getString());
    5858        }
    5959    }
  • code/branches/core4/src/orxonox/gamestates/GSClient.cc

    r3243 r3255  
    4040    DeclareGameState(GSClient, "client", false, true);
    4141
    42     SetCommandLineArgument(ip, "127.0.0.1").information("#.#.#.#");
     42    SetCommandLineArgument(ip, "127.0.0.1").information("Sever IP as strin in the form #.#.#.#");
    4343
    4444    GSClient::GSClient(const GameStateConstrParams& params)
  • code/branches/core4/src/orxonox/gamestates/GSRoot.cc

    r3245 r3255  
    4242{
    4343    DeclareGameState(GSRoot, "root", true, false);
    44     SetCommandLineSwitch(console);
     44    SetCommandLineSwitch(console).information("Start in console mode (text IO only)");
    4545    // Shortcuts for easy direct loading
    46     SetCommandLineSwitch(server);
    47     SetCommandLineSwitch(client);
    48     SetCommandLineSwitch(dedicated);
    49     SetCommandLineSwitch(standalone);
     46    SetCommandLineSwitch(server).information("Start in server mode");
     47    SetCommandLineSwitch(client).information("Start in client mode");
     48    SetCommandLineSwitch(dedicated).information("Start in dedicated server mode");
     49    SetCommandLineSwitch(standalone).information("Start in standalone mode");
    5050
    5151    GSRoot::GSRoot(const GameStateConstrParams& params)
  • code/branches/core4/src/orxonox/gamestates/GSServer.cc

    r3243 r3255  
    3939    DeclareGameState(GSServer, "server", false, true);
    4040
    41     SetCommandLineArgument(port, 55556).shortcut("p").information("0-65535");
     41    SetCommandLineArgument(port, 55556).shortcut("p").information("Network communication port to be used 0-65535 (default: 55556)");
    4242
    4343    GSServer::GSServer(const GameStateConstrParams& params)
Note: See TracChangeset for help on using the changeset viewer.