Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: removing some initialisation-stuff… i hope this works

File size: 10.0 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
23co-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
35//ENGINES
36#include "graphics_engine.h"
37#include "sound_engine.h"
38#include "resource_manager.h"
39#include "cd_engine.h"
40#include "text_engine.h"
41#include "event_handler.h"
42#include "garbage_collector.h"
43
44#include "factory.h"
45#include "fast_factory.h"
46
47#include "benchmark.h"
48
49#include "class_list.h"
50#include "substring.h"
51#include "shell.h"
52#include "shell_command.h"
53#include "shell_buffer.h"
54
55#include <string.h>
56
57int verbose = 4;
58
59using namespace std;
60
61SHELL_COMMAND(restart, Orxonox, restart);
62
63/**
64 *  create a new Orxonox
65
66   In this funcitons only global values are set. The game will not be started here.
67*/
68Orxonox::Orxonox ()
69{
70  this->setClassID(CL_ORXONOX, "Orxonox");
71  this->setName("orxonox-main");
72
73  this->iniParser = NULL;
74
75  this->argc = 0;
76  this->argv = NULL;
77
78  this->configFileName = NULL;
79}
80
81/**
82 *  remove Orxonox from memory
83*/
84Orxonox::~Orxonox ()
85{
86  delete GraphicsEngine::getInstance(); // deleting the Graphics
87  delete TextEngine::getInstance();
88  delete SoundEngine::getInstance();
89  delete ResourceManager::getInstance(); // deletes the Resource Manager
90  delete TextEngine::getInstance();
91  delete Factory::getFirst();
92  delete GameLoader::getInstance();
93  delete SoundEngine::getInstance();
94  delete CDEngine::getInstance();
95  delete GarbageCollector::getInstance();
96  FastFactory::deleteAll();
97  ShellCommandBase::debug();
98  ShellCommandClass::unregisterAllCommands();
99  ShellCommandBase::debug();
100  delete ShellBuffer::getInstance();
101
102  delete EventHandler::getInstance();
103  delete this->iniParser;
104  delete[] this->configFileName;
105
106  SDL_QuitSubSystem(SDL_INIT_TIMER);
107  ClassList::debug();
108
109  PRINT(3)
110      (
111      "===================================================\n" \
112      "Thanks for playing orxonox.\n" \
113      "visit: http://www.orxonox.net for new versions.\n" \
114      "===================================================\n" \
115      ORXONOX_LICENSE_SHORT
116      );
117
118  Orxonox::singletonRef = NULL;
119}
120
121/**
122 *  this is a singleton class to prevent duplicates
123 */
124Orxonox* Orxonox::singletonRef = NULL;
125
126// DANGEROUS
127void Orxonox::restart()
128{
129//   int argc = this->argc;
130//   char** argv = this->argv;
131//
132//   Orxonox *orx = Orxonox::getInstance();
133//
134//   delete orx;
135//
136//   orx = Orxonox::getInstance();
137//
138//   if((*orx).init(argc, argv) == -1)
139//   {
140//     PRINTF(1)("! Orxonox initialization failed\n");
141//     return;
142//   }
143//
144//   printf("finished inizialisation\n");
145//   orx->start();
146}
147
148/**
149 *  this finds the config file
150 * @returns the new config-fileName
151 * Since the config file varies from user to user and since one may want to specify different config files
152 * for certain occasions or platforms this function finds the right config file for every occasion and stores
153 * it's path and name into configfilename
154*/
155const char* Orxonox::getConfigFile ()
156{
157  this->configFileName = ResourceManager::homeDirCheck(DEFAULT_CONFIG_FILE);
158  this->iniParser = new IniParser(this->configFileName);
159}
160
161/**
162 * initialize Orxonox with command line
163 */
164int Orxonox::init (int argc, char** argv)
165{
166  this->argc = argc;
167  this->argv = argv;
168  // parse command line
169  // config file
170
171  // initialize the Config-file
172  this->getConfigFile();
173
174  // initialize everything
175  SDL_InitSubSystem (SDL_INIT_TIMER);
176  if( initResources () == -1) return -1;
177  if( initVideo() == -1) return -1;
178  if( initSound() == -1) return -1;
179  if( initInput() == -1) return -1;
180  if( initNetworking () == -1) return -1;
181  if( initMisc () == -1) return -1;
182
183  return 0;
184}
185
186/**
187 * initializes SDL and OpenGL
188*/
189int Orxonox::initVideo()
190{
191  PRINTF(3)("> Initializing video\n");
192
193  GraphicsEngine::getInstance();
194
195  GraphicsEngine::getInstance()->initFromIniFile(this->iniParser);
196
197  char* iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp");
198  if (iconName != NULL)
199  {
200    GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, iconName);
201    delete[] iconName;
202  }
203  return 0;
204}
205
206/**
207 * initializes the sound engine
208 */
209int Orxonox::initSound()
210{
211  PRINT(3)("> Initializing sound\n");
212  // SDL_InitSubSystem(SDL_INIT_AUDIO);
213  SoundEngine::getInstance()->initAudio();
214
215  SoundEngine::getInstance()->loadSettings(this->iniParser);
216  return 0;
217}
218
219
220/**
221 * initializes input functions
222 */
223int Orxonox::initInput()
224{
225  PRINT(3)("> Initializing input\n");
226
227  EventHandler::getInstance()->init(this->iniParser);
228  EventHandler::getInstance()->subscribe(GraphicsEngine::getInstance(), ES_ALL, EV_VIDEO_RESIZE);
229
230
231  return 0;
232}
233
234
235/**
236 * initializes network system
237 */
238int Orxonox::initNetworking()
239{
240  PRINT(3)("> Initializing networking\n");
241
242  printf("  ---Not yet implemented-FIXME--\n");
243  return 0;
244}
245
246
247/**
248 * initializes and loads resource files
249 */
250int Orxonox::initResources()
251{
252  PRINTF(3)("> Initializing resources\n");
253
254  PRINT(3)("initializing ResourceManager\n");
255
256  const char* dataPath;
257  if ((dataPath = this->iniParser->getVar(CONFIG_NAME_DATADIR, CONFIG_SECTION_DATA))!= NULL)
258  {
259    if (!ResourceManager::getInstance()->setDataDir(dataPath))
260    {
261      PRINTF(1)("Data Could not be located\n");
262      exit(-1);
263    }
264  }
265
266  if (!ResourceManager::getInstance()->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE))
267  {
268    PRINTF(1)("The DataDirectory %s could not be verified\n" \
269              "  Please Change in File %s Section %s Entry %s to a suitable value\n",
270              ResourceManager::getInstance()->getDataDir(),
271              DEFAULT_CONFIG_FILE,
272              CONFIG_SECTION_DATA,
273              CONFIG_NAME_DATADIR);
274    exit(-1);
275  }
276   //! @todo this is a hack and should be loadable
277  char* imageDir = ResourceManager::getInstance()->getFullName("maps/");
278  ResourceManager::getInstance()->addImageDir(imageDir);
279  delete[] imageDir;
280
281  PRINT(3)("initializing TextEngine\n");
282  TextEngine::getInstance();
283
284  CDEngine::getInstance();
285  return 0;
286}
287
288/**
289 * initializes miscelaneous features
290 * @return -1 on failure
291 */
292int Orxonox::initMisc()
293{
294  ShellBuffer::getInstance();
295  return 0;
296}
297
298/**
299 *  starts the orxonox game or menu
300 * here is the central orxonox state manager. There are currently two states
301 * - menu
302 * - game-play
303 * both states manage their states themselfs again.
304*/
305void Orxonox::start()
306{
307
308  this->gameLoader = GameLoader::getInstance();
309  this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");
310  //  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
311  this->gameLoader->init();
312  this->gameLoader->start();
313}
314
315
316/**
317 * handles sprecial events from localinput
318 * @param event: an event not handled by the CommandNode
319 */
320// void Orxonox::graphicsHandler(SDL_Event* event)
321// {
322//   // Handle special events such as reshape, quit, focus changes
323//   switch (event->type)
324//     {
325//     case SDL_VIDEORESIZE:
326//       GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance();
327//       tmpGEngine->resolutionChanged(event->resize);
328//       break;
329//     }
330// }
331
332
333
334
335
336
337bool showGui = false;
338
339
340
341/**********************************
342*** ORXONOX MAIN STARTING POINT ***
343**********************************/
344/**
345 *
346 *  main function
347 *
348 * here the journey begins
349*/
350int main(int argc, char** argv)
351{
352  // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
353  int i;
354  for(i = 1; i < argc; ++i)
355    {
356      if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv);
357      else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks();
358      else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
359      //      else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
360    }
361
362  return startOrxonox(argc, argv);
363}
364
365
366
367int startHelp(int argc, char** argv)
368{
369  PRINT(0)("orxonox: starts the orxonox game - rules\n");
370  PRINT(0)("usage: orxonox [arg [arg...]]\n\n");
371  PRINT(0)("valid options:\n");
372  {
373    Gui* gui = new Gui(argc, argv);
374    gui->printHelp();
375    delete gui;
376  }
377  PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n");
378  PRINT(0)(" -h|--help:\t\t\tshows this help\n");
379}
380
381
382
383/**
384 * starts orxonox
385 * @param argc parameters count given to orxonox
386 * @param argv parameters given to orxonox
387 */
388int startOrxonox(int argc, char** argv)
389{
390  // checking for existence of the configuration-files, or if the lock file is still used
391  if (showGui ||
392      !ResourceManager::isFile(DEFAULT_CONFIG_FILE)
393#if DEBUG < 3
394       || ResourceManager::isFile(DEFAULT_LOCK_FILE)
395#endif
396     )
397    {
398      if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
399        ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
400
401      // starting the GUI
402      Gui* gui = new Gui(argc, argv);
403      gui->startGui();
404
405      if (! gui->startOrxonox)
406        return 0;
407
408      delete gui;
409    }
410
411  PRINT(0)(">>> Starting Orxonox <<<\n");
412
413  ResourceManager::touchFile(DEFAULT_LOCK_FILE);
414
415  Orxonox *orx = Orxonox::getInstance();
416
417  if((*orx).init(argc, argv) == -1)
418    {
419      PRINTF(1)("! Orxonox initialization failed\n");
420      return -1;
421    }
422
423    printf("finished inizialisation\n");
424  orx->start();
425
426  delete orx;
427  ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
428
429}
Note: See TracBrowser for help on using the repository browser.