Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3648 was 3648, checked in by patrick, 19 years ago

orxonox/trunk: command arguments added to orxonox exec. you can pass benchmark and write your own benchmarking functions for testing purposes. try ./orxonox —help for more info

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