Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: some more classes now destroy themselves via virtual-destructors and call to predecessing destroy-function
also made
#include "stdincl.h" out of unnecessary h-files, so we got faster compile time.

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