From 1042f26eaae3eba1e9c973d54f4613331f743f5b Mon Sep 17 00:00:00 2001 From: Oliver-makes-code Date: Fri, 19 Jan 2024 15:11:54 -0600 Subject: [PATCH] Implement skeleton breadth search, disabled right now as it's broken --- Client/Rendering/World/ChunkRenderer.cs | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Client/Rendering/World/ChunkRenderer.cs b/Client/Rendering/World/ChunkRenderer.cs index eb0e506..ea75942 100644 --- a/Client/Rendering/World/ChunkRenderer.cs +++ b/Client/Rendering/World/ChunkRenderer.cs @@ -5,6 +5,7 @@ using Voxel.Client.Rendering.Models; using Voxel.Client.Rendering.Texture; using Voxel.Client.Rendering.VertexTypes; +using Voxel.Common.Collision; using Voxel.Common.Util; using Voxel.Common.World; using Voxel.Core.Util; @@ -30,6 +31,9 @@ public class ChunkRenderer : Renderer { var index = z + y * realRenderDistance + x * realRenderDistance * realRenderDistance; + if (index < 0 || index >= renderSlots.Length) + return null; + return renderSlots[index]; } set { @@ -37,6 +41,9 @@ public class ChunkRenderer : Renderer { var index = z + y * realRenderDistance + x * realRenderDistance * realRenderDistance; + if (index < 0 || index >= renderSlots.Length) + return; + renderSlots[index] = value; } } @@ -118,6 +125,42 @@ public override void Render(double delta) { CommandList.SetGraphicsResourceSet(2, TerrainAtlas.AtlasResourceSet); CommandList.SetIndexBuffer(RenderSystem.CommonIndexBuffer, IndexFormat.UInt32); + + var queue = new Stack(); + var visited = new HashSet(); + queue.Push(ivec3.Zero); + visited.Add(ivec3.Zero); + + ivec3[] directions = [ + new(1, 0, 0), new(-1, 0, 0), + new(0, 1, 0), new(0, -1, 0), + new(0, 0, 1), new(0, 0, -1) + ]; + + while (queue.Count > 0) { + // Doesn't work yet. + break; + var curr = queue.Pop(); + var chunk = this[curr + renderDistance]; + if (chunk == null) + continue; + chunk.Render(delta); + + foreach (var dir in directions) { + var pos = dir + curr; + var slotPos = pos + renderDistance; + // TODO: Check against frustum + if ( + visited.Contains(pos) || + (slotPos < 0).Any || + (slotPos >= realRenderDistance).Any + ) + continue; + queue.Push(pos); + visited.Add(pos); + } + } + foreach (var slot in createdRenderSlots) slot.Render(delta);