Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 23, 2005, 11:37:25 AM (19 years ago)
Author:
chris
Message:

orxonox/branches/ll2trunktemp: I tried… Not working…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/ll2trunktemp/src/story_entities/world.cc

    r3870 r3940  
     1
    12
    23/*
     
    4344#include "glmenu_imagescreen.h"
    4445#include "list.h"
    45 
    46 
     46#include "game_loader.h"
     47
     48#include "substring.h"
    4749
    4850using namespace std;
    49 
    5051
    5152WorldInterface* WorldInterface::singletonRef = 0;
     
    113114}
    114115
    115 
     116CREATE_FACTORY(World)
     117
     118World::World( TiXmlElement* root)
     119{
     120        const char *string;
     121        char *name;
     122        int id;
     123
     124        PRINTF0("Creating a World\n");
     125       
     126        // identifier
     127        string = grabParameter( root, "identifier");
     128        if( string == NULL || sscanf(string, "%d", &id) != 1)
     129        {
     130                PRINTF0("World is missing a proper 'identifier'\n");
     131                this->setStoryID( -1);
     132        }
     133        else setStoryID( id);
     134       
     135        // path
     136        string = grabParameter( root, "path");
     137        if( string == NULL)
     138        {
     139                PRINTF0("World is missing a proper 'path'\n");
     140                this->setPath( NULL);
     141        }
     142        else
     143        {
     144                name = new char[strlen(string + 2)];
     145                strcpy( name, string);
     146                this->setPath( name);
     147        }
     148       
     149  this->localPlayer = NULL;
     150  this->entities = new tList<WorldEntity>();
     151       
     152
     153  this->setClassName ("World");
     154}
    116155
    117156/**
     
    181220  this->setClassName ("World");
    182221
    183   this->worldName = name;
     222  //this->worldName = name;
     223  //this->worldName = new char[strlen(name)+1];
     224  //strcpy(this->worldName, name);
    184225  this->debugWorldNr = worldID;
    185226  this->entities = new tList<WorldEntity>();
     
    207248*/
    208249ErrorMessage World::load()
    209 {
    210   //  BezierCurve* tmpCurve = new BezierCurve();
    211   if(this->debugWorldNr != -1)
    212     {
    213       // initializing Font
    214       this->glmis->step();
     250{       
     251  PRINTF0("> Loading world: '%s'\n", getPath());
     252 
     253  GameLoader* loader = GameLoader::getInstance();
     254 
     255  if( getPath() == NULL)
     256    {
     257      PRINTF0("World has no path specified for loading");
     258      return (ErrorMessage){213,"Path not specified","World::load()"};
     259    }
     260 
     261  TiXmlDocument* XMLDoc = new TiXmlDocument( path);
     262  // load the campaign document
     263  if( !XMLDoc->LoadFile())
     264    //this->glmis->step();
     265 
     266  {
     267    // report an error
     268    PRINTF0("Error loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
     269    delete XMLDoc;
     270    return (ErrorMessage){213,"XML File parsing error","World::load()"};
     271  }
     272 
     273  // check basic validity
     274  TiXmlElement* root = XMLDoc->RootElement();
     275  assert( root != NULL);
     276 
     277  if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile"))
     278    {
     279      // report an error
     280      PRINTF0("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
     281      delete XMLDoc;
     282      return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"};
     283    }
     284 
     285  // load the parameters
     286  // name
     287  char* temp;
     288  const char* string = grabParameter( root, "name");
     289  if( string == NULL)
     290    {
     291      PRINTF0("World is missing a proper 'name'\n");
     292      string = "Unknown";
     293      temp = new char[strlen(string + 2)];
     294      strcpy( temp, string);
     295      this->worldName = temp;
     296    }
     297  else
     298    {
     299      temp = new char[strlen(string + 2)];
     300      strcpy( temp, string);
     301      this->worldName = temp;
     302    }
     303 
     304 
     305  // find WorldEntities
     306  TiXmlElement* element = root->FirstChildElement( "WorldEntities");
     307 
     308  if( element == NULL)
     309    {
     310      PRINTF0("World is missing 'WorldEntities'\n");
     311    }
     312  else
     313    {
     314      element = element->FirstChildElement();
     315      // load Players/Objects/Whatever
     316      PRINTF0("Loading WorldEntities\n");
     317      while( element != NULL)
     318        {
     319          WorldEntity* created = (WorldEntity*) loader->fabricate( element);
     320          if( created != NULL) this->spawn( created);
     321          // if we load a 'Player' we use it as localPlayer
     322          //todo do this more elegant
     323          if( element->Value() != NULL && !strcmp( element->Value(), "Player")) localPlayer = (Player*) created;
     324          element = element->NextSiblingElement();
     325        }
     326      PRINTF0("Done loading WorldEntities\n");
     327    }
     328 
     329  // find Track
     330  /*element = root->FirstChildElement( "Track");
     331  if( element == NULL)
     332    {
     333      PRINTF0("============>>>>>>>>>>>>>>>>>World is missing a 'Track'\n");
     334    }
     335  else
     336    {   
     337      //load track
     338      PRINTF0("============>>>>>>>>>>>>>>>>Loading Track\n");
     339      trackManager = TrackManager::getInstance();
     340      trackManager->loadTrack( element);
     341      trackManager->finalize();
     342      PRINTF0("============>>>>>>>>>>>>>>>>Done loading Track\n");
     343    }*/
     344 
     345  // free the XML data
     346  delete XMLDoc;
     347 
     348  // finalize world
     349  // initialize Font
     350//  testFont = new FontSet();
     351//  testFont->buildFont("../data/pictures/font.tga");
     352 
     353  // create null parent
     354  this->nullParent = NullParent::getInstance ();
     355  this->nullParent->setName ("NullParent");
     356 
     357  // finalize myPlayer
     358  if( localPlayer == NULL)
     359    {
     360      PRINTF0("No Player specified in World '%s'\n", this->worldName);
     361      return (ErrorMessage){213,"No Player defined","World::load()"};
     362    }
     363 
     364  // bind input
     365  Orxonox *orx = Orxonox::getInstance ();
     366  orx->getLocalInput()->bind (localPlayer);
     367 
     368  // bind camera
     369  this->localCamera = new Camera();
     370  this->localCamera->setName ("camera");
     371  //this->localCamera->bind (localPlayer);
     372  this->localPlayer->addChild (this->localCamera);
     373 
     374 
     375  // stuff beyond this point remains to be loaded properly
     376 
    215377      // initializing the TrackManager
    216378      trackManager = TrackManager::getInstance();
     
    272434
    273435     
    274       /*monitor progress*/
    275       this->glmis->step();
    276 
    277       // LIGHT initialisation
    278       lightMan = LightManager::getInstance();
    279       lightMan->setAmbientColor(.1,.1,.1);
    280       lightMan->addLight();
    281       //      lightMan->setAttenuation(1.0, .01, 0.0);
    282       //      lightMan->setDiffuseColor(1,1,1);
    283       //  lightMan->addLight(1);
    284       //  lightMan->setPosition(20, 10, -20);
    285       //  lightMan->setDiffuseColor(0,0,0);
    286       lightMan->debug();
    287 
    288       switch(this->debugWorldNr)
    289         {
    290           /*
    291             this loads the hard-coded debug world. this only for simplicity and will be
    292             removed by a reald world-loader, which interprets a world-file.
    293             if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and
    294             make whatever you want...
    295            */
    296         case DEBUG_WORLD_0:
    297           {
    298             lightMan->setPosition(-5.0, 10.0, -40.0);
    299             this->nullParent = NullParent::getInstance ();
    300             this->nullParent->setName ("NullParent");
    301 
    302             // !\todo old track-system has to be removed
    303 
    304             //create helper for player
    305             //HelperParent* hp = new HelperParent ();
    306             /* the player has to be added to this helper */
    307 
    308             // create a player
    309             this->localPlayer = new Player ();
    310             this->localPlayer->setName ("player");
    311             this->spawn (this->localPlayer);
    312             /*monitor progress*/
    313             //this->glmis->step();
    314             this->glmis->step();
    315 
    316             // bind input
    317             Orxonox *orx = Orxonox::getInstance ();
    318             orx->getLocalInput()->bind (this->localPlayer);
    319            
    320             // bind camera
    321             this->localCamera = new Camera();
    322             this->localCamera->setName ("camera");
    323            
    324             /*monitor progress*/
    325             this->glmis->step();
    326 
    327             // Create SkySphere
    328             //      this->skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
    329             //      this->skySphere->setName("SkySphere");
    330             //      this->localCamera->addChild(this->skySphere);
    331             //      this->spawn(this->skySphere);
    332             skyBox = new SkyBox();
    333             skyBox->setTexture("pictures/sky/skybox", "jpg");
    334             skyBox->setParent(localCamera);
    335             this->spawn(skyBox);
    336 
    337             /*monitor progress*/
    338             this->glmis->step();
    339 
    340            
    341             WorldEntity* env = new Environment();
    342             env->setName ("env");
    343             this->spawn(env);
    344 
    345            
    346             /*
    347             Vector* es = new Vector (10, 5, 0);
    348             Quaternion* qs = new Quaternion ();
    349             WorldEntity* pr = new Primitive(P_CYLINDER);
    350             pr->setName("primitive");
    351             this->spawn(pr, this->localPlayer, es, qs, PNODE_MOVEMENT);
    352             */
    353 
    354             /*monitor progress*/
    355             this->glmis->step();
    356 
    357             //      trackManager->setBindSlave(env);
    358             PNode* tn = trackManager->getTrackNode();
    359             tn->addChild(this->localPlayer);
    360             this->localCamera->lookAt(tn);
    361 
    362             //localCamera->setParent(TrackNode::getInstance());
    363             tn->addChild(this->localCamera);
    364             //      localCamera->lookAt(tn);
    365             this->localPlayer->setMode(PNODE_ALL);
    366             //Vector* cameraOffset = new Vector (0, 5, -10);
    367             trackManager->condition(2, LEFTRIGHT, this->localPlayer);
    368             this->glmis->step();
    369             break;
    370           }
    371         case DEBUG_WORLD_1:
    372           {
    373             lightMan->setPosition(.0, .0, .0);
    374             lightMan->setAttenuation(1.0, .01, 0.0);
    375             lightMan->setSpecularColor(1,0,0);
    376             this->nullParent = NullParent::getInstance ();
    377             this->nullParent->setName ("NullParent");
    378 
    379             // create a player
    380             WorldEntity* myPlayer = new Player();
    381             myPlayer->setName ("player");
    382             this->spawn(myPlayer);
    383             this->localPlayer = myPlayer;           
    384            
    385             // bind input
    386             Orxonox *orx = Orxonox::getInstance();
    387             orx->getLocalInput()->bind (myPlayer);
    388            
    389             // bind camera
    390             this->localCamera = new Camera ();
    391             this->localCamera->setName ("camera");
    392             this->localCamera->lookAt(LightManager::getInstance()->getLight(0));
    393             this->localCamera->setParent(this->localPlayer);
    394 
    395             // Create SkySphere
    396             skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
    397             this->localPlayer->addChild(this->skySphere);
    398             this->spawn(this->skySphere);
    399             Vector* es = new Vector (20, 0, 0);
    400             Quaternion* qs = new Quaternion ();
    401 
    402             lightMan->getLight(0)->setParent(trackManager->getTrackNode());
    403             break;
    404           }
    405         case DEBUG_WORLD_2:
    406           {
    407             lightMan->setAmbientColor(.1,.1,.1);
    408             lightMan->addLight();
    409             lightMan->setPosition(-5.0, 10.0, -40.0);
    410             this->nullParent = NullParent::getInstance ();
    411             this->nullParent->setName ("NullParent");
    412 
    413             // !\todo old track-system has to be removed
    414 
    415             //create helper for player
    416             //HelperParent* hp = new HelperParent ();
    417             /* the player has to be added to this helper */
    418 
    419             // create a player
    420             this->localPlayer = new Player ();
    421             this->localPlayer->setName ("player");
    422             this->spawn (this->localPlayer);
    423             /*monitor progress*/
    424             //this->glmis->step();         
    425             this->glmis->step();
    426 
    427             // bind input
    428             Orxonox *orx = Orxonox::getInstance ();
    429             orx->getLocalInput()->bind (this->localPlayer);
    430            
    431             // bind camera
    432             this->localCamera = new Camera();
    433             this->localCamera->setName ("camera");
    434             this->localCamera->lookAt(this->localPlayer);
    435             this->localCamera->setParent(this->localPlayer);
    436            
    437             /*monitor progress*/
    438             this->glmis->step();
    439 
    440             // Create SkySphere
    441             this->skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
    442             this->skySphere->setName("SkySphere");
    443             this->spawn(this->skySphere);
    444             this->localCamera->addChild(this->skySphere);
    445             this->skySphere->setMode(PNODE_MOVEMENT);
    446             /*monitor progress*/
    447             this->glmis->step();
    448 
    449 
    450             WorldEntity* baseNode = new Satellite(Vector(1,0,1), 1.2);
    451             this->localPlayer->addChild(baseNode);
    452             baseNode->setRelCoor(Vector(10.0, 2.0, 1.0));
    453             this->spawn(baseNode);
    454 
    455             WorldEntity* secondNode = new Satellite(Vector(0,0,1), 2.0);
    456             baseNode->addChild(secondNode);
    457             secondNode->setRelCoor(Vector(0.0, 0.0, 3.0));
    458             this->spawn(secondNode);
    459 
    460 
    461             WorldEntity* thirdNode = new Satellite(Vector(0,0,1), 1.0);
    462             secondNode->addChild(thirdNode);
    463             thirdNode->setRelCoor(Vector(2.0, 0.0, 0.0));
    464             this->spawn(thirdNode);
    465 
    466            
    467            
    468 
    469             WorldEntity* b = new Environment();
    470             this->localPlayer->addChild(b);
    471             b->setRelCoor(Vector(10.0, 1.0, 1.0));
    472             this->spawn(b);
    473 
    474            
    475             WorldEntity* c = new Environment();
    476             this->localPlayer->addChild(c);
    477             c->setRelCoor(Vector(10.0, 2.0, -1.0));
    478             this->spawn(c);
    479            
    480             /*     
    481                   KeyFrame* f1 = new KeyFrame;
    482                   f1->position = new Vector(-1.1, 0.0, 2.6);
    483                   f1->direction = new Quaternion();
    484                   f1->time = 1.0;
    485                   f1->mode = NEG_EXP;
    486                  
    487                  
    488                   KeyFrame* f2 = new KeyFrame;
    489                   f2->position = new Vector(-2.1, 0.0, 2.6);
    490                   f2->direction = new Quaternion();
    491                   f2->time = 0.1;
    492                   f2->mode = NEG_EXP;
    493                  
    494                   KeyFrame* f3 = new KeyFrame;
    495                   f3->position = new Vector(10.0, 2.0, -1.0);
    496                   f3->direction = new Quaternion();
    497                   f3->time = 0.2;
    498                   f3->mode = NEG_EXP;
    499                  
    500                   KeyFrame* f4 = new KeyFrame;
    501                   f4->position = new Vector(10.0, 5.0, -1.0);
    502                   f4->direction = new Quaternion();
    503                   f4->time = 1.0;
    504                   f4->mode = NEG_EXP;
    505                  
    506                  
    507                  
    508                   this->simpleAnimation->animatorBegin();
    509                   this->simpleAnimation->selectObject(b);
    510                   this->simpleAnimation->setAnimationMode(SINGLE);
    511                   this->simpleAnimation->addKeyFrame(f1);
    512                   this->simpleAnimation->addKeyFrame(f2);
    513                   this->simpleAnimation->start();
    514                   this->simpleAnimation->selectObject(c);
    515                   this->simpleAnimation->addKeyFrame(f3);
    516                   this->simpleAnimation->addKeyFrame(f4);
    517                   this->simpleAnimation->start();
    518                   this->simpleAnimation->animatorEnd();
    519             */
    520 
    521             /*
    522             Vector* es = new Vector (10, 5, 0);
    523             Quaternion* qs = new Quaternion ();
    524             WorldEntity* pr = new Primitive(P_CYLINDER);
    525             pr->setName("primitive");
    526             this->spawn(pr, this->localPlayer, es, qs, PNODE_MOVEMENT);
    527             */
    528 
    529             /*monitor progress*/
    530             this->glmis->step();
    531 
    532             //      trackManager->setBindSlave(env);
    533             PNode* tn = trackManager->getTrackNode();
    534             tn->addChild(this->localPlayer);
    535 
    536             //localCamera->setParent(TrackNode::getInstance());
    537             tn->addChild(this->localCamera);
    538             //      localCamera->lookAt(tn);
    539             this->localPlayer->setMode(PNODE_ALL);
    540             //Vector* cameraOffset = new Vector (0, 5, -10);
    541             trackManager->condition(2, LEFTRIGHT, this->localPlayer);
    542             this->glmis->step();
    543 
    544             break;
    545           }
    546         default:
    547           printf("World::load() - no world with ID %i found", this->debugWorldNr );
    548         }
    549     }
    550   else if(this->worldName != NULL)
    551     {
    552 
    553     }
    554 
     436  // LIGHT initialisation
     437  lightMan = LightManager::getInstance();
     438  lightMan->setAmbientColor(.1,.1,.1);
     439  lightMan->addLight();
     440  //      lightMan->setAttenuation(1.0, .01, 0.0);
     441  //      lightMan->setDiffuseColor(1,1,1);
     442  //  lightMan->addLight(1);
     443  //  lightMan->setPosition(20, 10, -20);
     444  //  lightMan->setDiffuseColor(0,0,0);
     445  lightMan->debug();
     446  lightMan->setPosition(-5.0, 10.0, -40.0);
     447 
     448 
     449  // Create SkySphere
     450  this->skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
     451  this->skySphere->setName("SkySphere");
     452  this->localCamera->addChild(this->skySphere);
     453  this->skySphere->setMode(PNODE_MOVEMENT);
     454 
     455 
     456  //        trackManager->setBindSlave(env);
     457  PNode* tn = trackManager->getTrackNode();
     458  tn->addChild(this->localPlayer);
     459 
     460  //localCamera->setParent(TrackNode::getInstance());
     461  tn->addChild(this->localCamera);
     462  //        localCamera->lookAt(tn);
     463  this->localPlayer->setMode(PNODE_ALL);
     464  //Vector* cameraOffset = new Vector (0, 5, -10);
     465  //trackManager->condition(2, LEFTRIGHT, this->localPlayer);
     466 
    555467  // initialize debug coord system
    556468  objectList = glGenLists(1);
    557469  glNewList (objectList, GL_COMPILE);
    558  
     470  
    559471  //  trackManager->drawGraph(.01);
    560472  trackManager->debug(2);
     
    840752      this->tick ();
    841753      // Update the state
    842       this->update ();      
     754      this->update ();     
    843755      // Process collision
    844756      this->collide ();
     
    1043955}
    1044956
     957void World::setPath( const char* name)
     958{
     959  this->path = new char[strlen(name)+1];
     960  strcpy(this->path, name);
     961}
     962
     963const char* World::getPath( void)
     964{
     965  return path;
     966}
Note: See TracChangeset for help on using the changeset viewer.