Improve LOD saving logic

This commit is contained in:
James Seibel
2021-08-14 08:19:44 -05:00
parent f6daf62c7d
commit 5198335948
4 changed files with 29 additions and 3 deletions
@@ -364,7 +364,7 @@ public class LodQuadTree
lodNode.combineData(dataList);
// update sub regions if requested
if (lodNode.detailLevel < LodUtil.CHUNK_DETAIL_LEVEL && recursiveUpdate)
if (lodNode.detailLevel < LodUtil.REGION_DETAIL_LEVEL && recursiveUpdate)
{
this.parent.updateRegion(recursiveUpdate);
}
@@ -354,7 +354,6 @@ public class LodQuadTreeDimension
int xIndex = (regionPos.x - center.x) + halfWidth;
int zIndex = (regionPos.z - center.z) + halfWidth;
isRegionDirty[xIndex][zIndex] = true;
fileHandler.saveDirtyRegionsToFileAsync();
}
return nodeAdded;
}
@@ -551,6 +550,14 @@ public class LodQuadTreeDimension
return null;
}
/**
* Save all dirty regions in this LodDimension to file.
*/
public void saveDirtyRegionsToFileAsync()
{
fileHandler.saveDirtyRegionsToFileAsync();
}
/**
* Returns whether the region at the given X and Z coordinates
@@ -27,7 +27,7 @@ import net.minecraft.world.DimensionType;
*
* @author James Seibel
* @author Leonardo Amato
* @version 8-7-2021
* @version 8-14-2021
*/
public class LodQuadTreeWorld
{
@@ -120,6 +120,18 @@ public class LodQuadTreeWorld
lodDimensions.get(key).setRegionWidth(newWidth);
}
/**
* Requests all dimensions save any dirty regions they may have.
*/
public void saveAllDimensions()
{
if (lodDimensions == null)
throw new IllegalStateException("LodWorld hasn't been given a world yet.");
for (DimensionType key : lodDimensions.keySet())
lodDimensions.get(key).saveDirtyRegionsToFileAsync();
}
public boolean getIsWorldLoaded()
{
@@ -115,6 +115,7 @@ public class ClientProxy
if (xOffset != 0 || zOffset != 0)
{
lodWorld.saveAllDimensions();
lodDim.move(new RegionPos(xOffset, zOffset));
}
@@ -186,6 +187,12 @@ public class ClientProxy
lodNodeBuilder.generateLodNodeAsync(event.getChunk(), lodWorld, event.getWorld());
}
@SubscribeEvent
public void worldSaveEvent(WorldEvent.Save event)
{
if (lodWorld != null)
lodWorld.saveAllDimensions();
}
@SubscribeEvent
public void worldLoadEvent(WorldEvent.Load event)