Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/textEngine/src/orxonox.cc @ 3693

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

orxonox/brnaches/textEngine: working with some default text, but far from finished

File size: 15.6 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
25*/
26
27#include "orxonox.h"
28
29#include "world.h"
30#include "data_tank.h"
31#include "command_node.h"
32#include "game_loader.h"
33#include "graphics_engine.h"
34#include "resource_manager.h"
35#include "glfont.h"
36
37#include <string.h>
38int verbose = 3;
39
40using namespace std;
41
42/**
43   \brief create a new Orxonox
44*/
45Orxonox::Orxonox ()
46{
47  pause = false;
48}
49
50/**
51   \brief remove Orxonox from memory
52*/
53Orxonox::~Orxonox () 
54{
55  Orxonox::singletonRef = NULL;
56  if( world != NULL) delete world;
57  if( localinput != NULL) delete world;
58  if( resources != NULL) delete resources;
59  delete GraphicsEngine::getInstance(); // deleting the Graphics
60  delete ResourceManager::getInstance(); // deletes the Resource Manager
61  GLFont::disableFonts();
62}
63
64/** \brief this is a singleton class to prevent duplicates */
65Orxonox* Orxonox::singletonRef = 0;
66
67/**
68   \returns reference or new Object of Orxonox if not existent.
69*/
70Orxonox* Orxonox::getInstance (void)
71{
72  if (singletonRef == NULL)
73    singletonRef = new Orxonox();
74  return singletonRef;
75}
76
77/**
78   \brief this finds the config file
79   
80   Since the config file varies from user to user and since one may want to specify different config files
81   for certain occasions or platforms this function finds the right config file for every occasion and stores
82   it's path and name into configfilename
83*/
84void Orxonox::getConfigFile (int argc, char** argv)
85{
86  strcpy (configfilename, "orxonox.conf");
87}
88
89/**
90   \brief initialize Orxonox with command line
91*/
92int Orxonox::init (int argc, char** argv)
93{
94  // parse command line
95  // config file
96 
97  getConfigFile (argc, argv);
98  SDL_Init (SDL_INIT_TIMER);
99  // initialize everything
100  if( initVideo() == -1) return -1;
101  if( initSound() == -1) return -1;
102  printf("> Initializing input\n");
103  if( initInput() == -1) return -1;
104  printf("> Initializing networking\n");
105  if( initNetworking () == -1) return -1;
106  printf("> Initializing resources\n");
107  if( initResources () == -1) return -1;
108  //printf("> Initializing world\n");
109  //if( init_world () == -1) return -1; PB: world will be initialized when started
110 
111  return 0;
112}
113
114/**
115   \brief initializes SDL and OpenGL
116*/
117int Orxonox::initVideo() 
118{
119  PRINTF(3)("> Initializing video\n");
120 
121  GraphicsEngine::getInstance();
122 
123  return 0;
124}
125
126
127/**
128   \brief initializes the sound engine
129*/
130int Orxonox::initSound() 
131{
132  printf("> Initializing sound\n");
133  // SDL_Init(SDL_INIT_AUDIO);
134  printf("Not yet implemented\n");
135  return 0;
136}
137
138
139/**
140   \brief initializes input functions
141*/
142int Orxonox::initInput() 
143{
144  // create localinput
145  localinput = new CommandNode( configfilename);
146 
147  return 0;
148}
149
150
151/**
152   \brief initializes network system
153*/
154int Orxonox::initNetworking() 
155{
156  printf("Not yet implemented\n");
157  return 0;
158}
159
160
161/**
162   \brief initializes and loads resource files
163*/
164int Orxonox::initResources() 
165{
166  //  printf("Not yet implemented\n");
167  PRINT(3)("initializing ResourceManager\n");
168  resourceManager = ResourceManager::getInstance();
169  resourceManager->setDataDir("../data/");
170  return 0;
171  PRINT(3)("initializing TextEngine\n");
172  GLFont::enableFonts();
173}
174
175
176/**
177   \brief initializes the world
178*/
179int Orxonox::initWorld() 
180{
181  //world = new World();
182 
183  // TO DO: replace this with a menu/intro
184  //world->load_debug_level();
185 
186  return 0;
187}
188
189
190/**
191   \brief starts the orxonox game or menu
192
193   here is the central orxonox state manager. There are currently two states
194   - menu
195   - game-play
196   both states manage their states themselfs again.
197*/
198void Orxonox::start()
199{
200 
201  this->gameLoader = GameLoader::getInstance();
202  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
203  this->gameLoader->init();
204  this->gameLoader->start();
205}
206
207
208/**
209   \brief exits Orxonox
210*/
211void Orxonox::quitGame() 
212{
213  bQuitOrxonox = true;
214}
215
216
217
218/**
219   \brief handles sprecial events from localinput
220   \param event: an event not handled by the CommandNode
221*/
222void Orxonox::eventHandler(SDL_Event* event)
223{
224  // Handle special events such as reshape, quit, focus changes
225  switch (event->type)
226    {
227    case SDL_VIDEORESIZE:
228      GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance();
229      tmpGEngine->resolutionChanged(&event->resize);
230      break;
231    }
232}
233 
234
235/**
236   \brief handle keyboard commands that are not meant for WorldEntities
237   \param cmd: the command to handle
238   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
239*/
240bool Orxonox::systemCommand(Command* cmd)
241{
242  /*
243  if( !strcmp( cmd->cmd, "quit"))
244    {
245      if( !cmd->bUp) this->gameLoader->stop();
246      return true;
247    }
248  return false;
249  */
250  return false;
251}
252
253/**
254   \brief retrieve a pointer to the local CommandNode
255   \return a pointer to localinput
256*/
257CommandNode* Orxonox::getLocalInput()
258{
259  return localinput;
260}
261
262
263/**
264   \brief retrieve a pointer to the local World
265   \return a pointer to world
266*/
267World* Orxonox::getWorld()
268{
269  return world;
270}
271
272/**
273   \return The reference of the SDL-screen of orxonox
274*/
275SDL_Surface* Orxonox::getScreen ()
276{
277  return this->screen;
278}
279
280
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
323
324int startOrxonox(int argc, char** argv)
325{
326  printf(">>> Starting Orxonox <<<\n");
327  Orxonox *orx = Orxonox::getInstance();
328 
329  if((*orx).init(argc, argv) == -1)
330    {
331      printf("! Orxonox initialization failed\n");
332      return -1;
333    }
334 
335  orx->start();
336 
337  delete orx;
338 
339}
340
341
342#include "list.h"
343#include "world_entity.h"
344#include "vector.h"
345#include "player.h"
346#include "base_object.h"
347#include <asm/msr.h>
348#include <linux/timex.h>
349
350
351#define LIST_MAX 1000
352#define VECTOR_MAX 1000000
353#define ITERATIONS 10000
354
355
356int startBenchmarks()
357{
358
359  printf("===========================================================\n");
360  printf("=                      BENCHMARKS                         =\n");
361  printf("===========================================================\n");
362  printf(" the author is not paying any attention to cacheing effects\n");
363  printf(" of the CPU.\n\n");
364  printf("[title]\t\t\t\t\t     [cycles]\t[loops]\n\n");
365  //  printf("------------------------------------------------------------\n\n");
366
367  // first measure the time overhead:
368  unsigned long ini, end, dt, tmp;
369  rdtscl(ini); rdtscl(end);
370  dt = end - ini;
371
372  int type = -1; 
373  /* type   -1 == all
374     type    0 == framework
375     type    1 == vector
376     type    2 == quaternion
377     type    3 == lists
378  */
379  if(type == 0 || type == -1)
380    {
381      /* framework test*/
382     
383      printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS);
384      /* ************WorldEntity class test************** */
385      WorldEntity* w = NULL;
386      int i = 0;
387      unsigned long mittel = 0;
388     
389      for(i = 0; i < ITERATIONS; ++i)
390        {
391          rdtscl(ini);
392         
393          WorldEntity* w = new WorldEntity();
394         
395          rdtscl(end);
396          delete w;
397          mittel += (end - ini - dt);
398        }
399      float mi = mittel / (float)ITERATIONS;
400      printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi);
401     
402      /*
403        mittel = 0;
404        for(i = 0; i < ITERATIONS; ++i)
405        {
406        rdtscl(ini);
407       
408        WorldEntity* w = new Primitive(P_SPHERE);
409       
410        rdtscl(end);
411        delete w;
412        mittel += (end - ini - dt);
413        }
414        mi = mittel / (float)ITERATIONS;
415        printf(" Generate a Primitive  object:\t\t%11.2f\n", mi);
416      */
417
418      mittel = 0;
419      for(i = 0; i < ITERATIONS; ++i)
420        {
421          rdtscl(ini);
422         
423          Vector* v = new Vector();
424         
425          rdtscl(end);
426          delete v;
427          mittel += (end - ini - dt);
428        }
429      mi = mittel / (float)ITERATIONS;
430      printf(" Generate a Vector object:\t\t%11.2f\n", mi);
431
432
433     mittel = 0;
434      for(i = 0; i < ITERATIONS; ++i)
435        {
436          rdtscl(ini);
437         
438          Quaternion* q = new Quaternion();
439         
440          rdtscl(end);
441          delete q;
442          mittel += (end - ini - dt);
443        }
444      mi = mittel / (float)ITERATIONS;
445      printf(" Generate a Quaternion object:\t\t%11.2f\n", mi);
446
447
448
449
450      printf("\nCalling function inline &| virtual, \t\t\t%i\n", ITERATIONS);
451      mittel = 0;
452      w = new WorldEntity();
453      for(i = 0; i < ITERATIONS; ++i)
454        {
455          rdtscl(ini);
456         
457          w->tick(0.0f);
458
459          rdtscl(end);
460          mittel += (end - ini - dt);
461          }
462      //delete w;
463      mi = mittel / (float)ITERATIONS;
464      printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi);
465
466
467      mittel = 0;
468      WorldEntity wo;
469      for(i = 0; i < ITERATIONS; ++i)
470        {
471          rdtscl(ini);
472         
473          wo.tick(0.0f);
474           
475          rdtscl(end);
476          mittel += (end - ini - dt);
477          }
478      //delete w;
479      mi = mittel / (float)ITERATIONS;
480      printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi);
481
482     
483      mittel = 0;
484      BaseObject* bo = new BaseObject();
485      for(i = 0; i < ITERATIONS; ++i)
486        {
487          rdtscl(ini);
488         
489          bo->isFinalized();
490           
491          rdtscl(end);
492          mittel += (end - ini - dt);
493          }
494      //delete w;
495      mi = mittel / (float)ITERATIONS;
496      printf(" Inl funct BaseObject::isFinazlized(): \t%11.2f\n", mi);
497
498     
499      tList<WorldEntity>* list = new tList<WorldEntity>();
500
501     
502      /* ************Primitvie class test************** */
503      list = new tList<WorldEntity>();
504 
505     
506      /*
507        mittel = 0;
508        w = new Primitive(P_SPHERE);
509        for(i = 0; i < ITERATIONS; ++i)
510        {
511        rdtscl(ini);
512       
513        w->tick(0.0f);
514       
515        rdtscl(end);
516        mittel += (end - ini - dt);
517        }
518        mi = mittel / (float)ITERATIONS;
519        printf(" Call function tick() of Prim:\t\t%11.2f\n", mi);
520      */
521     
522    }
523 
524  if(type == 1 || type == -1)
525    {
526      printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX);
527      /* vector test */
528      Vector* a = new Vector(1.3, 5.3, 4.1);
529      Vector* b = new Vector(0.4, 2.5, 6.2);
530      Vector* c = new Vector();
531     
532      unsigned long mittel, ini, end;
533      float mi;
534      int i = 0;
535      // addition
536      mittel = 0;
537      for(i = 0; i < VECTOR_MAX; ++i)
538        {
539          rdtscl(ini);
540         
541          *c = *a + *b;
542           
543          rdtscl(end);
544          mittel += (end - ini - dt);
545        }
546      mi = mittel / (float)VECTOR_MAX;
547      printf(" Addition of two vectors:\t\t%11.2f\n", mi);
548     
549      // multiplikation
550
551      mittel = 0;
552      for(i = 0; i < VECTOR_MAX; ++i)
553        {
554          rdtscl(ini);
555         
556          *c = a->cross( *b);
557           
558          rdtscl(end);
559          mittel += (end - ini - dt);
560        }
561      mi = mittel / (float)VECTOR_MAX;
562      printf(" CrossMult of two vectors:\t\t%11.2f\n", mi);
563
564    }
565  if( type == 2 || type == -1)
566    {
567      /* quaternion test */
568      printf("\nDoing some simple quaternion operations: \t\t%i\n", VECTOR_MAX);
569      /* vector test */
570      Quaternion* a = new Quaternion();
571      Quaternion* b = new Quaternion();
572      Quaternion* c = new Quaternion();
573     
574      unsigned long mittel, ini, end;
575      float mi;
576      int i = 0;
577      // quaternion generieren mit spez konstruktor
578      mittel = 0;
579      Vector* qa = new Vector(4.6, 9.3, 0.4);
580      Vector* qb = new Vector(3.5, 6.1, 4.3);
581      for(i = 0; i < VECTOR_MAX; ++i)
582        {
583          rdtscl(ini);
584         
585          Quaternion* qu = new Quaternion(*qa, *qb);
586         
587          rdtscl(end);
588          delete qu;
589          mittel += (end - ini - dt);
590        }
591      delete a;
592      delete b;
593      mi = mittel / (float)VECTOR_MAX;
594      printf(" Gen. quatern. betw. two vectors:\t%11.2f\n", mi);
595     
596     
597      // multiplication
598      mittel = 0;
599      for(i = 0; i < VECTOR_MAX; ++i)
600        {
601          rdtscl(ini);
602         
603          *c = *a * *b;
604         
605          rdtscl(end);
606          mittel += (end - ini - dt);
607        }
608      mi = mittel / (float)VECTOR_MAX;
609      printf(" Multiplying two quat.(=rot): a * b\t%11.2f\n", mi);
610     
611     
612     
613      // rotating a vector by a quaternion
614      mittel = 0;
615      for(i = 0; i < VECTOR_MAX; ++i)
616        {
617          rdtscl(ini);
618         
619          *qa = a->apply(*qb);
620         
621          rdtscl(end);
622          mittel += (end - ini - dt);
623        }
624      mi = mittel / (float)VECTOR_MAX;
625      printf(" Rot a vec by a quat: q->apply(v)\t%11.2f\n", mi);
626     
627     
628     
629      // generate rotation matrix
630      mittel = 0;
631      float matrix[4][4];
632      for(i = 0; i < VECTOR_MAX; ++i)
633        {
634          rdtscl(ini);
635         
636          a->matrix(matrix);
637         
638          rdtscl(end);
639          mittel += (end - ini - dt);
640        }
641      mi = mittel / (float)VECTOR_MAX;
642      printf(" Generate rot matrix: q->matrix(m)\t%11.2f\n", mi);
643    }
644  if( type == 3 || type == -1)
645    {
646      /* list tests*/
647      printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX);
648      tList<char>* list = new tList<char>();
649      char* name;
650     
651      printf(" Adding[1..10] elements to list, found:\n");
652      list->add("1");
653      list->add("2");
654      list->add("3");
655      list->add("4");
656      list->add("5");
657      list->add("6");
658      list->add("7");
659      list->add("8");
660      list->add("9");
661      list->add("10");
662     
663      /*give list out */
664      tIterator<char>* iterator = list->getIterator();
665      name = iterator->nextElement();
666      printf("  List Elements: \t\t");
667      while( name != NULL)
668        {
669          printf("%s,", name);
670          name = iterator->nextElement();
671        }
672      delete iterator;
673      printf("\n");
674     
675     
676      /*removing some elements from the list*/
677      printf(" Removing elements [2,3,6,8,10], adding [11] now found:\n");
678      list->remove("2");
679      list->remove("3");
680      list->remove("6");
681      list->remove("8");
682      list->remove("10");
683      list->add("11");
684      /*give list out */
685      iterator = list->getIterator();
686      name = iterator->nextElement();
687      printf("  List Elements: \t\t");
688      while( name != NULL)
689        {
690          printf("%s,", name);
691          name = iterator->nextElement();
692        }
693      delete iterator;
694      printf("\n");
695     
696      delete list;
697      printf("\nChecking list performance:\t\t\t\t%i\n", LIST_MAX);
698     
699      tList<int>* plist = new tList<int>();
700      unsigned long mittel, ini, end;
701      float mi;
702      int i = 0;
703      mittel = 0;
704      for(i = 0; i < LIST_MAX; ++i)
705        {
706          rdtscl(ini);
707         
708          plist->add(&i);
709         
710          rdtscl(end);
711          mittel += (end - ini - dt);
712        }
713      mi = mittel / (float)LIST_MAX;
714      printf(" Adding reference to list:\t\t%11.2f\n", mi);
715     
716      mittel = 0;
717      for(i = 0; i < LIST_MAX; ++i)
718        {
719          rdtscl(ini);
720         
721          plist->remove(&i);
722         
723          rdtscl(end);
724          mittel += (end - ini - dt);
725        }
726      mi = mittel / (float)LIST_MAX;
727      printf(" Removing 1st reference from list:\t%11.2f\n", mi);
728     
729     
730     
731    }
732 
733}
Note: See TracBrowser for help on using the repository browser.