Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: windowName defineable by the GraphicsEngine

File size: 8.7 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"
[3610]34#include "graphics_engine.h"
[4504]35#include "sound_engine.h"
[3655]36#include "resource_manager.h"
[4286]37#include "object_manager.h"
[3790]38#include "text_engine.h"
[4010]39#include "factory.h"
[4131]40#include "benchmark.h"
[4388]41#include "event_handler.h"
[4408]42#include "event.h"
[4616]43#include "cd_engine.h"
[3610]44
[2190]45#include <string.h>
[4032]46
[3966]47int verbose = 4;
[2036]48
[1803]49using namespace std;
50
[2190]51/**
[2636]52   \brief create a new Orxonox
[4135]53
54   In this funcitons only global values are set. The game will not be started here.
[2190]55*/
56Orxonox::Orxonox ()
[1872]57{
[4445]58  this->setClassID(CL_ORXONOX, "Orxonox");
[4597]59  this->setName("orxonox");
[4059]60
[4286]61  this->resourceManager = NULL;
62  this->objectManager = NULL;
[4442]63  this->eventHandler = NULL;
[4135]64
65  this->argc = 0;
66  this->argv = NULL;
[1872]67}
[1803]68
[2190]69/**
[2636]70   \brief remove Orxonox from memory
[2190]71*/
[4556]72Orxonox::~Orxonox ()
[2190]73{
[4054]74  int i =0;
[3226]75  Orxonox::singletonRef = NULL;
[3611]76  delete GraphicsEngine::getInstance(); // deleting the Graphics
[4504]77  delete TextEngine::getInstance();
78  delete SoundEngine::getInstance();
[3660]79  delete ResourceManager::getInstance(); // deletes the Resource Manager
[4286]80  delete ObjectManager::getInstance();
[3790]81  delete TextEngine::getInstance();
[4445]82  delete EventHandler::getInstance();
[2190]83}
[1850]84
[3449]85/** \brief this is a singleton class to prevent duplicates */
[3226]86Orxonox* Orxonox::singletonRef = 0;
[1872]87
[3449]88/**
89   \returns reference or new Object of Orxonox if not existent.
90*/
[1850]91Orxonox* Orxonox::getInstance (void)
[1803]92{
[3226]93  if (singletonRef == NULL)
94    singletonRef = new Orxonox();
95  return singletonRef;
[1850]96}
97
[2190]98/**
[2636]99   \brief this finds the config file
[4556]100
[2636]101   Since the config file varies from user to user and since one may want to specify different config files
102   for certain occasions or platforms this function finds the right config file for every occasion and stores
103   it's path and name into configfilename
[2190]104*/
[3226]105void Orxonox::getConfigFile (int argc, char** argv)
[1850]106{
[4084]107  strcpy (configfilename, "~/.orxonox/orxonox.conf");
[1803]108}
109
[2190]110/**
[2636]111   \brief initialize Orxonox with command line
[2190]112*/
113int Orxonox::init (int argc, char** argv)
[1803]114{
[4135]115  this->argc = argc;
116  this->argv = argv;
[2636]117  // parse command line
118  // config file
[4556]119
[3226]120  getConfigFile (argc, argv);
[3174]121  SDL_Init (SDL_INIT_TIMER);
[2636]122  // initialize everything
[4113]123  printf("> Initializing resources\n");
124  if( initResources () == -1) return -1;
125
[3226]126  if( initVideo() == -1) return -1;
127  if( initSound() == -1) return -1;
[4504]128  PRINT(3)("> Initializing input\n");
[3226]129  if( initInput() == -1) return -1;
[4504]130  PRINT(3)("> Initializing networking\n");
[3226]131  if( initNetworking () == -1) return -1;
[2636]132  //printf("> Initializing world\n");
133  //if( init_world () == -1) return -1; PB: world will be initialized when started
[4556]134
[2636]135  return 0;
[1850]136}
[1849]137
[2190]138/**
[2636]139   \brief initializes SDL and OpenGL
[2190]140*/
[4556]141int Orxonox::initVideo()
[2190]142{
[3611]143  PRINTF(3)("> Initializing video\n");
[4556]144
[3610]145  GraphicsEngine::getInstance();
[4619]146  GraphicsEngine::getInstance()->setWindowName("orxonox " PACKAGE_VERSION, "orxonox " PACKAGE_VERSION);
[4556]147
[2190]148  return 0;
149}
[1850]150
[3214]151
[2190]152/**
[2636]153   \brief initializes the sound engine
[2190]154*/
[4556]155int Orxonox::initSound()
[2190]156{
[4504]157  PRINT(3)("> Initializing sound\n");
[3226]158  // SDL_Init(SDL_INIT_AUDIO);
[4504]159  SoundEngine::getInstance()->initAudio();
[2636]160  return 0;
[2190]161}
[1900]162
[3214]163
[2190]164/**
[2636]165   \brief initializes input functions
[2190]166*/
[4556]167int Orxonox::initInput()
[2190]168{
[4408]169  this->eventHandler = EventHandler::getInstance();
170  this->eventHandler->init();
[4556]171
[2636]172  return 0;
[1803]173}
174
[3214]175
[2190]176/**
[2636]177   \brief initializes network system
[2190]178*/
[4556]179int Orxonox::initNetworking()
[1897]180{
[2636]181  printf("Not yet implemented\n");
182  return 0;
[1897]183}
184
[3214]185
[2190]186/**
[2636]187   \brief initializes and loads resource files
[2190]188*/
[4556]189int Orxonox::initResources()
[1858]190{
[4606]191   PRINT(3)("initializing ResourceManager\n");
192   resourceManager = ResourceManager::getInstance();
[4091]193
194  // create parser
[4606]195   IniParser parser (DEFAULT_CONFIG_FILE);
196   if( parser.getSection (CONFIG_SECTION_DATA) == -1)
197   {
198     PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE);
199     return -1;
200   }
201   char namebuf[256];
202   char valuebuf[256];
203   memset (namebuf, 0, 256);
204   memset (valuebuf, 0, 256);
[4556]205
[4606]206   while( parser.nextVar (namebuf, valuebuf) != -1)
207   {
208     if (!strcmp(namebuf, CONFIG_NAME_DATADIR))
209     {
[4556]210          //  printf("Not yet implemented\n");
[4606]211       if (!resourceManager->setDataDir(valuebuf))
212       {
213         PRINTF(1)("Data Could not be located\n");
214         exit(-1);
215       }
216     }
[4556]217
[4606]218     memset (namebuf, 0, 256);
219     memset (valuebuf, 0, 256);
220   }
[4556]221
[4606]222   if (!resourceManager->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE))
223   {
224     PRINTF(1)("The DataDirectory %s could not be verified\nPlease Change in File %s Section %s Entry %s to a suitable value\n",
225     resourceManager->getDataDir(),
226     DEFAULT_CONFIG_FILE,
227     CONFIG_SECTION_DATA,
228     CONFIG_NAME_DATADIR);
229     exit(-1);
230   }
231   //! \todo this is a hack and should be loadable
232   resourceManager->addImageDir(ResourceManager::getInstance()->getFullName("maps/"));
233   resourceManager->debug();
[4009]234
[4606]235   PRINT(3)("initializing TextEngine\n");
236   TextEngine::getInstance();
[4091]237
[4606]238   PRINT(3)("initializing ObjectManager\n");
239   this->objectManager = ObjectManager::getInstance();
[4132]240
[4616]241   CDEngine::getInstance();
242
243   return 0;
[1858]244}
[1849]245
[3214]246
[1896]247
[2636]248
[2190]249/**
[2636]250   \brief starts the orxonox game or menu
251
252   here is the central orxonox state manager. There are currently two states
253   - menu
254   - game-play
255   both states manage their states themselfs again.
[2190]256*/
[2636]257void Orxonox::start()
258{
[4556]259
[2636]260  this->gameLoader = GameLoader::getInstance();
[4094]261  this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");
[4010]262  //  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
[2636]263  this->gameLoader->init();
264  this->gameLoader->start();
265}
266
[3214]267
[2636]268/**
269   \brief handles sprecial events from localinput
[4556]270   \param event: an event not handled by the CommandNode
[2190]271*/
[4408]272void Orxonox::graphicsHandler(SDL_Event* event)
[2190]273{
[2636]274  // Handle special events such as reshape, quit, focus changes
[3619]275  switch (event->type)
276    {
277    case SDL_VIDEORESIZE:
278      GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance();
279      tmpGEngine->resolutionChanged(&event->resize);
280      break;
281    }
[2190]282}
[1875]283
[4556]284
[4445]285/**
286  \brief processes the events for orxonox main class
287  \param the event to handle
288*/
[4408]289void Orxonox::process(const Event &event)
290{}
291
[1803]292
[3214]293
[4059]294bool showGui = false;
[3648]295
[3449]296/**
297   \brief main function
[3214]298
[3449]299   here the journey begins
300*/
[4556]301int main(int argc, char** argv)
302{
[3648]303
[4135]304  // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
[3648]305  int i;
[4032]306  for(i = 1; i < argc; ++i)
[3648]307    {
[4135]308      if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv);
309      else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks();
310      else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
311      //      else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
[3648]312    }
313
314  return startOrxonox(argc, argv);
315}
316
317
318
[4132]319int startHelp(int argc, char** argv)
[3648]320{
[4032]321  PRINT(0)("orxonox: starts the orxonox game - rules\n");
[4134]322  PRINT(0)("usage: orxonox [arg [arg...]]\n\n");
[4032]323  PRINT(0)("valid options:\n");
[4132]324  {
325    Gui* gui = new Gui(argc, argv);
326    gui->printHelp();
327    delete gui;
328  }
[4135]329  PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n");
330  PRINT(0)(" -h|--help:\t\t\tshows this help\n");
[3648]331}
332
[3649]333
[3648]334int startOrxonox(int argc, char** argv)
335{
[4032]336  // checking for existence of the configuration-files
[4059]337  if (showGui ||
338      !ResourceManager::isFile("~/.orxonox/orxonox.conf") ||
339      ResourceManager::isFile("~/.orxonox/orxonox.lock"))
[4032]340    {
341      if (ResourceManager::isFile("~/.orxonox/orxonox.lock"))
[4556]342        ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
343
[4132]344      // starting the GUI
[4056]345      Gui* gui = new Gui(argc, argv);
[4132]346      gui->startGui();
347
[4054]348      if (! gui->startOrxonox)
[4556]349        return 0;
350
[4054]351      delete gui;
[4032]352    }
[4556]353
[4032]354  PRINT(0)(">>> Starting Orxonox <<<\n");
[4033]355
356  ResourceManager::touchFile("~/.orxonox/orxonox.lock");
357
[1850]358  Orxonox *orx = Orxonox::getInstance();
[4556]359
[3226]360  if((*orx).init(argc, argv) == -1)
[2636]361    {
[4032]362      PRINTF(1)("! Orxonox initialization failed\n");
[2636]363      return -1;
364    }
[4556]365
[2636]366  orx->start();
[4556]367
[3676]368  delete orx;
[4033]369  ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
[4556]370
[1803]371}
Note: See TracBrowser for help on using the repository browser.