Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 15, 2005, 3:15:36 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: tracked some segfaults: now the first world starts, as you will see, the world wont be running correctly: guess some problems with initialisation of the trackmanager. I corrected also the worldName segfault. on level change/exit the application will hang. i guess on the resource manager but my ddd doesn't help anything here…

File:
1 edited

Legend:

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

    r3753 r3834  
    220220  this->setClassName ("World");
    221221
    222   this->worldName = name;
     222  //this->worldName = name;
     223  //this->worldName = new char[strlen(name)+1];
     224  //strcpy(this->worldName, name);
    223225  this->debugWorldNr = worldID;
    224226  this->entities = new tList<WorldEntity>();
     
    247249ErrorMessage World::load()
    248250{       
    249         PRINTF0("> Loading world: '%s'\n", getPath());
    250        
    251         GameLoader* loader = GameLoader::getInstance();
    252        
     251  PRINTF0("> Loading world: '%s'\n", getPath());
     252 
     253  GameLoader* loader = GameLoader::getInstance();
     254 
    253255  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 
    254266  {
    255                 PRINTF0("World has no path specified for loading");
    256                 return (ErrorMessage){213,"Path not specified","World::load()"};
     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()"};
    257271  }
    258272 
    259         TiXmlDocument* XMLDoc = new TiXmlDocument( path);
    260         // load the campaign document
    261         if( !XMLDoc->LoadFile())
    262       this->glmis->step();
    263 
     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)
    264318        {
    265                 // report an error
    266                 PRINTF0("Error loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
    267                 delete XMLDoc;
    268                 return (ErrorMessage){213,"XML File parsing error","World::load()"};
     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();
    269325        }
    270        
    271         // check basic validity
    272         TiXmlElement* root = XMLDoc->RootElement();
    273         assert( root != NULL);
    274        
    275         if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile"))
    276         {
    277                 // report an error
    278                 PRINTF0("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
    279                 delete XMLDoc;
    280                 return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"};
    281         }
    282        
    283         // load the parameters
    284                 // name
    285         char* temp;
    286         const char* string = grabParameter( root, "name");
    287         if( string == NULL)
    288         {
    289                 PRINTF0("World is missing a proper 'name'\n");
    290                 string = "Unknown";
    291                 temp = new char[strlen(string + 2)];
    292                 strcpy( temp, string);
    293                 this->worldName = temp;
    294         }
    295         else
    296         {
    297                 temp = new char[strlen(string + 2)];
    298                 strcpy( temp, string);
    299                 this->worldName = temp;
    300         }
    301        
    302        
    303         // find WorldEntities
    304   TiXmlElement* element = root->FirstChildElement( "WorldEntities");
    305  
    306   if( element == NULL)
    307   {
    308                 PRINTF0("World is missing 'WorldEntities'\n");
    309   }
    310   else
    311   {
    312         element = element->FirstChildElement();
    313           // load Players/Objects/Whatever
    314                 PRINTF0("Loading WorldEntities\n");
    315                 while( element != NULL)
    316                 {
    317                         WorldEntity* created = (WorldEntity*) loader->fabricate( element);
    318                         if( created != NULL) this->spawn( created);
    319                                 // if we load a 'Player' we use it as localPlayer
    320                                 //todo do this more elegant
    321                          if( element->Value() != NULL && !strcmp( element->Value(), "Player")) localPlayer = (Player*) created;
    322                         element = element->NextSiblingElement();
    323                 }
    324                 PRINTF0("Done loading WorldEntities\n");
    325         }
    326        
    327         // find Track
     326      PRINTF0("Done loading WorldEntities\n");
     327    }
     328 
     329  // find Track
    328330  element = root->FirstChildElement( "Track");
    329331  if( element == NULL)
    330   {
    331                 PRINTF0("World is missing a 'Track'\n");
    332   }
     332    {
     333      PRINTF0("============>>>>>>>>>>>>>>>>>World is missing a 'Track'\n");
     334    }
    333335  else
    334   {     
    335         //load track
    336                 PRINTF0("Loading Track\n");
    337                 trackManager = TrackManager::getInstance();
    338         trackManager->loadTrack( element);
    339         trackManager->finalize();
    340                 PRINTF0("Done loading Track\n");
    341         }
    342        
    343         // free the XML data
    344         delete XMLDoc;
    345        
    346         // finalize world
    347           // initialize Font
    348           testFont = new FontSet();
    349           testFont->buildFont("../data/pictures/font.tga");
    350        
    351                 // create null parent
    352     this->nullParent = NullParent::getInstance ();
    353     this->nullParent->setName ("NullParent");
    354    
    355     // finalize myPlayer
    356                 if( localPlayer == NULL)
    357                 {
    358                         PRINTF0("No Player specified in World '%s'\n", this->worldName);
    359                         return (ErrorMessage){213,"No Player defined","World::load()"};
    360                 }
    361                
    362         // bind input
    363     Orxonox *orx = Orxonox::getInstance ();
    364     orx->getLocalInput()->bind (localPlayer);
    365    
    366         // bind camera
    367     this->localCamera = new Camera();
    368     this->localCamera->setName ("camera");
    369     //this->localCamera->bind (localPlayer);
    370     this->localPlayer->addChild (this->localCamera);
    371 
    372        
    373         // stuff beyond this point remains to be loaded properly
    374        
    375       /*monitor progress*/
     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 
     377  /*monitor progress*/
    376378  //  this->glmis->step();
    377 
    378       // LIGHT initialisation
    379       lightMan = LightManager::getInstance();
    380       lightMan->setAmbientColor(.1,.1,.1);
    381       lightMan->addLight();
    382       //      lightMan->setAttenuation(1.0, .01, 0.0);
    383       //      lightMan->setDiffuseColor(1,1,1);
    384       //  lightMan->addLight(1);
    385       //  lightMan->setPosition(20, 10, -20);
    386       //  lightMan->setDiffuseColor(0,0,0);
    387       lightMan->debug();
    388             lightMan->setPosition(-5.0, 10.0, -40.0);
    389 
    390 
    391             // Create SkySphere
    392             this->skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
    393             this->skySphere->setName("SkySphere");
    394             this->localCamera->addChild(this->skySphere);
    395             this->skySphere->setMode(PNODE_MOVEMENT);
    396 
    397 
    398             //      trackManager->setBindSlave(env);
    399             PNode* tn = trackManager->getTrackNode();
    400             tn->addChild(this->localPlayer);
    401 
    402             //localCamera->setParent(TrackNode::getInstance());
    403             tn->addChild(this->localCamera);
    404             //      localCamera->lookAt(tn);
    405             this->localPlayer->setMode(PNODE_ALL);
    406             //Vector* cameraOffset = new Vector (0, 5, -10);
    407             //trackManager->condition(2, LEFTRIGHT, this->localPlayer);
    408 
     379 
     380  // LIGHT initialisation
     381  lightMan = LightManager::getInstance();
     382  lightMan->setAmbientColor(.1,.1,.1);
     383  lightMan->addLight();
     384  //      lightMan->setAttenuation(1.0, .01, 0.0);
     385  //      lightMan->setDiffuseColor(1,1,1);
     386  //  lightMan->addLight(1);
     387  //  lightMan->setPosition(20, 10, -20);
     388  //  lightMan->setDiffuseColor(0,0,0);
     389  lightMan->debug();
     390  lightMan->setPosition(-5.0, 10.0, -40.0);
     391 
     392 
     393  // Create SkySphere
     394  this->skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
     395  this->skySphere->setName("SkySphere");
     396  this->localCamera->addChild(this->skySphere);
     397  this->skySphere->setMode(PNODE_MOVEMENT);
     398 
     399 
     400  //        trackManager->setBindSlave(env);
     401  PNode* tn = trackManager->getTrackNode();
     402  tn->addChild(this->localPlayer);
     403 
     404  //localCamera->setParent(TrackNode::getInstance());
     405  tn->addChild(this->localCamera);
     406  //        localCamera->lookAt(tn);
     407  this->localPlayer->setMode(PNODE_ALL);
     408  //Vector* cameraOffset = new Vector (0, 5, -10);
     409  //trackManager->condition(2, LEFTRIGHT, this->localPlayer);
     410 
    409411  // initialize debug coord system
    410412  objectList = glGenLists(1);
    411413  glNewList (objectList, GL_COMPILE);
    412  
     414  
    413415  trackManager->drawGraph(.01);
    414416  trackManager->debug(2);
     
    697699      this->tick ();
    698700      // Update the state
    699       this->update ();      
     701      this->update ();     
    700702      // Process collision
    701703     this->collide ();
Note: See TracChangeset for help on using the changeset viewer.