Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4555 in orxonox.OLD for orxonox/trunk/src/story_entities/world.cc


Ignore:
Timestamp:
Jun 8, 2005, 2:17:00 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: small diffs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/story_entities/world.cc

    r4518 r4555  
    11
    22
    3 /* 
     3/*
    44   orxonox - the future of 3D-vertical-scrollers
    55
     
    107107   \param reference to the world
    108108
    109    if the worldinterface is not initilizes, there wont be any 
     109   if the worldinterface is not initilizes, there wont be any
    110110   useable interface
    111111*/
     
    139139  this->constuctorInit("", -1);
    140140  this->path = NULL;
    141  
     141
    142142  this->loadParams(root);
    143143}
    144144
    145 /** 
     145/**
    146146    \brief create a new World
    147    
     147
    148148    This creates a new empty world!
    149149*/
     
    165165}
    166166
    167 /** 
     167/**
    168168    \brief remove the World from memory
    169    
     169
    170170    delete everything explicitly, that isn't contained in the parenting tree!
    171171    things contained in the tree are deleted automaticaly
     
    197197
    198198/**
    199    \brief initializes the world. 
     199   \brief initializes the world.
    200200
    201201   set all stuff here that is world generic and does not use to much memory
    202202   because the real init() function StoryEntity::init() will be called
    203    shortly before start of the game. 
     203   shortly before start of the game.
    204204   since all worlds are initiated/referenced before they will be started.
    205205   NO LEVEL LOADING HERE - NEVER!
     
    232232
    233233
    234   /* 
     234  /*
    235235  // identifier
    236236  string = grabParameter( root, "identifier");
     
    250250  }
    251251  else setNextStoryID( id);
    252  
     252
    253253
    254254  // path
     
    295295  this->localCamera = new Camera();
    296296  this->localCamera->setName ("Camera");
    297  
     297
    298298  State::getInstance()->setCamera(this->localCamera, this->localCamera->getTarget());
    299299
     
    306306*/
    307307ErrorMessage World::load()
    308 {       
     308{
    309309  PRINTF(3)("> Loading world: '%s'\n", getPath());
    310310  TiXmlElement* element;
    311311  GameLoader* loader = GameLoader::getInstance();
    312  
     312
    313313  if( getPath() == NULL)
    314314    {
     
    317317      return (ErrorMessage){213,"Path not specified","World::load()"};
    318318    }
    319  
     319
    320320  TiXmlDocument* XMLDoc = new TiXmlDocument( path);
    321321  // load the campaign document
    322   if( !XMLDoc->LoadFile()) 
     322  if( !XMLDoc->LoadFile())
    323323  {
    324324    // report an error
     
    327327    return (ErrorMessage){213,"XML File parsing error","World::load()"};
    328328  }
    329  
     329
    330330  // check basic validity
    331331  TiXmlElement* root = XMLDoc->RootElement();
    332332  assert( root != NULL);
    333  
     333
    334334  if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile"))
    335335    {
     
    339339      return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"};
    340340    }
    341  
     341
    342342  // load the parameters
    343343  // name
     
    378378  // find WorldEntities
    379379  element = root->FirstChildElement("WorldEntities");
    380  
     380
    381381  if( element == NULL)
    382382    {
     
    389389      PRINTF(4)("Loading WorldEntities\n");
    390390      while( element != NULL)
    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         }
     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        }
    401401      PRINTF(4)("Done loading WorldEntities\n");
    402402    }
    403  
     403
    404404  // find Track
    405405  element = root->FirstChildElement( "Track");
     
    409409    }
    410410  else
    411     {   
     411    {
    412412      //load track
    413413      PRINTF(4)("Loading Track\n");
     
    416416      trackManager->finalize();
    417417    }
    418  
     418
    419419  // free the XML data
    420420
    421421  delete XMLDoc;
    422422  /* GENERIC LOADING PROCESS FINISHED */
    423  
     423
    424424  // bind input
    425425  this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_UP);
     
    430430  this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_NEXT_WEAPON);
    431431  this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_PREVIOUS_WEAPON);
    432  
     432
    433433  // bind camera
    434434  //this->localCamera->bind (localPlayer);
    435435  this->localPlayer->addChild (this->localCamera);
    436      
     436
    437437
    438438  lightMan->setAmbientColor(.1,.1,.1);
     
    445445  //lightMan->debug();
    446446  lightMan->setPosition(-5.0, 10.0, -40.0);
    447  
    448   //        trackManager->setBindSlave(env);
     447
     448  //        trackManager->setBindSlave(env);
    449449  PNode* tn = trackManager->getTrackNode();
    450450  tn->addChild(this->localPlayer);
    451  
     451
    452452  //localCamera->setParent(TrackNode::getInstance());
    453453  tn->addChild(this->localCamera);
     
    463463  objectList = glGenLists(1);
    464464  glNewList (objectList, GL_COMPILE);
    465  
     465
    466466  //trackManager->drawGraph(.01);
    467467  //trackManager->debug(2);
     
    488488  system->setColor(1.0, 0,0,0,0);
    489489
     490
    490491  // Creating a Test Particle Emitter
    491492  ParticleEmitter* emitter = new ParticleEmitter(Vector(-1, 0, 0), M_PI_4, 400, .5);
     
    498499  gravity->setMagnitude(10.0);
    499500  //  gravity->setParent(this->localCamera->getTarget());
    500  
     501
    501502  // Add the Flow from the Emitter into the System
    502503  particleEngine->addConnection(emitter, system);
     
    504505  new PhysicsConnection(system, gravity);
    505506  //    new PhysicsConnection(this->localPlayer, gravity);
    506  
     507
    507508
    508509  TestEntity* testEntity = new TestEntity();
     
    547548  trackManager->addPointV(Vector(570, 20, -10));
    548549  trackManager->setDuration(2);
    549      
     550
    550551  trackManager->forkS("testFork1,testFork2");
    551552  trackManager->workOnS("testFork1");
     
    572573
    573574  trackManager->setDuration(4);
    574      
    575      
     575
     576
    576577  trackManager->joinS("testFork1,testFork2");
    577        
     578
    578579  trackManager->addPointV(Vector(1200, 60, -50));
    579580  trackManager->addPointV(Vector(1300, 50, -50));
     
    586587  trackManager->addPointV(Vector(1800, 100, -40));
    587588  trackManager->setDuration(10);
    588  
     589
    589590  trackManager->finalize();
    590  
     591
    591592
    592593  // LIGHT initialisation
     
    598599    {
    599600      /*
    600         this loads the hard-coded debug world. this only for simplicity and will be
    601         removed by a reald world-loader, which interprets a world-file.
    602         if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and
    603         make whatever you want...
     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...
    604605      */
    605606    case DEBUG_WORLD_0:
    606607      {
    607         lightMan->setPosition(-5.0, 10.0, -40.0);
    608 
    609 
    610         this->localPlayer = new Player ();
    611         this->localPlayer->setName ("player");
    612         this->spawn (this->localPlayer);
    613         this->localPlayer->setRelCoor(Vector(5,0,0));
    614         /*monitor progress*/
    615         this->glmis->step();
    616 
    617 
    618         this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_FIRE1);
    619         this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_NEXT_WEAPON);
    620         this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_PREVIOUS_WEAPON);
    621 
    622         /*
    623         Field* testField = new Gravity();
    624         testField->setMagnitude(10);
    625         new PhysicsConnection(this->localPlayer, testField);
    626         */
    627 
    628         // bind camera
    629         this->localCamera = new Camera();
    630         this->localCamera->setName ("camera");
    631         /*monitor progress*/
    632         this->glmis->step();
    633 
    634 
    635         // Create SkySphere
    636         this->sky = new Skysphere("pictures/sky-replace.jpg");
    637         this->sky->setName("SkySphere");
    638         this->spawn(this->sky);
    639         this->localCamera->addChild(this->sky);
    640         this->sky->setParentMode(PNODE_MOVEMENT);
    641         /*monitor progress*/
    642         this->glmis->step();
    643 
    644 
    645         terrain = new Terrain("worlds/newGround.obj");
    646         terrain->setRelCoor(Vector(0,-10,0));
    647         this->spawn(terrain);
    648         /*monitor progress*/
    649         this->glmis->step();
    650 
    651         this->pilotNode = new PilotNode();
    652         this->spawn(this->pilotNode);
    653         this->pilotNode->setAbsCoor(Vector(150, -35, 5));
    654         this->pilotNode->addChild(this->localPlayer);
    655         this->pilotNode->addChild(this->localCamera);
    656         this->localCamera->lookAt(this->localPlayer);
    657 
    658         this->eventHandler->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_UP);
    659         this->eventHandler->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_DOWN);
    660         this->eventHandler->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_LEFT);
    661         this->eventHandler->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_RIGHT);
    662         this->eventHandler->subscribe(this->pilotNode, ES_GAME, EV_MOUSE_MOTION);
    663 
    664         // bind input
    665         Orxonox *orx = Orxonox::getInstance ();
    666         //orx->getLocalInput()->bind (this->pilotNode);     
    667        
    668         /*
    669         PNode* tn = trackManager->getTrackNode();
    670         tn->addChild(this->localPlayer);
    671         this->localCamera->lookAt(tn);
    672        
    673         tn->addChild(this->localCamera);
    674         this->localPlayer->setParentMode(PNODE_ALL);
    675         trackManager->condition(2, LEFTRIGHT, this->localPlayer);
    676         */
    677         this->glmis->step();
    678         break;
     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;
    679680      }
    680681    case DEBUG_WORLD_1:
    681682      {
    682683
    683         break;
     684        break;
    684685      }
    685686    case DEBUG_WORLD_2:
    686687      {
    687688
    688         break;
     689        break;
    689690      }
    690691    default:
     
    698699   \brief initializes a new World shortly before start
    699700
    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
    701702   started
    702703*/
     
    759760void World::displayLoadScreen ()
    760761{
    761   PRINTF(3)("World::displayLoadScreen - start\n"); 
    762  
    763   //GLMenuImageScreen* 
     762  PRINTF(3)("World::displayLoadScreen - start\n");
     763
     764  //GLMenuImageScreen*
    764765  this->glmis = new GLMenuImageScreen();
    765766  this->glmis->init();
    766767  this->glmis->setMaximum(8);
    767768  //  this->glmis->draw();
    768  
    769   PRINTF(3)("World::displayLoadScreen - end\n"); 
     769
     770  PRINTF(3)("World::displayLoadScreen - end\n");
    770771}
    771772
     
    777778void World::releaseLoadScreen ()
    778779{
    779   PRINTF(3)("World::releaseLoadScreen - start\n"); 
     780  PRINTF(3)("World::releaseLoadScreen - start\n");
    780781  this->glmis->setValue(this->glmis->getMaximum());
    781   PRINTF(3)("World::releaseLoadScreen - end\n"); 
     782  PRINTF(3)("World::releaseLoadScreen - end\n");
    782783  delete this->glmis;
    783784}
     
    804805
    805806
    806 /** 
     807/**
    807808    \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
    811812    is called.
    812813*/
     
    816817  List *a, *b;
    817818  WorldEntity *aobj, *bobj;
    818    
     819
    819820  a = entities;
    820  
     821
    821822  while( a != NULL)
    822823    {
    823824      aobj = a->nextElement();
    824825      if( aobj->bCollide && aobj->collisioncluster != NULL)
    825         {
    826           b = a->nextElement();
    827           while( b != NULL )
    828             {
    829               bobj = b->nextElement();
    830               if( bobj->bCollide && bobj->collisioncluster != NULL )
    831                 {
    832                   unsigned long ahitflg, bhitflg;
    833                   if( check_collision ( &aobj->place, aobj->collisioncluster,
    834                                         &ahitflg, &bobj->place, bobj->collisioncluster,
    835                                         &bhitflg) );
    836                   {
    837                     aobj->collide (bobj, ahitflg, bhitflg);
    838                     bobj->collide (aobj, bhitflg, ahitflg);
    839                   }
    840                 }
    841               b = b->nextElement();
    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        }
    844845      a = a->enumerate();
    845846    }
     
    847848}
    848849
    849 /** 
     850/**
    850851    \brief runs through all entities calling their draw() methods
    851852*/
     
    859860  tIterator<WorldEntity>* iterator = this->entities->getIterator();
    860861  entity = iterator->nextElement();
    861   while( entity != NULL ) 
    862     { 
     862  while( entity != NULL )
     863    {
    863864      if( entity->bDraw ) entity->draw();
    864865      //entity = this->entities->nextElement();
     
    866867    }
    867868  delete iterator;
    868  
     869
    869870  glCallList (objectList);
    870871
     
    900901  p3->debug ();
    901902  p4->debug ();
    902  
     903
    903904  p1->update (0);
    904905
     
    928929
    929930  delete p1;
    930  
    931  
     931
     932
    932933  /*
    933934  WorldEntity* entity;
    934935  printf("counting all entities\n");
    935936  printf("World::debug() - enumerate()\n");
    936   entity = entities->enumerate(); 
    937   while( entity != NULL ) 
    938     { 
     937  entity = entities->enumerate();
     938  while( entity != NULL )
     939    {
    939940      if( entity->bDraw ) printf("got an entity\n");
    940941      entity = entities->nextElement();
     
    963964      this->handleInput ();
    964965      if( this->bQuitCurrentGame || this->bQuitOrxonox)
    965           break;
     966          break;
    966967      // Process time
    967968      this->tick ();
    968969      // Update the state
    969       this->update ();     
     970      this->update ();
    970971      // Process collision
    971972      this->collide ();
     
    10211022    {
    10221023      this->dt = currentFrame - this->lastFrame;
    1023      
     1024
    10241025      if( this->dt > 0)
    1025         {
    1026           float fps = 1000/dt;
    1027 
    1028           // temporary, only for showing how fast the text-engine is
    1029           char tmpChar[20];
    1030           sprintf(tmpChar, "fps: %4.0f", fps);
    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        }
    10321033      else
    1033         {
    1034           /* the frame-rate is limited to 100 frames per second, all other things are for
    1035              nothing.
    1036           */
    1037           PRINTF(2)("fps = 1000 - frame rate is adjusted\n");
    1038           SDL_Delay(10);
    1039           this->dt = 10;
    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        }
    10411042      //this->timeSlice (dt);
    1042      
     1043
    10431044      /* 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;
    10451046      this->gameTime += this->dtS;
    1046       //entity = entities->enumerate(); 
     1047      //entity = entities->enumerate();
    10471048      tIterator<WorldEntity>* iterator = this->entities->getIterator();
    10481049      WorldEntity* entity = iterator->nextElement();
    1049       while( entity != NULL) 
    1050         {
    1051           entity->tick (this->dtS);
    1052           entity = iterator->nextElement();
    1053         }
     1050      while( entity != NULL)
     1051        {
     1052          entity->tick (this->dtS);
     1053          entity = iterator->nextElement();
     1054        }
    10541055      delete iterator;
    10551056
     
    10631064      particleEngine->tick(this->dtS);
    10641065      this->garbageCollector->tick(this->dtS);
    1065          
     1066
    10661067      /* actualy the Graphics Engine should tick the world not the other way around...
    1067         but since we like the things not too complicated we got it this way around
    1068         until there is need or time to do it the other way around.
    1069         \todo: GraphicsEngine ticks world: separation of processes and data...
     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...
    10701071      */
    10711072      GraphicsEngine::getInstance()->tick(this->dtS);
     
    10921093/**
    10931094   \brief render the current frame
    1094    
     1095
    10951096   clear all buffers and draw the world
    10961097*/
     
    11471148   \param In which relative direction should it look.
    11481149*/
    1149 void World::spawn(WorldEntity* entity, PNode* parentNode, 
    1150                   Vector* relCoor, Quaternion* relDir,
    1151                   int parentingMode)
     1150void World::spawn(WorldEntity* entity, PNode* parentNode,
     1151                  Vector* relCoor, Quaternion* relDir,
     1152                  int parentingMode)
    11521153{
    11531154  this->nullParent = NullParent::getInstance();
     
    11551156    {
    11561157      parentNode->addChild (entity);
    1157      
     1158
    11581159      entity->setRelCoor (*relCoor);
    11591160      entity->setRelDir (*relDir);
    11601161      entity->setParentMode(parentingMode);
    1161      
     1162
    11621163      this->entities->add (entity);
    1163      
     1164
    11641165      entity->postSpawn ();
    11651166    }
Note: See TracChangeset for help on using the changeset viewer.