Changeset 4194 in orxonox.OLD for orxonox/branches/openAL/src/orxonox.cc
- Timestamp:
- May 16, 2005, 1:33:19 PM (20 years ago)
- Location:
- orxonox/branches/openAL
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/openAL
- Property svn:externals
-
old new 1 data http://svn.orxonox.ethz.ch/data 1
-
- Property svn:externals
-
orxonox/branches/openAL/src/orxonox.cc
r3790 r4194 22 22 main-programmer: Patrick Boenzli 23 23 co-programmer: Christian Meyer 24 co-programmer: Benjamin Grauer: injected ResourceManager/GraphicsEngine 24 co-programmer: Benjamin Grauer: injected ResourceManager/GraphicsEngine/GUI 25 25 */ 26 26 27 27 #include "orxonox.h" 28 29 #include "gui.h" 28 30 29 31 #include "world.h" 30 32 #include "data_tank.h" 31 33 #include "command_node.h" 34 #include "ini_parser.h" 32 35 #include "game_loader.h" 33 36 #include "graphics_engine.h" 34 37 #include "resource_manager.h" 35 38 #include "text_engine.h" 39 #include "factory.h" 40 #include "benchmark.h" 36 41 37 42 #include <string.h> 38 int verbose = 3; 43 44 int verbose = 4; 39 45 40 46 using namespace std; … … 42 48 /** 43 49 \brief create a new Orxonox 50 51 In this funcitons only global values are set. The game will not be started here. 44 52 */ 45 53 Orxonox::Orxonox () 46 54 { 47 pause = false; 55 this->pause = false; 56 57 this->world = NULL; 58 this->resources = NULL; 59 this->localinput = NULL; 60 61 this->argc = 0; 62 this->argv = NULL; 48 63 } 49 64 … … 53 68 Orxonox::~Orxonox () 54 69 { 70 int i =0; 55 71 Orxonox::singletonRef = NULL; 56 72 if( world != NULL) delete world; 57 if( localinput != NULL) delete world;73 if( localinput != NULL) delete localinput; 58 74 if( resources != NULL) delete resources; 59 75 delete GraphicsEngine::getInstance(); // deleting the Graphics … … 84 100 void Orxonox::getConfigFile (int argc, char** argv) 85 101 { 86 strcpy (configfilename, " orxonox.conf");102 strcpy (configfilename, "~/.orxonox/orxonox.conf"); 87 103 } 88 104 … … 92 108 int Orxonox::init (int argc, char** argv) 93 109 { 110 this->argc = argc; 111 this->argv = argv; 94 112 // parse command line 95 113 // config file … … 98 116 SDL_Init (SDL_INIT_TIMER); 99 117 // initialize everything 118 printf("> Initializing resources\n"); 119 if( initResources () == -1) return -1; 120 100 121 if( initVideo() == -1) return -1; 101 122 if( initSound() == -1) return -1; … … 104 125 printf("> Initializing networking\n"); 105 126 if( initNetworking () == -1) return -1; 106 printf("> Initializing resources\n");107 if( initResources () == -1) return -1;108 127 //printf("> Initializing world\n"); 109 128 //if( init_world () == -1) return -1; PB: world will be initialized when started … … 120 139 121 140 GraphicsEngine::getInstance(); 122 141 123 142 return 0; 124 143 } … … 143 162 { 144 163 // create localinput 145 localinput = new CommandNode( 164 localinput = new CommandNode(configfilename); 146 165 147 166 return 0; … … 164 183 int Orxonox::initResources() 165 184 { 166 // printf("Not yet implemented\n");167 185 PRINT(3)("initializing ResourceManager\n"); 168 186 resourceManager = ResourceManager::getInstance(); 169 resourceManager->setDataDir("../data/"); 170 return 0; 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); 223 exit(-1); 224 } 225 226 171 227 PRINT(3)("initializing TextEngine\n"); 172 228 TextEngine::getInstance(); 229 230 return 0; 173 231 } 174 232 … … 200 258 201 259 this->gameLoader = GameLoader::getInstance(); 202 this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); 260 this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); 261 // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); 203 262 this->gameLoader->init(); 204 263 this->gameLoader->start(); … … 279 338 280 339 340 bool showGui = false; 281 341 282 342 /** … … 286 346 */ 287 347 int 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 348 { 349 350 // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark. 301 351 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"); 352 for(i = 1; i < argc; ++i) 353 { 354 if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv); 355 else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks(); 356 else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true; 357 // else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]); 358 } 359 309 360 return startOrxonox(argc, argv); 310 361 } … … 312 363 313 364 314 int 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"); 365 int startHelp(int argc, char** argv) 366 { 367 PRINT(0)("orxonox: starts the orxonox game - rules\n"); 368 PRINT(0)("usage: orxonox [arg [arg...]]\n\n"); 369 PRINT(0)("valid options:\n"); 370 { 371 Gui* gui = new Gui(argc, argv); 372 gui->printHelp(); 373 delete gui; 374 } 375 PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n"); 376 PRINT(0)(" -h|--help:\t\t\tshows this help\n"); 321 377 } 322 378 … … 324 380 int startOrxonox(int argc, char** argv) 325 381 { 326 printf(">>> Starting Orxonox <<<\n"); 382 // checking for existence of the configuration-files 383 if (showGui || 384 !ResourceManager::isFile("~/.orxonox/orxonox.conf") || 385 ResourceManager::isFile("~/.orxonox/orxonox.lock")) 386 { 387 if (ResourceManager::isFile("~/.orxonox/orxonox.lock")) 388 ResourceManager::deleteFile("~/.orxonox/orxonox.lock"); 389 390 // starting the GUI 391 Gui* gui = new Gui(argc, argv); 392 gui->startGui(); 393 394 if (! gui->startOrxonox) 395 return 0; 396 397 delete gui; 398 } 399 400 PRINT(0)(">>> Starting Orxonox <<<\n"); 401 402 ResourceManager::touchFile("~/.orxonox/orxonox.lock"); 403 327 404 Orxonox *orx = Orxonox::getInstance(); 328 405 329 406 if((*orx).init(argc, argv) == -1) 330 407 { 331 printf("! Orxonox initialization failed\n");408 PRINTF(1)("! Orxonox initialization failed\n"); 332 409 return -1; 333 410 } … … 336 413 337 414 delete orx; 338 339 } 340 341 #if defined __linux__ 342 343 #include "list.h" 344 #include "world_entity.h" 345 #include "vector.h" 346 #include "player.h" 347 #include "base_object.h" 348 #include <asm/msr.h> 349 #include <linux/timex.h> 350 351 352 #define LIST_MAX 1000 353 #define VECTOR_MAX 1000000 354 #define ITERATIONS 10000 355 356 357 int startBenchmarks() 358 { 359 360 printf("===========================================================\n"); 361 printf("= BENCHMARKS =\n"); 362 printf("===========================================================\n"); 363 printf(" the author is not paying any attention to cacheing effects\n"); 364 printf(" of the CPU.\n\n"); 365 printf("[title]\t\t\t\t\t [cycles]\t[loops]\n\n"); 366 // printf("------------------------------------------------------------\n\n"); 367 368 // first measure the time overhead: 369 unsigned long ini, end, dt, tmp; 370 rdtscl(ini); rdtscl(end); 371 dt = end - ini; 372 373 int type = -1; 374 /* type -1 == all 375 type 0 == framework 376 type 1 == vector 377 type 2 == quaternion 378 type 3 == lists 379 */ 380 if(type == 0 || type == -1) 381 { 382 /* framework test*/ 383 384 printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS); 385 /* ************WorldEntity class test************** */ 386 WorldEntity* w = NULL; 387 int i = 0; 388 unsigned long mittel = 0; 389 390 for(i = 0; i < ITERATIONS; ++i) 391 { 392 rdtscl(ini); 393 394 WorldEntity* w = new WorldEntity(); 395 396 rdtscl(end); 397 delete w; 398 mittel += (end - ini - dt); 399 } 400 float mi = mittel / (float)ITERATIONS; 401 printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi); 402 403 /* 404 mittel = 0; 405 for(i = 0; i < ITERATIONS; ++i) 406 { 407 rdtscl(ini); 408 409 WorldEntity* w = new Primitive(P_SPHERE); 410 411 rdtscl(end); 412 delete w; 413 mittel += (end - ini - dt); 414 } 415 mi = mittel / (float)ITERATIONS; 416 printf(" Generate a Primitive object:\t\t%11.2f\n", mi); 417 */ 418 419 mittel = 0; 420 for(i = 0; i < ITERATIONS; ++i) 421 { 422 rdtscl(ini); 423 424 Vector* v = new Vector(); 425 426 rdtscl(end); 427 delete v; 428 mittel += (end - ini - dt); 429 } 430 mi = mittel / (float)ITERATIONS; 431 printf(" Generate a Vector object:\t\t%11.2f\n", mi); 432 433 434 mittel = 0; 435 for(i = 0; i < ITERATIONS; ++i) 436 { 437 rdtscl(ini); 438 439 Quaternion* q = new Quaternion(); 440 441 rdtscl(end); 442 delete q; 443 mittel += (end - ini - dt); 444 } 445 mi = mittel / (float)ITERATIONS; 446 printf(" Generate a Quaternion object:\t\t%11.2f\n", mi); 447 448 449 450 451 printf("\nCalling function inline &| virtual, \t\t\t%i\n", ITERATIONS); 452 mittel = 0; 453 w = new WorldEntity(); 454 for(i = 0; i < ITERATIONS; ++i) 455 { 456 rdtscl(ini); 457 458 w->tick(0.0f); 459 460 rdtscl(end); 461 mittel += (end - ini - dt); 462 } 463 //delete w; 464 mi = mittel / (float)ITERATIONS; 465 printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi); 466 467 468 mittel = 0; 469 WorldEntity wo; 470 for(i = 0; i < ITERATIONS; ++i) 471 { 472 rdtscl(ini); 473 474 wo.tick(0.0f); 475 476 rdtscl(end); 477 mittel += (end - ini - dt); 478 } 479 //delete w; 480 mi = mittel / (float)ITERATIONS; 481 printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi); 482 483 484 mittel = 0; 485 BaseObject* bo = new BaseObject(); 486 for(i = 0; i < ITERATIONS; ++i) 487 { 488 rdtscl(ini); 489 490 bo->isFinalized(); 491 492 rdtscl(end); 493 mittel += (end - ini - dt); 494 } 495 //delete w; 496 mi = mittel / (float)ITERATIONS; 497 printf(" Inl funct BaseObject::isFinazlized(): \t%11.2f\n", mi); 498 499 500 tList<WorldEntity>* list = new tList<WorldEntity>(); 501 502 503 /* ************Primitvie class test************** */ 504 list = new tList<WorldEntity>(); 505 506 507 /* 508 mittel = 0; 509 w = new Primitive(P_SPHERE); 510 for(i = 0; i < ITERATIONS; ++i) 511 { 512 rdtscl(ini); 513 514 w->tick(0.0f); 515 516 rdtscl(end); 517 mittel += (end - ini - dt); 518 } 519 mi = mittel / (float)ITERATIONS; 520 printf(" Call function tick() of Prim:\t\t%11.2f\n", mi); 521 */ 522 523 } 524 525 if(type == 1 || type == -1) 526 { 527 printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX); 528 /* vector test */ 529 Vector* a = new Vector(1.3, 5.3, 4.1); 530 Vector* b = new Vector(0.4, 2.5, 6.2); 531 Vector* c = new Vector(); 532 533 unsigned long mittel, ini, end; 534 float mi; 535 int i = 0; 536 // addition 537 mittel = 0; 538 for(i = 0; i < VECTOR_MAX; ++i) 539 { 540 rdtscl(ini); 541 542 *c = *a + *b; 543 544 rdtscl(end); 545 mittel += (end - ini - dt); 546 } 547 mi = mittel / (float)VECTOR_MAX; 548 printf(" Addition of two vectors:\t\t%11.2f\n", mi); 549 550 // multiplikation 551 552 mittel = 0; 553 for(i = 0; i < VECTOR_MAX; ++i) 554 { 555 rdtscl(ini); 556 557 *c = a->cross( *b); 558 559 rdtscl(end); 560 mittel += (end - ini - dt); 561 } 562 mi = mittel / (float)VECTOR_MAX; 563 printf(" CrossMult of two vectors:\t\t%11.2f\n", mi); 564 565 } 566 if( type == 2 || type == -1) 567 { 568 /* quaternion test */ 569 printf("\nDoing some simple quaternion operations: \t\t%i\n", VECTOR_MAX); 570 /* vector test */ 571 Quaternion* a = new Quaternion(); 572 Quaternion* b = new Quaternion(); 573 Quaternion* c = new Quaternion(); 574 575 unsigned long mittel, ini, end; 576 float mi; 577 int i = 0; 578 // quaternion generieren mit spez konstruktor 579 mittel = 0; 580 Vector* qa = new Vector(4.6, 9.3, 0.4); 581 Vector* qb = new Vector(3.5, 6.1, 4.3); 582 for(i = 0; i < VECTOR_MAX; ++i) 583 { 584 rdtscl(ini); 585 586 Quaternion* qu = new Quaternion(*qa, *qb); 587 588 rdtscl(end); 589 delete qu; 590 mittel += (end - ini - dt); 591 } 592 delete a; 593 delete b; 594 mi = mittel / (float)VECTOR_MAX; 595 printf(" Gen. quatern. betw. two vectors:\t%11.2f\n", mi); 596 597 598 // multiplication 599 mittel = 0; 600 for(i = 0; i < VECTOR_MAX; ++i) 601 { 602 rdtscl(ini); 603 604 *c = *a * *b; 605 606 rdtscl(end); 607 mittel += (end - ini - dt); 608 } 609 mi = mittel / (float)VECTOR_MAX; 610 printf(" Multiplying two quat.(=rot): a * b\t%11.2f\n", mi); 611 612 613 614 // rotating a vector by a quaternion 615 mittel = 0; 616 for(i = 0; i < VECTOR_MAX; ++i) 617 { 618 rdtscl(ini); 619 620 *qa = a->apply(*qb); 621 622 rdtscl(end); 623 mittel += (end - ini - dt); 624 } 625 mi = mittel / (float)VECTOR_MAX; 626 printf(" Rot a vec by a quat: q->apply(v)\t%11.2f\n", mi); 627 628 629 630 // generate rotation matrix 631 mittel = 0; 632 float matrix[4][4]; 633 for(i = 0; i < VECTOR_MAX; ++i) 634 { 635 rdtscl(ini); 636 637 a->matrix(matrix); 638 639 rdtscl(end); 640 mittel += (end - ini - dt); 641 } 642 mi = mittel / (float)VECTOR_MAX; 643 printf(" Generate rot matrix: q->matrix(m)\t%11.2f\n", mi); 644 } 645 if( type == 3 || type == -1) 646 { 647 /* list tests*/ 648 printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX); 649 tList<char>* list = new tList<char>(); 650 char* name; 651 652 printf(" Adding[1..10] elements to list, found:\n"); 653 list->add("1"); 654 list->add("2"); 655 list->add("3"); 656 list->add("4"); 657 list->add("5"); 658 list->add("6"); 659 list->add("7"); 660 list->add("8"); 661 list->add("9"); 662 list->add("10"); 663 664 /*give list out */ 665 tIterator<char>* iterator = list->getIterator(); 666 name = iterator->nextElement(); 667 printf(" List Elements: \t\t"); 668 while( name != NULL) 669 { 670 printf("%s,", name); 671 name = iterator->nextElement(); 672 } 673 delete iterator; 674 printf("\n"); 675 676 677 /*removing some elements from the list*/ 678 printf(" Removing elements [2,3,6,8,10], adding [11] now found:\n"); 679 list->remove("2"); 680 list->remove("3"); 681 list->remove("6"); 682 list->remove("8"); 683 list->remove("10"); 684 list->add("11"); 685 /*give list out */ 686 iterator = list->getIterator(); 687 name = iterator->nextElement(); 688 printf(" List Elements: \t\t"); 689 while( name != NULL) 690 { 691 printf("%s,", name); 692 name = iterator->nextElement(); 693 } 694 delete iterator; 695 printf("\n"); 696 697 delete list; 698 printf("\nChecking list performance:\t\t\t\t%i\n", LIST_MAX); 699 700 tList<int>* plist = new tList<int>(); 701 unsigned long mittel, ini, end; 702 float mi; 703 int i = 0; 704 mittel = 0; 705 for(i = 0; i < LIST_MAX; ++i) 706 { 707 rdtscl(ini); 708 709 plist->add(&i); 710 711 rdtscl(end); 712 mittel += (end - ini - dt); 713 } 714 mi = mittel / (float)LIST_MAX; 715 printf(" Adding reference to list:\t\t%11.2f\n", mi); 716 717 mittel = 0; 718 for(i = 0; i < LIST_MAX; ++i) 719 { 720 rdtscl(ini); 721 722 plist->remove(&i); 723 724 rdtscl(end); 725 mittel += (end - ini - dt); 726 } 727 mi = mittel / (float)LIST_MAX; 728 printf(" Removing 1st reference from list:\t%11.2f\n", mi); 729 730 731 printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX); 732 list = new tList<char>(); 733 printf(" Adding[1..10] elements to list, found:\n"); 734 list->add("1"); 735 list->add("2"); 736 list->add("3"); 737 list->add("4"); 738 list->add("5"); 739 list->add("6"); 740 list->add("7"); 741 list->add("8"); 742 list->add("9"); 743 list->add("10"); 744 745 /*give list out */ 746 iterator = list->getIterator(); 747 name = iterator->nextElement(); 748 printf(" List Elements: \t\t"); 749 while( name != NULL) 750 { 751 printf("%s,", name); 752 name = iterator->nextElement(); 753 } 754 delete iterator; 755 printf("\n"); 756 757 758 int c = 0; 759 printf(" Going trough list with nextElement(el) func: "); 760 name = list->firstElement(); 761 while(c < 20) 762 { 763 printf("%s,", name); 764 name = list->nextElement(name); 765 c++; 766 } 767 printf("\n"); 768 769 770 771 } 772 773 } 774 775 #else 776 777 int startBenchmarks() 778 { 779 PRINTF(1)("Benchmark is not implemented in this system\n"); 780 } 781 782 #endif 415 ResourceManager::deleteFile("~/.orxonox/orxonox.lock"); 416 417 }
Note: See TracChangeset
for help on using the changeset viewer.