Fix incorrect DhSectionPos method var order

This commit is contained in:
James Seibel
2024-05-16 22:14:34 -05:00
parent 172e7560fd
commit 894a2dbe7d
32 changed files with 108 additions and 132 deletions
@@ -364,7 +364,7 @@ public class FullDataPointIdMap
if (newMap.size() != entityCount) if (newMap.size() != entityCount)
{ {
// if the mappings are out of sync then the LODs will render incorrectly due to IDs being wrong // if the mappings are out of sync then the LODs will render incorrectly due to IDs being wrong
LodUtil.assertNotReach("ID maps failed to deserialize for pos: ["+DhSectionPos.toString(pos)+"], incorrect entity count. Expected count ["+entityCount+"], actual count ["+newMap.size()+"]"); LodUtil.assertNotReach("ID maps failed to deserialize for pos: ["+ DhSectionPos.toString(pos)+"], incorrect entity count. Expected count ["+entityCount+"], actual count ["+newMap.size()+"]");
} }
return newMap; return newMap;
@@ -271,7 +271,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
// both data sources should have the same detail level // both data sources should have the same detail level
if (DhSectionPos.getDetailLevel(inputDataSource.pos) != DhSectionPos.getDetailLevel(this.pos)) if (DhSectionPos.getDetailLevel(inputDataSource.pos) != DhSectionPos.getDetailLevel(this.pos))
{ {
throw new IllegalArgumentException("Both data sources must have the same detail level. Expected ["+DhSectionPos.getDetailLevel(this.pos)+"], received ["+DhSectionPos.getDetailLevel(inputDataSource.pos)+"]."); throw new IllegalArgumentException("Both data sources must have the same detail level. Expected ["+ DhSectionPos.getDetailLevel(this.pos)+"], received ["+ DhSectionPos.getDetailLevel(inputDataSource.pos)+"].");
} }
// copy over everything from the input data source into this one // copy over everything from the input data source into this one
@@ -362,9 +362,9 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
// determine where in the input data source should be written to // determine where in the input data source should be written to
// since the input is one detail level below it will be one of this position's 4 children // since the input is one detail level below it will be one of this position's 4 children
int minChildXPos = DhSectionPos.getX(DhSectionPos.getChildByIndex(0, this.pos)); int minChildXPos = DhSectionPos.getX(DhSectionPos.getChildByIndex(this.pos, 0));
int recipientOffsetX = (DhSectionPos.getX(inputDataSource.pos) == minChildXPos) ? 0 : (WIDTH / 2); int recipientOffsetX = (DhSectionPos.getX(inputDataSource.pos) == minChildXPos) ? 0 : (WIDTH / 2);
int minChildZPos = DhSectionPos.getZ(DhSectionPos.getChildByIndex(0, this.pos)); int minChildZPos = DhSectionPos.getZ(DhSectionPos.getChildByIndex(this.pos, 0));
int recipientOffsetZ = (DhSectionPos.getZ(inputDataSource.pos) == minChildZPos) ? 0 : (WIDTH / 2); int recipientOffsetZ = (DhSectionPos.getZ(inputDataSource.pos) == minChildZPos) ? 0 : (WIDTH / 2);
@@ -793,7 +793,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
if (firstBottomY < lastBottomY) if (firstBottomY < lastBottomY)
{ {
throw new IllegalStateException("Incorrect data point order at pos: ["+DhSectionPos.toString(pos)+"], first datapoint bottom Y ["+firstBottomY+"], last datapoint bottom Y ["+lastBottomY+"]."); throw new IllegalStateException("Incorrect data point order at pos: ["+ DhSectionPos.toString(pos)+"], first datapoint bottom Y ["+firstBottomY+"], last datapoint bottom Y ["+lastBottomY+"].");
} }
} }
@@ -115,9 +115,9 @@ public class FullDataToRenderDataTransformer
int baseX = DhSectionPos.getMinCornerBlockX(pos); int baseX = DhSectionPos.getMinCornerBlockX(pos);
int baseZ = DhSectionPos.getMinCornerBlockZ(pos); int baseZ = DhSectionPos.getMinCornerBlockZ(pos);
for (int x = 0; x < DhSectionPos.getWidthCountForLowerDetailedSection(dataDetail, pos); x++) for (int x = 0; x < DhSectionPos.getWidthCountForLowerDetailedSection(pos, dataDetail); x++)
{ {
for (int z = 0; z < DhSectionPos.getWidthCountForLowerDetailedSection(dataDetail, pos); z++) for (int z = 0; z < DhSectionPos.getWidthCountForLowerDetailedSection(pos, dataDetail); z++)
{ {
throwIfThreadInterrupted(); throwIfThreadInterrupted();
@@ -177,7 +177,7 @@ public abstract class AbstractDataSourceHandler
catch (InterruptedException ignore) { } catch (InterruptedException ignore) { }
catch (IOException e) catch (IOException e)
{ {
LOGGER.warn("File read Error for pos ["+DhSectionPos.toString(pos)+"], error: "+e.getMessage(), e); LOGGER.warn("File read Error for pos ["+ DhSectionPos.toString(pos)+"], error: "+e.getMessage(), e);
} }
return dataSource; return dataSource;
@@ -1,7 +1,6 @@
package com.seibel.distanthorizons.core.file; package com.seibel.distanthorizons.core.file;
import com.seibel.distanthorizons.core.level.IDhLevel; import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
@@ -3,7 +3,6 @@ package com.seibel.distanthorizons.core.file;
import com.seibel.distanthorizons.api.enums.EDhApiDetailLevel; import com.seibel.distanthorizons.api.enums.EDhApiDetailLevel;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.level.IDhLevel; import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.sql.dto.IBaseDTO; import com.seibel.distanthorizons.core.sql.dto.IBaseDTO;
/** /**
@@ -2,7 +2,6 @@ package com.seibel.distanthorizons.core.file.fullDatafile;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.util.TimerUtil; import com.seibel.distanthorizons.core.util.TimerUtil;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -134,12 +134,12 @@ public class FullDataSourceProviderV1<TDhLevel extends IDhLevel>
{ {
// stack trace not included since a lot of corrupt data would cause the log to get quite messy, // stack trace not included since a lot of corrupt data would cause the log to get quite messy,
// and it should be fairly easy to see what the problem was from the message // and it should be fairly easy to see what the problem was from the message
LOGGER.warn("Corrupted data found at pos ["+DhSectionPos.toString(pos)+"]. Data at position will be deleted so it can be re-generated and to prevent future issues. Error: "+e.getMessage()); LOGGER.warn("Corrupted data found at pos ["+ DhSectionPos.toString(pos)+"]. Data at position will be deleted so it can be re-generated and to prevent future issues. Error: "+e.getMessage());
this.repo.deleteWithKey(pos); this.repo.deleteWithKey(pos);
} }
catch (IOException e) catch (IOException e)
{ {
LOGGER.warn("File read Error for pos ["+DhSectionPos.toString(pos)+"], error: "+e.getMessage(), e); LOGGER.warn("File read Error for pos ["+ DhSectionPos.toString(pos)+"], error: "+e.getMessage(), e);
} }
return dataSource; return dataSource;
@@ -50,7 +50,6 @@ import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
/** /**
* Handles reading/writing {@link FullDataSourceV2} * Handles reading/writing {@link FullDataSourceV2}
@@ -42,7 +42,6 @@ import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function;
public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 implements IDebugRenderable public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 implements IDebugRenderable
{ {
@@ -280,7 +279,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
// TODO speed up this logic by only checking ungenerated columns // TODO speed up this logic by only checking ungenerated columns
LongArrayList generationList = new LongArrayList(); LongArrayList generationList = new LongArrayList();
byte minGeneratorSectionDetailLevel = (byte) (worldGenQueue.highestDataDetail() + DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL); byte minGeneratorSectionDetailLevel = (byte) (worldGenQueue.highestDataDetail() + DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
DhSectionPos.forEachChildAtDetailLevel(minGeneratorSectionDetailLevel, (genPos) -> DhSectionPos.forEachChildAtDetailLevel(pos, minGeneratorSectionDetailLevel, (genPos) ->
{ {
if (!this.repo.existsWithKey(genPos)) if (!this.repo.existsWithKey(genPos))
{ {
@@ -331,7 +330,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
generationList.add(genPos); generationList.add(genPos);
} }
}, pos); });
return generationList; return generationList;
} }
@@ -224,8 +224,8 @@ public class SubDimensionLevelMatcher implements AutoCloseable
// confirm both data sources have the same section pos // confirm both data sources have the same section pos
long newSectionChunkPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL, newDataSource.getPos()); long newSectionChunkPos = DhSectionPos.convertToDetailLevel(newDataSource.getPos(), DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL);
long testSectionChunkPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL, testFullDataSource.getPos()); long testSectionChunkPos = DhSectionPos.convertToDetailLevel(testFullDataSource.getPos(), DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL);
LodUtil.assertTrue(newSectionChunkPos == testSectionChunkPos, "data source positions don't match"); LodUtil.assertTrue(newSectionChunkPos == testSectionChunkPos, "data source positions don't match");
@@ -27,7 +27,6 @@ import com.seibel.distanthorizons.core.render.LodQuadTree;
import java.io.Closeable; import java.io.Closeable;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
/** /**
* Used to track what full data sources the system currently * Used to track what full data sources the system currently
@@ -49,7 +49,6 @@ import java.awt.*;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function;
public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDebugRenderable public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDebugRenderable
{ {
@@ -310,14 +309,14 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb
LinkedList<CompletableFuture<WorldGenResult>> childFutures = new LinkedList<>(); LinkedList<CompletableFuture<WorldGenResult>> childFutures = new LinkedList<>();
long sectionPos = closestTask.pos; long sectionPos = closestTask.pos;
WorldGenTask finalClosestTask = closestTask; WorldGenTask finalClosestTask = closestTask;
DhSectionPos.forEachChild((childDhSectionPos) -> DhSectionPos.forEachChild(sectionPos, (childDhSectionPos) ->
{ {
CompletableFuture<WorldGenResult> newFuture = new CompletableFuture<>(); CompletableFuture<WorldGenResult> newFuture = new CompletableFuture<>();
childFutures.add(newFuture); childFutures.add(newFuture);
WorldGenTask newGenTask = new WorldGenTask(childDhSectionPos, DhSectionPos.getDetailLevel(childDhSectionPos), finalClosestTask.taskTracker, newFuture); WorldGenTask newGenTask = new WorldGenTask(childDhSectionPos, DhSectionPos.getDetailLevel(childDhSectionPos), finalClosestTask.taskTracker, newFuture);
this.waitingTasks.put(newGenTask.pos, newGenTask); this.waitingTasks.put(newGenTask.pos, newGenTask);
}, sectionPos); });
// send the child futures to the future recipient, to notify them of the new tasks // send the child futures to the future recipient, to notify them of the new tasks
closestTask.future.complete(WorldGenResult.CreateSplit(childFutures)); closestTask.future.complete(WorldGenResult.CreateSplit(childFutures));
@@ -19,8 +19,6 @@
package com.seibel.distanthorizons.core.generation.tasks; package com.seibel.distanthorizons.core.generation.tasks;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@@ -19,8 +19,6 @@
package com.seibel.distanthorizons.core.generation.tasks; package com.seibel.distanthorizons.core.generation.tasks;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
/** /**
@@ -20,7 +20,6 @@
package com.seibel.distanthorizons.core.generation.tasks; package com.seibel.distanthorizons.core.generation.tasks;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
@@ -29,7 +29,6 @@ import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.logging.f3.F3Screen; import com.seibel.distanthorizons.core.logging.f3.F3Screen;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D; import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.render.LodQuadTree; import com.seibel.distanthorizons.core.render.LodQuadTree;
import com.seibel.distanthorizons.core.render.RenderBufferHandler; import com.seibel.distanthorizons.core.render.RenderBufferHandler;
import com.seibel.distanthorizons.core.render.renderer.LodRenderer; import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
@@ -28,7 +28,6 @@ import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhBlockPos; import com.seibel.distanthorizons.core.pos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D; import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
@@ -23,7 +23,6 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSour
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2; import com.seibel.distanthorizons.core.file.fullDatafile.FullDataSourceProviderV2;
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure; import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D; import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
@@ -106,7 +106,7 @@ public class DhSectionPos
public static long encodeBlockPos(int blockX, int blockZ) public static long encodeBlockPos(int blockX, int blockZ)
{ {
long pos = encode(LodUtil.BLOCK_DETAIL_LEVEL, blockX, blockZ); long pos = encode(LodUtil.BLOCK_DETAIL_LEVEL, blockX, blockZ);
pos = convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, pos); pos = convertToDetailLevel(pos, DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
return pos; return pos;
} }
@@ -114,7 +114,7 @@ public class DhSectionPos
public static long encodeChunkPos(int chunkX, int chunkZ) public static long encodeChunkPos(int chunkX, int chunkZ)
{ {
long pos = encode(LodUtil.CHUNK_DETAIL_LEVEL, chunkX, chunkZ); long pos = encode(LodUtil.CHUNK_DETAIL_LEVEL, chunkX, chunkZ);
pos = convertToDetailLevel(DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL, pos); pos = convertToDetailLevel(pos, DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL);
return pos; return pos;
} }
@@ -125,7 +125,7 @@ public class DhSectionPos
//============// //============//
/** uses the absolute detail level aka detail levels like {@link LodUtil#CHUNK_DETAIL_LEVEL} instead of the dhSectionPos detailLevels. */ /** uses the absolute detail level aka detail levels like {@link LodUtil#CHUNK_DETAIL_LEVEL} instead of the dhSectionPos detailLevels. */
public static long convertToDetailLevel(byte newDetailLevel, long pos) public static long convertToDetailLevel(long pos, byte newDetailLevel)
{ {
byte detailLevel = getDetailLevel(pos); byte detailLevel = getDetailLevel(pos);
int x = getX(pos); int x = getX(pos);
@@ -199,7 +199,7 @@ public class DhSectionPos
* *
* @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 DhSectionPos}'s at the given detail level it would take to span the width of this section.
*/ */
public static int getWidthCountForLowerDetailedSection(byte returnDetailLevel, long pos) public static int getWidthCountForLowerDetailedSection(long pos, byte returnDetailLevel)
{ {
byte detailLevel = getDetailLevel(pos); byte detailLevel = getDetailLevel(pos);
@@ -214,9 +214,9 @@ public class DhSectionPos
public static DhBlockPos2D getCenterBlockPos(long pos) { return new DhBlockPos2D(getCenterBlockPosX(pos), getCenterBlockPosZ(pos)); } public static DhBlockPos2D getCenterBlockPos(long pos) { return new DhBlockPos2D(getCenterBlockPosX(pos), getCenterBlockPosZ(pos)); }
public static int getCenterBlockPosX(long pos) { return getCenterBlockPosXOrZ(true, pos); } public static int getCenterBlockPosX(long pos) { return getCenterBlockPosXOrZ(pos, true); }
public static int getCenterBlockPosZ(long pos) { return getCenterBlockPosXOrZ(false, pos); } public static int getCenterBlockPosZ(long pos) { return getCenterBlockPosXOrZ(pos, false); }
private static int getCenterBlockPosXOrZ(boolean returnX, long pos) private static int getCenterBlockPosXOrZ(long pos, boolean returnX)
{ {
byte detailLevel = getDetailLevel(pos); byte detailLevel = getDetailLevel(pos);
int x = getX(pos); int x = getX(pos);
@@ -241,7 +241,7 @@ public class DhSectionPos
return (centerBlockPos * BitShiftUtil.powerOfTwo(detailLevel)) + positionOffset; return (centerBlockPos * BitShiftUtil.powerOfTwo(detailLevel)) + positionOffset;
} }
public static int getManhattanBlockDistance(DhBlockPos2D blockPos, long pos) public static int getManhattanBlockDistance(long pos, DhBlockPos2D blockPos)
{ {
return Math.abs(getCenterBlockPosX(pos) - blockPos.x) return Math.abs(getCenterBlockPosX(pos) - blockPos.x)
+ Math.abs(getCenterBlockPosZ(pos) - blockPos.z); + Math.abs(getCenterBlockPosZ(pos) - blockPos.z);
@@ -264,7 +264,7 @@ public class DhSectionPos
* *
* @param child0to3 must be an int between 0 and 3 * @param child0to3 must be an int between 0 and 3
*/ */
public static long getChildByIndex(int child0to3, long pos) throws IllegalArgumentException, IllegalStateException public static long getChildByIndex(long pos, int child0to3) throws IllegalArgumentException, IllegalStateException
{ {
byte detailLevel = getDetailLevel(pos); byte detailLevel = getDetailLevel(pos);
int x = getX(pos); int x = getX(pos);
@@ -290,7 +290,7 @@ public class DhSectionPos
public static long getAdjacentPos(EDhDirection dir, long pos) throws IllegalArgumentException public static long getAdjacentPos(long pos, EDhDirection dir) throws IllegalArgumentException
{ {
if (dir == EDhDirection.UP || dir == EDhDirection.DOWN) if (dir == EDhDirection.UP || dir == EDhDirection.DOWN)
{ {
@@ -334,16 +334,16 @@ public class DhSectionPos
//===========// //===========//
/** Applies the given consumer to all 4 of this position's children. */ /** Applies the given consumer to all 4 of this position's children. */
public static void forEachChild(LongConsumer callback, long pos) throws IllegalArgumentException, IllegalStateException public static void forEachChild(long pos, LongConsumer callback) throws IllegalArgumentException, IllegalStateException
{ {
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
callback.accept(getChildByIndex(i, pos)); callback.accept(getChildByIndex(pos, i));
} }
} }
/** Applies the given consumer to all children of the position at the given section detail level. */ /** Applies the given consumer to all children of the position at the given section detail level. */
public static void forEachChildDownToDetailLevel(byte minSectionDetailLevel, ICancelablePrimitiveLongConsumer callback, long pos) throws IllegalArgumentException, IllegalStateException public static void forEachChildDownToDetailLevel(long pos, byte minSectionDetailLevel, ICancelablePrimitiveLongConsumer callback) throws IllegalArgumentException, IllegalStateException
{ {
boolean stop = callback.accept(pos); boolean stop = callback.accept(pos);
if (stop || minSectionDetailLevel == getDetailLevel(pos)) if (stop || minSectionDetailLevel == getDetailLevel(pos))
@@ -353,12 +353,12 @@ public class DhSectionPos
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
forEachChildDownToDetailLevel(minSectionDetailLevel, callback, getChildByIndex(i, pos)); forEachChildDownToDetailLevel(getChildByIndex(pos, i), minSectionDetailLevel, callback);
} }
} }
/** Applies the given consumer to all children of the position at the given section detail level. */ /** Applies the given consumer to all children of the position at the given section detail level. */
public static void forEachChildAtDetailLevel(byte sectionDetailLevel, LongConsumer callback, long pos) throws IllegalArgumentException, IllegalStateException public static void forEachChildAtDetailLevel(long pos, byte sectionDetailLevel, LongConsumer callback) throws IllegalArgumentException, IllegalStateException
{ {
if (sectionDetailLevel == getDetailLevel(pos)) if (sectionDetailLevel == getDetailLevel(pos))
{ {
@@ -368,12 +368,12 @@ public class DhSectionPos
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
forEachChildAtDetailLevel(sectionDetailLevel, callback, getChildByIndex(i, pos)); forEachChildAtDetailLevel(getChildByIndex(pos, i), sectionDetailLevel, callback);
} }
} }
/** Applies the given consumer to all children of the position at the given section detail level. */ /** Applies the given consumer to all children of the position at the given section detail level. */
public static void forEachPosUpToDetailLevel(byte maxSectionDetailLevel, LongConsumer callback, long pos) public static void forEachPosUpToDetailLevel(long pos, byte maxSectionDetailLevel, LongConsumer callback)
{ {
callback.accept(pos); callback.accept(pos);
if (maxSectionDetailLevel == getDetailLevel(pos)) if (maxSectionDetailLevel == getDetailLevel(pos))
@@ -381,7 +381,7 @@ public class DhSectionPos
return; return;
} }
forEachPosUpToDetailLevel(maxSectionDetailLevel, callback, getParentPos(pos)); forEachPosUpToDetailLevel(getParentPos(pos), maxSectionDetailLevel, callback);
} }
@@ -38,7 +38,6 @@ import com.seibel.distanthorizons.core.util.objects.quadTree.QuadTree;
import com.seibel.distanthorizons.coreapi.util.MathUtil; import com.seibel.distanthorizons.coreapi.util.MathUtil;
import it.unimi.dsi.fastutil.longs.LongIterator; import it.unimi.dsi.fastutil.longs.LongIterator;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import javax.annotation.WillNotClose; import javax.annotation.WillNotClose;
import java.awt.*; import java.awt.*;
@@ -233,8 +232,8 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
nodesNeedingLoading.sort((a, b) -> nodesNeedingLoading.sort((a, b) ->
{ {
int aDist = DhSectionPos.getManhattanBlockDistance(playerPos, a.pos); int aDist = DhSectionPos.getManhattanBlockDistance(a.pos, playerPos);
int bDist = DhSectionPos.getManhattanBlockDistance(playerPos, b.pos); int bDist = DhSectionPos.getManhattanBlockDistance(b.pos, playerPos);
return Integer.compare(aDist, bDist); return Integer.compare(aDist, bDist);
}); });
@@ -547,7 +546,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
// and lights may not show up over LOD borders // and lights may not show up over LOD borders
for (EDhDirection direction : EDhDirection.ADJ_DIRECTIONS) for (EDhDirection direction : EDhDirection.ADJ_DIRECTIONS)
{ {
this.sectionsToReload.add(DhSectionPos.getAdjacentPos(direction, pos)); this.sectionsToReload.add(DhSectionPos.getAdjacentPos(pos, direction));
} }
} }
@@ -567,8 +566,8 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
// sort the nodes from nearest to farthest // sort the nodes from nearest to farthest
nodesNeedingRetrieval.sort((a, b) -> nodesNeedingRetrieval.sort((a, b) ->
{ {
int aDist = DhSectionPos.getManhattanBlockDistance(playerPos, a.pos); int aDist = DhSectionPos.getManhattanBlockDistance(a.pos, playerPos);
int bDist = DhSectionPos.getManhattanBlockDistance(playerPos, b.pos); int bDist = DhSectionPos.getManhattanBlockDistance(b.pos, playerPos);
return Integer.compare(aDist, bDist); return Integer.compare(aDist, bDist);
}); });
@@ -237,7 +237,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
EDhDirection direction = EDhDirection.ADJ_DIRECTIONS[i]; EDhDirection direction = EDhDirection.ADJ_DIRECTIONS[i];
int arrayIndex = direction.ordinal() - 2; int arrayIndex = direction.ordinal() - 2;
long adjPos = DhSectionPos.getAdjacentPos(direction, this.pos); long adjPos = DhSectionPos.getAdjacentPos(this.pos, direction);
try try
{ {
LodRenderSection adjRenderSection = this.quadTree.getValue(adjPos); LodRenderSection adjRenderSection = this.quadTree.getValue(adjPos);
@@ -22,7 +22,6 @@ package com.seibel.distanthorizons.core.sql.dto;
import com.seibel.distanthorizons.api.enums.config.EDhApiDataCompressionMode; import com.seibel.distanthorizons.api.enums.config.EDhApiDataCompressionMode;
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep; import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV1; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV1;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream; import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@@ -24,7 +24,6 @@ import com.seibel.distanthorizons.api.enums.config.EDhApiWorldCompressionMode;
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep; import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap; import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.util.FullDataPointUtil; import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil; import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.objects.DataCorruptedException; import com.seibel.distanthorizons.core.util.objects.DataCorruptedException;
@@ -21,7 +21,6 @@ package com.seibel.distanthorizons.core.sql.repo;
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep; import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
import com.seibel.distanthorizons.core.pos.DhSectionPos; import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV1DTO; import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV1DTO;
import com.seibel.distanthorizons.coreapi.util.StringUtil; import com.seibel.distanthorizons.coreapi.util.StringUtil;
import it.unimi.dsi.fastutil.longs.LongArrayList; import it.unimi.dsi.fastutil.longs.LongArrayList;
@@ -32,7 +32,6 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -64,7 +63,7 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<Long, FullDataSourceV2D
public String createWhereStatement(Long pos) public String createWhereStatement(Long pos)
{ {
int detailLevel = DhSectionPos.getDetailLevel(pos) - DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL; int detailLevel = DhSectionPos.getDetailLevel(pos) - DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL;
return "DetailLevel = '"+detailLevel+"' AND PosX = '"+DhSectionPos.getX(pos)+"' AND PosZ = '"+DhSectionPos.getZ(pos)+"'"; return "DetailLevel = '"+detailLevel+"' AND PosX = '"+ DhSectionPos.getX(pos)+"' AND PosZ = '"+ DhSectionPos.getZ(pos)+"'";
} }
@@ -208,7 +207,7 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<Long, FullDataSourceV2D
String sql = String sql =
"UPDATE "+this.getTableName()+" \n" + "UPDATE "+this.getTableName()+" \n" +
"SET ApplyToParent = "+applyToParent+" \n" + "SET ApplyToParent = "+applyToParent+" \n" +
"WHERE DetailLevel = "+detailLevel+" AND PosX = "+DhSectionPos.getX(pos)+" AND PosZ = "+DhSectionPos.getZ(pos); "WHERE DetailLevel = "+detailLevel+" AND PosX = "+ DhSectionPos.getX(pos)+" AND PosZ = "+ DhSectionPos.getZ(pos);
this.queryDictionaryFirst(sql); this.queryDictionaryFirst(sql);
} }
@@ -245,7 +244,7 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<Long, FullDataSourceV2D
Map<String, Object> resultMap = this.queryDictionaryFirst( Map<String, Object> resultMap = this.queryDictionaryFirst(
"select ColumnGenerationStep, CompressionMode " + "select ColumnGenerationStep, CompressionMode " +
"from "+this.getTableName()+" " + "from "+this.getTableName()+" " +
"WHERE DetailLevel = "+detailLevel+" AND PosX = "+DhSectionPos.getX(pos)+" AND PosZ = "+DhSectionPos.getZ(pos)); "WHERE DetailLevel = "+detailLevel+" AND PosX = "+ DhSectionPos.getX(pos)+" AND PosZ = "+ DhSectionPos.getZ(pos));
if (resultMap != null) if (resultMap != null)
{ {
@@ -317,7 +316,7 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<Long, FullDataSourceV2D
Map<String, Object> resultMap = this.queryDictionaryFirst( Map<String, Object> resultMap = this.queryDictionaryFirst(
"select LENGTH(Data) as dataSize " + "select LENGTH(Data) as dataSize " +
"from "+this.getTableName()+" " + "from "+this.getTableName()+" " +
"WHERE DetailLevel = "+detailLevel+" AND PosX = "+DhSectionPos.getX(pos)+" AND PosZ = "+DhSectionPos.getZ(pos)); "WHERE DetailLevel = "+detailLevel+" AND PosX = "+ DhSectionPos.getX(pos)+" AND PosZ = "+ DhSectionPos.getZ(pos));
if (resultMap != null && resultMap.get("dataSize") != null) if (resultMap != null && resultMap.get("dataSize") != null)
{ {
@@ -181,7 +181,7 @@ public class QuadNode<T>
if (!DhSectionPos.contains(this.sectionPos, inputSectionPos)) if (!DhSectionPos.contains(this.sectionPos, inputSectionPos))
{ {
LOGGER.error((replaceValue ? "set " : "get ") + inputSectionPos + " center block: " + DhSectionPos.getCenterBlockPos(inputSectionPos) + ", this pos: " + this.sectionPos + " this center block: " + DhSectionPos.getCenterBlockPos(this.sectionPos)); LOGGER.error((replaceValue ? "set " : "get ") + inputSectionPos + " center block: " + DhSectionPos.getCenterBlockPos(inputSectionPos) + ", this pos: " + this.sectionPos + " this center block: " + DhSectionPos.getCenterBlockPos(this.sectionPos));
throw new IllegalArgumentException("Input section pos " + inputSectionPos + " outside of this quadNode's pos: " + this.sectionPos + ", this node's blockPos: " + DhSectionPos.convertToDetailLevel(LodUtil.BLOCK_DETAIL_LEVEL, this.sectionPos) + " block width: " + DhSectionPos.getBlockWidth(this.sectionPos) + " input detail level: " + DhSectionPos.convertToDetailLevel(LodUtil.BLOCK_DETAIL_LEVEL, inputSectionPos) + " width: " + DhSectionPos.getBlockWidth(inputSectionPos)); throw new IllegalArgumentException("Input section pos " + inputSectionPos + " outside of this quadNode's pos: " + this.sectionPos + ", this node's blockPos: " + DhSectionPos.convertToDetailLevel(this.sectionPos, LodUtil.BLOCK_DETAIL_LEVEL) + " block width: " + DhSectionPos.getBlockWidth(this.sectionPos) + " input detail level: " + DhSectionPos.convertToDetailLevel(inputSectionPos, LodUtil.BLOCK_DETAIL_LEVEL) + " width: " + DhSectionPos.getBlockWidth(inputSectionPos));
} }
if (DhSectionPos.getDetailLevel(inputSectionPos) > DhSectionPos.getDetailLevel(this.sectionPos)) if (DhSectionPos.getDetailLevel(inputSectionPos) > DhSectionPos.getDetailLevel(this.sectionPos))
@@ -218,10 +218,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()); // LOGGER.info((replaceValue ? "set " : "get ")+inputSectionPos+" center block: "+inputSectionPos.getCenter().getCornerBlockPos()+", this pos: "+this.sectionPos+" this center block: "+this.sectionPos.getCenter().getCornerBlockPos());
long nwPos = DhSectionPos.getChildByIndex(0, this.sectionPos); long nwPos = DhSectionPos.getChildByIndex(this.sectionPos, 0);
long swPos = DhSectionPos.getChildByIndex(1, this.sectionPos); long swPos = DhSectionPos.getChildByIndex(this.sectionPos, 1);
long nePos = DhSectionPos.getChildByIndex(2, this.sectionPos); long nePos = DhSectionPos.getChildByIndex(this.sectionPos, 2);
long sePos = DhSectionPos.getChildByIndex(3, this.sectionPos); long sePos = DhSectionPos.getChildByIndex(this.sectionPos, 3);
// look for the child that contains the input position (there may be a faster way to do this, but this works for now) // 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; QuadNode<T> childNode;
@@ -124,12 +124,12 @@ public class QuadTree<T>
int radius = this.diameterInBlocks() / 2; int radius = this.diameterInBlocks() / 2;
DhBlockPos2D minPos = this.getCenterBlockPos().add(new DhBlockPos2D(-radius, -radius)); DhBlockPos2D minPos = this.getCenterBlockPos().add(new DhBlockPos2D(-radius, -radius));
DhBlockPos2D maxPos = this.getCenterBlockPos().add(new DhBlockPos2D(radius, radius)); DhBlockPos2D maxPos = this.getCenterBlockPos().add(new DhBlockPos2D(radius, radius));
throw new IndexOutOfBoundsException("QuadTree GetOrSet failed. Position out of bounds, min pos: " + minPos + ", max pos: " + maxPos + ", min detail level: " + this.treeMaxDetailLevel + ", max detail level: " + this.treeMinDetailLevel + ". Given Position: [" + DhSectionPos.toString(pos) + "] = block pos: " + DhSectionPos.convertToDetailLevel(LodUtil.BLOCK_DETAIL_LEVEL, pos)); throw new IndexOutOfBoundsException("QuadTree GetOrSet failed. Position out of bounds, min pos: " + minPos + ", max pos: " + maxPos + ", min detail level: " + this.treeMaxDetailLevel + ", max detail level: " + this.treeMinDetailLevel + ". Given Position: [" + DhSectionPos.toString(pos) + "] = block pos: " + DhSectionPos.convertToDetailLevel(pos, LodUtil.BLOCK_DETAIL_LEVEL));
} }
long rootPos = DhSectionPos.convertToDetailLevel(this.treeMinDetailLevel, pos); long rootPos = DhSectionPos.convertToDetailLevel(pos, this.treeMinDetailLevel);
int ringListPosX = DhSectionPos.getX(rootPos); int ringListPosX = DhSectionPos.getX(rootPos);
int ringListPosZ = DhSectionPos.getZ(rootPos); int ringListPosZ = DhSectionPos.getZ(rootPos);
@@ -177,7 +177,7 @@ public class QuadTree<T>
DhBlockPos2D treeBlockCorner = this.centerBlockPos.add(new DhBlockPos2D(-this.diameterInBlocks / 2, -this.diameterInBlocks / 2)); DhBlockPos2D treeBlockCorner = this.centerBlockPos.add(new DhBlockPos2D(-this.diameterInBlocks / 2, -this.diameterInBlocks / 2));
DhLodPos treeCornerPos = new DhLodPos((byte) 0, treeBlockCorner.x, treeBlockCorner.z); DhLodPos treeCornerPos = new DhLodPos((byte) 0, treeBlockCorner.x, treeBlockCorner.z);
long inputSectionCorner = DhSectionPos.convertToDetailLevel((byte) 0, testPos); long inputSectionCorner = DhSectionPos.convertToDetailLevel(testPos, (byte) 0);
DhLodPos inputCornerPos = new DhLodPos((byte) 0, DhSectionPos.getX(inputSectionCorner), DhSectionPos.getZ(inputSectionCorner)); DhLodPos inputCornerPos = new DhLodPos((byte) 0, DhSectionPos.getX(inputSectionCorner), DhSectionPos.getZ(inputSectionCorner));
int inputBlockWidth = BitShiftUtil.powerOfTwo(DhSectionPos.getDetailLevel(testPos)); int inputBlockWidth = BitShiftUtil.powerOfTwo(DhSectionPos.getDetailLevel(testPos));
@@ -211,7 +211,7 @@ public class QuadTree<T>
int childCount = 0; int childCount = 0;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
long childPos = DhSectionPos.getChildByIndex(i, pos); long childPos = DhSectionPos.getChildByIndex(pos, i);
if (this.isSectionPosInBounds(childPos)) if (this.isSectionPosInBounds(childPos))
{ {
T value = this.getValue(childPos); T value = this.getValue(childPos);
@@ -23,9 +23,7 @@ import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.util.objects.quadTree.QuadNode; import com.seibel.distanthorizons.core.util.objects.quadTree.QuadNode;
import it.unimi.dsi.fastutil.longs.LongIterator; import it.unimi.dsi.fastutil.longs.LongIterator;
import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.function.Consumer;
import java.util.function.LongConsumer; import java.util.function.LongConsumer;
public class QuadNodeDirectChildPosIterator<T> implements LongIterator public class QuadNodeDirectChildPosIterator<T> implements LongIterator
@@ -55,7 +53,7 @@ public class QuadNodeDirectChildPosIterator<T> implements LongIterator
int childIndex = this.childIndexIterator.next(); int childIndex = this.childIndexIterator.next();
long sectionPos = DhSectionPos.getChildByIndex(childIndex, this.parentNode.sectionPos); long sectionPos = DhSectionPos.getChildByIndex(this.parentNode.sectionPos, childIndex);
return sectionPos; return sectionPos;
} }
@@ -21,7 +21,6 @@ package tests;
import com.seibel.distanthorizons.api.enums.config.EDhApiDataCompressionMode; import com.seibel.distanthorizons.api.enums.config.EDhApiDataCompressionMode;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV2DTO; import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV2DTO;
import com.seibel.distanthorizons.core.sql.repo.FullDataSourceV2Repo; import com.seibel.distanthorizons.core.sql.repo.FullDataSourceV2Repo;
import it.unimi.dsi.fastutil.longs.LongArrayList; import it.unimi.dsi.fastutil.longs.LongArrayList;
@@ -30,7 +29,6 @@ import org.junit.Assert;
import java.io.*; import java.io.*;
import java.text.CharacterIterator; import java.text.CharacterIterator;
import java.text.StringCharacterIterator; import java.text.StringCharacterIterator;
import java.util.ArrayList;
/** /**
* <strong>Note:</strong> * <strong>Note:</strong>
+53 -53
View File
@@ -127,23 +127,23 @@ public class DhSectionPosTest
public void parentPosTest() public void parentPosTest()
{ {
long leaf = DhSectionPos.encode((byte) 0, 0, 0); long leaf = DhSectionPos.encode((byte) 0, 0, 0);
long convert = DhSectionPos.convertToDetailLevel((byte) 1, leaf); long convert = DhSectionPos.convertToDetailLevel(leaf, (byte) 1);
long parent = DhSectionPos.getParentPos(leaf); long parent = DhSectionPos.getParentPos(leaf);
assertSectionPosEqual("get parent at 0,0 fail", convert, parent); assertSectionPosEqual("get parent at 0,0 fail", convert, parent);
leaf = DhSectionPos.encode((byte) 0, 1, 1); leaf = DhSectionPos.encode((byte) 0, 1, 1);
convert = DhSectionPos.convertToDetailLevel((byte) 1, leaf); convert = DhSectionPos.convertToDetailLevel(leaf, (byte) 1);
parent = DhSectionPos.getParentPos(leaf); parent = DhSectionPos.getParentPos(leaf);
assertSectionPosEqual("get parent at 1,1 fail", convert, parent); assertSectionPosEqual("get parent at 1,1 fail", convert, parent);
leaf = DhSectionPos.encode((byte) 1, 2, 2); leaf = DhSectionPos.encode((byte) 1, 2, 2);
convert = DhSectionPos.convertToDetailLevel((byte) 2, leaf); convert = DhSectionPos.convertToDetailLevel(leaf, (byte) 2);
parent = DhSectionPos.getParentPos(leaf); parent = DhSectionPos.getParentPos(leaf);
assertSectionPosEqual("parent upscale fail", convert, parent); assertSectionPosEqual("parent upscale fail", convert, parent);
convert = DhSectionPos.convertToDetailLevel((byte) 0, leaf); convert = DhSectionPos.convertToDetailLevel(leaf, (byte) 0);
long childIndex = DhSectionPos.getChildByIndex(0, leaf); long childIndex = DhSectionPos.getChildByIndex(leaf, 0);
assertSectionPosEqual("child detail fail", convert, childIndex); assertSectionPosEqual("child detail fail", convert, childIndex);
} }
@@ -152,10 +152,10 @@ public class DhSectionPosTest
public void childPosTest() public void childPosTest()
{ {
long node = DhSectionPos.encode((byte) 1, 2302, 0); long node = DhSectionPos.encode((byte) 1, 2302, 0);
long nw = DhSectionPos.getChildByIndex(0, node); long nw = DhSectionPos.getChildByIndex(node, 0);
long sw = DhSectionPos.getChildByIndex(1, node); long sw = DhSectionPos.getChildByIndex(node, 1);
long ne = DhSectionPos.getChildByIndex(2, node); long ne = DhSectionPos.getChildByIndex(node, 2);
long se = DhSectionPos.getChildByIndex(3, node); long se = DhSectionPos.getChildByIndex(node, 3);
// confirm no children have the same values // confirm no children have the same values
Assert.assertNotEquals(nw, sw); Assert.assertNotEquals(nw, sw);
@@ -259,13 +259,13 @@ public class DhSectionPosTest
long originSectionPos = DhSectionPos.encode((byte) 0,0,0); long originSectionPos = DhSectionPos.encode((byte) 0,0,0);
originSectionPos = DhSectionPos.convertToDetailLevel((byte) 1, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, (byte) 1);
assertSectionPosEqual(DhSectionPos.encode((byte) 1, 0, 0), originSectionPos); assertSectionPosEqual(DhSectionPos.encode((byte) 1, 0, 0), originSectionPos);
originSectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
assertSectionPosEqual(DhSectionPos.encode(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0), originSectionPos); assertSectionPosEqual(DhSectionPos.encode(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0), originSectionPos);
originSectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
assertSectionPosEqual(DhSectionPos.encode(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, 0, 0), originSectionPos); assertSectionPosEqual(DhSectionPos.encode(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, 0, 0), originSectionPos);
@@ -273,13 +273,13 @@ public class DhSectionPosTest
long offsetSectionPos = DhSectionPos.encode((byte) 0,-10000,5000); long offsetSectionPos = DhSectionPos.encode((byte) 0,-10000,5000);
offsetSectionPos = DhSectionPos.convertToDetailLevel((byte) 1, offsetSectionPos); offsetSectionPos = DhSectionPos.convertToDetailLevel(offsetSectionPos, (byte) 1);
assertSectionPosEqual(DhSectionPos.encode((byte) 1, -5000, 2500), offsetSectionPos); assertSectionPosEqual(DhSectionPos.encode((byte) 1, -5000, 2500), offsetSectionPos);
offsetSectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, offsetSectionPos); offsetSectionPos = DhSectionPos.convertToDetailLevel(offsetSectionPos, DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
assertSectionPosEqual(DhSectionPos.encode(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, -157, 78), offsetSectionPos); assertSectionPosEqual(DhSectionPos.encode(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, -157, 78), offsetSectionPos);
offsetSectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, offsetSectionPos); offsetSectionPos = DhSectionPos.convertToDetailLevel(offsetSectionPos, DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
assertSectionPosEqual(DhSectionPos.encode(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, -1, 0), offsetSectionPos); assertSectionPosEqual(DhSectionPos.encode(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, -1, 0), offsetSectionPos);
} }
@@ -294,38 +294,38 @@ public class DhSectionPosTest
// 1 -> 0 // 1 -> 0
byte returnDetailLevel = 0; byte returnDetailLevel = 0;
originSectionPos = DhSectionPos.convertToDetailLevel((byte) 1, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, (byte) 1);
assertSectionPosEqual(2, DhSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel, originSectionPos)); assertSectionPosEqual(2, DhSectionPos.getWidthCountForLowerDetailedSection(originSectionPos, returnDetailLevel));
sectionPos = DhSectionPos.convertToDetailLevel((byte) 1, sectionPos); sectionPos = DhSectionPos.convertToDetailLevel(sectionPos, (byte) 1);
assertSectionPosEqual(2, DhSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel, sectionPos)); assertSectionPosEqual(2, DhSectionPos.getWidthCountForLowerDetailedSection(sectionPos, returnDetailLevel));
// 2 -> 1 // 2 -> 1
returnDetailLevel = 1; returnDetailLevel = 1;
originSectionPos = DhSectionPos.convertToDetailLevel((byte) 2, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, (byte) 2);
assertSectionPosEqual(2, DhSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel, originSectionPos)); assertSectionPosEqual(2, DhSectionPos.getWidthCountForLowerDetailedSection(originSectionPos, returnDetailLevel));
sectionPos = DhSectionPos.convertToDetailLevel((byte) 2, sectionPos); sectionPos = DhSectionPos.convertToDetailLevel(sectionPos, (byte) 2);
assertSectionPosEqual(2, DhSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel, sectionPos)); assertSectionPosEqual(2, DhSectionPos.getWidthCountForLowerDetailedSection(sectionPos, returnDetailLevel));
// Block -> 0 // Block -> 0
returnDetailLevel = 0; returnDetailLevel = 0;
originSectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
assertSectionPosEqual(64, DhSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel, originSectionPos)); assertSectionPosEqual(64, DhSectionPos.getWidthCountForLowerDetailedSection(originSectionPos, returnDetailLevel));
sectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, sectionPos); sectionPos = DhSectionPos.convertToDetailLevel(sectionPos, DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
assertSectionPosEqual(64, DhSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel, sectionPos)); assertSectionPosEqual(64, DhSectionPos.getWidthCountForLowerDetailedSection(sectionPos, returnDetailLevel));
// Region -> 3 // Region -> 3
returnDetailLevel = 3; returnDetailLevel = 3;
originSectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
assertSectionPosEqual(4096, DhSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel, originSectionPos)); assertSectionPosEqual(4096, DhSectionPos.getWidthCountForLowerDetailedSection(originSectionPos, returnDetailLevel));
sectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, sectionPos); sectionPos = DhSectionPos.convertToDetailLevel(sectionPos, DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
assertSectionPosEqual(4096, DhSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel, sectionPos)); assertSectionPosEqual(4096, DhSectionPos.getWidthCountForLowerDetailedSection(sectionPos, returnDetailLevel));
} }
@@ -339,19 +339,19 @@ public class DhSectionPosTest
assertSectionPosEqual(1, DhSectionPos.getBlockWidth(originSectionPos)); assertSectionPosEqual(1, DhSectionPos.getBlockWidth(originSectionPos));
assertSectionPosEqual(1, DhSectionPos.getBlockWidth(sectionPos)); assertSectionPosEqual(1, DhSectionPos.getBlockWidth(sectionPos));
originSectionPos = DhSectionPos.convertToDetailLevel((byte) 1, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, (byte) 1);
assertSectionPosEqual(2, DhSectionPos.getBlockWidth(originSectionPos)); assertSectionPosEqual(2, DhSectionPos.getBlockWidth(originSectionPos));
sectionPos = DhSectionPos.convertToDetailLevel((byte) 1, sectionPos); sectionPos = DhSectionPos.convertToDetailLevel(sectionPos, (byte) 1);
assertSectionPosEqual(2, DhSectionPos.getBlockWidth(sectionPos)); assertSectionPosEqual(2, DhSectionPos.getBlockWidth(sectionPos));
originSectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
assertSectionPosEqual(64, DhSectionPos.getBlockWidth(originSectionPos)); assertSectionPosEqual(64, DhSectionPos.getBlockWidth(originSectionPos));
sectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, sectionPos); sectionPos = DhSectionPos.convertToDetailLevel(sectionPos, DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
assertSectionPosEqual(64, DhSectionPos.getBlockWidth(sectionPos)); assertSectionPosEqual(64, DhSectionPos.getBlockWidth(sectionPos));
originSectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
assertSectionPosEqual(32768, DhSectionPos.getBlockWidth(originSectionPos)); assertSectionPosEqual(32768, DhSectionPos.getBlockWidth(originSectionPos));
sectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, sectionPos); sectionPos = DhSectionPos.convertToDetailLevel(sectionPos, DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
assertSectionPosEqual(32768, DhSectionPos.getBlockWidth(sectionPos)); assertSectionPosEqual(32768, DhSectionPos.getBlockWidth(sectionPos));
} }
@@ -370,32 +370,32 @@ public class DhSectionPosTest
// 2x2 blocks // 2x2 blocks
originSectionPos = DhSectionPos.convertToDetailLevel((byte) 1, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, (byte) 1);
Assert.assertEquals(new DhBlockPos2D(0, 0), DhSectionPos.getCenterBlockPos(originSectionPos)); Assert.assertEquals(new DhBlockPos2D(0, 0), DhSectionPos.getCenterBlockPos(originSectionPos));
sectionPos = DhSectionPos.convertToDetailLevel((byte) 1, sectionPos); sectionPos = DhSectionPos.convertToDetailLevel(sectionPos, (byte) 1);
Assert.assertEquals(new DhBlockPos2D(-10000, 5000), DhSectionPos.getCenterBlockPos(sectionPos)); Assert.assertEquals(new DhBlockPos2D(-10000, 5000), DhSectionPos.getCenterBlockPos(sectionPos));
//sectionPos = DhSectionPos.encode((byte) 1, 2303, 0); //sectionPos = DhSectionPos.encode((byte) 1, 2303, 0);
//Assert.assertEquals(new DhBlockPos2D(4606, 0), DhSectionPos.getCenterBlockPos(sectionPos)); //Assert.assertEquals(new DhBlockPos2D(4606, 0), DhSectionPos.getCenterBlockPos(sectionPos));
// 4x4 blocks // 4x4 blocks
originSectionPos = DhSectionPos.convertToDetailLevel((byte) 2, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, (byte) 2);
Assert.assertEquals(new DhBlockPos2D(2, 2), DhSectionPos.getCenterBlockPos(originSectionPos)); Assert.assertEquals(new DhBlockPos2D(2, 2), DhSectionPos.getCenterBlockPos(originSectionPos));
sectionPos = DhSectionPos.convertToDetailLevel((byte) 2, sectionPos); sectionPos = DhSectionPos.convertToDetailLevel(sectionPos, (byte) 2);
Assert.assertEquals(new DhBlockPos2D(-9998, 5002), DhSectionPos.getCenterBlockPos(sectionPos)); Assert.assertEquals(new DhBlockPos2D(-9998, 5002), DhSectionPos.getCenterBlockPos(sectionPos));
// 64x64 blocks // 64x64 blocks
originSectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(new DhBlockPos2D(32, 32), DhSectionPos.getCenterBlockPos(originSectionPos)); Assert.assertEquals(new DhBlockPos2D(32, 32), DhSectionPos.getCenterBlockPos(originSectionPos));
sectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, sectionPos); sectionPos = DhSectionPos.convertToDetailLevel(sectionPos, DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(new DhBlockPos2D(-10016, 5024), DhSectionPos.getCenterBlockPos(sectionPos)); Assert.assertEquals(new DhBlockPos2D(-10016, 5024), DhSectionPos.getCenterBlockPos(sectionPos));
// 32,768 x 32,768 blocks // 32,768 x 32,768 blocks
originSectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, originSectionPos); originSectionPos = DhSectionPos.convertToDetailLevel(originSectionPos, DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(new DhBlockPos2D(16384, 16384), DhSectionPos.getCenterBlockPos(originSectionPos)); Assert.assertEquals(new DhBlockPos2D(16384, 16384), DhSectionPos.getCenterBlockPos(originSectionPos));
sectionPos = DhSectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, sectionPos); sectionPos = DhSectionPos.convertToDetailLevel(sectionPos, DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(new DhBlockPos2D(-16384, 16384), DhSectionPos.getCenterBlockPos(sectionPos)); Assert.assertEquals(new DhBlockPos2D(-16384, 16384), DhSectionPos.getCenterBlockPos(sectionPos));
} }
@@ -439,15 +439,15 @@ public class DhSectionPosTest
{ {
long pos = DhSectionPos.encode((byte) 0, 0, 0); long pos = DhSectionPos.encode((byte) 0, 0, 0);
assertSectionPosEqual(DhSectionPos.encode((byte) 0, 0, -1), DhSectionPos.getAdjacentPos(EDhDirection.NORTH, pos)); assertSectionPosEqual(DhSectionPos.encode((byte) 0, 0, -1), DhSectionPos.getAdjacentPos(pos, EDhDirection.NORTH));
assertSectionPosEqual(DhSectionPos.encode((byte) 0, 0, 1), DhSectionPos.getAdjacentPos(EDhDirection.SOUTH, pos)); assertSectionPosEqual(DhSectionPos.encode((byte) 0, 0, 1), DhSectionPos.getAdjacentPos(pos, EDhDirection.SOUTH));
assertSectionPosEqual(DhSectionPos.encode((byte) 0, 1, 0), DhSectionPos.getAdjacentPos(EDhDirection.EAST, pos)); assertSectionPosEqual(DhSectionPos.encode((byte) 0, 1, 0), DhSectionPos.getAdjacentPos(pos, EDhDirection.EAST));
assertSectionPosEqual(DhSectionPos.encode((byte) 0, -1, 0), DhSectionPos.getAdjacentPos(EDhDirection.WEST, pos)); assertSectionPosEqual(DhSectionPos.encode((byte) 0, -1, 0), DhSectionPos.getAdjacentPos(pos, EDhDirection.WEST));
// getting the adjacent position in the up and down position don't make sense // getting the adjacent position in the up and down position don't make sense
Assert.assertThrows(IllegalArgumentException.class, () -> { DhSectionPos.getAdjacentPos(EDhDirection.UP, pos); }); Assert.assertThrows(IllegalArgumentException.class, () -> { DhSectionPos.getAdjacentPos(pos, EDhDirection.UP); });
Assert.assertThrows(IllegalArgumentException.class, () -> { DhSectionPos.getAdjacentPos(EDhDirection.DOWN, pos); }); Assert.assertThrows(IllegalArgumentException.class, () -> { DhSectionPos.getAdjacentPos(pos, EDhDirection.DOWN); });
} }
@Test @Test
@@ -457,11 +457,11 @@ public class DhSectionPosTest
ArrayList<Long> childPosList = new ArrayList<>(); ArrayList<Long> childPosList = new ArrayList<>();
AtomicInteger childCount = new AtomicInteger(0); AtomicInteger childCount = new AtomicInteger(0);
DhSectionPos.forEachChild((childPos) -> DhSectionPos.forEachChild(pos, (childPos) ->
{ {
childCount.incrementAndGet(); childCount.incrementAndGet();
childPosList.add(childPos); childPosList.add(childPos);
}, pos); });
Assert.assertTrue(childPosList.contains(DhSectionPos.encode((byte) 0, 0, 0))); Assert.assertTrue(childPosList.contains(DhSectionPos.encode((byte) 0, 0, 0)));
Assert.assertTrue(childPosList.contains(DhSectionPos.encode((byte) 0, 1, 0))); Assert.assertTrue(childPosList.contains(DhSectionPos.encode((byte) 0, 1, 0)));
+1 -1
View File
@@ -692,7 +692,7 @@ public class QuadTreeTest
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
long childPos = DhSectionPos.getChildByIndex(i, rootNode.sectionPos); long childPos = DhSectionPos.getChildByIndex(rootNode.sectionPos, i);
QuadNode<Integer> childNode = rootNode.getChildByIndex(i); QuadNode<Integer> childNode = rootNode.getChildByIndex(i);
Assert.assertEquals("child position not the same as " + long.class.getSimpleName() + "'s getChildByIndex()", childPos, childNode.sectionPos); Assert.assertEquals("child position not the same as " + long.class.getSimpleName() + "'s getChildByIndex()", childPos, childNode.sectionPos);
} }