Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Implement skeleton breadth search, disabled right now as it's broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver-makes-code committed Jan 19, 2024
1 parent 2e7b37d commit 1042f26
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Client/Rendering/World/ChunkRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,13 +31,19 @@ public class ChunkRenderer : Renderer {

var index = z + y * realRenderDistance + x * realRenderDistance * realRenderDistance;

if (index < 0 || index >= renderSlots.Length)
return null;

return renderSlots[index];
}
set {
if (renderSlots == null) return;

var index = z + y * realRenderDistance + x * realRenderDistance * realRenderDistance;

if (index < 0 || index >= renderSlots.Length)
return;

renderSlots[index] = value;
}
}
Expand Down Expand Up @@ -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<ivec3>();
var visited = new HashSet<ivec3>();
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);

Expand Down

0 comments on commit 1042f26

Please sign in to comment.