diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataFileHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataFileHandler.java index f4dfb459f..7819f7716 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataFileHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataFileHandler.java @@ -335,7 +335,7 @@ public class FullDataFileHandler implements IFullDataSourceProvider /** This call is concurrent. I.e. it supports multiple threads calling this method at the same time. */ @Override - public CompletableFuture flushAndSave() + public CompletableFuture flushAndSaveAsync() { ArrayList> futures = new ArrayList<>(); for (FullDataMetaFile metaFile : this.loadedMetaFileBySectionPos.values()) @@ -346,7 +346,7 @@ public class FullDataFileHandler implements IFullDataSourceProvider } @Override - public CompletableFuture flushAndSave(DhSectionPos sectionPos) + public CompletableFuture flushAndSaveAsync(DhSectionPos sectionPos) { FullDataMetaFile metaFile = this.loadedMetaFileBySectionPos.get(sectionPos); if (metaFile == null) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataFileHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataFileHandler.java index 50fe8bf96..5983c7314 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataFileHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataFileHandler.java @@ -130,7 +130,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandler metaFile.markNeedsUpdate(); }); - this.flushAndSave(); // Trigger an update to the meta files + this.flushAndSaveAsync(); // Trigger an update to the meta files } public void clearGenerationQueue() @@ -270,7 +270,18 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandler else if (genTaskResult.success) { // generation completed, update the files and listener(s) - this.flushAndSave(pos); + this.flushAndSaveAsync(pos).join(); + + // FIXME this is a bad fix to prevent full data sources saving incomplete, causing holes in the world after generation. + // The problem appears to be that the save may be happening too quickly, + // potentially happening before the meta file has the newly generated data added to it. + new Thread(() -> + { + try{ Thread.sleep(4000); }catch (InterruptedException e){} + + this.flushAndSaveAsync(pos).join(); + }).start(); + this.fireOnGenPosSuccessListeners(pos); return; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/IFullDataSourceProvider.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/IFullDataSourceProvider.java index 85e6b22ad..13f8e8fbe 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/IFullDataSourceProvider.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/IFullDataSourceProvider.java @@ -32,8 +32,8 @@ public interface IFullDataSourceProvider extends AutoCloseable { CompletableFuture readAsync(DhSectionPos pos); void writeChunkDataToFile(DhSectionPos sectionPos, ChunkSizedFullDataAccessor chunkData); - CompletableFuture flushAndSave(); - CompletableFuture flushAndSave(DhSectionPos sectionPos); + CompletableFuture flushAndSaveAsync(); + CompletableFuture flushAndSaveAsync(DhSectionPos sectionPos); //long getCacheVersion(DhSectionPos sectionPos); //boolean isCacheVersionValid(DhSectionPos sectionPos, long cacheVersion); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientLevel.java b/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientLevel.java index 316189645..1bacd0eaf 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientLevel.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientLevel.java @@ -20,7 +20,6 @@ package com.seibel.distanthorizons.core.level; import com.seibel.distanthorizons.core.dataObjects.fullData.accessor.ChunkSizedFullDataAccessor; -import com.seibel.distanthorizons.core.file.fullDatafile.FullDataFileHandler; import com.seibel.distanthorizons.core.file.fullDatafile.IFullDataSourceProvider; import com.seibel.distanthorizons.core.file.fullDatafile.RemoteFullDataFileHandler; import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure; @@ -112,7 +111,7 @@ public class DhClientLevel extends DhLevel implements IDhClientLevel @Override public CompletableFuture saveAsync() { - return CompletableFuture.allOf(clientside.saveAsync(), dataFileHandler.flushAndSave()); + return CompletableFuture.allOf(clientside.saveAsync(), dataFileHandler.flushAndSaveAsync()); } @Override diff --git a/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientServerLevel.java b/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientServerLevel.java index 3f098d7f0..1edae45a5 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientServerLevel.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientServerLevel.java @@ -183,7 +183,7 @@ public class DhClientServerLevel extends DhLevel implements IDhClientLevel, IDhS @Override public CompletableFuture saveAsync() { - return CompletableFuture.allOf(clientside.saveAsync(), getFileHandler().flushAndSave()); + return CompletableFuture.allOf(clientside.saveAsync(), getFileHandler().flushAndSaveAsync()); } //===============// diff --git a/core/src/main/java/com/seibel/distanthorizons/core/level/DhServerLevel.java b/core/src/main/java/com/seibel/distanthorizons/core/level/DhServerLevel.java index 1cf9d9d98..dd9bb218f 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/level/DhServerLevel.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/level/DhServerLevel.java @@ -24,7 +24,6 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.CompleteFull import com.seibel.distanthorizons.core.file.fullDatafile.IFullDataSourceProvider; import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure; import com.seibel.distanthorizons.core.pos.DhBlockPos2D; -import com.seibel.distanthorizons.core.pos.DhLodPos; import com.seibel.distanthorizons.core.pos.DhSectionPos; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; @@ -75,7 +74,7 @@ public class DhServerLevel extends DhLevel implements IDhServerLevel } @Override - public CompletableFuture saveAsync() { return getFileHandler().flushAndSave(); } + public CompletableFuture saveAsync() { return getFileHandler().flushAndSaveAsync(); } @Override public void doWorldGen()