1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | This program is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with this program; if not, write to the Free Software Foundation, |
---|
18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
19 | |
---|
20 | |
---|
21 | ### File Specific: |
---|
22 | main-programmer: Patrick Boenzli |
---|
23 | co-programmer: Christian Meyer |
---|
24 | */ |
---|
25 | |
---|
26 | #include "orxonox.h" |
---|
27 | #include "world.h" |
---|
28 | #include "camera.h" |
---|
29 | #include "data_tank.h" |
---|
30 | #include "command_node.h" |
---|
31 | #include "game_loader.h" |
---|
32 | #include <string.h> |
---|
33 | int verbose = 3; |
---|
34 | |
---|
35 | using namespace std; |
---|
36 | |
---|
37 | /** |
---|
38 | \brief create a new Orxonox |
---|
39 | */ |
---|
40 | Orxonox::Orxonox () |
---|
41 | { |
---|
42 | pause = false; |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | \brief remove Orxonox from memory |
---|
47 | */ |
---|
48 | Orxonox::~Orxonox () |
---|
49 | { |
---|
50 | Orxonox::singletonRef = NULL; |
---|
51 | if( world != NULL) delete world; |
---|
52 | if( localinput != NULL) delete world; |
---|
53 | if( localcamera != NULL) delete localcamera; |
---|
54 | if( resources != NULL) delete resources; |
---|
55 | } |
---|
56 | |
---|
57 | /** \brief this is a singleton class to prevent duplicates */ |
---|
58 | Orxonox* Orxonox::singletonRef = 0; |
---|
59 | |
---|
60 | /** |
---|
61 | \returns reference or new Object of Orxonox if not existent. |
---|
62 | */ |
---|
63 | Orxonox* Orxonox::getInstance (void) |
---|
64 | { |
---|
65 | if (singletonRef == NULL) |
---|
66 | singletonRef = new Orxonox(); |
---|
67 | return singletonRef; |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | \brief this finds the config file |
---|
72 | |
---|
73 | Since the config file varies from user to user and since one may want to specify different config files |
---|
74 | for certain occasions or platforms this function finds the right config file for every occasion and stores |
---|
75 | it's path and name into configfilename |
---|
76 | */ |
---|
77 | void Orxonox::getConfigFile (int argc, char** argv) |
---|
78 | { |
---|
79 | strcpy (configfilename, "orxonox.conf"); |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | \brief initialize Orxonox with command line |
---|
84 | */ |
---|
85 | int Orxonox::init (int argc, char** argv) |
---|
86 | { |
---|
87 | // parse command line |
---|
88 | // config file |
---|
89 | |
---|
90 | getConfigFile (argc, argv); |
---|
91 | SDL_Init (SDL_INIT_TIMER); |
---|
92 | // initialize everything |
---|
93 | if( initVideo() == -1) return -1; |
---|
94 | if( initSound() == -1) return -1; |
---|
95 | printf("> Initializing input\n"); |
---|
96 | if( initInput() == -1) return -1; |
---|
97 | printf("> Initializing networking\n"); |
---|
98 | if( initNetworking () == -1) return -1; |
---|
99 | printf("> Initializing resources\n"); |
---|
100 | if( initResources () == -1) return -1; |
---|
101 | //printf("> Initializing world\n"); |
---|
102 | //if( init_world () == -1) return -1; PB: world will be initialized when started |
---|
103 | |
---|
104 | return 0; |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | \brief initializes SDL and OpenGL |
---|
109 | */ |
---|
110 | int Orxonox::initVideo() |
---|
111 | { |
---|
112 | printf("> Initializing video\n"); |
---|
113 | if (SDL_Init(SDL_INIT_VIDEO) == -1) |
---|
114 | { |
---|
115 | printf ("could not initialize SDL Video\n"); |
---|
116 | return -1; |
---|
117 | } |
---|
118 | // Set video mode |
---|
119 | // TO DO: parse arguments for settings |
---|
120 | //SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
---|
121 | //SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); |
---|
122 | //SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
---|
123 | //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); |
---|
124 | |
---|
125 | |
---|
126 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
---|
127 | SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16); |
---|
128 | SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); |
---|
129 | SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0); |
---|
130 | SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0); |
---|
131 | SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0); |
---|
132 | SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0); |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | int bpp = 16; |
---|
137 | int width = 640; |
---|
138 | int height = 480; |
---|
139 | //Uint32 flags = SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER; /* \todo: SDL_OPENGL doen't permit to load images*/ |
---|
140 | //Uint32 flags = SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER; |
---|
141 | |
---|
142 | Uint32 videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE; |
---|
143 | |
---|
144 | /* query SDL for information about our video hardware */ |
---|
145 | const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo (); |
---|
146 | |
---|
147 | if( videoInfo == NULL) |
---|
148 | { |
---|
149 | printf ("Orxonox::initVideo() - Failed getting Video Info :%s\n", SDL_GetError()); |
---|
150 | SDL_Quit (); |
---|
151 | } |
---|
152 | if( videoInfo->hw_available) |
---|
153 | videoFlags |= SDL_HWSURFACE; |
---|
154 | else |
---|
155 | videoFlags |= SDL_SWSURFACE; |
---|
156 | /* |
---|
157 | if(VideoInfo -> blit_hw) |
---|
158 | VideoFlags |= SDL_HWACCEL; |
---|
159 | */ |
---|
160 | |
---|
161 | if((this->screen = SDL_SetVideoMode (width, height, bpp, videoFlags)) == NULL) |
---|
162 | { |
---|
163 | printf("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", width, height, bpp, videoFlags, SDL_GetError()); |
---|
164 | SDL_Quit(); |
---|
165 | return -1; |
---|
166 | } |
---|
167 | |
---|
168 | // Set window labeling |
---|
169 | SDL_WM_SetCaption ("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION); |
---|
170 | |
---|
171 | // TO DO: Create a cool icon and use it here |
---|
172 | // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); |
---|
173 | |
---|
174 | return 0; |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | /** |
---|
179 | \brief initializes the sound engine |
---|
180 | */ |
---|
181 | int Orxonox::initSound() |
---|
182 | { |
---|
183 | printf("> Initializing sound\n"); |
---|
184 | // SDL_Init(SDL_INIT_AUDIO); |
---|
185 | printf("Not yet implemented\n"); |
---|
186 | return 0; |
---|
187 | } |
---|
188 | |
---|
189 | |
---|
190 | /** |
---|
191 | \brief initializes input functions |
---|
192 | */ |
---|
193 | int Orxonox::initInput() |
---|
194 | { |
---|
195 | // create localinput |
---|
196 | localinput = new CommandNode( configfilename); |
---|
197 | |
---|
198 | return 0; |
---|
199 | } |
---|
200 | |
---|
201 | |
---|
202 | /** |
---|
203 | \brief initializes network system |
---|
204 | */ |
---|
205 | int Orxonox::initNetworking() |
---|
206 | { |
---|
207 | printf("Not yet implemented\n"); |
---|
208 | return 0; |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | /** |
---|
213 | \brief initializes and loads resource files |
---|
214 | */ |
---|
215 | int Orxonox::initResources() |
---|
216 | { |
---|
217 | printf("Not yet implemented\n"); |
---|
218 | return 0; |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | /** |
---|
223 | \brief initializes the world |
---|
224 | */ |
---|
225 | int Orxonox::initWorld() |
---|
226 | { |
---|
227 | //world = new World(); |
---|
228 | |
---|
229 | // TO DO: replace this with a menu/intro |
---|
230 | //world->load_debug_level(); |
---|
231 | |
---|
232 | return 0; |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | /** |
---|
237 | \brief starts the orxonox game or menu |
---|
238 | |
---|
239 | here is the central orxonox state manager. There are currently two states |
---|
240 | - menu |
---|
241 | - game-play |
---|
242 | both states manage their states themselfs again. |
---|
243 | */ |
---|
244 | void Orxonox::start() |
---|
245 | { |
---|
246 | |
---|
247 | this->gameLoader = GameLoader::getInstance(); |
---|
248 | this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
---|
249 | this->gameLoader->init(); |
---|
250 | this->gameLoader->start(); |
---|
251 | } |
---|
252 | |
---|
253 | |
---|
254 | /** |
---|
255 | \brief exits Orxonox |
---|
256 | */ |
---|
257 | void Orxonox::quitGame() |
---|
258 | { |
---|
259 | bQuitOrxonox = true; |
---|
260 | } |
---|
261 | |
---|
262 | |
---|
263 | |
---|
264 | /** |
---|
265 | \brief handles sprecial events from localinput |
---|
266 | \param event: an event not handled by the CommandNode |
---|
267 | */ |
---|
268 | void Orxonox::eventHandler(SDL_Event* event) |
---|
269 | { |
---|
270 | // Handle special events such as reshape, quit, focus changes |
---|
271 | } |
---|
272 | |
---|
273 | |
---|
274 | /** |
---|
275 | \brief handle keyboard commands that are not meant for WorldEntities |
---|
276 | \param cmd: the command to handle |
---|
277 | \return true if the command was handled by the system or false if it may be passed to the WorldEntities |
---|
278 | */ |
---|
279 | bool Orxonox::systemCommand(Command* cmd) |
---|
280 | { |
---|
281 | /* |
---|
282 | if( !strcmp( cmd->cmd, "quit")) |
---|
283 | { |
---|
284 | if( !cmd->bUp) this->gameLoader->stop(); |
---|
285 | return true; |
---|
286 | } |
---|
287 | return false; |
---|
288 | */ |
---|
289 | return false; |
---|
290 | } |
---|
291 | |
---|
292 | |
---|
293 | /** |
---|
294 | \brief retrieve a pointer to the local Camera |
---|
295 | \return a pointer to localcamera |
---|
296 | */ |
---|
297 | Camera* Orxonox::getCamera() |
---|
298 | { |
---|
299 | return localcamera; |
---|
300 | } |
---|
301 | |
---|
302 | |
---|
303 | /** |
---|
304 | \brief retrieve a pointer to the local CommandNode |
---|
305 | \return a pointer to localinput |
---|
306 | */ |
---|
307 | CommandNode* Orxonox::getLocalInput() |
---|
308 | { |
---|
309 | return localinput; |
---|
310 | } |
---|
311 | |
---|
312 | |
---|
313 | /** |
---|
314 | \brief retrieve a pointer to the local World |
---|
315 | \return a pointer to world |
---|
316 | */ |
---|
317 | World* Orxonox::getWorld() |
---|
318 | { |
---|
319 | return world; |
---|
320 | } |
---|
321 | |
---|
322 | /** |
---|
323 | \return The reference of the SDL-screen of orxonox |
---|
324 | */ |
---|
325 | SDL_Surface* Orxonox::getScreen () |
---|
326 | { |
---|
327 | return this->screen; |
---|
328 | } |
---|
329 | |
---|
330 | /** |
---|
331 | \brief main function |
---|
332 | |
---|
333 | here the journey begins |
---|
334 | */ |
---|
335 | int main(int argc, char** argv) |
---|
336 | { |
---|
337 | printf(">>> Starting Orxonox <<<\n"); |
---|
338 | Orxonox *orx = Orxonox::getInstance(); |
---|
339 | |
---|
340 | if((*orx).init(argc, argv) == -1) |
---|
341 | { |
---|
342 | printf("! Orxonox initialization failed\n"); |
---|
343 | return -1; |
---|
344 | } |
---|
345 | |
---|
346 | orx->start(); |
---|
347 | |
---|
348 | //delete orx; |
---|
349 | |
---|
350 | return 0; |
---|
351 | } |
---|