Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4311 was 4286, checked in by patrick, 20 years ago

orxonox/trunk: implemented the objectmanager cache function

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