Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/shadows/src/orxonox.cc @ 4624

Last change on this file since 4624 was 4008, checked in by dave, 20 years ago

branches/shadows/src:Aufruf von createShadow() jetzt von einem anderen Ort, aber immer noch Problem dass Schatten noch nicht sichtbar, jedoch vorhanden

File size: 8.3 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{
[3226]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 */
[3226]59Orxonox* Orxonox::singletonRef = 0;
[1872]60
[1850]61Orxonox* Orxonox::getInstance (void)
[1803]62{
[3226]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*/
[3226]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 
[3226]88  getConfigFile (argc, argv);
[3174]89  SDL_Init (SDL_INIT_TIMER);
[2636]90  // initialize everything
[3226]91  if( initVideo() == -1) return -1;
92  if( initSound() == -1) return -1;
[2190]93  printf("> Initializing input\n");
[3226]94  if( initInput() == -1) return -1;
[2190]95  printf("> Initializing networking\n");
[3226]96  if( initNetworking () == -1) return -1;
[2190]97  printf("> Initializing resources\n");
[3226]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*/
[3226]108int Orxonox::initVideo() 
[2190]109{
[3174]110  printf("> Initializing video\n");
[3226]111  if (SDL_Init(SDL_INIT_VIDEO) == -1)
[3174]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
[3365]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 
[3365]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;
[4008]135  int width = 400;
136  int height = 300;
[3365]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 
[3365]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  {
[3365]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
[3365]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
[3365]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};
[3706]179  GLfloat lightPosition[] = {0.0, 10, 19.0, 0.0};
180  GLfloat lightPosition2[] ={50,10,0,0};
181 
[3365]182  glLightfv (GL_LIGHT0, GL_DIFFUSE, whiteLight);
183  glLightfv (GL_LIGHT0, GL_SPECULAR, whiteLight);
[3706]184  glLightfv(GL_LIGHT1,GL_SPECULAR,whiteLight);
[3365]185  glEnable (GL_LIGHTING);
186  glEnable (GL_LIGHT0);
[4008]187  //glEnable (GL_LIGHT1);
[3365]188  glEnable (GL_DEPTH_TEST);
189  glLightfv (GL_LIGHT0, GL_POSITION, lightPosition);
[3706]190  glLightfv (GL_LIGHT1, GL_POSITION, lightPosition2);
[3365]191  glLightfv (GL_LIGHT0, GL_DIFFUSE, whiteLight);
[3706]192  glLightfv (GL_LIGHT1, GL_DIFFUSE, whiteLight);
[2817]193   
[3365]194  //glEnable (GL_TEXTURE_2D);
[2792]195  //  glEnable(GL_COLOR);
196  //  glShadeModel(GL_SMOOTH);
[1899]197 
[2190]198  // create camera
[3213]199  //localcamera = new Camera(world); /* \todo camera/input node not used anymore*/
[2190]200 
201  return 0;
202}
[1850]203
[3214]204
[2190]205/**
[2636]206   \brief initializes the sound engine
[2190]207*/
[3226]208int Orxonox::initSound() 
[2190]209{
[3174]210  printf("> Initializing sound\n");
[3226]211  // SDL_Init(SDL_INIT_AUDIO);
[2636]212  printf("Not yet implemented\n");
213  return 0;
[2190]214}
[1900]215
[3214]216
[2190]217/**
[2636]218   \brief initializes input functions
[2190]219*/
[3226]220int Orxonox::initInput() 
[2190]221{
[2636]222  // create localinput
223  localinput = new CommandNode( configfilename);
224 
225  return 0;
[1803]226}
227
[3214]228
[2190]229/**
[2636]230   \brief initializes network system
[2190]231*/
[3226]232int Orxonox::initNetworking() 
[1897]233{
[2636]234  printf("Not yet implemented\n");
235  return 0;
[1897]236}
237
[3214]238
[2190]239/**
[2636]240   \brief initializes and loads resource files
[2190]241*/
[3226]242int Orxonox::initResources() 
[1858]243{
[2636]244  printf("Not yet implemented\n");
245  return 0;
[1858]246}
[1849]247
[3214]248
[2190]249/**
[2636]250   \brief initializes the world
[2190]251*/
[3226]252int Orxonox::initWorld() 
[1896]253{
[2636]254  //world = new World();
255 
256  // TO DO: replace this with a menu/intro
257  //world->load_debug_level();
258 
259  return 0;
[1896]260}
261
[2636]262
[2190]263/**
[2636]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.
[2190]270*/
[2636]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
[3214]280
[2636]281/**
282   \brief exits Orxonox
283*/
[1875]284void Orxonox::quitGame() 
285{
[2636]286  bQuitOrxonox = true;
[1875]287}
288
289
[3214]290
[2190]291/**
[2636]292   \brief handles sprecial events from localinput
293   \param event: an event not handled by the CommandNode
[2190]294*/
[3226]295void Orxonox::eventHandler(SDL_Event* event)
[2190]296{
[2636]297  // Handle special events such as reshape, quit, focus changes
[2190]298}
[3214]299 
[1875]300
[2190]301/**
[2636]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
[2190]305*/
[3226]306bool Orxonox::systemCommand(Command* cmd)
[2190]307{
[3220]308  /*
[2636]309  if( !strcmp( cmd->cmd, "quit"))
310    {
311      if( !cmd->bUp) this->gameLoader->stop();
312      return true;
313    }
314  return false;
[3220]315  */
316  return false;
[2190]317}
[1803]318
[1850]319
[2190]320/**
[2636]321   \brief retrieve a pointer to the local Camera
322   \return a pointer to localcamera
[2190]323*/
[3226]324Camera* Orxonox::getCamera()
[1872]325{
[2636]326  return localcamera;
[1872]327}
[1850]328
[3214]329
[2190]330/**
[2636]331   \brief retrieve a pointer to the local CommandNode
332   \return a pointer to localinput
[2190]333*/
[3226]334CommandNode* Orxonox::getLocalInput()
[1850]335{
[2636]336  return localinput;
[1803]337}
338
[3214]339
[2190]340/**
[2636]341   \brief retrieve a pointer to the local World
342   \return a pointer to world
[2190]343*/
[3226]344World* Orxonox::getWorld()
[1872]345{
[2636]346  return world;
[1872]347}
[1850]348
[3214]349
[3365]350SDL_Surface* Orxonox::getScreen ()
351{
352  return this->screen;
353}
[3214]354
355
[3226]356int main(int argc, char** argv) 
[1803]357{ 
[2636]358  printf(">>> Starting Orxonox <<<\n");
[1850]359  Orxonox *orx = Orxonox::getInstance();
[2190]360 
[3226]361  if((*orx).init(argc, argv) == -1)
[2636]362    {
363      printf("! Orxonox initialization failed\n");
364      return -1;
365    }
366 
367  orx->start();
368 
[2190]369  //delete orx;
370 
[1803]371  return 0;
372}
Note: See TracBrowser for help on using the repository browser.