Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5302 was 5298, checked in by bensch, 19 years ago

orxonox/trunk: output-issues

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