Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: license with newlines, and it gets displayed in the end

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
[4942]97  ClassList::debug();
[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" \
[4946]103      "===================================================\n" \
104      ORXONOX_LICENSE_SHORT);
[1872]105
[4766]106  Orxonox::singletonRef = NULL;
[1850]107}
108
[2190]109/**
[4836]110 *  this is a singleton class to prevent duplicates
[4766]111 */
112Orxonox* Orxonox::singletonRef = NULL;
[4556]113
[4766]114/**
[4836]115 *  this finds the config file
[4766]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/**
[4833]129 * initialize Orxonox with command line
130 */
[2190]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/**
[4833]154 * 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/**
[4833]169 * initializes the sound engine
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/**
[4833]181 * initializes input functions
182 */
[4556]183int Orxonox::initInput()
[2190]184{
[4766]185  PRINT(3)("> Initializing input\n");
186
[4866]187  EventHandler::getInstance()->init(this->iniParser);
[4833]188  EventHandler::getInstance()->subscribe(GraphicsEngine::getInstance(), ES_ALL, EV_VIDEO_RESIZE);
[4556]189
[4833]190
[2636]191  return 0;
[1803]192}
193
[3214]194
[2190]195/**
[4833]196 * initializes network system
197 */
[4556]198int Orxonox::initNetworking()
[1897]199{
[4766]200  PRINT(3)("> Initializing networking\n");
201
202  printf("  ---Not yet implemented-FIXME--\n");
[2636]203  return 0;
[1897]204}
205
[3214]206
[2190]207/**
[4833]208 * initializes and loads resource files
[4766]209 */
[4833]210int Orxonox::initResources()
[1858]211{
[4766]212  PRINTF(3)("> Initializing resources\n");
[4091]213
[4766]214  PRINT(3)("initializing ResourceManager\n");
215
[4091]216  // create parser
[4766]217  if( this->iniParser->getSection (CONFIG_SECTION_DATA) == -1)
218  {
219    PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE);
220    return -1;
221  }
222  char namebuf[256];
223  char valuebuf[256];
224  memset (namebuf, 0, 256);
225  memset (valuebuf, 0, 256);
[4556]226
[4766]227  while( this->iniParser->nextVar (namebuf, valuebuf) != -1)
228  {
229    if (!strcmp(namebuf, CONFIG_NAME_DATADIR))
230    {
[4556]231          //  printf("Not yet implemented\n");
[4822]232      if (!ResourceManager::getInstance()->setDataDir(valuebuf))
[4766]233      {
234        PRINTF(1)("Data Could not be located\n");
235        exit(-1);
236      }
237    }
[4556]238
[4766]239    memset (namebuf, 0, 256);
240    memset (valuebuf, 0, 256);
241  }
[4556]242
[4822]243  if (!ResourceManager::getInstance()->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE))
[4766]244  {
245    PRINTF(1)("The DataDirectory %s could not be verified\n" \
246              "  Please Change in File %s Section %s Entry %s to a suitable value\n",
[4822]247              ResourceManager::getInstance()->getDataDir(),
[4766]248              DEFAULT_CONFIG_FILE,
249              CONFIG_SECTION_DATA,
250              CONFIG_NAME_DATADIR);
251    exit(-1);
252  }
[4836]253   //! @todo this is a hack and should be loadable
[4822]254  ResourceManager::getInstance()->addImageDir(ResourceManager::getInstance()->getFullName("maps/"));
255  ResourceManager::getInstance()->debug();
[4009]256
[4766]257  PRINT(3)("initializing TextEngine\n");
258  TextEngine::getInstance();
[4091]259
[4766]260  PRINT(3)("initializing ObjectManager\n");
[4822]261  ObjectManager::getInstance();
[4766]262  CDEngine::getInstance();
[4616]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 ||
[4766]361      !ResourceManager::isFile(DEFAULT_CONFIG_FILE) ||
362      ResourceManager::isFile(DEFAULT_LOCK_FILE))
[4032]363    {
[4766]364      if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
365        ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
[4556]366
[4132]367      // starting the GUI
[4056]368      Gui* gui = new Gui(argc, argv);
[4132]369      gui->startGui();
370
[4054]371      if (! gui->startOrxonox)
[4556]372        return 0;
373
[4054]374      delete gui;
[4032]375    }
[4556]376
[4032]377  PRINT(0)(">>> Starting Orxonox <<<\n");
[4033]378
[4766]379  ResourceManager::touchFile(DEFAULT_LOCK_FILE);
[4033]380
[1850]381  Orxonox *orx = Orxonox::getInstance();
[4556]382
[3226]383  if((*orx).init(argc, argv) == -1)
[2636]384    {
[4032]385      PRINTF(1)("! Orxonox initialization failed\n");
[2636]386      return -1;
387    }
[4556]388
[2636]389  orx->start();
[4556]390
[3676]391  delete orx;
[4033]392  ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
[4556]393
[1803]394}
Note: See TracBrowser for help on using the repository browser.