Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/avi_play/src/orxonox.cc @ 6461

Last change on this file since 6461 was 5961, checked in by bensch, 19 years ago

orxonox/branches/avi_play: merged the trunk back to the avi_play branche again
merged with command
svn merge -r 5924:HEAD ../trunk/ avi_play/

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