Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/dave/src/orxonox.cc @ 3542

Last change on this file since 3542 was 3410, checked in by dave, 20 years ago

branches/dave/src: Ok, Himmel heller gemacht in orxonox.cc durch hinzufuegen eine Lichquelle, zusaetzlich Himmel noch ein wenig gedreht

File size: 8.4 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::singletonRef = 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::singletonRef = 0;
59
60Orxonox* Orxonox::getInstance (void)
61{
62  if (singletonRef == NULL)
63    singletonRef = new Orxonox();
64  return singletonRef;
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::getConfigFile (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  getConfigFile (argc, argv);
88  SDL_Init (SDL_INIT_TIMER);
89  // initialize everything
90  if( initVideo() == -1) return -1;
91  if( initSound() == -1) return -1;
92  printf("> Initializing input\n");
93  if( initInput() == -1) return -1;
94  printf("> Initializing networking\n");
95  if( initNetworking () == -1) return -1;
96  printf("> Initializing resources\n");
97  if( initResources () == -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::initVideo() 
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
123  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );   
124  SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);   
125  SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); 
126  SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0);
127  SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0);
128  SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0);
129  SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0);
130
131
132
133  int bpp = 16;
134  int width = 640;
135  int height = 480;
136  //Uint32 flags = SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER; /* \todo: SDL_OPENGL doen't permit to load images*/
137  //Uint32 flags = SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER;
138
139  Uint32 videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE;
140
141  /* query SDL for information about our video hardware */
142  const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo ();
143 
144  if( videoInfo == NULL)
145    {
146      printf ("Orxonox::initVideo() - Failed getting Video Info :%s\n", SDL_GetError()); 
147      SDL_Quit ();
148    }
149  if( videoInfo->hw_available)
150    videoFlags |= SDL_HWSURFACE;
151  else 
152    videoFlags |= SDL_SWSURFACE;
153  /*
154  if(VideoInfo -> blit_hw)                           
155    VideoFlags |= SDL_HWACCEL;
156  */
157 
158  if((this->screen = SDL_SetVideoMode (width, height, bpp, videoFlags)) == NULL)
159  {
160    printf("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", width, height, bpp, videoFlags, SDL_GetError());
161    SDL_Quit();
162    return -1;
163  }
164 
165  // Set window labeling
166  SDL_WM_SetCaption ("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION);
167 
168  // TO DO: Create a cool icon and use it here
169  // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); 
170
171  // OpenGL stuff
172  glClearColor (0.0, 0.0, 0.0, 0.0);
173  glEnable (GL_DEPTH_TEST);
174 
175  // LIGHTING
176  GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0};
177  GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0};
178  GLfloat brightLight[]={2.0,2.0,2.0,1.0};
179  GLfloat lightPosition[] = {10.0, 10, 19.0, 0.0};
180  GLfloat lightPosition2[]={ 180.0,-20.0,-30.0,0.0};
181
182  glLightfv (GL_LIGHT0, GL_DIFFUSE, whiteLight);
183  glLightfv (GL_LIGHT0, GL_SPECULAR, whiteLight);
184  glLightfv (GL_LIGHT1, GL_DIFFUSE, brightLight);
185  glLightfv (GL_LIGHT1, GL_SPECULAR, brightLight);
186  glEnable (GL_LIGHTING);
187  glEnable (GL_LIGHT0);
188  glEnable (GL_LIGHT1);
189  glEnable (GL_DEPTH_TEST);
190  glLightfv (GL_LIGHT0, GL_POSITION, lightPosition);
191  glLightfv (GL_LIGHT1, GL_POSITION, lightPosition2);
192  //glLightfv (GL_LIGHT0, GL_DIFFUSE, whiteLight);
193  //glLightfv (GL_LIGHT1, GL_D, brightLight); 
194  //glEnable (GL_TEXTURE_2D);
195  //  glEnable(GL_COLOR);
196  //  glShadeModel(GL_SMOOTH);
197 
198  // create camera
199  //localcamera = new Camera(world); /* \todo camera/input node not used anymore*/
200 
201  return 0;
202}
203
204
205/**
206   \brief initializes the sound engine
207*/
208int Orxonox::initSound() 
209{
210  printf("> Initializing sound\n");
211  // SDL_Init(SDL_INIT_AUDIO);
212  printf("Not yet implemented\n");
213  return 0;
214}
215
216
217/**
218   \brief initializes input functions
219*/
220int Orxonox::initInput() 
221{
222  // create localinput
223  localinput = new CommandNode( configfilename);
224 
225  return 0;
226}
227
228
229/**
230   \brief initializes network system
231*/
232int Orxonox::initNetworking() 
233{
234  printf("Not yet implemented\n");
235  return 0;
236}
237
238
239/**
240   \brief initializes and loads resource files
241*/
242int Orxonox::initResources() 
243{
244  printf("Not yet implemented\n");
245  return 0;
246}
247
248
249/**
250   \brief initializes the world
251*/
252int Orxonox::initWorld() 
253{
254  //world = new World();
255 
256  // TO DO: replace this with a menu/intro
257  //world->load_debug_level();
258 
259  return 0;
260}
261
262
263/**
264   \brief starts the orxonox game or menu
265
266   here is the central orxonox state manager. There are currently two states
267   - menu
268   - game-play
269   both states manage their states themselfs again.
270*/
271void Orxonox::start()
272{
273 
274  this->gameLoader = GameLoader::getInstance();
275  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
276  this->gameLoader->init();
277  this->gameLoader->start();
278}
279
280
281/**
282   \brief exits Orxonox
283*/
284void Orxonox::quitGame() 
285{
286  bQuitOrxonox = true;
287}
288
289
290
291/**
292   \brief handles sprecial events from localinput
293   \param event: an event not handled by the CommandNode
294*/
295void Orxonox::eventHandler(SDL_Event* event)
296{
297  // Handle special events such as reshape, quit, focus changes
298}
299 
300
301/**
302   \brief handle keyboard commands that are not meant for WorldEntities
303   \param cmd: the command to handle
304   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
305*/
306bool Orxonox::systemCommand(Command* cmd)
307{
308  /*
309  if( !strcmp( cmd->cmd, "quit"))
310    {
311      if( !cmd->bUp) this->gameLoader->stop();
312      return true;
313    }
314  return false;
315  */
316  return false;
317}
318
319
320/**
321   \brief retrieve a pointer to the local Camera
322   \return a pointer to localcamera
323*/
324Camera* Orxonox::getCamera()
325{
326  return localcamera;
327}
328
329
330/**
331   \brief retrieve a pointer to the local CommandNode
332   \return a pointer to localinput
333*/
334CommandNode* Orxonox::getLocalInput()
335{
336  return localinput;
337}
338
339
340/**
341   \brief retrieve a pointer to the local World
342   \return a pointer to world
343*/
344World* Orxonox::getWorld()
345{
346  return world;
347}
348
349
350SDL_Surface* Orxonox::getScreen ()
351{
352  return this->screen;
353}
354
355
356int main(int argc, char** argv) 
357{ 
358  printf(">>> Starting Orxonox <<<\n");
359  Orxonox *orx = Orxonox::getInstance();
360 
361  if((*orx).init(argc, argv) == -1)
362    {
363      printf("! Orxonox initialization failed\n");
364      return -1;
365    }
366 
367  orx->start();
368 
369  //delete orx;
370 
371  return 0;
372}
Note: See TracBrowser for help on using the repository browser.