Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: SubString now also can split by whiteSpaces :>
this cost me almost 2 hours… sometimes i think, that i am unable to think…. :/
other times it just works, like when learning some Information Transfer

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