Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3324 was 3226, checked in by bensch, 19 years ago

orxonox/trunk: world fixed (still unstable)

File size: 7.0 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>
[2036]33
[1803]34using namespace std;
35
[2190]36/**
[2636]37   \brief create a new Orxonox
[2190]38*/
39Orxonox::Orxonox ()
[1872]40{
41  pause = false;
42}
[1803]43
[2190]44/**
[2636]45   \brief remove Orxonox from memory
[2190]46*/
[1875]47Orxonox::~Orxonox () 
[2190]48{
[3226]49  Orxonox::singletonRef = NULL;
[2636]50  if( world != NULL) delete world;
51  if( localinput != NULL) delete world;
52  if( localcamera != NULL) delete localcamera;
53  if( resources != NULL) delete resources;
[2190]54}
[1850]55
56
[2190]57/* this is a singleton class to prevent duplicates */
[3226]58Orxonox* Orxonox::singletonRef = 0;
[1872]59
[1850]60Orxonox* Orxonox::getInstance (void)
[1803]61{
[3226]62  if (singletonRef == NULL)
63    singletonRef = new Orxonox();
64  return singletonRef;
[1850]65}
66
[2190]67/**
[2636]68   \brief this finds the config file
69   
70   Since the config file varies from user to user and since one may want to specify different config files
71   for certain occasions or platforms this function finds the right config file for every occasion and stores
72   it's path and name into configfilename
[2190]73*/
[3226]74void Orxonox::getConfigFile (int argc, char** argv)
[1850]75{
[2636]76  strcpy (configfilename, "orxonox.conf");
[1803]77}
78
[2190]79/**
[2636]80   \brief initialize Orxonox with command line
[2190]81*/
82int Orxonox::init (int argc, char** argv)
[1803]83{
[2636]84  // parse command line
85  // config file
86 
[3226]87  getConfigFile (argc, argv);
[3174]88  SDL_Init (SDL_INIT_TIMER);
[2636]89  // initialize everything
[3226]90  if( initVideo() == -1) return -1;
91  if( initSound() == -1) return -1;
[2190]92  printf("> Initializing input\n");
[3226]93  if( initInput() == -1) return -1;
[2190]94  printf("> Initializing networking\n");
[3226]95  if( initNetworking () == -1) return -1;
[2190]96  printf("> Initializing resources\n");
[3226]97  if( initResources () == -1) return -1;
[2636]98  //printf("> Initializing world\n");
99  //if( init_world () == -1) return -1; PB: world will be initialized when started
100 
101  return 0;
[1850]102}
[1849]103
[2190]104/**
[2636]105   \brief initializes SDL and OpenGL
[2190]106*/
[3226]107int Orxonox::initVideo() 
[2190]108{
[3174]109  printf("> Initializing video\n");
[3226]110  if (SDL_Init(SDL_INIT_VIDEO) == -1)
[3174]111    {
112      printf ("could not initialize SDL Video\n");
113      return -1;
114    }
[2190]115  // Set video mode
116  // TO DO: parse arguments for settings
[3226]117  SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
118  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
119  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
120  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
[2190]121 
122  int bpp = 16;
123  int width = 640;
124  int height = 480;
125  Uint32 flags = SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
126 
[3226]127  if((screen = SDL_SetVideoMode (width, height, bpp, flags)) == NULL)
[2190]128  {
[3226]129    printf("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", width, height, bpp, flags, SDL_GetError());
[2190]130    SDL_Quit();
131    return -1;
132  }
133 
134  // Set window labeling
[3226]135  SDL_WM_SetCaption("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION);
[2190]136 
137  // TO DO: Create a cool icon and use it here
138  // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); 
[1850]139
[2190]140  // OpenGL stuff
141  // (Is this all we initialize globally???)
[1872]142  glClearColor(0.0, 0.0, 0.0, 0.0);
[2190]143  glEnable(GL_DEPTH_TEST);
[2817]144 
145  // LIGHTING
146  GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0};
147  GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0};
148  GLfloat lightPosition[] = {10.0, 10, 19.0, 0.0};
149
150  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
151  glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight);
152  glEnable(GL_LIGHTING);
153  glEnable(GL_LIGHT0);
154  glEnable(GL_DEPTH_TEST);
155  glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
156  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
157   
[2792]158  //  glEnable(GL_COLOR);
159  //  glShadeModel(GL_SMOOTH);
[1899]160 
[2190]161  // create camera
[3213]162  //localcamera = new Camera(world); /* \todo camera/input node not used anymore*/
[2190]163 
164  return 0;
165}
[1850]166
[3214]167
[2190]168/**
[2636]169   \brief initializes the sound engine
[2190]170*/
[3226]171int Orxonox::initSound() 
[2190]172{
[3174]173  printf("> Initializing sound\n");
[3226]174  // SDL_Init(SDL_INIT_AUDIO);
[2636]175  printf("Not yet implemented\n");
176  return 0;
[2190]177}
[1900]178
[3214]179
[2190]180/**
[2636]181   \brief initializes input functions
[2190]182*/
[3226]183int Orxonox::initInput() 
[2190]184{
[2636]185  // create localinput
186  localinput = new CommandNode( configfilename);
187 
188  return 0;
[1803]189}
190
[3214]191
[2190]192/**
[2636]193   \brief initializes network system
[2190]194*/
[3226]195int Orxonox::initNetworking() 
[1897]196{
[2636]197  printf("Not yet implemented\n");
198  return 0;
[1897]199}
200
[3214]201
[2190]202/**
[2636]203   \brief initializes and loads resource files
[2190]204*/
[3226]205int Orxonox::initResources() 
[1858]206{
[2636]207  printf("Not yet implemented\n");
208  return 0;
[1858]209}
[1849]210
[3214]211
[2190]212/**
[2636]213   \brief initializes the world
[2190]214*/
[3226]215int Orxonox::initWorld() 
[1896]216{
[2636]217  //world = new World();
218 
219  // TO DO: replace this with a menu/intro
220  //world->load_debug_level();
221 
222  return 0;
[1896]223}
224
[2636]225
[2190]226/**
[2636]227   \brief starts the orxonox game or menu
228
229   here is the central orxonox state manager. There are currently two states
230   - menu
231   - game-play
232   both states manage their states themselfs again.
[2190]233*/
[2636]234void Orxonox::start()
235{
236 
237  this->gameLoader = GameLoader::getInstance();
238  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
239  this->gameLoader->init();
240  this->gameLoader->start();
241}
242
[3214]243
[2636]244/**
245   \brief exits Orxonox
246*/
[1875]247void Orxonox::quitGame() 
248{
[2636]249  bQuitOrxonox = true;
[1875]250}
251
252
[3214]253
[2190]254/**
[2636]255   \brief handles sprecial events from localinput
256   \param event: an event not handled by the CommandNode
[2190]257*/
[3226]258void Orxonox::eventHandler(SDL_Event* event)
[2190]259{
[2636]260  // Handle special events such as reshape, quit, focus changes
[2190]261}
[3214]262 
[1875]263
[2190]264/**
[2636]265   \brief handle keyboard commands that are not meant for WorldEntities
266   \param cmd: the command to handle
267   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
[2190]268*/
[3226]269bool Orxonox::systemCommand(Command* cmd)
[2190]270{
[3220]271  /*
[2636]272  if( !strcmp( cmd->cmd, "quit"))
273    {
274      if( !cmd->bUp) this->gameLoader->stop();
275      return true;
276    }
277  return false;
[3220]278  */
279  return false;
[2190]280}
[1803]281
[1850]282
[2190]283/**
[2636]284   \brief retrieve a pointer to the local Camera
285   \return a pointer to localcamera
[2190]286*/
[3226]287Camera* Orxonox::getCamera()
[1872]288{
[2636]289  return localcamera;
[1872]290}
[1850]291
[3214]292
[2190]293/**
[2636]294   \brief retrieve a pointer to the local CommandNode
295   \return a pointer to localinput
[2190]296*/
[3226]297CommandNode* Orxonox::getLocalInput()
[1850]298{
[2636]299  return localinput;
[1803]300}
301
[3214]302
[2190]303/**
[2636]304   \brief retrieve a pointer to the local World
305   \return a pointer to world
[2190]306*/
[3226]307World* Orxonox::getWorld()
[1872]308{
[2636]309  return world;
[1872]310}
[1850]311
[3214]312
313
314
[3226]315int main(int argc, char** argv) 
[1803]316{ 
[2636]317  printf(">>> Starting Orxonox <<<\n");
[1850]318  Orxonox *orx = Orxonox::getInstance();
[2190]319 
[3226]320  if((*orx).init(argc, argv) == -1)
[2636]321    {
322      printf("! Orxonox initialization failed\n");
323      return -1;
324    }
325 
326  orx->start();
327 
[2190]328  //delete orx;
329 
[1803]330  return 0;
331}
Note: See TracBrowser for help on using the repository browser.