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
RevLine 
[1850]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
[1855]20
21   ### File Specific:
22   main-programmer: Patrick Boenzli
[2190]23   co-programmer: Christian Meyer
[1850]24*/
25
[2190]26#include "orxonox.h"
[2036]27#include "world.h"
[2190]28#include "camera.h"
[2036]29#include "data_tank.h"
[2190]30#include "command_node.h"
[2636]31#include "game_loader.h"
[2190]32#include <string.h>
[3398]33int verbose;
[2036]34
[1803]35using namespace std;
36
[2190]37/**
[2636]38   \brief create a new Orxonox
[2190]39*/
40Orxonox::Orxonox ()
[1872]41{
42  pause = false;
43}
[1803]44
[2190]45/**
[2636]46   \brief remove Orxonox from memory
[2190]47*/
[1875]48Orxonox::~Orxonox () 
[2190]49{
[3543]50  this->destroy();
51}
52
53/**
54   \brief destroys orxonox. Frees al memory and so on.
55*/
56void Orxonox::destroy(void)
57{
[3226]58  Orxonox::singletonRef = NULL;
[2636]59  if( world != NULL) delete world;
60  if( localinput != NULL) delete world;
61  if( localcamera != NULL) delete localcamera;
62  if( resources != NULL) delete resources;
[3543]63
64 
[2190]65}
[1850]66
[3449]67/** \brief this is a singleton class to prevent duplicates */
[3226]68Orxonox* Orxonox::singletonRef = 0;
[1872]69
[3449]70/**
71   \returns reference or new Object of Orxonox if not existent.
72*/
[1850]73Orxonox* Orxonox::getInstance (void)
[1803]74{
[3226]75  if (singletonRef == NULL)
76    singletonRef = new Orxonox();
77  return singletonRef;
[1850]78}
79
[2190]80/**
[2636]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
[2190]86*/
[3226]87void Orxonox::getConfigFile (int argc, char** argv)
[1850]88{
[2636]89  strcpy (configfilename, "orxonox.conf");
[1803]90}
91
[2190]92/**
[2636]93   \brief initialize Orxonox with command line
[2190]94*/
95int Orxonox::init (int argc, char** argv)
[1803]96{
[2636]97  // parse command line
98  // config file
99 
[3226]100  getConfigFile (argc, argv);
[3174]101  SDL_Init (SDL_INIT_TIMER);
[2636]102  // initialize everything
[3226]103  if( initVideo() == -1) return -1;
104  if( initSound() == -1) return -1;
[2190]105  printf("> Initializing input\n");
[3226]106  if( initInput() == -1) return -1;
[2190]107  printf("> Initializing networking\n");
[3226]108  if( initNetworking () == -1) return -1;
[2190]109  printf("> Initializing resources\n");
[3226]110  if( initResources () == -1) return -1;
[2636]111  //printf("> Initializing world\n");
112  //if( init_world () == -1) return -1; PB: world will be initialized when started
113 
114  return 0;
[1850]115}
[1849]116
[2190]117/**
[2636]118   \brief initializes SDL and OpenGL
[2190]119*/
[3226]120int Orxonox::initVideo() 
[2190]121{
[3174]122  printf("> Initializing video\n");
[3226]123  if (SDL_Init(SDL_INIT_VIDEO) == -1)
[3174]124    {
125      printf ("could not initialize SDL Video\n");
126      return -1;
127    }
[2190]128  // Set video mode
129  // TO DO: parse arguments for settings
[3365]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);
[2190]134 
[3365]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
[2190]146  int bpp = 16;
147  int width = 640;
148  int height = 480;
[3365]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 ();
[2190]156 
[3365]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)
[2190]172  {
[3365]173    printf("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", width, height, bpp, videoFlags, SDL_GetError());
[2190]174    SDL_Quit();
175    return -1;
176  }
177 
178  // Set window labeling
[3365]179  SDL_WM_SetCaption ("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION);
[2190]180 
181  // TO DO: Create a cool icon and use it here
182  // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); 
[1850]183
[2190]184  return 0;
185}
[1850]186
[3214]187
[2190]188/**
[2636]189   \brief initializes the sound engine
[2190]190*/
[3226]191int Orxonox::initSound() 
[2190]192{
[3174]193  printf("> Initializing sound\n");
[3226]194  // SDL_Init(SDL_INIT_AUDIO);
[2636]195  printf("Not yet implemented\n");
196  return 0;
[2190]197}
[1900]198
[3214]199
[2190]200/**
[2636]201   \brief initializes input functions
[2190]202*/
[3226]203int Orxonox::initInput() 
[2190]204{
[2636]205  // create localinput
206  localinput = new CommandNode( configfilename);
207 
208  return 0;
[1803]209}
210
[3214]211
[2190]212/**
[2636]213   \brief initializes network system
[2190]214*/
[3226]215int Orxonox::initNetworking() 
[1897]216{
[2636]217  printf("Not yet implemented\n");
218  return 0;
[1897]219}
220
[3214]221
[2190]222/**
[2636]223   \brief initializes and loads resource files
[2190]224*/
[3226]225int Orxonox::initResources() 
[1858]226{
[2636]227  printf("Not yet implemented\n");
228  return 0;
[1858]229}
[1849]230
[3214]231
[2190]232/**
[2636]233   \brief initializes the world
[2190]234*/
[3226]235int Orxonox::initWorld() 
[1896]236{
[2636]237  //world = new World();
238 
239  // TO DO: replace this with a menu/intro
240  //world->load_debug_level();
241 
242  return 0;
[1896]243}
244
[2636]245
[2190]246/**
[2636]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.
[2190]253*/
[2636]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
[3214]263
[2636]264/**
265   \brief exits Orxonox
266*/
[1875]267void Orxonox::quitGame() 
268{
[2636]269  bQuitOrxonox = true;
[1875]270}
271
272
[3214]273
[2190]274/**
[2636]275   \brief handles sprecial events from localinput
276   \param event: an event not handled by the CommandNode
[2190]277*/
[3226]278void Orxonox::eventHandler(SDL_Event* event)
[2190]279{
[2636]280  // Handle special events such as reshape, quit, focus changes
[2190]281}
[3214]282 
[1875]283
[2190]284/**
[2636]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
[2190]288*/
[3226]289bool Orxonox::systemCommand(Command* cmd)
[2190]290{
[3220]291  /*
[2636]292  if( !strcmp( cmd->cmd, "quit"))
293    {
294      if( !cmd->bUp) this->gameLoader->stop();
295      return true;
296    }
297  return false;
[3220]298  */
299  return false;
[2190]300}
[1803]301
[1850]302
[2190]303/**
[2636]304   \brief retrieve a pointer to the local Camera
305   \return a pointer to localcamera
[2190]306*/
[3226]307Camera* Orxonox::getCamera()
[1872]308{
[2636]309  return localcamera;
[1872]310}
[1850]311
[3214]312
[2190]313/**
[2636]314   \brief retrieve a pointer to the local CommandNode
315   \return a pointer to localinput
[2190]316*/
[3226]317CommandNode* Orxonox::getLocalInput()
[1850]318{
[2636]319  return localinput;
[1803]320}
321
[3214]322
[2190]323/**
[2636]324   \brief retrieve a pointer to the local World
325   \return a pointer to world
[2190]326*/
[3226]327World* Orxonox::getWorld()
[1872]328{
[2636]329  return world;
[1872]330}
[1850]331
[3449]332/**
333   \return The reference of the SDL-screen of orxonox
334*/
[3365]335SDL_Surface* Orxonox::getScreen ()
336{
337  return this->screen;
338}
[3214]339
[3449]340/**
341   \brief main function
[3214]342
[3449]343   here the journey begins
344*/
[3226]345int main(int argc, char** argv) 
[1803]346{ 
[2636]347  printf(">>> Starting Orxonox <<<\n");
[1850]348  Orxonox *orx = Orxonox::getInstance();
[2190]349 
[3226]350  if((*orx).init(argc, argv) == -1)
[2636]351    {
352      printf("! Orxonox initialization failed\n");
353      return -1;
354    }
355 
356  orx->start();
357 
[2190]358  //delete orx;
359 
[1803]360  return 0;
361}
Note: See TracBrowser for help on using the repository browser.