Run body and fire phases during scripted control locks
This commit is contained in:
1 parent
5876da112c
commit
c285b57091
35 files changed
+1503
-45
No files matched your search
@@ -57,6 +57,9 @@ public sealed class LabSimulation
|
||||
: jumpState.JumpState == 3 && jumpState.EffectRemaining > 0 ? PlayerPose.Fly
|
||||
: !forceFall && Velocity.Y > 0 ? PlayerPose.Jump : PlayerPose.Fall;
|
||||
public int Steps { get; private set; }
|
||||
public int PhysicsSteps { get; private set; }
|
||||
public int ControllerSteps { get; private set; }
|
||||
public int EffectSteps { get; private set; }
|
||||
public int Jumps { get; private set; }
|
||||
public int Landings { get; private set; }
|
||||
public int WallHits { get; private set; }
|
||||
@@ -103,6 +106,7 @@ public sealed class LabSimulation
|
||||
Grounded = true;
|
||||
Noclip = HasNoclipEntry = false;
|
||||
Steps = Jumps = Landings = WallHits = 0;
|
||||
PhysicsSteps = ControllerSteps = EffectSteps = 0;
|
||||
Travel = MaximumRise = 0;
|
||||
CameraEye = DesiredEye().Eye;
|
||||
}
|
||||
@@ -144,21 +148,41 @@ public sealed class LabSimulation
|
||||
return ((float)Math.Sin(radians), (float)Math.Cos(radians));
|
||||
}
|
||||
|
||||
public void Step(PlayerInput input)
|
||||
public void Step(PlayerInput input, bool controlled = true)
|
||||
{
|
||||
if (Noclip) { StepNoclip(input); 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 (!InputAfterPlayerUpdate) StepInput(input);
|
||||
StepPlayer(input);
|
||||
//42469F..4246DC reasserts ordinary grounded radius before ownership
|
||||
//checks. The scooter's separate radius160 policy remains unimplemented.
|
||||
if (Grounded) InteractionRadius = 60;
|
||||
if (controlled && !InputAfterPlayerUpdate) StepInput(input);
|
||||
if (controlled) 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);
|
||||
EffectSteps++;
|
||||
if (controlled && InputAfterPlayerUpdate) StepInput(input);
|
||||
Steps++;
|
||||
}
|
||||
|
||||
/// <summary>43A750 preparation clears speed and velocity XYZ only. Queued
|
||||
/// impulse, acceleration, mode, jump/hold and owned fire timer survive.</summary>
|
||||
public void PrepareForScript()
|
||||
{
|
||||
Speed = 0; Velocity = Vector3.Zero;
|
||||
}
|
||||
|
||||
/// <summary>Authored AI root/Euler writes. They do not reset body motion or
|
||||
/// destination yaw61C; the full logical/render Euler model remains separate.</summary>
|
||||
public void ApplyAuthoredTransform(Vector3 root, float yaw)
|
||||
{
|
||||
if (!float.IsFinite(root.X) || !float.IsFinite(root.Y) || !float.IsFinite(root.Z) || !float.IsFinite(yaw))
|
||||
throw new ArgumentOutOfRangeException(nameof(root));
|
||||
Position = root - Vector3.UnitY * rootHeight; Yaw = yaw;
|
||||
}
|
||||
|
||||
/// <summary>Modern debug movement; never serialized into original save state.</summary>
|
||||
public bool SetNoclip(bool enabled)
|
||||
{
|
||||
@@ -239,6 +263,7 @@ public sealed class LabSimulation
|
||||
|
||||
private void StepPlayer(PlayerInput input)
|
||||
{
|
||||
ControllerSteps++;
|
||||
const float dt = FixedStepClock.Step;
|
||||
var yawError = MathF.IEEERemainder(targetYaw - Yaw, 360);
|
||||
Yaw = (Yaw + yawError * dt * 3.7f) % 360;
|
||||
@@ -249,7 +274,6 @@ public sealed class LabSimulation
|
||||
{
|
||||
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);
|
||||
@@ -277,6 +301,7 @@ public sealed class LabSimulation
|
||||
|
||||
private void StepPhysics()
|
||||
{
|
||||
PhysicsSteps++;
|
||||
const float dt = FixedStepClock.Step;
|
||||
var wasGrounded = Grounded;
|
||||
var velocity = Velocity;
|
||||
@@ -338,5 +363,5 @@ public sealed class LabSimulation
|
||||
step is >= 80 and < 120, step is >= 60 and < 95, false, step < 180);
|
||||
|
||||
public bool SmokePassed => Steps >= 240 && Travel > 50 && MaximumRise > 20 && Jumps > 0 && Landings > 0 && Grounded;
|
||||
public string Report => $"Walk checkpoint: steps={Steps}, travel={Travel:F2}, jumps={Jumps}, landings={Landings}, max rise={MaximumRise:F2}, wall hits={WallHits}, grounded={Grounded}, feet={Position}.";
|
||||
public string Report => $"Walk checkpoint: steps={Steps}, controller={ControllerSteps}, physics={PhysicsSteps}, effect={EffectSteps}, travel={Travel:F2}, jumps={Jumps}, landings={Landings}, max rise={MaximumRise:F2}, wall hits={WallHits}, grounded={Grounded}, feet={Position}.";
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace GamePort.Game;
|
||||
|
||||
/// <summary>Connect recovered raw-owner preparations and authored transforms to
|
||||
/// the port's player body. Full scene scheduling/other actor classes stay separate.</summary>
|
||||
public sealed class PlayerSceneBinding : IDisposable
|
||||
{
|
||||
private readonly SceneDirector director;
|
||||
private readonly LabSimulation player;
|
||||
private readonly SceneInventory inventory;
|
||||
private readonly string tag;
|
||||
public int UnsupportedGadgetCleanups { get; private set; }
|
||||
|
||||
public PlayerSceneBinding(SceneDirector director, LabSimulation player, SceneInventory inventory, string tag)
|
||||
{
|
||||
this.director = director; this.player = player; this.inventory = inventory; this.tag = tag;
|
||||
director.ActorPreparing += Prepare;
|
||||
director.AuthoredTransformChanged += Transform;
|
||||
}
|
||||
|
||||
public bool Step(PlayerInput input)
|
||||
{
|
||||
var acceptsInput = director.Controlled || player.Noclip;
|
||||
player.Step(input, acceptsInput);
|
||||
var rotation = director.FindActor(tag)?.Rotation ?? Vector3.Zero;
|
||||
director.SyncActor(tag, player.ActorRoot, rotation with { Y = player.Yaw });
|
||||
return acceptsInput;
|
||||
}
|
||||
|
||||
private void Prepare(DirectorActor actor, ScriptPreparation action)
|
||||
{
|
||||
if (!string.Equals(actor.Tag, tag, StringComparison.OrdinalIgnoreCase)) return;
|
||||
if (action == ScriptPreparation.StopMotion) player.PrepareForScript();
|
||||
else if (action == ScriptPreparation.ReleaseGadget)
|
||||
{
|
||||
//427FF0 has distinct cases. Only no-selection/jetpack cleanup is
|
||||
//implemented; do not turn the other gadget cases into blanket resets.
|
||||
if (inventory.SelectedGadget is -1 or 3)
|
||||
{ inventory.SelectGadget(-1); player.GadgetMode = -1; }
|
||||
else UnsupportedGadgetCleanups++;
|
||||
}
|
||||
}
|
||||
|
||||
private void Transform(DirectorActor actor)
|
||||
{
|
||||
if (string.Equals(actor.Tag, tag, StringComparison.OrdinalIgnoreCase))
|
||||
player.ApplyAuthoredTransform(actor.Position, actor.Rotation.Y);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
director.ActorPreparing -= Prepare;
|
||||
director.AuthoredTransformChanged -= Transform;
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ public sealed class DirectorActor
|
||||
}
|
||||
|
||||
public sealed record DirectorIssue(string Tag, string Kind, string Detail);
|
||||
public enum ScriptPreparation { StopMotion, ReleaseGadget, FlattenOrientation }
|
||||
|
||||
/// <summary>
|
||||
/// Recovered synchronous AI-trigger dispatch and audio-duration-driven CAM/MCA
|
||||
@@ -71,6 +72,7 @@ public sealed class SceneDirector
|
||||
public List<DirectorActor> Actors { get; } = [];
|
||||
public IReadOnlyList<DirectorIssue> Issues => issues;
|
||||
private string? controlledTag;
|
||||
public string? AuthoredControlledTag => controlledTag;
|
||||
/// <summary>Modern debug override; leaves authored control/camera transitions intact.</summary>
|
||||
public bool DebugForceControl { get; set; }
|
||||
public bool Controlled => Equal(ControlledTag, level.Player?.Tag);
|
||||
@@ -90,6 +92,8 @@ public sealed class SceneDirector
|
||||
public event Action? MusicStopped;
|
||||
public event Action? MusicRestarted;
|
||||
public event Action<DirectorActor>? ActorChanged;
|
||||
public event Action<DirectorActor, ScriptPreparation>? ActorPreparing;
|
||||
public event Action<DirectorActor>? AuthoredTransformChanged;
|
||||
public event Action<string, string>? Unsupported;
|
||||
|
||||
public SceneDirector(GamLevel level, TaskStates tasks, Func<string, int, double> soundDuration)
|
||||
@@ -277,7 +281,7 @@ public sealed class SceneDirector
|
||||
var number = activations.GetValueOrDefault(entity.Offset) + 1;
|
||||
activations[entity.Offset] = number;
|
||||
if (times != -1 && number > times) return;
|
||||
SetControl(entity);
|
||||
SetControl(entity, prepareOwner: true);
|
||||
|
||||
var targetTag = entity.Text("AITarget");
|
||||
if (!IsNone(targetTag))
|
||||
@@ -286,12 +290,13 @@ public sealed class SceneDirector
|
||||
Report(entity.Tag!, entity.Kind, $"AI target {targetTag} absent");
|
||||
else
|
||||
{
|
||||
var transformed = false;
|
||||
var hide = entity.Integer("AIHideObj", -1);
|
||||
if (hide != -1) target.Visible = hide == 0;
|
||||
var positionTag = entity.Text("AINewPos");
|
||||
if (!IsNone(positionTag))
|
||||
{
|
||||
if (actors.TryGetValue(positionTag!, out var marker)) target.Position = marker.Position;
|
||||
if (actors.TryGetValue(positionTag!, out var marker)) { target.Position = marker.Position; transformed = true; }
|
||||
else Report(entity.Tag!, entity.Kind, $"AINewPos {positionTag} absent");
|
||||
}
|
||||
var animation = entity.Text("AIAnim");
|
||||
@@ -302,7 +307,8 @@ public sealed class SceneDirector
|
||||
var patrol = entity.Text("AIPatrol");
|
||||
if (!IsNone(patrol)) target.Patrol = patrol;
|
||||
var yaw = entity.Number("AINewRotY", -1);
|
||||
if (yaw != -1) target.Rotation = target.Rotation with { Y = yaw };
|
||||
if (yaw != -1) { target.Rotation = target.Rotation with { Y = yaw }; transformed = true; }
|
||||
if (transformed) AuthoredTransformChanged?.Invoke(target);
|
||||
ActorChanged?.Invoke(target);
|
||||
if (target.AIstate == 3 && (target.Kind is "3DOG" or "3CAR") && !patrolConsumers.Contains(target.Tag))
|
||||
Report(target.Tag, target.Kind, "Patrol motion/arrival is not yet reconstructed; actor-state callback emitted");
|
||||
@@ -331,15 +337,26 @@ public sealed class SceneDirector
|
||||
private void StartMulti(GamEntity entity)
|
||||
{
|
||||
// MCA's PlayerControlled is its completion target (4311F0), not an
|
||||
// activation grant. Each valid shot clears control at43159E..4315A7.
|
||||
// activation grant. Only initial activation clears control; later shots
|
||||
//use431750 without repeating431502..4315A7 preparation.
|
||||
Toggle(entity);
|
||||
if (IsNone(entity.Text("CameraTarget0"))) return; //431300→431668 returns, not completion.
|
||||
if (skipping) { FinishMulti(entity); return; }
|
||||
//431502 initial activation only. Subsequent431750 shots do not repeat
|
||||
//preparation or clear control. The raw owner guard ignores debug force.
|
||||
PrepareOwner(ScriptPreparation.StopMotion, ScriptPreparation.FlattenOrientation, ScriptPreparation.ReleaseGadget);
|
||||
ControlledTag = null;
|
||||
StartCamera(entity, 0, applyCommon: false);
|
||||
}
|
||||
|
||||
private void StartCamera(GamEntity entity, int index, bool applyCommon = true)
|
||||
{
|
||||
if (applyCommon) { SetControl(entity); Toggle(entity); }
|
||||
if (applyCommon)
|
||||
{
|
||||
if (Equal(entity.Text("PlayerControlled"), "NULL"))
|
||||
PrepareOwner(ScriptPreparation.ReleaseGadget, ScriptPreparation.StopMotion, ScriptPreparation.FlattenOrientation);
|
||||
SetControl(entity); Toggle(entity);
|
||||
}
|
||||
if (entity.Integer("DeactivateInv") != 0) InventoryEnabled = false;
|
||||
if (skipping)
|
||||
{
|
||||
@@ -361,7 +378,6 @@ public sealed class SceneDirector
|
||||
Block(entity, $"Camera target {targetTag} absent", entity.Text("NextTrigger"));
|
||||
return;
|
||||
}
|
||||
if (index >= 0) ControlledTag = null;
|
||||
var database = entity.Text("SoundDatabase") ?? "none";
|
||||
var duration = soundDuration(database, sound);
|
||||
if (!double.IsFinite(duration) || duration < 0)
|
||||
@@ -478,11 +494,33 @@ public sealed class SceneDirector
|
||||
return target.Position + new Vector3(x * cy - pitchedZ * sy, pitchedY, x * sy + pitchedZ * cy);
|
||||
}
|
||||
|
||||
private void SetControl(GamEntity entity)
|
||||
private void PrepareOwner(params ScriptPreparation[] actions)
|
||||
{
|
||||
if (controlledTag == null || !actors.TryGetValue(controlledTag, out var owner)) return;
|
||||
foreach (var action in actions)
|
||||
{
|
||||
// Only Jimmy's derived preparation is modeled here; other classes
|
||||
//receive the boundary without inventing their virtual side effects.
|
||||
if (action == ScriptPreparation.StopMotion && owner.Kind == "3JIM")
|
||||
owner.Speed = 0;
|
||||
else if (action == ScriptPreparation.FlattenOrientation)
|
||||
owner.Rotation = new Vector3(0, owner.Rotation.Y, 0);
|
||||
ActorPreparing?.Invoke(owner, action);
|
||||
//42AFC0 invokes43A750 before the derived STOP animation request.
|
||||
if (action == ScriptPreparation.StopMotion && owner.Kind == "3JIM")
|
||||
{ owner.Animation = "STOP"; ActorChanged?.Invoke(owner); }
|
||||
}
|
||||
}
|
||||
|
||||
private void SetControl(GamEntity entity, bool prepareOwner = false)
|
||||
{
|
||||
var control = entity.Text("PlayerControlled");
|
||||
if (IsNone(control)) return;
|
||||
if (Equal(control, "NULL")) ControlledTag = null;
|
||||
if (Equal(control, "NULL"))
|
||||
{
|
||||
if (prepareOwner) PrepareOwner(ScriptPreparation.StopMotion); //40C4AD; no438/flatten.
|
||||
ControlledTag = null;
|
||||
}
|
||||
else if (actors.ContainsKey(control!)) ControlledTag = control;
|
||||
else Report(entity.Tag!, entity.Kind, $"PlayerControlled target {control} absent");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user