Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: benchmarking: modified formatting added some more measurement

File size: 11.9 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
272/**
273   \brief main function
274
275   here the journey begins
276*/
277int main(int argc, char** argv) 
278{ 
279 
280  /* reading arguments
281     
282     currently supported arguments are:
283     <no args>                   ::    just starts orxonox
284     --benchmark                 ::    start the benchmark without starting orxonox
285     
286     this is a preselection: it matches to one of the start* functions, the
287     finetuning is made in those functions.
288  */
289
290
291  int i;
292  for(i = 0; i < argc; ++i)
293    {
294      if(! strcmp( "--help", argv[i])) return startHelp();
295      else if(! strcmp( "--benchmark", argv[i])) return startBenchmarks();
296    }
297
298  PRINTF(2)("Orxonox does not understand the arguments");
299  return startOrxonox(argc, argv);
300}
301
302
303
304int startHelp()
305{
306  printf("orxonox: starts the orxonox game - rules\n");
307  printf("usage: orxonox [arg]\n\n");
308  printf("valid options:\n");
309  printf(" --benchmark\tstarts the orxonox benchmark\n");
310  printf(" --help \tshows this menu\n");
311}
312
313
314int startOrxonox(int argc, char** argv)
315{
316  printf(">>> Starting Orxonox <<<\n");
317  Orxonox *orx = Orxonox::getInstance();
318 
319  if((*orx).init(argc, argv) == -1)
320    {
321      printf("! Orxonox initialization failed\n");
322      return -1;
323    }
324 
325  orx->start();
326 
327  //delete orx;
328 
329}
330
331
332#include "list.h"
333#include "world_entity.h"
334#include "vector.h"
335#include "player.h"
336#include "primitive.h"
337#include <asm/msr.h>
338#include <linux/timex.h>
339
340
341#define LIST_MAX 10000
342#define VECTOR_MAX 1000000
343#define ITERATIONS 10000
344
345
346int startBenchmarks()
347{
348
349  printf("===========================================================\n");
350  printf("=                      BENCHMARKS                         =\n");
351  printf("===========================================================\n");
352  printf(" the author is not paying any attention to cacheing effects\n");
353  printf(" of the CPU.\n\n");
354  printf("[title]\t\t\t\t\t     [cycles]\t[loops]\n\n");
355  //  printf("------------------------------------------------------------\n\n");
356
357  // first measure the time overhead:
358  unsigned long ini, end, dt, tmp;
359  rdtscl(ini); rdtscl(end);
360  dt = end - ini;
361
362  int type = -1; 
363  /* type   -1 == all
364     type    0 == framework
365     type    1 == vector
366     type    2 == quaternion
367  */
368  if(type == 0 || type == -1)
369    {
370      /* framework test*/
371
372      printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS);
373      /* ************WorldEntity class test************** */
374      WorldEntity* w = NULL;
375      int i = 0;
376      unsigned long mittel = 0;
377     
378      for(i = 0; i < ITERATIONS; ++i)
379        {
380          rdtscl(ini);
381         
382          WorldEntity* w = new WorldEntity();
383         
384          rdtscl(end);
385          delete w;
386          mittel += (end - ini - dt);
387        }
388      float mi = mittel / (float)ITERATIONS;
389      printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi);
390     
391      mittel = 0;
392      for(i = 0; i < ITERATIONS; ++i)
393        {
394          rdtscl(ini);
395         
396          WorldEntity* w = new Primitive(P_SPHERE);
397         
398          rdtscl(end);
399          delete w;
400          mittel += (end - ini - dt);
401        }
402      mi = mittel / (float)ITERATIONS;
403      printf(" Generate a Primitive  object:\t\t%11.2f\n", mi);
404
405
406      mittel = 0;
407      for(i = 0; i < ITERATIONS; ++i)
408        {
409          rdtscl(ini);
410         
411          Vector* v = new Vector();
412         
413          rdtscl(end);
414          delete v;
415          mittel += (end - ini - dt);
416        }
417      mi = mittel / (float)ITERATIONS;
418      printf(" Generate a Vector object:\t\t%11.2f\n", mi);
419
420
421     mittel = 0;
422      for(i = 0; i < ITERATIONS; ++i)
423        {
424          rdtscl(ini);
425         
426          Quaternion* q = new Quaternion();
427         
428          rdtscl(end);
429          delete q;
430          mittel += (end - ini - dt);
431        }
432      mi = mittel / (float)ITERATIONS;
433      printf(" Generate a Quaternion object:\t\t%11.2f\n", mi);
434
435
436
437
438      printf("\nCalling function inline &| virtual, \t\t\t%i\n", ITERATIONS);
439      mittel = 0;
440      w = new WorldEntity();
441      for(i = 0; i < ITERATIONS; ++i)
442        {
443          rdtscl(ini);
444         
445          w->tick(0.0f);
446
447          rdtscl(end);
448          mittel += (end - ini - dt);
449          }
450      //delete w;
451      mi = mittel / (float)ITERATIONS;
452      printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi);
453
454
455      mittel = 0;
456      WorldEntity wo;
457      for(i = 0; i < ITERATIONS; ++i)
458        {
459          rdtscl(ini);
460         
461          wo.tick(0.0f);
462           
463          rdtscl(end);
464          mittel += (end - ini - dt);
465          }
466      //delete w;
467      mi = mittel / (float)ITERATIONS;
468      printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi);
469
470     
471      tList<WorldEntity>* list = new tList<WorldEntity>();
472
473     
474      /* ************Primitvie class test************** */
475      list = new tList<WorldEntity>();
476 
477     
478     
479      mittel = 0;
480      w = new Primitive(P_SPHERE);
481      for(i = 0; i < ITERATIONS; ++i)
482        {
483          rdtscl(ini);
484         
485          w->tick(0.0f);
486           
487          rdtscl(end);
488          mittel += (end - ini - dt);
489          }
490      mi = mittel / (float)ITERATIONS;
491      printf(" Call function tick() of Prim:\t\t%11.2f\n", mi);
492
493
494      }
495  if(type == 1 || type == -1)
496    {
497      printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX);
498      /* vector test */
499      Vector* a = new Vector(1.3, 5.3, 4.1);
500      Vector* b = new Vector(0.4, 2.5, 6.2);
501      Vector* c = new Vector();
502     
503      unsigned long mittel, ini, end;
504      float mi;
505      int i = 0;
506      // addition
507      mittel = 0;
508      for(i = 0; i < VECTOR_MAX; ++i)
509        {
510          rdtscl(ini);
511         
512          *c = *a + *b;
513           
514          rdtscl(end);
515          mittel += (end - ini - dt);
516        }
517      mi = mittel / (float)VECTOR_MAX;
518      printf(" Addition of two vectors:\t\t%11.2f\n", mi);
519     
520      // multiplikation
521
522      mittel = 0;
523      for(i = 0; i < VECTOR_MAX; ++i)
524        {
525          rdtscl(ini);
526         
527          *c = a->cross( *b);
528           
529          rdtscl(end);
530          mittel += (end - ini - dt);
531        }
532      mi = mittel / (float)VECTOR_MAX;
533      printf(" CrossMult of two vectors:\t\t%11.2f\n", mi);
534
535      if(type == 1 || type == -1)
536        {
537          /* quaternion test */
538          printf("\nDoing some simple quaternion operations: \t\t%i\n", VECTOR_MAX);
539          /* vector test */
540          Quaternion* a = new Quaternion();
541          Quaternion* b = new Quaternion();
542          Quaternion* c = new Quaternion();
543         
544          unsigned long mittel, ini, end;
545          float mi;
546          int i = 0;
547          // multiplication
548          mittel = 0;
549          for(i = 0; i < VECTOR_MAX; ++i)
550            {
551              rdtscl(ini);
552             
553              *c = *a * *b;
554             
555              rdtscl(end);
556              mittel += (end - ini - dt);
557            }
558          mi = mittel / (float)VECTOR_MAX;
559          printf(" Multiplying two quat. (=rot):\t\t%11.2f\n", mi);
560
561
562          // multiplication
563          mittel = 0;
564          for(i = 0; i < VECTOR_MAX; ++i)
565            {
566              rdtscl(ini);
567             
568              *c = *a * *b;
569             
570              rdtscl(end);
571              mittel += (end - ini - dt);
572            }
573          mi = mittel / (float)VECTOR_MAX;
574          printf(" Multiplying two quat.(=rot):\t\t%11.2f\n", mi);
575         
576         
577        }
578     
579
580    }
581}
Note: See TracBrowser for help on using the repository browser.