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

Commit

Permalink
waa
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver-makes-code committed Jan 20, 2024
1 parent 5eabde5 commit 790c875
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 8 additions & 0 deletions Common/Util/QueueExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Voxel.Common.Util;

public static class QueueExtensions {
public static void Add<T>(this Queue<T> queue, T value)
=> queue.Enqueue(value);
public static T Remove<T>(this Queue<T> queue)
=> queue.Dequeue();
}
11 changes: 5 additions & 6 deletions Common/World/Chunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public HashSet<ivec3> FloodFill(ivec3 root) {
return connected;
}

var queue = new Stack<ivec3>();
queue.Push(root.Loop(PositionExtensions.ChunkSize));
var queue = new Queue<ivec3>();
queue.Add(root.Loop(PositionExtensions.ChunkSize));
while (queue.Count > 0) {
var node = queue.Pop();
var node = queue.Remove();

if (!GetBlock(node).IsNonSolid)
continue;
Expand All @@ -87,14 +87,13 @@ public HashSet<ivec3> FloodFill(ivec3 root) {
var newNode = node;
newNode[i] -= 1;
if (!connected.Contains(newNode))
queue.Push(newNode);
queue.Add(newNode);
}
if (node[i] < PositionExtensions.ChunkSize) {
var newNode = node;
newNode[i] += 1;
queue.Push(newNode);
if (!connected.Contains(newNode))
queue.Push(newNode);
queue.Add(newNode);
}
}
}
Expand Down

0 comments on commit 790c875

Please sign in to comment.