Restore original airborne steering for jumps and jetpack bursts

This commit is contained in:
UnixNight committed 2026-10-24 20:57:39 -04:00
1 parent b58138d7ba
commit 976e677019
16 files changed
+357 -54

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
namespace GamePort.Game;
public readonly record struct AirSteeringResult(float Speed, float TurnRate);
/// <summary>Keyboard subset of normal airborne input439900 (mode1).
/// Modes1/2 share the handler; special flight mode2 and mouse/analog are separate.
/// </summary>
public static class AirSteering
{
public const float TurnAcceleration = 100; //48D96C, applied with dt.
public const float TurnLimit = 30; //439D81..439DB7, ordinary mode1.
public const float CoastThreshold = 0.9090909361839294f; //49D5DC.
public static AirSteeringResult Step(float speed, float turnRate, PlayerInput input, float seconds)
{
if (!float.IsFinite(speed) || !float.IsFinite(turnRate) || !float.IsFinite(seconds) || seconds < 0 || seconds >= 1)
throw new ArgumentOutOfRangeException(nameof(seconds));
var turnStep = TurnAcceleration * seconds;
if (input.Left) turnRate += turnStep;
else if (input.Right) turnRate -= turnStep;
else if (turnRate < 0) turnRate = MathF.Min(0, turnRate + turnStep);
else if (turnRate > 0) turnRate = MathF.Max(0, turnRate - turnStep);
turnRate = Math.Clamp(turnRate, -TurnLimit, TurnLimit);
if (input.Forward) speed = RecoveredMotion.AddSpeed(speed);
else if (speed > RecoveredMotion.MaximumSpeed * CoastThreshold)
speed -= RecoveredMotion.SpeedDecay * .5f;
//439C1D..439CB2 brakes to0, without starting reverse flight.
if (input.Backward)
{
if (speed > 0) speed = MathF.Max(0, speed - RecoveredMotion.SpeedDecay * .5f);
else if (speed < 0) speed = MathF.Min(0, speed + RecoveredMotion.SpeedDecay);
}
return new(speed, turnRate);
}
}
+21 -3
View File
@@ -7,7 +7,7 @@ public readonly record struct PlayerInput(bool Forward, bool Backward, bool Left
public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall, Fly }
/// <summary>
/// No-gadget walking checkpoint. Recovered input/arithmetic is described in
/// Walking, airborne steering and jetpack checkpoint. Recovered arithmetic is described in
/// movement-checkpoint.md. Capsule, floor-derived pivot and 60Hz are port policies;
/// original collision, intro, object interactions and animation timing remain open.
/// </summary>
@@ -33,6 +33,7 @@ public sealed class LabSimulation
public Vector3 Velocity { get; private set; }
public float Yaw { get; private set; }
public float Speed { get; private set; }
public float TurnRate { get; private set; }
public bool Grounded { get; private set; }
public PlayerPose Pose => Grounded ? Speed < -1 ? PlayerPose.Backpedal : Speed > 1 ? PlayerPose.Run : PlayerPose.Idle
: jumpState.JumpState == 3 && jumpState.EffectRemaining > 0 ? PlayerPose.Fly
@@ -74,7 +75,7 @@ public sealed class LabSimulation
Position = new(sourceStart.X, floor + SceneCollision.Skin, sourceStart.Z);
Velocity = Vector3.Zero;
Yaw = targetYaw = startYaw;
Speed = extraAirAcceleration = shadowDistance = 0;
Speed = TurnRate = extraAirAcceleration = shadowDistance = 0;
jumpState = default;
forceFall = JetpackEffectVisible = false;
InteractionRadius = 60; Bursts = 0;
@@ -109,11 +110,25 @@ public sealed class LabSimulation
if (input.Backward) Speed = MathF.Max(Speed - 52.5f, -300);
else if (!input.Forward) Speed = RecoveredMotion.ReleaseSpeed(Speed);
}
else
{
var steering = AirSteering.Step(Speed, TurnRate, input, dt);
Speed = steering.Speed; TurnRate = steering.TurnRate;
//439E2B preserves current yaw as the destination; air apply then
//438011..43802B adds the independent turn rate directly to yaw.
targetYaw = Yaw;
}
var yawError = MathF.IEEERemainder(targetYaw - Yaw, 360);
Yaw = (Yaw + yawError * dt * 3.7f) % 360;
if (Velocity.LengthSquared() != 0 || Grounded && lateral != 0)
Yaw = (Yaw + TurnRate * dt) % 360;
var (sin, cos) = Trig(Yaw);
var velocity = new Vector3(-sin * Speed, Velocity.Y, cos * Speed);
if (Grounded) velocity += new Vector3(cos, 0, sin) * (lateral * dt);
//437CDx ground uses /45 then dt;43803B air uses /55 without dt.
const float friction = .8f;
var sideSpeed = Grounded ? (TurnRate * (1 - friction) * Speed / 45 + lateral) * dt
: TurnRate * (1 - friction) * Speed * .0181818176060915f;
velocity += new Vector3(cos, 0, sin) * sideSpeed;
if (collision.GroundHeight(ActorRoot, 2500) is { } shadowFloor)
shadowDistance = MathF.Abs(ActorRoot.Y - shadowFloor - 13);
var air = JetpackBurst.Step(jumpState, new(Grounded, input.Jump, velocity.Y, shadowDistance,
@@ -170,6 +185,9 @@ public sealed class LabSimulation
public static PlayerInput SmokeInput(int step) => new(step < 120, false, false,
step >= 120 && step < 180, step >= 72 && step < 84);
public static PlayerInput JetpackSmokeInput(int step) => new(step is >= 45 and < 80,
step is >= 80 and < 120, step is >= 60 and < 95, false, step < 180);
public bool SmokePassed => Steps >= 240 && Travel > 50 && MaximumRise > 20 && Jumps > 0 && Landings > 0 && Grounded;
public string Report => $"Walk checkpoint: steps={Steps}, travel={Travel:F2}, jumps={Jumps}, landings={Landings}, max rise={MaximumRise:F2}, wall hits={WallHits}, grounded={Grounded}, feet={Position}.";
}
+27 -11
View File
@@ -76,7 +76,7 @@ internal static class Program
--smoke-practice-prompt Headless original jet pack practice prompt
--smoke-practice-transition Headless lab-to-VR04 practice transition
--smoke-practice-window SDL practice pause/dismiss/resize check (12 frames)
--smoke-jetpack Headless 300-step powered-jump/release check in VR04
--smoke-jetpack 300-step powered steering/jump check in VR04
--verify-assets Decode all original PNG/ASE files
--smoke-window Test keyboard event/resize (requires --frames 6 or more)
--no-validation Disable development validation
@@ -325,8 +325,8 @@ internal static class Program
if (!double.IsFinite(storyTime) || storyTime < 0 || storyTime > 3600 || storyTime > 0 && !headless)
throw new ArgumentException("Story time must be0..3600 seconds in headless mode.");
var frames = int.Parse(Option(args, "--frames") ?? (walkSmoke ? "240" : jetpackSmoke ? "300" : headless ? "1" : "0"));
if (jetpackSmoke && (!headless || level?.Code != "VR04" || frames < 300))
throw new ArgumentException("Jetpack smoke requires headless VR04 and at least300 frames");
if (jetpackSmoke && (level?.Code != "VR04" || frames < 300))
throw new ArgumentException("Jetpack smoke requires VR04 and at least300 frames");
if (walkSmoke && frames < 240) throw new ArgumentException("Walk smoke requires at least 240 frames.");
var smoke = args.Contains("--smoke-window");
if (frames < 0 || (smoke && (headless || frames < 6)))
@@ -413,6 +413,9 @@ internal static class Program
double poseTime = initialPoseTime;
var injectedInput = default(PlayerInput);
var sawWalkKeys = 0;
var sawJetpackKeys = 0;
float poweredAirTravel = 0;
var poweredAirTurn = false;
var sawPracticeDismiss = false;
var sawPracticePause = false;
double last = clock.Elapsed.TotalSeconds;
@@ -426,11 +429,13 @@ internal static class Program
}
while (running)
{
if (walkSmoke && !headless)
if ((walkSmoke || jetpackSmoke) && !headless)
{
var requested = LabSimulation.SmokeInput(simulation!.Steps);
var requested = jetpackSmoke ? LabSimulation.JetpackSmokeInput(simulation!.Steps)
: LabSimulation.SmokeInput(simulation!.Steps);
foreach (var (scancode, down, previous) in new[] {
(82u, requested.Forward, injectedInput.Forward),
(81u, requested.Backward, injectedInput.Backward), (80u, requested.Left, injectedInput.Left),
(79u, requested.Right, injectedInput.Right), (225u, requested.Jump, injectedInput.Jump) })
{
if (down == previous) continue;
@@ -461,6 +466,7 @@ internal static class Program
{
keys.Add(e.Scancode);
if (walkSmoke) sawWalkKeys |= e.Scancode == 82 ? 1 : e.Scancode == 79 ? 2 : e.Scancode == 225 ? 4 : 0;
if (jetpackSmoke) sawJetpackKeys |= e.Scancode == 82 ? 1 : e.Scancode == 81 ? 2 : e.Scancode == 80 ? 4 : e.Scancode == 225 ? 8 : 0;
if (smoke && e.Scancode == 79) sawKey = true;
if (e.Scancode is 41 or 44 && e.Repeat == 0 && director is { Controlled: false })
{ sceneAudio?.StopSpeech(); director.Skip(); keys.Clear(); mouseJump = false; }
@@ -504,18 +510,25 @@ internal static class Program
var elapsed = now - last;
var dt = (float)Math.Min(elapsed, 0.1);
last = now;
if (simulation != null && !inspecting && !practice.Active && (active || headless || walkSmoke))
if (simulation != null && !inspecting && !practice.Active && (active || headless || walkSmoke || jetpackSmoke))
{
var steps = headless || walkSmoke || practiceWindowSmoke ? 1 : stepClock.Advance(elapsed);
var steps = headless || walkSmoke || jetpackSmoke || practiceWindowSmoke ? 1 : stepClock.Advance(elapsed);
for (var step = 0; step < steps; step++)
{
var input = jetpackSmoke ? new PlayerInput(false, false, false, false, simulation.Steps < 180)
var input = jetpackSmoke && headless ? LabSimulation.JetpackSmokeInput(simulation.Steps)
: walkSmoke && headless ? LabSimulation.SmokeInput(simulation.Steps) : new PlayerInput(
keys.Contains(82), keys.Contains(81), keys.Contains(80), keys.Contains(79),
mouseJump || keys.Contains(225) || keys.Contains(229) || keys.Contains(73) || keys.Contains(98));
if (director?.Controlled != false)
{
var before = simulation.Position;
var powered = simulation.JetpackEffectVisible && !simulation.Grounded;
simulation.Step(input);
if (jetpackSmoke && powered)
{
poweredAirTravel += Vector2.Distance(new(before.X, before.Z), new(simulation.Position.X, simulation.Position.Z));
poweredAirTurn |= MathF.Abs(simulation.TurnRate) > 1;
}
interactions?.UpdateEnergy(simulation.Energy);
director?.SyncActor(level!.Player!.Tag!, simulation.ActorRoot, new Vector3(0, simulation.Yaw, 0));
director?.Touch(level!.Player!.Tag!, simulation.ActorRoot);
@@ -590,7 +603,7 @@ internal static class Program
if (!Sdl.SDL_PushEvent(ref key) || !Sdl.SDL_SetWindowSize(window, 800, 600))
throw new InvalidOperationException(Sdl.Error);
}
if (walkSmoke && !headless && count == 1 && !Sdl.SDL_SetWindowSize(window, 800, 600))
if ((walkSmoke || jetpackSmoke) && !headless && count == 1 && !Sdl.SDL_SetWindowSize(window, 800, 600))
throw new InvalidOperationException(Sdl.Error);
if (smoke && count == 1)
{
@@ -603,7 +616,7 @@ internal static class Program
if (!Sdl.SDL_PushEvent(ref cycle)) throw new InvalidOperationException(Sdl.Error);
}
}
if ((smoke || walkSmoke || practiceWindowSmoke) && renderer.Width == 800 && renderer.Height == 600) didResize = true;
if ((smoke || walkSmoke || jetpackSmoke || practiceWindowSmoke) && renderer.Width == 800 && renderer.Height == 600) didResize = true;
if (frames > 0 && count >= frames) break;
if (transitionRequest != null) break;
}
@@ -621,7 +634,10 @@ internal static class Program
if (jetpackSmoke)
{
Console.WriteLine($"Powered jump: bursts={simulation!.Bursts}, remaining={simulation.JetpackRemaining:F3}, energy={simulation.Energy:F3}, grounded={simulation.Grounded}.");
if (simulation.Bursts == 0 || simulation.MaximumRise <= 137.62f || !simulation.Grounded) return 2;
Console.WriteLine($"Powered air steering: travel={poweredAirTravel:F2}, turned={poweredAirTurn}.");
if (!headless) Console.WriteLine($"Jetpack SDL keys received={sawJetpackKeys == 15}, resize800x600={didResize}.");
if (simulation.Bursts == 0 || simulation.MaximumRise <= 137.62f || !simulation.Grounded
|| poweredAirTravel <= 20 || !poweredAirTurn || !headless && (sawJetpackKeys != 15 || !didResize)) return 2;
}
if (director != null)
{