Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

GameState class added. Tested and working, but now comes the hard part: Implementing the actual states…

  • Property svn:eol-style set to native
File size: 5.0 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#include "core/GameState.h"
113
114#ifdef __cplusplus
115extern "C" {
116#endif
117
118int main(int argc, char** argv)
119{
120    // create a signal handler (only works for linux)
121    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
122
123    if (!parseCommandLine(argc, argv))
124    {
125        COUT(0) << "Usage:" << std::endl << "orxonox [--mode client|server|dedicated|standalone] "
126                << "[--data PATH] [--ip IP] [--port PORT]" << std::endl;
127        return 0;
128    }
129
130
131    /*GameState* state1 = new GameState("state1");
132    GameState* state2 = new GameState("state2");
133    GameState* state3 = new GameState("state3");
134    GameState* state4 = new GameState("state4");
135    GameState* state5 = new GameState("state5");
136    GameState* state6 = new GameState("state6");
137
138    state1->addChild(state4);
139    state1->addChild(state6);
140    state2->addChild(state3);
141    state2->addChild(state5);
142    state3->addChild(state1);
143    state6->addChild(state2);
144
145    state5->requestState("state3");
146    COUT(2) << std::endl;
147    state2->requestState("state2");
148    COUT(2) << std::endl;
149    state2->requestState("state1");
150    COUT(2) << std::endl;
151    state4->requestState("state3");
152    COUT(2) << std::endl;
153    state1->requestState("state4");
154    COUT(2) << std::endl;
155    state1->requestState("state2");
156    COUT(2) << std::endl;
157    state1->requestState("stat");
158    COUT(2) << std::endl;
159    state1->requestState("state5");
160    COUT(2) << std::endl;*/
161
162
163
164    Orxonox orxonoxInstance;
165
166    try
167    {
168#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE
169        orxonoxInstance.start(macBundlePath());
170#else
171        orxonoxInstance.start();
172#endif
173    }
174    catch (std::exception& ex)
175    {
176        COUT(1) << ex.what() << std::endl;
177        COUT(1) << "Abort." << std::endl;
178    }
179
180    return 0;
181}
182
183#ifdef __cplusplus
184}
185#endif
Note: See TracBrowser for help on using the repository browser.