BodyPainBoxSession owns whether the box is on; BoxIntensity reads 0 once it is off

BoxOn is on until a SwitchOff or the disable time, counted from the call even
after the run has ended, so a run that ended on the will breaking still takes
the switch. BoxIntensity is the written intensity while on and 0 off.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-20 03:28:03 +01:00
commit 3c5b214f4a
4 changed files with 38 additions and 4 deletions

View file

@ -56,7 +56,7 @@ withdrawal events) and a one-line summary. Options: `--intensity`, `--pay` (what
steps; the native Ymir library builds with cmake and a C compiler on first
build) and adds a line with the time the hand left the box. The body run is also a stepping
session, `BodyPainBoxSession` (create, `Step`, read `Hand` and the world's lanes, `SetIntensity`,
`SwitchOff`, `DrainEvents`, dispose), that the Godot client drives and `run --body` steps to the end; `BadDay.Core` and
`SwitchOff`, `BoxOn`, `DrainEvents`, dispose), that the Godot client drives and `run --body` steps to the end; `BadDay.Core` and
`BadDay.Ymir` target net8.0 for Godot, the executables and tests net10.0. Events queue per tick until drained, so a frame spanning several steps loses none. Stepping past the end keeps the body moving; that free motion is float arithmetic on the platform's math and is not bit-identical across operating systems (the run itself is).
### Godot client

View file

@ -62,6 +62,13 @@ public sealed class PainBoxSession
/// <summary>True from the tick the Brain's withdraw goal takes over, its deliberate latency after the will breaks.</summary>
public bool Withdrew { get; private set; }
/// <summary>
/// Whether the box is on: until it is switched off (by <see cref="SwitchOff"/> or the parameters' disable time), from the
/// tick that switch names. It is the box's state, not the run's: a run that ended on the will breaking still has a box
/// the player can switch off.
/// </summary>
public bool BoxOn => TickIndex < _box.DisableTick;
/// <summary>Sets the box intensity the ramp scales; it takes effect on the next <see cref="Tick"/>. <see cref="PainBox.Level"/> owns the range and refuses a level outside it.</summary>
public void SetIntensity(double level) => _box.Level = level;

View file

@ -155,8 +155,11 @@ public sealed class BodyPainBoxSession : IDisposable
/// <summary>Ticks run so far; the tick the next <see cref="Step"/> runs.</summary>
public long TickIndex { get { Live(); return _session.TickIndex; } }
/// <summary>The box's intensity as written on the latest tick.</summary>
public double BoxIntensity { get { Live(); return _session.Box.Intensity; } }
/// <summary>Whether the box is on: until a switch-off (<see cref="SwitchOff"/>, the disable time), which counts from the call even after the run has ended.</summary>
public bool BoxOn { get { Live(); return _session.BoxOn; } }
/// <summary>The box's intensity as written on the latest tick, and 0 once the box is off: what a player sees the box doing.</summary>
public double BoxIntensity { get { Live(); return _session.BoxOn ? _session.Box.Intensity : 0.0; } }
/// <summary>The stimulus volume the hand is held in (a copy), for drawing the chamber.</summary>
public BoxStimulus Chamber { get { Live(); return _session.Box; } }

View file

@ -295,6 +295,30 @@ public static class Program
Check(control.BoxIntensity > 0.3 && live.BoxIntensity == 0.0, $"next tick: control {control.BoxIntensity}, live {live.BoxIntensity}");
}),
("body: the session owns whether the box is on: on until switched off or its disable time, off at once for the reader after a SwitchOff even when the run is over, and a run ended by the will breaking still takes the switch", () =>
{
using var live = new BodyPainBoxSession(OnBody, 1);
for (int i = 0; i < 4 * Hz; i++) live.Step();
Check(live.BoxOn && live.BoxIntensity > 0.3, $"on {live.BoxOn}, intensity {live.BoxIntensity}");
live.SwitchOff();
Check(!live.BoxOn && live.BoxIntensity == 0.0, "a switched-off box still reads on");
live.Step();
Check(live.Finished && live.Result().Outcome == Outcome.BoxDisabled && !live.BoxOn && live.BoxIntensity == 0.0, "a box that ended the run is not off");
using var scheduled = new BodyPainBoxSession(OnBody with { BoxDisableAtSeconds = 5.0 }, 1);
for (int i = 0; i < 5 * Hz - 1; i++) scheduled.Step();
Check(scheduled.BoxOn, "the box was off before its disable tick");
scheduled.Step();
Check(!scheduled.BoxOn, "the box was still on once the next tick is its disable tick");
using var broke = new BodyPainBoxSession(OnBody, 1);
while (!broke.Finished) broke.Step();
string render = broke.Result().Render();
Check(broke.Result().Outcome == Outcome.WillBroke && broke.BoxOn && broke.BoxIntensity > 0.3, "a run ended by the will breaking should leave the box on");
broke.SwitchOff();
Check(!broke.BoxOn && broke.BoxIntensity == 0.0 && broke.Result().Render() == render && broke.Result().Outcome == Outcome.WillBroke, "switching off after the run changed the box, or the result");
}),
("body: stepping past Finished keeps the world moving, the arm driven and the result frozen", () =>
{
using var s = new BodyPainBoxSession(OnBody, 1);
@ -440,7 +464,7 @@ public static class Program
("SwitchOff", () => s.SwitchOff()), ("DrainEvents", () => s.DrainEvents(new BodyEvent[4])), ("View", () => _ = s.View),
("Finished", () => _ = s.Finished), ("TickIndex", () => _ = s.TickIndex), ("Excursions", () => _ = s.Excursions),
("HandOutMs", () => _ = s.HandOutMs), ("BoxIntensity", () => _ = s.BoxIntensity), ("Pain", () => _ = s.Pain),
("Chamber", () => _ = s.Chamber), ("Strain", () => _ = s.Strain), ("Resolve", () => _ = s.Resolve), ("Goal", () => _ = s.Goal),
("Chamber", () => _ = s.Chamber), ("BoxOn", () => _ = s.BoxOn), ("Strain", () => _ = s.Strain), ("Resolve", () => _ = s.Resolve), ("Goal", () => _ = s.Goal),
};
foreach (var (name, call) in members)
{