Add controllable lab walking checkpoint with collision and chase camera
This commit is contained in:
1 parent
37fa18094f
commit
58424120bb
26 files changed
+1848
-110
No files matched your search
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="../../src/GamePort/Assets/*.cs" Link="Assets/%(Filename)%(Extension)" />
|
||||
<Compile Include="../../src/GamePort/Game/*.cs" Link="Game/%(Filename)%(Extension)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,313 @@
|
||||
using System.Numerics;
|
||||
using GamePort.Assets;
|
||||
using GamePort.Game;
|
||||
|
||||
var project = FindProject();
|
||||
var originals = args.Length == 1 ? Path.GetFullPath(args[0]) : Path.GetFullPath(Path.Combine(project, "../Original"));
|
||||
var tests = new (string Name, Action Check)[]
|
||||
{
|
||||
("60 simulation calls across 60/120/144 Hz presentation", ClockRates),
|
||||
("clock remainder, stall bound, reset and invalid intervals", ClockBoundaries),
|
||||
("turn-only speed, forward acceleration/cap and release", SpeedLimits),
|
||||
("backpedal cap and release", Backpedal),
|
||||
("yaw sign, forward half-turn and left precedence", Turning),
|
||||
("fixed-step input replay independent of presentation rate", ReplayRates),
|
||||
("jump rises, falls and returns to support", JumpLanding),
|
||||
("held zero-burn jump repeats and release stops repetition", HeldJump),
|
||||
("airborne jump re-press rearms landing without a double jump", JumpRepress),
|
||||
("air mode ignores arrow steering", AirControl),
|
||||
("reset restores spawn, camera and counters", Reset),
|
||||
("ten-minute simulation remains finite and supported", LongRun),
|
||||
("original lab placement, floor, walking and jump checkpoint", () => OriginalLab(project, originals)),
|
||||
};
|
||||
foreach (var (name, check) in tests)
|
||||
{
|
||||
check();
|
||||
Console.WriteLine($"PASS {name}");
|
||||
}
|
||||
Console.WriteLine($"Movement checks: {tests.Length} passed. Static reconstruction/port-policy regressions; no original-runtime comparison.");
|
||||
|
||||
static void ClockRates()
|
||||
{
|
||||
foreach (var rate in new[] { 60, 120, 144 })
|
||||
{
|
||||
var clock = new FixedStepClock();
|
||||
for (var second = 0; second < 20; second++)
|
||||
{
|
||||
var steps = 0;
|
||||
for (var frame = 0; frame < rate; frame++) steps += clock.Advance(1.0 / rate);
|
||||
Check(steps == 60, $"{rate} Hz second {second}: {steps} simulation calls");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ClockBoundaries()
|
||||
{
|
||||
var clock = new FixedStepClock();
|
||||
Check(clock.Advance(0) == 0, "zero elapsed interval");
|
||||
Check(clock.Advance(1.0 / 120) == 0 && clock.Advance(1.0 / 120) == 1, "fractional frame remainder retained");
|
||||
Check(clock.Advance(4) == 15, "stalled presentation advances at most a quarter second");
|
||||
clock.Advance(1.0 / 120);
|
||||
clock.Reset();
|
||||
Check(clock.Advance(1.0 / 120) == 0 && clock.Advance(1.0 / 120) == 1, "reset discards old remainder");
|
||||
foreach (var elapsed in new[] { -0.01, double.NaN, double.PositiveInfinity, double.NegativeInfinity })
|
||||
Throws<ArgumentOutOfRangeException>(() => clock.Advance(elapsed));
|
||||
}
|
||||
|
||||
static void SpeedLimits()
|
||||
{
|
||||
var turn = FlatSimulation();
|
||||
for (var i = 0; i < 40; i++) turn.Step(new(false, false, true, false, false));
|
||||
Near(turn.Speed, 0, 0, "turn-only +30 then decay35 clamps at zero");
|
||||
Check(turn.Grounded && turn.Pose == PlayerPose.Idle, "turn-only remains supported and idle");
|
||||
|
||||
var walk = FlatSimulation();
|
||||
walk.Step(new(true, false, false, false, false));
|
||||
Near(walk.Speed, 30, 0, "first forward invocation");
|
||||
for (var i = 1; i < 40; i++) walk.Step(new(true, false, false, false, false));
|
||||
Near(walk.Speed, 600, 0, "forward speed cap");
|
||||
Check(walk.Position.Z > 250 && walk.Pose == PlayerPose.Run, "forward speed produces visible travel");
|
||||
for (var i = 0; i < 20; i++) walk.Step(default);
|
||||
Near(walk.Speed, 0, 0, "release decays to zero");
|
||||
var stopped = walk.Position;
|
||||
for (var i = 0; i < 30; i++) walk.Step(default);
|
||||
NearVector(walk.Position, stopped, .001f, "released standing position remains stable");
|
||||
}
|
||||
|
||||
static void Backpedal()
|
||||
{
|
||||
var simulation = FlatSimulation();
|
||||
for (var i = 0; i < 180; i++) simulation.Step(new(false, true, false, false, false));
|
||||
Near(simulation.Speed, -300, 0, "reverse cap remains -300 without an invented turn-around timer");
|
||||
Check(simulation.Grounded && simulation.Pose == PlayerPose.Backpedal && simulation.Position.Z < -500,
|
||||
"backpedal moves opposite forward and stays supported");
|
||||
for (var i = 0; i < 20; i++) simulation.Step(default);
|
||||
Near(simulation.Speed, 0, 0, "reverse release clamps toward zero");
|
||||
}
|
||||
|
||||
static void Turning()
|
||||
{
|
||||
var left = FlatSimulation();
|
||||
var right = FlatSimulation();
|
||||
var forwardLeft = FlatSimulation();
|
||||
left.Step(new(false, false, true, false, false));
|
||||
right.Step(new(false, false, false, true, false));
|
||||
forwardLeft.Step(new(true, false, true, false, false));
|
||||
Check(left.Yaw > 0 && right.Yaw < 0, "left/right yaw signs");
|
||||
Near(left.Yaw, -right.Yaw, .00001f, "opposed keyboard yaw symmetry");
|
||||
Near(forwardLeft.Yaw, left.Yaw / 2, .00001f, "Up halves target turn offset");
|
||||
Near(forwardLeft.Speed, 60, 0, "Up plus turn performs both speed increments");
|
||||
Check(left.Position.X < 0 && right.Position.X > 0, "keyboard side-velocity signs");
|
||||
|
||||
var both = FlatSimulation();
|
||||
var leftOnly = FlatSimulation();
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
both.Step(new(true, false, true, true, false));
|
||||
leftOnly.Step(new(true, false, true, false, false));
|
||||
}
|
||||
SameState(both, leftOnly, "Left has precedence when Left and Right are held together");
|
||||
}
|
||||
|
||||
static void ReplayRates()
|
||||
{
|
||||
LabSimulation? reference = null;
|
||||
foreach (var rate in new[] { 60, 120, 144 })
|
||||
{
|
||||
var simulation = FlatSimulation();
|
||||
var clock = new FixedStepClock();
|
||||
for (var frame = 0; frame < rate * 4; frame++)
|
||||
{
|
||||
var steps = clock.Advance(1.0 / rate);
|
||||
for (var step = 0; step < steps; step++) simulation.Step(LabSimulation.SmokeInput(simulation.Steps));
|
||||
}
|
||||
Check(simulation.Steps == 240, $"{rate} Hz replay duration");
|
||||
Check(simulation.SmokePassed, $"{rate} Hz replay walks, jumps and lands: {simulation.Report}");
|
||||
if (reference is not null) SameState(simulation, reference, $"{rate} Hz replay");
|
||||
reference = simulation;
|
||||
}
|
||||
}
|
||||
|
||||
static void JumpLanding()
|
||||
{
|
||||
var simulation = FlatSimulation();
|
||||
var floor = simulation.Position.Y;
|
||||
simulation.Step(new(false, false, false, false, true));
|
||||
Check(!simulation.Grounded && simulation.Velocity.Y > 500 && simulation.Jumps == 1 && simulation.Pose == PlayerPose.Jump,
|
||||
"jump takes off with one queued impulse");
|
||||
var sawFall = false;
|
||||
var largestHeight = simulation.Position.Y;
|
||||
for (var i = 0; i < 120; i++)
|
||||
{
|
||||
simulation.Step(default);
|
||||
largestHeight = Math.Max(largestHeight, simulation.Position.Y);
|
||||
sawFall |= simulation.Pose == PlayerPose.Fall;
|
||||
}
|
||||
Check(sawFall && largestHeight - floor > 100, "jump rises and enters descending phase");
|
||||
Check(simulation.Grounded && simulation.Jumps == 1 && simulation.Landings == 1, "released jump lands once");
|
||||
Near(simulation.Position.Y, floor, .01f, "landing returns feet to supporting floor");
|
||||
Near(simulation.Velocity.Y, 0, 0, "landing clears downward velocity");
|
||||
}
|
||||
|
||||
static void HeldJump()
|
||||
{
|
||||
var simulation = FlatSimulation();
|
||||
for (var i = 0; i < 300; i++) simulation.Step(new(false, false, false, false, true));
|
||||
Check(simulation.Jumps >= 3 && simulation.Landings >= 2,
|
||||
$"zero-burn long hold rearms and repeats after landing: {simulation.Report}");
|
||||
var jumpCount = simulation.Jumps;
|
||||
for (var i = 0; i < 150; i++) simulation.Step(default);
|
||||
Check(simulation.Jumps == jumpCount && simulation.Grounded, "release stops held repetition and lands");
|
||||
simulation.Step(new(false, false, false, false, true));
|
||||
Check(simulation.Jumps == jumpCount + 1 && !simulation.Grounded, "new grounded press starts another jump");
|
||||
}
|
||||
|
||||
static void AirControl()
|
||||
{
|
||||
var idleInput = FlatSimulation();
|
||||
var arrowInput = FlatSimulation();
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
idleInput.Step(new(true, false, false, false, false));
|
||||
arrowInput.Step(new(true, false, false, false, false));
|
||||
}
|
||||
idleInput.Step(new(true, false, false, false, true));
|
||||
arrowInput.Step(new(true, false, false, false, true));
|
||||
for (var i = 0; i < 24; i++)
|
||||
{
|
||||
Check(!idleInput.Grounded && !arrowInput.Grounded, "comparison remains airborne");
|
||||
idleInput.Step(default);
|
||||
arrowInput.Step(new(true, true, true, true, false));
|
||||
SameState(arrowInput, idleInput, "ordinary arrows ignored while airborne");
|
||||
}
|
||||
Near(arrowInput.Speed, 600, 0, "takeoff speed retained in air");
|
||||
}
|
||||
|
||||
static void JumpRepress()
|
||||
{
|
||||
var simulation = FlatSimulation();
|
||||
simulation.Step(new(false, false, false, false, true));
|
||||
for (var i = 0; i < 5; i++) simulation.Step(default);
|
||||
Check(!simulation.Grounded && simulation.Jumps == 1, "released first jump remains airborne");
|
||||
var velocityBeforeRepress = simulation.Velocity.Y;
|
||||
simulation.Step(new(false, false, false, false, true));
|
||||
Check(simulation.Jumps == 1 && simulation.Velocity.Y < velocityBeforeRepress,
|
||||
"re-press cannot consume a second impulse while airborne");
|
||||
for (var i = 0; i < 120; i++) simulation.Step(new(false, false, false, false, true));
|
||||
Check(simulation.Jumps >= 2 && simulation.Landings >= 1,
|
||||
$"released-then-held jump rearms for the next landing: {simulation.Report}");
|
||||
var jumps = simulation.Jumps;
|
||||
for (var i = 0; i < 150; i++) simulation.Step(default);
|
||||
Check(simulation.Jumps == jumps && simulation.Grounded, "release after re-press repeat settles without more jumps");
|
||||
}
|
||||
|
||||
static void Reset()
|
||||
{
|
||||
var simulation = FlatSimulation(155);
|
||||
var fresh = FlatSimulation(155);
|
||||
for (var i = 0; i < 240; i++) simulation.Step(LabSimulation.SmokeInput(i));
|
||||
Check(simulation.Travel > 100 && simulation.Jumps > 0, "reset fixture has nontrivial history");
|
||||
simulation.Reset();
|
||||
SameState(simulation, fresh, "reset restores a fresh spawn");
|
||||
Check(simulation.Steps == 0 && simulation.Jumps == 0 && simulation.Landings == 0 && simulation.WallHits == 0
|
||||
&& simulation.Travel == 0 && simulation.MaximumRise == 0, "reset clears telemetry counters");
|
||||
for (var i = 0; i < 90; i++)
|
||||
{
|
||||
var input = new PlayerInput(i < 60, false, i >= 30, false, i >= 20 && i < 50);
|
||||
simulation.Step(input);
|
||||
fresh.Step(input);
|
||||
}
|
||||
SameState(simulation, fresh, "reset also clears hidden jump/turn/hold state");
|
||||
}
|
||||
|
||||
static void LongRun()
|
||||
{
|
||||
var simulation = FlatSimulation();
|
||||
for (var i = 0; i < 36000; i++)
|
||||
{
|
||||
var phase = i % 600;
|
||||
simulation.Step(new(phase < 400, phase >= 500, phase is >= 200 and < 400, false, phase is >= 80 and < 180));
|
||||
Check(Finite(simulation.Position) && Finite(simulation.Velocity) && Finite(simulation.CameraEye)
|
||||
&& Finite(simulation.CameraTarget) && float.IsFinite(simulation.Yaw) && float.IsFinite(simulation.Speed),
|
||||
$"simulation remains finite at step {i}");
|
||||
Check(simulation.Position.Y >= SceneCollision.Skin - .01f, $"no floor penetration at step {i}");
|
||||
}
|
||||
Check(simulation.Steps == 36000 && simulation.Jumps > 50 && simulation.Landings > 50, "sustained repeated movement/jump coverage");
|
||||
for (var i = 0; i < 120; i++) simulation.Step(default);
|
||||
Check(simulation.Grounded, "long run settles to support");
|
||||
}
|
||||
|
||||
static void OriginalLab(string project, string originals)
|
||||
{
|
||||
var sceneFile = Path.Combine(project, "artifacts/extracted/level1b/scene.json");
|
||||
Check(File.Exists(sceneFile), "prepared original lab required (run tools/extractors/prepare.py)");
|
||||
var mesh = Mesh.LoadSceneJson(sceneFile);
|
||||
var standing = AseMesh.Load(AssetPath.Resolve(originals, "ase/JIMSTOP.ASE"));
|
||||
var level = GamLevel.Load(AssetPath.Resolve(originals, "gam/level1b.gam"));
|
||||
var start = level.FindStart() ?? throw new Exception("Missing LV1B GAM startpoint");
|
||||
var collision = new SceneCollision(mesh);
|
||||
Near(collision.GroundHeight(start.Position, 2500)!.Value, .5486332f, .001f, "original floor below GAM placement");
|
||||
var simulation = new LabSimulation(collision, standing, start.Position, start.Rotation.Y);
|
||||
Near(simulation.Position.X, 5071.933105f, .001f, "GAM X retained");
|
||||
Near(simulation.Position.Z, 824.103943f, .001f, "GAM Z retained");
|
||||
Near(simulation.Position.Y, .5486332f + SceneCollision.Skin, .001f, "spawn feet on original floor");
|
||||
Near(simulation.Yaw, 155, .001f, "GAM yaw retained");
|
||||
Near(simulation.BodyHeight, 209.4361f, .01f, "capsule height from original standing bounds");
|
||||
var sole = standing.Vertices.Min(vertex => Vector3.Transform(vertex.Position, simulation.Model).Y);
|
||||
Near(sole, simulation.Position.Y, .001f, "rendered standing sole agrees with simulation feet");
|
||||
for (var i = 0; i < 240; i++) simulation.Step(LabSimulation.SmokeInput(i));
|
||||
Check(simulation.SmokePassed, $"original lab checkpoint: {simulation.Report}");
|
||||
Check(Finite(simulation.Position) && Finite(simulation.CameraEye), "original scene simulation/camera finite");
|
||||
Console.WriteLine($" {simulation.Report}");
|
||||
|
||||
simulation.Reset();
|
||||
simulation.Step(new(false, false, false, false, true));
|
||||
for (var i = 0; i < 120; i++) simulation.Step(default);
|
||||
Check(simulation.Jumps == 1 && simulation.Landings == 1 && simulation.Grounded, "stationary original-lab jump lands once");
|
||||
Near(simulation.Position.Y, .5486332f + SceneCollision.Skin, .03f, "original lab jump returns to floor");
|
||||
}
|
||||
|
||||
static LabSimulation FlatSimulation(float yaw = 0)
|
||||
{
|
||||
var positions = new[]
|
||||
{
|
||||
new Vector3(-100000, 0, -100000), new Vector3(-100000, 0, 100000), new Vector3(100000, 0, 100000),
|
||||
new Vector3(-100000, 0, -100000), new Vector3(100000, 0, 100000), new Vector3(100000, 0, -100000),
|
||||
};
|
||||
var floor = new Mesh(positions.Select(p => new MeshVertex(p, Vector2.Zero, Vector3.One)).ToArray(), [0, 1, 2, 3, 4, 5]);
|
||||
var standing = new Mesh([new(new(-20, -20, -20), Vector2.Zero, Vector3.One),
|
||||
new(new(20, 80, 20), Vector2.Zero, Vector3.One)], []);
|
||||
return new LabSimulation(new SceneCollision(floor), standing, new Vector3(0, 25, 0), yaw);
|
||||
}
|
||||
|
||||
static void SameState(LabSimulation actual, LabSimulation expected, string message)
|
||||
{
|
||||
NearVector(actual.Position, expected.Position, .0001f, $"{message}: position");
|
||||
NearVector(actual.Velocity, expected.Velocity, .0001f, $"{message}: velocity");
|
||||
NearVector(actual.CameraEye, expected.CameraEye, .0001f, $"{message}: camera");
|
||||
Near(actual.Yaw, expected.Yaw, .0001f, $"{message}: yaw");
|
||||
Near(actual.Speed, expected.Speed, 0, $"{message}: speed");
|
||||
Check(actual.Grounded == expected.Grounded && actual.Pose == expected.Pose && actual.Jumps == expected.Jumps
|
||||
&& actual.Landings == expected.Landings, $"{message}: movement state/counters");
|
||||
}
|
||||
static string FindProject()
|
||||
{
|
||||
var directory = new DirectoryInfo(Environment.CurrentDirectory);
|
||||
while (directory is not null)
|
||||
{
|
||||
if (File.Exists(Path.Combine(directory.FullName, "GamePort.slnx"))) return directory.FullName;
|
||||
directory = directory.Parent;
|
||||
}
|
||||
throw new InvalidOperationException("Run from within GamePort");
|
||||
}
|
||||
static bool Finite(Vector3 value) => float.IsFinite(value.X) && float.IsFinite(value.Y) && float.IsFinite(value.Z);
|
||||
static void Check(bool condition, string message) { if (!condition) throw new Exception(message); }
|
||||
static void Near(float actual, float expected, float tolerance, string message) =>
|
||||
Check(MathF.Abs(actual - expected) <= tolerance, $"{message}: actual={actual}, expected={expected}, tolerance={tolerance}");
|
||||
static void NearVector(Vector3 actual, Vector3 expected, float tolerance, string message) =>
|
||||
Check(Vector3.Distance(actual, expected) <= tolerance, $"{message}: actual={actual}, expected={expected}, tolerance={tolerance}");
|
||||
static void Throws<T>(Action check) where T : Exception
|
||||
{
|
||||
try { check(); } catch (T) { return; }
|
||||
throw new Exception($"Expected {typeof(T).Name}");
|
||||
}
|
||||
Reference in new issue
Block a user