Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4617 was 4616, checked in by patrick, 19 years ago

orxonox/trunk: now bounding box gets displayed very well

File size: 8.6 KB
RevLine 
[4556]1/*
[1850]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,
[4556]18   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
[1850]19
[1855]20
21   ### File Specific:
22   main-programmer: Patrick Boenzli
[2190]23   co-programmer: Christian Meyer
[4054]24   co-programmer: Benjamin Grauer: injected ResourceManager/GraphicsEngine/GUI
[1850]25*/
26
[2190]27#include "orxonox.h"
[3610]28
[4054]29#include "gui.h"
30
[2036]31#include "world.h"
[4091]32#include "ini_parser.h"
[2636]33#include "game_loader.h"
[3610]34#include "graphics_engine.h"
[4504]35#include "sound_engine.h"
[3655]36#include "resource_manager.h"
[4286]37#include "object_manager.h"
[3790]38#include "text_engine.h"
[4010]39#include "factory.h"
[4131]40#include "benchmark.h"
[4388]41#include "event_handler.h"
[4408]42#include "event.h"
[4616]43#include "cd_engine.h"
[3610]44
[2190]45#include <string.h>
[4032]46
[3966]47int verbose = 4;
[2036]48
[1803]49using namespace std;
50
[2190]51/**
[2636]52   \brief create a new Orxonox
[4135]53
54   In this funcitons only global values are set. The game will not be started here.
[2190]55*/
56Orxonox::Orxonox ()
[1872]57{
[4445]58  this->setClassID(CL_ORXONOX, "Orxonox");
[4597]59  this->setName("orxonox");
[4059]60
[4286]61  this->resourceManager = NULL;
62  this->objectManager = NULL;
[4442]63  this->eventHandler = NULL;
[4135]64
65  this->argc = 0;
66  this->argv = NULL;
[1872]67}
[1803]68
[2190]69/**
[2636]70   \brief remove Orxonox from memory
[2190]71*/
[4556]72Orxonox::~Orxonox ()
[2190]73{
[4054]74  int i =0;
[3226]75  Orxonox::singletonRef = NULL;
[3611]76  delete GraphicsEngine::getInstance(); // deleting the Graphics
[4504]77  delete TextEngine::getInstance();
78  delete SoundEngine::getInstance();
[3660]79  delete ResourceManager::getInstance(); // deletes the Resource Manager
[4286]80  delete ObjectManager::getInstance();
[3790]81  delete TextEngine::getInstance();
[4445]82  delete EventHandler::getInstance();
[2190]83}
[1850]84
[3449]85/** \brief this is a singleton class to prevent duplicates */
[3226]86Orxonox* Orxonox::singletonRef = 0;
[1872]87
[3449]88/**
89   \returns reference or new Object of Orxonox if not existent.
90*/
[1850]91Orxonox* Orxonox::getInstance (void)
[1803]92{
[3226]93  if (singletonRef == NULL)
94    singletonRef = new Orxonox();
95  return singletonRef;
[1850]96}
97
[2190]98/**
[2636]99   \brief this finds the config file
[4556]100
[2636]101   Since the config file varies from user to user and since one may want to specify different config files
102   for certain occasions or platforms this function finds the right config file for every occasion and stores
103   it's path and name into configfilename
[2190]104*/
[3226]105void Orxonox::getConfigFile (int argc, char** argv)
[1850]106{
[4084]107  strcpy (configfilename, "~/.orxonox/orxonox.conf");
[1803]108}
109
[2190]110/**
[2636]111   \brief initialize Orxonox with command line
[2190]112*/
113int Orxonox::init (int argc, char** argv)
[1803]114{
[4135]115  this->argc = argc;
116  this->argv = argv;
[2636]117  // parse command line
118  // config file
[4556]119
[3226]120  getConfigFile (argc, argv);
[3174]121  SDL_Init (SDL_INIT_TIMER);
[2636]122  // initialize everything
[4113]123  printf("> Initializing resources\n");
124  if( initResources () == -1) return -1;
125
[3226]126  if( initVideo() == -1) return -1;
127  if( initSound() == -1) return -1;
[4504]128  PRINT(3)("> Initializing input\n");
[3226]129  if( initInput() == -1) return -1;
[4504]130  PRINT(3)("> Initializing networking\n");
[3226]131  if( initNetworking () == -1) return -1;
[2636]132  //printf("> Initializing world\n");
133  //if( init_world () == -1) return -1; PB: world will be initialized when started
[4556]134
[2636]135  return 0;
[1850]136}
[1849]137
[2190]138/**
[2636]139   \brief initializes SDL and OpenGL
[2190]140*/
[4556]141int Orxonox::initVideo()
[2190]142{
[3611]143  PRINTF(3)("> Initializing video\n");
[4556]144
[3610]145  GraphicsEngine::getInstance();
[4556]146
[2190]147  return 0;
148}
[1850]149
[3214]150
[2190]151/**
[2636]152   \brief initializes the sound engine
[2190]153*/
[4556]154int Orxonox::initSound()
[2190]155{
[4504]156  PRINT(3)("> Initializing sound\n");
[3226]157  // SDL_Init(SDL_INIT_AUDIO);
[4504]158  SoundEngine::getInstance()->initAudio();
[2636]159  return 0;
[2190]160}
[1900]161
[3214]162
[2190]163/**
[2636]164   \brief initializes input functions
[2190]165*/
[4556]166int Orxonox::initInput()
[2190]167{
[4408]168  this->eventHandler = EventHandler::getInstance();
169  this->eventHandler->init();
[4556]170
[2636]171  return 0;
[1803]172}
173
[3214]174
[2190]175/**
[2636]176   \brief initializes network system
[2190]177*/
[4556]178int Orxonox::initNetworking()
[1897]179{
[2636]180  printf("Not yet implemented\n");
181  return 0;
[1897]182}
183
[3214]184
[2190]185/**
[2636]186   \brief initializes and loads resource files
[2190]187*/
[4556]188int Orxonox::initResources()
[1858]189{
[4606]190   PRINT(3)("initializing ResourceManager\n");
191   resourceManager = ResourceManager::getInstance();
[4091]192
193  // create parser
[4606]194   IniParser parser (DEFAULT_CONFIG_FILE);
195   if( parser.getSection (CONFIG_SECTION_DATA) == -1)
196   {
197     PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE);
198     return -1;
199   }
200   char namebuf[256];
201   char valuebuf[256];
202   memset (namebuf, 0, 256);
203   memset (valuebuf, 0, 256);
[4556]204
[4606]205   while( parser.nextVar (namebuf, valuebuf) != -1)
206   {
207     if (!strcmp(namebuf, CONFIG_NAME_DATADIR))
208     {
[4556]209          //  printf("Not yet implemented\n");
[4606]210       if (!resourceManager->setDataDir(valuebuf))
211       {
212         PRINTF(1)("Data Could not be located\n");
213         exit(-1);
214       }
215     }
[4556]216
[4606]217     memset (namebuf, 0, 256);
218     memset (valuebuf, 0, 256);
219   }
[4556]220
[4606]221   if (!resourceManager->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE))
222   {
223     PRINTF(1)("The DataDirectory %s could not be verified\nPlease Change in File %s Section %s Entry %s to a suitable value\n",
224     resourceManager->getDataDir(),
225     DEFAULT_CONFIG_FILE,
226     CONFIG_SECTION_DATA,
227     CONFIG_NAME_DATADIR);
228     exit(-1);
229   }
230   //! \todo this is a hack and should be loadable
231   resourceManager->addImageDir(ResourceManager::getInstance()->getFullName("maps/"));
232   resourceManager->debug();
[4009]233
[4606]234   PRINT(3)("initializing TextEngine\n");
235   TextEngine::getInstance();
[4091]236
[4606]237   PRINT(3)("initializing ObjectManager\n");
238   this->objectManager = ObjectManager::getInstance();
[4132]239
[4616]240   CDEngine::getInstance();
241
242   return 0;
[1858]243}
[1849]244
[3214]245
[1896]246
[2636]247
[2190]248/**
[2636]249   \brief starts the orxonox game or menu
250
251   here is the central orxonox state manager. There are currently two states
252   - menu
253   - game-play
254   both states manage their states themselfs again.
[2190]255*/
[2636]256void Orxonox::start()
257{
[4556]258
[2636]259  this->gameLoader = GameLoader::getInstance();
[4094]260  this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");
[4010]261  //  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
[2636]262  this->gameLoader->init();
263  this->gameLoader->start();
264}
265
[3214]266
[2636]267/**
268   \brief handles sprecial events from localinput
[4556]269   \param event: an event not handled by the CommandNode
[2190]270*/
[4408]271void Orxonox::graphicsHandler(SDL_Event* event)
[2190]272{
[2636]273  // Handle special events such as reshape, quit, focus changes
[3619]274  switch (event->type)
275    {
276    case SDL_VIDEORESIZE:
277      GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance();
278      tmpGEngine->resolutionChanged(&event->resize);
279      break;
280    }
[2190]281}
[1875]282
[4556]283
[4445]284/**
285  \brief processes the events for orxonox main class
286  \param the event to handle
287*/
[4408]288void Orxonox::process(const Event &event)
289{}
290
[1803]291
[3214]292
[4059]293bool showGui = false;
[3648]294
[3449]295/**
296   \brief main function
[3214]297
[3449]298   here the journey begins
299*/
[4556]300int main(int argc, char** argv)
301{
[3648]302
[4135]303  // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
[3648]304  int i;
[4032]305  for(i = 1; i < argc; ++i)
[3648]306    {
[4135]307      if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv);
308      else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks();
309      else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
310      //      else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
[3648]311    }
312
313  return startOrxonox(argc, argv);
314}
315
316
317
[4132]318int startHelp(int argc, char** argv)
[3648]319{
[4032]320  PRINT(0)("orxonox: starts the orxonox game - rules\n");
[4134]321  PRINT(0)("usage: orxonox [arg [arg...]]\n\n");
[4032]322  PRINT(0)("valid options:\n");
[4132]323  {
324    Gui* gui = new Gui(argc, argv);
325    gui->printHelp();
326    delete gui;
327  }
[4135]328  PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n");
329  PRINT(0)(" -h|--help:\t\t\tshows this help\n");
[3648]330}
331
[3649]332
[3648]333int startOrxonox(int argc, char** argv)
334{
[4032]335  // checking for existence of the configuration-files
[4059]336  if (showGui ||
337      !ResourceManager::isFile("~/.orxonox/orxonox.conf") ||
338      ResourceManager::isFile("~/.orxonox/orxonox.lock"))
[4032]339    {
340      if (ResourceManager::isFile("~/.orxonox/orxonox.lock"))
[4556]341        ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
342
[4132]343      // starting the GUI
[4056]344      Gui* gui = new Gui(argc, argv);
[4132]345      gui->startGui();
346
[4054]347      if (! gui->startOrxonox)
[4556]348        return 0;
349
[4054]350      delete gui;
[4032]351    }
[4556]352
[4032]353  PRINT(0)(">>> Starting Orxonox <<<\n");
[4033]354
355  ResourceManager::touchFile("~/.orxonox/orxonox.lock");
356
[1850]357  Orxonox *orx = Orxonox::getInstance();
[4556]358
[3226]359  if((*orx).init(argc, argv) == -1)
[2636]360    {
[4032]361      PRINTF(1)("! Orxonox initialization failed\n");
[2636]362      return -1;
363    }
[4556]364
[2636]365  orx->start();
[4556]366
[3676]367  delete orx;
[4033]368  ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
[4556]369
[1803]370}
Note: See TracBrowser for help on using the repository browser.