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 | |
---|
48 | #include "gamestates/GSRoot.h" |
---|
49 | #include "gamestates/GSGraphics.h" |
---|
50 | #include "gamestates/GSLevel.h" |
---|
51 | #include "gamestates/GSGUI.h" |
---|
52 | |
---|
53 | using namespace orxonox; |
---|
54 | |
---|
55 | #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE |
---|
56 | #include <CoreFoundation/CoreFoundation.h> |
---|
57 | |
---|
58 | // This function will locate the path to our application on OS X, |
---|
59 | // unlike windows you can not rely on the curent working directory |
---|
60 | // for locating your configuration files and resources. |
---|
61 | std::string macBundlePath() |
---|
62 | { |
---|
63 | char path[1024]; |
---|
64 | CFBundleRef mainBundle = CFBundleGetMainBundle(); |
---|
65 | assert(mainBundle); |
---|
66 | |
---|
67 | CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); |
---|
68 | assert(mainBundleURL); |
---|
69 | |
---|
70 | CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); |
---|
71 | assert(cfStringRef); |
---|
72 | |
---|
73 | CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII); |
---|
74 | |
---|
75 | CFRelease(mainBundleURL); |
---|
76 | CFRelease(cfStringRef); |
---|
77 | |
---|
78 | return std::string(path); |
---|
79 | } |
---|
80 | #endif |
---|
81 | |
---|
82 | bool parseCommandLine(int argc, char** argv) |
---|
83 | { |
---|
84 | ArgReader args; |
---|
85 | std::string errorStr = args.parse(argc, argv); |
---|
86 | if (errorStr != "") |
---|
87 | { |
---|
88 | COUT(1) << "Command Line: Parsing failed.\n" << errorStr << std::endl; |
---|
89 | return false; |
---|
90 | } |
---|
91 | |
---|
92 | // Argument reader parses the command line to check syntax. |
---|
93 | // Settings Singleton then stores the arguments. It always |
---|
94 | // expects a default value. |
---|
95 | bool success = true; |
---|
96 | success &= Settings::addCommandLineArgument<std::string> |
---|
97 | ("mode", args.getArgument("mode"), "standalone"); |
---|
98 | success &= Settings::addCommandLineArgument<std::string> |
---|
99 | ("dataPath", args.getArgument("dataPath"), "./"); |
---|
100 | success &= Settings::addCommandLineArgument<std::string> |
---|
101 | ("ip", args.getArgument("ip"), "127.0.0.0"); |
---|
102 | success &= Settings::addCommandLineArgument<int> |
---|
103 | ("port", args.getArgument("port"), NETWORK_PORT); |
---|
104 | |
---|
105 | if (!success) |
---|
106 | return false; |
---|
107 | |
---|
108 | if (!args.allChecked()) |
---|
109 | { |
---|
110 | COUT(1) << "Command Line: Parsing failed.\nNot all arguments were matched." << std::endl; |
---|
111 | return false; |
---|
112 | } |
---|
113 | |
---|
114 | return true; |
---|
115 | } |
---|
116 | |
---|
117 | #include "core/GameState.h" |
---|
118 | |
---|
119 | #ifdef __cplusplus |
---|
120 | extern "C" { |
---|
121 | #endif |
---|
122 | |
---|
123 | int main(int argc, char** argv) |
---|
124 | { |
---|
125 | // create a signal handler (only works for linux) |
---|
126 | SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log"); |
---|
127 | |
---|
128 | if (!parseCommandLine(argc, argv)) |
---|
129 | { |
---|
130 | COUT(0) << "Usage:" << std::endl << "orxonox [--mode client|server|dedicated|standalone] " |
---|
131 | << "[--data PATH] [--ip IP] [--port PORT]" << std::endl; |
---|
132 | return 0; |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | /*GameState* state1 = new GameState("state1"); |
---|
137 | GameState* state2 = new GameState("state2"); |
---|
138 | GameState* state3 = new GameState("state3"); |
---|
139 | GameState* state4 = new GameState("state4"); |
---|
140 | GameState* state5 = new GameState("state5"); |
---|
141 | GameState* state6 = new GameState("state6"); |
---|
142 | |
---|
143 | state1->addChild(state4); |
---|
144 | state1->addChild(state6); |
---|
145 | state2->addChild(state3); |
---|
146 | state2->addChild(state5); |
---|
147 | state6->addChild(state2); |
---|
148 | |
---|
149 | state6->removeChild("state2"); |
---|
150 | |
---|
151 | state5->requestState("state3"); |
---|
152 | COUT(2) << std::endl; |
---|
153 | state2->requestState("state2"); |
---|
154 | COUT(2) << std::endl; |
---|
155 | state2->requestState("state1"); |
---|
156 | COUT(2) << std::endl; |
---|
157 | state4->requestState("state3"); |
---|
158 | COUT(2) << std::endl; |
---|
159 | state1->requestState("state4"); |
---|
160 | COUT(2) << std::endl; |
---|
161 | state1->requestState("state2"); |
---|
162 | COUT(2) << std::endl; |
---|
163 | state1->requestState("stat"); |
---|
164 | COUT(2) << std::endl; |
---|
165 | state1->requestState("state5"); |
---|
166 | COUT(2) << std::endl;*/ |
---|
167 | |
---|
168 | |
---|
169 | GSRoot root; |
---|
170 | GSGraphics graphics; |
---|
171 | GSLevel level; |
---|
172 | GSGUI gui; |
---|
173 | |
---|
174 | root.addChild(&graphics); |
---|
175 | graphics.addChild(&level); |
---|
176 | graphics.addChild(&gui); |
---|
177 | |
---|
178 | root.requestState("gui"); |
---|
179 | root.tick(0.0f); |
---|
180 | root.requestState(""); |
---|
181 | |
---|
182 | |
---|
183 | Orxonox orxonoxInstance; |
---|
184 | |
---|
185 | try |
---|
186 | { |
---|
187 | #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE |
---|
188 | orxonoxInstance.start(macBundlePath()); |
---|
189 | #else |
---|
190 | //orxonoxInstance.start(); |
---|
191 | #endif |
---|
192 | } |
---|
193 | catch (std::exception& ex) |
---|
194 | { |
---|
195 | COUT(1) << ex.what() << std::endl; |
---|
196 | COUT(1) << "Abort." << std::endl; |
---|
197 | } |
---|
198 | |
---|
199 | return 0; |
---|
200 | } |
---|
201 | |
---|
202 | #ifdef __cplusplus |
---|
203 | } |
---|
204 | #endif |
---|