something
This commit is contained in:
+2
-2
@@ -88,9 +88,9 @@ public class CompleteFullDataSource extends FullDataArrayAccessor implements IFu
|
||||
public FullDataSourceSummaryData readSourceSummaryInfo(FullDataMetaFile dataFile, DhDataInputStream inputStream, IDhLevel level) throws IOException
|
||||
{
|
||||
int dataDetail = inputStream.readInt();
|
||||
if (dataDetail != dataFile.baseMetaData.dataLevel)
|
||||
if (dataFile.baseMetaData != null && dataDetail != dataFile.baseMetaData.dataLevel)
|
||||
{
|
||||
throw new IOException(LodUtil.formatLog("Data level mismatch: "+dataDetail+" != "+dataFile.baseMetaData.dataLevel));
|
||||
throw new IOException(LodUtil.formatLog("Data level mismatch: " + dataDetail + " != " + dataFile.baseMetaData.dataLevel));
|
||||
}
|
||||
|
||||
int width = inputStream.readInt();
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ public class HighDetailIncompleteFullDataSource implements IIncompleteFullDataSo
|
||||
LodUtil.assertTrue(dataFile.pos.sectionDetailLevel <= MAX_SECTION_DETAIL);
|
||||
|
||||
int dataDetail = inputStream.readShort();
|
||||
if(dataDetail != dataFile.baseMetaData.dataLevel)
|
||||
if (dataFile.baseMetaData != null && dataDetail != dataFile.baseMetaData.dataLevel)
|
||||
{
|
||||
throw new IOException(LodUtil.formatLog("Data level mismatch: {} != {}", dataDetail, dataFile.baseMetaData.dataLevel));
|
||||
}
|
||||
|
||||
+2
-2
@@ -103,9 +103,9 @@ public class LowDetailIncompleteFullDataSource extends FullDataArrayAccessor imp
|
||||
public FullDataSourceSummaryData readSourceSummaryInfo(FullDataMetaFile dataFile, DhDataInputStream inputStream, IDhLevel level) throws IOException
|
||||
{
|
||||
int dataDetail = inputStream.readInt();
|
||||
if(dataDetail != dataFile.baseMetaData.dataLevel)
|
||||
if (dataFile.baseMetaData != null && dataDetail != dataFile.baseMetaData.dataLevel)
|
||||
{
|
||||
throw new IOException(LodUtil.formatLog("Data level mismatch: "+dataDetail+" != "+dataFile.baseMetaData.dataLevel));
|
||||
throw new IOException(LodUtil.formatLog("Data level mismatch: " + dataDetail + " != " + dataFile.baseMetaData.dataLevel));
|
||||
}
|
||||
|
||||
int width = inputStream.readInt();
|
||||
|
||||
+37
-28
@@ -10,6 +10,7 @@ import com.seibel.distanthorizons.core.network.messages.FullDataSourceRequestMes
|
||||
import com.seibel.distanthorizons.core.network.messages.FullDataSourceResponseMessage;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -34,34 +35,42 @@ public class RemoteFullDataFileHandler extends FullDataFileHandler
|
||||
|
||||
@Override
|
||||
public CompletableFuture<IFullDataSource> read(DhSectionPos pos) {
|
||||
return super.read(pos).thenCompose(fullDataSource -> {
|
||||
if (fullDataSource == null)
|
||||
return null;
|
||||
|
||||
if (!fullDataSource.isEmpty())
|
||||
return CompletableFuture.completedFuture(fullDataSource);
|
||||
|
||||
FullDataMetaFile metaFile = this.getLoadOrMakeFile(pos, true);
|
||||
totalRequests++;
|
||||
return networkClient.<FullDataSourceResponseMessage>sendRequest(new FullDataSourceRequestMessage(pos))
|
||||
.handle((response, throwable) -> {
|
||||
try
|
||||
{
|
||||
finishedRequests++;
|
||||
if (throwable != null)
|
||||
throw throwable;
|
||||
|
||||
LOGGER.info("FullDataSourceResponseMessage " + pos);
|
||||
return response.getFullDataSource(metaFile, level);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
failedRequests++;
|
||||
LOGGER.error(e);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
});
|
||||
FullDataMetaFile metaFile = this.getLoadOrMakeFile(pos, false);
|
||||
if (metaFile != null)
|
||||
{
|
||||
return super.read(pos).thenCompose(fullDataSource -> requestFromServer(pos, fullDataSource));
|
||||
}
|
||||
else
|
||||
{
|
||||
return requestFromServer(pos, null).thenCompose(fullDataSource -> fullDataSource != null
|
||||
? CompletableFuture.completedFuture(fullDataSource)
|
||||
: super.read(pos));
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private CompletableFuture<IFullDataSource> requestFromServer(DhSectionPos pos, IFullDataSource fullDataSource)
|
||||
{
|
||||
totalRequests++;
|
||||
return networkClient.<FullDataSourceResponseMessage>sendRequest(new FullDataSourceRequestMessage(pos))
|
||||
.handle((response, throwable) -> {
|
||||
try
|
||||
{
|
||||
finishedRequests++;
|
||||
if (throwable != null)
|
||||
throw throwable;
|
||||
|
||||
LOGGER.info("FullDataSourceResponseMessage " + pos);
|
||||
FullDataMetaFile metaFile = this.getLoadOrMakeFile(pos, true);
|
||||
return response.getFullDataSource(metaFile, level);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
failedRequests++;
|
||||
LOGGER.error("Error while fetching full data source", e);
|
||||
return fullDataSource;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String[] f3Log()
|
||||
|
||||
@@ -80,10 +80,14 @@ public class DhServerLevel extends DhLevel implements IDhServerLevel
|
||||
// stop world gen
|
||||
serverside.stopWorldGen();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void doWorldGen(DhBlockPos2D pos) {
|
||||
this.doWorldGen();
|
||||
|
||||
if (serverside.isWorldGenRunning())
|
||||
{
|
||||
serverside.worldGenTick(new DhBlockPos2D(0, 0)); // todo;
|
||||
serverside.worldGenTick(pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class ConfigBasedLogger
|
||||
else
|
||||
logger.log(logLevel, msgStr);
|
||||
}
|
||||
if (mode.levelForChat.isLessSpecificThan(level))
|
||||
if (MC != null && mode.levelForChat.isLessSpecificThan(level))
|
||||
{
|
||||
if (param.length > 0 && param[param.length - 1] instanceof Throwable)
|
||||
MC.logToChat(level, msgStr + "\n" +
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld
|
||||
{
|
||||
@@ -33,7 +34,8 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld
|
||||
private final NetworkServer networkServer;
|
||||
private final HashMap<UUID, RemotePlayer> playersByUUID;
|
||||
private final BiMap<ChannelHandlerContext, RemotePlayer> playersByConnection;
|
||||
|
||||
private final ConcurrentLinkedQueue<IServerPlayerWrapper> worldGenLoopingQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
|
||||
|
||||
public DhServerWorld()
|
||||
@@ -109,9 +111,11 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld
|
||||
public void addPlayer(IServerPlayerWrapper serverPlayer)
|
||||
{
|
||||
this.playersByUUID.put(serverPlayer.getUUID(), new RemotePlayer(serverPlayer));
|
||||
this.worldGenLoopingQueue.add(serverPlayer);
|
||||
}
|
||||
public void removePlayer(IServerPlayerWrapper serverPlayer)
|
||||
{
|
||||
this.worldGenLoopingQueue.remove(serverPlayer);
|
||||
RemotePlayer dhPlayer = this.playersByUUID.remove(serverPlayer.getUUID());
|
||||
ChannelHandlerContext channelContext = this.playersByConnection.inverse().remove(dhPlayer);
|
||||
if (channelContext != null)
|
||||
@@ -167,7 +171,19 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld
|
||||
|
||||
public void serverTick() { this.levels.values().forEach(DhServerLevel::serverTick); }
|
||||
|
||||
public void doWorldGen() { this.levels.values().forEach(DhServerLevel::doWorldGen); }
|
||||
public void doWorldGen() { this.levels.values().forEach(level -> {
|
||||
// TODO Deal with dimensions and dimension switches
|
||||
|
||||
IServerPlayerWrapper firstPlayer = this.worldGenLoopingQueue.poll();
|
||||
if (firstPlayer == null) {
|
||||
level.doWorldGen();
|
||||
return;
|
||||
}
|
||||
this.worldGenLoopingQueue.add(firstPlayer);
|
||||
|
||||
com.seibel.distanthorizons.coreapi.util.math.Vec3d position = firstPlayer.getPosition();
|
||||
level.doWorldGen(new DhBlockPos2D((int) position.x, (int) position.z));
|
||||
}); }
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> saveAndFlush()
|
||||
|
||||
+3
@@ -2,6 +2,7 @@ package com.seibel.distanthorizons.core.wrapperInterfaces.misc;
|
||||
|
||||
import com.seibel.distanthorizons.api.interfaces.IDhApiUnsafeWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.util.math.Vec3d;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -10,4 +11,6 @@ public interface IServerPlayerWrapper extends IDhApiUnsafeWrapper
|
||||
UUID getUUID();
|
||||
|
||||
IServerLevelWrapper getLevel();
|
||||
|
||||
Vec3d getPosition();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user