Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Fixed install target:

  • log and config file go a to separate folder each
  • The SignalHandler crash log is now "orxonox_crash.log" to avoid opening the file twice which might result in problems
  • moved tcl scripts to media/tcl8.#/ as a temporary solution. I've also created a ticket to fix this.
  • UPDATE YOUR MEDIA REPOSITORY
  • orxonox.log pre-main gets written to either %TEMP% (windows) or /tmp (Unix) and when the path was set, the content is copied.
  • removed Settings class and moved media path to Core
  • media, log and config path are now all in Core where only the media path can be configured via ini file or command line
  • Core::isDevBuild() tells whether we are running in the build or the installation directory (determined by the presence of "orxonox_dev_build.kepp_me" in the binary dir)
  • renamed Settings::getDataPath to Core::getMediaPath
  • Property svn:eol-style set to native
File size: 4.9 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#include <fstream>
40
41#include "OrxonoxConfig.h"
42#include "util/Debug.h"
43#include "util/SignalHandler.h"
44#include "core/ConfigFileManager.h"
45#include "core/CommandLine.h"
46#include "core/CommandExecutor.h"
47#include "core/Identifier.h"
48#include "core/Core.h"
49#include "core/Language.h"
50
51#include "gamestates/GSRoot.h"
52#include "gamestates/GSGraphics.h"
53#include "gamestates/GSStandalone.h"
54#include "gamestates/GSServer.h"
55#include "gamestates/GSClient.h"
56#include "gamestates/GSDedicated.h"
57#include "gamestates/GSGUI.h"
58#include "gamestates/GSIOConsole.h"
59
60#ifdef ORXONOX_PLATFORM_APPLE
61#include <CoreFoundation/CoreFoundation.h>
62
63// This function will locate the path to our application on OS X,
64// unlike windows you can not rely on the curent working directory
65// for locating your configuration files and resources.
66             std::string macBundlePath()
67{
68    char path[1024];
69    CFBundleRef mainBundle = CFBundleGetMainBundle();
70    assert(mainBundle);
71
72    CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
73    assert(mainBundleURL);
74
75    CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
76    assert(cfStringRef);
77
78    CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
79
80    CFRelease(mainBundleURL);
81    CFRelease(cfStringRef);
82
83    return std::string(path);
84}
85#endif
86
87
88SetCommandLineArgument(settingsFile, "orxonox.ini");
89SetCommandLineArgument(configFileDirectory, "");
90
91int main(int argc, char** argv)
92{
93    using namespace orxonox;
94
95    // First, determine whether we have an installed or a binary dir run
96    // The latter occurs when simply running from the build directory
97    std::ifstream probe;
98    probe.open("orxonox_dev_build.keep_me");
99    if (probe)
100    {
101        Core::setDevBuild();
102        probe.close();
103    }
104
105    // create a signal handler (only active for linux)
106    SignalHandler signalHandler;
107    signalHandler.doCatch(argv[0], Core::getLogPath() + "orxonox_crash.log");
108
109    // Parse command line arguments
110    try
111    {
112        CommandLine::parseAll(argc, argv);
113    }
114    catch (ArgumentException& ex)
115    {
116        COUT(1) << ex.what() << std::endl;
117        COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
118    }
119
120    // Create the ConfigFileManager before creating the GameStates in order to have
121    // setConfigValues() in the constructor (required).
122    ConfigFileManager* configFileManager = new ConfigFileManager();
123    configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString());
124    // create the Core settings to configure the output level
125    Language* language = new Language();
126    Core*     core     = new Core();
127
128    // put GameStates in its own scope so we can destroy the identifiers at the end of main().
129    {
130        // create the gamestates
131        GSRoot root;
132        GSGraphics graphics;
133        GSStandalone standalone;
134        GSServer server;
135        GSClient client;
136        GSDedicated dedicated;
137        GSGUI gui;
138        GSIOConsole ioConsole;
139
140        // make the hierarchy
141        root.addChild(&graphics);
142        graphics.addChild(&standalone);
143        graphics.addChild(&server);
144        graphics.addChild(&client);
145        graphics.addChild(&gui);
146        root.addChild(&ioConsole);
147        root.addChild(&dedicated);
148
149        // Here happens the game
150        root.start();
151    }
152
153    // destroy singletons
154    delete core;
155    delete language;
156    delete configFileManager;
157
158    // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
159    Identifier::destroyAllIdentifiers();
160    // destroy command line arguments
161    CommandLine::destroyAllArguments();
162    // Also delete external console command that don't belong to an Identifier
163    CommandExecutor::destroyExternalCommands();
164
165    return 0;
166}
Note: See TracBrowser for help on using the repository browser.