refactoring quadTree/Node, RenderSection, and ColRenderSource

This commit is contained in:
James Seibel
2023-03-27 21:11:09 -05:00
parent 779d93700f
commit 82fe7c099d
6 changed files with 35 additions and 20 deletions
@@ -13,8 +13,6 @@ import com.seibel.lod.core.render.AbstractRenderBuffer;
import com.seibel.lod.core.enums.ELodDirection;
import com.seibel.lod.core.logging.DhLoggerBuilder;
import com.seibel.lod.core.level.IDhLevel;
import com.seibel.lod.core.render.LodQuadTree;
import com.seibel.lod.core.render.LodRenderSection;
import com.seibel.lod.core.util.BitShiftUtil;
import com.seibel.lod.core.util.ColorUtil;
import com.seibel.lod.core.util.RenderDataPointUtil;
@@ -366,10 +364,9 @@ public class ColumnRenderSource
}
}
public void enableRender(IDhClientLevel level, LodQuadTree quadTree)
public void enableRender(IDhClientLevel level)
{
this.level = level;
//this.tryBuildBuffer(level, quadTree); // FIXME why was this commented out?
}
public void disableRender() { this.cancelBuildBuffer(); }
@@ -382,7 +379,7 @@ public class ColumnRenderSource
* @param renderBufferToSwap The slot for swapping in the new buffer.
* @return True if the swap was successful. False if swap is not needed or if it is in progress.
*/
public boolean trySwapRenderBufferAsync(ColumnRenderSource renderSource, AtomicReference<AbstractRenderBuffer> renderBufferToSwap)
public boolean trySwapRenderBuffer(ColumnRenderSource renderSource, AtomicReference<AbstractRenderBuffer> renderBufferToSwap)
{
// prevent swapping the buffer to quickly
if (this.lastNs != -1 && System.nanoTime() - this.lastNs < SWAP_TIMEOUT_IN_NS)
@@ -7,8 +7,6 @@ import com.seibel.lod.core.pos.DhSectionPos;
import com.seibel.lod.core.file.renderfile.ILodRenderSourceProvider;
import com.seibel.lod.core.logging.DhLoggerBuilder;
import com.seibel.lod.core.util.DetailDistanceUtil;
import com.seibel.lod.core.util.LodUtil;
import com.seibel.lod.core.util.gridList.MovableGridRingList;
import com.seibel.lod.core.util.objects.quadTree.QuadNode;
import com.seibel.lod.core.util.objects.quadTree.QuadTree;
import org.apache.logging.log4j.Logger;
@@ -247,14 +245,14 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements AutoClose
// enable the render section
nullableRenderSection.loadRenderSourceAndEnableRendering(this.renderSourceProvider);
nullableRenderSection.tick(this, this.level);
nullableRenderSection.tick(this.level);
// delete/disable children
nullableQuadNode.deleteAllChildren((renderSection) ->
{
if (renderSection != null)
{
renderSection.disableAndDisposeRender();
renderSection.disableAndDisposeRendering();
}
});
}
@@ -290,7 +288,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements AutoClose
}
private static boolean isSectionLoaded(LodRenderSection renderSection)
{
return renderSection != null && renderSection.isLoaded() && !renderSection.getRenderSource().isEmpty();
return renderSection != null && renderSection.isLoaded() && renderSection.isRenderingEnabled() && !renderSection.getRenderSource().isEmpty();
}
@@ -53,7 +53,9 @@ public class LodRenderSection
}
this.isRenderEnabled = true;
}
public void disableAndDisposeRender()
public void disableAndDisposeRendering()
{
if (!this.isRenderEnabled)
{
@@ -102,7 +104,7 @@ public class LodRenderSection
// update methods //
//================//
public void tick(LodQuadTree quadTree, IDhClientLevel level)
public void tick(IDhClientLevel level)
{
// get the renderSource if it has finished loading
if (this.loadFuture != null && this.loadFuture.isDone())
@@ -112,7 +114,7 @@ public class LodRenderSection
if (this.isRenderEnabled)
{
this.renderSource.enableRender(level, quadTree);
this.renderSource.enableRender(level);
}
}
}
@@ -135,7 +135,7 @@ public class RenderBufferHandler
// Build the sorted list
this.loadedNearToFarBuffers = new SortedArraySet<>((a, b) -> -farToNearComparator.compare(a, b)); // TODO is the comparator named wrong?
this.quadTree.forEachLeafValue((renderSection, sectionPos) ->
this.quadTree.forEachValue((renderSection, sectionPos) ->
{
if (renderSection != null && renderSection.shouldRender())
{
@@ -166,7 +166,7 @@ public class RenderBufferHandler
public void update()
{
this.quadTree.forEachLeafValue((renderSection, sectionPos) ->
this.quadTree.forEachValue((renderSection, sectionPos) ->
{
if (renderSection != null)
{
@@ -185,7 +185,7 @@ public class RenderBufferHandler
else
{
LodUtil.assertTrue(currentRenderSource != null); // section.shouldRender() should have ensured this
currentRenderSource.trySwapRenderBufferAsync(renderSection.getRenderSource(), renderSection.abstractRenderBufferRef);
currentRenderSource.trySwapRenderBuffer(renderSection.getRenderSource(), renderSection.abstractRenderBufferRef);
}
}
});
@@ -193,9 +193,9 @@ public class RenderBufferHandler
public void close()
{
this.quadTree.forEachLeafValue((renderSection) ->
this.quadTree.forEachValue((renderSection) ->
{
if (renderSection.abstractRenderBufferRef.get() != null)
if (renderSection != null && renderSection.abstractRenderBufferRef.get() != null)
{
renderSection.abstractRenderBufferRef.get().close();
renderSection.abstractRenderBufferRef.set(null);
@@ -268,7 +268,10 @@ public class QuadNode<T>
* Applies the given consumer to all leaf nodes below this node. <br>
* Note: this will pass in null values.
*/
public void forAllLeafValues(BiConsumer<? super T, DhSectionPos> consumer)
public void forAllLeafValues(BiConsumer<? super T, DhSectionPos> consumer) { this.forAllChildValues(consumer, true, true); }
public void forAllChildValues(BiConsumer<? super T, DhSectionPos> consumer) { this.forAllChildValues(consumer, false, true); }
private void forAllChildValues(BiConsumer<? super T, DhSectionPos> consumer, boolean onlyReturnLeafNodes, boolean topCaller) // TODO rename/refactor topCaller parameter
{
if (this.getChildCount() == 0 || this.sectionPos.sectionDetailLevel == this.minimumDetailLevel)
{
@@ -277,18 +280,24 @@ public class QuadNode<T>
}
else
{
if (!onlyReturnLeafNodes && !topCaller)
{
consumer.accept(this.value, this.sectionPos);
}
for (int i = 0; i < 4; i++)
{
QuadNode<T> childNode = this.getChildByIndex(i);
if (childNode != null)
{
// TODO should this pass in a null value if the child node is null?
childNode.forAllLeafValues(consumer);
childNode.forAllChildValues(consumer, onlyReturnLeafNodes, false);
}
}
}
}
public void deleteAllChildren() { this.deleteAllChildren(null); }
/** @param removedItemConsumer is only fired for non-null nodes, however the value passed in may be null */
public void deleteAllChildren(Consumer<? super T> removedItemConsumer)
@@ -216,6 +216,15 @@ public class QuadTree<T>
});
}
public void forEachValue(Consumer<? super T> consumer) { this.forEachValue((value, sectionPos) -> { consumer.accept(value); }); }
public void forEachValue(BiConsumer<? super T, DhSectionPos> consumer)
{
this.forEachRootNode((rootNode) ->
{
rootNode.forAllChildValues(consumer);
});
}