Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/orxonox.cc @ 5752

Last change on this file since 5752 was 5563, checked in by hdavid, 19 years ago

orxonox/branches/network: removed temporary timex.h in benchmark.cc. Know it runs on UBUNTU.

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