Files
Neutron/tests/GamePort.UndergroundRouteTests/Program.cs
T

163 lines
9.3 KiB
C#

using System.Numerics;
using GamePort.Assets;
using GamePort.Game;
using GamePort.Application;
// Modern input replay using original geometry/actors, not recovered navigation.
// SCENE65 is an explicit initial fixture, not an award or proof that the prior
// game progression reaches65. The player starts only at authored STRT riverlab.
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("riverlab")!;
var world = Mesh.LoadSceneJson(Path.Combine(prepared, "level1b/scene.json"));
var save = OriginalSave.Load(AssetPath.Resolve(original, "NewGame.tsk"));
var tasks = new TaskStates(save.Tasks);
tasks.SetExisting("SCENE", 65);
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) };
var resolverCalls = 0;
simulation.DynamicRootResolver = (before, after, radius) =>
{
resolverCalls++;
return 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(); };
}
LevelTransition? destination = null;
interactions.Transition += request => destination ??= request;
director.Begin(start);
interactions.Reset(); mechanisms.Reset();
Require(director.Controlled && !director.Playing, "Authored underground start must grant control without the lab intro");
var bars = director.FindActor("bars")!;
var closedY = bars.SourceGam!.Position.Y;
var amount = bars.SourceGam.Number("OpenAmount");
var buttons = director.Actors.Where(a => a.Kind == "3BUT").ToArray();
Require(buttons.Length == 2 && buttons[0].Position.Y > buttons[1].Position.Y && buttons[0].Position.Z > buttons[1].Position.Z,
"Source switch ordering/door sides changed");
Require(bars.Position.Y == closedY && buttons.All(b => b.Animation == "UP"), "Authored bars/switches must begin closed/available");
var pressed = new bool[2];
var sawFullyOpen = false;
var openingLoops = 0;
var stoppedLoops = 0;
var crossings = 0;
mechanisms.Sound += (_, id, loop) => { if (id == 59 && loop) openingLoops++; };
mechanisms.StopSound += _ => stoppedLoops++;
// Explicit center approaches keep the capsule away from the arched entrance's
// masonry. These waypoint coordinates are test input policy, not source AI.
Walk("lower switch", new(buttons[1].Position.X, buttons[1].Position.Z));
Require(pressed[1] && bars.Position.Y > closedY, "Lower switch contact did not start opening the original bars");
Walk("lower center approach", new(bars.Position.X, -1900));
Walk("lower gate approach", new(bars.Position.X, bars.Position.Z - 200));
Walk("upper passage", new(bars.Position.X, bars.Position.Z + 300));
Require(crossings == 1 && sawFullyOpen, "Lower-to-upper passage did not cross the open source doorway");
Walk("upper switch approach", new(3500, -900));
Require(pressed[0], "Upper switch was not pressed through live player contact");
Walk("upper center approach", new(bars.Position.X, -900));
Walk("lower return passage", new(bars.Position.X, -1450));
Require(crossings == 2, "Upper-to-lower passage did not cross the source doorway");
Walk("lower return", new(bars.Position.X, -2000));
for (var i = 0; i < 1200; i++) Tick(default);
Require(MathF.Abs(bars.Position.Y - closedY) < .01f && buttons.All(b => b.Animation == "UP"),
"Timed bars and both switches did not return to their authored resting states");
// A separate negative collision query uses the replay's actual standing root
// height. It never assigns the player position or bypasses a button during play.
// Correct NC-water exclusion leaves this body inside the source broadphase;
// treating water as solid raised it85.89 units and incorrectly skipped the bars.
var probeBefore = new Vector3(bars.Position.X, simulation.ActorRoot.Y, bars.Position.Z - 100);
var probeAfter = probeBefore + new Vector3(0, 0, 80);
var probeBox = visuals.DoorColliders().Single();
Require(DynamicSceneCollision.BroadPhase(probeBox, new(probeBefore, probeAfter, 60)),
"Closed source gate must receive the actual standing-height body sweep");
var liveRoot = simulation.ActorRoot;
var blocked = DynamicBodyResponse.Resolve([probeBox], probeBefore, probeAfter, 60);
Require(blocked.Z < bars.Position.Z - 76 && simulation.ActorRoot == liveRoot,
"Closed bars failed the negative sweep, or the query moved the live player");
Require(tasks.Get("SCENE") == 65 && interactions.Score == save.Score && destination == null,
"Walking the button route must not invent task/score or enter the separate river LOAD");
Require(simulation.Steps > 1200 && simulation.Travel > 3500 && simulation.Jumps == 0 && simulation.Grounded,
"Replay did not exercise actual grounded movement");
Require(resolverCalls == simulation.Steps && openingLoops >= 1 && stoppedLoops >= 1,
"Live dynamic collision or door-loop lifetime was not exercised");
Require(!director.Blocked && mechanisms.Unsupported.Count == 0, "Route encountered unsupported director/mechanism behavior");
Console.WriteLine($"PASS input-only underground passage both ways, both switches, timed reclose, {crossings} clear crossings. {simulation.Report}");
Console.WriteLine("Initial fixture is original riverlab/SCENE65. Original collision, timing, water and prior progression fidelity remain separate evidence.");
void Walk(string name, Vector2 target)
{
for (var tick = 0; tick < 1800; tick++)
{
var difference = target - new Vector2(simulation.Position.X, simulation.Position.Z);
if (difference.Length() < 30)
{
// Release before turning for the next leg. Source steering changes
// yaw while decelerating, rather than snapping the heading or root.
for (var pause = 0; pause < 90; pause++) Tick(default);
Console.WriteLine($"PASS walked {name}: root={simulation.ActorRoot}, barsY={bars.Position.Y:F2}");
return;
}
var desiredYaw = MathF.Atan2(-difference.X, difference.Y) * 180 / MathF.PI;
var error = MathF.IEEERemainder(desiredYaw - simulation.Yaw, 360);
Tick(new(MathF.Abs(error) < 6, false, error > 1, error < -1, false));
}
throw new InvalidOperationException($"Input route blocked at {name}: {simulation.ActorRoot}");
}
void Tick(PlayerInput input)
{
Require(director.Controlled, "Underground route unexpectedly lost player control");
var previous = simulation.ActorRoot;
simulation.Step(input);
Require(Vector3.Distance(previous, simulation.ActorRoot) < 100, "Player warped during input replay");
if (simulation.Steps == 1)
Require(MathF.Abs(previous.Y - simulation.ActorRoot.Y) < 1,
"Authored riverlab spawn popped onto an excluded NC water surface");
director.SyncActor(level.Player!.Tag!, simulation.ActorRoot, new(0, simulation.Yaw, 0));
director.Touch(level.Player.Tag!, simulation.ActorRoot);
interactions.Update(simulation.ActorRoot, simulation.InteractionRadius);
mechanisms.Update(simulation.ActorRoot, simulation.InteractionRadius);
// Test the recovered radius60 root body when crossing the gate plane,
// before mechanism movement. Raw standing mesh height is a provisional
// visual/pivot policy, not the dynamic collider used by the source adapter.
if ((previous.Z - bars.Position.Z) * (simulation.ActorRoot.Z - bars.Position.Z) < 0)
{
var box = visuals.DoorColliders().Single();
var minimumY = DynamicSceneCollision.Corners(box).Min(p => p.Y);
Require(minimumY > simulation.ActorRoot.Y + simulation.InteractionRadius,
"Replay crossed the bars before the moving doorway cleared the recovered body");
crossings++;
}
mechanisms.Step(FixedStepClock.Step);
foreach (var patrol in patrols) patrol.Step(FixedStepClock.Step);
director.Step(FixedStepClock.Step);
for (var i = 0; i < buttons.Length; i++) pressed[i] |= buttons[i].Animation == "DOWN";
sawFullyOpen |= MathF.Abs(bars.Position.Y - closedY - amount) < .01f;
}
static void Require(bool condition, string message)
{
if (!condition) throw new InvalidOperationException(message);
}