Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: setClassID implemented in all files

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