Fix BroadcastFeed chyron freeze past 32 lines and isolate Smoke.cs crater rebake

This commit is contained in:
Meta Vens 2026-12-04 14:28:09 +01:00
commit 3bd66c3b64
4 changed files with 45 additions and 13 deletions

View file

@ -48,7 +48,7 @@ public partial class Hud : CanvasLayer
private VBoxContainer _chyronBox = null!;
private readonly Label[] _chyronLabels = new Label[3];
private BroadcastFeed? _lastBroadcastFeed;
private int _lastChyronCount = -1;
private long _lastChyronVersion = -1;
private PanelContainer _outcomeBanner = null!;
private Label _outcomeLabel = null!;
@ -472,13 +472,13 @@ public partial class Hud : CanvasLayer
private void SyncBroadcastChyron(BroadcastFeed broadcast)
{
var lines = broadcast.Lines;
if (ReferenceEquals(_lastBroadcastFeed, broadcast) && lines.Count == _lastChyronCount)
if (ReferenceEquals(_lastBroadcastFeed, broadcast) && broadcast.Version == _lastChyronVersion)
{
return;
}
_lastBroadcastFeed = broadcast;
_lastChyronCount = lines.Count;
_lastChyronVersion = broadcast.Version;
int start = Math.Max(0, lines.Count - _chyronLabels.Length);
int visibleCount = lines.Count - start;

View file

@ -90,17 +90,29 @@ public partial class Smoke : Node
Check(displacement > 3f, $"Expected player displacement > 3m after 60 frames, got {displacement:F2}m");
Check(!float.IsNaN(player.X) && !float.IsNaN(player.Y) && !float.IsNaN(player.Z), "Player position became NaN");
// Pause physics during the isolated crater check so AI contender track stamps in other tiles do not race it.
_main.SetScriptedInput(null);
_main.SetPhysicsProcess(false);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
bool isHeadless = DisplayServer.GetName() == "headless";
int rebakesBefore = _main.Terrain.DirtyRebakes;
float cpuBefore = _main.Session.State.Terrain.SampleHeight(-48f, -48f);
bool hasGpuBefore = _main.Terrain.TrySampleBakedHeight(-48f, -48f, out float gpuBefore);
if (hasGpuBefore)
float gpuBefore = 0f;
if (!isHeadless)
{
Check(MathF.Abs(gpuBefore - cpuBefore) <= 0.25f,
$"Expected baked GPU height ({gpuBefore:F2}m) to match CPU height ({cpuBefore:F2}m) before crater");
bool hasGpuBefore = _main.Terrain.TrySampleBakedHeight(-48f, -48f, out gpuBefore);
Check(hasGpuBefore, "Expected GPU HeightViewport readback to succeed before crater");
if (hasGpuBefore)
{
Check(MathF.Abs(gpuBefore - cpuBefore) <= 0.25f,
$"Expected baked GPU height ({gpuBefore:F2}m) to match CPU height ({cpuBefore:F2}m) before crater");
}
}
_main.Session.State.Terrain.StampCrater(-48f, -48f, radius: 5f, depth: 1.4f);
await ToSignal(GetTree(), SceneTree.SignalName.PhysicsFrame);
_main.Terrain.Sync(_main.Session.State.Terrain);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
float cpuAfter = _main.Session.State.Terrain.SampleHeight(-48f, -48f);
@ -109,18 +121,20 @@ public partial class Smoke : Node
Check(_main.Terrain.DirtyRebakes == rebakesBefore + 1,
$"Expected 1 dirty tile rebake from isolated crater stamp, got {_main.Terrain.DirtyRebakes - rebakesBefore}");
if (_main.Terrain.TrySampleBakedHeight(-48f, -48f, out float gpuAfter))
if (!isHeadless)
{
Check(MathF.Abs(gpuAfter - cpuAfter) <= 0.25f,
$"Expected baked GPU height ({gpuAfter:F2}m) to match CPU height ({cpuAfter:F2}m) after crater");
if (hasGpuBefore)
bool hasGpuAfter = _main.Terrain.TrySampleBakedHeight(-48f, -48f, out float gpuAfter);
Check(hasGpuAfter, "Expected GPU HeightViewport readback to succeed after crater");
if (hasGpuAfter)
{
Check(MathF.Abs(gpuAfter - cpuAfter) <= 0.25f,
$"Expected baked GPU height ({gpuAfter:F2}m) to match CPU height ({cpuAfter:F2}m) after crater");
Check(gpuAfter < gpuBefore - 0.8f,
$"Expected baked GPU height to drop after crater (before {gpuBefore:F2}m, after {gpuAfter:F2}m)");
}
}
_main.SetScriptedInput(null);
_main.SetPhysicsProcess(true);
}
private void Check(bool condition, string message)

View file

@ -23,6 +23,7 @@ namespace RustToDust.Core
public IReadOnlyList<BroadcastLine> Lines => _lines;
public BroadcastLine? Latest => _lines.Count > 0 ? _lines[_lines.Count - 1] : null;
public long Version { get; private set; }
public void Emit(float timestamp, BroadcastKind kind, string text)
{
@ -31,6 +32,7 @@ namespace RustToDust.Core
_lines.RemoveAt(0);
}
_lines.Add(new BroadcastLine(timestamp, kind, text));
Version++;
}
public void EmitMatchStart(float timestamp) =>

View file

@ -129,5 +129,21 @@ namespace RustToDust.Tests
Assert.Equal(SpectatorStance.Provoked, clearedSpec.Stance);
Assert.Equal(1, ring.CountProvokedFor(0));
}
[Fact]
public void BroadcastFeed_VersionAdvancesPastRingBufferCap()
{
var feed = new BroadcastFeed();
for (int i = 0; i < 40; i++)
{
long prev = feed.Version;
feed.Emit(i, BroadcastKind.TouristPull, $"line-{i}");
Assert.Equal(prev + 1, feed.Version);
}
Assert.Equal(32, feed.Lines.Count);
Assert.Equal(40, feed.Version);
Assert.Equal("line-39", feed.Latest?.Text);
}
}
}