feat(render): Phase A8 Wave 2 — EnvCellRenderer (WB EnvCellRenderManager port)
The core port. 1013 LOC of WB-faithful rendering algorithm:
- GetEnvCellGeomId : WB EnvCellRenderManager.cs:94-103 verbatim
- PrepareRenderBatches : WB EnvCellRenderManager.cs:247-373 verbatim
(parallel frustum-cull, per-cell slow path,
ThreadLocal merge, atomic snapshot swap)
- Render(filter:) : WB EnvCellRenderManager.cs:395-511 verbatim
(filter-driven gfxObj group + draw call build)
- RenderModernMDIInternal : WB BaseObjectRenderManager.cs:709-848
(single-slot variant; resize buffers,
group by cull mode + additive, MDI draw)
- PopulatePartGroups : WB EnvCellRenderManager.cs:572-580 verbatim
(Setup part recursion via PopulateRecursive)
- RegisterCell / FinalizeLandblock / RemoveLandblock — streaming seam
(no WB analog; bridges acdream's existing StreamingController +
LandblockStreamer to the renderer's per-cell instance store)
Documented deviations from WB:
- Drop _useModernRendering branch (Phase N.5 mandatory modern path)
- Drop SelectedInstance/HoveredInstance highlights (no editor state)
- _activeSnapshotGlobalGroups/GfxObjIds as sibling fields on the class
rather than on the snapshot (EnvCellVisibilitySnapshot per Task 4 spec
only carries BatchedByCell + VisibleLandblocks; global groups only
used in the unfiltered Render(pass) path which we don't take)
- ConcurrentDictionary<uint, EnvCellLandblock> keyed by full 32-bit
landblock id (WB uses ushort packed key; acdream uses full id throughout)
10 unit tests (GetEnvCellGeomId determinism + bit-33 dedup flag +
NeedsPrepare + dispose semantics + RemoveLandblock idempotence). Build
green; 23/23 Wave 1+2 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fc68d6d01f
commit
f16b8e9812
2 changed files with 1129 additions and 0 deletions
1013
src/AcDream.App/Rendering/Wb/EnvCellRenderer.cs
Normal file
1013
src/AcDream.App/Rendering/Wb/EnvCellRenderer.cs
Normal file
File diff suppressed because it is too large
Load diff
116
tests/AcDream.App.Tests/Rendering/Wb/EnvCellRendererTests.cs
Normal file
116
tests/AcDream.App.Tests/Rendering/Wb/EnvCellRendererTests.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
// Tests for EnvCellRenderer (Phase A8, 2026-05-28).
|
||||
// These cover the pure data-handling portions of EnvCellRenderer.
|
||||
// The GL-dependent Render() and RenderModernMDIInternal() paths require a
|
||||
// GL context and are visual-verified at the render frame (Task 10).
|
||||
|
||||
using System.Collections.Generic;
|
||||
using AcDream.App.Rendering.Wb;
|
||||
using Xunit;
|
||||
|
||||
namespace AcDream.App.Tests.Rendering.Wb;
|
||||
|
||||
public class EnvCellRendererTests
|
||||
{
|
||||
// -----------------------------------------------------------------------
|
||||
// GetEnvCellGeomId — verbatim port of WB EnvCellRenderManager.cs:94-103
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
[Fact]
|
||||
public void GetEnvCellGeomId_DedupBitSet()
|
||||
{
|
||||
var id = EnvCellRenderer.GetEnvCellGeomId(0x42, 7, new List<ushort> { 1, 2, 3 });
|
||||
// Bit 33 (0x2_0000_0000) must be set — distinguishes dedup geom from per-cell ids.
|
||||
Assert.NotEqual(0UL, id & 0x2_0000_0000UL);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEnvCellGeomId_Deterministic()
|
||||
{
|
||||
var s = new List<ushort> { 1, 2, 3 };
|
||||
var a = EnvCellRenderer.GetEnvCellGeomId(0x42, 7, s);
|
||||
var b = EnvCellRenderer.GetEnvCellGeomId(0x42, 7, s);
|
||||
Assert.Equal(a, b);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEnvCellGeomId_DiffersByEnvironmentId()
|
||||
{
|
||||
var a = EnvCellRenderer.GetEnvCellGeomId(0x42, 7, new List<ushort> { 1 });
|
||||
var b = EnvCellRenderer.GetEnvCellGeomId(0x43, 7, new List<ushort> { 1 });
|
||||
Assert.NotEqual(a, b);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEnvCellGeomId_DiffersByCellStructure()
|
||||
{
|
||||
var a = EnvCellRenderer.GetEnvCellGeomId(0x42, 7, new List<ushort> { 1 });
|
||||
var b = EnvCellRenderer.GetEnvCellGeomId(0x42, 8, new List<ushort> { 1 });
|
||||
Assert.NotEqual(a, b);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEnvCellGeomId_DiffersBySurfaces()
|
||||
{
|
||||
var a = EnvCellRenderer.GetEnvCellGeomId(0x42, 7, new List<ushort> { 1 });
|
||||
var b = EnvCellRenderer.GetEnvCellGeomId(0x42, 7, new List<ushort> { 2 });
|
||||
Assert.NotEqual(a, b);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructor — pure data, no GL
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
[Fact]
|
||||
public void NewRenderer_NeedsPrepareIsTrue()
|
||||
{
|
||||
// GL and meshManager are null — only valid for pure-data tests (no
|
||||
// Initialize() is called, so no GL calls are made).
|
||||
var r = new EnvCellRenderer(gl: null!, meshManager: null!, frustum: new WbFrustum());
|
||||
Assert.True(r.NeedsPrepare);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NewRenderer_NotDisposed()
|
||||
{
|
||||
var r = new EnvCellRenderer(gl: null!, meshManager: null!, frustum: new WbFrustum());
|
||||
Assert.False(r.IsDisposed);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// RemoveLandblock — pure data path
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
[Fact]
|
||||
public void RemoveLandblock_NonExistent_DoesNotThrow()
|
||||
{
|
||||
var r = new EnvCellRenderer(gl: null!, meshManager: null!, frustum: new WbFrustum());
|
||||
// Should silently no-op.
|
||||
r.RemoveLandblock(0xA9B40000u);
|
||||
Assert.True(r.NeedsPrepare);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// GetEnvCellGeomId — additional edge cases
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
[Fact]
|
||||
public void GetEnvCellGeomId_EmptySurfaces_Deterministic()
|
||||
{
|
||||
var a = EnvCellRenderer.GetEnvCellGeomId(1, 0, new List<ushort>());
|
||||
var b = EnvCellRenderer.GetEnvCellGeomId(1, 0, new List<ushort>());
|
||||
Assert.Equal(a, b);
|
||||
Assert.NotEqual(0UL, a & 0x2_0000_0000UL);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEnvCellGeomId_SurfaceOrderMatters()
|
||||
{
|
||||
var a = EnvCellRenderer.GetEnvCellGeomId(1, 1, new List<ushort> { 10, 20 });
|
||||
var b = EnvCellRenderer.GetEnvCellGeomId(1, 1, new List<ushort> { 20, 10 });
|
||||
// The hash is order-sensitive (matches WB's foreach loop), so
|
||||
// swapped order should produce a different id.
|
||||
Assert.NotEqual(a, b);
|
||||
}
|
||||
|
||||
// (Render() requires a GL context — visual-verified in Task 10.)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue