Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: nicer help

File size: 9.1 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 "data_tank.h"
33#include "command_node.h"
34#include "ini_parser.h"
35#include "game_loader.h"
36#include "graphics_engine.h"
37#include "resource_manager.h"
38#include "text_engine.h"
39#include "factory.h"
40#include "benchmark.h"
41
42#include <string.h>
43
44int verbose = 4;
45
46using namespace std;
47
48/**
49   \brief create a new Orxonox
50*/
51Orxonox::Orxonox ()
52{
53  this->pause = false;
54
55  this->world = NULL;
56  this->resources = NULL;
57  this->localinput = NULL;
58}
59
60/**
61   \brief remove Orxonox from memory
62*/
63Orxonox::~Orxonox () 
64{
65  int i =0;
66  Orxonox::singletonRef = NULL;
67  if( world != NULL) delete world;
68  if( localinput != NULL) delete localinput;
69  if( resources != NULL) delete resources;
70  delete GraphicsEngine::getInstance(); // deleting the Graphics
71  delete ResourceManager::getInstance(); // deletes the Resource Manager
72  delete TextEngine::getInstance();
73}
74
75/** \brief this is a singleton class to prevent duplicates */
76Orxonox* Orxonox::singletonRef = 0;
77
78/**
79   \returns reference or new Object of Orxonox if not existent.
80*/
81Orxonox* Orxonox::getInstance (void)
82{
83  if (singletonRef == NULL)
84    singletonRef = new Orxonox();
85  return singletonRef;
86}
87
88/**
89   \brief this finds the config file
90   
91   Since the config file varies from user to user and since one may want to specify different config files
92   for certain occasions or platforms this function finds the right config file for every occasion and stores
93   it's path and name into configfilename
94*/
95void Orxonox::getConfigFile (int argc, char** argv)
96{
97  strcpy (configfilename, "~/.orxonox/orxonox.conf");
98}
99
100/**
101   \brief initialize Orxonox with command line
102*/
103int Orxonox::init (int argc, char** argv)
104{
105  // parse command line
106  // config file
107 
108  getConfigFile (argc, argv);
109  SDL_Init (SDL_INIT_TIMER);
110  // initialize everything
111  printf("> Initializing resources\n");
112  if( initResources () == -1) return -1;
113
114  if( initVideo() == -1) return -1;
115  if( initSound() == -1) return -1;
116  printf("> Initializing input\n");
117  if( initInput() == -1) return -1;
118  printf("> Initializing networking\n");
119  if( initNetworking () == -1) return -1;
120  //printf("> Initializing world\n");
121  //if( init_world () == -1) return -1; PB: world will be initialized when started
122 
123  return 0;
124}
125
126/**
127   \brief initializes SDL and OpenGL
128*/
129int Orxonox::initVideo() 
130{
131  PRINTF(3)("> Initializing video\n");
132 
133  GraphicsEngine::getInstance();
134 
135  return 0;
136}
137
138
139/**
140   \brief initializes the sound engine
141*/
142int Orxonox::initSound() 
143{
144  printf("> Initializing sound\n");
145  // SDL_Init(SDL_INIT_AUDIO);
146  printf("Not yet implemented\n");
147  return 0;
148}
149
150
151/**
152   \brief initializes input functions
153*/
154int Orxonox::initInput() 
155{
156  // create localinput
157  localinput = new CommandNode(configfilename);
158 
159  return 0;
160}
161
162
163/**
164   \brief initializes network system
165*/
166int Orxonox::initNetworking() 
167{
168  printf("Not yet implemented\n");
169  return 0;
170}
171
172
173/**
174   \brief initializes and loads resource files
175*/
176int Orxonox::initResources() 
177{
178  PRINT(3)("initializing ResourceManager\n");
179  resourceManager = ResourceManager::getInstance();
180
181  // create parser
182  IniParser parser (DEFAULT_CONFIG_FILE);
183  if( parser.getSection (CONFIG_SECTION_DATA) == -1)
184    {
185      PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE);
186      return -1;
187    }
188  char namebuf[256];
189  char valuebuf[256];
190  memset (namebuf, 0, 256);
191  memset (valuebuf, 0, 256);
192 
193  while( parser.nextVar (namebuf, valuebuf) != -1)
194    {
195      if (!strcmp(namebuf, CONFIG_NAME_DATADIR))
196        {
197          //  printf("Not yet implemented\n");
198          if (!resourceManager->setDataDir(valuebuf))
199            {
200              PRINTF(1)("Data Could not be located\n");
201              exit(-1);
202            }
203        }
204     
205      memset (namebuf, 0, 256);
206      memset (valuebuf, 0, 256);
207    }
208 
209  if (!resourceManager->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE))
210    {
211      PRINTF(1)("The DataDirectory %s could not be verified\nPlease Change in File %s Section %s Entry %s to a suitable value\n",
212                resourceManager->getDataDir(),
213                DEFAULT_CONFIG_FILE,
214                CONFIG_SECTION_DATA,
215                CONFIG_NAME_DATADIR);
216      exit(-1);
217    }
218
219
220  PRINT(3)("initializing TextEngine\n");
221  TextEngine::getInstance();
222
223  return 0;
224}
225
226
227/**
228   \brief initializes the world
229*/
230int Orxonox::initWorld() 
231{
232  //world = new World();
233 
234  // TO DO: replace this with a menu/intro
235  //world->load_debug_level();
236 
237  return 0;
238}
239
240
241/**
242   \brief starts the orxonox game or menu
243
244   here is the central orxonox state manager. There are currently two states
245   - menu
246   - game-play
247   both states manage their states themselfs again.
248*/
249void Orxonox::start()
250{
251 
252  this->gameLoader = GameLoader::getInstance();
253  this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");
254  //  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
255  this->gameLoader->init();
256  this->gameLoader->start();
257}
258
259
260/**
261   \brief exits Orxonox
262*/
263void Orxonox::quitGame() 
264{
265  bQuitOrxonox = true;
266}
267
268
269
270/**
271   \brief handles sprecial events from localinput
272   \param event: an event not handled by the CommandNode
273*/
274void Orxonox::eventHandler(SDL_Event* event)
275{
276  // Handle special events such as reshape, quit, focus changes
277  switch (event->type)
278    {
279    case SDL_VIDEORESIZE:
280      GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance();
281      tmpGEngine->resolutionChanged(&event->resize);
282      break;
283    }
284}
285 
286
287/**
288   \brief handle keyboard commands that are not meant for WorldEntities
289   \param cmd: the command to handle
290   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
291*/
292bool Orxonox::systemCommand(Command* cmd)
293{
294  /*
295  if( !strcmp( cmd->cmd, "quit"))
296    {
297      if( !cmd->bUp) this->gameLoader->stop();
298      return true;
299    }
300  return false;
301  */
302  return false;
303}
304
305/**
306   \brief retrieve a pointer to the local CommandNode
307   \return a pointer to localinput
308*/
309CommandNode* Orxonox::getLocalInput()
310{
311  return localinput;
312}
313
314
315/**
316   \brief retrieve a pointer to the local World
317   \return a pointer to world
318*/
319World* Orxonox::getWorld()
320{
321  return world;
322}
323
324/**
325   \return The reference of the SDL-screen of orxonox
326*/
327SDL_Surface* Orxonox::getScreen ()
328{
329  return this->screen;
330}
331
332
333bool showGui = false;
334
335/**
336   \brief main function
337
338   here the journey begins
339*/
340int main(int argc, char** argv) 
341{ 
342 
343  /* reading arguments
344     
345     currently supported arguments are:
346     <no args>                   ::    just starts orxonox
347     --benchmark                 ::    start the benchmark without starting orxonox
348     
349     this is a preselection: it matches to one of the start* functions, the
350     finetuning is made in those functions.
351  */
352
353
354  int i;
355  for(i = 1; i < argc; ++i)
356    {
357      if(! strcmp( "--help", argv[i])) return startHelp(argc, argv);
358      else if(! strcmp( "--benchmark", argv[i])) return startBenchmarks();
359      else if(! strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
360      else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
361    }
362
363  return startOrxonox(argc, argv);
364}
365
366
367
368int startHelp(int argc, char** argv)
369{
370  PRINT(0)("orxonox: starts the orxonox game - rules\n");
371  PRINT(0)("usage: orxonox [arg [arg...]]\n\n");
372  PRINT(0)("valid options:\n");
373  {
374    Gui* gui = new Gui(argc, argv);
375    gui->printHelp();
376    delete gui;
377  }
378  PRINT(0)(" --benchmark:\t\t\tstarts the orxonox benchmark\n");
379  PRINT(0)(" --help: \t\t\tshows this help\n");
380}
381
382
383int startOrxonox(int argc, char** argv)
384{
385  // checking for existence of the configuration-files
386  if (showGui ||
387      !ResourceManager::isFile("~/.orxonox/orxonox.conf") ||
388      ResourceManager::isFile("~/.orxonox/orxonox.lock"))
389    {
390      if (ResourceManager::isFile("~/.orxonox/orxonox.lock"))
391        ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
392     
393      // starting the GUI
394      Gui* gui = new Gui(argc, argv);
395      gui->startGui();
396
397      if (! gui->startOrxonox)
398        return 0;
399     
400      delete gui;
401    }
402 
403  PRINT(0)(">>> Starting Orxonox <<<\n");
404
405  ResourceManager::touchFile("~/.orxonox/orxonox.lock");
406
407  Orxonox *orx = Orxonox::getInstance();
408 
409  if((*orx).init(argc, argv) == -1)
410    {
411      PRINTF(1)("! Orxonox initialization failed\n");
412      return -1;
413    }
414 
415  orx->start();
416 
417  delete orx;
418  ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
419 
420}
Note: See TracBrowser for help on using the repository browser.