Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3620 was 3619, checked in by bensch, 20 years ago

orxonox/trunk: added a Function to resize the Window, but it does not work :( GL does not update with SDL together

File size: 5.8 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"
[3610]27
[2036]28#include "world.h"
29#include "data_tank.h"
[2190]30#include "command_node.h"
[2636]31#include "game_loader.h"
[3610]32#include "graphics_engine.h"
33
[2190]34#include <string.h>
[3592]35int verbose = 4;
[2036]36
[1803]37using namespace std;
38
[2190]39/**
[2636]40   \brief create a new Orxonox
[2190]41*/
42Orxonox::Orxonox ()
[1872]43{
44  pause = false;
45}
[1803]46
[2190]47/**
[2636]48   \brief remove Orxonox from memory
[2190]49*/
[1875]50Orxonox::~Orxonox () 
[2190]51{
[3226]52  Orxonox::singletonRef = NULL;
[2636]53  if( world != NULL) delete world;
54  if( localinput != NULL) delete world;
55  if( resources != NULL) delete resources;
[3611]56  delete GraphicsEngine::getInstance(); // deleting the Graphics
[2190]57}
[1850]58
[3449]59/** \brief this is a singleton class to prevent duplicates */
[3226]60Orxonox* Orxonox::singletonRef = 0;
[1872]61
[3449]62/**
63   \returns reference or new Object of Orxonox if not existent.
64*/
[1850]65Orxonox* Orxonox::getInstance (void)
[1803]66{
[3226]67  if (singletonRef == NULL)
68    singletonRef = new Orxonox();
69  return singletonRef;
[1850]70}
71
[2190]72/**
[2636]73   \brief this finds the config file
74   
75   Since the config file varies from user to user and since one may want to specify different config files
76   for certain occasions or platforms this function finds the right config file for every occasion and stores
77   it's path and name into configfilename
[2190]78*/
[3226]79void Orxonox::getConfigFile (int argc, char** argv)
[1850]80{
[2636]81  strcpy (configfilename, "orxonox.conf");
[1803]82}
83
[2190]84/**
[2636]85   \brief initialize Orxonox with command line
[2190]86*/
87int Orxonox::init (int argc, char** argv)
[1803]88{
[2636]89  // parse command line
90  // config file
91 
[3226]92  getConfigFile (argc, argv);
[3174]93  SDL_Init (SDL_INIT_TIMER);
[2636]94  // initialize everything
[3226]95  if( initVideo() == -1) return -1;
96  if( initSound() == -1) return -1;
[2190]97  printf("> Initializing input\n");
[3226]98  if( initInput() == -1) return -1;
[2190]99  printf("> Initializing networking\n");
[3226]100  if( initNetworking () == -1) return -1;
[2190]101  printf("> Initializing resources\n");
[3226]102  if( initResources () == -1) return -1;
[2636]103  //printf("> Initializing world\n");
104  //if( init_world () == -1) return -1; PB: world will be initialized when started
105 
106  return 0;
[1850]107}
[1849]108
[2190]109/**
[2636]110   \brief initializes SDL and OpenGL
[2190]111*/
[3226]112int Orxonox::initVideo() 
[2190]113{
[3611]114  PRINTF(3)("> Initializing video\n");
[2190]115 
[3610]116  GraphicsEngine::getInstance();
[2190]117 
118  return 0;
119}
[1850]120
[3214]121
[2190]122/**
[2636]123   \brief initializes the sound engine
[2190]124*/
[3226]125int Orxonox::initSound() 
[2190]126{
[3174]127  printf("> Initializing sound\n");
[3226]128  // SDL_Init(SDL_INIT_AUDIO);
[2636]129  printf("Not yet implemented\n");
130  return 0;
[2190]131}
[1900]132
[3214]133
[2190]134/**
[2636]135   \brief initializes input functions
[2190]136*/
[3226]137int Orxonox::initInput() 
[2190]138{
[2636]139  // create localinput
140  localinput = new CommandNode( configfilename);
141 
142  return 0;
[1803]143}
144
[3214]145
[2190]146/**
[2636]147   \brief initializes network system
[2190]148*/
[3226]149int Orxonox::initNetworking() 
[1897]150{
[2636]151  printf("Not yet implemented\n");
152  return 0;
[1897]153}
154
[3214]155
[2190]156/**
[2636]157   \brief initializes and loads resource files
[2190]158*/
[3226]159int Orxonox::initResources() 
[1858]160{
[2636]161  printf("Not yet implemented\n");
162  return 0;
[1858]163}
[1849]164
[3214]165
[2190]166/**
[2636]167   \brief initializes the world
[2190]168*/
[3226]169int Orxonox::initWorld() 
[1896]170{
[2636]171  //world = new World();
172 
173  // TO DO: replace this with a menu/intro
174  //world->load_debug_level();
175 
176  return 0;
[1896]177}
178
[2636]179
[2190]180/**
[2636]181   \brief starts the orxonox game or menu
182
183   here is the central orxonox state manager. There are currently two states
184   - menu
185   - game-play
186   both states manage their states themselfs again.
[2190]187*/
[2636]188void Orxonox::start()
189{
190 
191  this->gameLoader = GameLoader::getInstance();
192  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
193  this->gameLoader->init();
194  this->gameLoader->start();
195}
196
[3214]197
[2636]198/**
199   \brief exits Orxonox
200*/
[1875]201void Orxonox::quitGame() 
202{
[2636]203  bQuitOrxonox = true;
[1875]204}
205
206
[3214]207
[2190]208/**
[2636]209   \brief handles sprecial events from localinput
210   \param event: an event not handled by the CommandNode
[2190]211*/
[3226]212void Orxonox::eventHandler(SDL_Event* event)
[2190]213{
[2636]214  // Handle special events such as reshape, quit, focus changes
[3619]215  switch (event->type)
216    {
217    case SDL_VIDEORESIZE:
218      GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance();
219      tmpGEngine->resolutionChanged(&event->resize);
220      break;
221    }
[2190]222}
[3214]223 
[1875]224
[2190]225/**
[2636]226   \brief handle keyboard commands that are not meant for WorldEntities
227   \param cmd: the command to handle
228   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
[2190]229*/
[3226]230bool Orxonox::systemCommand(Command* cmd)
[2190]231{
[3220]232  /*
[2636]233  if( !strcmp( cmd->cmd, "quit"))
234    {
235      if( !cmd->bUp) this->gameLoader->stop();
236      return true;
237    }
238  return false;
[3220]239  */
240  return false;
[2190]241}
[1803]242
[2190]243/**
[2636]244   \brief retrieve a pointer to the local CommandNode
245   \return a pointer to localinput
[2190]246*/
[3226]247CommandNode* Orxonox::getLocalInput()
[1850]248{
[2636]249  return localinput;
[1803]250}
251
[3214]252
[2190]253/**
[2636]254   \brief retrieve a pointer to the local World
255   \return a pointer to world
[2190]256*/
[3226]257World* Orxonox::getWorld()
[1872]258{
[2636]259  return world;
[1872]260}
[1850]261
[3449]262/**
263   \return The reference of the SDL-screen of orxonox
264*/
[3365]265SDL_Surface* Orxonox::getScreen ()
266{
267  return this->screen;
268}
[3214]269
[3449]270/**
271   \brief main function
[3214]272
[3449]273   here the journey begins
274*/
[3226]275int main(int argc, char** argv) 
[1803]276{ 
[2636]277  printf(">>> Starting Orxonox <<<\n");
[1850]278  Orxonox *orx = Orxonox::getInstance();
[2190]279 
[3226]280  if((*orx).init(argc, argv) == -1)
[2636]281    {
282      printf("! Orxonox initialization failed\n");
283      return -1;
284    }
285 
286  orx->start();
287 
[2190]288  //delete orx;
289 
[1803]290  return 0;
291}
Note: See TracBrowser for help on using the repository browser.