Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4994 was 4985, checked in by bensch, 19 years ago

orxonox/trunk: loading some stuff from ths sound-engine

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