feat(rendering): frustum-cull chunk draws and log render counts
This commit is contained in:
@@ -39,6 +39,7 @@ public sealed class ChunkStreamer : IDisposable
|
||||
private Vector3i _spawnAnchor;
|
||||
|
||||
public int RendererCount => this._renderers.Count;
|
||||
public int TrackedCount => this._tracked.Count;
|
||||
public bool IsReady(Vector3i pos) => this._ready.Contains(pos);
|
||||
public bool SpawnReady => this._spawnReady;
|
||||
|
||||
@@ -88,9 +89,20 @@ public sealed class ChunkStreamer : IDisposable
|
||||
this.UpdateSpawnReady();
|
||||
}
|
||||
|
||||
public void DrawAll(Action<Vector3i, IChunkRenderer> drawCallback)
|
||||
// Draws every loaded chunk for which `isChunkVisible` returns true. Returns
|
||||
// the number of chunks actually drawn (passed the visibility test). The
|
||||
// visibility predicate lives with the caller so the streamer stays free of
|
||||
// any rendering/Frustum dependency.
|
||||
public int DrawVisible(Func<Vector3i, bool> isChunkVisible, Action<Vector3i, IChunkRenderer> draw)
|
||||
{
|
||||
foreach (var kvp in this._renderers) drawCallback(kvp.Key, kvp.Value);
|
||||
int drawn = 0;
|
||||
foreach (var kvp in this._renderers)
|
||||
{
|
||||
if (!isChunkVisible(kvp.Key)) continue;
|
||||
draw(kvp.Key, kvp.Value);
|
||||
drawn++;
|
||||
}
|
||||
return drawn;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -258,7 +270,7 @@ public sealed class ChunkStreamer : IDisposable
|
||||
}
|
||||
// Skip renderer allocation for empty meshes (pure-air chunks above
|
||||
// terrain, or chunks whose every face culls). The chunk still counts
|
||||
// as ready — DrawAll's iteration over _renderers naturally no-ops.
|
||||
// as ready — DrawVisible's iteration over _renderers naturally no-ops.
|
||||
if (result.Mesh.Length > 0)
|
||||
{
|
||||
this._renderers[result.Pos] = this._rendererFactory(result.Mesh);
|
||||
|
||||
Reference in New Issue
Block a user