Browse Source

fixed a bug in the world loader if the world does not exists

Kolja Strohm 3 years ago
parent
commit
99aeb1fa2e
3 changed files with 22 additions and 17 deletions
  1. 4 3
      FactoryCraft/Game.cpp
  2. 2 2
      FactoryCraft/Game.h
  3. 16 12
      FactoryCraft/WorldLoader.cpp

+ 4 - 3
FactoryCraft/Game.cpp

@@ -142,13 +142,13 @@ Game::Game( Framework::Text name, Framework::Text worldsDir )
     dimensions( new RCArray<Dimension>() ),
     updates( new RCArray<WorldUpdate>() ),
     clients( new RCArray<GameClient>() ),
-    generator( 0 ),
-    loader( new WorldLoader( this ) ),
     ticker( new TickOrganizer() ),
     path( (const char *)( worldsDir + "/" + name ) ),
     stop( 0 ),
     tickId( 0 ),
-    nextEntityId( 0 )
+    nextEntityId( 0 ),
+    generator( 0 ),
+    loader( 0 )
 {
     if( !DateiExistiert( worldsDir + "/" + name ) )
         DateiPfadErstellen( worldsDir + "/" + name + "/" );
@@ -165,6 +165,7 @@ Game::Game( Framework::Text name, Framework::Text worldsDir )
     for( char *n = name; n; n++ )
         seed += (int)pow( (float)*n * 31, ( float )++index );
     generator = new WorldGenerator( seed, this );
+    loader = new WorldLoader( this );
     start();
 }
 

+ 2 - 2
FactoryCraft/Game.h

@@ -59,14 +59,14 @@ private:
     Framework::RCArray<Dimension> *dimensions;
     Framework::RCArray<WorldUpdate> *updates;
     Framework::RCArray<GameClient> *clients;
-    WorldGenerator *generator;
-    WorldLoader *loader;
     TickOrganizer *ticker;
     Framework::Text path;
     bool stop;
     __int64 tickId;
     CriticalSection cs;
     int nextEntityId;
+    WorldGenerator *generator;
+    WorldLoader *loader;
 
     void thread() override;
 public:

+ 16 - 12
FactoryCraft/WorldLoader.cpp

@@ -12,26 +12,30 @@ WorldLoader::WorldLoader( Game *zGame )
     zGame( zGame ),
     exit( 0 )
 {
-    Datei d;
+    oader i
+        Datei d;
     d.setDatei( zGame->getWorldDirectory() + "/dim" );
     RCArray<Text> *names = d.getDateiListe();
-    for( auto name = names->getIterator(); name; name++ )
+    if( names )
     {
-        Datei entities;
-        entities.setDatei( zGame->getWorldDirectory() + "/dim/" + Text( name->getText() ) + "/entities" );
-        if( entities.open( Datei::Style::lesen ) )
+        for( auto name = names->getIterator(); name; name++ )
         {
-            Dimension *dim = new Dimension( *name.val() );
-            while( !entities.istEnde() )
+            Datei entities;
+            entities.setDatei( zGame->getWorldDirectory() + "/dim/" + Text( name->getText() ) + "/entities" );
+            if( entities.open( Datei::Style::lesen ) )
             {
-                int type = 0;
-                entities.lese( (char *)&type, 4 );
-                dim->addEntity( StaticRegistry<EntityType>::INSTANCE.zElement( type )->loadEntity( zGame, &entities ) );
+                Dimension *dim = new Dimension( *name.val() );
+                while( !entities.istEnde() )
+                {
+                    int type = 0;
+                    entities.lese( (char *)&type, 4 );
+                    dim->addEntity( StaticRegistry<EntityType>::INSTANCE.zElement( type )->loadEntity( zGame, &entities ) );
+                }
+                zGame->addDimension( dim );
             }
-            zGame->addDimension( dim );
         }
+        names->release();
     }
-    names->release();
     start();
 }