Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3448 was 3436, checked in by bensch, 20 years ago

orxonox/trunk: added new Class light, that handles lights (needed for Bump-mapping).
Because Light is very important in 3D, I have created this Class

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