OfficeBodySession steps the office with Lodur Physiology; Wound command; death ends the run limp; OfficeBody.Run is a recorder
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a30c0a04ff
commit
9d21d81156
9 changed files with 356 additions and 46 deletions
12
README.md
12
README.md
|
|
@ -36,7 +36,7 @@ recorder. It needs sibling checkouts of Lodur and Ymir (`LODUR_ROOT`, else
|
|||
- `src/BadDay.Core/PainBoxParameters.cs`: the box and clock tunables, plus Lodur's parameter records as members.
|
||||
- `src/BadDay.Core/Sweep.cs`: consecutive seeds, break-time min/median/max.
|
||||
- `src/BadDay.Ymir/BodyPainBox.cs`: the same run on the Ymir ragdoll, with the hand-out time.
|
||||
- `src/BadDay.Ymir/SeatedPuppet.cs`: the stool, ground and ragdoll every body run is built on.
|
||||
- `src/BadDay.Ymir/SeatedPuppet.cs`: the stool, ground and ragdoll every body is built from (`SeatedBody` holds the world).
|
||||
- `src/BadDay.Cli`: `baddaysim`.
|
||||
- `tests/BadDay.Tests`: determinism, break-time, monotonicity and body tests.
|
||||
- `tools/PainSweep`: the intensity x suppression table.
|
||||
|
|
@ -123,6 +123,9 @@ The scenarios, one owner per decision:
|
|||
| `ChamberBrain`, `OfficeBrain` | `PainBoxParameters` or `StressParameters`, the poses | a Lodur `Brain`: goals and their rules as data, and the release goal's id (`withdraw`, `calm`) | none; Lodur's Actor commits each switch | a session choosing a goal; a goal rule outside the Brain |
|
||||
| `PainBoxSession`, `StressSession` | seed, traits, the box or the cause, the player's commands (`Silence`, box off) | the box's or the emitters' intensities each tick; rows read back from the Actor (the stress column is the drive's arousal, the goal column the Actor's goal); the end of the run | the release goal, found by id at construction (an unknown id refuses the build) | computing load, arousal, resolve or a goal; a goal index hard-coded for the release |
|
||||
| Lodur (`Actor`, the drive, the Brain) | the sessions' stimuli, the body's region points | muscle strengths and targets; the events | resolve, strain, pain, arousal, the breaks, the sensory gain in force | BDS writing any of it |
|
||||
| Lodur's `Physiology` | `Afflict` calls (only from `StressSession.Wound`) and the Actor's step input | blood loss, consciousness, air hunger, death and its cause (`Died` once; a dead body is limp) | tissue integrity, bleed, the motor ceiling | a session or client deciding death, bleed or consciousness; any `Afflict` outside `StressSession.Wound` |
|
||||
| `SeatedBody` | the scenario's strengths and targets each tick | the world's view, the sense points, the `BodyEvent` queue | the ragdoll and its world, built through `SeatedPuppet.Build` | any `Box3DSoaWorld` or world step in BDS outside it |
|
||||
| `BodyPainBoxSession`, `OfficeBodySession` | their scenario's commands (`SetIntensity`, `SwitchOff`; `Silence`, `Wound`) | one `SeatedBody` stepped per `Step`; the chamber's hand and result, the office's read-outs (will, arousal, resolve, consciousness, blood loss, air hunger, death) | none: neither owns a world | creating or stepping a world; deciding death |
|
||||
|
||||
Found stale by Modeling, 2026-11-20, not changed: `docs/scenarios/fella-bad-day-at-the-office.md` is a design document (Status: design, not built) whose ladder rows 3 and 4 are now built; its text outside the ladder is not a map of the code.
|
||||
|
||||
|
|
@ -206,6 +209,8 @@ The chamber's release is declared the same way (`PainBoxParameters.ReleaseGoalId
|
|||
apart from the setting and the cause. Each scenario builds its own Brain from its own parameters; one entry point keyed by character id
|
||||
waits for Brains as content. Headless the rage moves nothing; `office --body` runs it on the puppet.
|
||||
|
||||
On the puppet the office is `OfficeBodySession`, stepped by its caller one 1/120 s step at a time like the chamber's session (`OfficeBody.Run` records one to its end). It builds a `SeatedBody`, the one owner of every BDS body world, and attaches a Lodur `Physiology` to the Actor (`StressParameters.SlowScale`, default 20 [P]: ruling `lodur:ruling:bds-physiology-clock`; Acute afflictions such as a cut do not move with it). The player's harm is `Wound(part, tool)`: a `WoundTool` names tissue layers and a severity, and `StressSession.Wound` binds one Cut affliction on each layer the part has (a palm has no fat), the only path harm takes into the body. The knife (`WoundTool.Knife`, skin, fat and muscle at 60 [P]) is the click-cut's content until contacts become afflictions. Lodur decides the rest: blood loss, consciousness, air hunger and death (`lodur:ruling:bds-death`). A cut on the left lower arm bleeds the body out in about 40 s; the Actor reports `Died` once, the body goes limp (it writes no strength from then on), the session logs a `Died` row, ends the run `ReleaseSeconds` later with `Outcome.Died`, and `StressResult` carries `DiedAtMs` and `DeathCause`. An unwounded run is unchanged: nothing in it can die.
|
||||
|
||||
The stress bar is his arousal, how wound up he is right now, and reads **stress (arousal)** (`StressResult.StressBarLabel`; ruling `lodur:ruling:stress-bar-shows-arousal-calm-silences`).
|
||||
It rises with each stressor and falls in quiet; will is not on it. Entering calm fades his arousal and his senses' gain to nothing over `CalmFadeSeconds` (3 s, the aftershock tail of
|
||||
`lodur:ruling:flinch-tail-after-stimulus`; the calm goal's `EntryArousal`, `SensoryGain` and `EntrySeconds`), so the bar drains and stays empty for the rest of the run while the stressor columns
|
||||
|
|
@ -214,7 +219,10 @@ keep sounding. Arousal is exactly 0 from `CalmFadeSeconds` on; the load column t
|
|||
- `src/BadDay.Core/Setting.cs`, `Cause.cs`: the office's defaults, in code, not persisted yet.
|
||||
- `src/BadDay.Core/StressSession.cs`: one run, driven per tick by the headless run, the sweep, the CLI and a client.
|
||||
- `src/BadDay.Core/OfficeBrain.cs`: Office Fella's goals, and the poses they write.
|
||||
- `src/BadDay.Ymir/OfficeBody.cs`: the office on the seated puppet: both hands, the pelvis and the strikes.
|
||||
- `src/BadDay.Ymir/OfficeBody.cs`: the office on the seated puppet, recorded to its end: both hands, the pelvis and the strikes.
|
||||
- `src/BadDay.Ymir/OfficeBodySession.cs`: the office's stepping session on a `SeatedBody` with a Lodur `Physiology`; `Wound`, the read-outs, death.
|
||||
- `src/BadDay.Ymir/SeatedBody.cs`: the one owner of a BDS body world and its step order.
|
||||
- `src/BadDay.Core/WoundTool.cs`: what a wound is made of; `Knife`.
|
||||
- `src/BadDay.Core/StressSimulation.cs`: the headless run with scheduled silences, and the seed sweep.
|
||||
|
||||
```
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ public enum Outcome
|
|||
BoxDisabled,
|
||||
/// <summary>MaxSeconds passed with the box on and the will intact.</summary>
|
||||
Endured,
|
||||
/// <summary>A body with a physiology died (an office run; the chamber never produces it).</summary>
|
||||
Died,
|
||||
}
|
||||
|
||||
public enum EntryKind { Sample, Flinch, WillBroke, Withdrew, BoxDisabled, Endured }
|
||||
|
|
|
|||
|
|
@ -41,4 +41,7 @@ public sealed record StressParameters
|
|||
|
||||
/// <summary>Per-seed trait spread (fraction): the senses' gain and resolve drain.</summary>
|
||||
public double TraitJitter { get; init; } = 0.2;
|
||||
|
||||
/// <summary>The per-session multiplier on slow body processes [P] (ruling lodur:ruling:bds-physiology-clock): a Slow affliction or regen runs this many times faster than its table rate; Acute ones do not move.</summary>
|
||||
public double SlowScale { get; init; } = 20.0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Lodur;
|
||||
|
||||
namespace BadDay.Core;
|
||||
|
||||
public enum StressEntryKind { Sample, Silenced, WillBroke, GoalChanged, Endured }
|
||||
public enum StressEntryKind { Sample, Silenced, WillBroke, GoalChanged, Died, Endured }
|
||||
|
||||
/// <summary>One timeline row: end-of-tick state read from the Actor. Audio, Visual and Interrupt are the stimulus that reached the head on each channel.</summary>
|
||||
public readonly record struct StressEntry(
|
||||
|
|
@ -16,7 +17,7 @@ public readonly record struct SilenceCommand(string StressorId, double AtSeconds
|
|||
|
||||
public sealed record StressResult(
|
||||
ulong Seed,
|
||||
/// <summary>WillBroke (the run goes on through the release) or Endured; the office has no box to disable.</summary>
|
||||
/// <summary>WillBroke (the run goes on through the release), Endured, or Died (a body with a physiology died); the office has no box to disable.</summary>
|
||||
Outcome Outcome,
|
||||
/// <summary>When the run ended: the release after calm took over, or MaxSeconds.</summary>
|
||||
long EndMs,
|
||||
|
|
@ -24,7 +25,11 @@ public sealed record StressResult(
|
|||
long? TimeToBreakMs,
|
||||
/// <summary>The lowest resolve at any tick of the run.</summary>
|
||||
double MinResolve,
|
||||
IReadOnlyList<StressEntry> Timeline)
|
||||
IReadOnlyList<StressEntry> Timeline,
|
||||
/// <summary>When the body died, ms (Lodur's Physiology decided it); null if it did not.</summary>
|
||||
long? DiedAtMs = null,
|
||||
/// <summary>What killed it; None unless <see cref="DiedAtMs"/> is set.</summary>
|
||||
DeathCause DeathCause = DeathCause.None)
|
||||
{
|
||||
/// <summary>What the stress bar means (ruling lodur:ruling:stress-bar-shows-arousal-calm-silences): how wound up he is right now, his arousal. Will is not on this bar.</summary>
|
||||
public const string StressBarLabel = "stress (arousal)";
|
||||
|
|
@ -46,7 +51,9 @@ public sealed record StressResult(
|
|||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string Summary() => Outcome == Outcome.WillBroke
|
||||
public string Summary() => Outcome == Outcome.Died
|
||||
? $"seed {Seed}: died of {DeathCause} at {DiedAtMs} ms"
|
||||
: Outcome == Outcome.WillBroke
|
||||
? $"seed {Seed}: will broke at {TimeToBreakMs} ms"
|
||||
: $"seed {Seed}: endured to {EndMs} ms, will held, min resolve {MinResolve.ToString("F3", CultureInfo.InvariantCulture)}";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,15 +25,30 @@ public sealed class StressSession
|
|||
private readonly long _sampleEvery;
|
||||
private readonly long _releaseTicks;
|
||||
private readonly int _releaseGoal;
|
||||
private readonly Physiology? _physiology;
|
||||
private readonly PhysiologyPlan? _physiologyPlan;
|
||||
private readonly int[]? _stackOf;
|
||||
private readonly int _cut;
|
||||
private long _breakTick = -1;
|
||||
private double _minResolve = 1.0;
|
||||
private Outcome _outcome = Outcome.Endured;
|
||||
private long _endTick;
|
||||
private long _diedTick = -1;
|
||||
|
||||
/// <param name="poses">What the Brain's goals write, one rotation per muscle; the Actor's muscle count is theirs.</param>
|
||||
public StressSession(StressParameters p, ulong seed, int regionCount, OfficePoses poses, int senseRegion = 0)
|
||||
/// <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>
|
||||
public StressSession(StressParameters p, ulong seed, int regionCount, OfficePoses poses, int senseRegion = 0,
|
||||
Physiology? physiology = null, BodyPlan? body = null, PhysiologyPlan? physiologyPlan = null)
|
||||
{
|
||||
_p = p;
|
||||
if (physiology is not null)
|
||||
{
|
||||
if (body is null || physiologyPlan is null) throw new ArgumentException("a physiology needs the body and the physiology plan it was built on.");
|
||||
_physiology = physiology;
|
||||
_physiologyPlan = physiologyPlan;
|
||||
_stackOf = physiologyPlan.Resolve(body);
|
||||
_cut = physiologyPlan.AfflictionIndex("Cut");
|
||||
}
|
||||
_stressors = new Stressor[p.Cause.Stressors.Count];
|
||||
_emitterOf = new int[_stressors.Length];
|
||||
_silenced = new bool[_stressors.Length];
|
||||
|
|
@ -65,7 +80,8 @@ public sealed class StressSession
|
|||
Actor = new Actor(p.TickSeconds, regionCount, p.Nerve, p.Reflex,
|
||||
p.Drive with { DrainTrait = p.Drive.DrainTrait * drainTrait },
|
||||
OfficeBrain.Build(p, poses),
|
||||
p.Character.Senses with { Gain = p.Character.Senses.Gain * gainTrait }, senseRegion);
|
||||
p.Character.Senses with { Gain = p.Character.Senses.Gain * gainTrait }, senseRegion,
|
||||
physiology: physiology, body: body);
|
||||
_maxTick = Ticks(p.MaxSeconds);
|
||||
_sampleEvery = Math.Max(1, Ticks(p.SampleEverySeconds));
|
||||
_releaseTicks = Ticks(p.ReleaseSeconds);
|
||||
|
|
@ -100,6 +116,31 @@ public sealed class StressSession
|
|||
Log(TickIndex, StressEntryKind.Silenced);
|
||||
}
|
||||
|
||||
/// <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.
|
||||
/// </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;
|
||||
var stack = _physiologyPlan.Parts[_stackOf[part]].Tissues;
|
||||
int applied = 0;
|
||||
bool accepted = true;
|
||||
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++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return applied > 0 && accepted;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One step: each stressor draws its jitter (always, so the stream never depends on state) and writes its
|
||||
/// schedule value; each emitter takes the largest of its unsilenced stressors; the Actor runs on the caller's
|
||||
|
|
@ -125,6 +166,14 @@ public sealed class StressSession
|
|||
_outcome = Outcome.WillBroke;
|
||||
Log(tick, StressEntryKind.WillBroke);
|
||||
}
|
||||
if ((events & TickEvents.Died) != 0)
|
||||
{
|
||||
// The Actor reported the body's death (once); it is limp and frozen from here, and the run ends a release later.
|
||||
_diedTick = tick;
|
||||
_outcome = Outcome.Died;
|
||||
_endTick = Math.Min(_endTick, tick + _releaseTicks);
|
||||
Log(tick, StressEntryKind.Died);
|
||||
}
|
||||
if (tick % _sampleEvery == 0) Log(tick, StressEntryKind.Sample);
|
||||
if ((events & TickEvents.GoalChanged) != 0)
|
||||
{
|
||||
|
|
@ -140,7 +189,8 @@ public sealed class StressSession
|
|||
}
|
||||
|
||||
public StressResult Result() => new(
|
||||
Seed, _outcome, Ms(_endTick), _breakTick >= 0 ? Ms(_breakTick) : null, _minResolve, _timeline);
|
||||
Seed, _outcome, Ms(_endTick), _breakTick >= 0 ? Ms(_breakTick) : null, _minResolve, _timeline,
|
||||
_diedTick >= 0 ? Ms(_diedTick) : null, _diedTick >= 0 ? _physiology!.Cause : DeathCause.None);
|
||||
|
||||
public long Ms(long tick) => (long)Math.Round(tick * _p.TickSeconds * 1000.0);
|
||||
|
||||
|
|
|
|||
14
src/BadDay.Core/WoundTool.cs
Normal file
14
src/BadDay.Core/WoundTool.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace BadDay.Core;
|
||||
|
||||
/// <summary>
|
||||
/// What a wound is made of: one Cut affliction of <see cref="Severity"/> on each of the named tissue <see cref="Layers"/>
|
||||
/// of the part (a part without a layer skips it). Content, not a rule: <see cref="Knife"/> is the click-cut's [P] until
|
||||
/// lodur-insult-resolution turns contacts into afflictions (question bds-first-wound-tool).
|
||||
/// </summary>
|
||||
public sealed record WoundTool(IReadOnlyList<string> Layers, double Severity)
|
||||
{
|
||||
/// <summary>Skin, fat and muscle cut to the same depth.</summary>
|
||||
public static WoundTool Knife { get; } = new(new[] { "Skin", "Fat", "Muscle" }, 60.0);
|
||||
}
|
||||
|
|
@ -28,10 +28,8 @@ public sealed record OfficeBodyResult(
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Office Fella on the seated puppet: <see cref="SeatedPuppet"/>'s world, the desk's emitters moved to where the head
|
||||
/// sits and sensed there, and the same <see cref="StressSession"/> the headless run drives. Per step: the body reports its
|
||||
/// points, the session decides (Lodur's Actor commits the Brain's goals, <see cref="OfficeBrain"/>), the ragdoll is driven,
|
||||
/// the world steps. The run ends as the session ends, the release after calm takes over.
|
||||
/// Office Fella on the seated puppet: <see cref="Run"/> records an <see cref="OfficeBodySession"/>, the one stepper of the
|
||||
/// office's world, from its start to its end, the release after calm takes over (or after a death).
|
||||
/// </summary>
|
||||
public static class OfficeBody
|
||||
{
|
||||
|
|
@ -55,43 +53,17 @@ public static class OfficeBody
|
|||
/// <summary>Runs the office on the puppet to the end of the release; the tick rate must be 1/120 s.</summary>
|
||||
public static OfficeBodyResult Run(StressParameters p, ulong seed)
|
||||
{
|
||||
if (Math.Abs(p.TickSeconds - TickSeconds) > 1e-12)
|
||||
{
|
||||
throw new ArgumentException($"The body run steps at 1/120 s; got TickSeconds {p.TickSeconds}.");
|
||||
}
|
||||
|
||||
var needs = SeatedPuppet.Needs;
|
||||
using var world = new Box3DSoaWorld(capacity: needs.Bodies, jointCapacity: needs.Joints);
|
||||
var ragdoll = SeatedPuppet.Build(world);
|
||||
var plan = ragdoll.Plan;
|
||||
var x = new float[plan.SensePoints.Count];
|
||||
var y = new float[plan.SensePoints.Count];
|
||||
var z = new float[plan.SensePoints.Count];
|
||||
ragdoll.ReadSensePoints(x, y, z);
|
||||
int head = plan.SenseIndex("Head");
|
||||
int handLIdx = plan.SenseIndex("Hand", Side.Left), handRIdx = plan.SenseIndex("Hand", Side.Right);
|
||||
// The desk's emitters sit where the head does and are sensed there.
|
||||
var session = new StressSession(p with { Setting = p.Setting.Shifted(x[head], y[head], z[head]) }, seed,
|
||||
plan.SensePoints.Count, Poses, head);
|
||||
|
||||
var strengths = new float[plan.Joints.Count];
|
||||
var targets = new Quat[plan.Joints.Count];
|
||||
using var session = new OfficeBodySession(p, seed);
|
||||
var handL = new List<BodyPoint>();
|
||||
var handR = new List<BodyPoint>();
|
||||
var pelvis = new List<BodyPoint>();
|
||||
int pelvisLane = ragdoll.BodyLane(plan.PartIndex("Pelvis"));
|
||||
while (!session.Finished)
|
||||
for (;;)
|
||||
{
|
||||
ragdoll.ReadSensePoints(x, y, z);
|
||||
session.Tick(x, y, z, strengths, targets);
|
||||
ragdoll.Drive(strengths, targets);
|
||||
world.Step((float)p.TickSeconds, SeatedPuppet.Substeps);
|
||||
|
||||
ragdoll.ReadSensePoints(x, y, z);
|
||||
handL.Add(new BodyPoint(x[handLIdx], y[handLIdx], z[handLIdx]));
|
||||
handR.Add(new BodyPoint(x[handRIdx], y[handRIdx], z[handRIdx]));
|
||||
var v = world.View;
|
||||
pelvis.Add(new BodyPoint(v.PositionX[pelvisLane], v.PositionY[pelvisLane], v.PositionZ[pelvisLane]));
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
147
src/BadDay.Ymir/OfficeBodySession.cs
Normal file
147
src/BadDay.Ymir/OfficeBodySession.cs
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
using System;
|
||||
using BadDay.Core;
|
||||
using Lodur;
|
||||
using Lodur.Body.Ymir;
|
||||
using Ymir.Box3D;
|
||||
|
||||
namespace BadDay.Ymir;
|
||||
|
||||
/// <summary>
|
||||
/// The office on the seated body, stepped by its caller like <see cref="BodyPainBoxSession"/>: a <see cref="SeatedBody"/>
|
||||
/// (the one owner of the world), a Lodur <see cref="Physiology"/> on the humanoid plan with the session's slow scale,
|
||||
/// and the <see cref="StressSession"/> the headless run drives, with the desk's emitters moved to where the head sits and
|
||||
/// sensed there. Per <see cref="Step"/>: the body reports its points, the session decides (Lodur's Actor, which steps
|
||||
/// the physiology first), the ragdoll is driven, the world steps. Harm enters only through <see cref="Wound"/>; the
|
||||
/// session never decides death, blood or consciousness: the read-outs are Lodur's. A dead body is limp (the Actor writes
|
||||
/// no strength) and the run ends a release after the death. After <see cref="Finished"/> <see cref="Step"/> only keeps
|
||||
/// the body moving, as the chamber does.
|
||||
/// </summary>
|
||||
public sealed class OfficeBodySession : IDisposable
|
||||
{
|
||||
private readonly SeatedBody _body;
|
||||
private readonly StressSession _session;
|
||||
private readonly Physiology _physiology;
|
||||
private readonly double _tickSeconds;
|
||||
private readonly int _handL, _handR, _pelvisLane;
|
||||
private bool _disposed;
|
||||
|
||||
public OfficeBodySession(StressParameters p, ulong seed)
|
||||
{
|
||||
if (Math.Abs(p.TickSeconds - OfficeBody.TickSeconds) > 1e-12)
|
||||
{
|
||||
throw new ArgumentException($"The body run steps at 1/120 s; got TickSeconds {p.TickSeconds}.");
|
||||
}
|
||||
|
||||
_tickSeconds = p.TickSeconds;
|
||||
_body = new SeatedBody();
|
||||
try
|
||||
{
|
||||
var plan = _body.Plan;
|
||||
_body.ReadSenses();
|
||||
int head = plan.SenseIndex("Head");
|
||||
_handL = plan.SenseIndex("Hand", Side.Left);
|
||||
_handR = plan.SenseIndex("Hand", Side.Right);
|
||||
_pelvisLane = _body.Ragdoll.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.
|
||||
_session = new StressSession(p with { Setting = p.Setting.Shifted(_body.X[head], _body.Y[head], _body.Z[head]) }, seed,
|
||||
plan.SensePoints.Count, OfficeBody.Poses, head, _physiology, plan, physiologyPlan);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_body.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The live lanes of the world, for rendering. Read-only: nothing outside the body writes them.</summary>
|
||||
public Box3DSoaView View { get { Live(); return _body.View; } }
|
||||
|
||||
/// <summary>Ticks run so far; the tick the next <see cref="Step"/> runs.</summary>
|
||||
public long TickIndex { get { Live(); return _session.TickIndex; } }
|
||||
|
||||
public bool Finished { get { Live(); return _session.Finished; } }
|
||||
|
||||
/// <summary>The Actor's state at the end of the latest tick, and the body's (Lodur's numbers, never BDS's).</summary>
|
||||
public double Will { get { Live(); return _session.Actor.Drive.Will; } }
|
||||
public double Arousal { get { Live(); return _session.Actor.Drive.Arousal; } }
|
||||
public double Resolve { get { Live(); return _session.Actor.Drive.Resolve; } }
|
||||
public double AirHunger { get { Live(); return _session.Actor.Drive.AirHunger; } }
|
||||
public double Consciousness { get { Live(); return _physiology.Consciousness; } }
|
||||
public double BloodLoss { get { Live(); return _physiology.BloodLoss; } }
|
||||
public bool Dead { get { Live(); return _physiology.Dead; } }
|
||||
public DeathCause DeathCause { get { Live(); return _physiology.Cause; } }
|
||||
public OfficeGoal Goal { get { Live(); return OfficeBrain.GoalAt(_session.Actor.GoalIndex); } }
|
||||
|
||||
/// <summary>The hands and the pelvis as of the latest step (read from the world each time).</summary>
|
||||
public BodyPoint HandL { get { Live(); return Sense(_handL); } }
|
||||
public BodyPoint HandR { get { Live(); return Sense(_handR); } }
|
||||
public BodyPoint Pelvis
|
||||
{
|
||||
get
|
||||
{
|
||||
Live();
|
||||
var v = _body.View;
|
||||
return new BodyPoint(v.PositionX[_pelvisLane], v.PositionY[_pelvisLane], v.PositionZ[_pelvisLane]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>One step of 1/120 s; see the type's summary for what it does after <see cref="Finished"/>.</summary>
|
||||
public void Step()
|
||||
{
|
||||
Live();
|
||||
if (!_session.Finished)
|
||||
{
|
||||
long tick = _session.TickIndex;
|
||||
_body.ReadSenses();
|
||||
var events = _session.Tick(_body.X, _body.Y, _body.Z, _body.Strengths, _body.Targets);
|
||||
if (events != TickEvents.None) _body.Enqueue(tick, events);
|
||||
}
|
||||
_body.DriveAndStep(_tickSeconds); // after Finished: the last strengths and targets again
|
||||
}
|
||||
|
||||
/// <summary>Moves the queued events (oldest first) into <paramref name="buffer"/>; see <see cref="SeatedBody.DrainEvents"/>.</summary>
|
||||
public int DrainEvents(Span<BodyEvent> buffer)
|
||||
{
|
||||
Live();
|
||||
return _body.DrainEvents(buffer);
|
||||
}
|
||||
|
||||
/// <summary>The player silences a stressor from the next tick; see <see cref="StressSession.Silence"/>.</summary>
|
||||
public void Silence(string stressorId)
|
||||
{
|
||||
Live();
|
||||
_session.Silence(stressorId);
|
||||
}
|
||||
|
||||
/// <summary>Wounds the body's part from the next tick; false when refused (see <see cref="StressSession.Wound"/>).</summary>
|
||||
public bool Wound(int part, WoundTool tool)
|
||||
{
|
||||
Live();
|
||||
return _session.Wound(part, tool);
|
||||
}
|
||||
|
||||
/// <summary>The nervous result so far, with the death if there was one.</summary>
|
||||
public StressResult Result()
|
||||
{
|
||||
Live();
|
||||
return _session.Result();
|
||||
}
|
||||
|
||||
/// <summary>Frees the world; a second call does nothing.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed) return;
|
||||
_disposed = true;
|
||||
_body.Dispose();
|
||||
}
|
||||
|
||||
private BodyPoint Sense(int i)
|
||||
{
|
||||
_body.ReadSenses();
|
||||
return new BodyPoint(_body.X[i], _body.Y[i], _body.Z[i]);
|
||||
}
|
||||
|
||||
private void Live() => ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
}
|
||||
|
|
@ -1089,6 +1089,113 @@ public static class Program
|
|||
var headless = Office(new StressParameters(), 1);
|
||||
Check(Math.Abs(body.TimeToBreakMs!.Value - headless.TimeToBreakMs!.Value) < 500, $"body {body.TimeToBreakMs} ms, headless {headless.TimeToBreakMs} ms");
|
||||
}),
|
||||
|
||||
("office session: stepping OfficeBodySession to Finished gives OfficeBody.Run's timeline, seeds 1 and 2, and the pelvis and hands are the ones Run recorded", () =>
|
||||
{
|
||||
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
|
||||
foreach (ulong seed in new ulong[] { 1, 2 })
|
||||
{
|
||||
var run = OfficeBody.Run(p, seed);
|
||||
using var s = new OfficeBodySession(p, seed);
|
||||
int steps = 0;
|
||||
while (!s.Finished) { s.Step(); steps++; }
|
||||
Check(s.Result().Render() == run.Run.Render(), $"seed {seed}: the stepped session's timeline differs from Run's");
|
||||
Check(steps == run.HandL.Count && s.HandL == run.HandL[^1] && s.HandR == run.HandR[^1] && s.Pelvis == run.Pelvis[^1], $"seed {seed}: {steps} steps against {run.HandL.Count} recorded, or the last points differ");
|
||||
bool threw = false;
|
||||
try { new OfficeBodySession(p with { TickSeconds = 0.01 }, seed).Dispose(); } catch (ArgumentException) { threw = true; }
|
||||
Check(threw, "a tick rate other than 1/120 s was accepted");
|
||||
}
|
||||
}),
|
||||
|
||||
("office wound kills by blood loss: Wound(LowerArm L, Knife) at tick 0 gives exactly one Died event, DeathCause BloodLoss, Outcome Died, a death 30-60 s in (probe: 42.1 s with skin and muscle) that two runs agree on, and a run that ends ReleaseSeconds later", () =>
|
||||
{
|
||||
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
|
||||
var arm = SeatedPuppet.Plan.PartIndex("LowerArm", Lodur.Side.Left);
|
||||
long? diedAt = null;
|
||||
for (int run = 0; run < 2; run++)
|
||||
{
|
||||
using var s = new OfficeBodySession(p, 1);
|
||||
Check(s.Wound(arm, WoundTool.Knife), "the knife was refused on the lower arm");
|
||||
var buffer = new BodyEvent[16];
|
||||
int died = 0;
|
||||
bool deadBefore = false;
|
||||
while (!s.Finished)
|
||||
{
|
||||
s.Step();
|
||||
int n; while ((n = s.DrainEvents(buffer)) > 0) for (int i = 0; i < n; i++) if ((buffer[i].Events & Lodur.TickEvents.Died) != 0) died++;
|
||||
deadBefore |= s.Dead && died == 0;
|
||||
}
|
||||
var r = s.Result();
|
||||
Check(died == 1 && !deadBefore, $"{died} Died events drained");
|
||||
Check(s.Dead && s.DeathCause == Lodur.DeathCause.BloodLoss && r.DeathCause == Lodur.DeathCause.BloodLoss, $"cause {s.DeathCause}");
|
||||
Check(r.Outcome == Outcome.Died && r.DiedAtMs is long ms && ms >= 30000 && ms <= 60000, $"outcome {r.Outcome}, died at {r.DiedAtMs} ms");
|
||||
Check(r.EndMs == r.DiedAtMs + (long)Math.Round(p.ReleaseSeconds * 1000.0), $"the run ended at {r.EndMs} ms, the death was at {r.DiedAtMs} ms");
|
||||
Check(r.Timeline.Count(e => e.Kind == StressEntryKind.Died) == 1 && r.Summary().Contains("BloodLoss"), "the Died row or the summary is missing");
|
||||
Check(s.Consciousness == 0.0 && s.BloodLoss >= 1.0, $"consciousness {s.Consciousness}, blood loss {s.BloodLoss}");
|
||||
if (diedAt is null) diedAt = r.DiedAtMs; else Check(diedAt == r.DiedAtMs, $"two runs died at {diedAt} and {r.DiedAtMs} ms");
|
||||
}
|
||||
}),
|
||||
|
||||
("office death is limp and ends the run: after the Died tick every strength the session wrote is 0 and the goal never changes again, the death is before the run's end by exactly ReleaseSeconds, and before it the body was driving muscles", () =>
|
||||
{
|
||||
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
|
||||
var plan = SeatedPuppet.Plan;
|
||||
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);
|
||||
Check(session.Wound(plan.PartIndex("LowerArm", Lodur.Side.Left), WoundTool.Knife), "the knife was refused");
|
||||
var pts = new float[plan.SensePoints.Count];
|
||||
var strengths = new float[plan.Joints.Count];
|
||||
var targets = new Quat[plan.Joints.Count];
|
||||
float drivenBefore = 0f;
|
||||
long diedTick = -1;
|
||||
int goalAtDeath = -1;
|
||||
while (!session.Finished)
|
||||
{
|
||||
var ev = session.Tick(pts, pts, pts, strengths, targets);
|
||||
if ((ev & Lodur.TickEvents.Died) != 0) { diedTick = session.TickIndex - 1; goalAtDeath = session.Actor.GoalIndex; }
|
||||
if (diedTick < 0) drivenBefore = Math.Max(drivenBefore, strengths.Max());
|
||||
else Check(strengths.All(v => v == 0f) && session.Actor.GoalIndex == goalAtDeath, $"tick {session.TickIndex - 1}: a strength or the goal moved after the death");
|
||||
}
|
||||
var r = session.Result();
|
||||
Check(diedTick >= 0 && r.Outcome == Outcome.Died, "the body did not die");
|
||||
Check(drivenBefore > 0f, "no muscle was driven before the death, so limp proves nothing");
|
||||
Check(session.TickIndex - 1 == diedTick + (long)Math.Round(p.ReleaseSeconds / p.TickSeconds), $"the run ended at tick {session.TickIndex - 1}, the death was at {diedTick}");
|
||||
}),
|
||||
|
||||
("office wound refusals: an out-of-range part and a headless session refuse, a tool with no layer the part has is refused, and a palm takes the knife on skin and muscle without fat", () =>
|
||||
{
|
||||
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
|
||||
using (var s = new OfficeBodySession(p, 1))
|
||||
{
|
||||
Check(!s.Wound(-1, WoundTool.Knife) && !s.Wound(SeatedPuppet.Plan.Parts.Count, WoundTool.Knife), "an out-of-range part was wounded");
|
||||
}
|
||||
Check(!NewOffice(p, 1).Wound(0, WoundTool.Knife), "a headless session was wounded");
|
||||
|
||||
var plan = SeatedPuppet.Plan;
|
||||
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);
|
||||
int palm = plan.PartIndex("Palm", Lodur.Side.Left);
|
||||
Check(!session.Wound(palm, new WoundTool(new[] { "Fat" }, 60.0)), "a palm took a fat-only wound");
|
||||
Check(session.Wound(palm, WoundTool.Knife), "the palm refused the knife");
|
||||
var pts = new float[plan.SensePoints.Count];
|
||||
session.Tick(pts, pts, pts, new float[plan.Joints.Count], new Quat[plan.Joints.Count]);
|
||||
Check(physiology.Integrity(palm, physiology.TissueIndex(palm, "Skin")) < 1.0 && physiology.Integrity(palm, physiology.TissueIndex(palm, "Muscle")) < 1.0, "the palm's skin or muscle is unhurt");
|
||||
Check(physiology.Integrity(palm, physiology.TissueIndex(palm, "Metacarpals")) == 1.0, "the palm's metacarpals were hurt");
|
||||
}),
|
||||
|
||||
("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 };
|
||||
for (ulong seed = 1; seed <= 3; seed++)
|
||||
{
|
||||
using var s = new OfficeBodySession(p, seed);
|
||||
while (!s.Finished) s.Step();
|
||||
var r = s.Result();
|
||||
Check(!s.Dead && s.DeathCause == Lodur.DeathCause.None && r.DiedAtMs is null && r.Outcome != Outcome.Died && s.Consciousness == 1.0, $"seed {seed}: dead {s.Dead}, cause {s.DeathCause}, consciousness {s.Consciousness}");
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
private static readonly float[] Point = new float[1], Strengths = new float[1];
|
||||
|
|
|
|||
Loading…
Reference in a new issue