From fa29d1256f41e5d2f2989bc9c0139d77a63dc226 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 20 Nov 2026 06:14:47 +0100 Subject: [PATCH] Puppet: one build counter, at the Godot mesh build; the model's and the shape's counters are gone, and the smoke asserts it Co-Authored-By: Claude Sonnet 5.5 --- client/BodyRenderer.cs | 3 +++ client/Puppet.cs | 4 ++++ client/PuppetField.cs | 3 --- client/PuppetModel.cs | 4 ---- client/tests/PuppetChecks.cs | 16 +++++++++------- client/tests/Smoke.cs | 4 ++-- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/client/BodyRenderer.cs b/client/BodyRenderer.cs index 6053912..5522126 100644 --- a/client/BodyRenderer.cs +++ b/client/BodyRenderer.cs @@ -22,6 +22,9 @@ public partial class BodyRenderer : Node3D /// What the puppet's mesh is made of now, or null while it draws none. public PuppetShape? PuppetShape => _puppet.Shape; + /// How many times the puppet's Godot mesh has been built. + public int PuppetMeshBuilds => _puppet.MeshBuilds; + public BaseMaterial3D SceneryMaterial => _material; /// Where body is drawn now, or null if it is not drawn. diff --git a/client/Puppet.cs b/client/Puppet.cs index decc457..9a35b12 100644 --- a/client/Puppet.cs +++ b/client/Puppet.cs @@ -33,6 +33,9 @@ public partial class Puppet : Node3D public int BodyCount => _nodes.Count; + /// How many times the Godot mesh has been made from a shape: the one build counter, which the smoke asserts. + public int MeshBuilds { get; private set; } + /// The colour the puppet is drawn in: the shader's albedo. public Color Color => _material.GetShaderParameter("albedo").AsColor(); @@ -142,6 +145,7 @@ public partial class Puppet : Node3D _boneNodes = new Node3D[shape.Ids.Length]; _inverseBind = new Transform3D[shape.Ids.Length]; for (int i = 0; i < shape.Ids.Length; i++) { _boneNodes[i] = _nodes[shape.Ids[i]]; _inverseBind[i] = ToTransform(shape.SpreadBind[i].Inverse()); } _mesh = MeshOf(shape); + MeshBuilds++; _skin.Mesh = _mesh; } diff --git a/client/PuppetField.cs b/client/PuppetField.cs index af80187..1d93e62 100644 --- a/client/PuppetField.cs +++ b/client/PuppetField.cs @@ -66,9 +66,6 @@ public sealed class PuppetShape /// How far a skinned vertex can lie from its bone's origin. public required float Reach { get; init; } - /// How many times the mesh has been built; Puppet counts. - public int Builds { get; internal set; } - public int Triangles => Positions.Length / 3; } diff --git a/client/PuppetModel.cs b/client/PuppetModel.cs index 45ef749..928f0d7 100644 --- a/client/PuppetModel.cs +++ b/client/PuppetModel.cs @@ -36,9 +36,6 @@ public sealed class PuppetModel /// The shape built from the current signature, or null before the first update or while there are more than shape bodies. public PuppetShape? Shape { get; private set; } - /// How many meshes have been built. - public int Builds { get; private set; } - /// Reads the shape bodies and qualifying joints of the lanes and updates. public bool Update(in Box3DSoaView view) { @@ -96,7 +93,6 @@ public sealed class PuppetModel if (bound.Count > MaxBones) { Shape = null; return true; } Shape = PuppetField.Build(bound, built, _smin, _ballScale, _boxRound); - Shape.Builds = ++Builds; return true; } diff --git a/client/tests/PuppetChecks.cs b/client/tests/PuppetChecks.cs index 87d60ab..449b485 100644 --- a/client/tests/PuppetChecks.cs +++ b/client/tests/PuppetChecks.cs @@ -39,16 +39,16 @@ public static class PuppetChecks // The first update builds; the same signature again, even from new lists, never does. var m = Fresh(); var (bodies, joints) = Chain(); - Check(m.Update(bodies, joints) && m.Builds == 1 && m.Shape is not null, "the first update did not build the puppet once"); + Check(m.Update(bodies, joints) && m.Shape is not null, "the first update did not build the puppet"); + var first = m.Shape; var (again, againJoints) = Chain(); - Check(!m.Update(again, againJoints) && m.Builds == 1, "an unchanged signature rebuilt the puppet"); + Check(!m.Update(again, againJoints) && ReferenceEquals(m.Shape, first), "an unchanged signature rebuilt the puppet"); // Poses and joint origins alone are not topology: the bind is the first sight. var moved = Chain(); for (int i = 0; i < moved.Bodies.Count; i++) moved.Bodies[i] = moved.Bodies[i] with { Bind = Rigid.FromQuaternion(0, 0, 0, 1, new float3(0.5f, 2f + i, 0)) }; moved.Joints[0] = moved.Joints[0] with { Origin = new float3(9, 9, 9) }; - var before = m.Shape; - Check(!m.Update(moved.Bodies, moved.Joints) && m.Builds == 1 && ReferenceEquals(m.Shape, before), "bodies that only moved rebuilt the puppet"); + Check(!m.Update(moved.Bodies, moved.Joints) && ReferenceEquals(m.Shape, first), "bodies that only moved rebuilt the puppet"); // Each change of topology rebuilds exactly once, and then holds. void Changes(string what, Action, List> edit) @@ -56,9 +56,11 @@ public static class PuppetChecks var model = Fresh(); var (b, j) = Chain(); model.Update(b, j); + var built = model.Shape; edit(b, j); - Check(model.Update(b, j) && model.Builds == 2, $"{what}: the signature changed and the puppet was not rebuilt once"); - Check(!model.Update(b, j) && model.Builds == 2, $"{what}: the new signature rebuilt again"); + Check(model.Update(b, j) && !ReferenceEquals(model.Shape, built), $"{what}: the signature changed and the puppet was not rebuilt"); + var rebuilt = model.Shape; + Check(!model.Update(b, j) && ReferenceEquals(model.Shape, rebuilt), $"{what}: the new signature rebuilt again"); } Changes("a joint removed", (b, j) => j.RemoveAt(1)); Changes("a body added", (b, j) => b.Add(Body(13, Box3DSoaKind.Sphere, 0.05f, 0f, 1.3f))); @@ -71,7 +73,7 @@ public static class PuppetChecks // Past the skin's bone count nothing is drawn, once, and the signature still decides. var many = Fresh(); var crowd = Enumerable.Range(0, PuppetModel.MaxBones + 1).Select(i => Body((ulong)(100 + i), Box3DSoaKind.Sphere, 0.05f, 0f, i * 0.2f)).ToList(); - Check(many.Update(crowd, new List()) && many.Shape is null && many.Builds == 0, "more shape bodies than bones was drawn"); + Check(many.Update(crowd, new List()) && many.Shape is null, "more shape bodies than bones was drawn"); Check(!many.Update(crowd, new List()), "an over-full puppet reported a change with none"); crowd.RemoveAt(0); Check(many.Update(crowd, new List()) && many.Shape is not null, "the puppet did not come back once it fit the skin"); diff --git a/client/tests/Smoke.cs b/client/tests/Smoke.cs index 13414bc..d96ad6b 100644 --- a/client/tests/Smoke.cs +++ b/client/tests/Smoke.cs @@ -75,7 +75,7 @@ public partial class Smoke : Node // A Reset is not a topology change: the mesh stays the one built at startup. Checked after three resets so a rebuild per // Reset fails here, not after hundreds. for (ulong seed = 1; seed <= 3; seed++) { PressReset(seed); await Frame(); } - Check(_main.Bodies.PuppetShape?.Builds == 1, $"the puppet mesh was built {_main.Bodies.PuppetShape?.Builds} times by the third Reset; the signature never changed, so once"); + Check(_main.Bodies.PuppetMeshBuilds == 1, $"the puppet mesh was built {_main.Bodies.PuppetMeshBuilds} times by the third Reset; the signature never changed, so once"); if (_failures.Count > 0) return; // Seed 1 at the default intensity against the headless run: events, and the hand at ticks 240 and 1500. @@ -130,7 +130,7 @@ public partial class Smoke : Node await Frame(); } Check(_main.Seed == 1399, $"after 400 resets the seed is {_main.Seed}"); - Check(_main.Bodies.PuppetShape?.Builds == 1, $"the puppet mesh was built {_main.Bodies.PuppetShape?.Builds} times; the signature never changed, so once"); + Check(_main.Bodies.PuppetMeshBuilds == 1, $"the puppet mesh was built {_main.Bodies.PuppetMeshBuilds} times; the signature never changed, so once"); // Box off, through the HUD button, at tick 600: the run ends with the will intact and the screen shows the box off. PressReset(Seed);