Add DhSectionPos getBlockWidth() and getWidthCountForLowerDetailedSection()
This commit is contained in:
+1
-1
@@ -523,7 +523,7 @@ public class HighDetailIncompleteFullDataSource implements IIncompleteFullDataSo
|
||||
DhLodPos basePos = this.sectionPos.getCorner(SPARSE_UNIT_DETAIL);
|
||||
DhLodPos dataPos = pos.getCorner(SPARSE_UNIT_DETAIL);
|
||||
|
||||
int coveredChunks = pos.getWidth(SPARSE_UNIT_DETAIL).numberOfLodSectionsWide;
|
||||
int coveredChunks = pos.getWidthCountForLowerDetailedSection(SPARSE_UNIT_DETAIL);
|
||||
int sourceDataPerChunk = SPARSE_UNIT_SIZE >>> completeDataSource.getDataDetailLevel();
|
||||
LodUtil.assertTrue((coveredChunks * sourceDataPerChunk) == CompleteFullDataSource.WIDTH);
|
||||
|
||||
|
||||
+6
-6
@@ -398,7 +398,7 @@ public class LowDetailIncompleteFullDataSource extends FullDataArrayAccessor imp
|
||||
LodUtil.assertTrue(offsetX >= 0 && offsetX < WIDTH && offsetZ >= 0 && offsetZ < WIDTH);
|
||||
|
||||
int chunksPerData = 1 << (this.getDataDetailLevel() - HighDetailIncompleteFullDataSource.SPARSE_UNIT_DETAIL);
|
||||
int dataSpan = this.sectionPos.getWidth(this.getDataDetailLevel()).numberOfLodSectionsWide;
|
||||
int dataSpan = this.sectionPos.getWidthCountForLowerDetailedSection(this.getDataDetailLevel());
|
||||
|
||||
for (int xOffset = 0; xOffset < dataSpan; xOffset++)
|
||||
{
|
||||
@@ -419,7 +419,7 @@ public class LowDetailIncompleteFullDataSource extends FullDataArrayAccessor imp
|
||||
else
|
||||
{
|
||||
DhLodPos dataLodPos = pos.getSectionBBoxPos();
|
||||
int lowerSectionsPerData = this.sectionPos.getWidth(dataLodPos.detailLevel).numberOfLodSectionsWide;
|
||||
int lowerSectionsPerData = this.sectionPos.getWidthCountForLowerDetailedSection(dataLodPos.detailLevel);
|
||||
if (dataLodPos.x % lowerSectionsPerData != 0 || dataLodPos.z % lowerSectionsPerData != 0)
|
||||
{
|
||||
return;
|
||||
@@ -452,7 +452,7 @@ public class LowDetailIncompleteFullDataSource extends FullDataArrayAccessor imp
|
||||
|
||||
int offsetX = dataLodPos.x - thisLodPos.x;
|
||||
int offsetZ = dataLodPos.z - thisLodPos.z;
|
||||
int dataWidth = this.sectionPos.getWidth(this.getDataDetailLevel()).numberOfLodSectionsWide;
|
||||
int dataWidth = this.sectionPos.getWidthCountForLowerDetailedSection(this.getDataDetailLevel());
|
||||
|
||||
for (int xOffset = 0; xOffset < dataWidth; xOffset++)
|
||||
{
|
||||
@@ -465,7 +465,7 @@ public class LowDetailIncompleteFullDataSource extends FullDataArrayAccessor imp
|
||||
else
|
||||
{
|
||||
DhLodPos dataPos = pos.getSectionBBoxPos();
|
||||
int lowerSectionsPerData = this.sectionPos.getWidth(dataPos.detailLevel).numberOfLodSectionsWide;
|
||||
int lowerSectionsPerData = this.sectionPos.getWidthCountForLowerDetailedSection(dataPos.detailLevel);
|
||||
if (dataPos.x % lowerSectionsPerData != 0 || dataPos.z % lowerSectionsPerData != 0)
|
||||
{
|
||||
return;
|
||||
@@ -495,7 +495,7 @@ public class LowDetailIncompleteFullDataSource extends FullDataArrayAccessor imp
|
||||
|
||||
int offsetX = dataLodPos.x - thisLodPos.x;
|
||||
int offsetZ = dataLodPos.z - thisLodPos.z;
|
||||
int dataWidth = this.sectionPos.getWidth(this.getDataDetailLevel()).numberOfLodSectionsWide;
|
||||
int dataWidth = this.sectionPos.getWidthCountForLowerDetailedSection(this.getDataDetailLevel());
|
||||
|
||||
for (int xOffset = 0; xOffset < dataWidth; xOffset++)
|
||||
{
|
||||
@@ -508,7 +508,7 @@ public class LowDetailIncompleteFullDataSource extends FullDataArrayAccessor imp
|
||||
else
|
||||
{
|
||||
DhLodPos dataPos = pos.getSectionBBoxPos();
|
||||
int lowerSectionsPerData = this.sectionPos.getWidth(dataPos.detailLevel).numberOfLodSectionsWide;
|
||||
int lowerSectionsPerData = this.sectionPos.getWidthCountForLowerDetailedSection(dataPos.detailLevel);
|
||||
if (dataPos.x % lowerSectionsPerData != 0 || dataPos.z % lowerSectionsPerData != 0)
|
||||
{
|
||||
return;
|
||||
|
||||
+1
-1
@@ -526,7 +526,7 @@ public class ColumnRenderSource
|
||||
stringBuilder.append(this.sectionPos);
|
||||
stringBuilder.append(LINE_DELIMITER);
|
||||
|
||||
int size = this.sectionPos.getWidth().numberOfLodSectionsWide;
|
||||
int size = 1;
|
||||
for (int z = 0; z < size; z++)
|
||||
{
|
||||
for (int x = 0; x < size; x++)
|
||||
|
||||
+4
-4
@@ -135,9 +135,9 @@ public class FullDataToRenderDataTransformer
|
||||
int baseX = pos.getCorner().getCornerBlockPos().x;
|
||||
int baseZ = pos.getCorner().getCornerBlockPos().z;
|
||||
|
||||
for (int x = 0; x < pos.getWidth(dataDetail).numberOfLodSectionsWide; x++)
|
||||
for (int x = 0; x < pos.getWidthCountForLowerDetailedSection(dataDetail); x++)
|
||||
{
|
||||
for (int z = 0; z < pos.getWidth(dataDetail).numberOfLodSectionsWide; z++)
|
||||
for (int z = 0; z < pos.getWidthCountForLowerDetailedSection(dataDetail); z++)
|
||||
{
|
||||
throwIfThreadInterrupted();
|
||||
|
||||
@@ -184,9 +184,9 @@ public class FullDataToRenderDataTransformer
|
||||
{
|
||||
int baseX = pos.getCorner().getCornerBlockPos().x;
|
||||
int baseZ = pos.getCorner().getCornerBlockPos().z;
|
||||
for (int x = 0; x < pos.getWidth(dataDetail).numberOfLodSectionsWide; x++)
|
||||
for (int x = 0; x < pos.getWidthCountForLowerDetailedSection(dataDetail); x++)
|
||||
{
|
||||
for (int z = 0; z < pos.getWidth(dataDetail).numberOfLodSectionsWide; z++)
|
||||
for (int z = 0; z < pos.getWidthCountForLowerDetailedSection(dataDetail); z++)
|
||||
{
|
||||
throwIfThreadInterrupted();
|
||||
|
||||
|
||||
@@ -181,22 +181,25 @@ public class DhSectionPos
|
||||
this.sectionZ * BitShiftUtil.powerOfTwo(offset));
|
||||
}
|
||||
|
||||
public DhLodUnit getWidth() { return this.getWidth(this.sectionDetailLevel); } // this always returns 1...
|
||||
public DhLodUnit getWidth(byte returnDetailLevel)
|
||||
/**
|
||||
* A detail level of X lower than this section's detail level will return: <br>
|
||||
* 0 -> 1 <br>
|
||||
* 1 -> 2 <br>
|
||||
* 2 -> 4 <br>
|
||||
* 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.
|
||||
*/
|
||||
public int getWidthCountForLowerDetailedSection(byte returnDetailLevel)
|
||||
{
|
||||
LodUtil.assertTrue(returnDetailLevel <= this.sectionDetailLevel, "returnDetailLevel must be less than sectionDetail");
|
||||
byte offset = (byte) (this.sectionDetailLevel - returnDetailLevel);
|
||||
return new DhLodUnit(this.sectionDetailLevel, BitShiftUtil.powerOfTwo(offset));
|
||||
}
|
||||
|
||||
public int getNumberOfLodSectionsWide() { return this.getNumberOfLodSectionsWide(this.sectionDetailLevel); } // TODO this always returns 1...
|
||||
public int getNumberOfLodSectionsWide(byte returnDetailLevel)
|
||||
{
|
||||
LodUtil.assertTrue(returnDetailLevel <= this.sectionDetailLevel, "returnDetailLevel must be less than sectionDetail"); // TODO add something to the method name stating this
|
||||
byte offset = (byte) (this.sectionDetailLevel - returnDetailLevel);
|
||||
return BitShiftUtil.powerOfTwo(offset);
|
||||
}
|
||||
|
||||
/** @return how wide this section is in blocks */
|
||||
public int getBlockWidth() { return BitShiftUtil.powerOfTwo(this.sectionDetailLevel); }
|
||||
|
||||
|
||||
//==================//
|
||||
@@ -261,7 +264,7 @@ public class DhSectionPos
|
||||
DhBlockPos2D thisMinBlockPos = this.getCorner(LodUtil.BLOCK_DETAIL_LEVEL).getCornerBlockPos();
|
||||
DhBlockPos2D otherCornerBlockPos = otherPos.getCorner(LodUtil.BLOCK_DETAIL_LEVEL).getCornerBlockPos();
|
||||
|
||||
int thisBlockWidth = this.getWidth().toBlockWidth() - 1; // minus 1 to account for zero based positional indexing
|
||||
int thisBlockWidth = this.getBlockWidth() - 1; // minus 1 to account for zero based positional indexing
|
||||
DhBlockPos2D thisMaxBlockPos = new DhBlockPos2D(thisMinBlockPos.x + thisBlockWidth, thisMinBlockPos.z + thisBlockWidth);
|
||||
|
||||
return thisMinBlockPos.x <= otherCornerBlockPos.x && otherCornerBlockPos.x <= thisMaxBlockPos.x &&
|
||||
|
||||
+1
-1
@@ -180,7 +180,7 @@ public class QuadNode<T>
|
||||
if (!this.sectionPos.contains(inputSectionPos))
|
||||
{
|
||||
LOGGER.error((replaceValue ? "set " : "get ") + inputSectionPos + " center block: " + inputSectionPos.getCenter().getCornerBlockPos() + ", this pos: " + this.sectionPos + " this center block: " + this.sectionPos.getCenter().getCornerBlockPos());
|
||||
throw new IllegalArgumentException("Input section pos " + inputSectionPos + " outside of this quadNode's pos: " + this.sectionPos + ", this node's blockPos: " + this.sectionPos.convertNewToDetailLevel(LodUtil.BLOCK_DETAIL_LEVEL) + " block width: " + this.sectionPos.getWidth().toBlockWidth() + " input detail level: " + inputSectionPos.convertNewToDetailLevel(LodUtil.BLOCK_DETAIL_LEVEL) + " width: " + inputSectionPos.getWidth().toBlockWidth());
|
||||
throw new IllegalArgumentException("Input section pos " + inputSectionPos + " outside of this quadNode's pos: " + this.sectionPos + ", this node's blockPos: " + this.sectionPos.convertNewToDetailLevel(LodUtil.BLOCK_DETAIL_LEVEL) + " block width: " + this.sectionPos.getBlockWidth() + " input detail level: " + inputSectionPos.convertNewToDetailLevel(LodUtil.BLOCK_DETAIL_LEVEL) + " width: " + inputSectionPos.getBlockWidth());
|
||||
}
|
||||
|
||||
if (inputSectionPos.sectionDetailLevel > this.sectionPos.sectionDetailLevel)
|
||||
|
||||
@@ -256,40 +256,6 @@ public class DhSectionPosTest
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void GetDefaultWidth()
|
||||
{
|
||||
DhSectionPos originSectionPos = new DhSectionPos((byte) 0,0,0);
|
||||
DhSectionPos sectionPos = new DhSectionPos((byte) 0,-10000,5000);
|
||||
|
||||
// widths should be the same regardless of position in the world
|
||||
originSectionPos = originSectionPos.convertNewToDetailLevel((byte) 1);
|
||||
Assert.assertEquals(1, originSectionPos.getNumberOfLodSectionsWide());
|
||||
Assert.assertEquals(originSectionPos.getWidth().numberOfLodSectionsWide, originSectionPos.getNumberOfLodSectionsWide());
|
||||
|
||||
sectionPos = sectionPos.convertNewToDetailLevel((byte) 1);
|
||||
Assert.assertEquals(1, sectionPos.getNumberOfLodSectionsWide());
|
||||
Assert.assertEquals(sectionPos.getWidth().numberOfLodSectionsWide, sectionPos.getNumberOfLodSectionsWide());
|
||||
|
||||
|
||||
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
|
||||
Assert.assertEquals(1, originSectionPos.getNumberOfLodSectionsWide());
|
||||
Assert.assertEquals(originSectionPos.getWidth().numberOfLodSectionsWide, originSectionPos.getNumberOfLodSectionsWide());
|
||||
|
||||
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
|
||||
Assert.assertEquals(1, sectionPos.getNumberOfLodSectionsWide());
|
||||
Assert.assertEquals(sectionPos.getWidth().numberOfLodSectionsWide, sectionPos.getNumberOfLodSectionsWide());
|
||||
|
||||
|
||||
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
|
||||
Assert.assertEquals(1, originSectionPos.getNumberOfLodSectionsWide());
|
||||
Assert.assertEquals(originSectionPos.getWidth().numberOfLodSectionsWide, originSectionPos.getNumberOfLodSectionsWide());
|
||||
|
||||
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
|
||||
Assert.assertEquals(1, sectionPos.getNumberOfLodSectionsWide());
|
||||
Assert.assertEquals(sectionPos.getWidth().numberOfLodSectionsWide, sectionPos.getNumberOfLodSectionsWide());
|
||||
|
||||
}
|
||||
@Test
|
||||
public void GetOffsetWidth()
|
||||
{
|
||||
@@ -297,32 +263,70 @@ public class DhSectionPosTest
|
||||
DhSectionPos sectionPos = new DhSectionPos((byte) 0,-10000,5000);
|
||||
|
||||
|
||||
|
||||
// 1 -> 0
|
||||
byte returnDetailLevel = 0;
|
||||
originSectionPos = originSectionPos.convertNewToDetailLevel((byte) 1);
|
||||
Assert.assertEquals(2, originSectionPos.getNumberOfLodSectionsWide((byte) 0));
|
||||
Assert.assertEquals(originSectionPos.getWidth((byte) 0).numberOfLodSectionsWide, originSectionPos.getNumberOfLodSectionsWide((byte) 0));
|
||||
Assert.assertEquals(2, originSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel));
|
||||
|
||||
sectionPos = sectionPos.convertNewToDetailLevel((byte) 1);
|
||||
Assert.assertEquals(2, sectionPos.getNumberOfLodSectionsWide((byte) 0));
|
||||
Assert.assertEquals(sectionPos.getWidth((byte) 0).numberOfLodSectionsWide, sectionPos.getNumberOfLodSectionsWide((byte) 0));
|
||||
Assert.assertEquals(2, sectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel));
|
||||
|
||||
|
||||
|
||||
// 2 -> 1
|
||||
returnDetailLevel = 1;
|
||||
originSectionPos = originSectionPos.convertNewToDetailLevel((byte) 2);
|
||||
Assert.assertEquals(2, originSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel));
|
||||
|
||||
sectionPos = sectionPos.convertNewToDetailLevel((byte) 2);
|
||||
Assert.assertEquals(2, sectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel));
|
||||
|
||||
|
||||
|
||||
// Block -> 0
|
||||
returnDetailLevel = 0;
|
||||
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
|
||||
Assert.assertEquals(64, originSectionPos.getNumberOfLodSectionsWide((byte) 0));
|
||||
Assert.assertEquals(originSectionPos.getWidth((byte) 0).numberOfLodSectionsWide, originSectionPos.getNumberOfLodSectionsWide((byte) 0));
|
||||
Assert.assertEquals(64, originSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel));
|
||||
|
||||
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
|
||||
Assert.assertEquals(64, sectionPos.getNumberOfLodSectionsWide((byte) 0));
|
||||
Assert.assertEquals(sectionPos.getWidth((byte) 0).numberOfLodSectionsWide, sectionPos.getNumberOfLodSectionsWide((byte) 0));
|
||||
Assert.assertEquals(64, sectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel));
|
||||
|
||||
|
||||
// Region -> 3
|
||||
returnDetailLevel = 3;
|
||||
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
|
||||
Assert.assertEquals(4096, originSectionPos.getNumberOfLodSectionsWide((byte) 3));
|
||||
Assert.assertEquals(originSectionPos.getWidth((byte) 3).numberOfLodSectionsWide, originSectionPos.getNumberOfLodSectionsWide((byte) 3));
|
||||
Assert.assertEquals(4096, originSectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel));
|
||||
|
||||
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
|
||||
Assert.assertEquals(4096, sectionPos.getNumberOfLodSectionsWide((byte) 3));
|
||||
Assert.assertEquals(sectionPos.getWidth((byte) 3).numberOfLodSectionsWide, sectionPos.getNumberOfLodSectionsWide((byte) 3));
|
||||
Assert.assertEquals(4096, sectionPos.getWidthCountForLowerDetailedSection(returnDetailLevel));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void GetBlockWidth()
|
||||
{
|
||||
DhSectionPos originSectionPos = new DhSectionPos((byte) 0,0,0);
|
||||
DhSectionPos sectionPos = new DhSectionPos((byte) 0,-10000,5000);
|
||||
|
||||
|
||||
Assert.assertEquals(1, originSectionPos.getBlockWidth());
|
||||
Assert.assertEquals(1, sectionPos.getBlockWidth());
|
||||
|
||||
originSectionPos = originSectionPos.convertNewToDetailLevel((byte) 1);
|
||||
Assert.assertEquals(2, originSectionPos.getBlockWidth());
|
||||
sectionPos = sectionPos.convertNewToDetailLevel((byte) 1);
|
||||
Assert.assertEquals(2, sectionPos.getBlockWidth());
|
||||
|
||||
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
|
||||
Assert.assertEquals(64, originSectionPos.getBlockWidth());
|
||||
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
|
||||
Assert.assertEquals(64, sectionPos.getBlockWidth());
|
||||
|
||||
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
|
||||
Assert.assertEquals(32768, originSectionPos.getBlockWidth());
|
||||
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
|
||||
Assert.assertEquals(32768, sectionPos.getBlockWidth());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user