Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/buildsystem3/src/orxonox/Main.cc @ 2702

Last change on this file since 2702 was 2702, checked in by rgrieder, 15 years ago

Completed work on installation:

  • The CMake switch INSTALL_COPYABLE tells whether you will be able to move the installed directory or not. If TRUE then all folders, including log and config directory, will be put into the CMAKE_INSTALL_PREFIX. Furthermore, relative paths are used, which get resolved at run time.
  • If INSTALL_COPYABLE is set to FALSE, the standard operating system directories will be used. That also means on Windows files get written to the Application Data/.orxonox folder instead of Program Files/Orxonox
  • Default configuration is INSTALL_COPYABLE=TRUE for Windows and FALSE for Unix
  • Split OrxonoxConfig.h.in in two to avoid complete recompiles when changing only a path or INSTALL_COPYABLE
  • Added a global constant character: CP_SLASH which stands for cross platform slash, meaning '/' on Unix and '
    ' on Windows
  • Core class now has methods getFooPath(), getFooPathString() and getFooPathPOSIXString() where Foo can be Media, Log or Config
  • getFooPathPOSIXString() will always return a directory formatted with slashes, even on Windows
  • getFooPath() returns a reference to the boost::filesystem::path
  • boost/filesystem.hpp does not get included to Core.h because it has a very large rat tail
  • The platform specific directory stuff gets done in Core::postMainInitialisation()
  • Adjusted all classes using the media path
  • Property svn:eol-style set to native
File size: 4.6 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
24 *      Reto Grieder
25 *   Co-authors:
26 *      ...
27 *
28 */
29
30 /**
31 @file
32 @brief Entry point of the program.
33  */
34
35#include "OrxonoxStableHeaders.h"
36
37#include <exception>
38#include <cassert>
39
40#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"
49
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"
58
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
90int main(int argc, char** argv)
91{
92    using namespace orxonox;
93
94    Core::postMainInitialisation();
95
96    // create a signal handler (only active for linux)
97    SignalHandler signalHandler;
98    signalHandler.doCatch(argv[0], Core::getLogPathString() + "orxonox_crash.log");
99
100    // Parse command line arguments
101    try
102    {
103        CommandLine::parseAll(argc, argv);
104    }
105    catch (ArgumentException& ex)
106    {
107        COUT(1) << ex.what() << std::endl;
108        COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
109    }
110
111    // Create the ConfigFileManager before creating the GameStates in order to have
112    // setConfigValues() in the constructor (required).
113    ConfigFileManager* configFileManager = new ConfigFileManager();
114    configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString());
115    // create the Core settings to configure the output level
116    Language* language = new Language();
117    Core*     core     = new Core();
118
119    // put GameStates in its own scope so we can destroy the identifiers at the end of main().
120    {
121        // create the gamestates
122        GSRoot root;
123        GSGraphics graphics;
124        GSStandalone standalone;
125        GSServer server;
126        GSClient client;
127        GSDedicated dedicated;
128        GSGUI gui;
129        GSIOConsole ioConsole;
130
131        // make the hierarchy
132        root.addChild(&graphics);
133        graphics.addChild(&standalone);
134        graphics.addChild(&server);
135        graphics.addChild(&client);
136        graphics.addChild(&gui);
137        root.addChild(&ioConsole);
138        root.addChild(&dedicated);
139
140        // Here happens the game
141        root.start();
142    }
143
144    // destroy singletons
145    delete core;
146    delete language;
147    delete configFileManager;
148
149    // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
150    Identifier::destroyAllIdentifiers();
151    // destroy command line arguments
152    CommandLine::destroyAllArguments();
153    // Also delete external console command that don't belong to an Identifier
154    CommandExecutor::destroyExternalCommands();
155
156    return 0;
157}
Note: See TracBrowser for help on using the repository browser.