Rename IWorldGenerationQueue -> IFullDataSourceRetrievalQueue

This commit is contained in:
James Seibel
2024-03-17 16:46:56 -05:00
parent 569a4b16b4
commit bf00a23499
4 changed files with 78 additions and 26 deletions
@@ -23,7 +23,7 @@ import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGeneratio
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
import com.seibel.distanthorizons.core.generation.IWorldGenerationQueue;
import com.seibel.distanthorizons.core.generation.IFullDataSourceRetrievalQueue;
import com.seibel.distanthorizons.core.generation.tasks.IWorldGenTaskTracker;
import com.seibel.distanthorizons.core.generation.tasks.WorldGenResult;
import com.seibel.distanthorizons.core.level.IDhLevel;
@@ -50,7 +50,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandlerV2 implemen
public static final int MAX_WORLD_GEN_REQUESTS_PER_THREAD = 20;
private final AtomicReference<IWorldGenerationQueue> worldGenQueueRef = new AtomicReference<>(null);
private final AtomicReference<IFullDataSourceRetrievalQueue> worldGenQueueRef = new AtomicReference<>(null);
private final ArrayList<IOnWorldGenCompleteListener> onWorldGenTaskCompleteListeners = new ArrayList<>();
protected final DelayedFullDataSourceSaveCache delayedFullDataSourceSaveCache = new DelayedFullDataSourceSaveCache(this::onDataSourceSave, 5_000);
@@ -73,7 +73,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandlerV2 implemen
* Assigns the queue for handling world gen and does first time setup as well. <br>
* Assumes there isn't a pre-existing queue.
*/
public void setWorldGenerationQueue(IWorldGenerationQueue newWorldGenQueue)
public void setWorldGenerationQueue(IFullDataSourceRetrievalQueue newWorldGenQueue)
{
boolean oldQueueExists = this.worldGenQueueRef.compareAndSet(null, newWorldGenQueue);
LodUtil.assertTrue(oldQueueExists, "previous world gen queue is still here!");
@@ -87,7 +87,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandlerV2 implemen
{
// TODO there has to be a better way to do this
IWorldGenerationQueue worldGenQueue = this.worldGenQueueRef.get();
IFullDataSourceRetrievalQueue worldGenQueue = this.worldGenQueueRef.get();
if (worldGenQueue != null)
{
worldGenQueue.removeGenRequestIf(removeIf);
@@ -163,7 +163,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandlerV2 implemen
@Override
public void setTotalRetrievalPositionCount(int newCount)
{
IWorldGenerationQueue worldGenQueue = this.worldGenQueueRef.get();
IFullDataSourceRetrievalQueue worldGenQueue = this.worldGenQueueRef.get();
if (worldGenQueue != null)
{
worldGenQueue.setEstimatedTotalTaskCount(newCount);
@@ -179,7 +179,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandlerV2 implemen
}
IWorldGenerationQueue worldGenQueue = this.worldGenQueueRef.get();
IFullDataSourceRetrievalQueue worldGenQueue = this.worldGenQueueRef.get();
if (worldGenQueue == null)
{
// we can't queue anything if the world generator isn't set up yet
@@ -203,7 +203,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandlerV2 implemen
@Override
public boolean queuePositionForRetrieval(DhSectionPos genPos)
{
IWorldGenerationQueue worldGenQueue = this.worldGenQueueRef.get();
IFullDataSourceRetrievalQueue worldGenQueue = this.worldGenQueueRef.get();
if (worldGenQueue == null)
{
return false;
@@ -219,7 +219,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandlerV2 implemen
@Override
public ArrayList<DhSectionPos> getPositionsToRetrieve(DhSectionPos pos)
{
IWorldGenerationQueue worldGenQueue = this.worldGenQueueRef.get();
IFullDataSourceRetrievalQueue worldGenQueue = this.worldGenQueueRef.get();
if (worldGenQueue == null)
{
return null;
@@ -288,7 +288,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandlerV2 implemen
@Override
public int getMaxPossibleRetrievalPositionCountForPos(DhSectionPos pos)
{
IWorldGenerationQueue worldGenQueue = this.worldGenQueueRef.get();
IFullDataSourceRetrievalQueue worldGenQueue = this.worldGenQueueRef.get();
if (worldGenQueue == null)
{
return -1;
@@ -23,24 +23,80 @@ import com.seibel.distanthorizons.core.generation.tasks.IWorldGenTaskTracker;
import com.seibel.distanthorizons.core.generation.tasks.WorldGenResult;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.render.LodQuadTree;
import java.io.Closeable;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
// TODO This doesn't need an interface, remove the interface
@Deprecated
public interface IWorldGenerationQueue extends Closeable
/**
* Used to track what full data sources the system currently
* wants but doesn't have. <br>
* IE, what sections should be generated via the world generator. <br><br>
*
* Note: <br>
* This won't contain every position that needs to be retrieved
* (due to causing issues at extreme render distances).
* TODO does that mean this object isn't necessary or
* should just be renamed since it isn't the full queue <br><br>
*
* Use by both world gen and server networking.
*
* @see LodQuadTree
*/
public interface IFullDataSourceRetrievalQueue extends Closeable
{
//=========//
// getters //
//=========//
/** the largest numerical detail level */
byte lowestDataDetail();
/** the smallest numerical detail level */
byte highestDataDetail();
//=======//
// setup //
//=======//
/**
* Starts the retrieval process if not already running,
* and if running updates the target position.
*
* @param targetPos the position that retrieval should be centered around,
* generally this will be the player's position.
* */
void startAndSetTargetPos(DhBlockPos2D targetPos);
//===============//
// task handling //
//===============//
/** @deprecated replace with {@link IFullDataSourceRetrievalQueue#removeGenTask(DhSectionPos)} */
@Deprecated
void removeGenRequestIf(Function<DhSectionPos, Boolean> removeIf);
void removeGenTask(DhSectionPos pos);
CompletableFuture<WorldGenResult> submitGenTask(DhSectionPos pos, byte requiredDataDetail, IWorldGenTaskTracker tracker);
/** @param targetPos the position that world generation should be centered around, generally this will be the player's position. */
void startGenerationQueueAndSetTargetPos(DhBlockPos2D targetPos);
//==========//
// shutdown //
//==========//
CompletableFuture<Void> startClosing(boolean cancelCurrentGeneration, boolean alsoInterruptRunning);
void close();
//===============//
// debug display //
//===============//
int getWaitingTaskCount();
int getInProgressTaskCount();
@@ -49,11 +105,5 @@ public interface IWorldGenerationQueue extends Closeable
int getEstimatedTotalTaskCount();
void setEstimatedTotalTaskCount(int newEstimate);
CompletableFuture<Void> startClosing(boolean cancelCurrentGeneration, boolean alsoInterruptRunning);
void close();
void removeGenRequestIf(Function<DhSectionPos, Boolean> removeIf);
void removeGenTask(DhSectionPos pos);
}
@@ -49,7 +49,7 @@ import java.util.concurrent.*;
import java.util.function.Consumer;
import java.util.function.Function;
public class WorldGenerationQueue implements IWorldGenerationQueue, IDebugRenderable
public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDebugRenderable
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
private static final IWrapperFactory WRAPPER_FACTORY = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
@@ -187,7 +187,8 @@ public class WorldGenerationQueue implements IWorldGenerationQueue, IDebugRender
// running tasks //
//===============//
public void startGenerationQueueAndSetTargetPos(DhBlockPos2D targetPos)
@Override
public void startAndSetTargetPos(DhBlockPos2D targetPos)
{
// update the target pos
this.generationTargetPos = targetPos;
@@ -20,7 +20,7 @@
package com.seibel.distanthorizons.core.level;
import com.seibel.distanthorizons.core.file.fullDatafile.GeneratedFullDataFileHandler;
import com.seibel.distanthorizons.core.generation.IWorldGenerationQueue;
import com.seibel.distanthorizons.core.generation.IFullDataSourceRetrievalQueue;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
@@ -156,10 +156,10 @@ public class WorldGenModule implements Closeable
// helper classes //
//================//
/** Handles the {@link IWorldGenerationQueue} and any other necessary world gen information. */
/** Handles the {@link IFullDataSourceRetrievalQueue} and any other necessary world gen information. */
public static abstract class AbstractWorldGenState
{
public IWorldGenerationQueue worldGenerationQueue;
public IFullDataSourceRetrievalQueue worldGenerationQueue;
CompletableFuture<Void> closeAsync(boolean doInterrupt)
{
@@ -178,7 +178,8 @@ public class WorldGenModule implements Closeable
}
/** @param targetPosForGeneration the position that world generation should be centered around */
public void startGenerationQueueAndSetTargetPos(DhBlockPos2D targetPosForGeneration) { this.worldGenerationQueue.startGenerationQueueAndSetTargetPos(targetPosForGeneration); }
public void startGenerationQueueAndSetTargetPos(DhBlockPos2D targetPosForGeneration)
{ this.worldGenerationQueue.startAndSetTargetPos(targetPosForGeneration); }
}
}