Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5143 was 5098, checked in by bensch, 19 years ago

orxonox/trunk: reverted the steps taken in Revision 5095
The error seems to come from somewhere else…

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