From c324570dbdacac547820b30210f87fd731e5825d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 27 Nov 2026 23:12:45 +0100 Subject: [PATCH] Actor.Tick steps a dead physiology so its flows read zero; allocation tests run with TieredPGO off; Nose comment A dead physiology's Step zeroes Bleed, AirwayBleed, Coughed, Drained, DrawnLive and DrawnPooled, but the Actor skipped it, so the flows stood at the dying step's values for every tick after. The Actor now steps it; the drive is still written only on ticks the physiology was alive at entry. Folds vessel-sites-s2-lows: the Core tests run with TieredPGO off (the instrumented tier allocates when the background tier-up lands), and the Nose pin comment reads 20.8 degrees plus 1.11 per mm. Co-Authored-By: Claude Sonnet 5.5 --- src/Lodur.Core/Actor.cs | 6 +++-- .../Lodur.Core.Tests/ActorPhysiologyTests.cs | 23 +++++++++++++++++++ .../Lodur.Core.Tests/Lodur.Core.Tests.csproj | 2 ++ tests/Lodur.Tests/AirwayTests.cs | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Lodur.Core/Actor.cs b/src/Lodur.Core/Actor.cs index 1863f07..feb8807 100644 --- a/src/Lodur.Core/Actor.cs +++ b/src/Lodur.Core/Actor.cs @@ -299,9 +299,11 @@ namespace Lodur } // The physiology steps first, on the drive as the last tick left it, and its consciousness is the slot's only writer. - if (!_physiology.Dead) + // A dead physiology is stepped too: that step zeroes its flows, so they stand only on the tick it died. + var wasDead = _physiology.Dead; + _physiology.Step(_dt, new PhysiologyInput(_drive.Arousal, _effort, _held, airway)); + if (!wasDead) { - _physiology.Step(_dt, new PhysiologyInput(_drive.Arousal, _effort, _held, airway)); _drive.Consciousness = _physiology.Consciousness; _drive.AirHunger = _physiology.BreathUrge; } diff --git a/tests/Lodur.Core.Tests/ActorPhysiologyTests.cs b/tests/Lodur.Core.Tests/ActorPhysiologyTests.cs index 8ac55e1..442286c 100644 --- a/tests/Lodur.Core.Tests/ActorPhysiologyTests.cs +++ b/tests/Lodur.Core.Tests/ActorPhysiologyTests.cs @@ -112,6 +112,29 @@ public sealed class ActorPhysiologyTests Assert.Equal(0.0, frozen.Will); } + [Fact] + public void A_dead_physiologys_flows_stand_on_the_tick_it_died_and_read_zero_after() + { + var p = new Physiology(Body3(), Plan3(blood: new BloodDef(1000.0, 0.5, 1e-4), slots: 9, organism: new[] { Hypoxia }), 20); + Assert.True(p.Afflict(Af("Bleeder"), 1, 0, 0.8)); + var a = Make(p); + var s = new float[2]; + var q = new Quat[2]; + for (var i = 0; i < 10; i++) Assert.Equal(TickEvents.None, Tick(a, 0.0, s, q) & TickEvents.Died); + Assert.True(p.Bleed(1) > 0.0); + Assert.True(p.Afflict(Af("Lesion"), 0, BrainLayer, 10)); // not the heart: a stopped heart would stop the bleed on the dying step + Assert.Equal(TickEvents.Died, Tick(a, 0.0, s, q)); + Assert.True(p.Dead); + Assert.True(p.Bleed(1) > 0.0, "the dying step's bleed was not reported"); // Lodur reports the step it died on + Assert.Equal(TickEvents.None, Tick(a, 0.0, s, q)); + Assert.Equal(0.0, p.Bleed(1)); + Assert.Equal(0.0, p.AirwayBleed); + Assert.Equal(0.0, p.DrawnLive); + Assert.Equal(0.0, p.DrawnPooled); + Assert.Equal(0.0, p.Coughed); + Assert.Equal(0.0, p.Drained); + } + [Fact] public void A_physiology_that_died_before_it_was_bound_reports_the_death_on_the_first_tick() { diff --git a/tests/Lodur.Core.Tests/Lodur.Core.Tests.csproj b/tests/Lodur.Core.Tests/Lodur.Core.Tests.csproj index 617d2d1..05426b1 100644 --- a/tests/Lodur.Core.Tests/Lodur.Core.Tests.csproj +++ b/tests/Lodur.Core.Tests/Lodur.Core.Tests.csproj @@ -5,6 +5,8 @@ net10.0 enable false + + false diff --git a/tests/Lodur.Tests/AirwayTests.cs b/tests/Lodur.Tests/AirwayTests.cs index 129d9e8..45cba22 100644 --- a/tests/Lodur.Tests/AirwayTests.cs +++ b/tests/Lodur.Tests/AirwayTests.cs @@ -421,7 +421,7 @@ public sealed class AirwayTests var flipDown = Sweep(down, 40f, -40f, -0.05f, Nose); // The hold is the margin itself (ruling deterministic-bound-margin, readings at 0.05 degree steps): margin 5 mm (shipped) holds Mouth to +10.40 and Nose to -26.35 degrees; 1 mm holds +5.95 and -21.90, 10 mm holds +15.99 and -31.95. // Mouth bound (7.87, 12.9) = sqrt(10.40 x 5.95) and sqrt(10.40 x 15.99), separation 1.75 and 1.54; Nose bound (-29.0, -24.0) = sqrt(26.35 x 31.95) and sqrt(26.35 x 21.90), separation 1.21 and 1.20. - // Why the Nose separation is 1.20: the Nose reading is 20.4 degrees plus 1.12 per mm of margin, so no margin pair a 5 mm shipped value is held against separates it by more; the Mouth bound (1.75, 1.54) is the pin, and this one claims the same mutants + // Why the Nose separation is 1.20: the Nose reading is 20.8 degrees plus 1.11 per mm of margin, so no margin pair a 5 mm shipped value is held against separates it by more; the Mouth bound (1.75, 1.54) is the pin, and this one claims the same mutants // (a margin of 2.5 mm or less, 8 mm or more; 3 to 7 mm pass both) on a second axis, 0.05 degree steps, identical on a MinGW and an MSVC native build. Assert.True(flipUp > 7.87f && flipUp < 12.9f, $"held Mouth to {flipUp} degrees"); Assert.True(flipDown < -24.0f && flipDown > -29.0f, $"held Nose to {flipDown} degrees");