Fix batch: the camera's binding table owns what Alt+left means (guard live with emulation off and mid-drag, smoke-pinned); drawn blood pinned to the lanes; bars with a visible track
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
53b14bd272
commit
7416d15dd0
5 changed files with 83 additions and 7 deletions
|
|
@ -13,11 +13,17 @@ namespace BadDay.Client;
|
|||
public partial class BloodRenderer : Node3D
|
||||
{
|
||||
/// <summary>A patch is a disc this thick (m), lifted this far (m) so it does not z-fight the surface it lies on.</summary>
|
||||
private const float PatchThickness = 0.004f, PatchLift = 0.003f;
|
||||
public const float PatchThickness = 0.004f, PatchLift = 0.003f;
|
||||
|
||||
private readonly MultiMeshInstance3D _drops = Instances(new BoxMesh { Size = Vector3.One }, "Drops");
|
||||
private readonly MultiMeshInstance3D _patches = Instances(new CylinderMesh { TopRadius = 1f, BottomRadius = 1f, Height = 1f, RadialSegments = 8, Rings = 0 }, "Patches");
|
||||
|
||||
private readonly System.Collections.Generic.List<Transform3D> _dropPoses = new(), _patchPoses = new();
|
||||
|
||||
/// <summary>The transforms the latest Sync gave the drops and the patches, in lane order (a copy of what the MultiMeshes were told, display-only: a headless renderer keeps none).</summary>
|
||||
public System.Collections.Generic.IReadOnlyList<Transform3D> Drops => _dropPoses;
|
||||
public System.Collections.Generic.IReadOnlyList<Transform3D> Patches => _patchPoses;
|
||||
|
||||
/// <summary>Drops and wet patches drawn by the latest <see cref="Sync"/>: the live fluid lanes and the live wet lanes.</summary>
|
||||
public int DropCount { get; private set; }
|
||||
public int PatchCount { get; private set; }
|
||||
|
|
@ -42,11 +48,14 @@ public partial class BloodRenderer : Node3D
|
|||
int drops = 0;
|
||||
for (int i = 0; i < live.Length; i++) if (live[i] != 0 && (phase[i] & Box3DSoaPhase.Fluid) != 0) drops++;
|
||||
Reserve(_drops.Multimesh, drops);
|
||||
_dropPoses.Clear();
|
||||
int d = 0;
|
||||
for (int i = 0; i < live.Length && d < drops; i++)
|
||||
{
|
||||
if (live[i] == 0 || (phase[i] & Box3DSoaPhase.Fluid) == 0) continue;
|
||||
_drops.Multimesh.SetInstanceTransform(d++, new Transform3D(Basis.FromScale(Vector3.One * 2f * radius[i]), new Vector3(view.ParticleX[i], view.ParticleY[i], view.ParticleZ[i])));
|
||||
var pose = new Transform3D(Basis.FromScale(Vector3.One * 2f * radius[i]), new Vector3(view.ParticleX[i], view.ParticleY[i], view.ParticleZ[i]));
|
||||
_dropPoses.Add(pose);
|
||||
_drops.Multimesh.SetInstanceTransform(d++, pose);
|
||||
}
|
||||
DropCount = drops;
|
||||
_drops.Multimesh.VisibleInstanceCount = drops;
|
||||
|
|
@ -55,6 +64,7 @@ public partial class BloodRenderer : Node3D
|
|||
int patches = 0;
|
||||
for (int i = 0; i < wet.Length; i++) if (wet[i] != 0) patches++;
|
||||
Reserve(_patches.Multimesh, patches);
|
||||
_patchPoses.Clear();
|
||||
int p = 0;
|
||||
for (int i = 0; i < wet.Length && p < patches; i++)
|
||||
{
|
||||
|
|
@ -70,7 +80,9 @@ public partial class BloodRenderer : Node3D
|
|||
else if (particle >= 0) at = new Vector3(view.ParticleX[particle], view.ParticleY[particle], view.ParticleZ[particle]);
|
||||
else at = local;
|
||||
float r = view.WetRadius[i];
|
||||
_patches.Multimesh.SetInstanceTransform(p++, new Transform3D(Basis.FromScale(new Vector3(r, PatchThickness, r)), at + Vector3.Up * PatchLift));
|
||||
var pose = new Transform3D(Basis.FromScale(new Vector3(r, PatchThickness, r)), at + Vector3.Up * PatchLift);
|
||||
_patchPoses.Add(pose);
|
||||
_patches.Multimesh.SetInstanceTransform(p++, pose);
|
||||
}
|
||||
PatchCount = patches;
|
||||
_patches.Multimesh.VisibleInstanceCount = patches;
|
||||
|
|
|
|||
|
|
@ -24,9 +24,18 @@ public partial class Hud : CanvasLayer
|
|||
|
||||
public OptionButton ScenarioPicker { get; } = new();
|
||||
/// <summary>His will, 0 to 1 (lodur:ruling:bds-will-visible).</summary>
|
||||
public ProgressBar WillBar { get; } = new() { MinValue = 0, MaxValue = 1, Step = 0, ShowPercentage = false, CustomMinimumSize = new Vector2(220, 18) };
|
||||
public ProgressBar WillBar { get; } = Bar(Color.Color8(0x4c, 0x9a, 0xd8));
|
||||
/// <summary>His arousal, 0 to 1 (lodur:ruling:stress-bar-shows-arousal-calm-silences).</summary>
|
||||
public ProgressBar StressBar { get; } = new() { MinValue = 0, MaxValue = 1, Step = 0, ShowPercentage = false, CustomMinimumSize = new Vector2(220, 18) };
|
||||
public ProgressBar StressBar { get; } = Bar(Color.Color8(0xd8, 0x8a, 0x2c));
|
||||
|
||||
/// <summary>A 0 to 1 bar with a visible track (dark, outlined), so an empty bar reads as empty, and a fill in <paramref name="fill"/>.</summary>
|
||||
private static ProgressBar Bar(Color fill)
|
||||
{
|
||||
var bar = new ProgressBar { MinValue = 0, MaxValue = 1, Step = 0, ShowPercentage = false, CustomMinimumSize = new Vector2(220, 18) };
|
||||
bar.AddThemeStyleboxOverride("background", new StyleBoxFlat { BgColor = Color.Color8(0x1c, 0x1c, 0x20), BorderColor = Ink, BorderWidthLeft = 1, BorderWidthTop = 1, BorderWidthRight = 1, BorderWidthBottom = 1 });
|
||||
bar.AddThemeStyleboxOverride("fill", new StyleBoxFlat { BgColor = fill });
|
||||
return bar;
|
||||
}
|
||||
/// <summary>One button per stressor of the office's cause, by id.</summary>
|
||||
public IReadOnlyDictionary<string, Button> SilenceButtons => _silence;
|
||||
public SpinBox SeedBox { get; } = new() { MinValue = 0, MaxValue = 999999999, Step = 1, Value = 1 };
|
||||
|
|
|
|||
|
|
@ -148,8 +148,8 @@ public partial class Main : Node3D
|
|||
|
||||
public override void _UnhandledInput(InputEvent e)
|
||||
{
|
||||
// The knife takes plain left presses; Alt+left is the camera's emulated middle button, and the camera never binds a plain left.
|
||||
if (Scenario == Scenario.Office && e is InputEventMouseButton { Pressed: true, ButtonIndex: MouseButton.Left, AltPressed: false } press)
|
||||
// The knife takes a left press the camera's binding table does not (Alt+left is its emulated middle button, whatever its mode).
|
||||
if (Scenario == Scenario.Office && e is InputEventMouseButton { Pressed: true, ButtonIndex: MouseButton.Left } press && !OrbitCamera.Binds(press))
|
||||
{
|
||||
CutAt(press.Position);
|
||||
GetViewport().SetInputAsHandled();
|
||||
|
|
|
|||
|
|
@ -43,6 +43,17 @@ public partial class OrbitCamera : Camera3D
|
|||
/// <summary>Alt+left-drag stands for the middle button (Blender's Emulate 3 Button Mouse).</summary>
|
||||
public bool Emulate3ButtonMouse { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether <paramref name="press"/> is one of the camera's gestures: a button and modifier combination in its binding table. The knife leaves
|
||||
/// every such press alone, in every camera mode (emulation off, a drag in progress): the camera's table is the one owner of what a press means to it.
|
||||
/// </summary>
|
||||
public static bool Binds(InputEventMouseButton press)
|
||||
{
|
||||
foreach (var row in Bindings)
|
||||
if (row.Button == press.ButtonIndex && row.Alt == press.AltPressed && row.Shift == press.ShiftPressed && row.Ctrl == press.CtrlPressed) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Where an orbit turns, read once at each orbit press; null, or a null result, means the view centre.</summary>
|
||||
public Func<Vector3?>? Pivot { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -189,6 +189,7 @@ public partial class Smoke : Node
|
|||
Click(at, alt: false);
|
||||
Check(_main.Cuts.Count == 1 && _main.Cuts[0].Part == "LowerArm L", $"a left press on LowerArm L's centre left cuts [{string.Join(", ", _main.Cuts)}]");
|
||||
Check(office.Result().Timeline.Count > 0, "no timeline after a cut");
|
||||
await CheckAltGuard(at);
|
||||
await UntilTick(600);
|
||||
|
||||
// The blood drawn is the blood the world holds: a drop per live fluid lane, a disc per live wet lane, counted from the lanes here.
|
||||
|
|
@ -200,6 +201,8 @@ public partial class Smoke : Node
|
|||
Check(_main.Blood.DropCount == liveDrops && _main.Blood.PatchCount == livePatches,
|
||||
$"blood draws {_main.Blood.DropCount} drops and {_main.Blood.PatchCount} patches; the lanes hold {liveDrops} and {livePatches}");
|
||||
|
||||
CheckBloodPlaced(view);
|
||||
|
||||
// The bars are the session's will and arousal, to the bit, once a frame has drawn them (stepping paused so the session holds still).
|
||||
// Run on until the cut has cost his will, so a bar bound to resolve instead shows a different number.
|
||||
await UntilTick(1800);
|
||||
|
|
@ -228,6 +231,47 @@ public partial class Smoke : Node
|
|||
Check(Throws(() => _ = office.TickIndex), "the office run was not disposed by the switch");
|
||||
}
|
||||
|
||||
/// <summary>Each drop is drawn at its lane's point and 2 x its radius wide; each disc at its body's pose applied to its point, lifted, and as wide as its radius (both in lane order).</summary>
|
||||
private void CheckBloodPlaced(Box3DSoaView view)
|
||||
{
|
||||
int d = 0;
|
||||
for (int i = 0; i < view.ParticleCount; i++)
|
||||
{
|
||||
if (view.ParticleLive[i] == 0 || (view.ParticlePhase[i] & Box3DSoaPhase.Fluid) == 0) continue;
|
||||
var t = _main.Blood.Drops[d++];
|
||||
Check(t.Origin == new Vector3(view.ParticleX[i], view.ParticleY[i], view.ParticleZ[i]) && Math.Abs(t.Basis.Scale.X - 2f * view.ParticleRadius[i]) < 1e-6f,
|
||||
$"drop {d - 1} is drawn at {t.Origin} size {t.Basis.Scale.X}; lane {i} is at ({view.ParticleX[i]}, {view.ParticleY[i]}, {view.ParticleZ[i]}), radius {view.ParticleRadius[i]}");
|
||||
}
|
||||
int p = 0;
|
||||
for (int i = 0; i < view.WetCount; i++)
|
||||
{
|
||||
if (view.WetLive[i] == 0) continue;
|
||||
int b = view.WetBody[i];
|
||||
if (b < 0) { p++; continue; }
|
||||
var q = new Quaternion(view.RotationX[b], view.RotationY[b], view.RotationZ[b], view.RotationW[b]);
|
||||
var want = new Vector3(view.PositionX[b], view.PositionY[b], view.PositionZ[b]) + q * new Vector3(view.WetX[i], view.WetY[i], view.WetZ[i]) + Vector3.Up * BloodRenderer.PatchLift;
|
||||
var t = _main.Blood.Patches[p++];
|
||||
Check(t.Origin.DistanceTo(want) < 1e-5f && Math.Abs(t.Basis.Scale.X - view.WetRadius[i]) < 1e-6f,
|
||||
$"patch {p - 1} is drawn at {t.Origin} radius {t.Basis.Scale.X}; lane {i} puts it at {want}, radius {view.WetRadius[i]}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The knife leaves the camera's presses alone in every mode: with emulation off, and while a middle drag is under way, an Alt+left press cuts nothing.</summary>
|
||||
private async Task CheckAltGuard(Vector2 at)
|
||||
{
|
||||
var camera = _main.GetNode<OrbitCamera>("Camera");
|
||||
int cuts = _main.Cuts.Count;
|
||||
camera.Emulate3ButtonMouse = false;
|
||||
Click(at, alt: true);
|
||||
camera.Emulate3ButtonMouse = true;
|
||||
Check(_main.Cuts.Count == cuts, "an Alt+left press cut with camera emulation off");
|
||||
GetViewport().PushInput(new InputEventMouseButton { ButtonIndex = MouseButton.Middle, Pressed = true, Position = at, GlobalPosition = at, ButtonMask = MouseButtonMask.Middle }, true);
|
||||
Click(at, alt: true);
|
||||
Check(_main.Cuts.Count == cuts, "an Alt+left press cut during a middle drag");
|
||||
GetViewport().PushInput(new InputEventMouseButton { ButtonIndex = MouseButton.Middle, Pressed = false, Position = at, GlobalPosition = at }, true);
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>A left press and release at <paramref name="at"/> (viewport coordinates), pushed through the viewport like the mouse's.</summary>
|
||||
private void Click(Vector2 at, bool alt)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue