Blood spreads over the cut when the spawn spot is taken instead of waiting; wet friction pinned by a slide; stale figures corrected (94/94)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-27 02:34:45 +01:00
commit 3f0a0592b3
3 changed files with 98 additions and 11 deletions

View file

@ -36,6 +36,9 @@ public sealed record BloodParameters
public float Viscosity { get; init; } = 0.01f;
public float WetFriction { get; init; } = 0.1f;
/// <summary>Sets the blood material in <paramref name="world"/>: the one place the table entry is written, used by the seated body.</summary>
public void ApplyTo(Box3DSoaWorld world) => world.SetMaterial(Material, Friction, viscosity: Viscosity, wetFriction: WetFriction);
/// <summary>One drop's volume in m^3.</summary>
public double DropVolume => Math.Pow(2.0 * DropRadius, 3.0);
}
@ -49,7 +52,7 @@ public sealed record BloodParameters
/// dropped. After every step a drop that has rested on something for <see cref="BloodParameters.SettleTicks"/> ticks
/// settles into a wet patch, and the oldest supported drops settle until the live drops are at most LiveCap - MaxDropsPerTick, so
/// they stay under <see cref="BloodParameters.LiveCap"/>. A lane Settle frees cannot be taken before the next Step, so a cap-bound run sheds fewer drops
/// than it could (measured 69% of 8 a tick at saturation; the rest waits as backlog, none is lost); a lethal bleed (2.5 drops a tick) never reaches it. Ymir never settles by itself; this is the policy.
/// than it could (measured 50% of 8 a tick at saturation, 19268 of 38400 drops over 4800 ticks at SettleTicks 30; the rest waits as backlog, none is lost); a lethal bleed (2.5 drops a tick) never reaches it. Ymir never settles by itself; this is the policy.
/// Allocation-free once the wound points are open.
/// </summary>
public sealed class Blood
@ -61,6 +64,7 @@ public sealed class Blood
public double Volume; // visible m^3 gathered and not yet shed
}
private const int SpiralSpots = 40;
private readonly Box3DSoaWorld _world;
private readonly Ragdoll _ragdoll;
private readonly BloodParameters _p;
@ -142,15 +146,34 @@ public sealed class Blood
var q = new Quat(v.RotationX[lane], v.RotationY[lane], v.RotationZ[lane], v.RotationW[lane]);
q.Rotate(w.Px, w.Py, w.Pz, out var px, out var py, out var pz);
q.Rotate(w.Nx, w.Ny, w.Nz, out var nx, out var ny, out var nz);
// Outside the surface, and then outward until clear of every drop already live or shed this tick (coincident cuts, a wound that sheds
// faster than a drop leaves): overlapped fluid blows up. A point still blocked after a few diameters waits; its volume stays gathered.
// Outside the surface at the picked point; when a live drop or one shed this tick is in the way (coincident cuts, a wound that sheds faster
// than a drop leaves), at a free spot on the cut around the point (a spiral over the tangent plane, so a cut spreads), then outward. Overlapped
// fluid blows up. A point with no free spot at all waits; its volume stays gathered.
float lift = r + 0.002f;
(float X, float Y, float Z) at = default;
bool clear = false;
for (int attempt = 0; attempt < 12 && !clear; attempt++, lift += r)
float bx = v.PositionX[lane] + px + nx * lift, by = v.PositionY[lane] + py + ny * lift, bz = v.PositionZ[lane] + pz + nz * lift;
(float X, float Y, float Z) at = (bx, by, bz);
bool clear = Clear(at, n, v);
if (!clear)
{
at = (v.PositionX[lane] + px + nx * lift, v.PositionY[lane] + py + ny * lift, v.PositionZ[lane] + pz + nz * lift);
clear = Clear(at, n, v);
// The tangent basis: a deterministic pair across the normal.
float ax = MathF.Abs(ny) < 0.9f ? 0f : 1f, ay = MathF.Abs(ny) < 0.9f ? 1f : 0f;
float tx = -nz * ay, ty = nz * ax, tz = nx * ay - ny * ax; // n x axis
float tl = MathF.Sqrt(tx * tx + ty * ty + tz * tz);
tx /= tl; ty /= tl; tz /= tl;
float ux = ny * tz - nz * ty, uy = nz * tx - nx * tz, uz = nx * ty - ny * tx; // n x t
for (int spot = 1; spot <= SpiralSpots && !clear; spot++)
{
float angle = spot * 2.39996323f; // the golden angle
float radius = 1.8f * r * MathF.Sqrt(spot);
float c = MathF.Cos(angle) * radius, d = MathF.Sin(angle) * radius;
at = (bx + tx * c + ux * d, by + ty * c + uy * d, bz + tz * c + uz * d);
clear = Clear(at, n, v);
}
for (int step = 1; step <= 12 && !clear; step++)
{
at = (bx + nx * step * r, by + ny * step * r, bz + nz * step * r);
clear = Clear(at, n, v);
}
}
if (!clear) continue;
w.Volume -= _dropVolume;

