Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelloader/src/orxonox.cc @ 3715

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

orxonox/trunk: merged trunk back to levelloader
merged with command:
svn merge -r 3499:HEAD trunk branches/levelloader

Conflicts in
C track_manager.h
C world_entities/player.cc
C world_entities/player.h
C world_entities/environment.h
C lib/coord/p_node.cc
C defs/debug.h
C track_manager.cc
C story_entities/campaign.h

solved in merge-favouring. It was quite easy because Chris only worked on the headers, and he didi it quite clean. Thats the spirit :)

Conflits in world.cc are a MESS: fix it

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