Match Jimmy controller arithmetic and facing to original probes
This commit is contained in:
1 parent
42ea2b8cd5
commit
0e2f426d42
60 files changed
+6027
-48
No files matched your search
@@ -2,8 +2,9 @@ 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>Legacy stateless compatibility helper and shared steering constants.
|
||||
/// Live ordinary input uses JimmyAirMotion, which retains the keyboard latch,
|
||||
/// supported mode1 braking and original coast comparison precision.
|
||||
/// </summary>
|
||||
public static class AirSteering
|
||||
{
|
||||
|
||||
@@ -66,7 +66,7 @@ public static class JetpackBurst
|
||||
}
|
||||
|
||||
if (state.JumpState < 3)
|
||||
extra = input.GravityY * 1.33f - input.GravityY;
|
||||
extra = (float)((double)input.GravityY * 1.33f - input.GravityY);
|
||||
else
|
||||
{
|
||||
if (input.EffectAvailable && state.EffectRemaining <= 0 && state.JumpState is 3 or 4)
|
||||
@@ -109,8 +109,11 @@ public static class JetpackBurst
|
||||
EffectRemaining = input.EffectAvailable ? 0 : state.EffectRemaining };
|
||||
return Result(impulse: JumpImpulse, pose: JetpackPose.Jump);
|
||||
case 1:
|
||||
state = state with { HoldSeconds = state.HoldSeconds + input.DeltaSeconds };
|
||||
if (state.HoldSeconds <= HoldThreshold) return Result();
|
||||
//438407 storesfloat but keeps the unrounded sum on x87 for
|
||||
//43840D's comparison. Different sums can store the samefloat.
|
||||
double hold=(double)state.HoldSeconds+input.DeltaSeconds;
|
||||
state = state with { HoldSeconds = (float)hold };
|
||||
if (hold <= HoldThreshold) return Result();
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.Numerics;
|
||||
namespace GamePort.Game;
|
||||
|
||||
public readonly record struct JimmyAirInputState(float Speed,float TurnRate,bool KeyboardTurn);
|
||||
public readonly record struct JimmyAirApply(Vector3 Velocity,Vector3 Rotation,float AppliedTurnRate);
|
||||
|
||||
/// <summary>Ordinary mode1 keyboard input439900 and437F90 velocity prefix.
|
||||
/// Body integration, facing interpolation, jump suffix and input ownership are
|
||||
/// caller phases. Source constraints and observations: jimmy-air-motion.md.</summary>
|
||||
public static class JimmyAirMotion
|
||||
{
|
||||
public static JimmyAirInputState Input(JimmyAirInputState state,PlayerInput input,bool supported,
|
||||
float seconds,float maximumSpeed=600)
|
||||
{
|
||||
if(!float.IsFinite(state.Speed)||!float.IsFinite(state.TurnRate)||!float.IsFinite(seconds)
|
||||
||seconds<=0||seconds>=1||!float.IsFinite(maximumSpeed)||maximumSpeed<=0)
|
||||
throw new ArgumentOutOfRangeException(nameof(seconds));
|
||||
float turn=state.TurnRate;bool keyboard=state.KeyboardTurn;float turnStep=100*seconds;
|
||||
if(input.Left){turn+=turnStep;keyboard=true;}
|
||||
else if(input.Right){turn-=turnStep;keyboard=true;}
|
||||
else if(keyboard)turn=turn<0?MathF.Min(0,turn+turnStep):MathF.Max(0,turn-turnStep);
|
||||
float speed=state.Speed;
|
||||
if(input.Forward)
|
||||
{
|
||||
if(speed<maximumSpeed)speed=MathF.Min(maximumSpeed,speed+30);
|
||||
}
|
||||
//439B77 compares the unrounded x87 product against stored speed.
|
||||
else if(speed>(double)maximumSpeed*.9090909361839294f)speed-=17.5f;
|
||||
//A stored air mode may still receive input while body218 is supported.
|
||||
//This independent subtraction intentionally has no crossing clamp.
|
||||
if(supported)speed=speed>0?speed-17.5f:0;
|
||||
if(input.Backward)
|
||||
{
|
||||
if(speed>0)speed=MathF.Max(0,speed-(supported?35:17.5f));
|
||||
else if(speed<0)speed=MathF.Min(0,speed+35);
|
||||
}
|
||||
return new(speed,Math.Clamp(turn,-30,30),keyboard);
|
||||
}
|
||||
|
||||
public static JimmyAirApply Apply(float speed,float turn,Vector3 rotation,Vector3 velocity,
|
||||
float seconds,float friction=.8f)
|
||||
{
|
||||
if(!float.IsFinite(speed)||!float.IsFinite(turn)||!float.IsFinite(seconds)||seconds<0||seconds>=1
|
||||
||!float.IsFinite(friction)||!float.IsFinite(velocity.X)||!float.IsFinite(velocity.Y)||!float.IsFinite(velocity.Z))
|
||||
throw new ArgumentOutOfRangeException(nameof(seconds));
|
||||
float side=0,applied=0;
|
||||
if(velocity!=Vector3.Zero)
|
||||
{
|
||||
applied=turn;
|
||||
rotation=RocketOrientation.Add(rotation,new(0,turn*seconds,0));
|
||||
side=(float)((double)turn*.0181818176060915f*(1.0-friction)*speed);
|
||||
}
|
||||
var forward=RocketOrientation.Rotate(new(0,0,speed),rotation);
|
||||
var(sin,cos)=RocketOrientation.Trig(rotation.Y);
|
||||
return new(new((float)(forward.X+(double)cos*side),velocity.Y,
|
||||
(float)(forward.Z+(double)sin*side)),rotation,applied);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Numerics;
|
||||
namespace GamePort.Game;
|
||||
|
||||
public readonly record struct JimmyGroundState(float Speed,float TargetYaw,
|
||||
float BackSeconds=0,bool AutoTurning=false,float BackYaw=0);
|
||||
public readonly record struct JimmyGroundInput(JimmyGroundState State,float Lateral,bool HeadingUpdated);
|
||||
public readonly record struct JimmyGroundApply(Vector3 Velocity,Vector3 Rotation);
|
||||
|
||||
/// <summary>43915D..4395CF keyboard ground suffix and437C40 ground apply.
|
||||
/// Body, phase gates, backward acceptance and the830 clock owner remain caller-owned.
|
||||
/// See docs/gameplay/jimmy-ground-motion.md for copied-original references/limits.</summary>
|
||||
public static class JimmyGroundMotion
|
||||
{
|
||||
public static JimmyGroundInput Input(JimmyGroundState state,float yaw,PlayerInput input,
|
||||
float maximumSpeed=600,bool blockBackward=false)
|
||||
{
|
||||
Finite(state.Speed);Finite(state.TargetYaw);Finite(state.BackSeconds);Finite(state.BackYaw);Finite(yaw);Finite(maximumSpeed);
|
||||
if(maximumSpeed<=0)throw new ArgumentOutOfRangeException(nameof(maximumSpeed));
|
||||
float speed=state.Speed,angle=0,lateral=0,backTime=state.BackSeconds,backYaw=state.BackYaw;
|
||||
bool active=false,back=input.Backward&&!blockBackward,auto=state.AutoTurning;
|
||||
float Accelerate(float value)=>value<maximumSpeed?MathF.Min(value+30,maximumSpeed):value;
|
||||
if(input.Left){angle+=20;lateral=-1000;active=true;speed=Accelerate(speed);}
|
||||
else if(input.Right){angle-=20;lateral=1000;active=true;speed=Accelerate(speed);}
|
||||
if(input.Forward){angle*=.5f;active=true;speed=Accelerate(speed);}
|
||||
if(back)
|
||||
{
|
||||
active=true;
|
||||
if(!auto)
|
||||
{
|
||||
speed=MathF.Max(speed-52.5f,-maximumSpeed*.5f);
|
||||
if((double)backTime>1.5){speed=maximumSpeed;auto=true;backYaw=yaw+180;angle=0;}
|
||||
}
|
||||
else speed=maximumSpeed;
|
||||
}
|
||||
else {backTime=0;auto=false;}
|
||||
if(!input.Forward&&!back)
|
||||
{if(speed>0)speed=MathF.Max(0,speed-35);if(speed<0)speed=MathF.Min(0,speed+35);}
|
||||
float target=state.TargetYaw;
|
||||
if(active)target=auto?(angle!=0?yaw-angle*.5f:backYaw):yaw+angle;
|
||||
return new(new(speed,target,backTime,auto,backYaw),lateral,active);
|
||||
}
|
||||
|
||||
public static JimmyGroundApply Apply(float speed,Vector3 velocity,Vector3 rotation,float turnRate,
|
||||
float lateral,bool supported,bool hasSupportPolygon,float seconds,float friction=.8f,bool specialLocked=false)
|
||||
{
|
||||
Finite(speed);Finite(turnRate);Finite(lateral);Finite(seconds);Finite(friction);
|
||||
Finite(velocity.X);Finite(velocity.Y);Finite(velocity.Z);
|
||||
Finite(rotation.X);Finite(rotation.Y);Finite(rotation.Z);
|
||||
if(seconds<=0||seconds>=1)throw new ArgumentOutOfRangeException(nameof(seconds));
|
||||
if(specialLocked)return new(velocity,rotation);
|
||||
float side=0;
|
||||
if(velocity!=Vector3.Zero||lateral!=0)
|
||||
{
|
||||
rotation=RocketOrientation.Add(rotation,new(0,turnRate*seconds,0));
|
||||
side=(float)(((double)turnRate*.02222222276031971f*(1.0-friction)*speed+lateral)*seconds);
|
||||
}
|
||||
var forward=RocketOrientation.Rotate(new(0,0,speed),rotation);
|
||||
var(sine,cosine)=RocketOrientation.Trig(rotation.Y);
|
||||
var result=new Vector3(forward.X+cosine*side,velocity.Y,forward.Z+sine*side);
|
||||
if(supported&&hasSupportPolygon)result.Y-=250;
|
||||
return new(result,rotation);
|
||||
}
|
||||
private static void Finite(float value){if(!float.IsFinite(value))throw new ArgumentOutOfRangeException(nameof(value));}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Numerics;
|
||||
namespace GamePort.Game;
|
||||
|
||||
/// <summary>43A420 active Jimmy facing, followed by334→458F90→472480.
|
||||
/// Targets are retained caller state; all three axes take the shortest arc.
|
||||
/// Source4.5/3.7 constants are doubles and delta parameters publish as floats.</summary>
|
||||
public static class JimmyOrientation
|
||||
{
|
||||
public static Vector3 Step(Vector3 current,Vector3 target,float seconds,bool enabled=true,bool dirty=true)
|
||||
{
|
||||
if(!float.IsFinite(current.X)||!float.IsFinite(current.Y)||!float.IsFinite(current.Z)
|
||||
||!float.IsFinite(target.X)||!float.IsFinite(target.Y)||!float.IsFinite(target.Z)
|
||||
||!float.IsFinite(seconds)||seconds<0||seconds>=1)
|
||||
throw new ArgumentOutOfRangeException(nameof(seconds));
|
||||
if(!enabled||!dirty)return current;
|
||||
static float Arc(float value)=>value>180?value-360:value< -180?value+360:value;
|
||||
static double WideArc(double value)=>value>180?value-360:value< -180?value+360:value;
|
||||
var x=Arc(target.X-current.X);var y=Arc(target.Y-current.Y);
|
||||
//X/Y differences have explicit float stack stores. The Z difference
|
||||
//remains on x87 until its final float argument publication.
|
||||
var z=WideArc((double)target.Z-current.Z);
|
||||
var delta=new Vector3((float)((double)x*seconds*4.5),(float)((double)y*seconds*3.7),(float)(z*seconds*4.5));
|
||||
return RocketOrientation.Add(current,delta);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall, Fly, Shoot, Swing }
|
||||
|
||||
/// <summary>
|
||||
/// Walking, airborne steering and jetpack checkpoint. Recovered arithmetic is described in
|
||||
/// movement-checkpoint.md. Legacy capsule, floor-derived pivot and60Hz are port policies;
|
||||
/// jimmy-movement-stabilization.md. Legacy capsule, floor-derived pivot and60Hz are port policies;
|
||||
/// original collision, intro, object interactions and animation timing remain open.
|
||||
/// </summary>
|
||||
public sealed class LabSimulation
|
||||
@@ -32,6 +32,7 @@ public sealed class LabSimulation
|
||||
private int movementMode;
|
||||
private JetpackBurstState jumpState;
|
||||
private bool forceFall;
|
||||
private bool keyboardTurn, hasSupportPolygon;
|
||||
private Vector3 noclipEntry;
|
||||
private float noclipEntryYaw;
|
||||
private int gadgetMode = -1;
|
||||
@@ -189,6 +190,7 @@ public sealed class LabSimulation
|
||||
Yaw = targetYaw = startYaw;
|
||||
Speed = PublishedSpeed = TurnRate = extraAirAcceleration = shadowDistance = 0;
|
||||
lateralContribution = 0; pendingImpulse = Vector3.Zero; movementMode = 0;
|
||||
keyboardTurn=false;hasSupportPolygon=false;
|
||||
jumpState = default;
|
||||
forceFall = JetpackEffectVisible = false;
|
||||
Shooting = false;
|
||||
@@ -262,6 +264,7 @@ public sealed class LabSimulation
|
||||
//424BE0..424C34 runs this wrapper before437940's ownership gate.
|
||||
StepCeiling();
|
||||
StepFloorPolicy(); //437940's base40E050, before the input-identity gate.
|
||||
StepFacing(); //40E050→473240→43A420 also runs without input ownership.
|
||||
if (controlled) StepPlayer(input);
|
||||
Invisible.Step(FixedStepClock.Step, anyControlled ?? controlled, input.Fire, input.Jump,
|
||||
Energy, IgnoresGadgetEnergy, AdjustEnergy);
|
||||
@@ -444,26 +447,26 @@ public sealed class LabSimulation
|
||||
//438A60 dispatches by stored movement mode, not current support.
|
||||
if (movementMode == 0)
|
||||
{
|
||||
if (TracksBubbleOrientation && (input.Forward || input.Left || input.Right
|
||||
|| input.Backward && !(GadgetMode is -1 or 3 && input.Fire))) targetPitch=targetRoll=0;
|
||||
float yawDelta = 0;
|
||||
if (input.Left) { yawDelta += 20; lateralContribution = -1000; Speed = RecoveredMotion.AddSpeed(Speed,MaximumSpeed); }
|
||||
else if (input.Right) { yawDelta -= 20; lateralContribution = 1000; Speed = RecoveredMotion.AddSpeed(Speed,MaximumSpeed); }
|
||||
if (input.Forward) { yawDelta *= 0.5f; Speed = RecoveredMotion.AddSpeed(Speed,MaximumSpeed); }
|
||||
if (yawDelta != 0) targetYaw = Yaw + yawDelta;
|
||||
if (input.Backward) Speed = MathF.Max(Speed - 52.5f, -300);
|
||||
else if (!input.Forward) Speed = RecoveredMotion.ReleaseSpeed(Speed);
|
||||
//The830 backward clock owner remains unresolved; ordinary state0
|
||||
//does not invent a hold timer or admit its seeded auto-turn branch.
|
||||
var ground=JimmyGroundMotion.Input(new(Speed,targetYaw),Yaw,input,MaximumSpeed,
|
||||
blockBackward:(GadgetMode is -1 or 3)&&input.Fire);
|
||||
Speed=ground.State.Speed;targetYaw=ground.State.TargetYaw;lateralContribution=ground.Lateral;
|
||||
if(input.Left||input.Right)keyboardTurn=true;
|
||||
if(ground.HeadingUpdated)targetPitch=targetRoll=0;
|
||||
}
|
||||
else if (movementMode==2)
|
||||
{
|
||||
var steering=BubbleMotion.StepInput(Speed,TurnRate,input,Grounded,dt,MaximumSpeed);
|
||||
Speed=steering.Speed; TurnRate=steering.TurnRate;
|
||||
if(input.Left||input.Right)keyboardTurn=true;
|
||||
targetPitch=steering.TargetPitch; targetRoll=steering.TargetRoll; targetYaw=Yaw;
|
||||
}
|
||||
else
|
||||
{
|
||||
var steering = AirSteering.Step(Speed, TurnRate, input, dt,MaximumSpeed);
|
||||
var steering = JimmyAirMotion.Input(new(Speed,TurnRate,keyboardTurn),input,Grounded,dt,MaximumSpeed);
|
||||
Speed = steering.Speed; TurnRate = steering.TurnRate;
|
||||
keyboardTurn=steering.KeyboardTurn;
|
||||
if (TracksBubbleOrientation) { targetPitch=0; targetRoll=-TurnRate; }
|
||||
//439E2B preserves current yaw as the destination; air apply then
|
||||
//438011..43802B adds the independent turn rate directly to yaw.
|
||||
@@ -492,15 +495,16 @@ public sealed class LabSimulation
|
||||
StopForPrimaryFire,SetShooting,AdjustEnergy);
|
||||
}
|
||||
|
||||
private void StepFacing()
|
||||
{
|
||||
var rotation=JimmyOrientation.Step(new(Pitch,Yaw,Roll),new(targetPitch,targetYaw,targetRoll),FixedStepClock.Step);
|
||||
Pitch=rotation.X;Yaw=rotation.Y;Roll=rotation.Z;
|
||||
}
|
||||
|
||||
private void StepPlayer(PlayerInput input)
|
||||
{
|
||||
ControllerSteps++;
|
||||
const float dt = FixedStepClock.Step;
|
||||
if (TracksBubbleOrientation)
|
||||
{
|
||||
Pitch+=(targetPitch-Pitch)*dt*4.5f;
|
||||
Roll+=(targetRoll-Roll)*dt*4.5f;
|
||||
}
|
||||
if (movementMode==2)
|
||||
{
|
||||
var bubble=BubbleMotion.StepApply(Speed,TurnRate,Yaw,Pitch,Velocity,Grounded,input.Jump,dt);
|
||||
@@ -508,8 +512,6 @@ public sealed class LabSimulation
|
||||
if (Grounded) { BubbleBounces++; if (bubble.Boing) GadgetSound?.Invoke(106,false); }
|
||||
return;
|
||||
}
|
||||
var yawError = MathF.IEEERemainder(targetYaw - Yaw, 360);
|
||||
Yaw = (Yaw + yawError * dt * 3.7f) % 360;
|
||||
//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;
|
||||
@@ -517,15 +519,18 @@ public sealed class LabSimulation
|
||||
{
|
||||
movementMode = 0; TurnRate = 0;
|
||||
}
|
||||
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 = movementMode == 0 ? (TurnRate * (1 - friction) * Speed / 45 + lateralContribution) * dt
|
||||
: TurnRate * (1 - friction) * Speed * .0181818176060915f;
|
||||
velocity += new Vector3(cos, 0, sin) * sideSpeed;
|
||||
Vector3 velocity;
|
||||
if(movementMode==0)
|
||||
{
|
||||
var ground=JimmyGroundMotion.Apply(Speed,Velocity,new(Pitch,Yaw,Roll),TurnRate,
|
||||
lateralContribution,Grounded,hasSupportPolygon,dt);
|
||||
velocity=ground.Velocity;Pitch=ground.Rotation.X;Yaw=ground.Rotation.Y;Roll=ground.Rotation.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
var airMotion=JimmyAirMotion.Apply(Speed,TurnRate,new(Pitch,Yaw,Roll),Velocity,dt);
|
||||
velocity=airMotion.Velocity;Pitch=airMotion.Rotation.X;Yaw=airMotion.Rotation.Y;Roll=airMotion.Rotation.Z;
|
||||
}
|
||||
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,
|
||||
@@ -576,6 +581,10 @@ public sealed class LabSimulation
|
||||
}
|
||||
}
|
||||
Grounded = result.Grounded && velocity.Y <= 0;
|
||||
//The capsule has no original338 support polygon. Combining source
|
||||
//downward pressure with its slide solver blocks the lab stair route.
|
||||
//Keep that solver's baseline until the source body/contact bridge lands.
|
||||
hasSupportPolygon=false;
|
||||
if (Grounded && velocity.Y < 0 || result.HitCeiling && velocity.Y > 0 && ceilingRay == null) velocity.Y = 0;
|
||||
if (Grounded) { extraAirAcceleration = 0; forceFall = false; }
|
||||
Velocity = velocity;
|
||||
@@ -598,6 +607,7 @@ public sealed class LabSimulation
|
||||
pendingImpulse = result.Body.Impulse;
|
||||
extraAirAcceleration = result.Body.Acceleration.Y;
|
||||
Grounded = result.Body.Supported;
|
||||
hasSupportPolygon=result.SupportHit!=null;
|
||||
if (Grounded) forceFall = false;
|
||||
if (result.Landing != null) Landings++;
|
||||
if (result.Contact is { StoredNormal.Y: > -.7f }) {WallHits++;Grappler?.Contact();}
|
||||
|
||||
@@ -18,7 +18,8 @@ public static class RecoveredMotion
|
||||
|
||||
// Deliberately per invocation: original increments omit dt. Call cadence is
|
||||
// not yet verified. Rendering must not directly choose simulation cadence.
|
||||
public static float AddSpeed(float speed, float maximumSpeed = MaximumSpeed) => MathF.Min(speed + SpeedIncrement, maximumSpeed);
|
||||
public static float AddSpeed(float speed, float maximumSpeed = MaximumSpeed) =>
|
||||
speed<maximumSpeed?MathF.Min(speed+SpeedIncrement,maximumSpeed):speed;
|
||||
public static float ReleaseSpeed(float speed) => speed > 0
|
||||
? MathF.Max(0, speed - SpeedDecay) : MathF.Min(0, speed + SpeedDecay);
|
||||
|
||||
|
||||
Reference in new issue
Block a user