Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: reverted the steps taken in Revision 5095
The error seems to come from somewhere else…

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