Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 20, 2008, 10:30:28 PM (16 years ago)
Author:
rgrieder
Message:

Added CommandLine class.
You can now call SetCommandLineArgument like SetConsoleCommand and hereby define a new command line argument. They are passed in main() and then they can be accessed by commandLine::getCommandLineArgument().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/orxonox/Main.cc

    r1661 r1663  
    3939
    4040#include "util/OrxonoxPlatform.h"
    41 #include "util/ArgReader.h"
    4241#include "core/SignalHandler.h"
    4342#include "core/Debug.h"
    44 #include "network/ClientConnection.h"
    45 #include "Settings.h"
    46 #include "Orxonox.h"
     43#include "core/CommandLine.h"
     44//#include "Orxonox.h"
    4745
    4846#include "gamestates/GSRoot.h"
     
    8078#endif
    8179
    82 bool parseCommandLine(int argc, char** argv)
    83 {
    84     ArgReader args;
    85     std::string errorStr = args.parse(argc, argv);
    86     if (errorStr != "")
    87     {
    88         COUT(1) << "Command Line: Parsing failed.\n" << errorStr << std::endl;
    89         return false;
    90     }
    91 
    92     // Argument reader parses the command line to check syntax.
    93     // Settings Singleton then stores the arguments. It always
    94     // expects a default value.
    95     bool success = true;
    96     success &= Settings::addCommandLineArgument<std::string>
    97         ("mode",     args.getArgument("mode"),     "standalone");
    98     success &= Settings::addCommandLineArgument<std::string>
    99         ("dataPath", args.getArgument("dataPath"), "./");
    100     success &= Settings::addCommandLineArgument<std::string>
    101         ("ip",       args.getArgument("ip"),       "127.0.0.0");
    102     success &= Settings::addCommandLineArgument<int>
    103         ("port",     args.getArgument("port"),     NETWORK_PORT);
    104 
    105     if (!success)
    106         return false;
    107 
    108     if (!args.allChecked())
    109     {
    110         COUT(1) << "Command Line: Parsing failed.\nNot all arguments were matched." << std::endl;
    111         return false;
    112     }
    113 
    114     return true;
    115 }
    116 
    117 #include "core/GameState.h"
    11880
    11981#ifdef __cplusplus
     
    12385int main(int argc, char** argv)
    12486{
     87    try
     88    {
     89        orxonox::CommandLine::parse(argc, argv);
     90    }
     91    catch (orxonox::ArgumentException& ex)
     92    {
     93        COUT(1) << ex.what() << std::endl;
     94        COUT(0) << "Usage:" << std::endl << "orxonox [--mode client|server|dedicated|standalone] "
     95                << "[--data PATH] [--ip IP] [--port PORT]" << std::endl;
     96    }
     97
     98
    12599    // create a signal handler (only works for linux)
    126100    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
    127101
    128     if (!parseCommandLine(argc, argv))
    129     {
    130         COUT(0) << "Usage:" << std::endl << "orxonox [--mode client|server|dedicated|standalone] "
    131                 << "[--data PATH] [--ip IP] [--port PORT]" << std::endl;
    132         return 0;
    133     }
    134102
    135103
     
    181149
    182150
    183     Orxonox orxonoxInstance;
     151    //Orxonox orxonoxInstance;
    184152
    185153    try
Note: See TracChangeset for help on using the changeset viewer.