OfficeBody.Run is a plain while; SeatedBody hands out BodyLane, not the Ragdoll; Wound is refused on a dead or finished body and is whole or nothing; tests pin the slow clock, the will read-outs and the world after Finished

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-26 03:48:35 +01:00
commit 0f4b3a03a8
5 changed files with 155 additions and 12 deletions

View file

@ -34,6 +34,7 @@ public sealed class StressSession
private Outcome _outcome = Outcome.Endured;
private long _endTick;
private long _diedTick = -1;
private int _wounds;
/// <param name="poses">What the Brain's goals write, one rotation per muscle; the Actor's muscle count is theirs.</param>
/// <param name="physiology">The body's physiology, stepped by the Actor (null: a headless run, nothing can be wounded or die); it needs the <paramref name="body"/> it was built on and its <paramref name="physiologyPlan"/>.</param>
@ -119,26 +120,34 @@ public sealed class StressSession
/// <summary>
/// The player wounds a part with a tool from the current tick on: one Cut affliction of the tool's severity on each
/// of the tool's layers the part has (a layer the part lacks is skipped), through <see cref="Physiology.Afflict"/>,
/// the only way harm enters. False, and nothing wounded, for a headless session, a part the body lacks, a tool none
/// of whose layers the part has, or when the affliction table refused a slot.
/// the only way harm enters. All of the layers or none: false, and nothing wounded, for a headless session, a body
/// that is dead (death is permanent, bds-death) or a run that is <see cref="Finished"/>, a part the body lacks, a tool
/// none of whose layers the part has, or when the affliction table lacks room for every layer. The session counts its
/// own wounds against the table (it is the only one that wounds its physiology), so a healed wound still counts: the
/// refusal errs toward full.
/// </summary>
public bool Wound(int part, WoundTool tool)
{
if (_physiology is null || _physiologyPlan is null || _stackOf is null || (uint)part >= (uint)_stackOf.Length) return false;
if (Finished || _physiology.Dead) return false;
var stack = _physiologyPlan.Parts[_stackOf[part]].Tissues;
int applied = 0;
bool accepted = true;
var layers = new List<int>();
foreach (var label in tool.Layers)
{
for (int layer = 0; layer < stack.Count; layer++)
{
if (stack[layer].Label != label) continue;
accepted &= _physiology.Afflict(_cut, part, layer, tool.Severity);
applied++;
layers.Add(layer);
break;
}
}
return applied > 0 && accepted;
if (layers.Count == 0 || _wounds + layers.Count > _physiologyPlan.AfflictionSlots) return false;
foreach (int layer in layers)
{
if (!_physiology.Afflict(_cut, part, layer, tool.Severity)) throw new InvalidOperationException("the physiology's affliction table is full of wounds this session did not make.");
_wounds++;
}
return true;
}
/// <summary>

View file

@ -57,13 +57,12 @@ public static class OfficeBody
var handL = new List<BodyPoint>();
var handR = new List<BodyPoint>();
var pelvis = new List<BodyPoint>();
for (;;)
while (!session.Finished)
{
session.Step();
handL.Add(session.HandL);
handR.Add(session.HandR);
pelvis.Add(session.Pelvis);
if (session.Finished) break; // a fresh session is never finished: the first step is a tick
}
return new OfficeBodyResult(session.Result(), handL, handR, pelvis);
}

View file

@ -41,7 +41,7 @@ public sealed class OfficeBodySession : IDisposable
int head = plan.SenseIndex("Head");
_handL = plan.SenseIndex("Hand", Side.Left);
_handR = plan.SenseIndex("Hand", Side.Right);
_pelvisLane = _body.Ragdoll.BodyLane(plan.PartIndex("Pelvis"));
_pelvisLane = _body.BodyLane(plan.PartIndex("Pelvis"));
var physiologyPlan = PhysiologyPlans.Humanoid();
_physiology = new Physiology(plan, physiologyPlan, p.SlowScale);
// The desk's emitters sit where the head does and are sensed there.

View file

