Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Added CommandLine class.
You can now call SetCommandLineArgument like SetConsoleCommand and hereby define a new command line argument. They are passed in main() and then they can be accessed by commandLine::getCommandLineArgument().

  • Property svn:eol-style set to native
File size: 4.3 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 "core/SignalHandler.h"
42#include "core/Debug.h"
43#include "core/CommandLine.h"
44//#include "Orxonox.h"
45
46#include "gamestates/GSRoot.h"
47#include "gamestates/GSGraphics.h"
48#include "gamestates/GSLevel.h"
49#include "gamestates/GSGUI.h"
50
51using namespace orxonox;
52
53#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE
54#include <CoreFoundation/CoreFoundation.h>
55
56// This function will locate the path to our application on OS X,
57// unlike windows you can not rely on the curent working directory
58// for locating your configuration files and resources.
59             std::string macBundlePath()
60{
61    char path[1024];
62    CFBundleRef mainBundle = CFBundleGetMainBundle();
63    assert(mainBundle);
64
65    CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
66    assert(mainBundleURL);
67
68    CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
69    assert(cfStringRef);
70
71    CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
72
73    CFRelease(mainBundleURL);
74    CFRelease(cfStringRef);
75
76    return std::string(path);
77}
78#endif
79
80
81#ifdef __cplusplus
82extern "C" {
83#endif
84
85int main(int argc, char** argv)
86{
87    try
88    {
89        orxonox::CommandLine::parse(argc, argv);
90    }
91    catch (orxonox::ArgumentException& ex)
92    {
93        COUT(1) << ex.what() << std::endl;
94        COUT(0) << "Usage:" << std::endl << "orxonox [--mode client|server|dedicated|standalone] "
95                << "[--data PATH] [--ip IP] [--port PORT]" << std::endl;
96    }
97
98
99    // create a signal handler (only works for linux)
100    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
101
102
103
104    /*GameState* state1 = new GameState("state1");
105    GameState* state2 = new GameState("state2");
106    GameState* state3 = new GameState("state3");
107    GameState* state4 = new GameState("state4");
108    GameState* state5 = new GameState("state5");
109    GameState* state6 = new GameState("state6");
110
111    state1->addChild(state4);
112    state1->addChild(state6);
113    state2->addChild(state3);
114    state2->addChild(state5);
115    state6->addChild(state2);
116
117    state6->removeChild("state2");
118
119    state5->requestState("state3");
120    COUT(2) << std::endl;
121    state2->requestState("state2");
122    COUT(2) << std::endl;
123    state2->requestState("state1");
124    COUT(2) << std::endl;
125    state4->requestState("state3");
126    COUT(2) << std::endl;
127    state1->requestState("state4");
128    COUT(2) << std::endl;
129    state1->requestState("state2");
130    COUT(2) << std::endl;
131    state1->requestState("stat");
132    COUT(2) << std::endl;
133    state1->requestState("state5");
134    COUT(2) << std::endl;*/
135
136
137    GSRoot root;
138    GSGraphics graphics;
139    GSLevel level;
140    GSGUI gui;
141
142    root.addChild(&graphics);
143    graphics.addChild(&level);
144    graphics.addChild(&gui);
145
146    root.requestState("gui");
147    root.tick(0.0f);
148    root.requestState("");
149
150
151    //Orxonox orxonoxInstance;
152
153    try
154    {
155#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE
156        orxonoxInstance.start(macBundlePath());
157#else
158        //orxonoxInstance.start();
159#endif
160    }
161    catch (std::exception& ex)
162    {
163        COUT(1) << ex.what() << std::endl;
164        COUT(1) << "Abort." << std::endl;
165    }
166
167    return 0;
168}
169
170#ifdef __cplusplus
171}
172#endif
Note: See TracBrowser for help on using the repository browser.