Apply recovered player phases, static camera query and level availability
This commit is contained in:
1 parent
117db77c7b
commit
09cf1172bf
33 files changed
+1500
-99
No files matched your search
@@ -8,6 +8,8 @@ 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),
|
||||
("physics consumes prior motion; fresh versus retained input order", FrameOrdering),
|
||||
("source camera query origin, hit adjustment, gain and one query per input", CameraQueryConsumer),
|
||||
("turn-only speed, forward acceleration/cap and release", SpeedLimits),
|
||||
("backpedal cap and release", Backpedal),
|
||||
("yaw sign, forward half-turn and left precedence", Turning),
|
||||
@@ -59,6 +61,69 @@ static void ClockBoundaries()
|
||||
Throws<ArgumentOutOfRangeException>(() => clock.Advance(elapsed));
|
||||
}
|
||||
|
||||
static void FrameOrdering()
|
||||
{
|
||||
var fresh = FlatSimulation();
|
||||
var origin = fresh.Position;
|
||||
var forward = new PlayerInput(true, false, false, false, false);
|
||||
fresh.Step(forward);
|
||||
NearVector(fresh.Position, origin, .0001f, "input cannot move an already integrated body");
|
||||
Near(fresh.Speed, 30, 0, "fresh input runs before player callback");
|
||||
Near(fresh.Velocity.Z, 30, 0, "player produces velocity for the next physics pass");
|
||||
fresh.Step(forward);
|
||||
Near(fresh.Position.Z - origin.Z, 30 * FixedStepClock.Step, .0001f, "next physics consumes previous30, not current60");
|
||||
|
||||
var retained = FlatSimulation();
|
||||
retained.InputAfterPlayerUpdate = true;
|
||||
retained.Step(forward);
|
||||
Near(retained.Speed, 30, 0, "new level game updates retained player's input later");
|
||||
Near(retained.Velocity.Z, 0, 0, "retained player callback preceded first destination input");
|
||||
retained.Step(forward);
|
||||
NearVector(retained.Position, origin, .0001f, "second retained physics still sees old zero velocity");
|
||||
Near(retained.Velocity.Z, 30, 0, "retained player now produces prior input speed");
|
||||
retained.Step(forward);
|
||||
Near(retained.Position.Z - origin.Z, 30 * FixedStepClock.Step, .0001f, "retained third physics consumes first input");
|
||||
|
||||
var jump = FlatSimulation();
|
||||
jump.Step(new(false, false, false, false, true));
|
||||
NearVector(jump.Position, origin, .0001f, "queued jump cannot retroactively change physics");
|
||||
Near(jump.PendingImpulse.Y, 550, 0, "jump impulse remains pending until next body pass");
|
||||
Check(jump.Grounded && jump.Pose == PlayerPose.Jump, "jump animation request does not change physical support");
|
||||
jump.Step(default);
|
||||
Near(jump.PendingImpulse.Y, 0, 0, "next body pass consumes queued impulse exactly once");
|
||||
Near(jump.Velocity.Y, 550 - 800 * 1.33f * FixedStepClock.Step, .0001f,
|
||||
"next body pass applies one impulse plus the retained provisional gravity adapter");
|
||||
Check(!jump.Grounded && jump.Position.Y > origin.Y, "queued jump takes off on following body pass");
|
||||
jump.Step(default);
|
||||
Check(jump.Velocity.Y < 550 && jump.Velocity.Y > 500, "later body pass adds acceleration without repeating impulse");
|
||||
jump.Reset();
|
||||
NearVector(jump.PendingImpulse, Vector3.Zero, 0, "reset clears pending physical work");
|
||||
Check(jump.MovementMode == 0, "reset restores stored walking input mode");
|
||||
}
|
||||
|
||||
static void CameraQueryConsumer()
|
||||
{
|
||||
var enabled = false;
|
||||
var queries = 0;
|
||||
var lastLook = Vector3.Zero;
|
||||
var lastDesired = Vector3.Zero;
|
||||
SupportHit? Query(Vector3 look, Vector3 desired)
|
||||
{
|
||||
queries++; lastLook = look; lastDesired = desired;
|
||||
return enabled ? new SupportHit((look + desired) / 2, 7, 9, 0) : null;
|
||||
}
|
||||
var simulation = FlatSimulation(cameraRay: Query);
|
||||
var before = simulation.CameraEye;
|
||||
var beforeQueries = queries;
|
||||
enabled = true;
|
||||
simulation.Step(default);
|
||||
NearVector(lastLook, simulation.CameraTarget, .0001f, "ray origin is look target rather than actor root");
|
||||
var adjusted = lastLook + (lastDesired - lastLook) * .375f;
|
||||
var expected = before + (adjusted - before) * new Vector3(1.6f, 1.2f, 1.6f) * 1.5f * FixedStepClock.Step;
|
||||
NearVector(simulation.CameraEye, expected, .0001f, "source hit weighting and follow gain feed interpolation");
|
||||
Check(queries == beforeQueries + 1, "no additional camera obstruction query after interpolation");
|
||||
}
|
||||
|
||||
static void SpeedLimits()
|
||||
{
|
||||
var turn = FlatSimulation();
|
||||
@@ -102,7 +167,8 @@ static void Turning()
|
||||
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");
|
||||
Check(left.Velocity.X < 0 && right.Velocity.X > 0, "keyboard side-velocity signs for next physics pass");
|
||||
Near(left.Position.X, 0, .0001f, "turn input waits for subsequent physics");
|
||||
|
||||
var both = FlatSimulation();
|
||||
var leftOnly = FlatSimulation();
|
||||
@@ -138,8 +204,8 @@ 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");
|
||||
Check(simulation.Grounded && simulation.PendingImpulse.Y == 550 && simulation.Jumps == 1 && simulation.Pose == PlayerPose.Jump,
|
||||
"jump queues once after physics and requests its animation");
|
||||
var sawFall = false;
|
||||
var largestHeight = simulation.Position.Y;
|
||||
for (var i = 0; i < 120; i++)
|
||||
@@ -164,7 +230,7 @@ static void HeldJump()
|
||||
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");
|
||||
Check(simulation.Jumps == jumpCount + 1 && simulation.PendingImpulse.Y == 550, "new grounded press queues another jump");
|
||||
}
|
||||
|
||||
static void AirArithmetic()
|
||||
@@ -196,6 +262,7 @@ static void AirControl()
|
||||
{
|
||||
var simulation = FlatSimulation();
|
||||
simulation.Step(new(false, false, false, false, true));
|
||||
simulation.Step(default); // Consume the queued takeoff before airborne input.
|
||||
var origin = simulation.Position;
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
@@ -262,10 +329,14 @@ static void LandingTurn()
|
||||
{
|
||||
var simulation = FlatSimulation();
|
||||
simulation.Step(new(true, false, false, false, true));
|
||||
for (var i = 0; i < 120 && !simulation.Grounded; i++)
|
||||
var largestAirTurn = 0f;
|
||||
for (var i = 0; i < 120 && (i == 0 || !simulation.Grounded); i++)
|
||||
{
|
||||
simulation.Step(new(true, false, initialLeft, !initialLeft, false));
|
||||
Check(simulation.Grounded && MathF.Abs(simulation.TurnRate) > 20,
|
||||
"Landing fixture retains an opposing air turn before outer grounded reset");
|
||||
largestAirTurn = MathF.Max(largestAirTurn, MathF.Abs(simulation.TurnRate));
|
||||
}
|
||||
Check(simulation.Grounded && largestAirTurn > 20 && simulation.TurnRate == 0,
|
||||
"Physics landing precedes the same-frame player update clearing air turn");
|
||||
var before = simulation.Yaw;
|
||||
simulation.Step(new(true, false, !initialLeft, initialLeft, false));
|
||||
Near(simulation.TurnRate, 0, 0, "grounded released-jump reset clears shared air-turn field");
|
||||
@@ -376,7 +447,7 @@ static void OriginalLab(string project, string originals)
|
||||
Near(simulation.Position.Y, .5486332f + SceneCollision.Skin, .03f, "original lab jump returns to floor");
|
||||
}
|
||||
|
||||
static LabSimulation FlatSimulation(float yaw = 0)
|
||||
static LabSimulation FlatSimulation(float yaw = 0, Func<Vector3, Vector3, SupportHit?>? cameraRay = null)
|
||||
{
|
||||
var positions = new[]
|
||||
{
|
||||
@@ -386,7 +457,7 @@ static LabSimulation FlatSimulation(float yaw = 0)
|
||||
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);
|
||||
return new LabSimulation(new SceneCollision(floor), standing, new Vector3(0, 25, 0), yaw, cameraRay);
|
||||
}
|
||||
|
||||
static void SameState(LabSimulation actual, LabSimulation expected, string message)
|
||||
|
||||
Reference in new issue
Block a user