Răsfoiți Sursa

fix chunk data loading order issue

Kolja Strohm 2 ani în urmă
părinte
comite
017b5cc046
3 a modificat fișierele cu 9 adăugiri și 10 ștergeri
  1. 5 8
      FactoryCraft/Chunk.cpp
  2. 3 1
      FactoryCraft/Dimension.cpp
  3. 1 1
      FactoryCraft/PlayerKam.cpp

+ 5 - 8
FactoryCraft/Chunk.cpp

@@ -92,7 +92,6 @@ void Chunk::load(Framework::StreamReader* zReader)
         }
     }
     cs.unlock();
-    RCTrie<Block> blockCache;
     isLoading = 1;
     Framework::Vec3<int> pos = {0, 0, 0};
     unsigned short id;
@@ -112,8 +111,6 @@ void Chunk::load(Framework::StreamReader* zReader)
                     pos.y + location.y - CHUNK_SIZE / 2,
                     pos.z});
             blocks[index] = b;
-            blockCache.set(
-                (char*)&index, 4, dynamic_cast<Block*>(b->getThis()));
             cs.unlock();
             vcs.lock();
             if (b->isVisible())
@@ -147,7 +144,7 @@ void Chunk::load(Framework::StreamReader* zReader)
             if (x == -1)
             {
                 int cacheIndex = y * WORLD_HEIGHT + z;
-                Block* zB = blockCache.z((char*)&cacheIndex, 4);
+                Block* zB = blocks[cacheIndex];
                 if (zB)
                 {
                     zB->setLightData(WEST, (unsigned char*)lightData);
@@ -156,7 +153,7 @@ void Chunk::load(Framework::StreamReader* zReader)
             else if (y == -1)
             {
                 int cacheIndex = (x * CHUNK_SIZE) * WORLD_HEIGHT + z;
-                Block* zB = blockCache.z((char*)&cacheIndex, 4);
+                Block* zB = blocks[cacheIndex];
                 if (zB)
                 {
                     zB->setLightData(NORTH, (unsigned char*)lightData);
@@ -166,7 +163,7 @@ void Chunk::load(Framework::StreamReader* zReader)
             {
                 int cacheIndex
                     = ((CHUNK_SIZE - 1) * CHUNK_SIZE + y) * WORLD_HEIGHT + z;
-                Block* zB = blockCache.z((char*)&cacheIndex, 4);
+                Block* zB = blocks[cacheIndex];
                 if (zB)
                 {
                     zB->setLightData(EAST, (unsigned char*)lightData);
@@ -176,7 +173,7 @@ void Chunk::load(Framework::StreamReader* zReader)
             {
                 int cacheIndex
                     = (x * CHUNK_SIZE + (CHUNK_SIZE - 1)) * WORLD_HEIGHT + z;
-                Block* zB = blockCache.z((char*)&cacheIndex, 4);
+                Block* zB = blocks[cacheIndex];
                 if (zB)
                 {
                     zB->setLightData(SOUTH, (unsigned char*)lightData);
@@ -201,7 +198,7 @@ void Chunk::load(Framework::StreamReader* zReader)
                         int cacheIndex
                             = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT
                             + pos.z;
-                        Block* zB = blockCache.z((char*)&cacheIndex, 4);
+                        Block* zB = blocks[cacheIndex];
                         if (zB)
                         {
                             bool visible = zB->isVisible();

+ 3 - 1
FactoryCraft/Dimension.cpp

@@ -97,6 +97,7 @@ void Dimension::api(char* message)
             cs.unlock();
             World::INSTANCE->unlockWorld();
             World::INSTANCE->onChunkAdded(center);
+            World::INSTANCE->zClient()->chunkAPIRequest(center, "\2", 1);
             break;
         }
     case 5: // light update
@@ -121,7 +122,8 @@ void Dimension::api(char* message)
                             (unsigned char*)(message + 13));
                         if (zB->isVisible() != visible)
                         {
-                            zChunk(World::INSTANCE->getChunkCenter(pos.x, pos.y))
+                            zChunk(
+                                World::INSTANCE->getChunkCenter(pos.x, pos.y))
                                 ->blockVisibilityChanged(zB);
                         }
                     }

+ 1 - 1
FactoryCraft/PlayerKam.cpp

@@ -134,7 +134,7 @@ bool PlayerKam::tick(double time)
         setShowCursor(false);
         setMausPos(window->getPosition() + window->getGröße() / 2);
     }
-    return result;
+    return 1;
 }
 
 void PlayerKam::setEntityId(int id)