Implement Bubble controller, sprite and VR01 body behavior

This commit is contained in:
UnixNight committed 2026-11-02 16:57:54 -05:00
1 parent 9ea578492d
commit 1ae5f4251c
51 files changed
+2811 -54

No files matched your search

+152
View File
@@ -0,0 +1,152 @@
using System.Numerics;
using GamePort.Game;
var tests = new (string Name, Action Check)[]
{
("mode2 fire throttles without forward arrows and caps at current maximum", FireThrottle),
("turn limit 50, left precedence, release and pose priorities", TurnAndPose),
("supported input reduction precedes brake and permits negative crossing", SupportInput),
("coast threshold and air brake retain source ordering", CoastAndBrake),
("supported XZ 112.5 halves only later published scalar to 56.25", PublishedScalarOrder),
("held bounce 900 and repeat sound versus released 300 without sound", BounceBranches),
("unsupported apply retains vertical velocity and scalar", Unsupported),
("zero incoming velocity suppresses yaw and side, including nonzero scalar", Stationary),
("quantized pitch cosine scales only horizontal forward velocity", QuantizedPitch),
("nonzero incoming velocity turns and adds source lateral term", Lateral),
("finite input and bounded timestep validation", InvalidInputs),
};
foreach (var (name, check) in tests)
{
check();
Console.WriteLine($"PASS {name}");
}
Console.WriteLine($"Bubble motion checks: {tests.Length} passed. Source arithmetic/port regressions; no original gameplay execution.");
static PlayerInput Input(bool forward = false, bool backward = false, bool left = false,
bool right = false, bool fire = false) => new(forward, backward, left, right, false, Fire: fire);
static void FireThrottle()
{
var fire = BubbleMotion.StepInput(0, 0, Input(fire: true), false, .1f);
Check(fire == BubbleMotion.StepInput(0, 0, Input(forward: true), false, .1f), "fire matches forward");
Near(fire.Speed, 30, 0, "source per-call increment");
Near(fire.TargetPitch, -10, 0, "forward target pitch");
Near(BubbleMotion.StepInput(1340, 0, Input(fire: true), false, .1f).Speed, 1350, 0, "Bubble cap");
Near(BubbleMotion.StepInput(640, 0, Input(forward: true), false, .1f, 650).Speed, 650, 0, "caller maximum");
}
static void TurnAndPose()
{
var both = BubbleMotion.StepInput(100, 49, Input(left: true, right: true), false, .5f);
Near(both.TurnRate, 50, 0, "left precedence and positive cap");
Near(both.TargetRoll, -12.5f, 0, "source lean sign");
Near(BubbleMotion.StepInput(100, -49, Input(right: true), false, .5f).TurnRate, -50, 0, "negative cap");
Near(BubbleMotion.StepInput(100, -20, Input(), false, .5f).TurnRate, 0, 0, "release crosses zero");
var throttleBrake = BubbleMotion.StepInput(100, 10, Input(forward: true, backward: true, left: true), false, .1f);
Near(throttleBrake.Speed, 112.5f, 0, "forward before backward");
Near(throttleBrake.TargetPitch, -10, 0, "throttle pitch wins");
Near(throttleBrake.TargetRoll, -5, 0, "updated turn drives lean");
Near(BubbleMotion.StepInput(100, 0, Input(backward: true), false, .1f).TargetPitch, 10, 0, "brake pitch");
Near(BubbleMotion.StepInput(100, 0, Input(), false, .1f).TargetPitch, 0, 0, "coast pitch");
}
static void SupportInput()
{
Near(BubbleMotion.StepInput(100, 0, Input(), true, .1f).Speed, 82.5f, 0, "supported coast");
Near(BubbleMotion.StepInput(100, 0, Input(backward: true), true, .1f).Speed, 47.5f, 0, "support decay then full brake");
var crossed = BubbleMotion.StepInput(5, 0, Input(), true, .1f).Speed;
Near(crossed, -12.5f, 0, "unclamped source crossing");
Near(BubbleMotion.StepInput(crossed, 0, Input(), true, .1f).Speed, 0, 0, "following supported input clears negative");
}
static void CoastAndBrake()
{
Near(BubbleMotion.StepInput(1350, 0, Input(), false, .1f).Speed, 1332.5f, 0, "high coast decay");
Near(BubbleMotion.StepInput(1200, 0, Input(), false, .1f).Speed, 1200, 0, "below coast threshold");
Near(BubbleMotion.StepInput(5, 0, Input(backward: true), false, .1f).Speed, 0, 0, "positive brake clamps");
Near(BubbleMotion.StepInput(-5, 0, Input(backward: true), false, .1f).Speed, 0, 0, "negative brake clamps");
}
static void PublishedScalarOrder()
{
var steering = BubbleMotion.StepInput(100, 0, Input(forward: true), true, .1f);
Near(steering.Speed, 112.5f, 0, "supported input scalar");
var applied = BubbleMotion.StepApply(steering.Speed, steering.TurnRate, 0, 0, Vector3.UnitZ, true, false, .1f);
Near(applied.Velocity.Z, 112.5f, 0, "XZ composed before bounce decay");
Near(applied.Speed, 56.25f, 0, "only later published scalar halves");
Near(applied.Velocity.Y, 300, 0, "automatic released bounce");
}
static void BounceBranches()
{
var held = BubbleMotion.StepApply(100, 0, 0, 0, new(0, -800, 10), true, true, .1f);
Check(held.Velocity == new Vector3(0, 900, 100) && held.Boing, "direct held velocity and sound");
Near(held.Speed, 100, 0, "held bounce retains scalar");
Check(BubbleMotion.StepApply(100, 0, 0, 0, held.Velocity, true, true, .1f).Boing, "no invented edge latch");
var released = BubbleMotion.StepApply(100, 0, 0, 0, new(0, -800, 10), true, false, .1f);
Check(released.Velocity == new Vector3(0, 300, 100) && !released.Boing, "released velocity without boing");
Near(released.Speed, 50, 0, "released scalar");
}
static void Unsupported()
{
var applied = BubbleMotion.StepApply(100, 0, 0, 0, new(0, -99, 10), false, true, .1f);
Near(applied.Velocity.Y, -99, 0, "unsupported liveY retained");
Near(applied.Speed, 100, 0, "unsupported scalar retained");
Check(!applied.Boing, "unsupported jump produces no sound");
}
static void Stationary()
{
var applied = BubbleMotion.StepApply(100, 50, 0, 0, Vector3.Zero, false, false, .1f);
Near(applied.Yaw, 0, 0, "zero incoming velocity skips direct yaw");
Check(applied.Velocity == new Vector3(0, 0, 100), "forward still starts, side remains zero");
}
static void QuantizedPitch()
{
const float pitch = 17.123f;
var expected = LabSimulation.Trig(pitch).Cos * 100;
var applied = BubbleMotion.StepApply(100, 0, 0, pitch, new(0, -12, 1), false, false, .1f);
Near(applied.Velocity.Z, expected, 0, "same quantized cosine helper");
Near(applied.Velocity.Y, -12, 0, "transformed forwardY deliberately unused");
Check(applied.Velocity.Z != MathF.Cos(pitch * MathF.PI / 180) * 100, "continuous cosine would differ");
}
static void Lateral()
{
var applied = BubbleMotion.StepApply(100, 50, 0, 0, Vector3.UnitY, false, false, .1f);
Near(applied.Yaw, 5, 0, "direct yaw from nonzero incomingY");
var (sin, cos) = LabSimulation.Trig(5);
var side = 50 * .0181818176060915f * (1 - .8f) * 100;
Near(applied.Velocity.X, -sin * 100 + cos * side, 0, "yaw-only lateralX");
Near(applied.Velocity.Z, cos * 100 + sin * side, 0, "yaw-only lateralZ");
}
static void InvalidInputs()
{
foreach (var seconds in new[] { -1f, 1f, float.NaN, float.PositiveInfinity })
{
Throws(() => BubbleMotion.StepInput(0, 0, Input(), false, seconds));
Throws(() => BubbleMotion.StepApply(0, 0, 0, 0, Vector3.Zero, false, false, seconds));
}
Throws(() => BubbleMotion.StepInput(float.NaN, 0, Input(), false, .1f));
Throws(() => BubbleMotion.StepInput(0, 0, Input(), false, .1f, 0));
Throws(() => BubbleMotion.StepApply(0, 0, 0, 0, new(float.NaN, 0, 0), false, false, .1f));
}
static void Check(bool condition, string message)
{
if (!condition) throw new InvalidOperationException(message);
}
static void Near(float actual, float expected, float tolerance, string message) =>
Check(float.IsFinite(actual) && MathF.Abs(actual - expected) <= tolerance,
$"{message}: expected {expected}, got {actual}");
static void Throws(Action action)
{
try { action(); }
catch (ArgumentOutOfRangeException) { return; }
throw new InvalidOperationException("Expected bounded-input rejection");
}