Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4938 was 4885, checked in by bensch, 19 years ago

orxonox/trunk: merged the weaponSystem back to the trunk, because it seems safe
merged with command:
svn merge -r 4847:HEAD branches/weaponSystem/ trunk/
conflict in file src/world-entities/weapons/weapon.h resolved in favor of the weaponSystem

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