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
@@ -11,9 +11,11 @@ public static class AirSteering
|
||||
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)
|
||||
public static AirSteeringResult Step(float speed, float turnRate, PlayerInput input, float seconds,
|
||||
float maximumSpeed = RecoveredMotion.MaximumSpeed)
|
||||
{
|
||||
if (!float.IsFinite(speed) || !float.IsFinite(turnRate) || !float.IsFinite(seconds) || seconds < 0 || seconds >= 1)
|
||||
if (!float.IsFinite(speed) || !float.IsFinite(turnRate) || !float.IsFinite(seconds)
|
||||
|| !float.IsFinite(maximumSpeed) || maximumSpeed<=0 || seconds < 0 || seconds >= 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(seconds));
|
||||
var turnStep = TurnAcceleration * seconds;
|
||||
if (input.Left) turnRate += turnStep;
|
||||
@@ -22,8 +24,8 @@ public static class AirSteering
|
||||
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)
|
||||
if (input.Forward) speed = RecoveredMotion.AddSpeed(speed,maximumSpeed);
|
||||
else if (speed > maximumSpeed * CoastThreshold)
|
||||
speed -= RecoveredMotion.SpeedDecay * .5f;
|
||||
//439C1D..439CB2 brakes to0, without starting reverse flight.
|
||||
if (input.Backward)
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace GamePort.Game;
|
||||
|
||||
/// <summary>Owned C3DBubble sprite transitions (410AE0/410CA0/410D00).
|
||||
/// The caller owns equip, cleanup, placement and callback scheduling.</summary>
|
||||
public sealed class BubbleEffect(bool conventionalBlend = false)
|
||||
{
|
||||
public bool Visible { get; private set; }
|
||||
public bool Active { get; private set; }
|
||||
public bool Expanding { get; private set; }
|
||||
public bool Collapsing { get; private set; }
|
||||
public float Timer { get; private set; }
|
||||
public Vector4 Color { get; private set; } = conventionalBlend ? new(.9f, .9f, .9f, 1) : Vector4.One;
|
||||
public float Width { get; private set; } = 200;
|
||||
public float Height { get; private set; } = 200;
|
||||
public bool ConventionalBlend { get; } = conventionalBlend;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
// Source equip rejects all three flags before calling this leaf.
|
||||
Expanding = true;
|
||||
Timer = 0;
|
||||
Visible = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
// Source410D00 leaves expansion alone. Jimmy cleanup clears it separately.
|
||||
Collapsing = true;
|
||||
Active = false;
|
||||
Timer = 0;
|
||||
}
|
||||
|
||||
public void ClearExpansion() => Expanding = false;
|
||||
|
||||
public void Step(float seconds)
|
||||
{
|
||||
if (!float.IsFinite(seconds) || seconds < 0 || seconds >= 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(seconds));
|
||||
//410AF2 stores float timer but retains the addition on the x87 stack
|
||||
//for the fade comparisons. Preserve that distinction at strict boundaries.
|
||||
var sum = (double)Timer + seconds;
|
||||
Timer = (float)sum;
|
||||
if (Active)
|
||||
{
|
||||
Width = 240;
|
||||
Height = (float)(240 + Math.Sin((double)Timer * 10) * 30);
|
||||
if (ConventionalBlend) Color = new(1, 1, 1, .5f);
|
||||
}
|
||||
else if (Expanding)
|
||||
{
|
||||
var scalar = (float)sum;
|
||||
if (sum > 1) { scalar = 1; Active = true; Expanding = false; }
|
||||
Color = new(scalar);
|
||||
}
|
||||
else if (Collapsing)
|
||||
{
|
||||
var fade = 1 - sum;
|
||||
var scalar = (float)fade;
|
||||
if (fade < 0) { scalar = 0; Collapsing = false; Visible = false; }
|
||||
Color = new(scalar);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Visible = Active = Expanding = Collapsing = false;
|
||||
Timer = 0;
|
||||
Color = ConventionalBlend ? new(.9f, .9f, .9f, 1) : Vector4.One;
|
||||
Width = Height = 200;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace GamePort.Game;
|
||||
|
||||
public readonly record struct BubbleSteering(float Speed, float TurnRate, float TargetPitch, float TargetRoll);
|
||||
public readonly record struct BubbleApply(Vector3 Velocity, float Yaw, float Speed, bool Boing);
|
||||
|
||||
/// <summary>
|
||||
/// Keyboard subset of mode2 input439900 and apply4387E0. Body integration,
|
||||
/// impulses, acceleration and gadget lifetime belong to their existing phases.
|
||||
/// Source ownership and precision limits: docs/gameplay/bubble-motion.md.
|
||||
/// </summary>
|
||||
public static class BubbleMotion
|
||||
{
|
||||
public const float MaximumSpeed = 1350;
|
||||
public const float TurnLimit = 50;
|
||||
public const float ReleasedBounceSpeed = 300;
|
||||
public const float HeldBounceSpeed = 900;
|
||||
|
||||
public static BubbleSteering StepInput(float speed, float turn, PlayerInput input,
|
||||
bool supported, float seconds, float maximumSpeed = MaximumSpeed)
|
||||
{
|
||||
Validate(speed, turn, seconds);
|
||||
if (!float.IsFinite(maximumSpeed) || maximumSpeed <= 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(maximumSpeed));
|
||||
|
||||
var turnStep = AirSteering.TurnAcceleration * seconds;
|
||||
if (input.Left) turn += turnStep;
|
||||
else if (input.Right) turn -= turnStep;
|
||||
else if (turn < 0) turn = MathF.Min(0, turn + turnStep);
|
||||
else if (turn > 0) turn = MathF.Max(0, turn - turnStep);
|
||||
|
||||
//439ABB..439AE6: mode2 also uses the shared fire predicate as throttle.
|
||||
var forward = input.Forward || input.Fire;
|
||||
if (forward && speed < maximumSpeed)
|
||||
speed = MathF.Min(maximumSpeed, speed + RecoveredMotion.SpeedIncrement);
|
||||
if (!forward && speed > maximumSpeed * AirSteering.CoastThreshold)
|
||||
speed -= RecoveredMotion.SpeedDecay * .5f;
|
||||
|
||||
//439BA2..439BED: this subtraction deliberately has no crossing clamp.
|
||||
if (supported) speed = speed > 0 ? speed - RecoveredMotion.SpeedDecay * .5f : 0;
|
||||
if (input.Backward)
|
||||
{
|
||||
if (speed > 0)
|
||||
speed = MathF.Max(0, speed - RecoveredMotion.SpeedDecay * (supported ? 1 : .5f));
|
||||
else if (speed < 0)
|
||||
speed = MathF.Min(0, speed + RecoveredMotion.SpeedDecay);
|
||||
}
|
||||
|
||||
turn = Math.Clamp(turn, -TurnLimit, TurnLimit);
|
||||
return new(speed, turn, forward ? -10 : input.Backward ? 10 : 0, -.25f * turn);
|
||||
}
|
||||
|
||||
public static BubbleApply StepApply(float speed, float turn, float yaw, float pitch,
|
||||
Vector3 velocity, bool supported, bool jump, float seconds)
|
||||
{
|
||||
Validate(speed, turn, seconds);
|
||||
if (!float.IsFinite(yaw) || !float.IsFinite(pitch)
|
||||
|| !float.IsFinite(velocity.X) || !float.IsFinite(velocity.Y) || !float.IsFinite(velocity.Z))
|
||||
throw new ArgumentOutOfRangeException(nameof(velocity));
|
||||
|
||||
float sideSpeed = 0;
|
||||
//43884E..4388AE: test incoming velocity before replacing its X/Z.
|
||||
if (velocity != Vector3.Zero)
|
||||
{
|
||||
yaw += turn * seconds;
|
||||
const float friction = .8f;
|
||||
sideSpeed = turn * .0181818176060915f * (1 - friction) * speed;
|
||||
}
|
||||
var (sin, cos) = LabSimulation.Trig(yaw);
|
||||
var forwardSpeed = LabSimulation.Trig(pitch).Cos * speed;
|
||||
velocity = new(-sin * forwardSpeed + cos * sideSpeed, velocity.Y,
|
||||
cos * forwardSpeed + sin * sideSpeed);
|
||||
|
||||
//43899A..438A50: direct liveY assignment, after composing current X/Z.
|
||||
//Only the published scalar halves; current velocity keeps pre-half X/Z.
|
||||
if (supported)
|
||||
{
|
||||
velocity.Y = jump ? HeldBounceSpeed : ReleasedBounceSpeed;
|
||||
if (!jump) speed *= .5f;
|
||||
}
|
||||
return new(velocity, yaw, speed, supported && jump);
|
||||
}
|
||||
|
||||
private static void Validate(float speed, float turn, float seconds)
|
||||
{
|
||||
if (!float.IsFinite(speed) || !float.IsFinite(turn) || !float.IsFinite(seconds)
|
||||
|| seconds < 0 || seconds >= 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(seconds));
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace GamePort.Game;
|
||||
public readonly record struct GadgetCanvas(int Id, Vector2 Position);
|
||||
|
||||
/// <summary>Bounded group0 gadget panel; source425870/425EF0/425B20/427370.</summary>
|
||||
public sealed class GadgetScreen(SceneInventory inventory)
|
||||
public sealed class GadgetScreen(SceneInventory inventory, Func<int>? rawMode = null)
|
||||
{
|
||||
public static IReadOnlyList<Vector2> Positions { get; } = Array.AsReadOnly<Vector2>([new(12,182), new(158,182), new(12,327), new(157,327),
|
||||
new(342,182), new(487,182), new(342,327), new(487,327)]);
|
||||
@@ -24,7 +24,7 @@ public sealed class GadgetScreen(SceneInventory inventory)
|
||||
{
|
||||
if (Open) { Close(); return true; }
|
||||
if (!permitted) return false;
|
||||
if (EquippedMode(inventory.SelectedGadget) != -1)
|
||||
if ((rawMode?.Invoke() ?? EquippedMode(inventory.SelectedGadget)) != -1)
|
||||
{
|
||||
inventory.SelectGadget(-1); Changed?.Invoke(); return true;
|
||||
}
|
||||
@@ -72,7 +72,8 @@ public sealed class GadgetScreen(SceneInventory inventory)
|
||||
var item = Hovered;
|
||||
var practice = PracticeArmed;
|
||||
Close();
|
||||
inventory.SelectGadget(item);
|
||||
//428F61 loads Bubble practice BEFORE live radius/mode/effect setup.
|
||||
inventory.SelectGadget(item,equip:!(practice && item==0));
|
||||
if (practice) PracticeRequested?.Invoke(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ public sealed class InvisibleGadget
|
||||
public int Activations { get; private set; }
|
||||
public bool Active => Equipped && !Targetable;
|
||||
public event Action<bool>? EquippedChanged;
|
||||
public event Action<float>? AlphaRequested;
|
||||
public event Action<bool>? BlendRequested;
|
||||
|
||||
public bool Equip(float energy, bool energyOverride)
|
||||
{
|
||||
@@ -30,6 +32,8 @@ public sealed class InvisibleGadget
|
||||
|
||||
public void Release()
|
||||
{
|
||||
BlendRequested?.Invoke(true);
|
||||
AlphaRequested?.Invoke(0);
|
||||
Equipped = false; Remaining = Duration; Recharge = 0;
|
||||
Targetable = true; Opacity = 1; ConventionalBlend = false;
|
||||
MeterVisible = false; MeterReady = false;
|
||||
@@ -62,6 +66,7 @@ public sealed class InvisibleGadget
|
||||
adjustEnergy(-2);
|
||||
Remaining = Duration; Recharge = 0; Activations++;
|
||||
ConventionalBlend = false; Opacity = .7f; Targetable = false;
|
||||
BlendRequested?.Invoke(false); AlphaRequested?.Invoke(.7f);
|
||||
}
|
||||
}
|
||||
if (Remaining == 0 && (energy > 0 || energyOverride))
|
||||
@@ -79,9 +84,13 @@ public sealed class InvisibleGadget
|
||||
{
|
||||
Remaining = 0; Opacity = 1; Targetable = true;
|
||||
ConventionalBlend = false; MeterReady = false;
|
||||
BlendRequested?.Invoke(true); AlphaRequested?.Invoke(0);
|
||||
return;
|
||||
}
|
||||
if (Remaining <= 3)
|
||||
{
|
||||
ConventionalBlend = ((int)((double)Remaining * 5) & 1) != 0;
|
||||
BlendRequested?.Invoke(ConventionalBlend);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -34,6 +34,8 @@ public sealed class OriginalBodyPhysics
|
||||
this.collision = collision;
|
||||
}
|
||||
|
||||
public int? MaterialFor(SupportHit hit) => collision.MaterialFor(hit);
|
||||
|
||||
public OrdinaryBodyStep Step(OrdinaryBodyState body, float seconds,
|
||||
float radius = OriginalBodySupport.JimmyRadius, float factor = OriginalBodySupport.JimmyFactor,
|
||||
float friction = .8f, float suppressionScale = .5f, bool geometryEnabled = true)
|
||||
|
||||
@@ -58,15 +58,15 @@ public sealed class OriginalCameraRay
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LV1B/VR04/LEV1 complete game slot134 is475CD0 (false), so only the proven
|
||||
/// LV1B/VR01/VR04/LEV1 complete game slot134 is475CD0 (false), so only the proven
|
||||
/// NC/checkpoint gates apply. Reject other levels rather than inventing masks.
|
||||
/// Prepared source metadata is required; raw render visibility is irrelevant.
|
||||
/// </summary>
|
||||
public static OriginalCameraRay FromRouteScene(Mesh mesh, string levelCode)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(mesh);
|
||||
if (levelCode is not ("LV1B" or "VR04" or "LEV1"))
|
||||
throw new NotSupportedException("Static camera game-filter recovery currently covers LV1B, VR04 and LEV1");
|
||||
if (levelCode is not ("LV1B" or "VR01" or "VR04" or "LEV1"))
|
||||
throw new NotSupportedException("Static camera game-filter recovery covers the route and VR01");
|
||||
if (mesh.Indices.Length % 3 != 0 || mesh.CollisionPolygons.Length != mesh.Indices.Length / 3)
|
||||
throw new InvalidDataException("Original camera query requires source polygon metadata");
|
||||
var polygons = new CameraRayPolygon[mesh.CollisionPolygons.Length];
|
||||
|
||||
@@ -23,6 +23,7 @@ public sealed class OriginalStaticCollision
|
||||
{
|
||||
private readonly Dictionary<int, List<CameraRayPolygon>> walls = [];
|
||||
private readonly Dictionary<int, List<SupportTriangle>> all = [];
|
||||
private readonly Dictionary<(int Shape,int Polygon),int?> materialIds = [];
|
||||
public int PolygonCount { get; }
|
||||
public int WallPolygonCount { get; }
|
||||
public bool HasSpecialPlayerContacts { get; }
|
||||
@@ -38,6 +39,7 @@ public sealed class OriginalStaticCollision
|
||||
Finite(t.A); Finite(t.B); Finite(t.C); Finite(polygon.StoredNormal);
|
||||
if (!identities.Add((t.ShapeId, t.PolygonId)))
|
||||
throw new InvalidDataException("Source static collision needs one triangle per polygon");
|
||||
materialIds.Add((t.ShapeId,t.PolygonId),polygon.MaterialId);
|
||||
var min = Vector3.Min(t.A, Vector3.Min(t.B, t.C));
|
||||
var max = Vector3.Max(t.A, Vector3.Max(t.B, t.C));
|
||||
foreach (var cell in Rectangle(new(Cell(min.X), Cell(max.X), Cell(min.Z), Cell(max.Z))))
|
||||
@@ -59,8 +61,8 @@ public sealed class OriginalStaticCollision
|
||||
public static OriginalStaticCollision FromRouteScene(Mesh mesh, string level)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(mesh);
|
||||
if (level is not ("LV1B" or "VR04" or "LEV1"))
|
||||
throw new NotSupportedException("Original static game-filter recovery covers only the three route scenes");
|
||||
if (level is not ("LV1B" or "VR01" or "VR04" or "LEV1"))
|
||||
throw new NotSupportedException("Original static game-filter recovery covers the route and VR01");
|
||||
if (mesh.Indices.Length % 3 != 0 || mesh.CollisionPolygons.Length != mesh.Indices.Length / 3)
|
||||
throw new InvalidDataException("Source static collision requires original polygon metadata");
|
||||
if (!mesh.HasCollisionMaterialIds)
|
||||
@@ -76,6 +78,8 @@ public sealed class OriginalStaticCollision
|
||||
}));
|
||||
}
|
||||
|
||||
public int? MaterialFor(SupportHit hit) => materialIds.GetValueOrDefault((hit.ShapeId,hit.PolygonId));
|
||||
|
||||
public StaticCollisionMove Move(Vector3 previous, Vector3 delta, float radius,
|
||||
StaticCollisionContext context, bool edges = true, bool lowerEdges = false, bool geometryEnabled = true)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Numerics;
|
||||
using GamePort.Assets;
|
||||
|
||||
namespace GamePort.Game;
|
||||
|
||||
/// <summary>Stored current-atlas material state. Source alpha/FC requests and
|
||||
/// late direct RGBA writes have different owners and must retain their order.</summary>
|
||||
public sealed class PlayerAppearance
|
||||
{
|
||||
public Vector4 Color { get; private set; } = Vector4.One;
|
||||
public bool BlendEnabled { get; private set; }
|
||||
public bool Conventional { get; private set; }
|
||||
public MeshBlend Blend => !BlendEnabled ? MeshBlend.Opaque : Conventional ? MeshBlend.Alpha : MeshBlend.Additive;
|
||||
|
||||
public void SetAlpha(float alpha)
|
||||
{
|
||||
if (!float.IsFinite(alpha) || alpha > 1) throw new ArgumentOutOfRangeException(nameof(alpha));
|
||||
BlendEnabled = alpha > 0;
|
||||
Color = alpha > 0 ? new(1,1,1,alpha) : Vector4.One;
|
||||
Conventional = alpha <= 0;
|
||||
}
|
||||
public void SetBlend(bool conventional) => Conventional = conventional;
|
||||
public void SetColor(Vector4 color)
|
||||
{
|
||||
if (!float.IsFinite(color.X+color.Y+color.Z+color.W)
|
||||
|| color.X<0 || color.Y<0 || color.Z<0 || color.W<0 || color.W>1)
|
||||
throw new ArgumentOutOfRangeException(nameof(color));
|
||||
Color = color;
|
||||
}
|
||||
public void Reset() { Color=Vector4.One; BlendEnabled=false; Conventional=false; }
|
||||
}
|
||||
@@ -20,6 +20,7 @@ public sealed class PlayerSceneBinding : IDisposable
|
||||
director.GadgetReleaseRequested += Release;
|
||||
inventory.GadgetSelected += Selected;
|
||||
player.Invisible.EquippedChanged += InvisibleEquipped;
|
||||
player.DefaultGadgetRequested += DefaultGadget;
|
||||
Selected(inventory.SelectedGadget);
|
||||
}
|
||||
|
||||
@@ -27,8 +28,10 @@ public sealed class PlayerSceneBinding : IDisposable
|
||||
{
|
||||
var acceptsInput = director.Controlled || player.Noclip;
|
||||
player.Step(input, acceptsInput, director.ControlledTag != null);
|
||||
var rotation = director.FindActor(tag)?.Rotation ?? Vector3.Zero;
|
||||
director.SyncActor(tag, player.ActorRoot, rotation with { Y = player.Yaw });
|
||||
if (player.GadgetMode==0 && player.Grounded && director.FindActor(tag) is{} actor) actor.Animation="STOP";
|
||||
var rotation=director.FindActor(tag)?.Rotation ?? Vector3.Zero;
|
||||
director.SyncActor(tag,player.ActorRoot,player.TracksBubbleOrientation
|
||||
? new(player.Pitch,player.Yaw,player.Roll) : rotation with{Y=player.Yaw});
|
||||
return acceptsInput;
|
||||
}
|
||||
|
||||
@@ -36,6 +39,7 @@ public sealed class PlayerSceneBinding : IDisposable
|
||||
{
|
||||
if (!string.Equals(actor.Tag, tag, StringComparison.OrdinalIgnoreCase)) return;
|
||||
if (action == ScriptPreparation.StopMotion) player.PrepareForScript();
|
||||
else if (action == ScriptPreparation.FlattenOrientation) player.FlattenOrientation();
|
||||
else if (action == ScriptPreparation.ReleaseGadget)
|
||||
Release(actor);
|
||||
}
|
||||
@@ -45,12 +49,17 @@ public sealed class PlayerSceneBinding : IDisposable
|
||||
if (!string.Equals(actor.Tag, tag, StringComparison.OrdinalIgnoreCase)) return;
|
||||
//427FF0 switches raw mode, not display selection. A rejected Invisible
|
||||
//equip can leave display2 with raw mode-1; cleanup does not equip it.
|
||||
if (player.GadgetMode == 2 || inventory.SelectedGadget is -1 or 3)
|
||||
if (player.GadgetMode is 0 or 2 || inventory.SelectedGadget is -1 or 3)
|
||||
{ inventory.SelectGadget(-1); player.GadgetMode = -1; }
|
||||
else if (player.GadgetMode != -1) UnsupportedGadgetCleanups++;
|
||||
}
|
||||
|
||||
private void Selected(int item) => player.GadgetMode = GadgetScreen.EquippedMode(item);
|
||||
private void Selected(int item)
|
||||
{
|
||||
if (item==0 && director.FindActor(tag) is{} actor) player.SeedBubbleTilt(actor.Rotation);
|
||||
player.GadgetMode=GadgetScreen.EquippedMode(item);
|
||||
}
|
||||
private void DefaultGadget() => inventory.SelectGadget(-1);
|
||||
|
||||
private void InvisibleEquipped(bool equipped)
|
||||
{
|
||||
@@ -74,5 +83,6 @@ public sealed class PlayerSceneBinding : IDisposable
|
||||
director.GadgetReleaseRequested -= Release;
|
||||
inventory.GadgetSelected -= Selected;
|
||||
player.Invisible.EquippedChanged -= InvisibleEquipped;
|
||||
player.DefaultGadgetRequested -= DefaultGadget;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ 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) => MathF.Min(speed + SpeedIncrement, MaximumSpeed);
|
||||
public static float AddSpeed(float speed, float maximumSpeed = MaximumSpeed) => MathF.Min(speed + SpeedIncrement, maximumSpeed);
|
||||
public static float ReleaseSpeed(float speed) => speed > 0
|
||||
? MathF.Max(0, speed - SpeedDecay) : MathF.Min(0, speed + SpeedDecay);
|
||||
|
||||
|
||||
@@ -54,12 +54,12 @@ public sealed class SceneInventory
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectGadget(int item)
|
||||
public void SelectGadget(int item, bool equip = true)
|
||||
{
|
||||
if (item != -1 && (item is < 0 or >= 9 || State(0, item) == 0))
|
||||
throw new ArgumentOutOfRangeException(nameof(item), "Gadget is outside the recovered group or unavailable");
|
||||
SelectedGadget = item;
|
||||
GadgetSelected?.Invoke(item);
|
||||
if (equip) GadgetSelected?.Invoke(item);
|
||||
}
|
||||
|
||||
public int[] Snapshot() => states.ToArray();
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace GamePort.Game;
|
||||
|
||||
public readonly record struct Vr01FloorEffect(bool Entered, bool Damaged);
|
||||
|
||||
/// <summary>Textured retained-support callback for actual VR01 IDs0..4/111.
|
||||
/// Other damage flags, floor classes and footstep-loop playback remain outside.</summary>
|
||||
public sealed class Vr01FloorState
|
||||
{
|
||||
public bool InLava { get; private set; }
|
||||
public bool Flashing { get; private set; }
|
||||
public float Timer { get; private set; }
|
||||
public int SoundSelector { get; private set; } = 5;
|
||||
public Vr01FloorEffect Visit(int? material, int rawMode)
|
||||
{
|
||||
//Null means no eligible textured support. The actual VR01 profile's
|
||||
//used material IDs all have source-verified texture links.
|
||||
if (material == null) return default;
|
||||
if (material is not (0 or 1 or 2 or 3 or 4 or 111))
|
||||
throw new NotSupportedException("Outside the recovered VR01 floor profile");
|
||||
var lava = material == 111;
|
||||
var entered = lava && !InLava;
|
||||
var damaged = lava && !Flashing && rawMode != 0;
|
||||
InLava = lava; SoundSelector = lava ? 35 : 5;
|
||||
if (damaged) { Flashing=true; Timer=0; }
|
||||
return new(entered,damaged);
|
||||
}
|
||||
public void Step(float seconds, Action<Vector4> color)
|
||||
{
|
||||
if (!float.IsFinite(seconds) || seconds<0 || seconds>=1) throw new ArgumentOutOfRangeException(nameof(seconds));
|
||||
ArgumentNullException.ThrowIfNull(color);
|
||||
if (!Flashing) return;
|
||||
var sum = (double)Timer + seconds;
|
||||
Timer = (float)sum;
|
||||
if (sum>4) { Flashing=false; color(Vector4.One); return; }
|
||||
var pulse = (float)((Math.Sin(sum*20)+1)*.5);
|
||||
color(new(pulse,1,pulse,1));
|
||||
}
|
||||
public void Reset() { InLava=Flashing=false; Timer=0; SoundSelector=5; }
|
||||
}
|
||||
Reference in new issue
Block a user