Implement Bubble controller, sprite and VR01 body behavior
This commit is contained in:
1 parent
9ea578492d
commit
1ae5f4251c
51 files changed
+2811
-54
No files matched your search
@@ -23,6 +23,10 @@ public sealed class LabSimulation
|
||||
private readonly Vector3 sourceStart;
|
||||
private readonly float startYaw, modelMinimumY, rootHeight, startFloor;
|
||||
private float targetYaw, extraAirAcceleration, shadowDistance, lateralContribution;
|
||||
private float targetPitch, targetRoll;
|
||||
private int? retainedSupportMaterial;
|
||||
private bool bubbleLoop;
|
||||
private PlayerPose bubblePose;
|
||||
private Vector3 pendingImpulse;
|
||||
private int movementMode;
|
||||
private JetpackBurstState jumpState;
|
||||
@@ -36,13 +40,35 @@ public sealed class LabSimulation
|
||||
public Func<int>? JetpackInventoryState { get; set; }
|
||||
public string LevelCode { get; set; } = "LV1B";
|
||||
public InvisibleGadget Invisible { get; } = new();
|
||||
public BubbleEffect Bubble { get; } = new();
|
||||
public PlayerAppearance Appearance { get; } = new();
|
||||
public Vr01FloorState FloorState { get; } = new();
|
||||
public Vector3 BubbleRoot { get; private set; }
|
||||
public float BodyFactor { get; private set; } = OriginalBodySupport.JimmyFactor;
|
||||
public float MaximumSpeed { get; private set; } = RecoveredMotion.MaximumSpeed;
|
||||
public float Pitch { get; private set; }
|
||||
public float Roll { get; private set; }
|
||||
public bool TracksBubbleOrientation { get; private set; }
|
||||
public int BubbleBounces { get; private set; }
|
||||
public int GadgetMode
|
||||
{
|
||||
get => gadgetMode;
|
||||
set
|
||||
{
|
||||
var previousPose=Pose;
|
||||
if (gadgetMode == 0) ReleaseBubble();
|
||||
if (gadgetMode == 2) Invisible.Release();
|
||||
gadgetMode = -1;
|
||||
if (value == 0)
|
||||
{
|
||||
if (Energy <= 0 && !IgnoresGadgetEnergy || Bubble.Active || Bubble.Expanding || Bubble.Collapsing) return;
|
||||
InteractionRadius=160; BodyFactor=.415f; movementMode=2; MaximumSpeed=1350;
|
||||
bubblePose=previousPose;
|
||||
TracksBubbleOrientation=true;
|
||||
gadgetMode=0; Bubble.Start();
|
||||
if (!bubbleLoop) { GadgetSound?.Invoke(2,true); bubbleLoop=true; }
|
||||
return;
|
||||
}
|
||||
if (value == 2 && !Invisible.Equip(Energy, IgnoresGadgetEnergy)) return;
|
||||
gadgetMode = value;
|
||||
}
|
||||
@@ -51,6 +77,10 @@ public sealed class LabSimulation
|
||||
public float Energy { get => energy.Value; set => energy.Value = value; }
|
||||
public bool LowEnergyWarning => energy.LowWarning;
|
||||
public event Action<int>? EnergySound;
|
||||
public event Action<int,bool>? GadgetSound;
|
||||
public event Action? BubbleSoundStopped;
|
||||
public event Action<int>? ScoreChanged;
|
||||
public event Action? DefaultGadgetRequested;
|
||||
//Source260/live15C serves both body collision and contact tests. The name
|
||||
//predates source-body integration; burst100 is not an interaction-only size.
|
||||
public float InteractionRadius { get; private set; } = 60;
|
||||
@@ -76,6 +106,7 @@ public sealed class LabSimulation
|
||||
public float TurnRate { get; private set; }
|
||||
public bool Grounded { get; private set; }
|
||||
public PlayerPose Pose => Noclip ? Velocity.LengthSquared() > 0 ? PlayerPose.Fly : PlayerPose.Idle
|
||||
: GadgetMode == 0 ? bubblePose
|
||||
: pendingImpulse.Y > 0 ? PlayerPose.Jump
|
||||
: Grounded ? Shooting ? PlayerPose.Shoot : Speed < -1 ? PlayerPose.Backpedal : Speed > 1 ? PlayerPose.Run : PlayerPose.Idle
|
||||
: jumpState.JumpState == 3 && jumpState.EffectRemaining > 0 ? PlayerPose.Fly
|
||||
@@ -94,7 +125,8 @@ public sealed class LabSimulation
|
||||
public Vector3 ActorRoot => Position + Vector3.UnitY * rootHeight;
|
||||
public Vector3 CameraEye { get; private set; }
|
||||
public Vector3 CameraTarget => ActorRoot + new Vector3(0, 99, 0);
|
||||
public Matrix4x4 Model => Matrix4x4.CreateRotationY(-Yaw * MathF.PI / 180)
|
||||
public Matrix4x4 Model => Matrix4x4.CreateRotationZ(-(TracksBubbleOrientation?Roll:0) * MathF.PI / 180)
|
||||
* Matrix4x4.CreateRotationX(-(TracksBubbleOrientation?Pitch:0) * MathF.PI / 180) * Matrix4x4.CreateRotationY(-Yaw * MathF.PI / 180)
|
||||
* Matrix4x4.CreateTranslation(Position - new Vector3(0, modelMinimumY, 0));
|
||||
|
||||
public LabSimulation(SceneCollision collision, Mesh standingPose, Vector3 start, float yaw,
|
||||
@@ -107,6 +139,8 @@ public sealed class LabSimulation
|
||||
this.ceilingRay = ceilingRay;
|
||||
originalBody = originalCollision == null ? null : new OriginalBodyPhysics(originalCollision);
|
||||
this.energy = energy ?? new PlayerEnergy();
|
||||
Invisible.AlphaRequested += Appearance.SetAlpha;
|
||||
Invisible.BlendRequested += Appearance.SetBlend;
|
||||
sourceStart = start;
|
||||
startYaw = yaw;
|
||||
var bounds = standingPose.Bounds();
|
||||
@@ -124,8 +158,13 @@ public sealed class LabSimulation
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
if (gadgetMode == 0) { GadgetMode=-1; DefaultGadgetRequested?.Invoke(); }
|
||||
if (gadgetMode == 2) gadgetMode = -1;
|
||||
Invisible.Reset();
|
||||
Bubble.Reset(); FloorState.Reset(); Appearance.Reset(); retainedSupportMaterial=null;
|
||||
Pitch=Roll=targetPitch=targetRoll=0; BubbleBounces=0;
|
||||
TracksBubbleOrientation=false;
|
||||
MaximumSpeed=RecoveredMotion.MaximumSpeed; BodyFactor=OriginalBodySupport.JimmyFactor;
|
||||
var floor = collision.GroundHeight(sourceStart, 2500)!.Value;
|
||||
Position = new(sourceStart.X, floor + (UsesOriginalBody ? 0 : SceneCollision.Skin), sourceStart.Z);
|
||||
Velocity = Vector3.Zero;
|
||||
@@ -183,24 +222,35 @@ public sealed class LabSimulation
|
||||
|
||||
public void Step(PlayerInput input, bool controlled = true, bool? anyControlled = null)
|
||||
{
|
||||
if (Noclip) { StepNoclip(input); return; }
|
||||
if (Noclip)
|
||||
{
|
||||
StepNoclip(input);
|
||||
Bubble.Step(FixedStepClock.Step); //Modern flight skips body/input, not the released owned sprite's fade.
|
||||
return;
|
||||
}
|
||||
//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 (controlled && !InputAfterPlayerUpdate) StepInput(input);
|
||||
//42469F..4246DC reasserts ordinary grounded radius before ownership
|
||||
//checks. Bubble mode0's separate radius160 policy remains unimplemented.
|
||||
if (Grounded) InteractionRadius = 60;
|
||||
//42469F..4246DC runs independently of raw ownership.
|
||||
if (Grounded)
|
||||
{
|
||||
InteractionRadius = GadgetMode == 0 ? 160 : 60;
|
||||
if (GadgetMode==0) bubblePose=PlayerPose.Idle;
|
||||
}
|
||||
//424BE0..424C34 runs this wrapper before437940's ownership gate.
|
||||
StepCeiling();
|
||||
StepFloorPolicy(); //437940's base40E050, before the input-identity gate.
|
||||
if (controlled) StepPlayer(input);
|
||||
Invisible.Step(FixedStepClock.Step, anyControlled ?? controlled, input.Fire, input.Jump,
|
||||
Energy, IgnoresGadgetEnergy, AdjustEnergy);
|
||||
if (LevelCode == "VR01") FloorState.Step(FixedStepClock.Step,Appearance.SetColor);
|
||||
var effect = JetpackBurst.StepEffect(jumpState, Grounded, FixedStepClock.Step, Energy, LevelCode);
|
||||
jumpState = effect.State; JetpackEffectVisible = effect.Visible;
|
||||
if (effect.Visible) AdjustEnergy(-FixedStepClock.Step * JetpackBurst.EnergyPerSecond);
|
||||
EffectSteps++;
|
||||
Bubble.Step(FixedStepClock.Step); //Owned effect clock is not Jimmy input ownership.
|
||||
if (controlled && InputAfterPlayerUpdate) StepInput(input);
|
||||
Steps++;
|
||||
}
|
||||
@@ -216,6 +266,37 @@ public sealed class LabSimulation
|
||||
public void SetShooting(bool shooting) => Shooting = shooting;
|
||||
public void AdjustEnergy(float delta) => energy.Adjust(delta, LevelCode, id => EnergySound?.Invoke(id));
|
||||
|
||||
private void ReleaseBubble()
|
||||
{
|
||||
movementMode=0; MaximumSpeed=650;
|
||||
Bubble.Stop(); Bubble.ClearExpansion();
|
||||
if (bubbleLoop) BubbleSoundStopped?.Invoke();
|
||||
bubbleLoop=false; InteractionRadius=60; BodyFactor=OriginalBodySupport.JimmyFactor;
|
||||
}
|
||||
|
||||
public void FlattenOrientation() { Pitch=Roll=0; }
|
||||
public void SeedBubbleTilt(Vector3 euler)
|
||||
{
|
||||
if (TracksBubbleOrientation) return;
|
||||
Pitch=targetPitch=euler.X; Roll=targetRoll=euler.Z;
|
||||
}
|
||||
|
||||
private void StepFloorPolicy()
|
||||
{
|
||||
if (LevelCode!="VR01" || originalBody==null) return;
|
||||
var effect=FloorState.Visit(retainedSupportMaterial,GadgetMode);
|
||||
if (effect.Entered)
|
||||
{ GadgetSound?.Invoke(39,false); if (GadgetMode!=0) GadgetSound?.Invoke(190,false); }
|
||||
if (!effect.Damaged) return;
|
||||
AdjustEnergy(-5); ScoreChanged?.Invoke(-5); CancelPoweredFlight();
|
||||
}
|
||||
|
||||
private void CancelPoweredFlight()
|
||||
{
|
||||
if (movementMode!=1) return;
|
||||
jumpState=jumpState with {JumpState=0,EffectRemaining=0}; forceFall=true;
|
||||
}
|
||||
|
||||
private void StepCeiling()
|
||||
{
|
||||
if (Velocity.Y <= 0 || ceilingRay == null
|
||||
@@ -224,9 +305,7 @@ public sealed class LabSimulation
|
||||
CeilingHits++;
|
||||
//425120 leaves hold, mode, pending impulse and acceleration intact.
|
||||
//Full sound/selected-gadget cleanup callbacks remain a separate gap.
|
||||
if (movementMode != 1) return;
|
||||
jumpState = jumpState with { JumpState = 0, EffectRemaining = 0 };
|
||||
forceFall = true;
|
||||
CancelPoweredFlight();
|
||||
}
|
||||
|
||||
/// <summary>Authored AI root/Euler writes. They do not reset body motion or
|
||||
@@ -244,6 +323,7 @@ public sealed class LabSimulation
|
||||
if (enabled == Noclip) return false;
|
||||
if (enabled)
|
||||
{
|
||||
if (gadgetMode==0) { GadgetMode=-1; DefaultGadgetRequested?.Invoke(); }
|
||||
noclipEntry = Position; noclipEntryYaw = Yaw; HasNoclipEntry = true;
|
||||
}
|
||||
var returned = !enabled && !collision.CanOccupy(Position, BodyRadius, BodyHeight);
|
||||
@@ -257,6 +337,7 @@ public sealed class LabSimulation
|
||||
|
||||
public void StopDebugMotion()
|
||||
{
|
||||
if (gadgetMode==0) { GadgetMode=-1; DefaultGadgetRequested?.Invoke(); }
|
||||
Shooting = false;
|
||||
Velocity = pendingImpulse = Vector3.Zero;
|
||||
Speed = PublishedSpeed = TurnRate = extraAirAcceleration = lateralContribution = 0;
|
||||
@@ -298,23 +379,41 @@ 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); }
|
||||
else if (input.Right) { yawDelta -= 20; lateralContribution = 1000; Speed = RecoveredMotion.AddSpeed(Speed); }
|
||||
if (input.Forward) { yawDelta *= 0.5f; Speed = RecoveredMotion.AddSpeed(Speed); }
|
||||
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);
|
||||
}
|
||||
else if (movementMode==2)
|
||||
{
|
||||
var steering=BubbleMotion.StepInput(Speed,TurnRate,input,Grounded,dt,MaximumSpeed);
|
||||
Speed=steering.Speed; TurnRate=steering.TurnRate;
|
||||
targetPitch=steering.TargetPitch; targetRoll=steering.TargetRoll; targetYaw=Yaw;
|
||||
}
|
||||
else
|
||||
{
|
||||
var steering = AirSteering.Step(Speed, TurnRate, input, dt);
|
||||
var steering = AirSteering.Step(Speed, TurnRate, input, dt,MaximumSpeed);
|
||||
Speed = steering.Speed; TurnRate = steering.TurnRate;
|
||||
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.
|
||||
targetYaw = Yaw;
|
||||
}
|
||||
StepCamera(); //438BC0/439900 input path owns follow; still provisional geometry/state.
|
||||
if (movementMode==2)
|
||||
{
|
||||
AdjustEnergy(-dt*.5f);
|
||||
if (Energy<=0) { GadgetMode=-1; DefaultGadgetRequested?.Invoke(); }
|
||||
//4262A5 continues placement even if depletion just cleaned the mode.
|
||||
var direction=ActorRoot+Vector3.UnitY*100-CameraEye;
|
||||
direction=direction.LengthSquared()>0 ? Vector3.Normalize(direction) : Vector3.Zero;
|
||||
BubbleRoot=ActorRoot+Vector3.UnitY*50-direction*80;
|
||||
}
|
||||
InputActions?.Invoke(input);
|
||||
}
|
||||
|
||||
@@ -322,6 +421,18 @@ public sealed class LabSimulation
|
||||
{
|
||||
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);
|
||||
Velocity=bubble.Velocity; Yaw=bubble.Yaw; Speed=bubble.Speed; PublishedSpeed=Speed;
|
||||
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
|
||||
@@ -405,7 +516,8 @@ public sealed class LabSimulation
|
||||
throw new NotSupportedException("Original ordinary-body subset cannot use the provisional dynamic resolver");
|
||||
var before = Position;
|
||||
var result = originalBody!.Step(new(ActorRoot, Velocity, Vector3.UnitY * extraAirAcceleration,
|
||||
pendingImpulse, Grounded, PublishedSpeed), FixedStepClock.Step, InteractionRadius);
|
||||
pendingImpulse, Grounded, PublishedSpeed), FixedStepClock.Step, InteractionRadius,BodyFactor);
|
||||
if (result.SupportHit is { } hit) retainedSupportMaterial=originalBody.MaterialFor(hit);
|
||||
Position = result.Body.Position - Vector3.UnitY * rootHeight;
|
||||
Velocity = result.Body.Velocity;
|
||||
pendingImpulse = result.Body.Impulse;
|
||||
|
||||
Reference in new issue
Block a user