Index: orxonox/branches/textEngine/src/orxonox.cc
===================================================================
--- orxonox/branches/textEngine/src/orxonox.cc	(revision 3467)
+++ orxonox/branches/textEngine/src/orxonox.cc	(revision 3681)
@@ -22,14 +22,18 @@
    main-programmer: Patrick Boenzli
    co-programmer: Christian Meyer
+   co-programmer: Benjamin Grauer: injected ResourceManager/GraphicsEngine
 */
 
 #include "orxonox.h"
+
 #include "world.h"
-#include "camera.h"
 #include "data_tank.h"
 #include "command_node.h"
 #include "game_loader.h"
+#include "graphics_engine.h"
+#include "resource_manager.h"
+
 #include <string.h>
-int verbose;
+int verbose = 3;
 
 using namespace std;
@@ -51,8 +55,8 @@
   if( world != NULL) delete world;
   if( localinput != NULL) delete world;
-  if( localcamera != NULL) delete localcamera;
   if( resources != NULL) delete resources;
-}
-
+  delete GraphicsEngine::getInstance(); // deleting the Graphics
+  delete ResourceManager::getInstance(); // deletes the Resource Manager
+}
 
 /** \brief this is a singleton class to prevent duplicates */
@@ -111,70 +115,8 @@
 int Orxonox::initVideo() 
 {
-  printf("> Initializing video\n");
-  if (SDL_Init(SDL_INIT_VIDEO) == -1)
-    {
-      printf ("could not initialize SDL Video\n");
-      return -1;
-    }
-  // Set video mode
-  // TO DO: parse arguments for settings
-  //SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
-  //SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
-  //SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
-  //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
-  
-
-  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );   
-  SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);    
-  SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0);  
-  SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0);
-  SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0);
-  SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0);
-  SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0);
-
-
-
-  int bpp = 16;
-  int width = 640;
-  int height = 480;
-  //Uint32 flags = SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER; /* \todo: SDL_OPENGL doen't permit to load images*/
-  //Uint32 flags = SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER;
-
-  Uint32 videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE;
-
-  /* query SDL for information about our video hardware */
-  const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo ();
-  
-  if( videoInfo == NULL)
-    {
-      printf ("Orxonox::initVideo() - Failed getting Video Info :%s\n", SDL_GetError()); 
-      SDL_Quit ();
-    }
-  if( videoInfo->hw_available)
-    videoFlags |= SDL_HWSURFACE;
-  else 
-    videoFlags |= SDL_SWSURFACE;
-  /*
-  if(VideoInfo -> blit_hw)                            
-    VideoFlags |= SDL_HWACCEL;
-  */
-  
-  if((this->screen = SDL_SetVideoMode (width, height, bpp, videoFlags)) == NULL)
-  {
-    printf("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", width, height, bpp, videoFlags, SDL_GetError());
-    SDL_Quit();
-    return -1;
-  }
-  
-  // Set window labeling
-  SDL_WM_SetCaption ("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION);
-  
-  // TO DO: Create a cool icon and use it here
-  // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask);  
-
-  // OpenGL stuff
-  glClearColor (0.0, 0.0, 0.0, 0.0);
-  glEnable (GL_DEPTH_TEST);
-   
+  PRINTF(3)("> Initializing video\n");
+  
+  GraphicsEngine::getInstance();
+  
   return 0;
 }
@@ -220,5 +162,8 @@
 int Orxonox::initResources() 
 {
-  printf("Not yet implemented\n");
+  //  printf("Not yet implemented\n");
+  PRINT(3)("initializing ResourceManager\n");
+  resourceManager = ResourceManager::getInstance();
+  resourceManager->setDataDir("../data/");
   return 0;
 }
@@ -274,4 +219,11 @@
 {
   // Handle special events such as reshape, quit, focus changes
+  switch (event->type)
+    {
+    case SDL_VIDEORESIZE:
+      GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance();
+      tmpGEngine->resolutionChanged(&event->resize);
+      break;
+    }
 }
  
@@ -295,15 +247,4 @@
 }
 
