Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/collision_detection/src/orxonox.cc @ 6955

Last change on this file since 6955 was 5716, checked in by patrick, 19 years ago

collision_detection: moved the treedepth variable and therefore the hole interface changed

File size: 10.5 KB
RevLine 
[4982]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
[5303]23   co-programmer: Christian Meyer
[4054]24   co-programmer: Benjamin Grauer: injected ResourceManager/GraphicsEngine/GUI
[1850]25*/
26
[5303]27#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ORXONOX
[2190]28#include "orxonox.h"
[3610]29
[4054]30#include "gui.h"
31
[2036]32#include "world.h"
[4091]33#include "ini_parser.h"
[5165]34#include "game_loader.h"
[4786]35
36//ENGINES
[3610]37#include "graphics_engine.h"
[4504]38#include "sound_engine.h"
[3655]39#include "resource_manager.h"
[4786]40#include "cd_engine.h"
[3790]41#include "text_engine.h"
[4786]42#include "event_handler.h"
[4815]43#include "garbage_collector.h"
[4786]44
[4010]45#include "factory.h"
[4980]46#include "fast_factory.h"
47
[4131]48#include "benchmark.h"
[3610]49
[4786]50#include "class_list.h"
[5641]51#include "shell_command_class.h"
[5165]52#include "shell_command.h"
[5175]53#include "shell_buffer.h"
[4748]54
[5546]55#include "load_param_description.h"
[5226]56
[2190]57#include <string.h>
[4032]58
[5716]59int verbose = 5;
[2036]60
[1803]61using namespace std;
62
[5207]63SHELL_COMMAND(restart, Orxonox, restart);
64
[2190]65/**
[4836]66 *  create a new Orxonox
[4135]67
68   In this funcitons only global values are set. The game will not be started here.
[2190]69*/
70Orxonox::Orxonox ()
[1872]71{
[4445]72  this->setClassID(CL_ORXONOX, "Orxonox");
[4766]73  this->setName("orxonox-main");
[4059]74
[4766]75  this->iniParser = NULL;
[4135]76
77  this->argc = 0;
78  this->argv = NULL;
[4782]79
[4830]80  this->configFileName = NULL;
[1872]81}
[1803]82
[2190]83/**
[4836]84 *  remove Orxonox from memory
[2190]85*/
[4556]86Orxonox::~Orxonox ()
[2190]87{
[5285]88  // game-specific
[4815]89  delete GameLoader::getInstance();
90  delete GarbageCollector::getInstance();
[5285]91
92  // class-less services/factories
93  delete Factory::getFirst();
[4980]94  FastFactory::deleteAll();
[5171]95  ShellCommandClass::unregisterAllCommands();
[5332]96
[5226]97  LoadClassDescription::deleteAllDescriptions();
98
[5285]99  // engines
100  delete CDEngine::getInstance();
101  delete SoundEngine::getInstance();
102  delete GraphicsEngine::getInstance(); // deleting the Graphics
[4817]103  delete EventHandler::getInstance();
[5285]104
105  // handlers
106  delete ResourceManager::getInstance(); // deletes the Resource Manager
107  // output-buffer
108  delete ShellBuffer::getInstance();
109
110  // orxonox class-stuff
[5078]111  delete this->iniParser;
[5210]112  delete[] this->configFileName;
[4817]113
[5225]114  SDL_QuitSubSystem(SDL_INIT_TIMER);
[4942]115  ClassList::debug();
[1850]116
[4833]117  PRINT(3)
[4981]118      (
119      "===================================================\n" \
[4766]120      "Thanks for playing orxonox.\n" \
[5037]121      "visit: http://www.orxonox.net for new versions.\n" \
[4946]122      "===================================================\n" \
[4981]123      ORXONOX_LICENSE_SHORT
124      );
[1872]125
[4766]126  Orxonox::singletonRef = NULL;
[1850]127}
128
[2190]129/**
[4836]130 *  this is a singleton class to prevent duplicates
[4766]131 */
132Orxonox* Orxonox::singletonRef = NULL;
[4556]133
[5207]134// DANGEROUS
135void Orxonox::restart()
136{
137//   int argc = this->argc;
138//   char** argv = this->argv;
139//
140//   Orxonox *orx = Orxonox::getInstance();
141//
142//   delete orx;
143//
144//   orx = Orxonox::getInstance();
145//
146//   if((*orx).init(argc, argv) == -1)
147//   {
148//     PRINTF(1)("! Orxonox initialization failed\n");
149//     return;
150//   }
151//
152//   printf("finished inizialisation\n");
153//   orx->start();
154}
155
[4766]156/**
[4836]157 *  this finds the config file
[4766]158 * @returns the new config-fileName
159 * Since the config file varies from user to user and since one may want to specify different config files
160 * for certain occasions or platforms this function finds the right config file for every occasion and stores
161 * it's path and name into configfilename
[2190]162*/
[4830]163const char* Orxonox::getConfigFile ()
[1850]164{
[5424]165  if (ResourceManager::isFile("orxonox.conf"))
166  {
167    this->configFileName = new char[strlen("orxonox.conf")+1];
168    strcpy(this->configFileName, "orxonox.conf");
169  }
170  else
171    this->configFileName = ResourceManager::homeDirCheck(DEFAULT_CONFIG_FILE);
[4766]172  this->iniParser = new IniParser(this->configFileName);
[5424]173  PRINTF(3)("Parsed Config File: '%s'\n", this->configFileName);
[1803]174}
175
[2190]176/**
[4833]177 * initialize Orxonox with command line
178 */
[2190]179int Orxonox::init (int argc, char** argv)
[1803]180{
[4135]181  this->argc = argc;
182  this->argv = argv;
[2636]183  // parse command line
184  // config file
[4556]185
[4766]186  // initialize the Config-file
[4830]187  this->getConfigFile();
[4766]188
[4782]189  // initialize everything
[5227]190  SDL_Init(SDL_INIT_TIMER);
[4113]191  if( initResources () == -1) return -1;
[3226]192  if( initVideo() == -1) return -1;
193  if( initSound() == -1) return -1;
194  if( initInput() == -1) return -1;
195  if( initNetworking () == -1) return -1;
[5074]196  if( initMisc () == -1) return -1;
[4556]197
[2636]198  return 0;
[1850]199}
[1849]200
[2190]201/**
[4833]202 * initializes SDL and OpenGL
[2190]203*/
[4556]204int Orxonox::initVideo()
[2190]205{
[3611]206  PRINTF(3)("> Initializing video\n");
[4556]207
[3610]208  GraphicsEngine::getInstance();
[4556]209
[4784]210  GraphicsEngine::getInstance()->initFromIniFile(this->iniParser);
[4766]211
[5219]212  char* iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp");
[5225]213  if (iconName != NULL)
214  {
215    GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, iconName);
216    delete[] iconName;
217  }
[2190]218  return 0;
219}
[1850]220
[2190]221/**
[4833]222 * initializes the sound engine
223 */
[4556]224int Orxonox::initSound()
[2190]225{
[4504]226  PRINT(3)("> Initializing sound\n");
[5225]227  // SDL_InitSubSystem(SDL_INIT_AUDIO);
[4504]228  SoundEngine::getInstance()->initAudio();
[4985]229
230  SoundEngine::getInstance()->loadSettings(this->iniParser);
[2636]231  return 0;
[2190]232}
[1900]233
[3214]234
[2190]235/**
[4833]236 * initializes input functions
237 */
[4556]238int Orxonox::initInput()
[2190]239{
[4766]240  PRINT(3)("> Initializing input\n");
241
[4866]242  EventHandler::getInstance()->init(this->iniParser);
[4833]243  EventHandler::getInstance()->subscribe(GraphicsEngine::getInstance(), ES_ALL, EV_VIDEO_RESIZE);
[4556]244
[2636]245  return 0;
[1803]246}
247
[3214]248
[2190]249/**
[4833]250 * initializes network system
251 */
[4556]252int Orxonox::initNetworking()
[1897]253{
[4766]254  PRINT(3)("> Initializing networking\n");
255
256  printf("  ---Not yet implemented-FIXME--\n");
[2636]257  return 0;
[1897]258}
259
[3214]260
[2190]261/**
[4833]262 * initializes and loads resource files
[4766]263 */
[4833]264int Orxonox::initResources()
[1858]265{
[4766]266  PRINTF(3)("> Initializing resources\n");
[4091]267
[4766]268  PRINT(3)("initializing ResourceManager\n");
269
[5488]270  // init the resource manager
[5014]271  const char* dataPath;
272  if ((dataPath = this->iniParser->getVar(CONFIG_NAME_DATADIR, CONFIG_SECTION_DATA))!= NULL)
[4766]273  {
[5480]274    if (!ResourceManager::getInstance()->setDataDir(dataPath) &&
275         !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
[4766]276    {
[5423]277      PRINTF(1)("Data Could not be located in %s\n", dataPath);
[4766]278    }
279  }
[4556]280
[5480]281  if (!ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
[4766]282  {
[5510]283    PRINTF(1)("The DataDirectory %s could not be verified\n\nh" \
284              "!!!  Please Change in File %s Section %s Entry %s to a suitable value !!!\n",
[4822]285              ResourceManager::getInstance()->getDataDir(),
[5424]286              this->configFileName,
[4766]287              CONFIG_SECTION_DATA,
[5510]288              CONFIG_NAME_DATADIR );
[5479]289    Gui* gui = new Gui(argc, argv);
290    gui->startGui();
291    delete gui;
[4766]292    exit(-1);
293  }
[4836]294   //! @todo this is a hack and should be loadable
[5335]295  char* imageDir = ResourceManager::getInstance()->getFullName("maps");
[5216]296  ResourceManager::getInstance()->addImageDir(imageDir);
297  delete[] imageDir;
[4009]298
[5488]299  // start the collision detection engine
[4766]300  CDEngine::getInstance();
[5074]301  return 0;
302}
303
304/**
305 * initializes miscelaneous features
306 * @return -1 on failure
307 */
308int Orxonox::initMisc()
309{
[5183]310  ShellBuffer::getInstance();
[4766]311  return 0;
[1858]312}
[1849]313
[2190]314/**
[4836]315 *  starts the orxonox game or menu
[4833]316 * here is the central orxonox state manager. There are currently two states
317 * - menu
318 * - game-play
319 * both states manage their states themselfs again.
[2190]320*/
[2636]321void Orxonox::start()
322{
[4556]323
[2636]324  this->gameLoader = GameLoader::getInstance();
[4094]325  this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");
[4010]326  //  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
[2636]327  this->gameLoader->init();
328  this->gameLoader->start();
329}
330
[3214]331
[2636]332/**
[4833]333 * handles sprecial events from localinput
334 * @param event: an event not handled by the CommandNode
335 */
[4817]336// void Orxonox::graphicsHandler(SDL_Event* event)
337// {
338//   // Handle special events such as reshape, quit, focus changes
339//   switch (event->type)
340//     {
341//     case SDL_VIDEORESIZE:
342//       GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance();
343//       tmpGEngine->resolutionChanged(event->resize);
344//       break;
345//     }
346// }
[1875]347
[4556]348
[4408]349
[1803]350
[3214]351
[4782]352
[4059]353bool showGui = false;
[3648]354
[4766]355
356
357/**********************************
358*** ORXONOX MAIN STARTING POINT ***
359**********************************/
[3449]360/**
[4833]361 *
[4836]362 *  main function
[4833]363 *
364 * here the journey begins
[3449]365*/
[4556]366int main(int argc, char** argv)
367{
[4135]368  // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
[3648]369  int i;
[4032]370  for(i = 1; i < argc; ++i)
[3648]371    {
[4135]372      if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv);
373      else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks();
374      else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
375      //      else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
[3648]376    }
377
378  return startOrxonox(argc, argv);
379}
380
381
382
[4132]383int startHelp(int argc, char** argv)
[3648]384{
[4032]385  PRINT(0)("orxonox: starts the orxonox game - rules\n");
[4134]386  PRINT(0)("usage: orxonox [arg [arg...]]\n\n");
[4032]387  PRINT(0)("valid options:\n");
[4132]388  {
389    Gui* gui = new Gui(argc, argv);
390    gui->printHelp();
391    delete gui;
392  }
[4135]393  PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n");
394  PRINT(0)(" -h|--help:\t\t\tshows this help\n");
[3648]395}
396
[3649]397
[4766]398
399/**
400 * starts orxonox
401 * @param argc parameters count given to orxonox
402 * @param argv parameters given to orxonox
403 */
[3648]404int startOrxonox(int argc, char** argv)
405{
[4830]406  // checking for existence of the configuration-files, or if the lock file is still used
[5424]407  if (showGui || (!ResourceManager::isFile("./orxonox.conf") &&
408      !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
409#if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails
[4981]410       || ResourceManager::isFile(DEFAULT_LOCK_FILE)
411#endif
412     )
[4032]413    {
[4766]414      if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
415        ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
[4556]416
[4132]417      // starting the GUI
[4056]418      Gui* gui = new Gui(argc, argv);
[4132]419      gui->startGui();
420
[4054]421      if (! gui->startOrxonox)
[4556]422        return 0;
423
[4054]424      delete gui;
[4032]425    }
[4556]426
[4032]427  PRINT(0)(">>> Starting Orxonox <<<\n");
[4033]428
[4766]429  ResourceManager::touchFile(DEFAULT_LOCK_FILE);
[4033]430
[1850]431  Orxonox *orx = Orxonox::getInstance();
[4556]432
[5488]433  if(orx->init(argc, argv) == -1)
[2636]434    {
[4032]435      PRINTF(1)("! Orxonox initialization failed\n");
[2636]436      return -1;
437    }
[4556]438
[5018]439    printf("finished inizialisation\n");
[2636]440  orx->start();
[4556]441
[3676]442  delete orx;
[4033]443  ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
[1803]444}
Note: See TracBrowser for help on using the repository browser.