Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: implemented aim

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
[3966]54int verbose = 4;
[2036]55
[1803]56using namespace std;
57
[2190]58/**
[2636]59   \brief 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/**
[2636]78   \brief 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
[4766]101  PRINT(3)("===================================================\n" \
102      "Thanks for playing orxonox.\n" \
103      "visit: http://www.orxonox.ethz.ch for new versions.\n" \
104      "===================================================\n");
[1872]105
[4766]106  Orxonox::singletonRef = NULL;
[1850]107}
108
[2190]109/**
[4766]110 * @brief this is a singleton class to prevent duplicates
111 */
112Orxonox* Orxonox::singletonRef = NULL;
[4556]113
[4766]114/**
115 * @brief this finds the config file
116 * @returns the new config-fileName
117 * Since the config file varies from user to user and since one may want to specify different config files
118 * for certain occasions or platforms this function finds the right config file for every occasion and stores
119 * it's path and name into configfilename
[2190]120*/
[4830]121const char* Orxonox::getConfigFile ()
[1850]122{
[4830]123  this->configFileName = new char[strlen(DEFAULT_CONFIG_FILE)];
[4766]124  strcpy (this->configFileName, DEFAULT_CONFIG_FILE);
125  this->iniParser = new IniParser(this->configFileName);
[1803]126}
127
[2190]128/**
[2636]129   \brief initialize Orxonox with command line
[2190]130*/
131int Orxonox::init (int argc, char** argv)
[1803]132{
[4135]133  this->argc = argc;
134  this->argv = argv;
[2636]135  // parse command line
136  // config file
[4556]137
[4766]138  // initialize the Config-file
[4830]139  this->getConfigFile();
[4766]140
141
[4782]142  // initialize everything
[3174]143  SDL_Init (SDL_INIT_TIMER);
[4113]144  if( initResources () == -1) return -1;
[3226]145  if( initVideo() == -1) return -1;
146  if( initSound() == -1) return -1;
147  if( initInput() == -1) return -1;
148  if( initNetworking () == -1) return -1;
[4556]149
[2636]150  return 0;
[1850]151}
[1849]152
[2190]153/**
[2636]154   \brief initializes SDL and OpenGL
[2190]155*/
[4556]156int Orxonox::initVideo()
[2190]157{
[3611]158  PRINTF(3)("> Initializing video\n");
[4556]159
[3610]160  GraphicsEngine::getInstance();
[4766]161  GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, PACKAGE_NAME " " PACKAGE_VERSION);
[4556]162
[4784]163  GraphicsEngine::getInstance()->initFromIniFile(this->iniParser);
[4766]164
[2190]165  return 0;
166}
[1850]167
[2190]168/**
[2636]169   \brief initializes the sound engine
[2190]170*/
[4556]171int Orxonox::initSound()
[2190]172{
[4504]173  PRINT(3)("> Initializing sound\n");
[3226]174  // SDL_Init(SDL_INIT_AUDIO);
[4504]175  SoundEngine::getInstance()->initAudio();
[2636]176  return 0;
[2190]177}
[1900]178
[3214]179
[2190]180/**
[4766]181 * @brief initializes input functions
[2190]182*/
[4556]183int Orxonox::initInput()
[2190]184{
[4766]185  PRINT(3)("> Initializing input\n");
186
[4822]187  EventHandler::getInstance()->init();
[4556]188
[2636]189  return 0;
[1803]190}
191
[3214]192
[2190]193/**
[4766]194* @brief initializes network system
[2190]195*/
[4556]196int Orxonox::initNetworking()
[1897]197{
[4766]198  PRINT(3)("> Initializing networking\n");
199
200  printf("  ---Not yet implemented-FIXME--\n");
[2636]201  return 0;
[1897]202}
203
[3214]204
[2190]205/**
[4766]206 * @brief initializes and loads resource files
207 */
208 int Orxonox::initResources()
[1858]209{
[4766]210  PRINTF(3)("> Initializing resources\n");
[4091]211
[4766]212  PRINT(3)("initializing ResourceManager\n");
213
[4091]214  // create parser
[4766]215  if( this->iniParser->getSection (CONFIG_SECTION_DATA) == -1)
216  {
217    PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE);
218    return -1;
219  }
220  char namebuf[256];
221  char valuebuf[256];
222  memset (namebuf, 0, 256);
223  memset (valuebuf, 0, 256);
[4556]224
[4766]225  while( this->iniParser->nextVar (namebuf, valuebuf) != -1)
226  {
227    if (!strcmp(namebuf, CONFIG_NAME_DATADIR))
228    {
[4556]229          //  printf("Not yet implemented\n");
[4822]230      if (!ResourceManager::getInstance()->setDataDir(valuebuf))
[4766]231      {
232        PRINTF(1)("Data Could not be located\n");
233        exit(-1);
234      }
235    }
[4556]236
[4766]237    memset (namebuf, 0, 256);
238    memset (valuebuf, 0, 256);
239  }
[4556]240
[4822]241  if (!ResourceManager::getInstance()->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE))
[4766]242  {
243    PRINTF(1)("The DataDirectory %s could not be verified\n" \
244              "  Please Change in File %s Section %s Entry %s to a suitable value\n",
[4822]245              ResourceManager::getInstance()->getDataDir(),
[4766]246              DEFAULT_CONFIG_FILE,
247              CONFIG_SECTION_DATA,
248              CONFIG_NAME_DATADIR);
249    exit(-1);
250  }
[4606]251   //! \todo this is a hack and should be loadable
[4822]252  ResourceManager::getInstance()->addImageDir(ResourceManager::getInstance()->getFullName("maps/"));
253  ResourceManager::getInstance()->debug();
[4009]254
[4766]255  PRINT(3)("initializing TextEngine\n");
256  TextEngine::getInstance();
[4091]257
[4766]258  PRINT(3)("initializing ObjectManager\n");
[4822]259  ObjectManager::getInstance();
[4766]260  CDEngine::getInstance();
[4616]261
[4766]262  return 0;
[1858]263}
[1849]264
[2190]265/**
[2636]266   \brief starts the orxonox game or menu
267
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/**
285   \brief handles sprecial events from localinput
[4556]286   \param event: an event not handled by the CommandNode
[2190]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/**
313   \brief main function
[3214]314
[3449]315   here the journey begins
316*/
[4556]317int main(int argc, char** argv)
318{
[4135]319  // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
[3648]320  int i;
[4032]321  for(i = 1; i < argc; ++i)
[3648]322    {
[4135]323      if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv);
324      else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks();
325      else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
326      //      else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
[3648]327    }
328
329  return startOrxonox(argc, argv);
330}
331
332
333
[4132]334int startHelp(int argc, char** argv)
[3648]335{
[4032]336  PRINT(0)("orxonox: starts the orxonox game - rules\n");
[4134]337  PRINT(0)("usage: orxonox [arg [arg...]]\n\n");
[4032]338  PRINT(0)("valid options:\n");
[4132]339  {
340    Gui* gui = new Gui(argc, argv);
341    gui->printHelp();
342    delete gui;
343  }
[4135]344  PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n");
345  PRINT(0)(" -h|--help:\t\t\tshows this help\n");
[3648]346}
347
[3649]348
[4766]349
350/**
351 * starts orxonox
352 * @param argc parameters count given to orxonox
353 * @param argv parameters given to orxonox
354 */
[3648]355int startOrxonox(int argc, char** argv)
356{
[4830]357  // checking for existence of the configuration-files, or if the lock file is still used
[4059]358  if (showGui ||
[4766]359      !ResourceManager::isFile(DEFAULT_CONFIG_FILE) ||
360      ResourceManager::isFile(DEFAULT_LOCK_FILE))
[4032]361    {
[4766]362      if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
363        ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
[4556]364
[4132]365      // starting the GUI
[4056]366      Gui* gui = new Gui(argc, argv);
[4132]367      gui->startGui();
368
[4054]369      if (! gui->startOrxonox)
[4556]370        return 0;
371
[4054]372      delete gui;
[4032]373    }
[4556]374
[4032]375  PRINT(0)(">>> Starting Orxonox <<<\n");
[4033]376
[4766]377  ResourceManager::touchFile(DEFAULT_LOCK_FILE);
[4033]378
[1850]379  Orxonox *orx = Orxonox::getInstance();
[4556]380
[3226]381  if((*orx).init(argc, argv) == -1)
[2636]382    {
[4032]383      PRINTF(1)("! Orxonox initialization failed\n");
[2636]384      return -1;
385    }
[4556]386
[2636]387  orx->start();
[4556]388
[3676]389  delete orx;
[4033]390  ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
[4556]391
[1803]392}
Note: See TracBrowser for help on using the repository browser.