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
@@ -15,9 +15,12 @@ public sealed class LabSimulation
|
||||
{
|
||||
public const float BodyRadius = 24; // Provisional, not a recovered collider dimension.
|
||||
private readonly SceneCollision collision;
|
||||
private readonly Func<Vector3, Vector3, SupportHit?>? cameraRay;
|
||||
private readonly Vector3 sourceStart;
|
||||
private readonly float startYaw, modelMinimumY, rootHeight, startFloor;
|
||||
private float targetYaw, extraAirAcceleration, shadowDistance;
|
||||
private float targetYaw, extraAirAcceleration, shadowDistance, lateralContribution;
|
||||
private Vector3 pendingImpulse;
|
||||
private int movementMode;
|
||||
private JetpackBurstState jumpState;
|
||||
private bool forceFall;
|
||||
public Func<int>? JetpackInventoryState { get; set; }
|
||||
@@ -31,11 +34,17 @@ public sealed class LabSimulation
|
||||
public float BodyHeight { get; }
|
||||
public Vector3 Position { get; private set; } // Feet, not original actor root.
|
||||
public Vector3 Velocity { get; private set; }
|
||||
public Vector3 PendingImpulse => pendingImpulse;
|
||||
public int MovementMode => movementMode;
|
||||
// Fresh game registers before Jimmy. A retained Jimmy precedes the newly
|
||||
// appended destination game, whose input callback therefore runs later.
|
||||
public bool InputAfterPlayerUpdate { get; 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
|
||||
public PlayerPose Pose => pendingImpulse.Y > 0 ? PlayerPose.Jump
|
||||
: Grounded ? Speed < -1 ? PlayerPose.Backpedal : Speed > 1 ? PlayerPose.Run : PlayerPose.Idle
|
||||
: jumpState.JumpState == 3 && jumpState.EffectRemaining > 0 ? PlayerPose.Fly
|
||||
: !forceFall && Velocity.Y > 0 ? PlayerPose.Jump : PlayerPose.Fall;
|
||||
public int Steps { get; private set; }
|
||||
@@ -51,9 +60,11 @@ public sealed class LabSimulation
|
||||
public Matrix4x4 Model => Matrix4x4.CreateRotationY(-Yaw * MathF.PI / 180)
|
||||
* Matrix4x4.CreateTranslation(Position - new Vector3(0, modelMinimumY, 0));
|
||||
|
||||
public LabSimulation(SceneCollision collision, Mesh standingPose, Vector3 start, float yaw)
|
||||
public LabSimulation(SceneCollision collision, Mesh standingPose, Vector3 start, float yaw,
|
||||
Func<Vector3, Vector3, SupportHit?>? cameraRay = null)
|
||||
{
|
||||
this.collision = collision;
|
||||
this.cameraRay = cameraRay;
|
||||
sourceStart = start;
|
||||
startYaw = yaw;
|
||||
var bounds = standingPose.Bounds();
|
||||
@@ -76,13 +87,14 @@ public sealed class LabSimulation
|
||||
Velocity = Vector3.Zero;
|
||||
Yaw = targetYaw = startYaw;
|
||||
Speed = TurnRate = extraAirAcceleration = shadowDistance = 0;
|
||||
lateralContribution = 0; pendingImpulse = Vector3.Zero; movementMode = 0;
|
||||
jumpState = default;
|
||||
forceFall = JetpackEffectVisible = false;
|
||||
InteractionRadius = 60; Bursts = 0;
|
||||
Grounded = true;
|
||||
Steps = Jumps = Landings = WallHits = 0;
|
||||
Travel = MaximumRise = 0;
|
||||
CameraEye = DesiredEye();
|
||||
CameraEye = DesiredEye().Eye;
|
||||
}
|
||||
|
||||
/// <summary>Jimmy PostLoad423A90..423ABF restores the saved RETURN root.
|
||||
@@ -92,7 +104,7 @@ public sealed class LabSimulation
|
||||
if (!float.IsFinite(root.X) || !float.IsFinite(root.Y) || !float.IsFinite(root.Z))
|
||||
throw new ArgumentOutOfRangeException(nameof(root));
|
||||
Position = root - Vector3.UnitY * rootHeight;
|
||||
CameraEye = DesiredEye();
|
||||
CameraEye = DesiredEye().Eye;
|
||||
}
|
||||
|
||||
// EXE 0x47F940 truncates, then degree lookup masks to the 16384-entry table.
|
||||
@@ -105,19 +117,29 @@ public sealed class LabSimulation
|
||||
}
|
||||
|
||||
public void Step(PlayerInput input)
|
||||
{
|
||||
//47E554 global body integration precedes473740 registry callbacks.
|
||||
// This reconstructs the player/input/fire partial order, not the full
|
||||
// scene registry, original cadence or original collision response.
|
||||
StepPhysics();
|
||||
if (!InputAfterPlayerUpdate) StepInput(input);
|
||||
StepPlayer(input);
|
||||
var effect = JetpackBurst.StepEffect(jumpState, Grounded, FixedStepClock.Step, Energy, LevelCode);
|
||||
jumpState = effect.State; Energy = effect.Energy; JetpackEffectVisible = effect.Visible;
|
||||
if (InputAfterPlayerUpdate) StepInput(input);
|
||||
Steps++;
|
||||
}
|
||||
|
||||
private void StepInput(PlayerInput input)
|
||||
{
|
||||
const float dt = FixedStepClock.Step;
|
||||
var wasGrounded = Grounded;
|
||||
float lateral = 0;
|
||||
if (Grounded)
|
||||
lateralContribution = 0;
|
||||
//438A60 dispatches by stored movement mode, not current support.
|
||||
if (movementMode == 0)
|
||||
{
|
||||
//437B9E..437BAC uses an interface pointer: interface+614 is
|
||||
//complete+6D4. Normal grounded/released input clears air turn.
|
||||
if (!input.Jump) TurnRate = 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); }
|
||||
if (input.Left) { yawDelta += 20; lateralContribution = -1000; Speed = RecoveredMotion.AddSpeed(Speed); }
|
||||
else if (input.Right) { yawDelta -= 20; lateralContribution = 1000; Speed = RecoveredMotion.AddSpeed(Speed); }
|
||||
if (input.Forward) { yawDelta *= 0.5f; Speed = RecoveredMotion.AddSpeed(Speed); }
|
||||
if (yawDelta != 0) targetYaw = Yaw + yawDelta;
|
||||
if (input.Backward) Speed = MathF.Max(Speed - 52.5f, -300);
|
||||
@@ -131,15 +153,29 @@ public sealed class LabSimulation
|
||||
//438011..43802B adds the independent turn rate directly to yaw.
|
||||
targetYaw = Yaw;
|
||||
}
|
||||
StepCamera(); //438BC0/439900 input path owns follow; still provisional geometry/state.
|
||||
}
|
||||
|
||||
private void StepPlayer(PlayerInput input)
|
||||
{
|
||||
const float dt = FixedStepClock.Step;
|
||||
var yawError = MathF.IEEERemainder(targetYaw - Yaw, 360);
|
||||
Yaw = (Yaw + yawError * dt * 3.7f) % 360;
|
||||
if (Velocity.LengthSquared() != 0 || Grounded && lateral != 0)
|
||||
//437A96 selects air mode on held jump;437B9E..BAC resets jump/mode/turn
|
||||
//only in the player's grounded/released update, after input when fresh.
|
||||
if (input.Jump) movementMode = 1;
|
||||
else if (Grounded)
|
||||
{
|
||||
movementMode = 0; TurnRate = 0;
|
||||
}
|
||||
if (Grounded) InteractionRadius = 60;
|
||||
if (Velocity.LengthSquared() != 0 || movementMode == 0 && lateralContribution != 0)
|
||||
Yaw = (Yaw + TurnRate * dt) % 360;
|
||||
var (sin, cos) = Trig(Yaw);
|
||||
var velocity = new Vector3(-sin * Speed, Velocity.Y, cos * Speed);
|
||||
//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
|
||||
var sideSpeed = movementMode == 0 ? (TurnRate * (1 - friction) * Speed / 45 + lateralContribution) * dt
|
||||
: TurnRate * (1 - friction) * Speed * .0181818176060915f;
|
||||
velocity += new Vector3(cos, 0, sin) * sideSpeed;
|
||||
if (collision.GroundHeight(ActorRoot, 2500) is { } shadowFloor)
|
||||
@@ -147,14 +183,26 @@ public sealed class LabSimulation
|
||||
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++; }
|
||||
pendingImpulse += new Vector3(0, air.ImpulseY, 0);
|
||||
if (air.ImpulseY != 0) Jumps++;
|
||||
if (air.MovementModeOverride is { } mode) movementMode = mode;
|
||||
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,
|
||||
Velocity = velocity; // Produced body state is consumed by the next physics pass.
|
||||
}
|
||||
|
||||
private void StepPhysics()
|
||||
{
|
||||
const float dt = FixedStepClock.Step;
|
||||
var wasGrounded = Grounded;
|
||||
var velocity = Velocity;
|
||||
// Keep the existing capsule/gravity adapter until C4 recovers Jimmy's
|
||||
// pre-integration support/response. Source479DF7..479E54 can cancel
|
||||
// gravity before a supported impulse; this adapter does not model that.
|
||||
var displacement = RecoveredMotion.Integrate(ref velocity, ref pendingImpulse,
|
||||
Vector3.UnitY * extraAirAcceleration, RecoveredMotion.Gravity, dt);
|
||||
var before = Position;
|
||||
var result = collision.Move(Position, displacement, BodyRadius, BodyHeight);
|
||||
@@ -175,24 +223,30 @@ public sealed class LabSimulation
|
||||
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 - startFloor);
|
||||
Steps++;
|
||||
var desired = DesiredEye();
|
||||
var delta = (desired - CameraEye) * new Vector3(1.6f, 1.2f, 1.6f) * dt;
|
||||
CameraEye = collision.ClipCamera(CameraTarget, CameraEye + delta);
|
||||
}
|
||||
|
||||
private Vector3 DesiredEye()
|
||||
private void StepCamera()
|
||||
{
|
||||
const float dt = FixedStepClock.Step;
|
||||
var desired = DesiredEye();
|
||||
var delta = (desired.Eye - CameraEye) * new Vector3(1.6f, 1.2f, 1.6f) * desired.Gain * dt;
|
||||
CameraEye = cameraRay == null ? collision.ClipCamera(CameraTarget, CameraEye + delta) : CameraEye + delta;
|
||||
}
|
||||
|
||||
private (Vector3 Eye, float Gain) DesiredEye()
|
||||
{
|
||||
var (sin, cos) = Trig(Yaw);
|
||||
return collision.ClipCamera(CameraTarget, ActorRoot + new Vector3(sin * 350, 180, -cos * 350));
|
||||
var eye = ActorRoot + new Vector3(sin * 350, 180, -cos * 350);
|
||||
if (cameraRay == null) return (collision.ClipCamera(CameraTarget, eye), 1);
|
||||
//43B820: query from the computed look target; first accepted static hit
|
||||
//moves desired eye25% toward look and returns follow gain1.5. No radius
|
||||
//or second sweep after interpolation occurs in that source callback.
|
||||
return cameraRay(CameraTarget, eye) is { } hit
|
||||
? (CameraTarget - (CameraTarget - hit.Position) * .75f, 1.5f) : (eye, 1);
|
||||
}
|
||||
|
||||
public static PlayerInput SmokeInput(int step) => new(step < 120, false, false,
|
||||
|
||||
Reference in new issue
Block a user