Răsfoiți Sursa

update ground model only on next tick and not for every single update

Kolja Strohm 2 ani în urmă
părinte
comite
6f5beed879
4 a modificat fișierele cu 14 adăugiri și 7 ștergeri
  1. 11 3
      FactoryCraft/Chunk.cpp
  2. 1 0
      FactoryCraft/Chunk.h
  3. 1 1
      FactoryCraft/Constants.h
  4. 1 3
      FactoryCraft/Dimension.cpp

+ 11 - 3
FactoryCraft/Chunk.cpp

@@ -96,6 +96,7 @@ void Chunk::load(Framework::StreamReader* zReader)
     Framework::Vec3<int> pos = {0, 0, 0};
     unsigned short id;
     zReader->lese((char*)&id, 2);
+    int count = 0;
     while (id)
     {
         int index;
@@ -122,10 +123,12 @@ void Chunk::load(Framework::StreamReader* zReader)
                     visibleBlocks.add(b);
                 }
             }
+            count++;
             vcs.unlock();
         }
         zReader->lese((char*)&id, 2);
     }
+    std::cout << "Loaded " << count << " blocks\n";
     int index = 0;
     // light
     zReader->lese((char*)&index, 4);
@@ -609,7 +612,7 @@ void Chunk::setBlock(Block* block)
         vcs.lock();
         if (affectsGround || newAffectsGround)
         {
-            buildGroundModel();
+            modelChanged = 1;
         }
         if (block && block->isVisible() && !newAffectsGround)
         {
@@ -624,7 +627,7 @@ void Chunk::setBlock(Block* block)
     vcs.lock();
     if (affectsGround || newAffectsGround)
     {
-        buildGroundModel();
+        modelChanged = 1;
     }
     if (block && block->isVisible() && !newAffectsGround)
     {
@@ -663,7 +666,7 @@ void Chunk::removeBlock(Block* zBlock)
                                  .istGleich("cube");
         blocks[index]->release();
         blocks[index] = 0;
-        if (affectsGround) buildGroundModel();
+        if (affectsGround) modelChanged = 1;
     }
     cs.unlock();
 }
@@ -721,6 +724,11 @@ bool Chunk::tick(std::function<void(Model3D*)> f, double time)
 {
     acs.lock();
     vcs.lock(); // TODO: enshure no dead lock occures
+    if (modelChanged)
+    {
+        modelChanged = 0;
+		buildGroundModel();
+    }
     if (lightChanged)
     {
         lightChanged = 0;

+ 1 - 0
FactoryCraft/Chunk.h

@@ -35,6 +35,7 @@ private:
     Framework::Critical acs;
     Framework::RCArray<BlockAnimation> animations;
     bool lightChanged;
+    bool modelChanged;
 
     void appendAnimation(
         Block* zB, int boneId, double time, Vec3<float> pos, Vec3<float> rot);

+ 1 - 1
FactoryCraft/Constants.h

@@ -5,6 +5,6 @@
 #ifdef _DEBUG
 #    define CHUNK_VISIBILITY_RANGE 2
 #else
-#    define CHUNK_VISIBILITY_RANGE 6
+#    define CHUNK_VISIBILITY_RANGE 9
 #endif
 #define MAX_VIEW_DISTANCE      CHUNK_SIZE* CHUNK_VISIBILITY_RANGE

+ 1 - 3
FactoryCraft/Dimension.cpp

@@ -49,12 +49,10 @@ void Dimension::api(char* message)
         {
             int cX = *(int*)(message + 1);
             int cY = *(int*)(message + 5);
-            uiFactory.initParam.bildschirm->lock();
             cs.lock();
             Chunk* ch = zChunk(Punkt(cX, cY));
             if (ch) ch->api(message + 9);
             cs.unlock();
-            uiFactory.initParam.bildschirm->unlock();
             break;
         }
     case 2: // entity
@@ -88,11 +86,11 @@ void Dimension::api(char* message)
             ZeitMesser zm;
             zm.messungStart();
             World::INSTANCE->lockWorld();
-            cs.lock();
             Chunk* chunk = new Chunk(center, &reader);
             zm.messungEnde();
             std::cout << "chunk loading took " << zm.getSekunden()
                       << " seconds\n";
+            cs.lock();
             setChunk(chunk, center);
             cs.unlock();
             World::INSTANCE->unlockWorld();