Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 8, 2009, 12:58:47 AM (16 years ago)
Author:
dafrick
Message:

Reverted to revision 2906 (because I'm too stupid to merge correctly, 2nd try will follow shortly. ;))

Location:
code/branches/questsystem5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem5

  • code/branches/questsystem5/src/orxonox/Main.cc

    r2907 r2908  
    2727 *
    2828 */
    29  
    30  /**
    31  @mainpage Orxonox Documentation
    32  */
    3329
    3430 /**
     
    3834
    3935#include "OrxonoxStableHeaders.h"
     36
     37#include <exception>
     38#include <cassert>
     39
    4040#include "OrxonoxConfig.h"
     41#include "util/Debug.h"
     42#include "util/SignalHandler.h"
     43#include "core/ConfigFileManager.h"
     44#include "core/CommandLine.h"
     45#include "core/CommandExecutor.h"
     46#include "core/Identifier.h"
     47#include "core/Core.h"
     48#include "core/Language.h"
    4149
    42 #include "util/Debug.h"
    43 #include "core/Identifier.h"
    44 #include "core/Game.h"
     50#include "gamestates/GSRoot.h"
     51#include "gamestates/GSGraphics.h"
     52#include "gamestates/GSStandalone.h"
     53#include "gamestates/GSServer.h"
     54#include "gamestates/GSClient.h"
     55#include "gamestates/GSDedicated.h"
     56#include "gamestates/GSGUI.h"
     57#include "gamestates/GSIOConsole.h"
    4558
    46 /*
    47 @brief
    48     Main method. Game starts here (except for static initialisations).
    49 */
     59#ifdef ORXONOX_PLATFORM_APPLE
     60#include <CoreFoundation/CoreFoundation.h>
     61
     62// This function will locate the path to our application on OS X,
     63// unlike windows you can not rely on the curent working directory
     64// for locating your configuration files and resources.
     65             std::string macBundlePath()
     66{
     67    char path[1024];
     68    CFBundleRef mainBundle = CFBundleGetMainBundle();
     69    assert(mainBundle);
     70
     71    CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
     72    assert(mainBundleURL);
     73
     74    CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
     75    assert(cfStringRef);
     76
     77    CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
     78
     79    CFRelease(mainBundleURL);
     80    CFRelease(cfStringRef);
     81
     82    return std::string(path);
     83}
     84#endif
     85
     86
     87SetCommandLineArgument(settingsFile, "orxonox.ini");
     88SetCommandLineArgument(configFileDirectory, "");
     89
    5090int main(int argc, char** argv)
    5191{
     92    using namespace orxonox;
     93
     94    // Parse command line arguments
     95    try
    5296    {
    53         orxonox::Game orxonox(argc, argv);
     97        CommandLine::parseAll(argc, argv);
     98    }
     99    catch (ArgumentException& ex)
     100    {
     101        COUT(1) << ex.what() << std::endl;
     102        COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
     103    }
    54104
    55         orxonox.setStateHierarchy(
    56         "root"
    57         " graphics"
    58         "  mainMenu"
    59         "  standalone"
    60         "   level"
    61         "  server"
    62         "   level"
    63         "  client"
    64         "   level"
    65         " dedicated"
    66         "  level"
    67         " ioConsole"
    68         );
     105    // Do this after parsing the command line to allow customisation
     106    Core::postMainInitialisation();
    69107
    70         orxonox.run();
    71     } // orxonox gets destroyed right here!
     108    // create a signal handler (only active for linux)
     109    SignalHandler signalHandler;
     110    signalHandler.doCatch(argv[0], Core::getLogPathString() + "orxonox_crash.log");
     111
     112    // Create the ConfigFileManager before creating the GameStates in order to have
     113    // setConfigValues() in the constructor (required).
     114    ConfigFileManager* configFileManager = new ConfigFileManager();
     115    configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString());
     116    // create the Core settings to configure the output level
     117    Language* language = new Language();
     118    Core*     core     = new Core();
     119
     120    // put GameStates in its own scope so we can destroy the identifiers at the end of main().
     121    {
     122        // create the gamestates
     123        GSRoot root;
     124        GSGraphics graphics;
     125        GSStandalone standalone;
     126        GSServer server;
     127        GSClient client;
     128        GSDedicated dedicated;
     129        GSGUI gui;
     130        GSIOConsole ioConsole;
     131
     132        // make the hierarchy
     133        root.addChild(&graphics);
     134        graphics.addChild(&standalone);
     135        graphics.addChild(&server);
     136        graphics.addChild(&client);
     137        graphics.addChild(&gui);
     138        root.addChild(&ioConsole);
     139        root.addChild(&dedicated);
     140
     141        // Here happens the game
     142        root.start();
     143    }
     144
     145    // destroy singletons
     146    delete core;
     147    delete language;
     148    delete configFileManager;
    72149
    73150    // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
    74     // Needs to be done after Game destructor because of ~OrxonoxClass
    75     orxonox::Identifier::destroyAllIdentifiers();
     151    Identifier::destroyAllIdentifiers();
     152    // destroy command line arguments
     153    CommandLine::destroyAllArguments();
     154    // Also delete external console command that don't belong to an Identifier
     155    CommandExecutor::destroyExternalCommands();
    76156
    77157    return 0;
Note: See TracChangeset for help on using the changeset viewer.