diff --git a/README.md b/README.md
index aa9ece2..dda6754 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/src/BadDay.Core/PainBoxSession.cs b/src/BadDay.Core/PainBoxSession.cs
index f0189a0..027e9a7 100644
--- a/src/BadDay.Core/PainBoxSession.cs
+++ b/src/BadDay.Core/PainBoxSession.cs
@@ -62,6 +62,13 @@ public sealed class PainBoxSession
/// True from the tick the Brain's withdraw goal takes over, its deliberate latency after the will breaks.
public bool Withdrew { get; private set; }
+ ///
+ /// Whether the box is on: until it is switched off (by 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.
+ ///
+ public bool BoxOn => TickIndex < _box.DisableTick;
+
/// Sets the box intensity the ramp scales; it takes effect on the next . owns the range and refuses a level outside it.
public void SetIntensity(double level) => _box.Level = level;
diff --git a/src/BadDay.Ymir/BodyPainBox.cs b/src/BadDay.Ymir/BodyPainBox.cs
index a249ebd..7e04122 100644
--- a/src/BadDay.Ymir/BodyPainBox.cs
+++ b/src/BadDay.Ymir/BodyPainBox.cs
@@ -155,8 +155,11 @@ public sealed class BodyPainBoxSession : IDisposable
/// Ticks run so far; the tick the next runs.
public long TickIndex { get { Live(); return _session.TickIndex; } }
- /// The box's intensity as written on the latest tick.
- public double BoxIntensity { get { Live(); return _session.Box.Intensity; } }
+ /// Whether the box is on: until a switch-off (, the disable time), which counts from the call even after the run has ended.
+ public bool BoxOn { get { Live(); return _session.BoxOn; } }
+
+ /// The box's intensity as written on the latest tick, and 0 once the box is off: what a player sees the box doing.
+ public double BoxIntensity { get { Live(); return _session.BoxOn ? _session.Box.Intensity : 0.0; } }
/// The stimulus volume the hand is held in (a copy), for drawing the chamber.
public BoxStimulus Chamber { get { Live(); return _session.Box; } }
diff --git a/tests/BadDay.Tests/Program.cs b/tests/BadDay.Tests/Program.cs
index 355f08c..0cd5bb0 100644
--- a/tests/BadDay.Tests/Program.cs
+++ b/tests/BadDay.Tests/Program.cs
@@ -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)
{