Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/orxonox/Main.cc @ 1638

Last change on this file since 1638 was 1638, checked in by rgrieder, 16 years ago

merged input branch into gui test branch (was about time)
svn save (it's still a mess and CMLs haven't been updated)
I'll have to create a special project to create the tolua_bind files for tolua itself anyway..

  • Property svn:eol-style set to native
File size: 4.1 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. Platform specific code.
33  */
34
35#include "OrxonoxStableHeaders.h"
36
37#include <exception>
38#include <cassert>
39
40#include "util/OrxonoxPlatform.h"
41#include "util/ArgReader.h"
42#include "core/SignalHandler.h"
43#include "core/Debug.h"
44#include "network/ClientConnection.h"
45#include "Settings.h"
46#include "Orxonox.h"
47
48using namespace orxonox;
49
50#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE
51#include <CoreFoundation/CoreFoundation.h>
52
53// This function will locate the path to our application on OS X,
54// unlike windows you can not rely on the curent working directory
55// for locating your configuration files and resources.
56             std::string macBundlePath()
57{
58    char path[1024];
59    CFBundleRef mainBundle = CFBundleGetMainBundle();
60    assert(mainBundle);
61
62    CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
63    assert(mainBundleURL);
64
65    CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
66    assert(cfStringRef);
67
68    CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
69
70    CFRelease(mainBundleURL);
71    CFRelease(cfStringRef);
72
73    return std::string(path);
74}
75#endif
76
77bool parseCommandLine(int argc, char** argv)
78{
79    ArgReader args;
80    std::string errorStr = args.parse(argc, argv);
81    if (errorStr != "")
82    {
83        COUT(1) << "Command Line: Parsing failed.\n" << errorStr << std::endl;
84        return false;
85    }
86
87    // Argument reader parses the command line to check syntax.
88    // Settings Singleton then stores the arguments. It always
89    // expects a default value.
90    bool success = true;
91    success &= Settings::addCommandLineArgument<std::string>
92        ("mode",     args.getArgument("mode"),     "standalone");
93    success &= Settings::addCommandLineArgument<std::string>
94        ("dataPath", args.getArgument("dataPath"), "./");
95    success &= Settings::addCommandLineArgument<std::string>
96        ("ip",       args.getArgument("ip"),       "127.0.0.0");
97    success &= Settings::addCommandLineArgument<int>
98        ("port",     args.getArgument("port"),     NETWORK_PORT);
99
100    if (!success)
101        return false;
102
103    if (!args.allChecked())
104    {
105        COUT(1) << "Command Line: Parsing failed.\nNot all arguments were matched." << std::endl;
106        return false;
107    }
108
109    return true;
110}
111
112#ifdef __cplusplus
113extern "C" {
114#endif
115
116int main(int argc, char** argv)
117{
118    // create a signal handler (only works for linux)
119    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
120
121    if (!parseCommandLine(argc, argv))
122    {
123        COUT(0) << "Usage:" << std::endl << "orxonox [--mode client|server|dedicated|standalone] "
124                << "[--data PATH] [--ip IP] [--port PORT]" << std::endl;
125        return 0;
126    }
127
128    Orxonox orxonoxInstance;
129
130    try
131    {
132#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE
133        orxonoxInstance.start(macBundlePath());
134#else
135        orxonoxInstance.start();
136#endif
137    }
138    catch (std::exception& ex)
139    {
140        COUT(1) << ex.what() << std::endl;
141        COUT(1) << "Abort." << std::endl;
142    }
143
144    return 0;
145}
146
147#ifdef __cplusplus
148}
149#endif
Note: See TracBrowser for help on using the repository browser.