View file

@ -41,7 +41,7 @@ public sealed class SeatedBody : IDisposable
Fluid: blood.LiveCap, Wets: blood.WetLanes, Sensors: needs.Sensors));
try
{
_world.SetMaterial(blood.Material, blood.Friction, viscosity: blood.Viscosity, wetFriction: blood.WetFriction);
blood.ApplyTo(_world);
_ragdoll = SeatedPuppet.Build(_world);
var plan = _ragdoll.Plan;
_blood = new Blood(_world, _ragdoll, blood);

View file

@ -1389,7 +1389,7 @@ public static class Program
}
clock.Stop();
Check(wetAt15 > 0, "no wet patch by 15 s");
// Measured: shipped peak 340 (319 before the spawn clearance), a settle by the cap alone (the cap-only-settle mutant) 504, this bound 384 between them.
// Measured: shipped peak 381 now (340 with clearance but no spread, 319 before the clearance), the cap-only-settle mutant 504, this bound 384, so the margin is 3 drops: the bound is not to be loosened, the shed pattern is to be changed instead.
Check(peak <= bloodParameters.LiveCap * 3 / 4, $"{peak} drops were live at once: the cap, not the slow-settle rule, is carrying the blood (probe: 256 live at 300 drops/s)");
double wet = 0.0;
var volume = s.View.WetPatchVolume;
@ -1397,7 +1397,7 @@ public static class Program
for (int i = 0; i < volume.Length; i++) if (live[i] != 0u) wet += volume[i];
double held = wet + s.LiveDrops * bloodParameters.DropVolume;
Check(Math.Abs(held - s.BloodEmitted) < 1e-6, $"wet {wet} + live {s.LiveDrops} x drop is {held}, emitted {s.BloodEmitted} m^3");
Console.WriteLine($" blood: {s.BloodEmitted * 1000.0:F1} L shed, backlog {s.BloodBacklog * 1000.0:F2} L, peak live {peak}, {s.View.WetCount} wet patches, {clock.Elapsed.TotalMilliseconds / (40 * Hz):F2} ms a tick whole (probe: +0.56 ms at 256 live)");
Console.WriteLine($" blood: {s.BloodEmitted * 1000.0:F1} L shed, backlog {s.BloodBacklog * 1000.0:F2} L, peak live {peak}, {s.View.WetCount} wet patches, {clock.Elapsed.TotalMilliseconds / (40 * Hz):F2} ms a tick, the whole session (Soul measured the blood alone at +1.03 ms over the idle particle system at 300 drops/s)");
}),
("office blood lands where it falls: every patch's support is the ground, the stool or a Fella lane, and six cuts give a ground patch (stable id 1) by 40 s", () =>
@ -1551,6 +1551,70 @@ public static class Program
Check(body.BloodEmitted > 24 * parameters.DropVolume, "the cap was never reached: the test pins nothing");
}),
("office blood keeps pace with the bleed at coincident and near-coincident cuts: five clicks on one PartHit and six points 1 cm apart on a lower arm; the unshed backlog never passes one second of the flow (0.78 L visible per knife) and, two ticks after the death, nothing more than a drop a point is left to shed", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
var parameters = new BloodParameters();
var arm = SeatedPuppet.Plan.PartIndex("LowerArm", Lodur.Side.Left);
foreach (var spread in new[] { 0.0, 0.01 })
{
using var s = new OfficeBodySession(p, 1);
var hits = new List<PartHit> { Hit(s, arm) };
if (spread == 0.0) { while (hits.Count < 5) hits.Add(hits[0]); }
else
{
var c = SeatedPuppet.Plan.Parts[arm].Position;
for (float u = -0.1f; u <= 0.1f && hits.Count < 6; u += 0.0025f)
{
// Rays along -Z... from the front, sliding up the arm: a point on the arm at least 1 cm from each chosen one.
if (s.Pick(new BodyPoint(c.X, c.Y + u, c.Z + 1f), new BodyPoint(0f, 0f, -1f)) is { } h && h.Part == arm &&
hits.All(o => Math.Sqrt(Math.Pow(o.Point.X - h.Point.X, 2) + Math.Pow(o.Point.Y - h.Point.Y, 2) + Math.Pow(o.Point.Z - h.Point.Z, 2)) >= 0.01)) hits.Add(h);
}
Check(hits.Count == 6, $"only {hits.Count} points 1 cm apart");
}
foreach (var h in hits) Check(s.Wound(h, WoundTool.Knife), "the knife was refused");
double bound = hits.Count * 0.78e-3, worst = 0.0, atDeath = -1.0;
int deadAt = -1;
for (int t = 0; !s.Finished; t++)
{
s.Step();
worst = Math.Max(worst, s.BloodBacklog);
if (s.Dead && deadAt < 0) deadAt = t;
if (deadAt >= 0 && t == deadAt + 2) atDeath = s.BloodEmitted;
}
Console.WriteLine($" {hits.Count} points, spread {spread}: peak backlog {worst * 1000.0:F2} L (bound {bound * 1000.0:F2}), shed {s.BloodEmitted * 1000.0:F1} L, backlog at the end {s.BloodBacklog * 1e6:F1} mL");
Check(worst <= bound, $"{hits.Count} points, spread {spread}: the backlog peaked at {worst * 1000.0:F2} L, over {bound * 1000.0:F2} L");
Check(atDeath >= 0.0 && s.BloodEmitted - atDeath < 2.0 * parameters.DropVolume, $"{hits.Count} points: {(s.BloodEmitted - atDeath) * 1e6:F1} mL was still being shed after the death");
Check(s.BloodBacklog < hits.Count * parameters.DropVolume, $"{hits.Count} points: {s.BloodBacklog * 1e6:F1} mL was never shed");
}
}),
("blood makes a surface slippery: the seated body's blood material (BloodParameters.ApplyTo, the one SeatedBody uses) lets a pushed box slide at least 5 cm further over a settled drop than over a dry floor", () =>
{
var parameters = new BloodParameters();
double Slide(bool patch)
{
float drop = 0.03f, scale = drop / parameters.DropRadius;
using var world = new global::Ymir.Box3D.Box3DSoaWorld(capacity: 8, gravityY: -9.81f,
particles: new global::Ymir.Box3D.Box3DSoaParticleCapacities(8, 0, 0, 0, 0, parameters.Material + 1, Fluid: 8, Wets: 4));
world.AddStaticBox(1, (0f, -0.5f, 0f), (4f, 0.5f, 2f), friction: 0.6f);
world.SetMaterial(0, 0.6f);
parameters.ApplyTo(world);
world.CreateParticles(new[] { new global::Ymir.Box3D.Box3DSoaParticleDesc((0f, drop, 0f), (float)(parameters.Density * Math.Pow(2.0 * drop, 3.0)), drop,
global::Ymir.Box3D.Box3DSoaPhase.Of(1, fluid: true), (uint)parameters.Material) });
for (int t = 0; t < 20; t++) world.Step(1f / 60f, 4);
var handle = new global::Ymir.Box3D.Box3DSoaParticleHandle(0, world.View.ParticleGeneration[0]);
if (patch) world.Settle(new[] { handle }); else world.DestroyParticles(new[] { handle });
int box = world.AddBox(10, (0f, 0.1f, 0f), (0.1f, 0.1f, 0.1f), 5f / 0.008f, friction: 0.6f);
double x0 = world.View.PositionX[box];
for (int t = 0; t < 40; t++) { world.View.ForceX[box] = 20f; world.Step(1f / 60f, 4); } // below the dry friction (29 N), above the wet one
return world.View.PositionX[box] - x0;
}
double dry = Slide(false), wet = Slide(true);
Console.WriteLine($" slide over 40 ticks: dry {dry * 100.0:F1} cm, over blood {wet * 100.0:F1} cm");
Check(wet - dry >= 0.05, $"the box slid {wet * 100.0:F1} cm over blood and {dry * 100.0:F1} cm dry");
}),
("seated airway pins: the pooled liquid reaches Lodur (a wound above the mouth settling on the face reads Pooled), down is the world's gravity (an upright mouth has no drop), and the blood material is slippery (wet friction 0.1, friction 0.3)", () =>
{
var plan = SeatedPuppet.Plan;