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