Make generation limit work

This commit is contained in:
s809
2024-11-22 00:16:30 +05:00
parent cf5ba685f4
commit b59965671c
4 changed files with 52 additions and 11 deletions
@@ -22,10 +22,11 @@ package com.seibel.distanthorizons.core.file.fullDatafile;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.file.structure.ISaveStructure;
import com.seibel.distanthorizons.core.generation.RemoteWorldRetrievalQueue;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.level.IDhClientLevel;
import com.seibel.distanthorizons.core.level.WorldGenModule;
import com.seibel.distanthorizons.core.multiplayer.client.SyncOnLoadRequestQueue;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
import org.jetbrains.annotations.Nullable;
@@ -51,7 +52,7 @@ public class RemoteFullDataSourceProvider extends GeneratedFullDataSourceProvide
//=============//
public RemoteFullDataSourceProvider(
IDhLevel level, ISaveStructure saveStructure, @Nullable File saveDirOverride,
IDhClientLevel level, ISaveStructure saveStructure, @Nullable File saveDirOverride,
@Nullable SyncOnLoadRequestQueue syncOnLoadRequestQueue)
{
super(level, saveStructure, saveDirOverride);
@@ -59,6 +60,24 @@ public class RemoteFullDataSourceProvider extends GeneratedFullDataSourceProvide
}
@Override
public boolean queuePositionForRetrieval(Long genPos)
{
if (this.syncOnLoadRequestQueue == null)
{
return super.queuePositionForRetrieval(genPos);
}
int maxGenerationRequestDistance = this.syncOnLoadRequestQueue.networkState.sessionConfig.getMaxGenerationRequestDistance();
DhBlockPos2D targetPos = this.level.getTargetPosForGeneration();
if (targetPos == null || DhSectionPos.getChebyshevSignedBlockDistance(genPos, targetPos) / 16 > maxGenerationRequestDistance)
{
return false;
}
return super.queuePositionForRetrieval(genPos);
}
//==================//
// override methods //
@@ -98,6 +117,13 @@ public class RemoteFullDataSourceProvider extends GeneratedFullDataSourceProvide
DhSectionPos.forEachChildAtDetailLevel(pos, DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL, childPos ->
{
int maxSyncOnLoadDistance = this.syncOnLoadRequestQueue.networkState.sessionConfig.getMaxSyncOnLoadDistance();
DhBlockPos2D targetPos = this.level.getTargetPosForGeneration();
if (targetPos == null || DhSectionPos.getChebyshevSignedBlockDistance(childPos, targetPos) / 16 > maxSyncOnLoadDistance)
{
return;
}
if (!this.visitedPositions.add(childPos))
{
return;
@@ -196,20 +196,25 @@ public abstract class AbstractDhServerLevel extends AbstractDhLevel implements I
Vec3d playerPosition = serverPlayerState.getServerPlayer().getPosition();
int distanceFromPlayer = DhSectionPos.getChebyshevSignedBlockDistance(message.sectionPos, new DhBlockPos2D((int) playerPosition.x, (int) playerPosition.z)) / 16;
if (distanceFromPlayer > Config.Server.maxGenerationRequestDistance.get())
{
message.sendResponse(new RequestOutOfRangeException("Distance too large: " + distanceFromPlayer + " > " + Config.Server.maxGenerationRequestDistance.get()));
return;
}
ServerPlayerState.RateLimiterSet rateLimiterSet = serverPlayerState.getRateLimiterSet(this);
if (message.clientTimestamp == null)
{
if (distanceFromPlayer > Config.Server.maxGenerationRequestDistance.get())
{
message.sendResponse(new RequestOutOfRangeException("Distance too large: " + distanceFromPlayer + " > " + Config.Server.maxGenerationRequestDistance.get()));
return;
}
this.queueWorldGenForRequestMessage(serverPlayerState, message, rateLimiterSet);
}
else
{
if (distanceFromPlayer > Config.Server.maxSyncOnLoadRequestDistance.get())
{
message.sendResponse(new RequestOutOfRangeException("Distance too large: " + distanceFromPlayer + " > " + Config.Server.maxSyncOnLoadRequestDistance.get()));
return;
}
this.queueLodSyncForRequestMessage(serverPlayerState, message, rateLimiterSet);
}
});
@@ -118,6 +118,11 @@ public abstract class AbstractFullDataNetworkRequestQueue implements IDebugRende
{
this.waitingTasksBySectionPos.remove(sectionPos);
if (throwable instanceof CancellationException)
{
return;
}
this.finishedRequests.incrementAndGet();
if (!success || throwable != null)
{
@@ -163,7 +168,6 @@ public abstract class AbstractFullDataNetworkRequestQueue implements IDebugRende
{
Map.Entry<Long, RequestQueueEntry> mapEntry = this.waitingTasksBySectionPos.entrySet().stream()
.filter(task -> task.getValue().networkDataSourceFuture == null)
.filter(task -> DhSectionPos.getChebyshevSignedBlockDistance(task.getKey(), targetPos) <= this.getMaxRequestDistance())
.min(Comparator.comparingInt(task -> DhSectionPos.getChebyshevSignedBlockDistance(task.getKey(), targetPos)))
.orElse(null);
@@ -176,6 +180,13 @@ public abstract class AbstractFullDataNetworkRequestQueue implements IDebugRende
long sectionPos = mapEntry.getKey();
RequestQueueEntry entry = mapEntry.getValue();
if (DhSectionPos.getChebyshevSignedBlockDistance(sectionPos, targetPos) > this.getMaxRequestDistance() * 16)
{
entry.future.cancel(false);
this.pendingTasksSemaphore.release();
return;
}
Long offsetEntryTimestamp = entry.updateTimestamp != null
? entry.updateTimestamp + this.networkState.getServerTimeOffset()
: null;
@@ -365,8 +376,8 @@ public abstract class AbstractFullDataNetworkRequestQueue implements IDebugRende
{
renderer.renderBox(new DebugRenderer.Box(mapEntry.getKey(), -32f, 64f, 0.05f,
mapEntry.getValue().networkDataSourceFuture != null ? Color.red
: DhSectionPos.getChebyshevSignedBlockDistance(mapEntry.getKey(), this.lastTargetPos) <= this.getMaxRequestDistance() ? Color.gray
: Color.lightGray
: DhSectionPos.getChebyshevSignedBlockDistance(mapEntry.getKey(), this.lastTargetPos) <= this.getMaxRequestDistance() * 16 ? Color.gray
: Color.darkGray
));
}
}
@@ -490,7 +490,6 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
{
// shouldn't normally happen, but just in case
this.missingGenerationPos.add(pos);
break;
}
}
}