ソースを参照

fix fluid flow caused huge lags

Kolja Strohm 9 ヶ月 前
コミット
1758c083f1
1 ファイル変更7 行追加15 行削除
  1. 7 15
      FactoryCraft/FluidBlock.cpp

+ 7 - 15
FactoryCraft/FluidBlock.cpp

@@ -89,6 +89,7 @@ void FluidBlock::doFlow()
     }
     bool changed = false;
     int minNeighborDistance = maxFlowDistance;
+    char nextFlowOptions = 0;
     for (int i = 0; i < 6; i++)
     {
         Direction dir = getDirectionFromIndex(i);
@@ -99,9 +100,7 @@ void FluidBlock::doFlow()
                 FluidBlock* neighbour
                     = dynamic_cast<FluidBlock*>(zNeighbours[i]);
                 minNeighborDistance = 0;
-                distanceToSource = neighbour->distanceToSource + 1;
-                flowOptions = (char)getOppositeDirection(dir);
-                changed = true;
+                nextFlowOptions = (char)getOppositeDirection(dir);
             }
             continue;
         }
@@ -144,21 +143,14 @@ void FluidBlock::doFlow()
             FluidBlock* neighbour = dynamic_cast<FluidBlock*>(zNeighbours[i]);
             if (neighbour)
             {
-                if (distanceToSource > neighbour->distanceToSource + 1)
-                {
-                    distanceToSource = neighbour->distanceToSource + 1;
-                    flowOptions = (char)getOppositeDirection(dir);
-                    changed = true;
-                }
-                else if (distanceToSource == neighbour->distanceToSource + 1)
-                {
-                    char tmp = flowOptions;
-                    flowOptions |= (char)getOppositeDirection(dir);
-                    changed |= tmp != flowOptions;
-                }
                 if (neighbour->distanceToSource < minNeighborDistance)
                 {
                     minNeighborDistance = neighbour->distanceToSource;
+                    nextFlowOptions = (char)getOppositeDirection(dir);
+                }
+                else if (neighbour->distanceToSource == minNeighborDistance)
+                {
+                    nextFlowOptions = (char)getOppositeDirection(dir);
                 }
             }
         }