Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

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