Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4139 in orxonox.OLD for orxonox/branches/md2_loader/src/orxonox.cc


Ignore:
Timestamp:
May 10, 2005, 10:39:01 AM (20 years ago)
Author:
patrick
Message:

orxonox/branches/md2_loader: merged trunk into branche using: svn merge ../trunk/ md2_loader -r 4063:HEAD

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/md2_loader/src/orxonox.cc

    r4072 r4139  
    3232#include "data_tank.h"
    3333#include "command_node.h"
     34#include "ini_parser.h"
    3435#include "game_loader.h"
    3536#include "graphics_engine.h"
     
    3738#include "text_engine.h"
    3839#include "factory.h"
     40#include "benchmark.h"
    3941
    4042#include <string.h>
     
    4648/**
    4749   \brief create a new Orxonox
     50
     51   In this funcitons only global values are set. The game will not be started here.
    4852*/
    4953Orxonox::Orxonox ()
     
    5458  this->resources = NULL;
    5559  this->localinput = NULL;
     60
     61  this->argc = 0;
     62  this->argv = NULL;
    5663}
    5764
     
    93100void Orxonox::getConfigFile (int argc, char** argv)
    94101{
    95   strcpy (configfilename, "orxonox.conf");
     102  strcpy (configfilename, "~/.orxonox/orxonox.conf");
    96103}
    97104
     
    101108int Orxonox::init (int argc, char** argv)
    102109{
     110  this->argc = argc;
     111  this->argv = argv;
    103112  // parse command line
    104113  // config file
     
    107116  SDL_Init (SDL_INIT_TIMER);
    108117  // initialize everything
     118  printf("> Initializing resources\n");
     119  if( initResources () == -1) return -1;
     120
    109121  if( initVideo() == -1) return -1;
    110122  if( initSound() == -1) return -1;
     
    113125  printf("> Initializing networking\n");
    114126  if( initNetworking () == -1) return -1;
    115   printf("> Initializing resources\n");
    116   if( initResources () == -1) return -1;
    117127  //printf("> Initializing world\n");
    118128  //if( init_world () == -1) return -1; PB: world will be initialized when started
     
    129139 
    130140  GraphicsEngine::getInstance();
    131  
     141   
    132142  return 0;
    133143}
     
    152162{
    153163  // create localinput
    154   localinput = new CommandNode( configfilename);
     164  localinput = new CommandNode(configfilename);
    155165 
    156166  return 0;
     
    173183int Orxonox::initResources()
    174184{
    175   //  printf("Not yet implemented\n");
    176185  PRINT(3)("initializing ResourceManager\n");
    177186  resourceManager = ResourceManager::getInstance();
    178   if (!resourceManager->setDataDir("../data/"))
    179     {
    180       PRINTF(1)("Data Could not be located\n");
     187
     188  // create parser
     189  IniParser parser (DEFAULT_CONFIG_FILE);
     190  if( parser.getSection (CONFIG_SECTION_DATA) == -1)
     191    {
     192      PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE);
     193      return -1;
     194    }
     195  char namebuf[256];
     196  char valuebuf[256];
     197  memset (namebuf, 0, 256);
     198  memset (valuebuf, 0, 256);
     199 
     200  while( parser.nextVar (namebuf, valuebuf) != -1)
     201    {
     202      if (!strcmp(namebuf, CONFIG_NAME_DATADIR))
     203        {
     204          //  printf("Not yet implemented\n");
     205          if (!resourceManager->setDataDir(valuebuf))
     206            {
     207              PRINTF(1)("Data Could not be located\n");
     208              exit(-1);
     209            }
     210        }
     211     
     212      memset (namebuf, 0, 256);
     213      memset (valuebuf, 0, 256);
     214    }
     215 
     216  if (!resourceManager->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE))
     217    {
     218      PRINTF(1)("The DataDirectory %s could not be verified\nPlease Change in File %s Section %s Entry %s to a suitable value\n",
     219                resourceManager->getDataDir(),
     220                DEFAULT_CONFIG_FILE,
     221                CONFIG_SECTION_DATA,
     222                CONFIG_NAME_DATADIR);
    181223      exit(-1);
    182224    }
     225
    183226
    184227  PRINT(3)("initializing TextEngine\n");
    185228  TextEngine::getInstance();
     229
     230  return 0;
    186231}
    187232
     
    213258 
    214259  this->gameLoader = GameLoader::getInstance();
    215   this->gameLoader->loadCampaign("../data/worlds/DefaultCampaign.oxc");
     260  this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");
    216261  //  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
    217262  this->gameLoader->init();
     
    301346*/
    302347int main(int argc, char** argv)
    303 
    304  
    305   /* reading arguments
    306      
    307      currently supported arguments are:
    308      <no args>                   ::    just starts orxonox
    309      --benchmark                 ::    start the benchmark without starting orxonox
    310      
    311      this is a preselection: it matches to one of the start* functions, the
    312      finetuning is made in those functions.
    313   */
    314 
    315   printf("++INFO++++++++++++++++++++++++++++++++++++++++++++++++\n");
     348{
     349
    316350  printf("+ This version of orxonox is for testing purposes    +\n");
    317351  printf("+ In order to run it, you will need some files for   +\n");
     
    326360  for(i = 1; i < argc; ++i)
    327361    {
    328       if(! strcmp( "--help", argv[i])) return startHelp();
    329       else if(! strcmp( "--benchmark", argv[i])) return startBenchmarks();
    330       else if(! strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
    331       else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
     362      if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv);
     363      else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks();
     364      else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
     365      //      else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
    332366    }
    333367
     
    337371
    338372
    339 int startHelp()
     373int startHelp(int argc, char** argv)
    340374{
    341375  PRINT(0)("orxonox: starts the orxonox game - rules\n");
    342   PRINT(0)("usage: orxonox [arg]\n\n");
     376  PRINT(0)("usage: orxonox [arg [arg...]]\n\n");
    343377  PRINT(0)("valid options:\n");
    344   PRINT(0)(" --benchmark\tstarts the orxonox benchmark\n");
    345   PRINT(0)(" --help \tshows this menu\n");
    346   PRINT(0)(" --gui/-g \tDisplays the Gui on startup\n");
     378  {
     379    Gui* gui = new Gui(argc, argv);
     380    gui->printHelp();
     381    delete gui;
     382  }
     383  PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n");
     384  PRINT(0)(" -h|--help:\t\t\tshows this help\n");
    347385}
    348386
     
    357395      if (ResourceManager::isFile("~/.orxonox/orxonox.lock"))
    358396        ResourceManager::deleteFile("~/.orxonox/orxonox.lock");
    359       //      char* guiExec = new char[strlen(argv[0])+20];
    360       //      sprintf(guiExec,"%sGui --gui", argv[0]);
     397     
     398      // starting the GUI
    361399      Gui* gui = new Gui(argc, argv);
     400      gui->startGui();
     401
    362402      if (! gui->startOrxonox)
    363403        return 0;
     
    384424 
    385425}
    386 
    387 #if defined __linux__
    388 
    389 #include "list.h"
    390 #include "world_entity.h"
    391 #include "vector.h"
    392 #include "player.h"
    393 #include "base_object.h"
    394 
    395 #include <asm/msr.h>
    396 #include <linux/timex.h>
    397 
    398 
    399 #define LIST_MAX 1000
    400 #define VECTOR_MAX 1000000
    401 #define ITERATIONS 10000
    402 
    403 
    404 int startBenchmarks()
    405 {
    406 
    407   printf("===========================================================\n");
    408   printf("=                      BENCHMARKS                         =\n");
    409   printf("===========================================================\n");
    410   printf(" the author is not paying any attention to cacheing effects\n");
    411   printf(" of the CPU.\n\n");
    412   printf("[title]\t\t\t\t\t     [cycles]\t[loops]\n\n");
    413   //  printf("------------------------------------------------------------\n\n");
    414 
    415   // first measure the time overhead:
    416   unsigned long ini, end, dt, tmp;
    417   rdtscl(ini); rdtscl(end);
    418   dt = end - ini;
    419 
    420   int type = -1;
    421   /* type   -1 == all
    422      type    0 == framework
    423      type    1 == vector
    424      type    2 == quaternion
    425      type    3 == lists
    426   */
    427   if(type == 0 || type == -1)
    428     {
    429       /* framework test*/
    430      
    431       printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS);
    432       /* ************WorldEntity class test************** */
    433       WorldEntity* w = NULL;
    434       int i = 0;
    435       unsigned long mittel = 0;
    436      
    437       for(i = 0; i < ITERATIONS; ++i)
    438         {
    439           rdtscl(ini);
    440          
    441           WorldEntity* w = new WorldEntity();
    442          
    443           rdtscl(end);
    444           delete w;
    445           mittel += (end - ini - dt);
    446         }
    447       float mi = mittel / (float)ITERATIONS;
    448       printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi);
    449      
    450       /*
    451         mittel = 0;
    452         for(i = 0; i < ITERATIONS; ++i)
    453         {
    454         rdtscl(ini);
    455        
    456         WorldEntity* w = new Primitive(P_SPHERE);
    457        
    458         rdtscl(end);
    459         delete w;
    460         mittel += (end - ini - dt);
    461         }
    462         mi = mittel / (float)ITERATIONS;
    463         printf(" Generate a Primitive  object:\t\t%11.2f\n", mi);
    464       */
    465 
    466       mittel = 0;
    467       for(i = 0; i < ITERATIONS; ++i)
    468         {
    469           rdtscl(ini);
    470          
    471           Vector* v = new Vector();
    472          
    473           rdtscl(end);
    474           delete v;
    475           mittel += (end - ini - dt);
    476         }
    477       mi = mittel / (float)ITERATIONS;
    478       printf(" Generate a Vector object:\t\t%11.2f\n", mi);
    479 
    480 
    481      mittel = 0;
    482       for(i = 0; i < ITERATIONS; ++i)
    483         {
    484           rdtscl(ini);
    485          
    486           Quaternion* q = new Quaternion();
    487          
    488           rdtscl(end);
    489           delete q;
    490           mittel += (end - ini - dt);
    491         }
    492       mi = mittel / (float)ITERATIONS;
    493       printf(" Generate a Quaternion object:\t\t%11.2f\n", mi);
    494 
    495 
    496 
    497 
    498       printf("\nCalling function inline &| virtual, \t\t\t%i\n", ITERATIONS);
    499       mittel = 0;
    500       w = new WorldEntity();
    501       for(i = 0; i < ITERATIONS; ++i)
    502         {
    503           rdtscl(ini);
    504          
    505           w->tick(0.0f);
    506 
    507           rdtscl(end);
    508           mittel += (end - ini - dt);
    509           }
    510       //delete w;
    511       mi = mittel / (float)ITERATIONS;
    512       printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi);
    513 
    514 
    515       mittel = 0;
    516       WorldEntity wo;
    517       for(i = 0; i < ITERATIONS; ++i)
    518         {
    519           rdtscl(ini);
    520          
    521           wo.tick(0.0f);
    522            
    523           rdtscl(end);
    524           mittel += (end - ini - dt);
    525           }
    526       //delete w;
    527       mi = mittel / (float)ITERATIONS;
    528       printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi);
    529 
    530      
    531       mittel = 0;
    532       BaseObject* bo = new BaseObject();
    533       for(i = 0; i < ITERATIONS; ++i)
    534         {
    535           rdtscl(ini);
    536          
    537           bo->isFinalized();
    538            
    539           rdtscl(end);
    540           mittel += (end - ini - dt);
    541           }
    542       //delete w;
    543       mi = mittel / (float)ITERATIONS;
    544       printf(" Inl funct BaseObject::isFinazlized(): \t%11.2f\n", mi);
    545 
    546      
    547       tList<WorldEntity>* list = new tList<WorldEntity>();
    548 
    549      
    550       /* ************Primitvie class test************** */
    551       list = new tList<WorldEntity>();
    552  
    553      
    554       /*
    555         mittel = 0;
    556         w = new Primitive(P_SPHERE);
    557         for(i = 0; i < ITERATIONS; ++i)
    558         {
    559         rdtscl(ini);
    560        
    561         w->tick(0.0f);
    562        
    563         rdtscl(end);
    564         mittel += (end - ini - dt);
    565         }
    566         mi = mittel / (float)ITERATIONS;
    567         printf(" Call function tick() of Prim:\t\t%11.2f\n", mi);
    568       */
    569      
    570     }
    571  
    572   if(type == 1 || type == -1)
    573     {
    574       printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX);
    575       /* vector test */
    576       Vector* a = new Vector(1.3, 5.3, 4.1);
    577       Vector* b = new Vector(0.4, 2.5, 6.2);
    578       Vector* c = new Vector();
    579      
    580       unsigned long mittel, ini, end;
    581       float mi;
    582       int i = 0;
    583       // addition
    584       mittel = 0;
    585       for(i = 0; i < VECTOR_MAX; ++i)
    586         {
    587           rdtscl(ini);
    588          
    589           *c = *a + *b;
    590            
    591           rdtscl(end);
    592           mittel += (end - ini - dt);
    593         }
    594       mi = mittel / (float)VECTOR_MAX;
    595       printf(" Addition of two vectors:\t\t%11.2f\n", mi);
    596      
    597       // multiplikation
    598 
    599       mittel = 0;
    600       for(i = 0; i < VECTOR_MAX; ++i)
    601         {
    602           rdtscl(ini);
    603          
    604           *c = a->cross( *b);
    605            
    606           rdtscl(end);
    607           mittel += (end - ini - dt);
    608         }
    609       mi = mittel / (float)VECTOR_MAX;
    610       printf(" CrossMult of two vectors:\t\t%11.2f\n", mi);
    611 
    612     }
    613   if( type == 2 || type == -1)
    614     {
    615       /* quaternion test */
    616       printf("\nDoing some simple quaternion operations: \t\t%i\n", VECTOR_MAX);
    617       /* vector test */
    618       Quaternion* a = new Quaternion();
    619       Quaternion* b = new Quaternion();
    620       Quaternion* c = new Quaternion();
    621      
    622       unsigned long mittel, ini, end;
    623       float mi;
    624       int i = 0;
    625       // quaternion generieren mit spez konstruktor
    626       mittel = 0;
    627       Vector* qa = new Vector(4.6, 9.3, 0.4);
    628       Vector* qb = new Vector(3.5, 6.1, 4.3);
    629       for(i = 0; i < VECTOR_MAX; ++i)
    630         {
    631           rdtscl(ini);
    632          
    633           Quaternion* qu = new Quaternion(*qa, *qb);
    634          
    635           rdtscl(end);
    636           delete qu;
    637           mittel += (end - ini - dt);
    638         }
    639       delete a;
    640       delete b;
    641       mi = mittel / (float)VECTOR_MAX;
    642       printf(" Gen. quatern. betw. two vectors:\t%11.2f\n", mi);
    643      
    644      
    645       // multiplication
    646       mittel = 0;
    647       for(i = 0; i < VECTOR_MAX; ++i)
    648         {
    649           rdtscl(ini);
    650          
    651           *c = *a * *b;
    652          
    653           rdtscl(end);
    654           mittel += (end - ini - dt);
    655         }
    656       mi = mittel / (float)VECTOR_MAX;
    657       printf(" Multiplying two quat.(=rot): a * b\t%11.2f\n", mi);
    658      
    659      
    660      
    661       // rotating a vector by a quaternion
    662       mittel = 0;
    663       for(i = 0; i < VECTOR_MAX; ++i)
    664         {
    665           rdtscl(ini);
    666          
    667           *qa = a->apply(*qb);
    668          
    669           rdtscl(end);
    670           mittel += (end - ini - dt);
    671         }
    672       mi = mittel / (float)VECTOR_MAX;
    673       printf(" Rot a vec by a quat: q->apply(v)\t%11.2f\n", mi);
    674      
    675      
    676      
    677       // generate rotation matrix
    678       mittel = 0;
    679       float matrix[4][4];
    680       for(i = 0; i < VECTOR_MAX; ++i)
    681         {
    682           rdtscl(ini);
    683          
    684           a->matrix(matrix);
    685          
    686           rdtscl(end);
    687           mittel += (end - ini - dt);
    688         }
    689       mi = mittel / (float)VECTOR_MAX;
    690       printf(" Generate rot matrix: q->matrix(m)\t%11.2f\n", mi);
    691     }
    692   if( type == 3 || type == -1)
    693     {
    694       /* list tests*/
    695       printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX);
    696       tList<char>* list = new tList<char>();
    697       char* name;
    698      
    699       printf(" Adding[1..10] elements to list, found:\n");
    700       list->add("1");
    701       list->add("2");
    702       list->add("3");
    703       list->add("4");
    704       list->add("5");
    705       list->add("6");
    706       list->add("7");
    707       list->add("8");
    708       list->add("9");
    709       list->add("10");
    710      
    711       /*give list out */
    712       tIterator<char>* iterator = list->getIterator();
    713       name = iterator->nextElement();
    714       printf("  List Elements: \t\t");
    715       while( name != NULL)
    716         {
    717           printf("%s,", name);
    718           name = iterator->nextElement();
    719         }
    720       delete iterator;
    721       printf("\n");
    722      
    723      
    724       /*removing some elements from the list*/
    725       printf(" Removing elements [2,3,6,8,10], adding [11] now found:\n");
    726       list->remove("2");
    727       list->remove("3");
    728       list->remove("6");
    729       list->remove("8");
    730       list->remove("10");
    731       list->add("11");
    732       /*give list out */
    733       iterator = list->getIterator();
    734       name = iterator->nextElement();
    735       printf("  List Elements: \t\t");
    736       while( name != NULL)
    737         {
    738           printf("%s,", name);
    739           name = iterator->nextElement();
    740         }
    741       delete iterator;
    742       printf("\n");
    743      
    744       delete list;
    745       printf("\nChecking list performance:\t\t\t\t%i\n", LIST_MAX);
    746      
    747       tList<int>* plist = new tList<int>();
    748       unsigned long mittel, ini, end;
    749       float mi;
    750       int i = 0;
    751       mittel = 0;
    752       for(i = 0; i < LIST_MAX; ++i)
    753         {
    754           rdtscl(ini);
    755          
    756           plist->add(&i);
    757          
    758           rdtscl(end);
    759           mittel += (end - ini - dt);
    760         }
    761       mi = mittel / (float)LIST_MAX;
    762       printf(" Adding reference to list:\t\t%11.2f\n", mi);
    763      
    764       mittel = 0;
    765       for(i = 0; i < LIST_MAX; ++i)
    766         {
    767           rdtscl(ini);
    768          
    769           plist->remove(&i);
    770          
    771           rdtscl(end);
    772           mittel += (end - ini - dt);
    773         }
    774       mi = mittel / (float)LIST_MAX;
    775       printf(" Removing 1st reference from list:\t%11.2f\n", mi);
    776      
    777 
    778       printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX);
    779       list = new tList<char>();
    780       printf(" Adding[1..10] elements to list, found:\n");
    781       list->add("1");
    782       list->add("2");
    783       list->add("3");
    784       list->add("4");
    785       list->add("5");
    786       list->add("6");
    787       list->add("7");
    788       list->add("8");
    789       list->add("9");
    790       list->add("10");
    791      
    792       /*give list out */
    793       iterator = list->getIterator();
    794       name = iterator->nextElement();
    795       printf("  List Elements: \t\t");
    796       while( name != NULL)
    797         {
    798           printf("%s,", name);
    799           name = iterator->nextElement();
    800         }
    801       delete iterator;
    802       printf("\n");
    803      
    804      
    805       int c = 0;
    806       printf(" Going trough list with nextElement(el) func: ");
    807       name = list->firstElement();
    808       while(c < 20)
    809         {
    810           printf("%s,", name);
    811           name = list->nextElement(name);
    812           c++;
    813         }
    814       printf("\n");
    815      
    816 
    817      
    818     }
    819  
    820 }
    821 
    822 #else
    823 
    824 int startBenchmarks()
    825 {
    826   PRINTF(1)("Benchmark is not implemented in this system\n");
    827 }
    828 
    829 #endif
Note: See TracChangeset for help on using the changeset viewer.