From 3bd66c3b64e0f4e55511bc16bee8e10f11b030e4 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 4 Dec 2026 14:28:09 +0100 Subject: [PATCH] Fix BroadcastFeed chyron freeze past 32 lines and isolate Smoke.cs crater rebake --- client/Hud.cs | 6 ++-- client/tests/Smoke.cs | 34 ++++++++++++++------ src/RustToDust.Core/Broadcast.cs | 2 ++ tests/RustToDust.Tests/SpectatorRingTests.cs | 16 +++++++++ 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/client/Hud.cs b/client/Hud.cs index 6f409c6..c1f22ea 100644 --- a/client/Hud.cs +++ b/client/Hud.cs @@ -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; diff --git a/client/tests/Smoke.cs b/client/tests/Smoke.cs index 7b13ad1..8663e72 100644 --- a/client/tests/Smoke.cs +++ b/client/tests/Smoke.cs @@ -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) diff --git a/src/RustToDust.Core/Broadcast.cs b/src/RustToDust.Core/Broadcast.cs index 4fc6231..d2ada9d 100644 --- a/src/RustToDust.Core/Broadcast.cs +++ b/src/RustToDust.Core/Broadcast.cs @@ -23,6 +23,7 @@ namespace RustToDust.Core public IReadOnlyList 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) => diff --git a/tests/RustToDust.Tests/SpectatorRingTests.cs b/tests/RustToDust.Tests/SpectatorRingTests.cs index 47bf0e6..09ad321 100644 --- a/tests/RustToDust.Tests/SpectatorRingTests.cs +++ b/tests/RustToDust.Tests/SpectatorRingTests.cs @@ -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); + } } }