166 lines
5.1 KiB
C#
166 lines
5.1 KiB
C#
using AcDream.App.Streaming;
|
|
|
|
namespace AcDream.App.Tests.Streaming;
|
|
|
|
public sealed class WorldRevealReadinessBarrierTests
|
|
{
|
|
private sealed class State
|
|
{
|
|
public bool RenderReady;
|
|
public bool SpawnCellReady;
|
|
public bool TerrainReady;
|
|
public bool CompositeReady;
|
|
public bool Unhydratable;
|
|
public int Invalidations;
|
|
public int Preparations;
|
|
public uint PreparedCell;
|
|
public int PreparedRadius = -1;
|
|
public int RenderRadius = -1;
|
|
public int TerrainRadius = -1;
|
|
|
|
public WorldRevealReadinessBarrier Build() => new(
|
|
isRenderNeighborhoodReady: (cell, radius) =>
|
|
{
|
|
RenderRadius = radius;
|
|
return RenderReady;
|
|
},
|
|
isSpawnCellReady: _ => SpawnCellReady,
|
|
isTerrainNeighborhoodReady: (cell, radius) =>
|
|
{
|
|
TerrainRadius = radius;
|
|
return TerrainReady;
|
|
},
|
|
areCompositeTexturesReady: () => CompositeReady,
|
|
prepareCompositeTextures: (cell, radius) =>
|
|
{
|
|
Preparations++;
|
|
PreparedCell = cell;
|
|
PreparedRadius = radius;
|
|
},
|
|
invalidateCompositeTextures: () => Invalidations++,
|
|
isSpawnClaimUnhydratable: _ => Unhydratable);
|
|
}
|
|
|
|
[Fact]
|
|
public void Begin_InvalidatesPriorDestinationTextureReadiness()
|
|
{
|
|
var state = new State();
|
|
var barrier = state.Build();
|
|
|
|
barrier.Begin();
|
|
|
|
Assert.Equal(1, state.Invalidations);
|
|
}
|
|
|
|
[Fact]
|
|
public void OutdoorReveal_JoinsNearRenderTexturesAndTerrain()
|
|
{
|
|
const uint outdoorCell = 0x11340021u;
|
|
var state = new State();
|
|
var barrier = state.Build();
|
|
|
|
Assert.False(barrier.IsReady(outdoorCell));
|
|
Assert.Equal(WorldRevealReadinessBarrier.OutdoorNeighborhoodRadius, state.RenderRadius);
|
|
|
|
state.RenderReady = true;
|
|
barrier.Prepare(outdoorCell);
|
|
Assert.Equal(1, state.Preparations);
|
|
Assert.Equal(outdoorCell, state.PreparedCell);
|
|
Assert.Equal(WorldRevealReadinessBarrier.OutdoorNeighborhoodRadius, state.PreparedRadius);
|
|
|
|
state.CompositeReady = true;
|
|
Assert.False(barrier.IsReady(outdoorCell));
|
|
|
|
state.TerrainReady = true;
|
|
Assert.True(barrier.IsReady(outdoorCell));
|
|
Assert.Equal(WorldRevealReadinessBarrier.OutdoorNeighborhoodRadius, state.TerrainRadius);
|
|
}
|
|
|
|
[Fact]
|
|
public void IndoorReveal_UsesCenterRenderAndExactEnvCellPhysics()
|
|
{
|
|
const uint indoorCell = 0x11340100u;
|
|
var state = new State
|
|
{
|
|
RenderReady = true,
|
|
CompositeReady = true,
|
|
TerrainReady = true,
|
|
};
|
|
var barrier = state.Build();
|
|
|
|
barrier.Prepare(indoorCell);
|
|
Assert.Equal(0, state.PreparedRadius);
|
|
Assert.False(barrier.IsReady(indoorCell));
|
|
Assert.Equal(-1, state.TerrainRadius);
|
|
|
|
state.SpawnCellReady = true;
|
|
Assert.True(barrier.IsReady(indoorCell));
|
|
Assert.Equal(0, state.RenderRadius);
|
|
}
|
|
|
|
[Fact]
|
|
public void Prepare_WaitsForStaticMeshPublication()
|
|
{
|
|
var state = new State();
|
|
var barrier = state.Build();
|
|
|
|
barrier.Prepare(0x11340021u);
|
|
|
|
Assert.Equal(0, state.Preparations);
|
|
}
|
|
|
|
[Fact]
|
|
public void ImpossibleClaim_CrossesExistingLoudRecoveryPath()
|
|
{
|
|
var state = new State { Unhydratable = true };
|
|
var barrier = state.Build();
|
|
|
|
barrier.Prepare(0x113401FFu);
|
|
|
|
Assert.True(barrier.IsReady(0x113401FFu));
|
|
Assert.Equal(0, state.Preparations);
|
|
Assert.Equal(-1, state.RenderRadius);
|
|
}
|
|
|
|
[Fact]
|
|
public void Evaluate_ExposesTheCanonicalOutdoorDecisionWithoutRepeatingDomains()
|
|
{
|
|
const uint outdoorCell = 0x11340021u;
|
|
var state = new State
|
|
{
|
|
RenderReady = true,
|
|
CompositeReady = true,
|
|
TerrainReady = true,
|
|
};
|
|
|
|
WorldRevealReadinessSnapshot snapshot = state.Build().Evaluate(outdoorCell);
|
|
|
|
Assert.Equal(outdoorCell, snapshot.DestinationCell);
|
|
Assert.False(snapshot.IsIndoor);
|
|
Assert.Equal(WorldRevealReadinessBarrier.OutdoorNeighborhoodRadius, snapshot.RequiredRenderRadius);
|
|
Assert.True(snapshot.IsRenderNeighborhoodReady);
|
|
Assert.True(snapshot.AreCompositeTexturesReady);
|
|
Assert.True(snapshot.IsCollisionReady);
|
|
Assert.True(snapshot.IsReady);
|
|
Assert.Equal(-1, state.PreparedRadius);
|
|
}
|
|
|
|
[Fact]
|
|
public void Evaluate_ShortCircuitsDownstreamDomainsUntilRenderPublication()
|
|
{
|
|
var state = new State
|
|
{
|
|
CompositeReady = true,
|
|
TerrainReady = true,
|
|
SpawnCellReady = true,
|
|
};
|
|
|
|
WorldRevealReadinessSnapshot snapshot = state.Build().Evaluate(0x11340100u);
|
|
|
|
Assert.False(snapshot.IsRenderNeighborhoodReady);
|
|
Assert.False(snapshot.AreCompositeTexturesReady);
|
|
Assert.False(snapshot.IsCollisionReady);
|
|
Assert.False(snapshot.IsReady);
|
|
Assert.Equal(-1, state.TerrainRadius);
|
|
}
|
|
}
|