Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5175 was 5175, checked in by bensch, 20 years ago

orxonox/trunk: cleaner outtakes of the ShellBuffer

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