-
-/**
-   \brief retrieve a pointer to the local Camera
-   \return a pointer to localcamera
-*/
-Camera* Orxonox::getCamera()
-{
-  return localcamera;
-}
-
-
 /**
    \brief retrieve a pointer to the local CommandNode
@@ -333,4 +274,6 @@
 }
 
+
+
 /**
    \brief main function
@@ -340,4 +283,41 @@
 int main(int argc, char** argv) 
 {  
+  
+  /* reading arguments 
+     
+     currently supported arguments are:
+     <no args>                   ::    just starts orxonox
+     --benchmark                 ::    start the benchmark without starting orxonox
+     
+     this is a preselection: it matches to one of the start* functions, the
+     finetuning is made in those functions.
+  */
+
+
+  int i;
+  for(i = 0; i < argc; ++i)
+    {
+      if(! strcmp( "--help", argv[i])) return startHelp();
+      else if(! strcmp( "--benchmark", argv[i])) return startBenchmarks();
+    }
+
+  PRINTF(2)("Orxonox does not understand the arguments");
+  return startOrxonox(argc, argv);
+}
+
+
+
+int startHelp()
+{
+  printf("orxonox: starts the orxonox game - rules\n");
+  printf("usage: orxonox [arg]\n\n");
+  printf("valid options:\n");
+  printf(" --benchmark\tstarts the orxonox benchmark\n");
+  printf(" --help \tshows this menu\n");
+}
+
+
+int startOrxonox(int argc, char** argv)
+{
   printf(">>> Starting Orxonox <<<\n");
   Orxonox *orx = Orxonox::getInstance();
@@ -351,6 +331,399 @@
   orx->start();
   
-  //delete orx;
-  
-  return 0;
-}
+  delete orx;
+  
+}
+
+
+#include "list.h"
+#include "world_entity.h"
+#include "vector.h"
+#include "player.h"
+#include "base_object.h"
+#include <asm/msr.h>
+#include <linux/timex.h>
+
+
+#define LIST_MAX 1000
+#define VECTOR_MAX 1000000
+#define ITERATIONS 10000
+
+
+int startBenchmarks()
+{
+
+  printf("===========================================================\n");
+  printf("=                      BENCHMARKS                         =\n");
+  printf("===========================================================\n");
+  printf(" the author is not paying any attention to cacheing effects\n");
+  printf(" of the CPU.\n\n");
+  printf("[title]\t\t\t\t\t     [cycles]\t[loops]\n\n");
+  //  printf("------------------------------------------------------------\n\n");
+
+  // first measure the time overhead:
+  unsigned long ini, end, dt, tmp;
+  rdtscl(ini); rdtscl(end);
+  dt = end - ini;
+
+  int type = -1; 
+  /* type   -1 == all 
+     type    0 == framework
+     type    1 == vector
+     type    2 == quaternion
+     type    3 == lists
+  */
+  if(type == 0 || type == -1)
+    {
+      /* framework test*/
+      
+      printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS);
+      /* ************WorldEntity class test************** */
+      WorldEntity* w = NULL;
+      int i = 0;
+      unsigned long mittel = 0;
+      
+      for(i = 0; i < ITERATIONS; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  WorldEntity* w = new WorldEntity();
+	  
+	  rdtscl(end);
+	  delete w;
+	  mittel += (end - ini - dt);
+	}
+      float mi = mittel / (float)ITERATIONS;
+      printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi);
+      
+      /*
+	mittel = 0;
+	for(i = 0; i < ITERATIONS; ++i)
+	{
+	rdtscl(ini);
+	
+	WorldEntity* w = new Primitive(P_SPHERE);
+	
+	rdtscl(end);
+	delete w;
+	mittel += (end - ini - dt);
+	}
+	mi = mittel / (float)ITERATIONS;
+	printf(" Generate a Primitive  object:\t\t%11.2f\n", mi);
+      */
+
+      mittel = 0;
+      for(i = 0; i < ITERATIONS; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  Vector* v = new Vector();
+	  
+	  rdtscl(end);
+	  delete v;
+	  mittel += (end - ini - dt);
+	}
+      mi = mittel / (float)ITERATIONS;
+      printf(" Generate a Vector object:\t\t%11.2f\n", mi);
+
+
+     mittel = 0;
+      for(i = 0; i < ITERATIONS; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  Quaternion* q = new Quaternion();
+	  
+	  rdtscl(end);
+	  delete q;
+	  mittel += (end - ini - dt);
+	}
+      mi = mittel / (float)ITERATIONS;
+      printf(" Generate a Quaternion object:\t\t%11.2f\n", mi);
+
+
+
+
+      printf("\nCalling function inline &| virtual, \t\t\t%i\n", ITERATIONS);
+      mittel = 0;
+      w = new WorldEntity();
+      for(i = 0; i < ITERATIONS; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  w->tick(0.0f);
+
+	  rdtscl(end);
+	  mittel += (end - ini - dt);
+	  }
+      //delete w;
+      mi = mittel / (float)ITERATIONS;
+      printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi);
+
+
+      mittel = 0;
+      WorldEntity wo;
+      for(i = 0; i < ITERATIONS; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  wo.tick(0.0f);
+	   
+	  rdtscl(end);
+	  mittel += (end - ini - dt);
+	  }
+      //delete w;
+      mi = mittel / (float)ITERATIONS;
+      printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi);
+
+      
+      mittel = 0;
+      BaseObject* bo = new BaseObject();
+      for(i = 0; i < ITERATIONS; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  bo->isFinalized();
+	   
+	  rdtscl(end);
+	  mittel += (end - ini - dt);
+	  }
+      //delete w;
+      mi = mittel / (float)ITERATIONS;
+      printf(" Inl funct BaseObject::isFinazlized(): \t%11.2f\n", mi);
+
+      
+      tList<WorldEntity>* list = new tList<WorldEntity>();
+
+      
+      /* ************Primitvie class test************** */
+      list = new tList<WorldEntity>();
+ 
+      
+      /*
+	mittel = 0;
+	w = new Primitive(P_SPHERE);
+	for(i = 0; i < ITERATIONS; ++i)
+	{
+	rdtscl(ini);
+	
+	w->tick(0.0f);
+	
+	rdtscl(end);
+	mittel += (end - ini - dt);
+	}
+	mi = mittel / (float)ITERATIONS;
+	printf(" Call function tick() of Prim:\t\t%11.2f\n", mi);
+      */
+      
+    }
+  
+  if(type == 1 || type == -1)
+    {
+      printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX);
+      /* vector test */
+      Vector* a = new Vector(1.3, 5.3, 4.1);
+      Vector* b = new Vector(0.4, 2.5, 6.2);
+      Vector* c = new Vector();
+      
+      unsigned long mittel, ini, end;
+      float mi;
+      int i = 0;
+      // addition
+      mittel = 0;
+      for(i = 0; i < VECTOR_MAX; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  *c = *a + *b;
+	   
+	  rdtscl(end);
+	  mittel += (end - ini - dt);
+	}
+      mi = mittel / (float)VECTOR_MAX;
+      printf(" Addition of two vectors:\t\t%11.2f\n", mi);
+      
+      // multiplikation
+
+      mittel = 0;
+      for(i = 0; i < VECTOR_MAX; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  *c = a->cross( *b);
+	   
+	  rdtscl(end);
+	  mittel += (end - ini - dt);
+	}
+      mi = mittel / (float)VECTOR_MAX;
+      printf(" CrossMult of two vectors:\t\t%11.2f\n", mi);
+
+    }
+  if( type == 2 || type == -1)
+    {
+      /* quaternion test */
+      printf("\nDoing some simple quaternion operations: \t\t%i\n", VECTOR_MAX);
+      /* vector test */
+      Quaternion* a = new Quaternion();
+      Quaternion* b = new Quaternion();
+      Quaternion* c = new Quaternion();
+      
+      unsigned long mittel, ini, end;
+      float mi;
+      int i = 0;
+      // quaternion generieren mit spez konstruktor
+      mittel = 0;
+      Vector* qa = new Vector(4.6, 9.3, 0.4);
+      Vector* qb = new Vector(3.5, 6.1, 4.3);
+      for(i = 0; i < VECTOR_MAX; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  Quaternion* qu = new Quaternion(*qa, *qb);
+	  
+	  rdtscl(end);
+	  delete qu;
+	  mittel += (end - ini - dt);
+	}
+      delete a;
+      delete b;
+      mi = mittel / (float)VECTOR_MAX;
+      printf(" Gen. quatern. betw. two vectors:\t%11.2f\n", mi);
+      
+      
+      // multiplication
+      mittel = 0;
+      for(i = 0; i < VECTOR_MAX; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  *c = *a * *b;
+	  
+	  rdtscl(end);
+	  mittel += (end - ini - dt);
+	}
+      mi = mittel / (float)VECTOR_MAX;
+      printf(" Multiplying two quat.(=rot): a * b\t%11.2f\n", mi);
+      
+      
+      
+      // rotating a vector by a quaternion
+      mittel = 0;
+      for(i = 0; i < VECTOR_MAX; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  *qa = a->apply(*qb);
+	  
+	  rdtscl(end);
+	  mittel += (end - ini - dt);
+	}
+      mi = mittel / (float)VECTOR_MAX;
+      printf(" Rot a vec by a quat: q->apply(v)\t%11.2f\n", mi);
+      
+      
+      
+      // generate rotation matrix
+      mittel = 0;
+      float matrix[4][4];
+      for(i = 0; i < VECTOR_MAX; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  a->matrix(matrix);
+	  
+	  rdtscl(end);
+	  mittel += (end - ini - dt);
+	}
+      mi = mittel / (float)VECTOR_MAX;
+      printf(" Generate rot matrix: q->matrix(m)\t%11.2f\n", mi);
+    }
+  if( type == 3 || type == -1)
+    {
+      /* list tests*/
+      printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX);
+      tList<char>* list = new tList<char>();
+      char* name;
+      
+      printf(" Adding[1..10] elements to list, found:\n");
+      list->add("1");
+      list->add("2");
+      list->add("3");
+      list->add("4");
+      list->add("5");
+      list->add("6");
+      list->add("7");
+      list->add("8");
+      list->add("9");
+      list->add("10");
+      
+      /*give list out */
+      tIterator<char>* iterator = list->getIterator();
+      name = iterator->nextElement();
+      printf("  List Elements: \t\t");
+      while( name != NULL)
+	{
+	  printf("%s,", name);
+	  name = iterator->nextElement();
+	}
+      delete iterator;
+      printf("\n");
+      
+      
+      /*removing some elements from the list*/
+      printf(" Removing elements [2,3,6,8,10], adding [11] now found:\n");
+      list->remove("2");
+      list->remove("3");
+      list->remove("6");
+      list->remove("8");
+      list->remove("10");
+      list->add("11");
+      /*give list out */
+      iterator = list->getIterator();
+      name = iterator->nextElement();
+      printf("  List Elements: \t\t");
+      while( name != NULL)
+	{
+	  printf("%s,", name);
+	  name = iterator->nextElement();
+	}
+      delete iterator;
+      printf("\n");
+      
+      delete list;
+      printf("\nChecking list performance:\t\t\t\t%i\n", LIST_MAX);
+      
+      tList<int>* plist = new tList<int>();
+      unsigned long mittel, ini, end;
+      float mi;
+      int i = 0;
+      mittel = 0;
+      for(i = 0; i < LIST_MAX; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  plist->add(&i);
+	  
+	  rdtscl(end);
+	  mittel += (end - ini - dt);
+	}
+      mi = mittel / (float)LIST_MAX;
+      printf(" Adding reference to list:\t\t%11.2f\n", mi);
+      
+      mittel = 0;
+      for(i = 0; i < LIST_MAX; ++i)
+	{
+	  rdtscl(ini);
+	  
+	  plist->remove(&i);
+	  
+	  rdtscl(end);
+	  mittel += (end - ini - dt);
+	}
+      mi = mittel / (float)LIST_MAX;
+      printf(" Removing 1st reference from list:\t%11.2f\n", mi);
+      
+      
+      
+    }
+  
+}
