Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the weaponSystem back to the trunk, because it seems safe
merged with command:
svn merge -r 4847:HEAD branches/weaponSystem/ trunk/
conflict in file src/world-entities/weapons/weapon.h resolved in favor of the weaponSystem

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