Rename DhSectionPos -> OldDhSectionPos before rewrite

This commit is contained in:
James Seibel
2024-05-15 07:50:52 -04:00
parent cec6438602
commit 331d75a3bc
44 changed files with 503 additions and 510 deletions
@@ -31,7 +31,7 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSour
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.pos.DhLodPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.RayCastUtil;
@@ -202,10 +202,10 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
// get the detail levels for this request
byte requestedDetailLevel = requestedColumnPos.detailLevel;
byte sectionDetailLevel = (byte) (requestedDetailLevel + DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
byte sectionDetailLevel = (byte) (requestedDetailLevel + OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
// get the positions for this request
DhSectionPos sectionPos = requestedColumnPos.getSectionPosWithSectionDetailLevel(sectionDetailLevel);
OldDhSectionPos sectionPos = requestedColumnPos.getSectionPosWithSectionDetailLevel(sectionDetailLevel);
DhLodPos relativePos = requestedColumnPos.getDhSectionRelativePositionForDetailLevel();
@@ -215,7 +215,7 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
FullDataSourceV2 dataSource = level.getFullDataProvider().getAsync(sectionPos).get();
if (dataSource == null)
{
return DhApiResult.createFail("Unable to find/generate any data at the " + DhSectionPos.class.getSimpleName() + " [" + sectionPos + "].");
return DhApiResult.createFail("Unable to find/generate any data at the " + OldDhSectionPos.class.getSimpleName() + " [" + sectionPos + "].");
}
else
{
@@ -30,7 +30,7 @@ import com.seibel.distanthorizons.core.config.types.*;
import com.seibel.distanthorizons.core.config.types.enums.*;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.coreapi.util.StringUtil;
@@ -1208,7 +1208,7 @@ public class Config
.addListener(DebugColumnConfigEventHandler.INSTANCE)
.build();
public static ConfigEntry<Integer> columnBuilderDebugDetailLevel = new ConfigEntry.Builder<Integer>()
.set((int) DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL)
.set((int) OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL)
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
.addListener(DebugColumnConfigEventHandler.INSTANCE)
.build();
@@ -20,7 +20,7 @@
package com.seibel.distanthorizons.core.dataObjects.fullData;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.objects.DataCorruptedException;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream;
@@ -67,7 +67,7 @@ public class FullDataPointIdMap
private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
/** should only be used for debugging */
private DhSectionPos pos;
private OldDhSectionPos pos;
/** The index should be the same as the Entry's ID */
private final ArrayList<Entry> entryList = new ArrayList<>();
@@ -79,7 +79,7 @@ public class FullDataPointIdMap
// constructor //
//=============//
public FullDataPointIdMap(DhSectionPos pos) { this.pos = pos; }
public FullDataPointIdMap(OldDhSectionPos pos) { this.pos = pos; }
@@ -123,7 +123,7 @@ public class FullDataPointIdMap
public boolean isEmpty() { return this.entryList.isEmpty(); }
public DhSectionPos getPos() { return this.pos; }
public OldDhSectionPos getPos() { return this.pos; }
@@ -270,7 +270,7 @@ public class FullDataPointIdMap
}
/** Should only be used if this map is going to be reused, otherwise bad things will happen. */
public void clear(DhSectionPos pos)
public void clear(OldDhSectionPos pos)
{
this.pos = pos;
this.entryList.clear();
@@ -321,7 +321,7 @@ public class FullDataPointIdMap
}
/** Creates a new IdBiomeBlockStateMap from the given UTF formatted stream */
public static FullDataPointIdMap deserialize(DhDataInputStream inputStream, DhSectionPos pos, ILevelWrapper levelWrapper) throws IOException, InterruptedException, DataCorruptedException
public static FullDataPointIdMap deserialize(DhDataInputStream inputStream, OldDhSectionPos pos, ILevelWrapper levelWrapper) throws IOException, InterruptedException, DataCorruptedException
{
int entityCount = inputStream.readInt();
if (entityCount < 0)
@@ -23,7 +23,7 @@ import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGeneratio
import com.seibel.distanthorizons.core.file.IDataSource;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV1DTO;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
@@ -51,7 +51,7 @@ public class FullDataSourceV1 implements IDataSource<IDhLevel>
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
public static final byte SECTION_SIZE_OFFSET = DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
public static final byte SECTION_SIZE_OFFSET = OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
/** measured in dataPoints */
public static final int WIDTH = BitShiftUtil.powerOfTwo(SECTION_SIZE_OFFSET);
@@ -75,7 +75,7 @@ public class FullDataSourceV1 implements IDataSource<IDhLevel>
/** A flattened 2D array (for the X and Z directions) containing an array for the Y direction. */
private final long[][] dataArrays;
private DhSectionPos sectionPos;
private OldDhSectionPos sectionPos;
private boolean isEmpty = true;
@@ -85,8 +85,8 @@ public class FullDataSourceV1 implements IDataSource<IDhLevel>
// constructors //
//==============//
public static FullDataSourceV1 createEmpty(DhSectionPos pos) { return new FullDataSourceV1(pos); }
private FullDataSourceV1(DhSectionPos sectionPos)
public static FullDataSourceV1 createEmpty(OldDhSectionPos pos) { return new FullDataSourceV1(pos); }
private FullDataSourceV1(OldDhSectionPos sectionPos)
{
this.dataArrays = new long[WIDTH * WIDTH][0];
this.mapping = new FullDataPointIdMap(sectionPos);
@@ -111,12 +111,12 @@ public class FullDataSourceV1 implements IDataSource<IDhLevel>
//=====================//
@Override
public DhSectionPos getKey() { return this.sectionPos; }
public OldDhSectionPos getKey() { return this.sectionPos; }
@Override
public DhSectionPos getPos() { return this.sectionPos; }
public OldDhSectionPos getPos() { return this.sectionPos; }
public void resizeDataStructuresForRepopulation(DhSectionPos pos)
public void resizeDataStructuresForRepopulation(OldDhSectionPos pos)
{
// no data structures need to be changed, only the source's position
this.sectionPos = pos;
@@ -28,7 +28,7 @@ import com.seibel.distanthorizons.core.file.DataSourcePool;
import com.seibel.distanthorizons.core.file.IDataSource;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
@@ -43,7 +43,7 @@ import javax.annotation.Nullable;
import java.util.Arrays;
/**
* This data source contains every datapoint over its given {@link DhSectionPos}. <br><br>
* This data source contains every datapoint over its given {@link OldDhSectionPos}. <br><br>
*
* @see FullDataPointUtil
* @see FullDataSourceV1
@@ -71,9 +71,9 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
private int cachedHashCode = 0;
private DhSectionPos pos;
private OldDhSectionPos pos;
@Override
public DhSectionPos getKey() { return this.pos; }
public OldDhSectionPos getKey() { return this.pos; }
public final FullDataPointIdMap mapping;
@@ -112,8 +112,8 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
// constructors //
//==============//
public static FullDataSourceV2 createEmpty(DhSectionPos pos) { return new FullDataSourceV2(pos); }
private FullDataSourceV2(DhSectionPos pos)
public static FullDataSourceV2 createEmpty(OldDhSectionPos pos) { return new FullDataSourceV2(pos); }
private FullDataSourceV2(OldDhSectionPos pos)
{
this.pos = pos;
this.dataPoints = new LongArrayList[WIDTH * WIDTH];
@@ -126,8 +126,8 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
this.columnWorldCompressionMode = new byte[WIDTH * WIDTH];
}
public static FullDataSourceV2 createWithData(DhSectionPos pos, FullDataPointIdMap mapping, LongArrayList[] data, byte[] columnGenerationStep, byte[] columnWorldCompressionMode) { return new FullDataSourceV2(pos, mapping, data, columnGenerationStep, columnWorldCompressionMode); }
private FullDataSourceV2(DhSectionPos pos, FullDataPointIdMap mapping, LongArrayList[] data, byte[] columnGenerationSteps, byte[] columnWorldCompressionMode)
public static FullDataSourceV2 createWithData(OldDhSectionPos pos, FullDataPointIdMap mapping, LongArrayList[] data, byte[] columnGenerationStep, byte[] columnWorldCompressionMode) { return new FullDataSourceV2(pos, mapping, data, columnGenerationStep, columnWorldCompressionMode); }
private FullDataSourceV2(OldDhSectionPos pos, FullDataPointIdMap mapping, LongArrayList[] data, byte[] columnGenerationSteps, byte[] columnWorldCompressionMode)
{
LodUtil.assertTrue(data.length == WIDTH * WIDTH);
@@ -783,7 +783,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
*
* @see FullDataSourceV2#dataPoints
*/
public static void throwIfDataColumnInWrongOrder(DhSectionPos pos, LongArrayList dataArray) throws IllegalStateException
public static void throwIfDataColumnInWrongOrder(OldDhSectionPos pos, LongArrayList dataArray) throws IllegalStateException
{
long firstDataPoint = dataArray.getLong(0);
int firstBottomY = FullDataPointUtil.getBottomY(firstDataPoint);
@@ -829,7 +829,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
// pooling //
//=========//
private static void prepPooledDataSource(DhSectionPos pos, boolean clearData, FullDataSourceV2 dataSource)
private static void prepPooledDataSource(OldDhSectionPos pos, boolean clearData, FullDataSourceV2 dataSource)
{
dataSource.pos = pos;
@@ -857,10 +857,10 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
//=====================//
@Override
public DhSectionPos getPos() { return this.pos; }
public OldDhSectionPos getPos() { return this.pos; }
@Override
public byte getDataDetailLevel() { return (byte) (this.pos.getDetailLevel() - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL); }
public byte getDataDetailLevel() { return (byte) (this.pos.getDetailLevel() - OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL); }
public EDhApiWorldGenerationStep getWorldGenStepAtRelativePos(int relX, int relZ)
{
@@ -26,7 +26,7 @@ import com.seibel.distanthorizons.core.file.DataSourcePool;
import com.seibel.distanthorizons.core.file.IDataSource;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnQuadView;
@@ -50,7 +50,7 @@ public class ColumnRenderSource implements IDataSource<IDhClientLevel>
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
public static final boolean DO_SAFETY_CHECKS = ModInfo.IS_DEV_BUILD;
public static final byte SECTION_SIZE_OFFSET = DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
public static final byte SECTION_SIZE_OFFSET = OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
public static final int SECTION_SIZE = BitShiftUtil.powerOfTwo(SECTION_SIZE_OFFSET);
public static final DataSourcePool<ColumnRenderSource, IDhClientLevel> DATA_SOURCE_POOL = new DataSourcePool<>(ColumnRenderSource::createEmptyRenderSource, null /* data source prep/cleanup needs to be done outside the pool since it requires additional inputs */);
@@ -59,7 +59,7 @@ public class ColumnRenderSource implements IDataSource<IDhClientLevel>
/** will be zero if an empty data source was created */
public int verticalDataCount;
public DhSectionPos pos;
public OldDhSectionPos pos;
public int yOffset;
public LongArrayList renderDataContainer;
@@ -77,11 +77,11 @@ public class ColumnRenderSource implements IDataSource<IDhClientLevel>
//==============//
/**
* This is separate from {@link DataSourcePool#getPooledSource(DhSectionPos, boolean)}
* This is separate from {@link DataSourcePool#getPooledSource(OldDhSectionPos, boolean)}
* because we need to pass in a couple extra values,
* specifically maxVerticalSize and yOffset.
*/
public static ColumnRenderSource getPooledRenderSource(DhSectionPos pos, int maxVerticalSize, int yOffset, boolean clearData)
public static ColumnRenderSource getPooledRenderSource(OldDhSectionPos pos, int maxVerticalSize, int yOffset, boolean clearData)
{
ColumnRenderSource renderSource = DATA_SOURCE_POOL.getPooledSource(pos);
@@ -109,14 +109,14 @@ public class ColumnRenderSource implements IDataSource<IDhClientLevel>
}
private static ColumnRenderSource createEmptyRenderSource(DhSectionPos sectionPos) { return new ColumnRenderSource(sectionPos, 0, 0); }
private static ColumnRenderSource createEmptyRenderSource(OldDhSectionPos sectionPos) { return new ColumnRenderSource(sectionPos, 0, 0); }
/**
* Creates an empty ColumnRenderSource.
*
* @param pos the relative position of the container
* @param maxVerticalSize the maximum vertical size of the container
*/
private ColumnRenderSource(DhSectionPos pos, int maxVerticalSize, int yOffset)
private ColumnRenderSource(OldDhSectionPos pos, int maxVerticalSize, int yOffset)
{
this.verticalDataCount = maxVerticalSize;
this.renderDataContainer = new LongArrayList(new long[SECTION_SIZE * SECTION_SIZE * this.verticalDataCount]);
@@ -215,9 +215,9 @@ public class ColumnRenderSource implements IDataSource<IDhClientLevel>
// data helper methods //
//=====================//
public DhSectionPos getPos() { return this.pos; }
public OldDhSectionPos getPos() { return this.pos; }
@Override
public DhSectionPos getKey() { return this.pos; }
public OldDhSectionPos getKey() { return this.pos; }
public byte getDataDetailLevel() { return (byte) (this.pos.getDetailLevel() - SECTION_SIZE_OFFSET); }
@@ -27,7 +27,7 @@ import com.seibel.distanthorizons.core.level.IDhClientLevel;
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
import com.seibel.distanthorizons.core.util.LodUtil;
@@ -98,7 +98,7 @@ public class ColumnRenderBufferBuilder
&& !clientLevel.getLevelWrapper().getDimensionType().isTheEnd()
// FIXME temporary fix
// Cave culling is currently broken for any detail level above 0
&& renderSource.pos.getDetailLevel() == DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL
&& renderSource.pos.getDetailLevel() == OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL
);
int skyLightCullingBelow = Config.Client.Advanced.Graphics.AdvancedGraphics.caveCullingHeight.get();
@@ -29,7 +29,7 @@ import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.level.IDhClientLevel;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.util.ColorUtil;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
@@ -52,7 +52,7 @@ public class FullDataToRenderDataTransformer
private static final IWrapperFactory WRAPPER_FACTORY = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
private static final HashSet<DhSectionPos> brokenPos = new HashSet<>();
private static final HashSet<OldDhSectionPos> brokenPos = new HashSet<>();
@@ -98,7 +98,7 @@ public class FullDataToRenderDataTransformer
*/
private static ColumnRenderSource transformCompleteFullDataToColumnData(IDhClientLevel level, FullDataSourceV2 fullDataSource) throws InterruptedException
{
final DhSectionPos pos = fullDataSource.getPos();
final OldDhSectionPos pos = fullDataSource.getPos();
final byte dataDetail = fullDataSource.getDataDetailLevel();
final int vertSize = Config.Client.Advanced.Graphics.Quality.verticalQuality.get().calculateMaxVerticalData(fullDataSource.getDataDetailLevel());
final ColumnRenderSource columnSource = ColumnRenderSource.getPooledRenderSource(pos, vertSize, level.getMinY(), true);
@@ -32,7 +32,7 @@ import com.seibel.distanthorizons.core.enums.EDhDirection;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.objects.DataCorruptedException;
@@ -73,7 +73,7 @@ public class LodDataBuilder
sectionPosX = (sectionPosX < 0) ? ((sectionPosX + 1) / NUMB_OF_CHUNKS_WIDE) - 1 : (sectionPosX / NUMB_OF_CHUNKS_WIDE);
int sectionPosZ = chunkWrapper.getChunkPos().z;
sectionPosZ = (sectionPosZ < 0) ? ((sectionPosZ + 1) / NUMB_OF_CHUNKS_WIDE) - 1 : (sectionPosZ / NUMB_OF_CHUNKS_WIDE);
DhSectionPos pos = new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, sectionPosX, sectionPosZ);
OldDhSectionPos pos = new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, sectionPosX, sectionPosZ);
FullDataSourceV2 dataSource = FullDataSourceV2.createEmpty(pos);
dataSource.isEmpty = false;
@@ -303,7 +303,7 @@ public class LodDataBuilder
/** @throws ClassCastException if an API user returns the wrong object type(s) */
public static FullDataSourceV2 createFromApiChunkData(DhApiChunk dataPoints) throws ClassCastException, DataCorruptedException
{
FullDataSourceV2 accessor = FullDataSourceV2.createEmpty(new DhSectionPos(new DhChunkPos(dataPoints.chunkPosX, dataPoints.chunkPosZ)));
FullDataSourceV2 accessor = FullDataSourceV2.createEmpty(new OldDhSectionPos(new DhChunkPos(dataPoints.chunkPosX, dataPoints.chunkPosZ)));
for (int relZ = 0; relZ < LodUtil.CHUNK_WIDTH; relZ++)
{
for (int relX = 0; relX < LodUtil.CHUNK_WIDTH; relX++)
@@ -4,7 +4,7 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSour
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.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.sql.repo.AbstractDhRepo;
import com.seibel.distanthorizons.core.sql.dto.IBaseDTO;
import com.seibel.distanthorizons.core.util.LodUtil;
@@ -17,7 +17,6 @@ import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.io.StreamCorruptedException;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
@@ -27,8 +26,8 @@ import java.util.concurrent.locks.ReentrantLock;
// We shouldn't need multiple data source handlers
public abstract class AbstractDataSourceHandler
<TDataSource extends IDataSource<TDhLevel>,
TDTO extends IBaseDTO<DhSectionPos>,
TRepo extends AbstractDhRepo<DhSectionPos, TDTO>,
TDTO extends IBaseDTO<OldDhSectionPos>,
TRepo extends AbstractDhRepo<OldDhSectionPos, TDTO>,
TDhLevel extends IDhLevel>
implements AutoCloseable
{
@@ -42,13 +41,13 @@ public abstract class AbstractDataSourceHandler
*
* @see AbstractDataSourceHandler#MIN_SECTION_DETAIL_LEVEL
*/
public static final byte TOP_SECTION_DETAIL_LEVEL = DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL + LodUtil.REGION_DETAIL_LEVEL;
public static final byte TOP_SECTION_DETAIL_LEVEL = OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL + LodUtil.REGION_DETAIL_LEVEL;
/**
* The lowest numerical detail level possible.
*
* @see AbstractDataSourceHandler#TOP_SECTION_DETAIL_LEVEL
* */
public static final byte MIN_SECTION_DETAIL_LEVEL = DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
public static final byte MIN_SECTION_DETAIL_LEVEL = OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
protected final PositionalLockProvider updateLockProvider = new PositionalLockProvider();
@@ -56,8 +55,8 @@ public abstract class AbstractDataSourceHandler
* generally just used for debugging,
* keeps track of which positions are currently locked.
*/
public final Set<DhSectionPos> lockedPosSet = ConcurrentHashMap.newKeySet();
public final ConcurrentHashMap<DhSectionPos, AtomicInteger> queuedUpdateCountsByPos = new ConcurrentHashMap<>();
public final Set<OldDhSectionPos> lockedPosSet = ConcurrentHashMap.newKeySet();
public final ConcurrentHashMap<OldDhSectionPos, AtomicInteger> queuedUpdateCountsByPos = new ConcurrentHashMap<>();
protected final ReentrantLock closeLock = new ReentrantLock();
@@ -102,7 +101,7 @@ public abstract class AbstractDataSourceHandler
protected abstract TDataSource createDataSourceFromDto(TDTO dto) throws InterruptedException, IOException, DataCorruptedException;
protected abstract TDTO createDtoFromDataSource(TDataSource dataSource);
protected abstract TDataSource makeEmptyDataSource(DhSectionPos pos);
protected abstract TDataSource makeEmptyDataSource(OldDhSectionPos pos);
@@ -116,7 +115,7 @@ public abstract class AbstractDataSourceHandler
*
* This call is concurrent. I.e. it supports being called by multiple threads at the same time.
*/
public CompletableFuture<TDataSource> getAsync(DhSectionPos pos)
public CompletableFuture<TDataSource> getAsync(OldDhSectionPos pos)
{
ThreadPoolExecutor executor = ThreadPoolUtil.getFileHandlerExecutor();
if (executor == null || executor.isTerminated())
@@ -138,10 +137,10 @@ public abstract class AbstractDataSourceHandler
/**
* Should only be used in internal file handler methods where we are already running on a file handler thread.
* Can return null if the repo is in the process of being shut down
* @see AbstractDataSourceHandler#getAsync(DhSectionPos)
* @see AbstractDataSourceHandler#getAsync(OldDhSectionPos)
*/
@Nullable
public TDataSource get(DhSectionPos pos)
public TDataSource get(OldDhSectionPos pos)
{
TDataSource dataSource = null;
try
@@ -231,7 +230,7 @@ public abstract class AbstractDataSourceHandler
* After this method returns the inputData will be written to file.
* @param updatePos the position to update
*/
protected void updateDataSourceAtPos(DhSectionPos updatePos, @NotNull FullDataSourceV2 inputData, boolean lockOnUpdatePos)
protected void updateDataSourceAtPos(OldDhSectionPos updatePos, @NotNull FullDataSourceV2 inputData, boolean lockOnUpdatePos)
{
boolean methodLocked = false;
// a lock is necessary to prevent two threads from writing to the same position at once,
@@ -293,7 +292,7 @@ public abstract class AbstractDataSourceHandler
//================//
/** used for debugging to track which positions are queued for updating */
private void markUpdateStart(DhSectionPos dataSourcePos)
private void markUpdateStart(OldDhSectionPos dataSourcePos)
{
this.queuedUpdateCountsByPos.compute(dataSourcePos, (pos, atomicCount) ->
{
@@ -306,7 +305,7 @@ public abstract class AbstractDataSourceHandler
});
}
/** used for debugging to track which positions are queued for updating */
private void markUpdateEnd(DhSectionPos dataSourcePos)
private void markUpdateEnd(OldDhSectionPos dataSourcePos)
{
this.queuedUpdateCountsByPos.compute(dataSourcePos, (pos, atomicCount) ->
{
@@ -1,8 +1,7 @@
package com.seibel.distanthorizons.core.file;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.util.ThreadUtil;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@@ -27,7 +26,7 @@ public class DataSourcePool<TDataSource extends IDataSource<TDhLevel>, TDhLevel
private final ArrayList<TDataSource> pooledDataSources = new ArrayList<>();
private final ReentrantLock poolLock = new ReentrantLock();
private final Function<DhSectionPos, TDataSource> createEmptyDatasourceFunc;
private final Function<OldDhSectionPos, TDataSource> createEmptyDatasourceFunc;
@Nullable
private final IPrepPooledDataSourceFunc<TDataSource, TDhLevel> prepDatasourceFunc;
@@ -37,7 +36,7 @@ public class DataSourcePool<TDataSource extends IDataSource<TDhLevel>, TDhLevel
// constructor //
//=============//
public DataSourcePool(Function<DhSectionPos, TDataSource> createEmptyDatasourceFunc, @Nullable IPrepPooledDataSourceFunc<TDataSource, TDhLevel> prepDatasourceFunc)
public DataSourcePool(Function<OldDhSectionPos, TDataSource> createEmptyDatasourceFunc, @Nullable IPrepPooledDataSourceFunc<TDataSource, TDhLevel> prepDatasourceFunc)
{
this.createEmptyDatasourceFunc = createEmptyDatasourceFunc;
this.prepDatasourceFunc = prepDatasourceFunc;
@@ -51,12 +50,12 @@ public class DataSourcePool<TDataSource extends IDataSource<TDhLevel>, TDhLevel
/**
* Returns a cleared data source.
* @see DataSourcePool#getPooledSource(DhSectionPos, boolean)
* @see DataSourcePool#getPooledSource(OldDhSectionPos, boolean)
*/
public TDataSource getPooledSource(DhSectionPos pos) { return this.getPooledSource(pos, true);}
public TDataSource getPooledSource(OldDhSectionPos pos) { return this.getPooledSource(pos, true);}
/** @return an empty data source if non are cached */
public TDataSource getPooledSource(DhSectionPos pos, boolean clearData)
public TDataSource getPooledSource(OldDhSectionPos pos, boolean clearData)
{
try
{
@@ -133,7 +132,7 @@ public class DataSourcePool<TDataSource extends IDataSource<TDhLevel>, TDhLevel
public interface IPrepPooledDataSourceFunc<TDataSource extends IDataSource<TDhLevel>, TDhLevel extends IDhLevel>
{
/** @param clearData will be false if the data will be immediately overwritten anyway */
void prepDataSource(DhSectionPos pos, boolean clearData, TDataSource dataSource);
void prepDataSource(OldDhSectionPos pos, boolean clearData, TDataSource dataSource);
}
}
@@ -3,7 +3,7 @@ package com.seibel.distanthorizons.core.file;
import com.seibel.distanthorizons.api.enums.EDhApiDetailLevel;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.sql.dto.IBaseDTO;
/**
@@ -13,9 +13,9 @@ import com.seibel.distanthorizons.core.sql.dto.IBaseDTO;
*
* @param <TDhLevel> there are times when we need specifically a client level vs a more generic level
*/
public interface IDataSource<TDhLevel extends IDhLevel> extends IBaseDTO<DhSectionPos>, AutoCloseable
public interface IDataSource<TDhLevel extends IDhLevel> extends IBaseDTO<OldDhSectionPos>, AutoCloseable
{
DhSectionPos getPos();
OldDhSectionPos getPos();
/** @return true if the data was changed */
boolean update(FullDataSourceV2 chunkData, TDhLevel level);
@@ -2,7 +2,7 @@ package com.seibel.distanthorizons.core.file.fullDatafile;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.util.TimerUtil;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
@@ -22,8 +22,8 @@ public class DelayedFullDataSourceSaveCache
private static final Timer DELAY_UPDATE_TIMER = TimerUtil.CreateTimer("Delayed Full Datasource Save Timer");
public final ConcurrentHashMap<DhSectionPos, FullDataSourceV2> dataSourceByPosition = new ConcurrentHashMap<>();
private final ConcurrentHashMap<DhSectionPos, TimerTask> saveTimerTasksBySectionPos = new ConcurrentHashMap<>();
public final ConcurrentHashMap<OldDhSectionPos, FullDataSourceV2> dataSourceByPosition = new ConcurrentHashMap<>();
private final ConcurrentHashMap<OldDhSectionPos, TimerTask> saveTimerTasksBySectionPos = new ConcurrentHashMap<>();
private final ISaveDataSourceFunc onSaveTimeoutFunc;
private final int saveDelayInMs;
@@ -48,7 +48,7 @@ public class DelayedFullDataSourceSaveCache
public void queueDataSourceForUpdateAndSave(FullDataSourceV2 inputDataSource)
{
DhSectionPos dataSourcePos = inputDataSource.getPos();
OldDhSectionPos dataSourcePos = inputDataSource.getPos();
this.dataSourceByPosition.compute(dataSourcePos, (inputPos, temporaryDataSource) ->
{
if (temporaryDataSource == null)
@@ -4,7 +4,7 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSour
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.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV1DTO;
import com.seibel.distanthorizons.core.sql.repo.FullDataSourceV1Repo;
import com.seibel.distanthorizons.core.util.objects.DataCorruptedException;
@@ -92,7 +92,7 @@ public class FullDataSourceProviderV1<TDhLevel extends IDhLevel>
*
* This call is concurrent. I.e. it supports being called by multiple threads at the same time.
*/
public CompletableFuture<FullDataSourceV1> getAsync(DhSectionPos pos)
public CompletableFuture<FullDataSourceV1> getAsync(OldDhSectionPos pos)
{
ThreadPoolExecutor executor = ThreadPoolUtil.getFileHandlerExecutor();
if (executor == null || executor.isTerminated())
@@ -113,10 +113,10 @@ public class FullDataSourceProviderV1<TDhLevel extends IDhLevel>
/**
* Should only be used in internal file handler methods where we are already running on a file handler thread.
* Can return null.
* @see FullDataSourceProviderV1#getAsync(DhSectionPos)
* @see FullDataSourceProviderV1#getAsync(OldDhSectionPos)
*/
@Nullable
public FullDataSourceV1 get(DhSectionPos pos)
public FullDataSourceV1 get(OldDhSectionPos pos)
{
FullDataSourceV1 dataSource = null;
try
@@ -156,10 +156,10 @@ public class FullDataSourceProviderV1<TDhLevel extends IDhLevel>
{
ArrayList<FullDataSourceV1> dataSourceList = new ArrayList<>();
ArrayList<DhSectionPos> migrationPosList = this.repo.getPositionsToMigrate(limit);
ArrayList<OldDhSectionPos> migrationPosList = this.repo.getPositionsToMigrate(limit);
for (int i = 0; i < migrationPosList.size(); i++)
{
DhSectionPos pos = migrationPosList.get(i);
OldDhSectionPos pos = migrationPosList.get(i);
FullDataSourceV1 dataSource = this.get(pos);
if (dataSource != null)
{
@@ -170,7 +170,7 @@ public class FullDataSourceProviderV1<TDhLevel extends IDhLevel>
return dataSourceList;
}
public void markMigrationFailed(DhSectionPos pos) { ((FullDataSourceV1Repo) this.repo).markMigrationFailed(pos); }
public void markMigrationFailed(OldDhSectionPos pos) { ((FullDataSourceV1Repo) this.repo).markMigrationFailed(pos); }
@@ -29,7 +29,7 @@ import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
import com.seibel.distanthorizons.core.file.AbstractDataSourceHandler;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable;
import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV2DTO;
@@ -97,7 +97,7 @@ public class FullDataSourceProviderV2
* Tracks which positions are currently being updated
* to prevent duplicate concurrent updates.
*/
public final Set<DhSectionPos> parentUpdatingPosSet = ConcurrentHashMap.newKeySet();
public final Set<OldDhSectionPos> parentUpdatingPosSet = ConcurrentHashMap.newKeySet();
// TODO only run thread if modifications happened recently
/**
@@ -172,7 +172,7 @@ public class FullDataSourceProviderV2
{ return dto.createPooledDataSource(this.level.getLevelWrapper()); }
@Override
protected FullDataSourceV2 makeEmptyDataSource(DhSectionPos pos) { return FullDataSourceV2.DATA_SOURCE_POOL.getPooledSource(pos, true); }
protected FullDataSourceV2 makeEmptyDataSource(OldDhSectionPos pos) { return FullDataSourceV2.DATA_SOURCE_POOL.getPooledSource(pos, true); }
@@ -201,11 +201,11 @@ public class FullDataSourceProviderV2
&& this.parentUpdatingPosSet.size() < MAX_UPDATE_TASK_COUNT)
{
// get the positions that need to be applied to their parents
ArrayList<DhSectionPos> parentUpdatePosList = this.repo.getPositionsToUpdate(MAX_UPDATE_TASK_COUNT);
ArrayList<OldDhSectionPos> parentUpdatePosList = this.repo.getPositionsToUpdate(MAX_UPDATE_TASK_COUNT);
// combine updates together based on their parent
HashMap<DhSectionPos, HashSet<DhSectionPos>> updatePosByParentPos = new HashMap<>();
for (DhSectionPos pos : parentUpdatePosList)
HashMap<OldDhSectionPos, HashSet<OldDhSectionPos>> updatePosByParentPos = new HashMap<>();
for (OldDhSectionPos pos : parentUpdatePosList)
{
updatePosByParentPos.compute(pos.getParentPos(), (parentPos, updatePosSet) ->
{
@@ -219,7 +219,7 @@ public class FullDataSourceProviderV2
}
// queue the updates
for (DhSectionPos parentUpdatePos : updatePosByParentPos.keySet())
for (OldDhSectionPos parentUpdatePos : updatePosByParentPos.keySet())
{
// stop if there are already a bunch of updates queued
if (this.parentUpdatingPosSet.size() > MAX_UPDATE_TASK_COUNT
@@ -246,7 +246,7 @@ public class FullDataSourceProviderV2
this.lockedPosSet.add(parentUpdatePos);
// apply each child pos to the parent
for (DhSectionPos childPos : updatePosByParentPos.get(parentUpdatePos))
for (OldDhSectionPos childPos : updatePosByParentPos.get(parentUpdatePos))
{
ReentrantLock childReadLock = this.updateLockProvider.getLock(childPos);
try
@@ -423,7 +423,7 @@ public class FullDataSourceProviderV2
}
catch (Exception e)
{
DhSectionPos migrationPos = legacyDataSource.getPos();
OldDhSectionPos migrationPos = legacyDataSource.getPos();
LOGGER.warn("Unexpected issue migrating data source at pos " + migrationPos + ". Error: " + e.getMessage(), e);
this.legacyFileHandler.markMigrationFailed(migrationPos);
}
@@ -555,18 +555,18 @@ public class FullDataSourceProviderV2
* an empty array if all positions were generated
*/
@Nullable
public ArrayList<DhSectionPos> getPositionsToRetrieve(DhSectionPos pos) { return null; }
public ArrayList<OldDhSectionPos> getPositionsToRetrieve(OldDhSectionPos pos) { return null; }
/**
* Returns how many positions could potentially be generated for this position assuming the position is empty.
* Used when estimating the total number of retrieval requests.
*/
public int getMaxPossibleRetrievalPositionCountForPos(DhSectionPos pos) { return -1; }
public int getMaxPossibleRetrievalPositionCountForPos(OldDhSectionPos pos) { return -1; }
/** @return true if the position was queued, false if not */
public boolean queuePositionForRetrieval(DhSectionPos genPos) { return false; }
public boolean queuePositionForRetrieval(OldDhSectionPos genPos) { return false; }
/** does nothing if the given position isn't present in the queue */
public void removeRetrievalRequestIf(Function<DhSectionPos, Boolean> removeIf) { }
public void removeRetrievalRequestIf(Function<OldDhSectionPos, Boolean> removeIf) { }
public void clearRetrievalQueue() { }
@@ -28,7 +28,7 @@ import com.seibel.distanthorizons.core.generation.tasks.IWorldGenTaskTracker;
import com.seibel.distanthorizons.core.generation.tasks.WorldGenResult;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable;
import com.seibel.distanthorizons.core.util.LodUtil;
@@ -116,7 +116,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
}
// TODO only fire after the section has finished generated or once every X seconds
private void fireOnGenPosSuccessListeners(DhSectionPos pos)
private void fireOnGenPosSuccessListeners(OldDhSectionPos pos)
{
// fire the event listeners
for (IOnWorldGenCompleteListener listener : this.onWorldGenTaskCompleteListeners)
@@ -205,7 +205,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
}
@Override
public boolean queuePositionForRetrieval(DhSectionPos genPos)
public boolean queuePositionForRetrieval(OldDhSectionPos genPos)
{
IFullDataSourceRetrievalQueue worldGenQueue = this.worldGenQueueRef.get();
if (worldGenQueue == null)
@@ -214,14 +214,14 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
}
GenTask genTask = new GenTask(genPos);
CompletableFuture<WorldGenResult> worldGenFuture = worldGenQueue.submitGenTask(genPos, (byte) (genPos.getDetailLevel() - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL), genTask);
CompletableFuture<WorldGenResult> worldGenFuture = worldGenQueue.submitGenTask(genPos, (byte) (genPos.getDetailLevel() - OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL), genTask);
worldGenFuture.whenComplete((genTaskResult, ex) -> this.onWorldGenTaskComplete(genTaskResult, ex));
return true;
}
@Override
public void removeRetrievalRequestIf(Function<DhSectionPos, Boolean> removeIf)
public void removeRetrievalRequestIf(Function<OldDhSectionPos, Boolean> removeIf)
{
IFullDataSourceRetrievalQueue worldGenQueue = this.worldGenQueueRef.get();
if (worldGenQueue != null)
@@ -238,7 +238,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
@Override
public ArrayList<DhSectionPos> getPositionsToRetrieve(DhSectionPos pos)
public ArrayList<OldDhSectionPos> getPositionsToRetrieve(OldDhSectionPos pos)
{
IFullDataSourceRetrievalQueue worldGenQueue = this.worldGenQueueRef.get();
if (worldGenQueue == null)
@@ -277,8 +277,8 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
// this section is missing one or more columns, queue the missing ones for generation.
// TODO speed up this logic by only checking ungenerated columns
ArrayList<DhSectionPos> generationList = new ArrayList<>();
byte minGeneratorSectionDetailLevel = (byte) (worldGenQueue.highestDataDetail() + DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
ArrayList<OldDhSectionPos> generationList = new ArrayList<>();
byte minGeneratorSectionDetailLevel = (byte) (worldGenQueue.highestDataDetail() + OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
pos.forEachChildAtDetailLevel(minGeneratorSectionDetailLevel, (genPos) ->
{
if (!this.repo.existsWithKey(genPos))
@@ -336,7 +336,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
}
@Override
public int getMaxPossibleRetrievalPositionCountForPos(DhSectionPos pos)
public int getMaxPossibleRetrievalPositionCountForPos(OldDhSectionPos pos)
{
IFullDataSourceRetrievalQueue worldGenQueue = this.worldGenQueueRef.get();
if (worldGenQueue == null)
@@ -344,7 +344,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
return -1;
}
int minGeneratorSectionDetailLevel = worldGenQueue.highestDataDetail() + DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
int minGeneratorSectionDetailLevel = worldGenQueue.highestDataDetail() + OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
int detailLevelDiff = pos.getDetailLevel() - minGeneratorSectionDetailLevel;
return BitShiftUtil.powerOfTwo(detailLevelDiff);
@@ -375,9 +375,9 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
// TODO may not be needed
private class GenTask implements IWorldGenTaskTracker
{
private final DhSectionPos pos;
private final OldDhSectionPos pos;
public GenTask(DhSectionPos pos)
public GenTask(OldDhSectionPos pos)
{
this.pos = pos;
}
@@ -406,7 +406,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
public interface IOnWorldGenCompleteListener
{
/** Fired whenever a section has completed generating */
void onWorldGenTaskComplete(DhSectionPos pos);
void onWorldGenTaskComplete(OldDhSectionPos pos);
}
@@ -29,7 +29,7 @@ import com.seibel.distanthorizons.core.level.DhClientLevel;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.dataObjects.transformers.LodDataBuilder;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
@@ -190,7 +190,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
}
FullDataSourceV2 newChunkSizedFullDataView = FullDataSourceV2.createFromChunk(newlyLoadedChunk);
// convert to a data source for easier comparing
FullDataSourceV2 newDataSource = FullDataSourceV2.createEmpty(new DhSectionPos(this.playerData.playerBlockPos));
FullDataSourceV2 newDataSource = FullDataSourceV2.createEmpty(new OldDhSectionPos(this.playerData.playerBlockPos));
newDataSource.update(newChunkSizedFullDataView);
@@ -215,7 +215,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
// get the data source to compare against
try (IDhLevel tempLevel = new DhClientLevel(new ClientOnlySaveStructure(), this.currentClientLevel, testLevelFolder, false))
{
testFullDataSource = tempLevel.getFullDataProvider().getAsync(new DhSectionPos(this.playerData.playerBlockPos)).join();
testFullDataSource = tempLevel.getFullDataProvider().getAsync(new OldDhSectionPos(this.playerData.playerBlockPos)).join();
if (testFullDataSource == null)
{
continue;
@@ -224,8 +224,8 @@ public class SubDimensionLevelMatcher implements AutoCloseable
// confirm both data sources have the same section pos
DhSectionPos newSectionChunkPos = newDataSource.getPos().convertNewToDetailLevel(DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL);
DhSectionPos testSectionChunkPos = testFullDataSource.getPos().convertNewToDetailLevel(DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL);
OldDhSectionPos newSectionChunkPos = newDataSource.getPos().convertNewToDetailLevel(OldDhSectionPos.SECTION_CHUNK_DETAIL_LEVEL);
OldDhSectionPos testSectionChunkPos = testFullDataSource.getPos().convertNewToDetailLevel(OldDhSectionPos.SECTION_CHUNK_DETAIL_LEVEL);
LodUtil.assertTrue(newSectionChunkPos.equals(testSectionChunkPos), "data source positions don't match");
@@ -22,7 +22,7 @@ package com.seibel.distanthorizons.core.generation;
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.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.render.LodQuadTree;
import java.io.Closeable;
@@ -80,9 +80,9 @@ public interface IFullDataSourceRetrievalQueue extends Closeable
* Generally the retrieval queue should be fairly small, so its faster to iterate over the existing list
* and check if each one is valid vs dumbly attempting to remove every position that just went out of range.
*/
void removeRetrievalRequestIf(Function<DhSectionPos, Boolean> removeIf);
void removeRetrievalRequestIf(Function<OldDhSectionPos, Boolean> removeIf);
CompletableFuture<WorldGenResult> submitGenTask(DhSectionPos pos, byte requiredDataDetail, IWorldGenTaskTracker tracker);
CompletableFuture<WorldGenResult> submitGenTask(OldDhSectionPos pos, byte requiredDataDetail, IWorldGenTaskTracker tracker);
@@ -29,7 +29,7 @@ import com.seibel.distanthorizons.core.generation.tasks.*;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dataObjects.transformers.LodDataBuilder;
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
@@ -58,9 +58,9 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
private final IDhApiWorldGenerator generator;
/** contains the positions that need to be generated */
private final ConcurrentHashMap<DhSectionPos, WorldGenTask> waitingTasks = new ConcurrentHashMap<>();
private final ConcurrentHashMap<OldDhSectionPos, WorldGenTask> waitingTasks = new ConcurrentHashMap<>();
private final ConcurrentHashMap<DhSectionPos, InProgressWorldGenTaskGroup> inProgressGenTasksByLodPos = new ConcurrentHashMap<>();
private final ConcurrentHashMap<OldDhSectionPos, InProgressWorldGenTaskGroup> inProgressGenTasksByLodPos = new ConcurrentHashMap<>();
// granularity is the detail level for batching world generator requests together
public final byte maxGranularity;
@@ -89,8 +89,8 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
// debug variables to test for duplicate world generator requests //
/** limits how many of the previous world gen requests we should track */
private static final int MAX_ALREADY_GENERATED_COUNT = 100;
private final HashMap<DhSectionPos, StackTraceElement[]> alreadyGeneratedPosHashSet = new HashMap<>(MAX_ALREADY_GENERATED_COUNT);
private final Queue<DhSectionPos> alreadyGeneratedPosQueue = new LinkedList<>();
private final HashMap<OldDhSectionPos, StackTraceElement[]> alreadyGeneratedPosHashSet = new HashMap<>(MAX_ALREADY_GENERATED_COUNT);
private final Queue<OldDhSectionPos> alreadyGeneratedPosQueue = new LinkedList<>();
/** just used for rendering to the F3 menu */
private int estimatedTotalTaskCount = 0;
@@ -131,7 +131,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
//=================//
@Override
public CompletableFuture<WorldGenResult> submitGenTask(DhSectionPos pos, byte requiredDataDetail, IWorldGenTaskTracker tracker)
public CompletableFuture<WorldGenResult> submitGenTask(OldDhSectionPos pos, byte requiredDataDetail, IWorldGenTaskTracker tracker)
{
// the generator is shutting down, don't add new tasks
if (this.generatorClosingFuture != null)
@@ -160,7 +160,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
}
@Override
public void removeRetrievalRequestIf(Function<DhSectionPos, Boolean> removeIf)
public void removeRetrievalRequestIf(Function<OldDhSectionPos, Boolean> removeIf)
{
this.waitingTasks.forEachKey(100, (genPos) ->
{
@@ -307,7 +307,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
// split up the task and add each one to the tree
LinkedList<CompletableFuture<WorldGenResult>> childFutures = new LinkedList<>();
DhSectionPos sectionPos = new DhSectionPos(closestTask.pos.getDetailLevel(), closestTask.pos.getX(), closestTask.pos.getZ());
OldDhSectionPos sectionPos = new OldDhSectionPos(closestTask.pos.getDetailLevel(), closestTask.pos.getX(), closestTask.pos.getZ());
WorldGenTask finalClosestTask = closestTask;
sectionPos.forEachChild((childDhSectionPos) ->
{
@@ -329,7 +329,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
private boolean tryStartingWorldGenTaskGroup(InProgressWorldGenTaskGroup newTaskGroup)
{
byte taskDetailLevel = newTaskGroup.group.dataDetail;
DhSectionPos taskPos = newTaskGroup.group.pos;
OldDhSectionPos taskPos = newTaskGroup.group.pos;
byte granularity = (byte) (taskPos.getDetailLevel() - taskDetailLevel);
LodUtil.assertTrue(granularity >= this.minGranularity && granularity <= this.maxGranularity);
LodUtil.assertTrue(taskDetailLevel >= this.highestDataDetail && taskDetailLevel <= this.lowestDataDetail);
@@ -343,7 +343,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
//LOGGER.trace("Duplicate generation section " + taskPos + " with granularity [" + granularity + "] at " + chunkPosMin + ". Skipping...");
// sending a success result is necessary to make sure the render sections are reloaded correctly
newTaskGroup.group.worldGenTasks.forEach(worldGenTask -> worldGenTask.future.complete(WorldGenResult.CreateSuccess(new DhSectionPos(granularity, taskPos.getX(), taskPos.getZ()))));
newTaskGroup.group.worldGenTasks.forEach(worldGenTask -> worldGenTask.future.complete(WorldGenResult.CreateSuccess(new OldDhSectionPos(granularity, taskPos.getX(), taskPos.getZ()))));
return false;
}
this.alreadyGeneratedPosHashSet.put(newTaskGroup.group.pos, Thread.currentThread().getStackTrace());
@@ -352,7 +352,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
// remove extra tracked duplicate positions
while (this.alreadyGeneratedPosQueue.size() > MAX_ALREADY_GENERATED_COUNT)
{
DhSectionPos posToRemove = this.alreadyGeneratedPosQueue.poll();
OldDhSectionPos posToRemove = this.alreadyGeneratedPosQueue.poll();
this.alreadyGeneratedPosHashSet.remove(posToRemove);
}
@@ -381,7 +381,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
else
{
//LOGGER.info("Section generation at "+pos+" completed");
newTaskGroup.group.worldGenTasks.forEach(worldGenTask -> worldGenTask.future.complete(WorldGenResult.CreateSuccess(new DhSectionPos(granularity, taskPos.getX(), taskPos.getZ()))));
newTaskGroup.group.worldGenTasks.forEach(worldGenTask -> worldGenTask.future.complete(WorldGenResult.CreateSuccess(new OldDhSectionPos(granularity, taskPos.getX(), taskPos.getZ()))));
}
boolean worked = this.inProgressGenTasksByLodPos.remove(taskPos, newTaskGroup);
LodUtil.assertTrue(worked);
@@ -624,7 +624,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
// helper methods //
//================//
private boolean canGeneratePos(byte worldGenTaskGroupDetailLevel /*when in doubt use 0*/ , DhSectionPos taskPos)
private boolean canGeneratePos(byte worldGenTaskGroupDetailLevel /*when in doubt use 0*/ , OldDhSectionPos taskPos)
{
byte granularity = (byte) (taskPos.getDetailLevel() - worldGenTaskGroupDetailLevel);
return (granularity >= this.minGranularity && granularity <= this.maxGranularity);
@@ -19,7 +19,7 @@
package com.seibel.distanthorizons.core.generation.tasks;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import java.util.Collection;
import java.util.LinkedList;
@@ -30,15 +30,15 @@ public class WorldGenResult
/** true if terrain was generated */
public final boolean success;
/** the position that was generated, will be null if nothing was generated */
public final DhSectionPos pos;
public final OldDhSectionPos pos;
/** if a position is too high detail for world generator to handle it, these futures are for its 4 children positions after being split up. */
public final LinkedList<CompletableFuture<WorldGenResult>> childFutures = new LinkedList<>();
public static WorldGenResult CreateSplit(Collection<CompletableFuture<WorldGenResult>> siblingFutures) { return new WorldGenResult(false, null, siblingFutures); }
public static WorldGenResult CreateFail() { return new WorldGenResult(false, null, null); }
public static WorldGenResult CreateSuccess(DhSectionPos pos) { return new WorldGenResult(true, pos, null); }
private WorldGenResult(boolean success, DhSectionPos pos, Collection<CompletableFuture<WorldGenResult>> childFutures)
public static WorldGenResult CreateSuccess(OldDhSectionPos pos) { return new WorldGenResult(true, pos, null); }
private WorldGenResult(boolean success, OldDhSectionPos pos, Collection<CompletableFuture<WorldGenResult>> childFutures)
{
this.success = success;
this.pos = pos;
@@ -19,8 +19,7 @@
package com.seibel.distanthorizons.core.generation.tasks;
import com.seibel.distanthorizons.core.pos.DhLodPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import java.util.concurrent.CompletableFuture;
@@ -30,14 +29,14 @@ import java.util.concurrent.CompletableFuture;
*/
public final class WorldGenTask
{
public final DhSectionPos pos;
public final OldDhSectionPos pos;
public final byte dataDetailLevel;
public final IWorldGenTaskTracker taskTracker;
public final CompletableFuture<WorldGenResult> future;
public WorldGenTask(DhSectionPos pos, byte dataDetail, IWorldGenTaskTracker taskTracker, CompletableFuture<WorldGenResult> future)
public WorldGenTask(OldDhSectionPos pos, byte dataDetail, IWorldGenTaskTracker taskTracker, CompletableFuture<WorldGenResult> future)
{
this.dataDetailLevel = dataDetail;
this.pos = pos;
@@ -20,7 +20,7 @@
package com.seibel.distanthorizons.core.generation.tasks;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import java.util.Iterator;
import java.util.LinkedList;
@@ -33,14 +33,14 @@ import java.util.function.Consumer;
@Deprecated // TODO look into how these are used and if they should continue to be used
public final class WorldGenTaskGroup
{
public final DhSectionPos pos;
public final OldDhSectionPos pos;
public byte dataDetail;
/** Only accessed by the generator polling thread */
public final LinkedList<WorldGenTask> worldGenTasks = new LinkedList<>();
public WorldGenTaskGroup(DhSectionPos pos, byte dataDetail)
public WorldGenTaskGroup(OldDhSectionPos pos, byte dataDetail)
{
this.pos = pos;
this.dataDetail = dataDetail;
@@ -24,7 +24,7 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSour
import com.seibel.distanthorizons.core.dataObjects.transformers.ChunkToLodBuilder;
import com.seibel.distanthorizons.core.file.fullDatafile.DelayedFullDataSourceSaveCache;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
@@ -36,8 +36,8 @@ public abstract class AbstractDhLevel implements IDhLevel
public final ChunkToLodBuilder chunkToLodBuilder;
protected final DelayedFullDataSourceSaveCache delayedFullDataSourceSaveCache = new DelayedFullDataSourceSaveCache(this::onDataSourceSave, 2_000);
/** contains the {@link DhChunkPos} for each {@link DhSectionPos} that are queued to save via {@link AbstractDhLevel#delayedFullDataSourceSaveCache} */
protected final ConcurrentHashMap<DhSectionPos, HashSet<DhChunkPos>> updatedChunkPosSetBySectionPos = new ConcurrentHashMap<>();
/** contains the {@link DhChunkPos} for each {@link OldDhSectionPos} that are queued to save via {@link AbstractDhLevel#delayedFullDataSourceSaveCache} */
protected final ConcurrentHashMap<OldDhSectionPos, HashSet<DhChunkPos>> updatedChunkPosSetBySectionPos = new ConcurrentHashMap<>();
@@ -29,7 +29,7 @@ import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.render.LodQuadTree;
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
@@ -313,7 +313,7 @@ public class ClientLevelModule implements Closeable, AbstractDataSourceHandler.I
}
}
public void reloadPos(DhSectionPos pos)
public void reloadPos(OldDhSectionPos pos)
{
ClientRenderState clientRenderState = this.ClientRenderStateRef.get();
if (clientRenderState != null && clientRenderState.quadtree != null)
@@ -28,7 +28,7 @@ import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
@@ -199,7 +199,7 @@ public class DhClientServerLevel extends AbstractDhLevel implements IDhClientLev
}
@Override
public void onWorldGenTaskComplete(DhSectionPos pos)
public void onWorldGenTaskComplete(OldDhSectionPos pos)
{
DebugRenderer.makeParticle(
new DebugRenderer.BoxParticle(
@@ -23,7 +23,7 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSour
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
@@ -105,7 +105,7 @@ public class DhServerLevel extends AbstractDhLevel implements IDhServerLevel
public boolean hasSkyLight() { return this.serverLevelWrapper.hasSkyLight(); }
@Override
public void onWorldGenTaskComplete(DhSectionPos pos)
public void onWorldGenTaskComplete(OldDhSectionPos pos)
{
//TODO: Send packet to client
}
@@ -53,7 +53,7 @@ public class DhLodPos implements Comparable<DhLodPos>
this.x = x;
this.z = z;
}
public DhLodPos(DhSectionPos sectionPos) { this(sectionPos.getDetailLevel(), sectionPos.getX(), sectionPos.getZ()); }
public DhLodPos(OldDhSectionPos sectionPos) { this(sectionPos.getDetailLevel(), sectionPos.getX(), sectionPos.getZ()); }
@@ -162,10 +162,10 @@ public class DhLodPos implements Comparable<DhLodPos>
}
/**
* @param sectionDetailLevel This is different from the normal LOD Detail level, see {@link DhSectionPos} for more information
* @param sectionDetailLevel This is different from the normal LOD Detail level, see {@link OldDhSectionPos} for more information
* @throws IllegalArgumentException if this position's detail level is lower than the output detail level
*/
public DhSectionPos getSectionPosWithSectionDetailLevel(byte sectionDetailLevel) throws IllegalArgumentException
public OldDhSectionPos getSectionPosWithSectionDetailLevel(byte sectionDetailLevel) throws IllegalArgumentException
{
if (sectionDetailLevel < this.detailLevel)
{
@@ -174,7 +174,7 @@ public class DhLodPos implements Comparable<DhLodPos>
DhLodPos lodPos = new DhLodPos(this.detailLevel, this.x, this.z);
lodPos = lodPos.convertToDetailLevel(sectionDetailLevel);
return new DhSectionPos(lodPos.detailLevel, lodPos.x, lodPos.z);
return new OldDhSectionPos(lodPos.detailLevel, lodPos.x, lodPos.z);
}
@@ -43,7 +43,7 @@ import java.util.function.Function;
*
* @author Leetom
*/
public class DhSectionPos
public class OldDhSectionPos
{
/**
* The lowest detail level a Section position can hold.
@@ -69,31 +69,31 @@ public class DhSectionPos
// constructors //
//==============//
public DhSectionPos(byte detailLevel, int x, int z)
public OldDhSectionPos(byte detailLevel, int x, int z)
{
this.detailLevel = detailLevel;
this.x = x;
this.z = z;
}
public DhSectionPos(DhBlockPos blockPos)
public OldDhSectionPos(DhBlockPos blockPos)
{
this(LodUtil.BLOCK_DETAIL_LEVEL, blockPos.x, blockPos.z);
this.convertSelfToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
this.convertSelfToDetailLevel(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
}
public DhSectionPos(DhBlockPos2D blockPos)
public OldDhSectionPos(DhBlockPos2D blockPos)
{
this(LodUtil.BLOCK_DETAIL_LEVEL, blockPos.x, blockPos.z);
this.convertSelfToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
this.convertSelfToDetailLevel(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
}
public DhSectionPos(DhChunkPos chunkPos)
public OldDhSectionPos(DhChunkPos chunkPos)
{
this(LodUtil.CHUNK_DETAIL_LEVEL, chunkPos.x, chunkPos.z);
this.convertSelfToDetailLevel(DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL);
this.convertSelfToDetailLevel(OldDhSectionPos.SECTION_CHUNK_DETAIL_LEVEL);
}
public DhSectionPos(byte detailLevel, DhLodPos dhLodPos)
public OldDhSectionPos(byte detailLevel, DhLodPos dhLodPos)
{
this.detailLevel = detailLevel;
this.x = dhLodPos.x;
@@ -111,9 +111,9 @@ public class DhSectionPos
*
* @return the new position closest to negative infinity with the new detail level
*/
public DhSectionPos convertNewToDetailLevel(byte newSectionDetailLevel)
public OldDhSectionPos convertNewToDetailLevel(byte newSectionDetailLevel)
{
DhSectionPos newPos = new DhSectionPos(this.detailLevel, this.x, this.z);
OldDhSectionPos newPos = new OldDhSectionPos(this.detailLevel, this.x, this.z);
newPos.convertSelfToDetailLevel(newSectionDetailLevel);
return newPos;
@@ -175,12 +175,12 @@ public class DhSectionPos
this.z * BitShiftUtil.powerOfTwo(offset));
}
public DhSectionPos getMinCornerPos(byte returnDetailLevel)
public OldDhSectionPos getMinCornerPos(byte returnDetailLevel)
{
LodUtil.assertTrue(returnDetailLevel <= this.detailLevel, "returnDetailLevel must be less than sectionDetail");
byte offset = (byte) (this.detailLevel - returnDetailLevel);
return new DhSectionPos(returnDetailLevel,
return new OldDhSectionPos(returnDetailLevel,
this.x * BitShiftUtil.powerOfTwo(offset),
this.z * BitShiftUtil.powerOfTwo(offset));
}
@@ -193,7 +193,7 @@ public class DhSectionPos
* 3 -> 8 <br>
* etc.
*
* @return how many {@link DhSectionPos}'s at the given detail level it would take to span the width of this section.
* @return how many {@link OldDhSectionPos}'s at the given detail level it would take to span the width of this section.
*/
public int getWidthCountForLowerDetailedSection(byte returnDetailLevel)
{
@@ -253,7 +253,7 @@ public class DhSectionPos
*
* @param child0to3 must be an int between 0 and 3
*/
public DhSectionPos getChildByIndex(int child0to3) throws IllegalArgumentException, IllegalStateException
public OldDhSectionPos getChildByIndex(int child0to3) throws IllegalArgumentException, IllegalStateException
{
if (child0to3 < 0 || child0to3 > 3)
{
@@ -264,21 +264,21 @@ public class DhSectionPos
throw new IllegalStateException("section detail must be greater than 0");
}
return new DhSectionPos((byte) (this.detailLevel - 1),
return new OldDhSectionPos((byte) (this.detailLevel - 1),
this.x * 2 + (child0to3 & 1),
this.z * 2 + BitShiftUtil.half(child0to3 & 2));
}
/** Returns this position's child index in its parent */
public int getChildIndexOfParent() { return (this.x & 1) + BitShiftUtil.square(this.z & 1); }
public DhSectionPos getParentPos() { return new DhSectionPos((byte) (this.detailLevel + 1), BitShiftUtil.half(this.x), BitShiftUtil.half(this.z)); }
public OldDhSectionPos getParentPos() { return new OldDhSectionPos((byte) (this.detailLevel + 1), BitShiftUtil.half(this.x), BitShiftUtil.half(this.z)); }
public DhSectionPos getAdjacentPos(EDhDirection dir)
public OldDhSectionPos getAdjacentPos(EDhDirection dir)
{
return new DhSectionPos(this.detailLevel,
return new OldDhSectionPos(this.detailLevel,
this.x + dir.getNormal().x,
this.z + dir.getNormal().z);
}
@@ -291,7 +291,7 @@ public class DhSectionPos
// comparisons //
//=============//
public boolean overlapsExactly(DhSectionPos other)
public boolean overlapsExactly(OldDhSectionPos other)
{
// original logic from DhLodPos
if (this.equals(other))
@@ -312,7 +312,7 @@ public class DhSectionPos
}
}
public boolean contains(DhSectionPos otherPos)
public boolean contains(OldDhSectionPos otherPos)
{
DhBlockPos2D thisMinBlockPos = this.getMinCornerLodPos(LodUtil.BLOCK_DETAIL_LEVEL).getCornerBlockPos();
DhBlockPos2D otherCornerBlockPos = otherPos.getMinCornerLodPos(LodUtil.BLOCK_DETAIL_LEVEL).getCornerBlockPos();
@@ -331,7 +331,7 @@ public class DhSectionPos
//===========//
/** Applies the given consumer to all 4 of this position's children. */
public void forEachChild(Consumer<DhSectionPos> callback)
public void forEachChild(Consumer<OldDhSectionPos> callback)
{
for (int i = 0; i < 4; i++)
{
@@ -340,7 +340,7 @@ public class DhSectionPos
}
/** Applies the given consumer to all children of the position at the given section detail level. */
public void forEachChildDownToDetailLevel(byte minSectionDetailLevel, Function<DhSectionPos, Boolean> callback)
public void forEachChildDownToDetailLevel(byte minSectionDetailLevel, Function<OldDhSectionPos, Boolean> callback)
{
boolean stop = callback.apply(this);
if (stop || minSectionDetailLevel == this.detailLevel)
@@ -355,7 +355,7 @@ public class DhSectionPos
}
/** Applies the given consumer to all children of the position at the given section detail level. */
public void forEachChildAtDetailLevel(byte sectionDetailLevel, Consumer<DhSectionPos> callback)
public void forEachChildAtDetailLevel(byte sectionDetailLevel, Consumer<OldDhSectionPos> callback)
{
if (sectionDetailLevel == this.detailLevel)
{
@@ -370,7 +370,7 @@ public class DhSectionPos
}
/** Applies the given consumer to all children of the position at the given section detail level. */
public void forEachPosUpToDetailLevel(byte maxSectionDetailLevel, Consumer<DhSectionPos> callback)
public void forEachPosUpToDetailLevel(byte maxSectionDetailLevel, Consumer<OldDhSectionPos> callback)
{
callback.accept(this);
if (maxSectionDetailLevel == this.detailLevel)
@@ -393,12 +393,12 @@ public class DhSectionPos
public String serialize() { return "[" + this.detailLevel + ',' + this.x + ',' + this.z + ']'; }
@Nullable
public static DhSectionPos deserialize(String value)
public static OldDhSectionPos deserialize(String value)
{
if (value.charAt(0) != '[' || value.charAt(value.length() - 1) != ']') return null;
String[] split = value.substring(1, value.length() - 1).split(",");
if (split.length != 3) return null;
return new DhSectionPos(Byte.parseByte(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
return new OldDhSectionPos(Byte.parseByte(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
}
@@ -418,12 +418,12 @@ public class DhSectionPos
{
return true;
}
if (obj == null || obj.getClass() != DhSectionPos.class)
if (obj == null || obj.getClass() != OldDhSectionPos.class)
{
return false;
}
DhSectionPos that = (DhSectionPos) obj;
OldDhSectionPos that = (OldDhSectionPos) obj;
return this.detailLevel == that.detailLevel &&
this.x == that.x &&
this.z == that.z;
@@ -444,12 +444,12 @@ public class DhSectionPos
//=============//
/**
* Identical to {@link DhSectionPos} except it is mutable.
* See {@link DhSectionPos} for full documentation.
* Identical to {@link OldDhSectionPos} except it is mutable.
* See {@link OldDhSectionPos} for full documentation.
*
* @see DhSectionPos
* @see OldDhSectionPos
*/
public static class DhMutableSectionPos extends DhSectionPos
public static class DhMutableSectionPos extends OldDhSectionPos
{
//==============//
@@ -28,7 +28,7 @@ import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV
import com.seibel.distanthorizons.core.level.IDhClientLevel;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable;
import com.seibel.distanthorizons.core.util.LodUtil;
@@ -68,10 +68,10 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
private final FullDataSourceProviderV2 fullDataSourceProvider;
/**
* This holds every {@link DhSectionPos} that should be reloaded next tick. <br>
* This holds every {@link OldDhSectionPos} that should be reloaded next tick. <br>
* This is a {@link ConcurrentLinkedQueue} because new sections can be added to this list via the world generator threads.
*/
private final ConcurrentLinkedQueue<DhSectionPos> sectionsToReload = new ConcurrentLinkedQueue<>();
private final ConcurrentLinkedQueue<OldDhSectionPos> sectionsToReload = new ConcurrentLinkedQueue<>();
private final IDhClientLevel level; //FIXME: Proper hierarchy to remove this reference!
private final ConfigChangeListener<EDhApiHorizontalQuality> horizontalScaleChangeListener;
private final ReentrantLock treeReadWriteLock = new ReentrantLock();
@@ -181,7 +181,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
// reload any sections that need it
DhSectionPos pos;
OldDhSectionPos pos;
while ((pos = this.sectionsToReload.poll()) != null)
{
// walk up the tree until we hit the root node
@@ -207,11 +207,11 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
// walk through each root node
ArrayList<LodRenderSection> nodesNeedingRetrieval = new ArrayList<>();
ArrayList<LodRenderSection> nodesNeedingLoading = new ArrayList<>();
Iterator<DhSectionPos> rootPosIterator = this.rootNodePosIterator();
Iterator<OldDhSectionPos> rootPosIterator = this.rootNodePosIterator();
while (rootPosIterator.hasNext())
{
// make sure all root nodes have been created
DhSectionPos rootPos = rootPosIterator.next();
OldDhSectionPos rootPos = rootPosIterator.next();
if (this.getNode(rootPos) == null)
{
this.setValue(rootPos, new LodRenderSection(rootPos, this, this.level, this.fullDataSourceProvider));
@@ -250,7 +250,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
/** @return whether the current position is able to render (note: not if it IS rendering, just if it is ABLE to.) */
private boolean recursivelyUpdateRenderSectionNode(
DhBlockPos2D playerPos,
QuadNode<LodRenderSection> rootNode, QuadNode<LodRenderSection> quadNode, DhSectionPos sectionPos,
QuadNode<LodRenderSection> rootNode, QuadNode<LodRenderSection> quadNode, OldDhSectionPos sectionPos,
boolean parentSectionIsRendering,
ArrayList<LodRenderSection> nodesNeedingRetrieval,
ArrayList<LodRenderSection> nodesNeedingLoading)
@@ -292,7 +292,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
//byte expectedDetailLevel = DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL + 3; // can be used instead of the following logic for testing
byte expectedDetailLevel = this.calculateExpectedDetailLevel(playerPos, sectionPos);
expectedDetailLevel = (byte) Math.min(expectedDetailLevel, this.minRenderDetailLevel);
expectedDetailLevel += DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL;
expectedDetailLevel += OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL;
if (sectionPos.getDetailLevel() > expectedDetailLevel)
@@ -302,10 +302,10 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
boolean allChildrenSectionsAreLoaded = true;
// recursively update all child render sections
Iterator<DhSectionPos> childPosIterator = quadNode.getChildPosIterator();
Iterator<OldDhSectionPos> childPosIterator = quadNode.getChildPosIterator();
while (childPosIterator.hasNext())
{
DhSectionPos childPos = childPosIterator.next();
OldDhSectionPos childPos = childPosIterator.next();
QuadNode<LodRenderSection> childNode = rootNode.getNode(childPos);
boolean childSectionLoaded = this.recursivelyUpdateRenderSectionNode(playerPos, rootNode, childNode, childPos, thisPosIsRendering || parentSectionIsRendering, nodesNeedingRetrieval, nodesNeedingLoading);
@@ -338,7 +338,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
childPosIterator = quadNode.getChildPosIterator();
while (childPosIterator.hasNext())
{
DhSectionPos childPos = childPosIterator.next();
OldDhSectionPos childPos = childPosIterator.next();
QuadNode<LodRenderSection> childNode = rootNode.getNode(childPos);
boolean childSectionLoaded = this.recursivelyUpdateRenderSectionNode(playerPos, rootNode, childNode, childPos, parentSectionIsRendering, nodesNeedingRetrieval, nodesNeedingLoading);
@@ -445,7 +445,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
* @param sectionPos section position
* @return detail level of this section pos
*/
public byte calculateExpectedDetailLevel(DhBlockPos2D playerPos, DhSectionPos sectionPos) { return this.getDetailLevelFromDistance(playerPos.dist(sectionPos.getCenterBlockPosX(), sectionPos.getCenterBlockPosZ())); }
public byte calculateExpectedDetailLevel(DhBlockPos2D playerPos, OldDhSectionPos sectionPos) { return this.getDetailLevelFromDistance(playerPos.dist(sectionPos.getCenterBlockPosX(), sectionPos.getCenterBlockPosZ())); }
private byte getDetailLevelFromDistance(double distance)
{
double maxDetailDistance = this.getDrawDistanceFromDetail(Byte.MAX_VALUE - 1);
@@ -537,7 +537,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
* Can be called whenever a render section's data needs to be refreshed. <br>
* This should be called whenever a world generation task is completed or if the connected server has new data to show.
*/
public void reloadPos(@NotNull DhSectionPos pos)
public void reloadPos(@NotNull OldDhSectionPos pos)
{
if (pos == null)
{
@@ -28,7 +28,7 @@ import com.seibel.distanthorizons.core.enums.EDhDirection;
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
import com.seibel.distanthorizons.core.level.IDhClientLevel;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable;
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.ColumnRenderBuffer;
@@ -56,7 +56,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
public final DhSectionPos pos;
public final OldDhSectionPos pos;
private final IDhClientLevel level;
@WillNotClose
@@ -85,7 +85,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
private boolean missingPositionsCalculated = false;
/** should be an empty array if no positions need to be generated */
private ArrayList<DhSectionPos> missingGenerationPos = null;
private ArrayList<OldDhSectionPos> missingGenerationPos = null;
@@ -93,7 +93,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
// constructor //
//=============//
public LodRenderSection(DhSectionPos pos, LodQuadTree quadTree, IDhClientLevel level, FullDataSourceProviderV2 fullDataSourceProvider)
public LodRenderSection(OldDhSectionPos pos, LodQuadTree quadTree, IDhClientLevel level, FullDataSourceProviderV2 fullDataSourceProvider)
{
this.pos = pos;
this.quadTree = quadTree;
@@ -236,7 +236,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
EDhDirection direction = EDhDirection.ADJ_DIRECTIONS[i];
int arrayIndex = direction.ordinal() - 2;
DhSectionPos adjPos = this.pos.getAdjacentPos(direction);
OldDhSectionPos adjPos = this.pos.getAdjacentPos(direction);
try
{
LodRenderSection adjRenderSection = this.quadTree.getValue(adjPos);
@@ -350,7 +350,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
break;
}
DhSectionPos pos = this.missingGenerationPos.remove(i);
OldDhSectionPos pos = this.missingGenerationPos.remove(i);
boolean positionQueued = this.fullDataSourceProvider.queuePositionForRetrieval(pos);
if (!positionQueued)
{
@@ -31,7 +31,7 @@ import com.seibel.distanthorizons.core.enums.EDhDirection;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
import com.seibel.distanthorizons.core.pos.DhLodPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.pos.Pos2D;
import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
import com.seibel.distanthorizons.core.util.LodUtil;
@@ -309,7 +309,7 @@ public class RenderBufferHandler implements AutoCloseable
{
QuadNode<LodRenderSection> node = nodeIterator.next();
DhSectionPos sectionPos = node.sectionPos;
OldDhSectionPos sectionPos = node.sectionPos;
LodRenderSection renderSection = node.value;
if (renderSection == null)
{
@@ -425,9 +425,9 @@ public class RenderBufferHandler implements AutoCloseable
private static class LoadedRenderBuffer
{
public final ColumnRenderBuffer buffer;
public final DhSectionPos pos;
public final OldDhSectionPos pos;
LoadedRenderBuffer(ColumnRenderBuffer buffer, DhSectionPos pos)
LoadedRenderBuffer(ColumnRenderBuffer buffer, OldDhSectionPos pos)
{
this.buffer = buffer;
this.pos = pos;
@@ -28,7 +28,7 @@ import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
import com.seibel.distanthorizons.core.logging.ConfigBasedSpamLogger;
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.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.render.glObject.GLState;
import com.seibel.distanthorizons.core.render.glObject.buffer.GLElementBuffer;
import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
@@ -288,12 +288,12 @@ public class DebugRenderer
this.color = color;
}
public Box(DhSectionPos pos, float minY, float maxY, float marginPercent, Color color)
public Box(OldDhSectionPos pos, float minY, float maxY, float marginPercent, Color color)
{
this(pos.getSectionBBoxPos(), minY, maxY, marginPercent, color);
}
public Box(DhSectionPos pos, float y, float yDiff, Object hash, float marginPercent, Color color)
public Box(OldDhSectionPos pos, float y, float yDiff, Object hash, float marginPercent, Color color)
{
this(pos.getSectionBBoxPos(), y, yDiff, hash, marginPercent, color);
}
@@ -22,21 +22,19 @@ package com.seibel.distanthorizons.core.sql.dto;
import com.seibel.distanthorizons.api.enums.config.EDhApiDataCompressionMode;
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV1;
import com.seibel.distanthorizons.core.dataObjects.render.ColumnRenderSource;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.atomic.AtomicLong;
/**
* Handles storing{@link FullDataSourceV1}'s in the database.
*/
public class FullDataSourceV1DTO implements IBaseDTO<DhSectionPos>
public class FullDataSourceV1DTO implements IBaseDTO<OldDhSectionPos>
{
public DhSectionPos pos;
public OldDhSectionPos pos;
public int checksum;
public byte dataDetailLevel;
public EDhApiWorldGenerationStep worldGenStep;
@@ -54,7 +52,7 @@ public class FullDataSourceV1DTO implements IBaseDTO<DhSectionPos>
// constructor //
//=============//
public FullDataSourceV1DTO(DhSectionPos pos, int checksum, byte dataDetailLevel, EDhApiWorldGenerationStep worldGenStep, String dataType, byte binaryDataFormatVersion, byte[] dataArray)
public FullDataSourceV1DTO(OldDhSectionPos pos, int checksum, byte dataDetailLevel, EDhApiWorldGenerationStep worldGenStep, String dataType, byte binaryDataFormatVersion, byte[] dataArray)
{
this.pos = pos;
this.checksum = checksum;
@@ -83,7 +81,7 @@ public class FullDataSourceV1DTO implements IBaseDTO<DhSectionPos>
//===========//
@Override
public DhSectionPos getKey() { return this.pos; }
public OldDhSectionPos getKey() { return this.pos; }
}
@@ -24,7 +24,7 @@ import com.seibel.distanthorizons.api.enums.config.EDhApiWorldCompressionMode;
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.objects.DataCorruptedException;
@@ -39,12 +39,12 @@ import java.util.zip.Adler32;
import java.util.zip.CheckedOutputStream;
/** handles storing {@link FullDataSourceV2}'s in the database. */
public class FullDataSourceV2DTO implements IBaseDTO<DhSectionPos>
public class FullDataSourceV2DTO implements IBaseDTO<OldDhSectionPos>
{
public static final boolean VALIDATE_INPUT_DATAPOINTS = true;
public DhSectionPos pos;
public OldDhSectionPos pos;
public int levelMinY;
@@ -91,7 +91,7 @@ public class FullDataSourceV2DTO implements IBaseDTO<DhSectionPos>
}
public FullDataSourceV2DTO(
DhSectionPos pos,
OldDhSectionPos pos,
int dataChecksum, byte[] compressedColumnGenStepByteArray, byte[] compressedWorldCompressionModeByteArray, byte dataFormatVersion, byte compressionModeValue, byte[] compressedDataByteArray,
long lastModifiedUnixDateTime, long createdUnixDateTime,
byte[] compressedMappingByteArray, boolean applyToParent,
@@ -342,7 +342,7 @@ public class FullDataSourceV2DTO implements IBaseDTO<DhSectionPos>
return byteArrayOutputStream.toByteArray();
}
private static FullDataPointIdMap readBlobToDataMapping(byte[] compressedMappingByteArray, DhSectionPos pos, @NotNull ILevelWrapper levelWrapper, EDhApiDataCompressionMode compressionModeEnum) throws IOException, InterruptedException, DataCorruptedException
private static FullDataPointIdMap readBlobToDataMapping(byte[] compressedMappingByteArray, OldDhSectionPos pos, @NotNull ILevelWrapper levelWrapper, EDhApiDataCompressionMode compressionModeEnum) throws IOException, InterruptedException, DataCorruptedException
{
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(compressedMappingByteArray);
DhDataInputStream compressedIn = new DhDataInputStream(byteArrayInputStream, compressionModeEnum);
@@ -358,7 +358,7 @@ public class FullDataSourceV2DTO implements IBaseDTO<DhSectionPos>
//===========//
@Override
public DhSectionPos getKey() { return this.pos; }
public OldDhSectionPos getKey() { return this.pos; }
@@ -20,7 +20,6 @@
package com.seibel.distanthorizons.core.sql.repo;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.sql.DatabaseUpdater;
import com.seibel.distanthorizons.core.sql.DbConnectionClosedException;
import com.seibel.distanthorizons.core.sql.dto.IBaseDTO;
@@ -20,7 +20,7 @@
package com.seibel.distanthorizons.core.sql.repo;
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV1DTO;
import com.seibel.distanthorizons.coreapi.util.StringUtil;
@@ -30,7 +30,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class FullDataSourceV1Repo extends AbstractDhRepo<DhSectionPos, FullDataSourceV1DTO>
public class FullDataSourceV1Repo extends AbstractDhRepo<OldDhSectionPos, FullDataSourceV1DTO>
{
public static final String TABLE_NAME = "Legacy_FullData_V1";
@@ -55,7 +55,7 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<DhSectionPos, FullDataS
public String getTableName() { return TABLE_NAME; }
@Override
public String createWhereStatement(DhSectionPos pos) { return "DhSectionPos = '"+pos.serialize()+"'"; }
public String createWhereStatement(OldDhSectionPos pos) { return "DhSectionPos = '"+pos.serialize()+"'"; }
@@ -67,7 +67,7 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<DhSectionPos, FullDataS
public FullDataSourceV1DTO convertDictionaryToDto(Map<String, Object> objectMap) throws ClassCastException
{
String posString = (String) objectMap.get("DhSectionPos");
DhSectionPos pos = DhSectionPos.deserialize(posString);
OldDhSectionPos pos = OldDhSectionPos.deserialize(posString);
// meta data
int checksum = (Integer) objectMap.get("Checksum");
@@ -162,7 +162,7 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<DhSectionPos, FullDataS
/**
* Returns the highest numerical detail level in this table. <Br>
* Returns {@link DhSectionPos#SECTION_MINIMUM_DETAIL_LEVEL} if no data is present.
* Returns {@link OldDhSectionPos#SECTION_MINIMUM_DETAIL_LEVEL} if no data is present.
*/
public int getMaxSectionDetailLevel()
{
@@ -177,7 +177,7 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<DhSectionPos, FullDataS
maxDetailLevel = (int)resultMap.get("maxDetailLevel");
}
return maxDetailLevel + DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
return maxDetailLevel + OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
}
@@ -205,9 +205,9 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<DhSectionPos, FullDataS
}
/** Returns the new "returnCount" positions that need to be migrated */
public ArrayList<DhSectionPos> getPositionsToMigrate(int returnCount)
public ArrayList<OldDhSectionPos> getPositionsToMigrate(int returnCount)
{
ArrayList<DhSectionPos> list = new ArrayList<>();
ArrayList<OldDhSectionPos> list = new ArrayList<>();
List<Map<String, Object>> resultMapList = this.queryDictionary(
"select DhSectionPos " +
@@ -218,14 +218,14 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<DhSectionPos, FullDataS
for (Map<String, Object> resultMap : resultMapList)
{
// returned in the format [sectionDetailLevel,x,z] IE [6,0,0]
DhSectionPos sectionPos = DhSectionPos.deserialize((String) resultMap.get("DhSectionPos"));
OldDhSectionPos sectionPos = OldDhSectionPos.deserialize((String) resultMap.get("DhSectionPos"));
list.add(sectionPos);
}
return list;
}
public void markMigrationFailed(DhSectionPos pos)
public void markMigrationFailed(OldDhSectionPos pos)
{
String sql =
"UPDATE "+this.getTableName()+" \n" +
@@ -260,7 +260,7 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<DhSectionPos, FullDataS
}
}
/** Returns single quote surrounded {@link DhSectionPos} serailzed values */
/** Returns single quote surrounded {@link OldDhSectionPos} serailzed values */
public ArrayList<String> getUnusedDataSourcePositionStringList(int deleteCount)
{
List<Map<String, Object>> deletePosResultMapList = this.queryDictionary(
@@ -22,9 +22,8 @@ package com.seibel.distanthorizons.core.sql.repo;
import com.seibel.distanthorizons.api.enums.config.EDhApiDataCompressionMode;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV2DTO;
import com.seibel.distanthorizons.core.util.objects.DataCorruptedException;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream;
import org.apache.logging.log4j.Logger;
@@ -36,7 +35,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class FullDataSourceV2Repo extends AbstractDhRepo<DhSectionPos, FullDataSourceV2DTO>
public class FullDataSourceV2Repo extends AbstractDhRepo<OldDhSectionPos, FullDataSourceV2DTO>
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
@@ -61,9 +60,9 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<DhSectionPos, FullDataS
public String getTableName() { return "FullData"; }
@Override
public String createWhereStatement(DhSectionPos pos)
public String createWhereStatement(OldDhSectionPos pos)
{
int detailLevel = pos.getDetailLevel() - DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL;
int detailLevel = pos.getDetailLevel() - OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL;
return "DetailLevel = '"+detailLevel+"' AND PosX = '"+pos.getX()+"' AND PosZ = '"+pos.getZ()+"'";
}
@@ -77,10 +76,10 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<DhSectionPos, FullDataS
public FullDataSourceV2DTO convertDictionaryToDto(Map<String, Object> objectMap) throws ClassCastException
{
byte detailLevel = (Byte) objectMap.get("DetailLevel");
byte sectionDetailLevel = (byte) (detailLevel + DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
byte sectionDetailLevel = (byte) (detailLevel + OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
int posX = (Integer) objectMap.get("PosX");
int posZ = (Integer) objectMap.get("PosZ");
DhSectionPos pos = new DhSectionPos(sectionDetailLevel, posX, posZ);
OldDhSectionPos pos = new OldDhSectionPos(sectionDetailLevel, posX, posZ);
int minY = (Integer) objectMap.get("MinY");
int dataChecksum = (Integer) objectMap.get("DataChecksum");
@@ -128,7 +127,7 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<DhSectionPos, FullDataS
PreparedStatement statement = this.createPreparedStatement(sql);
int i = 1;
statement.setObject(i++, dto.pos.getDetailLevel() - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
statement.setObject(i++, dto.pos.getDetailLevel() - OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
statement.setObject(i++, dto.pos.getX());
statement.setObject(i++, dto.pos.getZ());
@@ -190,7 +189,7 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<DhSectionPos, FullDataS
statement.setObject(i++, System.currentTimeMillis()); // last modified unix time
statement.setObject(i++, dto.createdUnixDateTime);
statement.setObject(i++, dto.pos.getDetailLevel() - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
statement.setObject(i++, dto.pos.getDetailLevel() - OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
statement.setObject(i++, dto.pos.getX());
statement.setObject(i++, dto.pos.getZ());
@@ -201,9 +200,9 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<DhSectionPos, FullDataS
// updates //
public void setApplyToParent(DhSectionPos pos, boolean applyToParent) throws SQLException
public void setApplyToParent(OldDhSectionPos pos, boolean applyToParent) throws SQLException
{
int detailLevel = pos.getDetailLevel() - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
int detailLevel = pos.getDetailLevel() - OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
String sql =
"UPDATE "+this.getTableName()+" \n" +
@@ -213,9 +212,9 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<DhSectionPos, FullDataS
this.queryDictionaryFirst(sql);
}
public ArrayList<DhSectionPos> getPositionsToUpdate(int returnCount)
public ArrayList<OldDhSectionPos> getPositionsToUpdate(int returnCount)
{
ArrayList<DhSectionPos> list = new ArrayList<>();
ArrayList<OldDhSectionPos> list = new ArrayList<>();
List<Map<String, Object>> resultMapList = this.queryDictionary(
"select DetailLevel, PosX, PosZ " +
@@ -226,11 +225,11 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<DhSectionPos, FullDataS
for (Map<String, Object> resultMap : resultMapList)
{
byte detailLevel = (Byte) resultMap.get("DetailLevel");
byte sectionDetailLevel = (byte) (detailLevel + DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
byte sectionDetailLevel = (byte) (detailLevel + OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
int posX = (Integer) resultMap.get("PosX");
int posZ = (Integer) resultMap.get("PosZ");
DhSectionPos pos = new DhSectionPos(sectionDetailLevel, posX, posZ);
OldDhSectionPos pos = new OldDhSectionPos(sectionDetailLevel, posX, posZ);
list.add(pos);
}
@@ -238,9 +237,9 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<DhSectionPos, FullDataS
}
/** @return null if nothing exists for this position */
public byte[] getColumnGenerationStepForPos(DhSectionPos pos)
public byte[] getColumnGenerationStepForPos(OldDhSectionPos pos)
{
int detailLevel = pos.getDetailLevel() - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
int detailLevel = pos.getDetailLevel() - OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
Map<String, Object> resultMap = this.queryDictionaryFirst(
"select ColumnGenerationStep, CompressionMode " +
@@ -284,9 +283,9 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<DhSectionPos, FullDataS
//===================//
/** @return every position in this database */
public ArrayList<DhSectionPos> getAllPositions()
public ArrayList<OldDhSectionPos> getAllPositions()
{
ArrayList<DhSectionPos> list = new ArrayList<>();
ArrayList<OldDhSectionPos> list = new ArrayList<>();
List<Map<String, Object>> resultMapList = this.queryDictionary(
"select DetailLevel, PosX, PosZ " +
@@ -295,11 +294,11 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<DhSectionPos, FullDataS
for (Map<String, Object> resultMap : resultMapList)
{
byte detailLevel = (Byte) resultMap.get("DetailLevel");
byte sectionDetailLevel = (byte) (detailLevel + DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
byte sectionDetailLevel = (byte) (detailLevel + OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
int posX = (Integer) resultMap.get("PosX");
int posZ = (Integer) resultMap.get("PosZ");
DhSectionPos pos = new DhSectionPos(sectionDetailLevel, posX, posZ);
OldDhSectionPos pos = new OldDhSectionPos(sectionDetailLevel, posX, posZ);
list.add(pos);
}
@@ -310,9 +309,9 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<DhSectionPos, FullDataS
* @return the size of the full data at the given position
* (doesn't include the size of the mapping or any other column)
*/
public long getDataSizeInBytes(DhSectionPos pos)
public long getDataSizeInBytes(OldDhSectionPos pos)
{
int detailLevel = pos.getDetailLevel() - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
int detailLevel = pos.getDetailLevel() - OldDhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL;
Map<String, Object> resultMap = this.queryDictionaryFirst(
"select LENGTH(Data) as dataSize " +
@@ -20,7 +20,7 @@
package com.seibel.distanthorizons.core.util.objects.quadTree;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.objects.quadTree.iterators.QuadNodeDirectChildIterator;
import com.seibel.distanthorizons.core.util.objects.quadTree.iterators.QuadNodeDirectChildPosIterator;
@@ -35,7 +35,7 @@ public class QuadNode<T>
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
public final DhSectionPos sectionPos;
public final OldDhSectionPos sectionPos;
public final byte minimumDetailLevel;
public T value;
@@ -67,7 +67,7 @@ public class QuadNode<T>
public QuadNode(DhSectionPos sectionPos, byte minimumDetailLevel)
public QuadNode(OldDhSectionPos sectionPos, byte minimumDetailLevel)
{
this.sectionPos = sectionPos;
this.minimumDetailLevel = minimumDetailLevel;
@@ -145,14 +145,14 @@ public class QuadNode<T>
* @return the node at the given position
* @throws IllegalArgumentException if childSectionPos has the wrong detail level or is outside the bounds of this node
*/
public QuadNode<T> getNode(DhSectionPos sectionPos) throws IllegalArgumentException { return this.getOrSetValue(sectionPos, false, null); }
public QuadNode<T> getNode(OldDhSectionPos sectionPos) throws IllegalArgumentException { return this.getOrSetValue(sectionPos, false, null); }
/**
* @param sectionPos must be 1 detail level lower than this node's detail level
* @return the value at the given position before the new value was set
* @throws IllegalArgumentException if childSectionPos has the wrong detail level or is outside the bounds of this node
*/
public T setValue(DhSectionPos sectionPos, T newValue) throws IllegalArgumentException
public T setValue(OldDhSectionPos sectionPos, T newValue) throws IllegalArgumentException
{
QuadNode<T> previousNode = this.getNode(sectionPos);
if (previousNode != null)
@@ -173,7 +173,7 @@ public class QuadNode<T>
* @return the node at the given position before the new node was set (if the new node should be set)
* @throws IllegalArgumentException if childSectionPos has the wrong detail level or is outside the bounds of this
*/
private QuadNode<T> getOrSetValue(DhSectionPos inputSectionPos, boolean replaceValue, T newValue) throws IllegalArgumentException
private QuadNode<T> getOrSetValue(OldDhSectionPos inputSectionPos, boolean replaceValue, T newValue) throws IllegalArgumentException
{
// debug validation
@@ -217,10 +217,10 @@ public class QuadNode<T>
// LOGGER.info((replaceValue ? "set " : "get ")+inputSectionPos+" center block: "+inputSectionPos.getCenter().getCornerBlockPos()+", this pos: "+this.sectionPos+" this center block: "+this.sectionPos.getCenter().getCornerBlockPos());
DhSectionPos nwPos = this.sectionPos.getChildByIndex(0);
DhSectionPos swPos = this.sectionPos.getChildByIndex(1);
DhSectionPos nePos = this.sectionPos.getChildByIndex(2);
DhSectionPos sePos = this.sectionPos.getChildByIndex(3);
OldDhSectionPos nwPos = this.sectionPos.getChildByIndex(0);
OldDhSectionPos swPos = this.sectionPos.getChildByIndex(1);
OldDhSectionPos nePos = this.sectionPos.getChildByIndex(2);
OldDhSectionPos sePos = this.sectionPos.getChildByIndex(3);
// look for the child that contains the input position (there may be a faster way to do this, but this works for now)
QuadNode<T> childNode;
@@ -293,7 +293,7 @@ public class QuadNode<T>
public Iterator<QuadNode<T>> getLeafNodeIterator() { return new QuadTreeNodeIterator<>(this, true); }
/** positions can point to null children */
public Iterator<DhSectionPos> getChildPosIterator() { return new QuadNodeDirectChildPosIterator<>(this); }
public Iterator<OldDhSectionPos> getChildPosIterator() { return new QuadNodeDirectChildPosIterator<>(this); }
public Iterator<QuadNode<T>> getChildNodeIterator() { return new QuadNodeDirectChildIterator<>(this); }
@@ -22,7 +22,7 @@ package com.seibel.distanthorizons.core.util.objects.quadTree;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
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.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.pos.Pos2D;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
@@ -93,9 +93,9 @@ public class QuadTree<T>
//=====================//
/** @return the node at the given section position */
public final QuadNode<T> getNode(DhSectionPos pos) throws IndexOutOfBoundsException { return this.getOrSetNode(pos, false, null, true); }
public final QuadNode<T> getNode(OldDhSectionPos pos) throws IndexOutOfBoundsException { return this.getOrSetNode(pos, false, null, true); }
/** @return the value at the given section position */
public final T getValue(DhSectionPos pos) throws IndexOutOfBoundsException
public final T getValue(OldDhSectionPos pos) throws IndexOutOfBoundsException
{
QuadNode<T> node = this.getNode(pos);
if (node != null)
@@ -106,7 +106,7 @@ public class QuadTree<T>
}
/** @return the value that was previously in the given position, null if nothing */
public final T setValue(DhSectionPos pos, T value) throws IndexOutOfBoundsException
public final T setValue(OldDhSectionPos pos, T value) throws IndexOutOfBoundsException
{
T previousValue = this.getValue(pos);
this.getOrSetNode(pos, true, value, true);
@@ -114,7 +114,7 @@ public class QuadTree<T>
}
/** @param runBoundaryChecks should only ever be set to true internally for removing out of bound nodes */
protected final QuadNode<T> getOrSetNode(DhSectionPos pos, boolean setNewValue, T newValue, boolean runBoundaryChecks) throws IndexOutOfBoundsException
protected final QuadNode<T> getOrSetNode(OldDhSectionPos pos, boolean setNewValue, T newValue, boolean runBoundaryChecks) throws IndexOutOfBoundsException
{
if (runBoundaryChecks && !this.isSectionPosInBounds(pos))
{
@@ -126,7 +126,7 @@ public class QuadTree<T>
DhSectionPos rootPos = pos.convertNewToDetailLevel(this.treeMinDetailLevel);
OldDhSectionPos rootPos = pos.convertNewToDetailLevel(this.treeMinDetailLevel);
int ringListPosX = rootPos.getX();
int ringListPosZ = rootPos.getZ();
@@ -160,7 +160,7 @@ public class QuadTree<T>
return returnNode;
}
public boolean isSectionPosInBounds(DhSectionPos testPos)
public boolean isSectionPosInBounds(OldDhSectionPos testPos)
{
// check if the testPos is within the detail level limits of the tree
boolean detailLevelWithinBounds = this.treeMaxDetailLevel <= testPos.getDetailLevel() && testPos.getDetailLevel() <= this.treeMinDetailLevel;
@@ -174,7 +174,7 @@ public class QuadTree<T>
DhBlockPos2D treeBlockCorner = this.centerBlockPos.add(new DhBlockPos2D(-this.diameterInBlocks / 2, -this.diameterInBlocks / 2));
DhLodPos treeCornerPos = new DhLodPos((byte) 0, treeBlockCorner.x, treeBlockCorner.z);
DhSectionPos inputSectionCorner = testPos.convertNewToDetailLevel((byte) 0);
OldDhSectionPos inputSectionCorner = testPos.convertNewToDetailLevel((byte) 0);
DhLodPos inputCornerPos = new DhLodPos((byte) 0, inputSectionCorner.getX(), inputSectionCorner.getZ());
int inputBlockWidth = BitShiftUtil.powerOfTwo(testPos.getDetailLevel());
@@ -202,13 +202,13 @@ public class QuadTree<T>
}
public int getNonNullChildCountAtPos(DhSectionPos pos) { return this.getChildCountAtPos(pos, false); }
public int getChildCountAtPos(DhSectionPos pos, boolean includeNullValues)
public int getNonNullChildCountAtPos(OldDhSectionPos pos) { return this.getChildCountAtPos(pos, false); }
public int getChildCountAtPos(OldDhSectionPos pos, boolean includeNullValues)
{
int childCount = 0;
for (int i = 0; i < 4; i++)
{
DhSectionPos childPos = pos.getChildByIndex(i);
OldDhSectionPos childPos = pos.getChildByIndex(i);
if (this.isSectionPosInBounds(childPos))
{
T value = this.getValue(childPos);
@@ -229,7 +229,7 @@ public class QuadTree<T>
//===========//
/** can include null nodes */
public Iterator<DhSectionPos> rootNodePosIterator() { return new QuadTreeRootPosIterator(true); }
public Iterator<OldDhSectionPos> rootNodePosIterator() { return new QuadTreeRootPosIterator(true); }
public Iterator<QuadNode<T>> nodeIterator() { return new QuadTreeNodeIterator(false); }
public Iterator<QuadNode<T>> leafNodeIterator() { return new QuadTreeNodeIterator(true); }
@@ -394,9 +394,9 @@ public class QuadTree<T>
// iterator classes //
//==================//
private class QuadTreeRootPosIterator implements Iterator<DhSectionPos>
private class QuadTreeRootPosIterator implements Iterator<OldDhSectionPos>
{
private final Queue<DhSectionPos> iteratorPosQueue = new ArrayDeque<>();
private final Queue<OldDhSectionPos> iteratorPosQueue = new ArrayDeque<>();
@@ -407,7 +407,7 @@ public class QuadTree<T>
if (node != null || includeNullNodes)
{
// TODO can these DhSectionPos be pooled?
DhSectionPos rootPos = new DhSectionPos(QuadTree.this.treeMinDetailLevel, pos2D.x, pos2D.y);
OldDhSectionPos rootPos = new OldDhSectionPos(QuadTree.this.treeMinDetailLevel, pos2D.x, pos2D.y);
if (QuadTree.this.isSectionPosInBounds(rootPos))
{
this.iteratorPosQueue.add(rootPos);
@@ -422,7 +422,7 @@ public class QuadTree<T>
public boolean hasNext() { return this.iteratorPosQueue.size() != 0; }
@Override
public DhSectionPos next()
public OldDhSectionPos next()
{
if (this.iteratorPosQueue.size() == 0)
{
@@ -430,7 +430,7 @@ public class QuadTree<T>
}
DhSectionPos sectionPos = this.iteratorPosQueue.poll();
OldDhSectionPos sectionPos = this.iteratorPosQueue.poll();
return sectionPos;
}
@@ -440,7 +440,7 @@ public class QuadTree<T>
public void remove() { throw new UnsupportedOperationException("remove"); }
@Override
public void forEachRemaining(Consumer<? super DhSectionPos> action) { Iterator.super.forEachRemaining(action); }
public void forEachRemaining(Consumer<? super OldDhSectionPos> action) { Iterator.super.forEachRemaining(action); }
}
@@ -498,7 +498,7 @@ public class QuadTree<T>
Iterator<QuadNode<T>> nodeIterator = null;
while ((nodeIterator == null || !nodeIterator.hasNext()) && this.rootNodeIterator.hasNext())
{
DhSectionPos sectionPos = this.rootNodeIterator.next();
OldDhSectionPos sectionPos = this.rootNodeIterator.next();
QuadNode<T> rootNode = QuadTree.this.getNode(sectionPos);
if (rootNode != null)
{
@@ -19,14 +19,14 @@
package com.seibel.distanthorizons.core.util.objects.quadTree.iterators;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.util.objects.quadTree.QuadNode;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.function.Consumer;
public class QuadNodeDirectChildPosIterator<T> implements Iterator<DhSectionPos>
public class QuadNodeDirectChildPosIterator<T> implements Iterator<OldDhSectionPos>
{
private final QuadNodeChildIndexIterator<T> childIndexIterator;
private final QuadNode<T> parentNode;
@@ -44,7 +44,7 @@ public class QuadNodeDirectChildPosIterator<T> implements Iterator<DhSectionPos>
public boolean hasNext() { return this.childIndexIterator.hasNext(); }
@Override
public DhSectionPos next()
public OldDhSectionPos next()
{
if (!this.hasNext())
{
@@ -53,7 +53,7 @@ public class QuadNodeDirectChildPosIterator<T> implements Iterator<DhSectionPos>
int childIndex = this.childIndexIterator.next();
DhSectionPos sectionPos = this.parentNode.sectionPos.getChildByIndex(childIndex);
OldDhSectionPos sectionPos = this.parentNode.sectionPos.getChildByIndex(childIndex);
return sectionPos;
}
@@ -63,6 +63,6 @@ public class QuadNodeDirectChildPosIterator<T> implements Iterator<DhSectionPos>
public void remove() { throw new UnsupportedOperationException("remove"); }
@Override
public void forEachRemaining(Consumer<? super DhSectionPos> action) { Iterator.super.forEachRemaining(action); }
public void forEachRemaining(Consumer<? super OldDhSectionPos> action) { Iterator.super.forEachRemaining(action); }
}
@@ -1,7 +1,7 @@
package com.seibel.distanthorizons.core.util.threading;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.util.ThreadUtil;
import org.apache.logging.log4j.Logger;
@@ -15,7 +15,7 @@ import java.util.concurrent.locks.ReentrantLock;
/**
* Handles creating and destroying {@link ReentrantLock}'s for
* a given {@link DhSectionPos}.
* a given {@link OldDhSectionPos}.
* This is necessary since we need an unlimited number of locks
* when handling data updating, but we don't want to infinitely create locks.
* This provider will create/destroy locks as necessary given the current requirements by the file handlers.
@@ -32,7 +32,7 @@ public class PositionalLockProvider
private static final int MAX_NUMBER_OF_LOCKS = 100;
private final ConcurrentHashMap<DhSectionPos, ExpiringLock> lockByPos = new ConcurrentHashMap<>();
private final ConcurrentHashMap<OldDhSectionPos, ExpiringLock> lockByPos = new ConcurrentHashMap<>();
private final AtomicBoolean lockRemovalThreadRunning = new AtomicBoolean(false);
@@ -50,7 +50,7 @@ public class PositionalLockProvider
// getter //
//========//
public ReentrantLock getLock(DhSectionPos pos)
public ReentrantLock getLock(OldDhSectionPos pos)
{
return this.lockByPos.compute(pos, (ignorePos, lock) ->
{
@@ -76,14 +76,14 @@ public class PositionalLockProvider
Thread.sleep(CLEANUP_THREAD_MAX_FREQUENCY_IN_MS);
// walk over every lock and check which ones need to be removed
Iterator<DhSectionPos> keySet = this.lockByPos.keySet().iterator();
Iterator<OldDhSectionPos> keySet = this.lockByPos.keySet().iterator();
while (keySet.hasNext())
{
try
{
long currentTime = System.currentTimeMillis();
DhSectionPos pos = keySet.next();
OldDhSectionPos pos = keySet.next();
ExpiringLock lock = this.lockByPos.get(pos);
// don't try removing a lock that's currently in use
@@ -21,7 +21,7 @@ package tests;
import com.seibel.distanthorizons.api.enums.config.EDhApiDataCompressionMode;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV2DTO;
import com.seibel.distanthorizons.core.sql.repo.FullDataSourceV2Repo;
import org.junit.Assert;
@@ -272,7 +272,7 @@ public class CompressionTest
ArrayList<DhSectionPos> positionList = uncompressedRepo.getAllPositions();
ArrayList<OldDhSectionPos> positionList = uncompressedRepo.getAllPositions();
totalUncompressedFileSizeInBytes = uncompressedRepo.getTotalDataSizeInBytes();
System.out.println("Found [" + positionList.size() + "] DTOs.");
@@ -282,7 +282,7 @@ public class CompressionTest
{
try
{
DhSectionPos pos = positionList.get(i);
OldDhSectionPos pos = positionList.get(i);
if (i % 20 == 0)
{
System.out.println(i + "/" + maxTestPosition);
+82 -82
View File
@@ -28,36 +28,36 @@ public class DhSectionPosTest
@Test
public void ContainsPosTest()
{
DhSectionPos root = new DhSectionPos((byte) 10, 0, 0);
DhSectionPos child = new DhSectionPos((byte) 9, 1, 1);
OldDhSectionPos root = new OldDhSectionPos((byte) 10, 0, 0);
OldDhSectionPos child = new OldDhSectionPos((byte) 9, 1, 1);
Assert.assertTrue("section pos contains fail", root.contains(child));
Assert.assertFalse("section pos contains fail", child.contains(root));
root = new DhSectionPos((byte) 10, 1, 0);
root = new OldDhSectionPos((byte) 10, 1, 0);
// out of bounds
child = new DhSectionPos((byte) 9, 0, 0);
child = new OldDhSectionPos((byte) 9, 0, 0);
Assert.assertFalse("position should be out of bounds", root.contains(child));
child = new DhSectionPos((byte) 9, 1, 1);
child = new OldDhSectionPos((byte) 9, 1, 1);
Assert.assertFalse("position should be out of bounds", root.contains(child));
// in bounds
child = new DhSectionPos((byte) 9, 2, 0);
child = new OldDhSectionPos((byte) 9, 2, 0);
Assert.assertTrue("position should be in bounds", root.contains(child));
child = new DhSectionPos((byte) 9, 3, 1);
child = new OldDhSectionPos((byte) 9, 3, 1);
Assert.assertTrue("position should be in bounds", root.contains(child));
// out of bounds
child = new DhSectionPos((byte) 9, 2, 2);
child = new OldDhSectionPos((byte) 9, 2, 2);
Assert.assertFalse("position should be out of bounds", root.contains(child));
child = new DhSectionPos((byte) 9, 3, 3);
child = new OldDhSectionPos((byte) 9, 3, 3);
Assert.assertFalse("position should be out of bounds", root.contains(child));
child = new DhSectionPos((byte) 9, 4, 4);
child = new OldDhSectionPos((byte) 9, 4, 4);
Assert.assertFalse("position should be out of bounds", root.contains(child));
child = new DhSectionPos((byte) 9, 5, 5);
child = new OldDhSectionPos((byte) 9, 5, 5);
Assert.assertFalse("position should be out of bounds", root.contains(child));
}
@@ -65,15 +65,15 @@ public class DhSectionPosTest
public void ContainsAdjacentPosTest()
{
// neither should contain the other, they are single blocks that are next to each other
DhSectionPos left = new DhSectionPos((byte) 0, 4606, 0);
DhSectionPos right = new DhSectionPos((byte) 0, 4607, 0);
OldDhSectionPos left = new OldDhSectionPos((byte) 0, 4606, 0);
OldDhSectionPos right = new OldDhSectionPos((byte) 0, 4607, 0);
Assert.assertFalse(left.contains(right));
Assert.assertFalse(right.contains(left));
// 512 block wide sections that are adjacent, but not overlapping
left = new DhSectionPos((byte) 9, 0, 0);
right = new DhSectionPos((byte) 9, 1, 0);
left = new OldDhSectionPos((byte) 9, 0, 0);
right = new OldDhSectionPos((byte) 9, 1, 0);
Assert.assertFalse(left.contains(right));
Assert.assertFalse(right.contains(left));
@@ -82,24 +82,24 @@ public class DhSectionPosTest
@Test
public void ParentPosTest()
{
DhSectionPos leaf = new DhSectionPos((byte) 0, 0, 0);
DhSectionPos convert = leaf.convertNewToDetailLevel((byte) 1);
DhSectionPos parent = leaf.getParentPos();
OldDhSectionPos leaf = new OldDhSectionPos((byte) 0, 0, 0);
OldDhSectionPos convert = leaf.convertNewToDetailLevel((byte) 1);
OldDhSectionPos parent = leaf.getParentPos();
Assert.assertEquals("get parent at 0,0 fail", convert, parent);
leaf = new DhSectionPos((byte) 0, 1, 1);
leaf = new OldDhSectionPos((byte) 0, 1, 1);
convert = leaf.convertNewToDetailLevel((byte) 1);
parent = leaf.getParentPos();
Assert.assertEquals("get parent at 1,1 fail", convert, parent);
leaf = new DhSectionPos((byte) 1, 2, 2);
leaf = new OldDhSectionPos((byte) 1, 2, 2);
convert = leaf.convertNewToDetailLevel((byte) 2);
parent = leaf.getParentPos();
Assert.assertEquals("parent upscale fail", convert, parent);
convert = leaf.convertNewToDetailLevel((byte) 0);
DhSectionPos childIndex = leaf.getChildByIndex(0);
OldDhSectionPos childIndex = leaf.getChildByIndex(0);
Assert.assertEquals("child detail fail", convert, childIndex);
}
@@ -107,11 +107,11 @@ public class DhSectionPosTest
@Test
public void ChildPosTest()
{
DhSectionPos node = new DhSectionPos((byte) 1, 2302, 0);
DhSectionPos nw = node.getChildByIndex(0);
DhSectionPos sw = node.getChildByIndex(1);
DhSectionPos ne = node.getChildByIndex(2);
DhSectionPos se = node.getChildByIndex(3);
OldDhSectionPos node = new OldDhSectionPos((byte) 1, 2302, 0);
OldDhSectionPos nw = node.getChildByIndex(0);
OldDhSectionPos sw = node.getChildByIndex(1);
OldDhSectionPos ne = node.getChildByIndex(2);
OldDhSectionPos se = node.getChildByIndex(3);
// confirm no children have the same values
Assert.assertNotEquals(nw, sw);
@@ -119,24 +119,24 @@ public class DhSectionPosTest
Assert.assertNotEquals(ne, se);
// confirm each child has the correct value
Assert.assertEquals(nw, new DhSectionPos((byte) 0, 4604, 0));
Assert.assertEquals(sw, new DhSectionPos((byte) 0, 4605, 0));
Assert.assertEquals(ne, new DhSectionPos((byte) 0, 4604, 1));
Assert.assertEquals(se, new DhSectionPos((byte) 0, 4605, 1));
Assert.assertEquals(nw, new OldDhSectionPos((byte) 0, 4604, 0));
Assert.assertEquals(sw, new OldDhSectionPos((byte) 0, 4605, 0));
Assert.assertEquals(ne, new OldDhSectionPos((byte) 0, 4604, 1));
Assert.assertEquals(se, new OldDhSectionPos((byte) 0, 4605, 1));
}
@Test
public void GetCenterTest()
{
DhSectionPos node = new DhSectionPos((byte) 1, 2303, 0);
OldDhSectionPos node = new OldDhSectionPos((byte) 1, 2303, 0);
DhBlockPos2D centerBlockPos = node.getCenterBlockPos();
DhBlockPos2D expectedCenterNode = new DhBlockPos2D(4606, 0);
Assert.assertEquals("", expectedCenterNode, centerBlockPos);
node = new DhSectionPos((byte) 10, 0, 0); // 1024 blocks wide
node = new OldDhSectionPos((byte) 10, 0, 0); // 1024 blocks wide
centerBlockPos = node.getCenterBlockPos();
expectedCenterNode = new DhBlockPos2D(1024 / 2, 1024 / 2);
Assert.assertEquals("", expectedCenterNode, centerBlockPos);
@@ -146,8 +146,8 @@ public class DhSectionPosTest
@Test
public void GetCenter2Test()
{
DhSectionPos parentNode = new DhSectionPos((byte) 2, 1151, 0); // width 4 blocks
DhSectionPos inputPos = new DhSectionPos((byte) 0, 4606, 0); // width 1 block
OldDhSectionPos parentNode = new OldDhSectionPos((byte) 2, 1151, 0); // width 4 blocks
OldDhSectionPos inputPos = new OldDhSectionPos((byte) 0, 4606, 0); // width 1 block
Assert.assertTrue(parentNode.contains(inputPos));
DhBlockPos2D parentCenter = parentNode.getCenterBlockPos();
@@ -164,19 +164,19 @@ public class DhSectionPosTest
// origin pos //
DhBlockPos originBlockPos = new DhBlockPos(0, 0, 0);
DhSectionPos originSectionPos = new DhSectionPos(originBlockPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0), originSectionPos);
OldDhSectionPos originSectionPos = new OldDhSectionPos(originBlockPos);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0), originSectionPos);
// offset pos //
DhBlockPos offsetBlockPos = new DhBlockPos(1000, 0, 42000);
DhSectionPos offsetSectionPos = new DhSectionPos(offsetBlockPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 15, 656), offsetSectionPos);
OldDhSectionPos offsetSectionPos = new OldDhSectionPos(offsetBlockPos);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 15, 656), offsetSectionPos);
offsetBlockPos = new DhBlockPos(-987654, 0, 46);
offsetSectionPos = new DhSectionPos(offsetBlockPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, -15433, 0), offsetSectionPos);
offsetSectionPos = new OldDhSectionPos(offsetBlockPos);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, -15433, 0), offsetSectionPos);
}
@@ -186,19 +186,19 @@ public class DhSectionPosTest
// origin pos //
DhBlockPos2D originBlockPos = new DhBlockPos2D(0, 0);
DhSectionPos originSectionPos = new DhSectionPos(originBlockPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0), originSectionPos);
OldDhSectionPos originSectionPos = new OldDhSectionPos(originBlockPos);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0), originSectionPos);
// offset pos //
DhBlockPos2D offsetBlockPos = new DhBlockPos2D(1000, 42000);
DhSectionPos offsetSectionPos = new DhSectionPos(offsetBlockPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 15, 656), offsetSectionPos);
OldDhSectionPos offsetSectionPos = new OldDhSectionPos(offsetBlockPos);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 15, 656), offsetSectionPos);
offsetBlockPos = new DhBlockPos2D(-987654, 46);
offsetSectionPos = new DhSectionPos(offsetBlockPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, -15433, 0), offsetSectionPos);
offsetSectionPos = new OldDhSectionPos(offsetBlockPos);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, -15433, 0), offsetSectionPos);
}
@@ -208,19 +208,19 @@ public class DhSectionPosTest
// origin pos //
DhChunkPos originChunkPos = new DhChunkPos(0,0);
DhSectionPos originSectionPos = new DhSectionPos(originChunkPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL, 0, 0), originSectionPos);
OldDhSectionPos originSectionPos = new OldDhSectionPos(originChunkPos);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_CHUNK_DETAIL_LEVEL, 0, 0), originSectionPos);
// offset pos //
DhChunkPos offsetChunkPos = new DhChunkPos(1000, 42000);
DhSectionPos offsetSectionPos = new DhSectionPos(offsetChunkPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL, 15, 656), offsetSectionPos);
OldDhSectionPos offsetSectionPos = new OldDhSectionPos(offsetChunkPos);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_CHUNK_DETAIL_LEVEL, 15, 656), offsetSectionPos);
offsetChunkPos = new DhChunkPos(-987654, 46);
offsetSectionPos = new DhSectionPos(offsetChunkPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL, -15433, 0), offsetSectionPos);
offsetSectionPos = new OldDhSectionPos(offsetChunkPos);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_CHUNK_DETAIL_LEVEL, -15433, 0), offsetSectionPos);
}
@@ -229,38 +229,38 @@ public class DhSectionPosTest
{
// origin pos //
DhSectionPos originSectionPos = new DhSectionPos((byte) 0,0,0);
OldDhSectionPos originSectionPos = new OldDhSectionPos((byte) 0,0,0);
originSectionPos = originSectionPos.convertNewToDetailLevel((byte) 1);
Assert.assertEquals(new DhSectionPos((byte) 1, 0, 0), originSectionPos);
Assert.assertEquals(new OldDhSectionPos((byte) 1, 0, 0), originSectionPos);
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0), originSectionPos);
originSectionPos = originSectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0), originSectionPos);
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, 0, 0), originSectionPos);
originSectionPos = originSectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_REGION_DETAIL_LEVEL, 0, 0), originSectionPos);
// offset pos //
DhSectionPos sectionPos = new DhSectionPos((byte) 0,-10000,5000);
OldDhSectionPos sectionPos = new OldDhSectionPos((byte) 0,-10000,5000);
sectionPos = sectionPos.convertNewToDetailLevel((byte) 1);
Assert.assertEquals(new DhSectionPos((byte) 1, -5000, 2500), sectionPos);
Assert.assertEquals(new OldDhSectionPos((byte) 1, -5000, 2500), sectionPos);
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, -157, 78), sectionPos);
sectionPos = sectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, -157, 78), sectionPos);
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, -1, 0), sectionPos);
sectionPos = sectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(new OldDhSectionPos(OldDhSectionPos.SECTION_REGION_DETAIL_LEVEL, -1, 0), sectionPos);
}
@Test
public void GetOffsetWidth()
{
DhSectionPos originSectionPos = new DhSectionPos((byte) 0,0,0);
DhSectionPos sectionPos = new DhSectionPos((byte) 0,-10000,5000);
OldDhSectionPos originSectionPos = new OldDhSectionPos((byte) 0,0,0);
OldDhSectionPos sectionPos = new OldDhSectionPos((byte) 0,-10000,5000);
@@ -284,19 +284,19 @@ public class DhSectionPosTest
// Block -> 0
returnDetailLevel = 0;
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
originSectionPos = originSectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(64, originSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel));
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
sectionPos = sectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(64, sectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel));
// Region -> 3
returnDetailLevel = 3;
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
originSectionPos = originSectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(4096, originSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel));
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
sectionPos = sectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(4096, sectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel));
}
@@ -304,8 +304,8 @@ public class DhSectionPosTest
@Test
public void GetBlockWidth()
{
DhSectionPos originSectionPos = new DhSectionPos((byte) 0,0,0);
DhSectionPos sectionPos = new DhSectionPos((byte) 0,-10000,5000);
OldDhSectionPos originSectionPos = new OldDhSectionPos((byte) 0,0,0);
OldDhSectionPos sectionPos = new OldDhSectionPos((byte) 0,-10000,5000);
Assert.assertEquals(1, originSectionPos.getBlockWidth());
@@ -316,14 +316,14 @@ public class DhSectionPosTest
sectionPos = sectionPos.convertNewToDetailLevel((byte) 1);
Assert.assertEquals(2, sectionPos.getBlockWidth());
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
originSectionPos = originSectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(64, originSectionPos.getBlockWidth());
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
sectionPos = sectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(64, sectionPos.getBlockWidth());
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
originSectionPos = originSectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(32768, originSectionPos.getBlockWidth());
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
sectionPos = sectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(32768, sectionPos.getBlockWidth());
}
@@ -331,8 +331,8 @@ public class DhSectionPosTest
@Test
public void GetCenterBlockPos()
{
DhSectionPos originSectionPos = new DhSectionPos((byte) 0,0,0);
DhSectionPos sectionPos = new DhSectionPos((byte) 0,-10000,5000);
OldDhSectionPos originSectionPos = new OldDhSectionPos((byte) 0,0,0);
OldDhSectionPos sectionPos = new OldDhSectionPos((byte) 0,-10000,5000);
Assert.assertEquals(new DhBlockPos2D(0, 0), originSectionPos.getCenterBlockPos());
@@ -345,15 +345,15 @@ public class DhSectionPosTest
Assert.assertEquals(new DhBlockPos2D(-10000, 5000), sectionPos.getCenterBlockPos());
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
originSectionPos = originSectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(new DhBlockPos2D(32, 32), originSectionPos.getCenterBlockPos());
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
sectionPos = sectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(new DhBlockPos2D(-10016, 5024), sectionPos.getCenterBlockPos());
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
originSectionPos = originSectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(new DhBlockPos2D(16384, 16384), originSectionPos.getCenterBlockPos());
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
sectionPos = sectionPos.convertNewToDetailLevel(OldDhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(new DhBlockPos2D(-16384, 16384), sectionPos.getCenterBlockPos());
}
+120 -120
View File
@@ -21,7 +21,7 @@ package tests;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.coreapi.util.MathUtil;
@@ -59,30 +59,30 @@ public class QuadTreeTest
// (pseudo) root node //
testSet(tree, new DhSectionPos((byte) 10, 0, 0), 0);
testSet(tree, new OldDhSectionPos((byte) 10, 0, 0), 0);
// first child (0,0) //
testSet(tree, new DhSectionPos((byte) 9, 0, 0), 1);
testSet(tree, new DhSectionPos((byte) 9, 1, 0), 2);
testSet(tree, new DhSectionPos((byte) 9, 0, 1), 3);
testSet(tree, new DhSectionPos((byte) 9, 1, 1), 4);
testSet(tree, new OldDhSectionPos((byte) 9, 0, 0), 1);
testSet(tree, new OldDhSectionPos((byte) 9, 1, 0), 2);
testSet(tree, new OldDhSectionPos((byte) 9, 0, 1), 3);
testSet(tree, new OldDhSectionPos((byte) 9, 1, 1), 4);
// second child (0,0) (0,0) //
testSet(tree, new DhSectionPos((byte) 8, 0, 0), 5);
testSet(tree, new DhSectionPos((byte) 8, 1, 0), 6);
testSet(tree, new DhSectionPos((byte) 8, 0, 1), 7);
testSet(tree, new DhSectionPos((byte) 8, 1, 1), 8);
testSet(tree, new OldDhSectionPos((byte) 8, 0, 0), 5);
testSet(tree, new OldDhSectionPos((byte) 8, 1, 0), 6);
testSet(tree, new OldDhSectionPos((byte) 8, 0, 1), 7);
testSet(tree, new OldDhSectionPos((byte) 8, 1, 1), 8);
// second child (0,0) (1,1) //
testSet(tree, new DhSectionPos((byte) 8, 2, 2), 9);
testSet(tree, new DhSectionPos((byte) 8, 3, 2), 10);
testSet(tree, new DhSectionPos((byte) 8, 2, 3), 11);
testSet(tree, new DhSectionPos((byte) 8, 3, 3), 12);
testSet(tree, new OldDhSectionPos((byte) 8, 2, 2), 9);
testSet(tree, new OldDhSectionPos((byte) 8, 3, 2), 10);
testSet(tree, new OldDhSectionPos((byte) 8, 2, 3), 11);
testSet(tree, new OldDhSectionPos((byte) 8, 3, 3), 12);
// third child (0,0) (1,0) (0,0) //
testSet(tree, new DhSectionPos((byte) 7, 5, 0), 9);
testSet(tree, new DhSectionPos((byte) 7, 6, 0), 10);
testSet(tree, new DhSectionPos((byte) 7, 5, 1), 11);
testSet(tree, new DhSectionPos((byte) 7, 6, 1), 12);
testSet(tree, new OldDhSectionPos((byte) 7, 5, 0), 9);
testSet(tree, new OldDhSectionPos((byte) 7, 6, 0), 10);
testSet(tree, new OldDhSectionPos((byte) 7, 5, 1), 11);
testSet(tree, new OldDhSectionPos((byte) 7, 6, 1), 12);
}
@@ -94,13 +94,13 @@ public class QuadTreeTest
// root node //
testSet(tree, new DhSectionPos((byte) 10, -1, -1), 0);
testSet(tree, new OldDhSectionPos((byte) 10, -1, -1), 0);
// first child (-1,-1) //
testSet(tree, new DhSectionPos((byte) 9, -2, -1), 1);
testSet(tree, new DhSectionPos((byte) 9, -1, -1), 2);
testSet(tree, new DhSectionPos((byte) 9, -2, -2), 3);
testSet(tree, new DhSectionPos((byte) 9, -1, -2), 4);
testSet(tree, new OldDhSectionPos((byte) 9, -2, -1), 1);
testSet(tree, new OldDhSectionPos((byte) 9, -1, -1), 2);
testSet(tree, new OldDhSectionPos((byte) 9, -2, -2), 3);
testSet(tree, new OldDhSectionPos((byte) 9, -1, -2), 4);
// TODO
// // second child (-1,-1) (0,0) //
@@ -131,36 +131,36 @@ public class QuadTreeTest
// wrong detail level on purpose, if the detail level was 0 (block) this should work
DhSectionPos outOfBoundsPos = new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2), 0);
OldDhSectionPos outOfBoundsPos = new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2), 0);
testSet(tree, outOfBoundsPos, -1, IndexOutOfBoundsException.class);
Assert.assertEquals("incorrect leaf node count", 0, tree.leafNodeCount());
// out of bounds //
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) + 1, 0);
outOfBoundsPos = new OldDhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) + 1, 0);
testSet(tree, outOfBoundsPos, -1, IndexOutOfBoundsException.class);
Assert.assertEquals("incorrect leaf node count", 0, tree.leafNodeCount());
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2), 0);
outOfBoundsPos = new OldDhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2), 0);
testSet(tree, outOfBoundsPos, -1, IndexOutOfBoundsException.class);
Assert.assertEquals("incorrect leaf node count", 0, tree.leafNodeCount());
// in bounds //
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) - 1, 0);
outOfBoundsPos = new OldDhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) - 1, 0);
testSet(tree, outOfBoundsPos, 0);
Assert.assertEquals("incorrect leaf node count", 1, tree.leafNodeCount());
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) - 3, 0);
outOfBoundsPos = new OldDhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) - 3, 0);
testSet(tree, outOfBoundsPos, 0);
Assert.assertEquals("incorrect leaf node count", 2, tree.leafNodeCount());
// TODO this position probably has trouble with getting the center.
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) - 2, 0);
outOfBoundsPos = new OldDhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) - 2, 0);
testSet(tree, outOfBoundsPos, 0);
Assert.assertEquals("incorrect leaf node count", 3, tree.leafNodeCount());
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) - 4, 0);
outOfBoundsPos = new OldDhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) - 4, 0);
testSet(tree, outOfBoundsPos, 0);
Assert.assertEquals("incorrect leaf node count", 4, tree.leafNodeCount());
@@ -173,15 +173,15 @@ public class QuadTreeTest
Assert.assertEquals("Test may need to be re-calculated for different max detail level.", 9, tree.treeMinDetailLevel);
DhSectionPos rootPos = new DhSectionPos((byte) 9, 0, -1);
OldDhSectionPos rootPos = new OldDhSectionPos((byte) 9, 0, -1);
testSet(tree, rootPos, 1);
// pos is in tree, but out of range
DhSectionPos midPos = new DhSectionPos((byte) 8, 0, -1);
OldDhSectionPos midPos = new OldDhSectionPos((byte) 8, 0, -1);
testSet(tree, midPos, 2, IndexOutOfBoundsException.class);
// pos is in tree, but out of range
DhSectionPos leafPos = new DhSectionPos((byte) 7, 0, -2);
OldDhSectionPos leafPos = new OldDhSectionPos((byte) 7, 0, -2);
testSet(tree, leafPos, 3, IndexOutOfBoundsException.class);
}
@@ -197,13 +197,13 @@ public class QuadTreeTest
// (pseudo) root nodes //
testSet(tree, new DhSectionPos((byte) 10, 0, 0), 1);
testSet(tree, new OldDhSectionPos((byte) 10, 0, 0), 1);
// first child (0,0) //
DhSectionPos nw = new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0);
DhSectionPos ne = new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 1, 0);
DhSectionPos sw = new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 1);
DhSectionPos se = new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 1, 1);
OldDhSectionPos nw = new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0);
OldDhSectionPos ne = new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 1, 0);
OldDhSectionPos sw = new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 1);
OldDhSectionPos se = new OldDhSectionPos(OldDhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 1, 1);
testSet(tree, nw, 2);
testSet(tree, ne, 3);
@@ -259,12 +259,12 @@ public class QuadTreeTest
Assert.assertEquals("Tree center incorrect", DhBlockPos2D.ZERO, tree.getCenterBlockPos());
// on the negative X edge
DhSectionPos edgePos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, -treeParams.getWidthInBlocks() / 2, 0);
OldDhSectionPos edgePos = new OldDhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, -treeParams.getWidthInBlocks() / 2, 0);
testSet(tree, edgePos, 1);
Assert.assertEquals("incorrect leaf node count", 1, tree.leafNodeCount());
// +1 root node from the negative X edge
DhSectionPos adjacentEdgePos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (-treeParams.getWidthInBlocks() / 2) + pseudoRootNodeWidthInBlocks, 0);
OldDhSectionPos adjacentEdgePos = new OldDhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (-treeParams.getWidthInBlocks() / 2) + pseudoRootNodeWidthInBlocks, 0);
testSet(tree, adjacentEdgePos, 2);
Assert.assertEquals("incorrect leaf node count", 2, tree.leafNodeCount());
@@ -284,21 +284,21 @@ public class QuadTreeTest
// (pseudo) root nodes //
testSet(tree, new DhSectionPos((byte) 10, 0, 0), 1);
testSet(tree, new DhSectionPos((byte) 10, 1, 0), 2);
testSet(tree, new OldDhSectionPos((byte) 10, 0, 0), 1);
testSet(tree, new OldDhSectionPos((byte) 10, 1, 0), 2);
// first child (0,0) //
testSet(tree, new DhSectionPos((byte) 9, 0, 0), 3);
testSet(tree, new DhSectionPos((byte) 9, 1, 0), 4);
testSet(tree, new DhSectionPos((byte) 9, 0, 1), 5);
testSet(tree, new DhSectionPos((byte) 9, 1, 1), 6);
testSet(tree, new OldDhSectionPos((byte) 9, 0, 0), 3);
testSet(tree, new OldDhSectionPos((byte) 9, 1, 0), 4);
testSet(tree, new OldDhSectionPos((byte) 9, 0, 1), 5);
testSet(tree, new OldDhSectionPos((byte) 9, 1, 1), 6);
// root nodes
int rootNodeCount = 0;
Iterator<DhSectionPos> rootNodePosIterator = tree.rootNodePosIterator();
Iterator<OldDhSectionPos> rootNodePosIterator = tree.rootNodePosIterator();
while (rootNodePosIterator.hasNext())
{
QuadNode<Integer> rootNode = tree.getNode(rootNodePosIterator.next());
@@ -332,19 +332,19 @@ public class QuadTreeTest
public void NewQuadTreeIterationTest()
{
AbstractTestTreeParams treeParams = new LargeTestTree();
QuadNode<Integer> rootNode = new QuadNode<>(new DhSectionPos((byte) 10, 0, 0), LodUtil.BLOCK_DETAIL_LEVEL);
QuadNode<Integer> rootNode = new QuadNode<>(new OldDhSectionPos((byte) 10, 0, 0), LodUtil.BLOCK_DETAIL_LEVEL);
rootNode.setValue(new DhSectionPos((byte) 10, 0, 0), 0);
rootNode.setValue(new OldDhSectionPos((byte) 10, 0, 0), 0);
rootNode.setValue(new DhSectionPos((byte) 9, 0, 0), 1);
rootNode.setValue(new DhSectionPos((byte) 9, 1, 0), 1);
rootNode.setValue(new DhSectionPos((byte) 9, 0, 1), 1);
rootNode.setValue(new DhSectionPos((byte) 9, 1, 1), null);
rootNode.setValue(new OldDhSectionPos((byte) 9, 0, 0), 1);
rootNode.setValue(new OldDhSectionPos((byte) 9, 1, 0), 1);
rootNode.setValue(new OldDhSectionPos((byte) 9, 0, 1), 1);
rootNode.setValue(new OldDhSectionPos((byte) 9, 1, 1), null);
rootNode.setValue(new DhSectionPos((byte) 8, 0, 0), 2);
rootNode.setValue(new DhSectionPos((byte) 8, 1, 0), 2);
rootNode.setValue(new DhSectionPos((byte) 8, 0, 1), 2);
rootNode.setValue(new DhSectionPos((byte) 8, 1, 1), null);
rootNode.setValue(new OldDhSectionPos((byte) 8, 0, 0), 2);
rootNode.setValue(new OldDhSectionPos((byte) 8, 1, 0), 2);
rootNode.setValue(new OldDhSectionPos((byte) 8, 0, 1), 2);
rootNode.setValue(new OldDhSectionPos((byte) 8, 1, 1), null);
@@ -411,11 +411,11 @@ public class QuadTreeTest
{
AbstractTestTreeParams treeParams = new TinyTestTree();
final QuadTree<Integer> tree = new QuadTree<>(treeParams.getWidthInBlocks(), treeParams.getPositiveEdgeCenterPos(), LodUtil.BLOCK_DETAIL_LEVEL);
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, 0, 0), 0);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, 0, 0), 0);
// confirm the root node were added
int rootNodeCount = 0;
Iterator<DhSectionPos> rootNodePosIterator = tree.rootNodePosIterator();
Iterator<OldDhSectionPos> rootNodePosIterator = tree.rootNodePosIterator();
while (rootNodePosIterator.hasNext())
{
QuadNode<Integer> rootNode = tree.getNode(rootNodePosIterator.next());
@@ -431,7 +431,7 @@ public class QuadTreeTest
rootNodePosIterator = tree.rootNodePosIterator();
while (rootNodePosIterator.hasNext())
{
DhSectionPos rootNodePos = rootNodePosIterator.next();
OldDhSectionPos rootNodePos = rootNodePosIterator.next();
QuadNode<Integer> rootNode = tree.getNode(rootNodePos);
if (rootNode != null)
{
@@ -468,7 +468,7 @@ public class QuadTreeTest
tree.setCenterBlockPos(treeMovePos);
Assert.assertEquals("tree move failed, incorrect position after move", treeMovePos, tree.getCenterBlockPos());
Iterator<DhSectionPos> rootNodePosIterator = tree.rootNodePosIterator();
Iterator<OldDhSectionPos> rootNodePosIterator = tree.rootNodePosIterator();
while (rootNodePosIterator.hasNext())
{
testSet(tree, rootNodePosIterator.next(), 0);
@@ -499,13 +499,13 @@ public class QuadTreeTest
Assert.assertEquals("incorrect tree width", treeParams.getWidthInBlocks(), tree.diameterInBlocks());
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, 0, 0), 0);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, 0, 0), 0);
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, -1, -1), -1, IndexOutOfBoundsException.class);
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, 1, 1), -1, IndexOutOfBoundsException.class);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, -1, -1), -1, IndexOutOfBoundsException.class);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, 1, 1), -1, IndexOutOfBoundsException.class);
int rootNodeCount = 0;
Iterator<DhSectionPos> rootNodeIterator = tree.rootNodePosIterator();
Iterator<OldDhSectionPos> rootNodeIterator = tree.rootNodePosIterator();
while (rootNodeIterator.hasNext())
{
QuadNode<Integer> rootNode = tree.getNode(rootNodeIterator.next());
@@ -529,22 +529,22 @@ public class QuadTreeTest
// 2x2 valid positions (overlap the tree's width)
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, 0, 0), 0);
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, -1, 0), 0);
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, 0, -1), 0);
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, -1, -1), 0);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, 0, 0), 0);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, -1, 0), 0);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, 0, -1), 0);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, -1, -1), 0);
// invalid positions
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, -1, 1), -1, IndexOutOfBoundsException.class);
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, 0, 1), -1, IndexOutOfBoundsException.class);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, -1, 1), -1, IndexOutOfBoundsException.class);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, 0, 1), -1, IndexOutOfBoundsException.class);
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, 1, 0), -1, IndexOutOfBoundsException.class);
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, 1, 1), -1, IndexOutOfBoundsException.class);
testSet(tree, new DhSectionPos(tree.treeMinDetailLevel, 1, -1), -1, IndexOutOfBoundsException.class);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, 1, 0), -1, IndexOutOfBoundsException.class);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, 1, 1), -1, IndexOutOfBoundsException.class);
testSet(tree, new OldDhSectionPos(tree.treeMinDetailLevel, 1, -1), -1, IndexOutOfBoundsException.class);
int rootNodeCount = 0;
Iterator<DhSectionPos> rootNodeIterator = tree.rootNodePosIterator();
Iterator<OldDhSectionPos> rootNodeIterator = tree.rootNodePosIterator();
while (rootNodeIterator.hasNext())
{
QuadNode<Integer> rootNode = tree.getNode(rootNodeIterator.next());
@@ -565,17 +565,17 @@ public class QuadTreeTest
Assert.assertEquals("Test detail level's need to be adjusted. This isn't necessarily a failed test.", 10, tree.treeMinDetailLevel);
// valid detail levels
testSet(tree, new DhSectionPos((byte) 10, 0, 0), 1);
testSet(tree, new DhSectionPos((byte) 9, 0, 0), 2);
testSet(tree, new DhSectionPos((byte) 8, 0, 0), 3);
testSet(tree, new OldDhSectionPos((byte) 10, 0, 0), 1);
testSet(tree, new OldDhSectionPos((byte) 9, 0, 0), 2);
testSet(tree, new OldDhSectionPos((byte) 8, 0, 0), 3);
// detail level too low
testSet(tree, new DhSectionPos((byte) 7, 0, 0), -1, IndexOutOfBoundsException.class);
testSet(tree, new DhSectionPos((byte) 6, 0, 0), -1, IndexOutOfBoundsException.class);
testSet(tree, new OldDhSectionPos((byte) 7, 0, 0), -1, IndexOutOfBoundsException.class);
testSet(tree, new OldDhSectionPos((byte) 6, 0, 0), -1, IndexOutOfBoundsException.class);
// detail level too high
testSet(tree, new DhSectionPos((byte) 11, 0, 0), -1, IndexOutOfBoundsException.class);
testSet(tree, new DhSectionPos((byte) 12, 0, 0), -1, IndexOutOfBoundsException.class);
testSet(tree, new OldDhSectionPos((byte) 11, 0, 0), -1, IndexOutOfBoundsException.class);
testSet(tree, new OldDhSectionPos((byte) 12, 0, 0), -1, IndexOutOfBoundsException.class);
}
@@ -587,25 +587,25 @@ public class QuadTreeTest
Assert.assertEquals("Test detail level's need to be adjusted. This isn't necessarily a failed test.", 10, tree.treeMinDetailLevel);
// create the root node
testSet(tree, new DhSectionPos((byte) 10, 0, 0), 1);
testSet(tree, new OldDhSectionPos((byte) 10, 0, 0), 1);
AtomicInteger minimumDetailLevelReachedRef = new AtomicInteger(tree.treeMinDetailLevel);
// recurse down the tree
Iterator<DhSectionPos> rootNodePosIterator = tree.rootNodePosIterator();
Iterator<OldDhSectionPos> rootNodePosIterator = tree.rootNodePosIterator();
while (rootNodePosIterator.hasNext())
{
DhSectionPos sectionPos = rootNodePosIterator.next();
OldDhSectionPos sectionPos = rootNodePosIterator.next();
QuadNode<Integer> rootNode = tree.getNode(sectionPos);
if (rootNode != null)
{
// fill in the root node's direct children
Iterator<DhSectionPos> childPosIterator = rootNode.getChildPosIterator();
Iterator<OldDhSectionPos> childPosIterator = rootNode.getChildPosIterator();
while (childPosIterator.hasNext())
{
DhSectionPos rootChildPos = childPosIterator.next();
OldDhSectionPos rootChildPos = childPosIterator.next();
rootNode.setValue(rootChildPos, 0);
}
@@ -634,7 +634,7 @@ public class QuadTreeTest
// fill in the null children
Iterator<DhSectionPos> directChildIterator = node.getChildPosIterator();
Iterator<OldDhSectionPos> directChildIterator = node.getChildPosIterator();
while (directChildIterator.hasNext())
{
node.setValue(directChildIterator.next(), 0);
@@ -646,7 +646,7 @@ public class QuadTreeTest
directChildIterator = node.getChildPosIterator();
while (directChildIterator.hasNext())
{
DhSectionPos sectionPos = directChildIterator.next();
OldDhSectionPos sectionPos = directChildIterator.next();
QuadNode<Integer> childNode = node.getNode(sectionPos);
Assert.assertTrue("Child node recurred too low. Min detail level: " + minDetailLevel + ", node detail level: " + childNode.sectionPos.getDetailLevel(), childNode.sectionPos.getDetailLevel() >= minDetailLevel);
@@ -678,11 +678,11 @@ public class QuadTreeTest
@Test
public void quadNodeChildPositionIndexTest()
{
QuadNode<Integer> rootNode = new QuadNode<>(new DhSectionPos((byte) 10, 0, 0), (byte) 0);
Iterator<DhSectionPos> directChildPosIterator = rootNode.getChildPosIterator();
QuadNode<Integer> rootNode = new QuadNode<>(new OldDhSectionPos((byte) 10, 0, 0), (byte) 0);
Iterator<OldDhSectionPos> directChildPosIterator = rootNode.getChildPosIterator();
while (directChildPosIterator.hasNext())
{
DhSectionPos sectionPos = directChildPosIterator.next();
OldDhSectionPos sectionPos = directChildPosIterator.next();
Assert.assertNotEquals("Root node pos shouldn't be included in direct child pos iteration", sectionPos, rootNode.sectionPos);
rootNode.setValue(sectionPos, 1);
@@ -692,9 +692,9 @@ public class QuadTreeTest
for (int i = 0; i < 4; i++)
{
DhSectionPos childPos = rootNode.sectionPos.getChildByIndex(i);
OldDhSectionPos childPos = rootNode.sectionPos.getChildByIndex(i);
QuadNode<Integer> childNode = rootNode.getChildByIndex(i);
Assert.assertEquals("child position not the same as " + DhSectionPos.class.getSimpleName() + "'s getChildByIndex()", childPos, childNode.sectionPos);
Assert.assertEquals("child position not the same as " + OldDhSectionPos.class.getSimpleName() + "'s getChildByIndex()", childPos, childNode.sectionPos);
}
}
@@ -708,7 +708,7 @@ public class QuadTreeTest
// center root node
DhSectionPos centerNodePos = new DhSectionPos((byte) 1, 0, 0);
OldDhSectionPos centerNodePos = new OldDhSectionPos((byte) 1, 0, 0);
// create node
tree.setValue(centerNodePos, 0);
@@ -716,10 +716,10 @@ public class QuadTreeTest
Assert.assertNotNull(centerRootNode);
// child pos in bounds of the tree
Iterator<DhSectionPos> childPosIterator = centerRootNode.getChildPosIterator();
Iterator<OldDhSectionPos> childPosIterator = centerRootNode.getChildPosIterator();
while (childPosIterator.hasNext())
{
DhSectionPos childPos = childPosIterator.next();
OldDhSectionPos childPos = childPosIterator.next();
centerRootNode.setValue(childPos, 1);
}
Assert.assertEquals("center node not filled", 4, centerRootNode.getNonNullChildCount());
@@ -727,7 +727,7 @@ public class QuadTreeTest
// edge root node
DhSectionPos offsetNodePos = new DhSectionPos((byte) 1, -17, -16);
OldDhSectionPos offsetNodePos = new OldDhSectionPos((byte) 1, -17, -16);
// create node
tree.setValue(offsetNodePos, 0);
@@ -738,7 +738,7 @@ public class QuadTreeTest
childPosIterator = offsetRootNode.getChildPosIterator();
while (childPosIterator.hasNext())
{
DhSectionPos childPos = childPosIterator.next();
OldDhSectionPos childPos = childPosIterator.next();
offsetRootNode.setValue(childPos, 1);
}
// TODO James thought this shouldn't work for all 4 nodes, but he must've thought wrong.
@@ -772,7 +772,7 @@ public class QuadTreeTest
//
testSet(tree, new DhSectionPos((byte) 0, 0, 0), 1);
testSet(tree, new OldDhSectionPos((byte) 0, 0, 0), 1);
Assert.assertEquals(1, tree.count());
tree.setCenterBlockPos(new DhBlockPos2D(treeWidth + (treeWidth / 2), 0));
Assert.assertEquals(0, tree.count());
@@ -783,21 +783,21 @@ public class QuadTreeTest
//@Test
public void autoDeleteNullQuadNodeChildTest()
{
QuadNode<Integer> rootNode = new QuadNode<>(new DhSectionPos((byte) 10, 0, 0), LodUtil.BLOCK_DETAIL_LEVEL);
QuadNode<Integer> rootNode = new QuadNode<>(new OldDhSectionPos((byte) 10, 0, 0), LodUtil.BLOCK_DETAIL_LEVEL);
rootNode.setValue(new DhSectionPos((byte) 10, 0, 0), 0);
rootNode.setValue(new OldDhSectionPos((byte) 10, 0, 0), 0);
DhSectionPos midNodePos = new DhSectionPos((byte) 9, 0, 0);
OldDhSectionPos midNodePos = new OldDhSectionPos((byte) 9, 0, 0);
//rootNode.setValue(midNodePos, null); // holds detail 8
rootNode.setValue(new DhSectionPos((byte) 9, 1, 0), 1);
rootNode.setValue(new DhSectionPos((byte) 9, 0, 1), 1);
rootNode.setValue(new DhSectionPos((byte) 9, 1, 1), 1);
rootNode.setValue(new OldDhSectionPos((byte) 9, 1, 0), 1);
rootNode.setValue(new OldDhSectionPos((byte) 9, 0, 1), 1);
rootNode.setValue(new OldDhSectionPos((byte) 9, 1, 1), 1);
rootNode.setValue(new DhSectionPos((byte) 8, 0, 0), 2);
rootNode.setValue(new DhSectionPos((byte) 8, 1, 0), 2);
rootNode.setValue(new DhSectionPos((byte) 8, 0, 1), 2);
rootNode.setValue(new DhSectionPos((byte) 8, 1, 1), 2);
rootNode.setValue(new OldDhSectionPos((byte) 8, 0, 0), 2);
rootNode.setValue(new OldDhSectionPos((byte) 8, 1, 0), 2);
rootNode.setValue(new OldDhSectionPos((byte) 8, 0, 1), 2);
rootNode.setValue(new OldDhSectionPos((byte) 8, 1, 1), 2);
@@ -810,12 +810,12 @@ public class QuadTreeTest
// test removing nodes //
// remove two leaf nodes from the root
DhSectionPos leafPos = new DhSectionPos((byte) 9, 1, 1);
OldDhSectionPos leafPos = new OldDhSectionPos((byte) 9, 1, 1);
rootNode.setValue(leafPos, null);
Assert.assertEquals(3, rootNode.getNonNullChildCount());
Assert.assertNull("Node wasn't deleted", rootNode.getNode(leafPos));
leafPos = new DhSectionPos((byte) 9, 0, 1);
leafPos = new OldDhSectionPos((byte) 9, 0, 1);
rootNode.setValue(leafPos, null);
Assert.assertEquals(2, rootNode.getNonNullChildCount());
Assert.assertNull("Node wasn't deleted", rootNode.getNode(leafPos));
@@ -827,13 +827,13 @@ public class QuadTreeTest
Assert.assertEquals(4, rootNode.getNode(midNodePos).getNonNullChildCount());
// remove all but one, mid-node should still be present
rootNode.setValue(new DhSectionPos((byte) 8, 0, 0), null);
rootNode.setValue(new DhSectionPos((byte) 8, 0, 1), null);
rootNode.setValue(new DhSectionPos((byte) 8, 1, 0), null);
rootNode.setValue(new OldDhSectionPos((byte) 8, 0, 0), null);
rootNode.setValue(new OldDhSectionPos((byte) 8, 0, 1), null);
rootNode.setValue(new OldDhSectionPos((byte) 8, 1, 0), null);
Assert.assertEquals(1, rootNode.getNode(midNodePos).getNonNullChildCount());
// remove last mid-node child, mid-node should now be removed
rootNode.setValue(new DhSectionPos((byte) 8, 1, 1), null);
rootNode.setValue(new OldDhSectionPos((byte) 8, 1, 1), null);
Assert.assertNull("Mid node not deleted.", rootNode.getNode(midNodePos));
Assert.assertEquals(3, rootNode.getNonNullChildCount());
@@ -847,8 +847,8 @@ public class QuadTreeTest
// helper methods //
//================//
private static void testSet(QuadTree<Integer> tree, DhSectionPos pos, Integer setValue) { testSet(tree, pos, setValue, null); }
private static <TE extends Throwable> void testSet(QuadTree<Integer> tree, DhSectionPos pos, Integer setValue, Class<TE> expectedExceptionClass)
private static void testSet(QuadTree<Integer> tree, OldDhSectionPos pos, Integer setValue) { testSet(tree, pos, setValue, null); }
private static <TE extends Throwable> void testSet(QuadTree<Integer> tree, OldDhSectionPos pos, Integer setValue, Class<TE> expectedExceptionClass)
{
// set
try
@@ -869,8 +869,8 @@ public class QuadTreeTest
testGet(tree, pos, setValue, expectedExceptionClass);
}
private static void testGet(QuadTree<Integer> tree, DhSectionPos pos, Integer getValue) { testSet(tree, pos, getValue, null); }
private static <TE extends Throwable> void testGet(QuadTree<Integer> tree, DhSectionPos pos, Integer getValue, Class<TE> expectedExceptionClass)
private static void testGet(QuadTree<Integer> tree, OldDhSectionPos pos, Integer getValue) { testSet(tree, pos, getValue, null); }
private static <TE extends Throwable> void testGet(QuadTree<Integer> tree, OldDhSectionPos pos, Integer getValue, Class<TE> expectedExceptionClass)
{
try
{