Reconstruct lab story, interactions, patrol and jet pack practice flow

This commit is contained in:
UnixNight committed 2026-10-24 20:33:03 -04:00
1 parent 58424120bb
commit c929f942e1
84 files changed
+7957 -305

No files matched your search

+57 -27
View File
@@ -4,7 +4,7 @@ using GamePort.Assets;
namespace GamePort.Game;
public readonly record struct PlayerInput(bool Forward, bool Backward, bool Left, bool Right, bool Jump);
public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall }
public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall, Fly }
/// <summary>
/// No-gadget walking checkpoint. Recovered input/arithmetic is described in
@@ -16,9 +16,18 @@ public sealed class LabSimulation
public const float BodyRadius = 24; // Provisional, not a recovered collider dimension.
private readonly SceneCollision collision;
private readonly Vector3 sourceStart;
private readonly float startYaw, modelMinimumY, rootHeight;
private float targetYaw, jumpHeldTime;
private int jumpState;
private readonly float startYaw, modelMinimumY, rootHeight, startFloor;
private float targetYaw, extraAirAcceleration, shadowDistance;
private JetpackBurstState jumpState;
private bool forceFall;
public Func<int>? JetpackInventoryState { get; set; }
public string LevelCode { get; set; } = "LV1B";
public int GadgetMode { get; set; } = -1;
public float Energy { get; set; } = 20;
public float InteractionRadius { get; private set; } = 60;
public bool JetpackEffectVisible { get; private set; }
public float JetpackRemaining => jumpState.EffectRemaining;
public int Bursts { get; private set; }
public float BodyHeight { get; }
public Vector3 Position { get; private set; } // Feet, not original actor root.
public Vector3 Velocity { get; private set; }
@@ -26,13 +35,15 @@ public sealed class LabSimulation
public float Speed { get; private set; }
public bool Grounded { get; private set; }
public PlayerPose Pose => Grounded ? Speed < -1 ? PlayerPose.Backpedal : Speed > 1 ? PlayerPose.Run : PlayerPose.Idle
: Velocity.Y > 0 ? PlayerPose.Jump : PlayerPose.Fall;
: jumpState.JumpState == 3 && jumpState.EffectRemaining > 0 ? PlayerPose.Fly
: !forceFall && Velocity.Y > 0 ? PlayerPose.Jump : PlayerPose.Fall;
public int Steps { get; private set; }
public int Jumps { get; private set; }
public int Landings { get; private set; }
public int WallHits { get; private set; }
public float Travel { get; private set; }
public float MaximumRise { get; private set; }
public Func<Vector3, Vector3, float, Vector3>? DynamicRootResolver { get; set; }
public Vector3 ActorRoot => Position + Vector3.UnitY * rootHeight;
public Vector3 CameraEye { get; private set; }
public Vector3 CameraTarget => ActorRoot + new Vector3(0, 99, 0);
@@ -49,7 +60,11 @@ public sealed class LabSimulation
BodyHeight = bounds.Max.Y - bounds.Min.Y;
var floor = collision.GroundHeight(start, 2500)
?? throw new InvalidDataException("No support below GAM startpoint");
rootHeight = start.Y - floor;
startFloor = floor;
// Normal Jimmy PostLoad4236A3..BA and support47BAE1 place the actor
// root at floor+60*1.265. Serialized spawnY is settled by physics.
// Feet collision and sole-based visual placement remain provisional.
rootHeight = OriginalBodySupport.JimmyRadius * OriginalBodySupport.JimmyFactor;
Reset();
}
@@ -59,8 +74,10 @@ public sealed class LabSimulation
Position = new(sourceStart.X, floor + SceneCollision.Skin, sourceStart.Z);
Velocity = Vector3.Zero;
Yaw = targetYaw = startYaw;
Speed = jumpHeldTime = 0;
jumpState = 0;
Speed = extraAirAcceleration = shadowDistance = 0;
jumpState = default;
forceFall = JetpackEffectVisible = false;
InteractionRadius = 60; Bursts = 0;
Grounded = true;
Steps = Jumps = Landings = WallHits = 0;
Travel = MaximumRise = 0;
@@ -83,7 +100,7 @@ public sealed class LabSimulation
float lateral = 0;
if (Grounded)
{
if (!input.Jump) jumpState = 0;
InteractionRadius = 60; // Jimmy's ordinary grounded update42469B.
float yawDelta = 0;
if (input.Left) { yawDelta += 20; lateral = -1000; Speed = RecoveredMotion.AddSpeed(Speed); }
else if (input.Right) { yawDelta -= 20; lateral = 1000; Speed = RecoveredMotion.AddSpeed(Speed); }
@@ -97,34 +114,47 @@ public sealed class LabSimulation
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);
var impulse = Vector3.Zero;
if (Grounded && input.Jump && jumpState == 0)
{
impulse.Y = RecoveredMotion.JumpImpulse;
jumpState = 1;
jumpHeldTime = 0;
Grounded = false;
Jumps++;
}
if (!Grounded && jumpState == 1)
{
if (!input.Jump) jumpState = 2;
else if ((jumpHeldTime += dt) > 0.4f) jumpState = 0; // Zero-fuel jetpack path resets to FALL.
}
else if (!Grounded && jumpState == 2 && input.Jump)
jumpState = 0; // Renewed hold enters the same disabled-gadget reset path.
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,
JetpackInventoryState?.Invoke() ?? 0, Energy, LevelCode, GadgetMode, dt, extraAirAcceleration));
jumpState = air.State; extraAirAcceleration = air.ExtraAccelerationY;
var impulse = new Vector3(0, air.ImpulseY, 0);
if (air.ImpulseY != 0) { Grounded = false; Jumps++; }
if (air.VelocityYOverride is { } vertical) velocity.Y = vertical;
if (air.RadiusOverride is { } radius) InteractionRadius = radius;
if (air.Pose == JetpackPose.Fall) forceFall = true;
else if (air.Pose is JetpackPose.Jump or JetpackPose.Fly) forceFall = false;
if (air.StartGadget) Bursts++;
var displacement = RecoveredMotion.Integrate(ref velocity, ref impulse,
RecoveredMotion.Gravity * 0.33f, RecoveredMotion.Gravity, dt);
Vector3.UnitY * extraAirAcceleration, RecoveredMotion.Gravity, dt);
var before = Position;
var result = collision.Move(Position, displacement, BodyRadius, BodyHeight);
Position = result.Position;
if (DynamicRootResolver != null)
{
var root = ActorRoot;
var resolved = DynamicRootResolver(before + Vector3.UnitY * rootHeight, root, InteractionRadius);
if (resolved != root)
{
// Original47A5E0 re-clips against static geometry before storing
// the new root. Here both kernels remain explicitly provisional.
result = collision.Move(Position, resolved - root, BodyRadius, BodyHeight);
Position = result.Position;
}
}
Grounded = result.Grounded && velocity.Y <= 0;
if (Grounded && velocity.Y < 0 || result.HitCeiling && velocity.Y > 0) velocity.Y = 0;
if (Grounded) { extraAirAcceleration = 0; forceFall = false; }
Velocity = velocity;
// Explicit port phase policy: controller, collision, then effect update.
// Original global object iteration order has not yet been matched.
var effect = JetpackBurst.StepEffect(jumpState, Grounded, dt, Energy, LevelCode);
jumpState = effect.State; Energy = effect.Energy; JetpackEffectVisible = effect.Visible;
if (!wasGrounded && Grounded) Landings++;
if (result.HitWall) WallHits++;
Travel += Vector2.Distance(new(before.X, before.Z), new(Position.X, Position.Z));
MaximumRise = Math.Max(MaximumRise, Position.Y - sourceStart.Y + rootHeight);
MaximumRise = Math.Max(MaximumRise, Position.Y - startFloor);
Steps++;
var desired = DesiredEye();
var delta = (desired - CameraEye) * new Vector3(1.6f, 1.2f, 1.6f) * dt;