@ -50,8 +50,12 @@ public sealed class SeatedBody : IDisposable
public BodyPlan Plan => _ragdoll.Plan;
/// <summary>The ragdoll, for reading the lane of a part (<see cref="Ragdoll.BodyLane"/>); the world is stepped only through <see cref="DriveAndStep"/>.</summary>
public Ragdoll Ragdoll { get { Live(); return _ragdoll; } }
/// <summary>The lane of a part's body in <see cref="View"/>. The ragdoll itself is not handed out: it is driven only through <see cref="DriveAndStep"/>.</summary>
public int BodyLane(int part)
{
Live();
return _ragdoll.BodyLane(part);
}
/// <summary>The live lanes of the world, for rendering. Read-only: nothing outside this body writes them.</summary>
public Box3DSoaView View { get { Live(); return _world.View; } }

View file

@ -1185,6 +1185,137 @@ public static class Program
Check(physiology.Integrity(palm, physiology.TissueIndex(palm, "Metacarpals")) == 1.0, "the palm's metacarpals were hurt");
}),
("office slow clock: SlowScale reaches the physiology, so a skin wound's bleed ends (it heals on the acute clock) and the blood regrows sooner the larger the scale: 1 > 20 > 1000 ticks to recover", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
var arm = SeatedPuppet.Plan.PartIndex("LowerArm", Lodur.Side.Left);
long Recovered(double scale)
{
using var s = new OfficeBodySession(p with { SlowScale = scale }, 1);
Check(s.Wound(arm, new WoundTool(new[] { "Skin" }, 0.006)), "the skin wound was refused");
bool bled = false;
while (!s.Finished)
{
s.Step();
bled |= s.BloodLoss > 0.0;
if (bled && s.BloodLoss == 0.0) return s.TickIndex;
}
throw new InvalidOperationException($"scale {scale}: the blood never regrew (bled: {bled})");
}
long slow = Recovered(1.0), normal = Recovered(20.0), fast = Recovered(1000.0);
Check(slow - normal > 100 && normal > fast, $"recovered at tick {slow} (scale 1), {normal} (20), {fast} (1000)");
}),
("office read-outs: Will is Lodur's will (the resolve while unwounded, the lesser of resolve and consciousness wounded), Arousal, Resolve and Goal are the rows' at the same tick, AirHunger is 0 unwounded and rises with both lungs cut", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds, SampleEverySeconds = 1.0 };
using (var s = new OfficeBodySession(p, 1))
{
var arousal = new List<double>(); var resolve = new List<double>(); var goal = new List<OfficeGoal>();
double firstWill = -1, minWill = 1;
while (!s.Finished)
{
s.Step();
if (firstWill < 0) firstWill = s.Will;
minWill = Math.Min(minWill, s.Will);
Check(s.Will == s.Resolve && s.AirHunger == 0.0, $"tick {s.TickIndex}: will {s.Will}, resolve {s.Resolve}, air hunger {s.AirHunger}");
arousal.Add(s.Arousal); resolve.Add(s.Resolve); goal.Add(s.Goal);
}
Check(firstWill == 1.0 && minWill == 0.0, $"will began at {firstWill} and fell to {minWill}");
foreach (var e in s.Result().Timeline)
{
int i = (int)Math.Round(e.TimeMs * OfficeBody.Hz / 1000.0);
Check(e.Arousal == arousal[i] && e.Resolve == resolve[i] && e.Goal == goal[i], $"{e.Kind} row at {e.TimeMs} ms: arousal {e.Arousal}, resolve {e.Resolve}, goal {e.Goal}; read-outs {arousal[i]}, {resolve[i]}, {goal[i]}");
}
Check(goal.Distinct().Count() == 3 && arousal.Max() > 0.3, "the run did not go through all three goals, or arousal never rose");
}
using (var s = new OfficeBodySession(p, 1))
{
Check(s.Wound(SeatedPuppet.Plan.PartIndex("Torso", Lodur.Side.Center), new WoundTool(new[] { "LungLeft", "LungRight" }, 15.0)), "the lungs were refused");
double maxHunger = 0.0;
while (!s.Finished)
{
s.Step();
maxHunger = Math.Max(maxHunger, s.AirHunger);
Check(s.Will == Math.Min(s.Resolve, s.Consciousness), $"tick {s.TickIndex}: will {s.Will}, resolve {s.Resolve}, consciousness {s.Consciousness}");
}
Check(maxHunger > 0.5, $"air hunger peaked at {maxHunger}");
}
}),
("office after Finished: Step ticks nothing (the tick index, the result and the event queue stay) and the world still steps (the hands and pelvis keep moving)", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
using var s = new OfficeBodySession(p, 1);
while (!s.Finished) s.Step();
var buffer = new BodyEvent[64];
while (s.DrainEvents(buffer) > 0) { }
long tick = s.TickIndex;
string result = s.Result().Render();
double will = s.Will;
var before = (s.HandL, s.HandR, s.Pelvis);
for (int i = 0; i < 60; i++) s.Step();
Check(s.TickIndex == tick && s.Result().Render() == result && s.Will == will && s.DrainEvents(buffer) == 0, "a step after Finished ticked the session");
Check(s.HandL != before.HandL && s.HandR != before.HandR && s.Pelvis != before.Pelvis, "the world stopped stepping after Finished");
}),
("office wound is refused once the body is dead or the run is finished, and a refused wound is whole or nothing: a tool the table lacks room for in full wounds no layer", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
var plan = SeatedPuppet.Plan;
var arm = plan.PartIndex("LowerArm", Lodur.Side.Left);
var leg = plan.PartIndex("Shin", Lodur.Side.Left);
using (var s = new OfficeBodySession(p, 1))
{
Check(s.Wound(arm, WoundTool.Knife), "the knife was refused");
while (!s.Dead) s.Step();
Check(!s.Finished, "the run finished at the death");
Check(!s.Wound(leg, WoundTool.Knife), "a dead body was wounded");
while (!s.Finished) s.Step();
Check(!s.Wound(leg, WoundTool.Knife), "a finished run was wounded");
}
using (var s = new OfficeBodySession(p, 1))
{
while (!s.Finished) s.Step();
Check(!s.Dead && !s.Wound(leg, WoundTool.Knife), "a finished, living run was wounded");
}
var physiologyPlan = Lodur.PhysiologyPlans.Humanoid();
var physiology = new Lodur.Physiology(plan, physiologyPlan, p.SlowScale);
var session = new StressSession(p, 1, plan.SensePoints.Count, OfficeBody.Poses, plan.SenseIndex("Head"), physiology, plan, physiologyPlan);
var skin = new WoundTool(new[] { "Skin" }, 1.0);
int knives = physiologyPlan.AfflictionSlots / 3;
for (int i = 0; i < knives; i++) Check(session.Wound(arm, WoundTool.Knife), $"knife {i} was refused with room left");
int free = physiologyPlan.AfflictionSlots - 3 * knives;
Check(free > 0 && free < 3, $"the table has {free} slots free; the test needs one or two");
Check(!session.Wound(arm, WoundTool.Knife), "a knife that does not fit was accepted");
for (int i = 0; i < free; i++) Check(session.Wound(arm, skin), $"the refused knife took a slot: skin wound {i} was refused");
Check(!session.Wound(arm, skin), "the table took more wounds than it has slots");
var foreign = new Lodur.Physiology(plan, physiologyPlan, p.SlowScale);
var shared = new StressSession(p, 1, plan.SensePoints.Count, OfficeBody.Poses, plan.SenseIndex("Head"), foreign, plan, physiologyPlan);
for (int i = 0; i < physiologyPlan.AfflictionSlots; i++) Check(foreign.Afflict(physiologyPlan.AfflictionIndex("Cut"), arm, 0, 1.0), "the table filled early");
bool threw = false;
try { shared.Wound(arm, skin); } catch (InvalidOperationException) { threw = true; }
Check(threw, "a wound the table refused behind the session's count was reported as accepted or refused quietly");
}),
("SeatedBody hands out no ragdoll: nothing public returns or takes a Ragdoll, so DriveAndStep is the one driver", () =>
{
var members = typeof(SeatedBody).GetMembers().Where(m => m.DeclaringType == typeof(SeatedBody)).ToArray();
Check(members.Length > 0, "no members found");
foreach (var m in members)
{
var types = m switch
{
System.Reflection.PropertyInfo pi => new[] { pi.PropertyType },
System.Reflection.MethodBase mb => mb.GetParameters().Select(x => x.ParameterType).Concat(m is System.Reflection.MethodInfo mi ? new[] { mi.ReturnType } : Array.Empty<Type>()).ToArray(),
_ => Array.Empty<Type>(),
};
Check(!types.Contains(typeof(Lodur.Body.Ymir.Ragdoll)), $"SeatedBody.{m.Name} exposes the Ragdoll");
}
}),
("unwounded office keeps its will: with no wound the body never dies, DeathCause is None and consciousness is 1 at the end, seeds 1-3", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };