Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/orxonox.cc @ 3214

Last change on this file since 3214 was 3214, checked in by patrick, 19 years ago

orxonox/trunk: cleaned up orxonox.cc, deleted unused code

File size: 7.0 KB
Line 
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
34using namespace std;
35
36/**
37   \brief create a new Orxonox
38*/
39Orxonox::Orxonox ()
40{
41  pause = false;
42}
43
44/**
45   \brief remove Orxonox from memory
46*/
47Orxonox::~Orxonox () 
48{
49  Orxonox::singleton_ref = NULL;
50  if( world != NULL) delete world;
51  if( localinput != NULL) delete world;
52  if( localcamera != NULL) delete localcamera;
53  if( resources != NULL) delete resources;
54}
55
56
57/* this is a singleton class to prevent duplicates */
58Orxonox* Orxonox::singleton_ref = 0;
59
60Orxonox* Orxonox::getInstance (void)
61{
62  if (singleton_ref == NULL)
63    singleton_ref = new Orxonox();
64  return singleton_ref;
65}
66
67/**
68   \brief this finds the config file
69   
70   Since the config file varies from user to user and since one may want to specify different config files
71   for certain occasions or platforms this function finds the right config file for every occasion and stores
72   it's path and name into configfilename
73*/
74void Orxonox::get_config_file (int argc, char** argv)
75{
76  strcpy (configfilename, "orxonox.conf");
77}
78
79/**
80   \brief initialize Orxonox with command line
81*/
82int Orxonox::init (int argc, char** argv)
83{
84  // parse command line
85  // config file
86 
87  get_config_file (argc, argv);
88  SDL_Init (SDL_INIT_TIMER);
89  // initialize everything
90  if( init_video () == -1) return -1;
91  if( init_sound () == -1) return -1;
92  printf("> Initializing input\n");
93  if( init_input () == -1) return -1;
94  printf("> Initializing networking\n");
95  if( init_networking () == -1) return -1;
96  printf("> Initializing resources\n");
97  if( init_resources () == -1) return -1;
98  //printf("> Initializing world\n");
99  //if( init_world () == -1) return -1; PB: world will be initialized when started
100 
101  return 0;
102}
103
104/**
105   \brief initializes SDL and OpenGL
106*/
107int Orxonox::init_video () 
108{
109  printf("> Initializing video\n");
110  if (SDL_Init (SDL_INIT_VIDEO) == -1)
111    {
112      printf ("could not initialize SDL Video\n");
113      return -1;
114    }
115  // Set video mode
116  // TO DO: parse arguments for settings
117  SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 5);
118  SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5);
119  SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5);
120  SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16);
121 
122  int bpp = 16;
123  int width = 640;
124  int height = 480;
125  Uint32 flags = SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
126 
127  if( (screen = SDL_SetVideoMode (width, height, bpp, flags)) == NULL)
128  {
129    printf ("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", width, height, bpp, flags, SDL_GetError());
130    SDL_Quit();
131    return -1;
132  }
133 
134  // Set window labeling
135  SDL_WM_SetCaption( "Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION);
136 
137  // TO DO: Create a cool icon and use it here
138  // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); 
139
140  // OpenGL stuff
141  // (Is this all we initialize globally???)
142  glClearColor(0.0, 0.0, 0.0, 0.0);
143  glEnable(GL_DEPTH_TEST);
144 
145  // LIGHTING
146  GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0};
147  GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0};
148  GLfloat lightPosition[] = {10.0, 10, 19.0, 0.0};
149
150  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
151  glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight);
152  glEnable(GL_LIGHTING);
153  glEnable(GL_LIGHT0);
154  glEnable(GL_DEPTH_TEST);
155  glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
156  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
157   
158  //  glEnable(GL_COLOR);
159  //  glShadeModel(GL_SMOOTH);
160 
161  // create camera
162  //localcamera = new Camera(world); /* \todo camera/input node not used anymore*/
163 
164  return 0;
165}
166
167
168/**
169   \brief initializes the sound engine
170*/
171int Orxonox::init_sound () 
172{
173  printf("> Initializing sound\n");
174  // SDL_Init (SDL_INIT_AUDIO);
175  printf("Not yet implemented\n");
176  return 0;
177}
178
179
180/**
181   \brief initializes input functions
182*/
183int Orxonox::init_input () 
184{
185  // create localinput
186  localinput = new CommandNode( configfilename);
187 
188  return 0;
189}
190
191
192/**
193   \brief initializes network system
194*/
195int Orxonox::init_networking () 
196{
197  printf("Not yet implemented\n");
198  return 0;
199}
200
201
202/**
203   \brief initializes and loads resource files
204*/
205int Orxonox::init_resources () 
206{
207  printf("Not yet implemented\n");
208  return 0;
209}
210
211
212/**
213   \brief initializes the world
214*/
215int Orxonox::init_world () 
216{
217  //world = new World();
218 
219  // TO DO: replace this with a menu/intro
220  //world->load_debug_level();
221 
222  return 0;
223}
224
225
226/**
227   \brief starts the orxonox game or menu
228
229   here is the central orxonox state manager. There are currently two states
230   - menu
231   - game-play
232   both states manage their states themselfs again.
233*/
234void Orxonox::start()
235{
236 
237  this->gameLoader = GameLoader::getInstance();
238  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
239  this->gameLoader->init();
240  this->gameLoader->start();
241}
242
243
244/**
245   \brief exits Orxonox
246*/
247void Orxonox::quitGame() 
248{
249  bQuitOrxonox = true;
250}
251
252
253
254/**
255   \brief handles sprecial events from localinput
256   \param event: an event not handled by the CommandNode
257*/
258void Orxonox::event_handler (SDL_Event* event)
259{
260  // Handle special events such as reshape, quit, focus changes
261}
262 
263
264/**
265   \brief handle keyboard commands that are not meant for WorldEntities
266   \param cmd: the command to handle
267   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
268*/
269bool Orxonox::system_command (Command* cmd)
270{
271  if( !strcmp( cmd->cmd, "quit"))
272    {
273      if( !cmd->bUp) this->gameLoader->stop();
274      return true;
275    }
276  return false;
277}
278
279
280/**
281   \brief retrieve a pointer to the local Camera
282   \return a pointer to localcamera
283*/
284Camera* Orxonox::get_camera ()
285{
286  return localcamera;
287}
288
289
290/**
291   \brief retrieve a pointer to the local CommandNode
292   \return a pointer to localinput
293*/
294CommandNode* Orxonox::get_localinput ()
295{
296  return localinput;
297}
298
299
300/**
301   \brief retrieve a pointer to the local World
302   \return a pointer to world
303*/
304World* Orxonox::get_world ()
305{
306  return world;
307}
308
309
310
311
312int main (int argc, char** argv) 
313{ 
314  printf(">>> Starting Orxonox <<<\n");
315  Orxonox *orx = Orxonox::getInstance();
316 
317  if( (*orx).init(argc, argv) == -1)
318    {
319      printf("! Orxonox initialization failed\n");
320      return -1;
321    }
322 
323  //(*orx).mainLoop();
324
325  orx->start();
326 
327  //delete orx;
328 
329  return 0;
330}
Note: See TracBrowser for help on using the repository browser.