114 lines
6.4 KiB
C#
114 lines
6.4 KiB
C#
using System.Numerics;
|
|
using GamePort.Assets;
|
|
using GamePort.Game;
|
|
using GamePort.Application;
|
|
|
|
// An explicit modern input replay, not recovered original navigation/AI. The
|
|
// player is never repositioned and all contacts use the live collision result.
|
|
var original = Path.GetFullPath(args.Length == 1 ? args[0] : "../Original");
|
|
var prepared = Path.GetFullPath("artifacts/extracted");
|
|
var level = GamLevel.Load(AssetPath.Resolve(original, "gam/level1b.gam"));
|
|
var start = level.FindStart()!;
|
|
var world = Mesh.LoadSceneJson(Path.Combine(prepared, "level1b/scene.json"));
|
|
var save = OriginalSave.Load(Path.Combine(original, "NewGame.tsk"));
|
|
var tasks = new TaskStates(save.Tasks);
|
|
var resources = new PreparedEntityResources(Path.Combine(prepared, "level1b/entities/entities.json"));
|
|
var director = new SceneDirector(level, tasks, resources.Duration);
|
|
var interactions = new SceneInteractions(director, tasks, save);
|
|
var mechanisms = new SceneMechanisms(director);
|
|
var visuals = new StaticSceneVisuals(world, director, original, Path.Combine(prepared, "level1b/models"));
|
|
var geometry = OriginalCameraRay.FromRouteScene(world, level.Code);
|
|
var simulation = new LabSimulation(new SceneCollision(world), AseMesh.Load(AssetPath.Resolve(original, "ASE/jimstop.ase")),
|
|
start.Position, start.Rotation.Y, (a,b) => geometry.Trace(a,b), (a,b) => geometry.TraceGeometry(a,b))
|
|
{ JetpackInventoryState = () => interactions.Inventory.State(0, 3) };
|
|
simulation.DynamicRootResolver = (before, after, radius) => DynamicBodyResponse.Resolve(visuals.DoorColliders(), before, after, radius);
|
|
var patrols = new List<ActorPatrol>();
|
|
foreach (var actor in director.Actors.Where(a => a.Kind is "3DOG" or "3CAR"))
|
|
{
|
|
var physics = new OriginalScenePhysics(world);
|
|
var grounded = false;
|
|
var patrol = new ActorPatrol(actor, director.FindActor, (body, dt) =>
|
|
{
|
|
var step = physics.Step(body.Position, body.Velocity, actor.Kind == "3DOG" ? 130 : 100,
|
|
actor.Kind == "3DOG" ? .3f : .75f, grounded, dt);
|
|
grounded = step.Supported;
|
|
return new(step.Body.Position, step.Body.Velocity);
|
|
});
|
|
patrols.Add(patrol);
|
|
director.RegisterPatrolConsumer(actor.Tag);
|
|
director.ActorChanged += changed => { if (ReferenceEquals(changed, actor)) patrol.SynchronizeAuthoredState(); };
|
|
}
|
|
var practice = new PracticePrompt();
|
|
interactions.PracticeRequested += practice.Show;
|
|
var prompts = 0;
|
|
LevelTransition? destination = null;
|
|
interactions.Transition += request => destination ??= request;
|
|
using var playerBinding = new PlayerSceneBinding(director, simulation, interactions.Inventory, level.Player!.Tag!);
|
|
director.Begin(start);
|
|
interactions.Reset(); mechanisms.Reset(); director.Skip();
|
|
|
|
Vector2 Point(string tag)
|
|
{
|
|
var p = director.FindActor(tag)!.Position;
|
|
return new(p.X, p.Z);
|
|
}
|
|
// Source trigger/item/marker/exit locations plus an explicit doorway approach.
|
|
// The approach avoids the wall outside the authored exit opening.
|
|
var exit = Point("LABTONEIGH");
|
|
var route = new[] { Point("teleportexplanation"), Point("shrinkray"), Point("CARLESC3"),
|
|
new Vector2(exit.X, 500), exit };
|
|
var sceneStates = new[] { 35, 50, 60, 60, 60 };
|
|
for (var leg = 0; leg < route.Length && destination == null; leg++)
|
|
{
|
|
var arrived = false;
|
|
for (var tick = 0; tick < 2400; tick++)
|
|
{
|
|
if (practice.Active)
|
|
{
|
|
Require(practice.Mode == 0, "Wrong lab practice mode");
|
|
practice.Key(17, Vector2.Zero); // N resumes; no direct task/pickup mutation.
|
|
prompts++;
|
|
}
|
|
var difference = route[leg] - new Vector2(simulation.Position.X, simulation.Position.Z);
|
|
if (difference.Length() < 90) { arrived = true; break; }
|
|
var desiredYaw = MathF.Atan2(-difference.X, difference.Y) * 180 / MathF.PI;
|
|
var error = MathF.IEEERemainder(desiredYaw - simulation.Yaw, 360);
|
|
var previous = simulation.ActorRoot;
|
|
// This is a modern input driver, not original navigation. Brake before
|
|
//large heading changes; coasting turns can miss the narrow exit opening
|
|
//when the recovered cutscene preparation changes the arrival speed.
|
|
var brake = MathF.Abs(error) > 15 && simulation.Speed > 0;
|
|
var input = brake ? new PlayerInput(false, true, false, false, false)
|
|
: new PlayerInput(MathF.Abs(error) < 10, false, error > 1, error < -1, false);
|
|
var acceptsInput = playerBinding.Step(input);
|
|
Require(Vector3.Distance(previous, simulation.ActorRoot) < 100, "Player warped during input replay");
|
|
interactions.UpdateEnergy(simulation.Energy);
|
|
if (acceptsInput)
|
|
{
|
|
director.Touch(level.Player!.Tag!, simulation.ActorRoot);
|
|
interactions.Update(simulation.ActorRoot, simulation.InteractionRadius);
|
|
if (practice.Active) continue; // Same modal activation boundary as Program.
|
|
mechanisms.Update(simulation.ActorRoot, simulation.InteractionRadius);
|
|
}
|
|
mechanisms.Step(FixedStepClock.Step);
|
|
foreach (var patrol in patrols) patrol.Step(FixedStepClock.Step);
|
|
director.Step(FixedStepClock.Step);
|
|
if (destination != null) break;
|
|
}
|
|
Require(arrived || destination != null, $"Input route blocked at leg{leg}: {simulation.Report}; yaw={simulation.Yaw}, control={director.AuthoredControlledTag}, shot={director.CurrentTag}, blocked={director.Blocked}, goal={route[leg]}");
|
|
Require(tasks.Get("SCENE") == sceneStates[leg], $"Wrong task state after walking leg{leg}");
|
|
Console.WriteLine($"PASS walked leg{leg}: SCENE={tasks.Get("SCENE")}, root={simulation.ActorRoot}");
|
|
}
|
|
Require(destination is { LevelFile: "level1.gam", StartPoint: "level1" }, "Walking did not enter the source outside LOAD");
|
|
Require(interactions.Score == 150 && interactions.Inventory.State(0, 3) == 1 && prompts == 1,
|
|
"Walking route did not preserve jetpack/Carl score, inventory and practice dispatch");
|
|
Require(simulation.Steps > 500 && simulation.Travel > 5000 && simulation.Jumps == 0, "Walking route did not exercise actual movement");
|
|
Require(!director.Blocked, "Source director blocked during the walking route");
|
|
Console.WriteLine($"PASS input-only lab route ->level1.gam, score150, jetpack owned, practice declined once. {simulation.Report}");
|
|
Console.WriteLine("This verifies port navigation through the lab; original collision/cadence/behavior fidelity remains unverified.");
|
|
|
|
static void Require(bool condition, string message)
|
|
{
|
|
if (!condition) throw new InvalidOperationException(message);
|
|
}
|