Got chunks to generate on server

This commit is contained in:
s809
2023-07-23 20:34:40 +05:00
parent d29ba9d423
commit d7ef6c8a72
15 changed files with 101 additions and 72 deletions
@@ -7,6 +7,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrappe
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
import com.seibel.distanthorizons.core.util.objects.dataStreams.*;
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import java.io.*;
import java.util.ArrayList;
@@ -86,25 +87,25 @@ public class FullDataPointIdMap
}
/** Serializes all contained entries into the given stream, formatted in UTF */
public void serialize(DhDataOutputStream outputStream) throws IOException
public void serialize(DhDataOutputStream outputStream, ILevelWrapper levelWrapper) throws IOException
{
lock.readLock().lock();
outputStream.writeInt(this.entries.size());
for (Entry entry : this.entries)
{
outputStream.writeUTF(entry.serialize());
outputStream.writeUTF(entry.serialize(levelWrapper));
}
lock.readLock().unlock();
}
/** Creates a new IdBiomeBlockStateMap from the given UTF formatted stream */
public static FullDataPointIdMap deserialize(DhDataInputStream inputStream) throws IOException, InterruptedException
public static FullDataPointIdMap deserialize(DhDataInputStream inputStream, ILevelWrapper levelWrapper) throws IOException, InterruptedException
{
int entityCount = inputStream.readInt();
FullDataPointIdMap newMap = new FullDataPointIdMap();
for (int i = 0; i < entityCount; i++)
{
newMap.entries.add(Entry.deserialize(inputStream.readUTF()));
newMap.entries.add(Entry.deserialize(inputStream.readUTF(), levelWrapper));
}
return newMap;
}
@@ -160,9 +161,9 @@ public class FullDataPointIdMap
}
public String serialize() { return this.biome.serialize() + SEPARATOR_STRING + this.blockState.serialize(); }
public String serialize(ILevelWrapper levelWrapper) { return this.biome.serialize(levelWrapper) + SEPARATOR_STRING + this.blockState.serialize(); }
public static Entry deserialize(String str) throws IOException, InterruptedException
public static Entry deserialize(String str, ILevelWrapper levelWrapper) throws IOException, InterruptedException
{
String[] stringArray = str.split(SEPARATOR_STRING);
if (stringArray.length != 2)
@@ -176,7 +177,7 @@ public class FullDataPointIdMap
throw new InterruptedException(FullDataPointIdMap.class.getSimpleName()+" task interrupted.");
}
IBiomeWrapper biome = WRAPPER_FACTORY.deserializeBiomeWrapper(stringArray[0]);
IBiomeWrapper biome = WRAPPER_FACTORY.deserializeBiomeWrapper(stringArray[0], levelWrapper);
IBlockStateWrapper blockState = WRAPPER_FACTORY.deserializeBlockStateWrapper(stringArray[1]);
return new Entry(biome, blockState);
}
@@ -17,6 +17,7 @@ import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataOutputStream;
import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
import org.apache.logging.log4j.Logger;
@@ -226,14 +227,14 @@ public class CompleteFullDataSource extends FullDataArrayAccessor implements IFu
@Override
public void writeIdMappings(DhDataOutputStream outputStream) throws IOException
public void writeIdMappings(DhDataOutputStream outputStream, ILevelWrapper levelWrapper) throws IOException
{
outputStream.writeInt(IFullDataSource.DATA_GUARD_BYTE);
this.mapping.serialize(outputStream);
this.mapping.serialize(outputStream, levelWrapper);
}
@Override
public FullDataPointIdMap readIdMappings(long[][] dataPoints, DhDataInputStream inputStream) throws IOException, InterruptedException
public FullDataPointIdMap readIdMappings(long[][] dataPoints, DhDataInputStream inputStream, ILevelWrapper levelWrapper) throws IOException, InterruptedException
{
int guardByte = inputStream.readInt();
if (guardByte != IFullDataSource.DATA_GUARD_BYTE)
@@ -241,7 +242,7 @@ public class CompleteFullDataSource extends FullDataArrayAccessor implements IFu
throw new IOException("Invalid data content end guard for ID mapping");
}
return FullDataPointIdMap.deserialize(inputStream);
return FullDataPointIdMap.deserialize(inputStream, levelWrapper);
}
@Override
public void setIdMapping(FullDataPointIdMap mappings) { this.mapping.mergeAndReturnRemappedEntityIds(mappings); }
@@ -17,6 +17,7 @@ import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataOutputStream;
import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
import org.apache.logging.log4j.Logger;
@@ -350,14 +351,14 @@ public class HighDetailIncompleteFullDataSource implements IIncompleteFullDataSo
@Override
public void writeIdMappings(DhDataOutputStream dataOutputStream) throws IOException
public void writeIdMappings(DhDataOutputStream dataOutputStream, ILevelWrapper levelWrapper) throws IOException
{
dataOutputStream.writeInt(IFullDataSource.DATA_GUARD_BYTE);
this.mapping.serialize(dataOutputStream);
this.mapping.serialize(dataOutputStream, levelWrapper);
}
@Override
public FullDataPointIdMap readIdMappings(long[][][] dataPoints, DhDataInputStream inputStream) throws IOException, InterruptedException
public FullDataPointIdMap readIdMappings(long[][][] dataPoints, DhDataInputStream inputStream, ILevelWrapper levelWrapper) throws IOException, InterruptedException
{
// mark the start of the ID data
int idMappingStartByte = inputStream.readInt();
@@ -368,7 +369,7 @@ public class HighDetailIncompleteFullDataSource implements IIncompleteFullDataSo
}
// deserialize the ID data
return FullDataPointIdMap.deserialize(inputStream);
return FullDataPointIdMap.deserialize(inputStream, levelWrapper);
}
@Override
public void setIdMapping(FullDataPointIdMap mappings) { this.mapping.mergeAndReturnRemappedEntityIds(mappings); }
@@ -17,6 +17,7 @@ import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataOutputStream;
import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
import org.apache.logging.log4j.Logger;
@@ -237,14 +238,14 @@ public class LowDetailIncompleteFullDataSource extends FullDataArrayAccessor imp
@Override
public void writeIdMappings(DhDataOutputStream outputStream) throws IOException
public void writeIdMappings(DhDataOutputStream outputStream, ILevelWrapper levelWrapper) throws IOException
{
outputStream.writeInt(IFullDataSource.DATA_GUARD_BYTE);
this.mapping.serialize(outputStream);
this.mapping.serialize(outputStream, levelWrapper);
}
@Override
public FullDataPointIdMap readIdMappings(StreamDataPointContainer streamDataPointContainer, DhDataInputStream inputStream) throws IOException, InterruptedException
public FullDataPointIdMap readIdMappings(StreamDataPointContainer streamDataPointContainer, DhDataInputStream inputStream, ILevelWrapper levelWrapper) throws IOException, InterruptedException
{
// Id mapping
int dataPresentFlag = inputStream.readInt();
@@ -252,7 +253,7 @@ public class LowDetailIncompleteFullDataSource extends FullDataArrayAccessor imp
{
throw new IOException("invalid ID mapping end guard");
}
return FullDataPointIdMap.deserialize(inputStream);
return FullDataPointIdMap.deserialize(inputStream, levelWrapper);
}
@Override
public void setIdMapping(FullDataPointIdMap mappings) { this.mapping.mergeAndReturnRemappedEntityIds(mappings); }
@@ -8,6 +8,7 @@ import com.seibel.distanthorizons.core.file.fullDatafile.FullDataMetaFile;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataOutputStream;
import com.seibel.distanthorizons.core.util.objects.dataStreams.*;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import java.io.IOException;
@@ -55,7 +56,7 @@ public interface IStreamableFullDataSource<SummaryDataType extends IStreamableFu
this.setDataPoints(dataPoints);
FullDataPointIdMap mapping = this.readIdMappings(dataPoints, inputStream);
FullDataPointIdMap mapping = this.readIdMappings(dataPoints, inputStream, level.getLevelWrapper());
this.setIdMapping(mapping);
}
@@ -70,7 +71,7 @@ public interface IStreamableFullDataSource<SummaryDataType extends IStreamableFu
return;
}
this.writeIdMappings(outputStream);
this.writeIdMappings(outputStream, level.getLevelWrapper());
}
@@ -96,8 +97,8 @@ public interface IStreamableFullDataSource<SummaryDataType extends IStreamableFu
void setDataPoints(DataContainerType dataPoints);
void writeIdMappings(DhDataOutputStream outputStream) throws IOException;
FullDataPointIdMap readIdMappings(DataContainerType dataPoints, DhDataInputStream inputStream) throws IOException, InterruptedException;
void writeIdMappings(DhDataOutputStream outputStream, ILevelWrapper levelWrapper) throws IOException;
FullDataPointIdMap readIdMappings(DataContainerType dataPoints, DhDataInputStream inputStream, ILevelWrapper levelWrapper) throws IOException, InterruptedException;
void setIdMapping(FullDataPointIdMap mappings);
@@ -80,7 +80,7 @@ public class ChunkToLodBuilder implements AutoCloseable
{
return;
}
else if (MC == null || !MC.playerExists())
else if (MC != null && !MC.playerExists())
{
// TODO handle server side properly
@@ -4,14 +4,12 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.interfaces.I
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.network.ChildNetworkEventSource;
import com.seibel.distanthorizons.core.network.NetworkClient;
import com.seibel.distanthorizons.core.network.messages.ChunkRequestMessage;
import com.seibel.distanthorizons.core.network.messages.ChunkResponseMessage;
import com.seibel.distanthorizons.core.network.messages.FullDataSourceRequestMessage;
import com.seibel.distanthorizons.core.network.messages.FullDataSourceResponseMessage;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import org.apache.logging.log4j.Logger;
import java.nio.file.FileAlreadyExistsException;
import java.util.concurrent.CompletableFuture;
public class RemoteFullDataFileHandler extends FullDataFileHandler
@@ -29,7 +27,7 @@ public class RemoteFullDataFileHandler extends FullDataFileHandler
public CompletableFuture<IFullDataSource> read(DhSectionPos pos) {
// TODO: LOD data file updating is probably incomplete
return super.read(pos).thenCompose((fullDataSource) -> {
CompletableFuture<ChunkResponseMessage> responseFuture = networkClient.<ChunkResponseMessage>sendRequest(new ChunkRequestMessage(pos))
CompletableFuture<FullDataSourceResponseMessage> responseFuture = networkClient.<FullDataSourceResponseMessage>sendRequest(new FullDataSourceRequestMessage(pos))
.exceptionally(throwable -> {
LOGGER.error(throwable);
return null;
@@ -1,21 +0,0 @@
package com.seibel.distanthorizons.core.network.messages;
import com.seibel.distanthorizons.core.network.protocol.FutureTrackableNetworkMessage;
import com.seibel.distanthorizons.core.network.protocol.INetworkObject;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import io.netty.buffer.ByteBuf;
public class ChunkResponseMessage extends FutureTrackableNetworkMessage
{
public ChunkResponseMessage() {}
@Override
public void encode0(ByteBuf out)
{
}
@Override
public void decode0(ByteBuf in)
{
}
}
@@ -5,13 +5,13 @@ import com.seibel.distanthorizons.core.network.protocol.INetworkObject;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import io.netty.buffer.ByteBuf;
public class ChunkRequestMessage extends FutureTrackableNetworkMessage
public class FullDataSourceRequestMessage extends FutureTrackableNetworkMessage
{
public DhSectionPos dhSectionPos;
public ChunkRequestMessage() {}
public FullDataSourceRequestMessage() {}
public ChunkRequestMessage(DhSectionPos dhSectionPos) {
public FullDataSourceRequestMessage(DhSectionPos dhSectionPos) {
this.dhSectionPos = dhSectionPos;
}
@@ -0,0 +1,34 @@
package com.seibel.distanthorizons.core.network.messages;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.interfaces.IFullDataSource;
import com.seibel.distanthorizons.core.level.DhServerLevel;
import com.seibel.distanthorizons.core.network.protocol.FutureTrackableNetworkMessage;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
public class FullDataSourceResponseMessage extends FutureTrackableNetworkMessage
{
public IFullDataSource fullDataSource;
public DhServerLevel level;
public FullDataSourceResponseMessage() {}
public FullDataSourceResponseMessage(IFullDataSource fullDataSource, DhServerLevel level)
{
this.fullDataSource = fullDataSource;
this.level = level;
}
@Override
public void encode0(ByteBuf out) throws IOException
{
//fullDataSource.writeToStream(new DhDataOutputStream(new ByteBufOutputStream(out)), level);
}
@Override
public void decode0(ByteBuf in)
{
//DhSectionPos sectionPos = INetworkObject.decode(new DhSectionPos((byte) 0, (byte) 0, (byte) 0), in);
//fullDataSource = HighDetailIncompleteFullDataSource.createEmpty(sectionPos);
}
}
@@ -15,16 +15,30 @@ public abstract class FutureTrackableNetworkMessage implements INetworkMessage
@Override public final void encode(ByteBuf out)
{
out.writeInt(futureId);
this.encode0(out);
try
{
out.writeInt(futureId);
this.encode0(out);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
@Override public final void decode(ByteBuf in)
{
futureId = in.readInt();
this.decode0(in);
try
{
futureId = in.readInt();
this.decode0(in);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
protected abstract void encode0(ByteBuf out);
protected abstract void decode0(ByteBuf in);
protected abstract void encode0(ByteBuf out) throws Exception;
protected abstract void decode0(ByteBuf in) throws Exception;
}
@@ -29,8 +29,8 @@ public class MessageRegistry
this.registerMessage(AckMessage.class, AckMessage::new);
this.registerMessage(PlayerUUIDMessage.class, PlayerUUIDMessage::new);
this.registerMessage(RemotePlayerConfigMessage.class, RemotePlayerConfigMessage::new);
this.registerMessage(ChunkRequestMessage.class, ChunkRequestMessage::new);
this.registerMessage(ChunkResponseMessage.class, ChunkResponseMessage::new);
this.registerMessage(FullDataSourceRequestMessage.class, FullDataSourceRequestMessage::new);
this.registerMessage(FullDataSourceResponseMessage.class, FullDataSourceResponseMessage::new);
}
@@ -2,25 +2,21 @@ package com.seibel.distanthorizons.core.world;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataMetaFile;
import com.seibel.distanthorizons.core.file.fullDatafile.IFullDataSourceProvider;
import com.seibel.distanthorizons.core.file.structure.LocalSaveStructure;
import com.seibel.distanthorizons.core.level.DhServerLevel;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.network.NetworkServer;
import com.seibel.distanthorizons.core.network.messages.*;
import com.seibel.distanthorizons.core.network.messages.ChunkRequestMessage;
import com.seibel.distanthorizons.core.network.objects.RemotePlayer;
import com.seibel.distanthorizons.core.network.protocol.FutureTrackableNetworkMessage;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
import io.netty.channel.ChannelHandlerContext;
import java.io.File;
import java.nio.file.FileAlreadyExistsException;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -91,7 +87,7 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld
channelContext.writeAndFlush(new AckMessage(RemotePlayerConfigMessage.class));
});
this.networkServer.registerHandler(ChunkRequestMessage.class, (msg, ctx) ->
this.networkServer.registerHandler(FullDataSourceRequestMessage.class, (msg, ctx) ->
{
if (msg.dhSectionPos == null) {
LOGGER.warn("RequestChunksMessage received with null msg.dhSectionPos");
@@ -107,9 +103,11 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld
// TODO: Add level to packet
level.serverside.worldGenTick(new DhBlockPos2D(msg.dhSectionPos.sectionX, msg.dhSectionPos.sectionZ));
// Send chunk response message back
ctx.writeAndFlush(FutureTrackableNetworkMessage.makeResponse(msg, new ChunkResponseMessage()));
level.serverside.dataFileHandler.read(msg.dhSectionPos).thenAccept(fullDataSource -> {
// Send chunk response message back
ctx.writeAndFlush(FutureTrackableNetworkMessage.makeResponse(msg, new FullDataSourceResponseMessage(fullDataSource, level)));
});
});
}
@@ -23,6 +23,7 @@ import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvironmentWrapper;
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
@@ -37,7 +38,7 @@ import java.io.IOException;
public interface IWrapperFactory extends IBindable
{
AbstractBatchGenerationEnvironmentWrapper createBatchGenerator(IDhLevel targetLevel);
IBiomeWrapper deserializeBiomeWrapper(String str) throws IOException;
IBiomeWrapper deserializeBiomeWrapper(String str, ILevelWrapper levelWrapper) throws IOException;
IBlockStateWrapper deserializeBlockStateWrapper(String str) throws IOException;
IBlockStateWrapper getAirBlockStateWrapper();
@@ -29,5 +29,5 @@ import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindab
public interface IBiomeWrapper extends IDhApiBiomeWrapper, IBindable
{
String getName();
String serialize();
String serialize(ILevelWrapper levelWrapper);
}