Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4616 was 4616, checked in by patrick, 19 years ago

orxonox/trunk: now bounding box gets displayed very well

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