Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: cleaned up orxonox.cc a bit, and now one has the ability to choose the resolution in the GUI

File size: 9.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
[4766]45#include "substring.h"
[4748]46#include "class_list.h"
47
[2190]48#include <string.h>
[4032]49
[3966]50int verbose = 4;
[2036]51
[1803]52using namespace std;
53
[2190]54/**
[2636]55   \brief create a new Orxonox
[4135]56
57   In this funcitons only global values are set. The game will not be started here.
[2190]58*/
59Orxonox::Orxonox ()
[1872]60{
[4445]61  this->setClassID(CL_ORXONOX, "Orxonox");
[4766]62  this->setName("orxonox-main");
[4059]63
[4286]64  this->resourceManager = NULL;
65  this->objectManager = NULL;
[4442]66  this->eventHandler = NULL;
[4766]67  this->iniParser = NULL;
[4135]68
69  this->argc = 0;
70  this->argv = NULL;
[1872]71}
[1803]72
[2190]73/**
[2636]74   \brief remove Orxonox from memory
[2190]75*/
[4556]76Orxonox::~Orxonox ()
[2190]77{
[4766]78  delete this->iniParser;
79
[3611]80  delete GraphicsEngine::getInstance(); // deleting the Graphics
[4504]81  delete TextEngine::getInstance();
82  delete SoundEngine::getInstance();
[3660]83  delete ResourceManager::getInstance(); // deletes the Resource Manager
[4286]84  delete ObjectManager::getInstance();
[3790]85  delete TextEngine::getInstance();
[4445]86  delete EventHandler::getInstance();
[4749]87  delete Factory::getFirst();
[4766]88  delete SoundEngine::getInstance();
[4748]89
[4753]90  ClassList::debug(0);
[1850]91
[4766]92  PRINT(3)("===================================================\n" \
93      "Thanks for playing orxonox.\n" \
94      "visit: http://www.orxonox.ethz.ch for new versions.\n" \
95      "===================================================\n");
[1872]96
[4766]97  Orxonox::singletonRef = NULL;
[1850]98}
99
[2190]100/**
[4766]101 * @brief this is a singleton class to prevent duplicates
102 */
103Orxonox* Orxonox::singletonRef = NULL;
[4556]104
[4766]105/**
106 * @brief this finds the config file
107 * @returns the new config-fileName
108 * Since the config file varies from user to user and since one may want to specify different config files
109 * for certain occasions or platforms this function finds the right config file for every occasion and stores
110 * it's path and name into configfilename
[2190]111*/
[4766]112const char* Orxonox::getConfigFile (int argc, char** argv)
[1850]113{
[4766]114  strcpy (this->configFileName, DEFAULT_CONFIG_FILE);
115  this->iniParser = new IniParser(this->configFileName);
[1803]116}
117
[2190]118/**
[2636]119   \brief initialize Orxonox with command line
[2190]120*/
121int Orxonox::init (int argc, char** argv)
[1803]122{
[4135]123  this->argc = argc;
124  this->argv = argv;
[2636]125  // parse command line
126  // config file
[4556]127
[4766]128  // initialize the Config-file
129  this->getConfigFile(argc, argv);
130
131
[3174]132  SDL_Init (SDL_INIT_TIMER);
[2636]133  // initialize everything
[4113]134  if( initResources () == -1) return -1;
[3226]135  if( initVideo() == -1) return -1;
136  if( initSound() == -1) return -1;
137  if( initInput() == -1) return -1;
138  if( initNetworking () == -1) return -1;
[2636]139  //printf("> Initializing world\n");
140  //if( init_world () == -1) return -1; PB: world will be initialized when started
[4556]141
[2636]142  return 0;
[1850]143}
[1849]144
[2190]145/**
[2636]146   \brief initializes SDL and OpenGL
[2190]147*/
[4556]148int Orxonox::initVideo()
[2190]149{
[3611]150  PRINTF(3)("> Initializing video\n");
[4556]151
[3610]152  GraphicsEngine::getInstance();
[4766]153  GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, PACKAGE_NAME " " PACKAGE_VERSION);
[4556]154
[4766]155
156  SubString resolution(this->iniParser->getVar(CONFIG_NAME_RESOLUTION, CONFIG_SECTION_VIDEO, "640x480"), 'x');
157  GraphicsEngine::getInstance()->setResolution(atoi(resolution.getString(0)), atoi(resolution.getString(1)), 16);
158
159//  const char* fullscreen = this->iniParser->getVar(CONFIG_NAME_FULLSCREEN, CONFIG_SECTION_VIDEO, 0);
160//  GraphicsEngine::getInstance()->setFullscreen(false);
161
[2190]162  return 0;
163}
[1850]164
[2190]165/**
[2636]166   \brief initializes the sound engine
[2190]167*/
[4556]168int Orxonox::initSound()
[2190]169{
[4504]170  PRINT(3)("> Initializing sound\n");
[3226]171  // SDL_Init(SDL_INIT_AUDIO);
[4504]172  SoundEngine::getInstance()->initAudio();
[2636]173  return 0;
[2190]174}
[1900]175
[3214]176
[2190]177/**
[4766]178 * @brief initializes input functions
[2190]179*/
[4556]180int Orxonox::initInput()
[2190]181{
[4766]182  PRINT(3)("> Initializing input\n");
183
[4408]184  this->eventHandler = EventHandler::getInstance();
185  this->eventHandler->init();
[4556]186
[2636]187  return 0;
[1803]188}
189
[3214]190
[2190]191/**
[4766]192* @brief initializes network system
[2190]193*/
[4556]194int Orxonox::initNetworking()
[1897]195{
[4766]196  PRINT(3)("> Initializing networking\n");
197
198  printf("  ---Not yet implemented-FIXME--\n");
[2636]199  return 0;
[1897]200}
201
[3214]202
[2190]203/**
[4766]204 * @brief initializes and loads resource files
205 */
206 int Orxonox::initResources()
[1858]207{
[4766]208  PRINTF(3)("> Initializing resources\n");
[4091]209
[4766]210  PRINT(3)("initializing ResourceManager\n");
211  resourceManager = ResourceManager::getInstance();
212
[4091]213  // create parser
[4766]214  if( this->iniParser->getSection (CONFIG_SECTION_DATA) == -1)
215  {
216    PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE);
217    return -1;
218  }
219  char namebuf[256];
220  char valuebuf[256];
221  memset (namebuf, 0, 256);
222  memset (valuebuf, 0, 256);
[4556]223
[4766]224  while( this->iniParser->nextVar (namebuf, valuebuf) != -1)
225  {
226    if (!strcmp(namebuf, CONFIG_NAME_DATADIR))
227    {
[4556]228          //  printf("Not yet implemented\n");
[4766]229      if (!resourceManager->setDataDir(valuebuf))
230      {
231        PRINTF(1)("Data Could not be located\n");
232        exit(-1);
233      }
234    }
[4556]235
[4766]236    memset (namebuf, 0, 256);
237    memset (valuebuf, 0, 256);
238  }
[4556]239
[4766]240  if (!resourceManager->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE))
241  {
242    PRINTF(1)("The DataDirectory %s could not be verified\n" \
243              "  Please Change in File %s Section %s Entry %s to a suitable value\n",
244              resourceManager->getDataDir(),
245              DEFAULT_CONFIG_FILE,
246              CONFIG_SECTION_DATA,
247              CONFIG_NAME_DATADIR);
248    exit(-1);
249  }
[4606]250   //! \todo this is a hack and should be loadable
[4766]251  resourceManager->addImageDir(ResourceManager::getInstance()->getFullName("maps/"));
252  resourceManager->debug();
[4009]253
[4766]254  PRINT(3)("initializing TextEngine\n");
255  TextEngine::getInstance();
[4091]256
[4766]257  PRINT(3)("initializing ObjectManager\n");
258  this->objectManager = ObjectManager::getInstance();
[4132]259
[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*/
[4408]288void Orxonox::graphicsHandler(SDL_Event* event)
[2190]289{
[2636]290  // Handle special events such as reshape, quit, focus changes
[3619]291  switch (event->type)
292    {
293    case SDL_VIDEORESIZE:
294      GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance();
295      tmpGEngine->resolutionChanged(&event->resize);
296      break;
297    }
[2190]298}
[1875]299
[4556]300
[4445]301/**
302  \brief processes the events for orxonox main class
303  \param the event to handle
304*/
[4408]305void Orxonox::process(const Event &event)
306{}
307
[1803]308
[3214]309
[4059]310bool showGui = false;
[3648]311
[4766]312
313
314/**********************************
315*** ORXONOX MAIN STARTING POINT ***
316**********************************/
[3449]317/**
318   \brief main function
[3214]319
[3449]320   here the journey begins
321*/
[4556]322int main(int argc, char** argv)
323{
[4135]324  // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
[3648]325  int i;
[4032]326  for(i = 1; i < argc; ++i)
[3648]327    {
[4135]328      if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv);
329      else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks();
330      else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
331      //      else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
[3648]332    }
333
334  return startOrxonox(argc, argv);
335}
336
337
338
[4132]339int startHelp(int argc, char** argv)
[3648]340{
[4032]341  PRINT(0)("orxonox: starts the orxonox game - rules\n");
[4134]342  PRINT(0)("usage: orxonox [arg [arg...]]\n\n");
[4032]343  PRINT(0)("valid options:\n");
[4132]344  {
345    Gui* gui = new Gui(argc, argv);
346    gui->printHelp();
347    delete gui;
348  }
[4135]349  PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n");
350  PRINT(0)(" -h|--help:\t\t\tshows this help\n");
[3648]351}
352
[3649]353
[4766]354
355/**
356 * starts orxonox
357 * @param argc parameters count given to orxonox
358 * @param argv parameters given to orxonox
359 */
[3648]360int startOrxonox(int argc, char** argv)
361{
[4032]362  // checking for existence of the configuration-files
[4059]363  if (showGui ||
[4766]364      !ResourceManager::isFile(DEFAULT_CONFIG_FILE) ||
365      ResourceManager::isFile(DEFAULT_LOCK_FILE))
[4032]366    {
[4766]367      if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
368        ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
[4556]369
[4132]370      // starting the GUI
[4056]371      Gui* gui = new Gui(argc, argv);
[4132]372      gui->startGui();
373
[4054]374      if (! gui->startOrxonox)
[4556]375        return 0;
376
[4054]377      delete gui;
[4032]378    }
[4556]379
[4032]380  PRINT(0)(">>> Starting Orxonox <<<\n");
[4033]381
[4766]382  ResourceManager::touchFile(DEFAULT_LOCK_FILE);
[4033]383
[1850]384  Orxonox *orx = Orxonox::getInstance();
[4556]385
[3226]386  if((*orx).init(argc, argv) == -1)
[2636]387    {
[4032]388      PRINTF(1)("! Orxonox initialization failed\n");
[2636]389      return -1;
390    }
[4556]391
[2636]392  orx->start();
[4556]393
[3676]394  delete orx;
[4033]395  ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
[4556]396
[1803]397}
Note: See TracBrowser for help on using the repository browser.