diff --git a/src/main/java/com/goby56/wakes/render/debug/WakeDebugRenderer.java b/src/main/java/com/goby56/wakes/render/debug/WakeDebugRenderer.java index 9ace79d..ee5821f 100644 --- a/src/main/java/com/goby56/wakes/render/debug/WakeDebugRenderer.java +++ b/src/main/java/com/goby56/wakes/render/debug/WakeDebugRenderer.java @@ -1,6 +1,7 @@ package com.goby56.wakes.render.debug; import com.goby56.wakes.WakesClient; +import com.goby56.wakes.simulation.QuadTree; import com.goby56.wakes.simulation.WakeHandler; import com.goby56.wakes.simulation.WakeNode; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; @@ -10,19 +11,38 @@ import net.minecraft.util.math.Vec3d; import java.util.ArrayList; +import java.util.Random; public class WakeDebugRenderer implements WorldRenderEvents.DebugRender { @Override public void beforeDebugRender(WorldRenderContext context) { - if (!WakesClient.CONFIG_INSTANCE.drawDebugBoxes) { - return; + if (WakesClient.CONFIG_INSTANCE.drawDebugBoxes) { + WakeHandler wakeHandler = WakeHandler.getInstance(); + for (QuadTree.DebugBB debugBox : wakeHandler.getBBs()) { + System.out.println(debugBox); + if (debugBox.depth() < 4) { + continue; + } + Random r = new Random(debugBox.depth()); + DebugRenderer.drawBox(context.matrixStack(), context.consumers(), debugBox.bb(), r.nextFloat(), r.nextFloat(), r.nextFloat(), 0.4f); + } + ArrayList nodes = wakeHandler.getVisible(context.frustum()); + for (WakeNode node : nodes) { + Vec3d pos = node.getPos().add(context.camera().getPos().negate()); + Box box = new Box(pos.x, pos.y - 0.1, pos.z, pos.x + 1, pos.y - 0.2, pos.z + 1); + DebugRenderer.drawBox(context.matrixStack(), context.consumers(), box, 1f, 0f, 1f, 0.4f); + } } - ArrayList nodes = WakeHandler.getInstance().getVisible(context.frustum()); - for (WakeNode node : nodes) { - Vec3d pos = node.getPos().add(context.camera().getPos().negate()); - Box box = new Box(pos.x, pos.y - 0.1, pos.z, pos.x + 1, pos.y - 0.2, pos.z + 1); - DebugRenderer.drawBox(context.matrixStack(), context.consumers(), box, 1f, 0f, 1f, 0.4f); + } + + public static class TreeBoundingBox { + public Box bb; + public int depth; + + public TreeBoundingBox(Box bb, int depth) { + this.bb = bb; + this.depth = depth; } } } diff --git a/src/main/java/com/goby56/wakes/simulation/QuadTree.java b/src/main/java/com/goby56/wakes/simulation/QuadTree.java index d57578d..c8f356f 100644 --- a/src/main/java/com/goby56/wakes/simulation/QuadTree.java +++ b/src/main/java/com/goby56/wakes/simulation/QuadTree.java @@ -191,6 +191,20 @@ private void distribute() { throw new NotImplementedException(); } + public void getBBs(ArrayList bbs, int height) { + bbs.add(new DebugBB(this.bounds.toBox(height), this.depth)); + if (this.NE == null) { + return; + } + this.NE.getBBs(bbs, height); + this.NW.getBBs(bbs, height); + this.SW.getBBs(bbs, height); + this.SE.getBBs(bbs, height); + } + + public record DebugBB(Box bb, int depth) { + } + public record AABB(int x, int z, int width) { public boolean contains(int x, int z) { return this.x - this.width <= x && x <= this.x + this.width && diff --git a/src/main/java/com/goby56/wakes/simulation/WakeHandler.java b/src/main/java/com/goby56/wakes/simulation/WakeHandler.java index 60f484c..07523a7 100644 --- a/src/main/java/com/goby56/wakes/simulation/WakeHandler.java +++ b/src/main/java/com/goby56/wakes/simulation/WakeHandler.java @@ -5,6 +5,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.Frustum; import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.math.Box; import net.minecraft.world.World; import java.util.ArrayList; @@ -101,16 +102,14 @@ public int getTotal() { return n; } - public ArrayList getNearby(int x, int y, int z) { - ArrayList foundNodes = new ArrayList<>(); - int i = this.getArrayIndex(y); - if (i < 0) return foundNodes; - if (this.trees.get(i) == null) { - return foundNodes; + public ArrayList getBBs() { + ArrayList boxes = new ArrayList<>(); + for (int y = 0; y < this.maxY - this.minY; y++) { + if (this.trees.get(y) != null) { + this.trees.get(y).getBBs(boxes, y - Math.abs(this.minY)); + } } - QuadTree.Circle range = new QuadTree.Circle(x, z, this.MAX_QUERY_RANGE); - this.trees.get(i).query(range, foundNodes); - return foundNodes; + return boxes; } private int getArrayIndex(int height) {