Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/height_map/src/orxonox.cc @ 5941

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

orxonox/trunk: merged branches/network to the trunk
merged with command:
svn merge -r 5505:HEAD branches/network trunk

conflicts resolved in favor of the trunk (as always :))
also fixed a typo in the #include "SDL_tread.h"

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