Changeset 4555 in orxonox.OLD for orxonox/trunk/src/story_entities
- Timestamp:
- Jun 8, 2005, 2:17:00 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/story_entities/world.cc
r4518 r4555 1 1 2 2 3 /* 3 /* 4 4 orxonox - the future of 3D-vertical-scrollers 5 5 … … 107 107 \param reference to the world 108 108 109 if the worldinterface is not initilizes, there wont be any 109 if the worldinterface is not initilizes, there wont be any 110 110 useable interface 111 111 */ … … 139 139 this->constuctorInit("", -1); 140 140 this->path = NULL; 141 141 142 142 this->loadParams(root); 143 143 } 144 144 145 /** 145 /** 146 146 \brief create a new World 147 147 148 148 This creates a new empty world! 149 149 */ … … 165 165 } 166 166 167 /** 167 /** 168 168 \brief remove the World from memory 169 169 170 170 delete everything explicitly, that isn't contained in the parenting tree! 171 171 things contained in the tree are deleted automaticaly … … 197 197 198 198 /** 199 \brief initializes the world. 199 \brief initializes the world. 200 200 201 201 set all stuff here that is world generic and does not use to much memory 202 202 because the real init() function StoryEntity::init() will be called 203 shortly before start of the game. 203 shortly before start of the game. 204 204 since all worlds are initiated/referenced before they will be started. 205 205 NO LEVEL LOADING HERE - NEVER! … … 232 232 233 233 234 /* 234 /* 235 235 // identifier 236 236 string = grabParameter( root, "identifier"); … … 250 250 } 251 251 else setNextStoryID( id); 252 252 253 253 254 254 // path … … 295 295 this->localCamera = new Camera(); 296 296 this->localCamera->setName ("Camera"); 297 297 298 298 State::getInstance()->setCamera(this->localCamera, this->localCamera->getTarget()); 299 299 … … 306 306 */ 307 307 ErrorMessage World::load() 308 { 308 { 309 309 PRINTF(3)("> Loading world: '%s'\n", getPath()); 310 310 TiXmlElement* element; 311 311 GameLoader* loader = GameLoader::getInstance(); 312 312 313 313 if( getPath() == NULL) 314 314 { … … 317 317 return (ErrorMessage){213,"Path not specified","World::load()"}; 318 318 } 319 319 320 320 TiXmlDocument* XMLDoc = new TiXmlDocument( path); 321 321 // load the campaign document 322 if( !XMLDoc->LoadFile()) 322 if( !XMLDoc->LoadFile()) 323 323 { 324 324 // report an error … … 327 327 return (ErrorMessage){213,"XML File parsing error","World::load()"}; 328 328 } 329 329 330 330 // check basic validity 331 331 TiXmlElement* root = XMLDoc->RootElement(); 332 332 assert( root != NULL); 333 333 334 334 if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile")) 335 335 { … … 339 339 return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"}; 340 340 } 341 341 342 342 // load the parameters 343 343 // name … … 378 378 // find WorldEntities 379 379 element = root->FirstChildElement("WorldEntities"); 380 380 381 381 if( element == NULL) 382 382 { … … 389 389 PRINTF(4)("Loading WorldEntities\n"); 390 390 while( element != NULL) 391 392 393 394 395 //todo do this more elegant 396 397 398 399 400 391 { 392 WorldEntity* created = dynamic_cast<WorldEntity*>( loader->fabricate( element)); 393 if( created != NULL) this->spawn( created); 394 // if we load a 'Player' we use it as localPlayer 395 //todo do this more elegant 396 if( element->Value() != NULL && !strcmp( element->Value(), "Player")) localPlayer = (Player*) created; 397 if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) sky = (SkyBox*) created; 398 element = element->NextSiblingElement(); 399 glmis->step(); //! \todo temporary 400 } 401 401 PRINTF(4)("Done loading WorldEntities\n"); 402 402 } 403 403 404 404 // find Track 405 405 element = root->FirstChildElement( "Track"); … … 409 409 } 410 410 else 411 { 411 { 412 412 //load track 413 413 PRINTF(4)("Loading Track\n"); … … 416 416 trackManager->finalize(); 417 417 } 418 418 419 419 // free the XML data 420 420 421 421 delete XMLDoc; 422 422 /* GENERIC LOADING PROCESS FINISHED */ 423 423 424 424 // bind input 425 425 this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_UP); … … 430 430 this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_NEXT_WEAPON); 431 431 this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_PREVIOUS_WEAPON); 432 432 433 433 // bind camera 434 434 //this->localCamera->bind (localPlayer); 435 435 this->localPlayer->addChild (this->localCamera); 436 436 437 437 438 438 lightMan->setAmbientColor(.1,.1,.1); … … 445 445 //lightMan->debug(); 446 446 lightMan->setPosition(-5.0, 10.0, -40.0); 447 448 // 447 448 // trackManager->setBindSlave(env); 449 449 PNode* tn = trackManager->getTrackNode(); 450 450 tn->addChild(this->localPlayer); 451 451 452 452 //localCamera->setParent(TrackNode::getInstance()); 453 453 tn->addChild(this->localCamera); … … 463 463 objectList = glGenLists(1); 464 464 glNewList (objectList, GL_COMPILE); 465 465 466 466 //trackManager->drawGraph(.01); 467 467 //trackManager->debug(2); … … 488 488 system->setColor(1.0, 0,0,0,0); 489 489 490 490 491 // Creating a Test Particle Emitter 491 492 ParticleEmitter* emitter = new ParticleEmitter(Vector(-1, 0, 0), M_PI_4, 400, .5); … … 498 499 gravity->setMagnitude(10.0); 499 500 // gravity->setParent(this->localCamera->getTarget()); 500 501 501 502 // Add the Flow from the Emitter into the System 502 503 particleEngine->addConnection(emitter, system); … … 504 505 new PhysicsConnection(system, gravity); 505 506 // new PhysicsConnection(this->localPlayer, gravity); 506 507 507 508 508 509 TestEntity* testEntity = new TestEntity(); … … 547 548 trackManager->addPointV(Vector(570, 20, -10)); 548 549 trackManager->setDuration(2); 549 550 550 551 trackManager->forkS("testFork1,testFork2"); 551 552 trackManager->workOnS("testFork1"); … … 572 573 573 574 trackManager->setDuration(4); 574 575 575 576 576 577 trackManager->joinS("testFork1,testFork2"); 577 578 578 579 trackManager->addPointV(Vector(1200, 60, -50)); 579 580 trackManager->addPointV(Vector(1300, 50, -50)); … … 586 587 trackManager->addPointV(Vector(1800, 100, -40)); 587 588 trackManager->setDuration(10); 588 589 589 590 trackManager->finalize(); 590 591 591 592 592 593 // LIGHT initialisation … … 598 599 { 599 600 /* 600 this loads the hard-coded debug world. this only for simplicity and will be 601 602 603 601 this loads the hard-coded debug world. this only for simplicity and will be 602 removed by a reald world-loader, which interprets a world-file. 603 if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and 604 make whatever you want... 604 605 */ 605 606 case DEBUG_WORLD_0: 606 607 { 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 //orx->getLocalInput()->bind (this->pilotNode); 667 668 669 670 671 672 673 674 675 676 677 678 608 lightMan->setPosition(-5.0, 10.0, -40.0); 609 610 611 this->localPlayer = new Player (); 612 this->localPlayer->setName ("player"); 613 this->spawn (this->localPlayer); 614 this->localPlayer->setRelCoor(Vector(5,0,0)); 615 /*monitor progress*/ 616 this->glmis->step(); 617 618 619 this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_FIRE1); 620 this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_NEXT_WEAPON); 621 this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_PREVIOUS_WEAPON); 622 623 /* 624 Field* testField = new Gravity(); 625 testField->setMagnitude(10); 626 new PhysicsConnection(this->localPlayer, testField); 627 */ 628 629 // bind camera 630 this->localCamera = new Camera(); 631 this->localCamera->setName ("camera"); 632 /*monitor progress*/ 633 this->glmis->step(); 634 635 636 // Create SkySphere 637 this->sky = new Skysphere("pictures/sky-replace.jpg"); 638 this->sky->setName("SkySphere"); 639 this->spawn(this->sky); 640 this->localCamera->addChild(this->sky); 641 this->sky->setParentMode(PNODE_MOVEMENT); 642 /*monitor progress*/ 643 this->glmis->step(); 644 645 646 terrain = new Terrain("worlds/newGround.obj"); 647 terrain->setRelCoor(Vector(0,-10,0)); 648 this->spawn(terrain); 649 /*monitor progress*/ 650 this->glmis->step(); 651 652 this->pilotNode = new PilotNode(); 653 this->spawn(this->pilotNode); 654 this->pilotNode->setAbsCoor(Vector(150, -35, 5)); 655 this->pilotNode->addChild(this->localPlayer); 656 this->pilotNode->addChild(this->localCamera); 657 this->localCamera->lookAt(this->localPlayer); 658 659 this->eventHandler->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_UP); 660 this->eventHandler->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_DOWN); 661 this->eventHandler->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_LEFT); 662 this->eventHandler->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_RIGHT); 663 this->eventHandler->subscribe(this->pilotNode, ES_GAME, EV_MOUSE_MOTION); 664 665 // bind input 666 Orxonox *orx = Orxonox::getInstance (); 667 //orx->getLocalInput()->bind (this->pilotNode); 668 669 /* 670 PNode* tn = trackManager->getTrackNode(); 671 tn->addChild(this->localPlayer); 672 this->localCamera->lookAt(tn); 673 674 tn->addChild(this->localCamera); 675 this->localPlayer->setParentMode(PNODE_ALL); 676 trackManager->condition(2, LEFTRIGHT, this->localPlayer); 677 */ 678 this->glmis->step(); 679 break; 679 680 } 680 681 case DEBUG_WORLD_1: 681 682 { 682 683 683 684 break; 684 685 } 685 686 case DEBUG_WORLD_2: 686 687 { 687 688 688 689 break; 689 690 } 690 691 default: … … 698 699 \brief initializes a new World shortly before start 699 700 700 this is the function, that will be loaded shortly before the world is 701 this is the function, that will be loaded shortly before the world is 701 702 started 702 703 */ … … 759 760 void World::displayLoadScreen () 760 761 { 761 PRINTF(3)("World::displayLoadScreen - start\n"); 762 763 //GLMenuImageScreen* 762 PRINTF(3)("World::displayLoadScreen - start\n"); 763 764 //GLMenuImageScreen* 764 765 this->glmis = new GLMenuImageScreen(); 765 766 this->glmis->init(); 766 767 this->glmis->setMaximum(8); 767 768 // this->glmis->draw(); 768 769 PRINTF(3)("World::displayLoadScreen - end\n"); 769 770 PRINTF(3)("World::displayLoadScreen - end\n"); 770 771 } 771 772 … … 777 778 void World::releaseLoadScreen () 778 779 { 779 PRINTF(3)("World::releaseLoadScreen - start\n"); 780 PRINTF(3)("World::releaseLoadScreen - start\n"); 780 781 this->glmis->setValue(this->glmis->getMaximum()); 781 PRINTF(3)("World::releaseLoadScreen - end\n"); 782 PRINTF(3)("World::releaseLoadScreen - end\n"); 782 783 delete this->glmis; 783 784 } … … 804 805 805 806 806 /** 807 /** 807 808 \brief checks for collisions 808 809 This method runs through all WorldEntities known to the world and checks for collisions 810 between them. In case of collisions the collide() method of the corresponding entities 809 810 This method runs through all WorldEntities known to the world and checks for collisions 811 between them. In case of collisions the collide() method of the corresponding entities 811 812 is called. 812 813 */ … … 816 817 List *a, *b; 817 818 WorldEntity *aobj, *bobj; 818 819 819 820 a = entities; 820 821 821 822 while( a != NULL) 822 823 { 823 824 aobj = a->nextElement(); 824 825 if( aobj->bCollide && aobj->collisioncluster != NULL) 825 826 827 828 829 830 831 832 833 if( check_collision ( &aobj->place, aobj->collisioncluster, 834 &ahitflg, &bobj->place, bobj->collisioncluster, 835 836 837 838 839 840 841 842 843 826 { 827 b = a->nextElement(); 828 while( b != NULL ) 829 { 830 bobj = b->nextElement(); 831 if( bobj->bCollide && bobj->collisioncluster != NULL ) 832 { 833 unsigned long ahitflg, bhitflg; 834 if( check_collision ( &aobj->place, aobj->collisioncluster, 835 &ahitflg, &bobj->place, bobj->collisioncluster, 836 &bhitflg) ); 837 { 838 aobj->collide (bobj, ahitflg, bhitflg); 839 bobj->collide (aobj, bhitflg, ahitflg); 840 } 841 } 842 b = b->nextElement(); 843 } 844 } 844 845 a = a->enumerate(); 845 846 } … … 847 848 } 848 849 849 /** 850 /** 850 851 \brief runs through all entities calling their draw() methods 851 852 */ … … 859 860 tIterator<WorldEntity>* iterator = this->entities->getIterator(); 860 861 entity = iterator->nextElement(); 861 while( entity != NULL ) 862 { 862 while( entity != NULL ) 863 { 863 864 if( entity->bDraw ) entity->draw(); 864 865 //entity = this->entities->nextElement(); … … 866 867 } 867 868 delete iterator; 868 869 869 870 glCallList (objectList); 870 871 … … 900 901 p3->debug (); 901 902 p4->debug (); 902 903 903 904 p1->update (0); 904 905 … … 928 929 929 930 delete p1; 930 931 931 932 932 933 /* 933 934 WorldEntity* entity; 934 935 printf("counting all entities\n"); 935 936 printf("World::debug() - enumerate()\n"); 936 entity = entities->enumerate(); 937 while( entity != NULL ) 938 { 937 entity = entities->enumerate(); 938 while( entity != NULL ) 939 { 939 940 if( entity->bDraw ) printf("got an entity\n"); 940 941 entity = entities->nextElement(); … … 963 964 this->handleInput (); 964 965 if( this->bQuitCurrentGame || this->bQuitOrxonox) 965 966 break; 966 967 // Process time 967 968 this->tick (); 968 969 // Update the state 969 this->update (); 970 this->update (); 970 971 // Process collision 971 972 this->collide (); … … 1021 1022 { 1022 1023 this->dt = currentFrame - this->lastFrame; 1023 1024 1024 1025 if( this->dt > 0) 1025 1026 1027 1028 1029 1030 1031 1026 { 1027 float fps = 1000/dt; 1028 1029 // temporary, only for showing how fast the text-engine is 1030 char tmpChar[20]; 1031 sprintf(tmpChar, "fps: %4.0f", fps); 1032 } 1032 1033 else 1033 1034 1035 1036 1037 1038 1039 1040 1034 { 1035 /* the frame-rate is limited to 100 frames per second, all other things are for 1036 nothing. 1037 */ 1038 PRINTF(2)("fps = 1000 - frame rate is adjusted\n"); 1039 SDL_Delay(10); 1040 this->dt = 10; 1041 } 1041 1042 //this->timeSlice (dt); 1042 1043 1043 1044 /* function to let all entities tick (iterate through list) */ 1044 this->dtS = (float)this->dt / 1000.0; 1045 this->dtS = (float)this->dt / 1000.0; 1045 1046 this->gameTime += this->dtS; 1046 //entity = entities->enumerate(); 1047 //entity = entities->enumerate(); 1047 1048 tIterator<WorldEntity>* iterator = this->entities->getIterator(); 1048 1049 WorldEntity* entity = iterator->nextElement(); 1049 while( entity != NULL) 1050 { 1051 1052 1053 1050 while( entity != NULL) 1051 { 1052 entity->tick (this->dtS); 1053 entity = iterator->nextElement(); 1054 } 1054 1055 delete iterator; 1055 1056 … … 1063 1064 particleEngine->tick(this->dtS); 1064 1065 this->garbageCollector->tick(this->dtS); 1065 1066 1066 1067 /* actualy the Graphics Engine should tick the world not the other way around... 1067 1068 1069 1068 but since we like the things not too complicated we got it this way around 1069 until there is need or time to do it the other way around. 1070 \todo: GraphicsEngine ticks world: separation of processes and data... 1070 1071 */ 1071 1072 GraphicsEngine::getInstance()->tick(this->dtS); … … 1092 1093 /** 1093 1094 \brief render the current frame 1094 1095 1095 1096 clear all buffers and draw the world 1096 1097 */ … … 1147 1148 \param In which relative direction should it look. 1148 1149 */ 1149 void World::spawn(WorldEntity* entity, PNode* parentNode, 1150 Vector* relCoor, Quaternion* relDir, 1151 1150 void World::spawn(WorldEntity* entity, PNode* parentNode, 1151 Vector* relCoor, Quaternion* relDir, 1152 int parentingMode) 1152 1153 { 1153 1154 this->nullParent = NullParent::getInstance(); … … 1155 1156 { 1156 1157 parentNode->addChild (entity); 1157 1158 1158 1159 entity->setRelCoor (*relCoor); 1159 1160 entity->setRelDir (*relDir); 1160 1161 entity->setParentMode(parentingMode); 1161 1162 1162 1163 this->entities->add (entity); 1163 1164 1164 1165 entity->postSpawn (); 1165 1166 }
Note: See TracChangeset
for help on using the changeset viewer.