Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/nico/src/orxonox.cc @ 3659

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

orxonox/branches/nico: merged trunk into branches/nico
merged with command:
svn merge ../trunk/ nico/ -r 3238:HEAD
resolved conflict in favor of branches/nico.

File size: 8.1 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>
[3399]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{
[3238]50  Orxonox::singletonRef = NULL;
[2636]51  if( world != NULL) delete world;
52  if( localinput != NULL) delete world;
53  if( localcamera != NULL) delete localcamera;
54  if( resources != NULL) delete resources;
[2190]55}
[1850]56
57
[2190]58/* this is a singleton class to prevent duplicates */
[3238]59Orxonox* Orxonox::singletonRef = 0;
[1872]60
[1850]61Orxonox* Orxonox::getInstance (void)
[1803]62{
[3238]63  if (singletonRef == NULL)
64    singletonRef = new Orxonox();
65  return singletonRef;
[1850]66}
67
[2190]68/**
[2636]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
[2190]74*/
[3238]75void Orxonox::getConfigFile (int argc, char** argv)
[1850]76{
[2636]77  strcpy (configfilename, "orxonox.conf");
[1803]78}
79
[2190]80/**
[2636]81   \brief initialize Orxonox with command line
[2190]82*/
83int Orxonox::init (int argc, char** argv)
[1803]84{
[2636]85  // parse command line
86  // config file
87 
[3238]88  getConfigFile (argc, argv);
89  SDL_Init (SDL_INIT_TIMER);
[2636]90  // initialize everything
[3238]91  if( initVideo() == -1) return -1;
92  if( initSound() == -1) return -1;
[2190]93  printf("> Initializing input\n");
[3238]94  if( initInput() == -1) return -1;
[2190]95  printf("> Initializing networking\n");
[3238]96  if( initNetworking () == -1) return -1;
[2190]97  printf("> Initializing resources\n");
[3238]98  if( initResources () == -1) return -1;
[2636]99  //printf("> Initializing world\n");
100  //if( init_world () == -1) return -1; PB: world will be initialized when started
101 
102  return 0;
[1850]103}
[1849]104
[2190]105/**
[2636]106   \brief initializes SDL and OpenGL
[2190]107*/
[3238]108int Orxonox::initVideo() 
[2190]109{
[3238]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    }
[2190]116  // Set video mode
117  // TO DO: parse arguments for settings
[3399]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);
[2190]122 
[3399]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
[2190]134  int bpp = 16;
135  int width = 640;
136  int height = 480;
[3399]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 ();
[2190]144 
[3399]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)
[2190]160  {
[3399]161    printf("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", width, height, bpp, videoFlags, SDL_GetError());
[2190]162    SDL_Quit();
163    return -1;
164  }
165 
166  // Set window labeling
[3399]167  SDL_WM_SetCaption ("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION);
[2190]168 
169  // TO DO: Create a cool icon and use it here
170  // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); 
[1850]171
[2190]172  // OpenGL stuff
[3399]173  glClearColor (0.0, 0.0, 0.0, 0.0);
174  glEnable (GL_DEPTH_TEST);
[2817]175 
176  // LIGHTING
177  GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0};
178  GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0};
179  GLfloat lightPosition[] = {10.0, 10, 19.0, 0.0};
180
[3399]181  glLightfv (GL_LIGHT0, GL_DIFFUSE, whiteLight);
182  glLightfv (GL_LIGHT0, GL_SPECULAR, whiteLight);
183  glEnable (GL_LIGHTING);
184  glEnable (GL_LIGHT0);
185  glEnable (GL_DEPTH_TEST);
186  glLightfv (GL_LIGHT0, GL_POSITION, lightPosition);
187  glLightfv (GL_LIGHT0, GL_DIFFUSE, whiteLight);
[2817]188   
[3399]189  //glEnable (GL_TEXTURE_2D);
[2792]190  //  glEnable(GL_COLOR);
191  //  glShadeModel(GL_SMOOTH);
[1899]192 
[2190]193  // create camera
[3238]194  //localcamera = new Camera(world); /* \todo camera/input node not used anymore*/
[2190]195 
196  return 0;
197}
[1850]198
[3238]199
[2190]200/**
[2636]201   \brief initializes the sound engine
[2190]202*/
[3238]203int Orxonox::initSound() 
[2190]204{
[3238]205  printf("> Initializing sound\n");
206  // SDL_Init(SDL_INIT_AUDIO);
[2636]207  printf("Not yet implemented\n");
208  return 0;
[2190]209}
[1900]210
[3238]211
[2190]212/**
[2636]213   \brief initializes input functions
[2190]214*/
[3238]215int Orxonox::initInput() 
[2190]216{
[2636]217  // create localinput
218  localinput = new CommandNode( configfilename);
219 
220  return 0;
[1803]221}
222
[3238]223
[2190]224/**
[2636]225   \brief initializes network system
[2190]226*/
[3238]227int Orxonox::initNetworking() 
[1897]228{
[2636]229  printf("Not yet implemented\n");
230  return 0;
[1897]231}
232
[3238]233
[2190]234/**
[2636]235   \brief initializes and loads resource files
[2190]236*/
[3238]237int Orxonox::initResources() 
[1858]238{
[2636]239  printf("Not yet implemented\n");
240  return 0;
[1858]241}
[1849]242
[3238]243
[2190]244/**
[2636]245   \brief initializes the world
[2190]246*/
[3238]247int Orxonox::initWorld() 
[1896]248{
[2636]249  //world = new World();
250 
251  // TO DO: replace this with a menu/intro
252  //world->load_debug_level();
253 
254  return 0;
[1896]255}
256
[2636]257
[2190]258/**
[2636]259   \brief starts the orxonox game or menu
260
261   here is the central orxonox state manager. There are currently two states
262   - menu
263   - game-play
264   both states manage their states themselfs again.
[2190]265*/
[2636]266void Orxonox::start()
267{
268 
269  this->gameLoader = GameLoader::getInstance();
270  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
271  this->gameLoader->init();
272  this->gameLoader->start();
273}
274
[3238]275
[2636]276/**
277   \brief exits Orxonox
278*/
[1875]279void Orxonox::quitGame() 
280{
[2636]281  bQuitOrxonox = true;
[1875]282}
283
284
[3238]285
[2190]286/**
[2636]287   \brief handles sprecial events from localinput
288   \param event: an event not handled by the CommandNode
[2190]289*/
[3238]290void Orxonox::eventHandler(SDL_Event* event)
[2190]291{
[2636]292  // Handle special events such as reshape, quit, focus changes
[2190]293}
[3238]294 
[1875]295
[2190]296/**
[2636]297   \brief handle keyboard commands that are not meant for WorldEntities
298   \param cmd: the command to handle
299   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
[2190]300*/
[3238]301bool Orxonox::systemCommand(Command* cmd)
[2190]302{
[3238]303  /*
[2636]304  if( !strcmp( cmd->cmd, "quit"))
305    {
306      if( !cmd->bUp) this->gameLoader->stop();
307      return true;
308    }
309  return false;
[3238]310  */
311  return false;
[2190]312}
[1803]313
[1850]314
[2190]315/**
[2636]316   \brief retrieve a pointer to the local Camera
317   \return a pointer to localcamera
[2190]318*/
[3238]319Camera* Orxonox::getCamera()
[1872]320{
[2636]321  return localcamera;
[1872]322}
[1850]323
[3238]324
[2190]325/**
[2636]326   \brief retrieve a pointer to the local CommandNode
327   \return a pointer to localinput
[2190]328*/
[3238]329CommandNode* Orxonox::getLocalInput()
[1850]330{
[2636]331  return localinput;
[1803]332}
333
[3238]334
[2190]335/**
[2636]336   \brief retrieve a pointer to the local World
337   \return a pointer to world
[2190]338*/
[3238]339World* Orxonox::getWorld()
[1872]340{
[2636]341  return world;
[1872]342}
[1850]343
[3238]344
[3399]345SDL_Surface* Orxonox::getScreen ()
346{
347  return this->screen;
348}
[3238]349
350
351int main(int argc, char** argv) 
[1803]352{ 
[2636]353  printf(">>> Starting Orxonox <<<\n");
[1850]354  Orxonox *orx = Orxonox::getInstance();
[2190]355 
[3238]356  if((*orx).init(argc, argv) == -1)
[2636]357    {
358      printf("! Orxonox initialization failed\n");
359      return -1;
360    }
361 
362  orx->start();
363 
[2190]364  //delete orx;
365 
[1803]366  return 0;
367}
Note: See TracBrowser for help on using the repository browser.