Implement verified Grappler body camera and helpers in VR08

This commit is contained in:
UnixNight committed 2026-11-04 11:27:03 -05:00
1 parent ffea678e90
commit 43806fe862
39 files changed
+2429 -40

No files matched your search

+63 -13
View File
@@ -21,9 +21,10 @@ internal static class Program
var returning = false;
var diagnostics = new DebugDiagnostics { Enabled = args.Contains("--debug-overlay") };
var energy = new PlayerEnergy();
var grapplerMemory = new GrapplerMemory();
while (true)
{
var result = Run(args, carriedSave, carriedPlayer, returning, diagnostics, presentation, energy, out var continuation);
var result = Run(args, carriedSave, carriedPlayer, returning, diagnostics, presentation, energy, grapplerMemory, out var continuation);
if (result != 0 || continuation == null) return result;
args = continuation.Args; carriedSave = continuation.Save; returning = continuation.Returning;
carriedPlayer = continuation.Player;
@@ -44,7 +45,7 @@ internal static class Program
private sealed record SceneContinuation(string[] Args, OriginalSave Save, bool Returning, PlayerLevelState? Player);
private static int Run(string[] args, OriginalSave? carriedSave, PlayerLevelState? carriedPlayer, bool returning, DebugDiagnostics diagnostics,
RenderSession presentation, PlayerEnergy energy, out SceneContinuation? continuation)
RenderSession presentation, PlayerEnergy energy, GrapplerMemory grapplerMemory, out SceneContinuation? continuation)
{
continuation = null;
if (args.Contains("--help"))
@@ -89,6 +90,7 @@ internal static class Program
--smoke-shrink-ray Fire at an actual VR04 soldier; explicit player-placement fixture
--smoke-invisible Accelerated recharge/activation/flash/expiry/unequip fixture in VR03
--smoke-baseball VR07 aim/release/flight/target/respawn fixture
--smoke-grappler VR08 attach/reel/swing/cleanup fixture
--smoke-rocketship VR02 flight/turn/roll/control fixture
--smoke-bubble VR01 expand/throttle/bounce/cleanup/fade input fixture
--gadget-menu Render original gadget panel (--skip-intro); fixture owns item3
@@ -263,6 +265,7 @@ internal static class Program
var invisibleSmoke = args.Contains("--smoke-invisible");
var bubbleSmoke = args.Contains("--smoke-bubble");
var baseballSmoke = args.Contains("--smoke-baseball");
var grapplerSmoke = args.Contains("--smoke-grappler");
var rocketSmoke = args.Contains("--smoke-rocketship");
var carlSmoke = args.Contains("--smoke-carl-cutscene");
var controlPhaseSmoke = args.Contains("--smoke-control-phases");
@@ -284,7 +287,7 @@ internal static class Program
var defaultStory = (defaultScene || args.Contains("--walk")) && !args.Contains("--inspect") && !walkSmoke && !args.Contains("--smoke-window")
&& animationPath == null && !args.Contains("--time");
var story = defaultStory || loadedSave != null || saveOutput != null || args.Contains("--story") || args.Contains("--story-time")
|| args.Contains("--skip-intro") || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || gadgetWindowSmoke || practiceWindowSmoke || practiceReturnSmoke || carlSmoke || controlPhaseSmoke || objectiveSmoke;
|| args.Contains("--skip-intro") || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || grapplerSmoke || gadgetWindowSmoke || practiceWindowSmoke || practiceReturnSmoke || carlSmoke || controlPhaseSmoke || objectiveSmoke;
if (story && (args.Contains("--inspect") || walkSmoke || args.Contains("--smoke-window")))
throw new ArgumentException("Story playback requires its own simulation mode.");
if (walkSmoke && args.Contains("--inspect")) throw new ArgumentException("Walk smoke cannot run in inspection mode.");
@@ -319,6 +322,7 @@ internal static class Program
BaseballAimOverlay? baseballAim = null;
Rocketship? rocketship = null;
RocketshipVisuals? rocketshipVisuals = null;
GrapplerVisuals? grapplerVisuals = null;
var practice = new PracticePrompt();
ObjectivePanel? objectivePanel = null;
var patrols = new Dictionary<string, ActorPatrol>(StringComparer.OrdinalIgnoreCase);
@@ -347,14 +351,15 @@ internal static class Program
var standingPose = AseMesh.Load(AssetPath.Resolve(root, "ASE/jimstop.ase"));
if (walking)
{
var cameraRay = level!.Code is "LV1B" or "VR01" or "VR02" or "VR04" or "VR07" or "LEV1"
var cameraRay = level!.Code is "LV1B" or "VR01" or "VR02" or "VR04" or "VR07" or "VR08" or "LEV1"
? OriginalCameraRay.FromRouteScene(world, level.Code) : null;
debugCameraRay = cameraRay;
simulation = new LabSimulation(new SceneCollision(world), standingPose, originalStart.Position, originalStart.Rotation.Y,
cameraRay == null ? null : (look, eye) => cameraRay.Trace(look, eye),
cameraRay == null ? null : (start, end) => cameraRay.TraceGeometry(start, end),
level.Code is "VR01" or "VR02" or "VR04" or "VR07" ? OriginalStaticCollision.FromRouteScene(world,level.Code) : null, energy)
level.Code is "VR01" or "VR02" or "VR04" or "VR07" or "VR08" ? OriginalStaticCollision.FromRouteScene(world,level.Code) : null, energy)
{ LevelCode = level.Code, InputAfterPlayerUpdate = carriedSave != null };
if(level.Code=="VR08")simulation.EnableGrappler(world,grapplerMemory);
if (carriedPlayer != null)
{
var applied = simulation.ApplyRetainedLevelState(carriedPlayer);
@@ -399,7 +404,7 @@ internal static class Program
gadgets = new SceneGadgets(director,interactions.Inventory,simulation,world);
gadgets.ScoreAwarded += interactions.ChangeScore;
}
if(level.Code is "LV1B" or "VR01" or "VR04" or "VR07" or "LEV1")
if(level.Code is "LV1B" or "VR01" or "VR04" or "VR07" or "VR08" or "LEV1")
{
baseballs=new(director,simulation,world);
baseballs.ScoreAwarded+=interactions.ChangeScore;
@@ -467,6 +472,11 @@ internal static class Program
rocketshipVisuals=new(mesh,Path.GetFullPath(Path.Combine(Path.GetDirectoryName(scene!)!,"..")));
mesh=rocketshipVisuals.Mesh;
}
if(simulation.Grappler!=null)
{
grapplerVisuals=new(mesh,Path.GetFullPath(Path.Combine(Path.GetDirectoryName(scene!)!,"..")));
mesh=grapplerVisuals.Mesh;
}
if (gadgets != null)
{
rayVisuals = new ShrinkRayVisuals(mesh,Path.GetFullPath(Path.Combine(Path.GetDirectoryName(scene!)!, "..")),root);
@@ -510,7 +520,7 @@ internal static class Program
var storyTime = double.Parse(Option(args, "--story-time") ?? "0", System.Globalization.CultureInfo.InvariantCulture);
if (!double.IsFinite(storyTime) || storyTime < 0 || storyTime > 3600 || storyTime > 0 && !headless)
throw new ArgumentException("Story time must be0..3600 seconds in headless mode.");
var frames = int.Parse(Option(args, "--frames") ?? (rocketSmoke ? "10" : walkSmoke ? "240" : jetpackSmoke ? "300" : shrinkSmoke ? "90" : invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke ? "8" : gadgetWindowSmoke ? "24" : objectiveWindowSmoke ? "180" : carlSmoke ? "60" : controlPhaseSmoke ? "32" : toolsSmoke ? "20" : debugSmoke ? "16" : diagnosticsSmoke ? "24" : headless ? "1" : "0"));
var frames = int.Parse(Option(args, "--frames") ?? (grapplerSmoke ? "9" : rocketSmoke ? "10" : walkSmoke ? "240" : jetpackSmoke ? "300" : shrinkSmoke ? "90" : invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke ? "8" : gadgetWindowSmoke ? "24" : objectiveWindowSmoke ? "180" : carlSmoke ? "60" : controlPhaseSmoke ? "32" : toolsSmoke ? "20" : debugSmoke ? "16" : diagnosticsSmoke ? "24" : headless ? "1" : "0"));
if (gadgetWindowSmoke && (headless || level?.Code != "LV1B" || loadedSave != null || frames < 24))
throw new ArgumentException("Gadget menu SDL fixture requires a fresh windowed lab and24 frames");
if (shrinkSmoke && (level?.Code != "VR04" || gadgets == null || frames < 60))
@@ -521,6 +531,8 @@ internal static class Program
throw new ArgumentException("Bubble smoke requires a fresh VR01 and at least8 frames");
if(baseballSmoke && (level?.Code!="VR07" || frames<8 || loadedSave!=null))
throw new ArgumentException("Baseball fixture requires a fresh VR07 and at least8 frames");
if(grapplerSmoke&&(level?.Code!="VR08"||frames<9||loadedSave!=null))
throw new ArgumentException("Grappler fixture requires fresh VR08 and at least9 frames");
if(rocketSmoke&&(level?.Code!="VR02"||frames<10||loadedSave!=null))
throw new ArgumentException("Rocketship fixture requires fresh VR02 and at least10 frames");
if (controlPhaseSmoke && (level?.Code != "LV1B" || loadedSave != null || frames < 32 || director == null))
@@ -558,8 +570,10 @@ internal static class Program
InvisibleSmoke? invisibleFixture = null;
BubbleSmoke? bubbleFixture = null;
BaseballSmoke? baseballFixture = null;
GrapplerSmoke? grapplerFixture=null;
RocketshipSmoke? rocketFixture=null;
var sawRocketKeys=0;
var sawGrapplerKeys=0;
var sawBaseballKeys=0;
var sawBubbleKeys=0;
Console.WriteLine($"Scene presentation: revision={renderer.SceneRevision}, windows={presentation.WindowCreationCount}, renderers={presentation.RendererCreationCount}, window ID={(window == 0 ? 0 : Sdl.SDL_GetWindowID(window))}, size={renderer.Width}x{renderer.Height}.");
@@ -567,6 +581,12 @@ internal static class Program
using var audio = Option(args, "--audio") is { } audioFile
? new SdlAudio(audioFile, args.Contains("--loop-audio"), debugMenu.Open) : null;
using var sceneAudio = resources != null && !headless && !args.Contains("--mute") ? new SceneAudio(resources) : null;
using var grapplerLifetime = simulation?.Grappler;
if(simulation?.Grappler is{} grapplerAudio)
{
grapplerAudio.Sound+=(id,loop)=>sceneAudio?.Effect(id,loop?"grappler":null);
grapplerAudio.LoopStopped+=()=>sceneAudio?.StopLoop("grappler");
}
sceneAudio?.SetPaused(debugMenu.Open);
if (simulation!=null)
{
@@ -623,7 +643,7 @@ internal static class Program
Console.WriteLine($"Practice RETURN: exact saved root={restored}, root={simulation.ActorRoot}, STRT yaw={simulation.Yaw}, intro suppressed={!director.Playing}, companion restored={companionRestored}, retained player input order={simulation.InputAfterPlayerUpdate}, gadget availability={interactions.Inventory.State(0, 3)}.");
if (!restored) throw new InvalidOperationException("RETURN did not restore the live departure root without replaying STRT actions");
}
if (args.Contains("--skip-intro") || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || gadgetWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke || controlPhaseSmoke) { sceneAudio?.StopSpeech(); director.Skip(); }
if (args.Contains("--skip-intro") || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || grapplerSmoke || gadgetWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke || controlPhaseSmoke) { sceneAudio?.StopSpeech(); director.Skip(); }
if (gadgetWindowSmoke) { interactions!.Inventory.SetState(0,3,1); interactions.Inventory.SelectGadget(3); }
if (controlPhaseSmoke)
{
@@ -705,6 +725,7 @@ internal static class Program
}
if (invisibleSmoke) invisibleFixture = new(simulation!,interactions!.Inventory);
if(baseballSmoke)baseballFixture=new(simulation!,playerBinding!,interactions!.Inventory,baseballs!,director);
if(grapplerSmoke)grapplerFixture=new(simulation!,playerBinding!,director,interactions!);
if(rocketSmoke)rocketFixture=new(simulation!,playerBinding!,director,interactions!);
if (bubbleSmoke) bubbleFixture = new(simulation!,interactions!.Inventory);
if (shrinkSmoke)
@@ -899,6 +920,11 @@ internal static class Program
debugMenu.Message=rocketship?.Mounted==true?"ROCKETSHIP EQUIPPED - ARROWS FLY, ENTER/T TURN, R ROLL":
"ROCKETSHIP GIVEN - SELECT ITS PRACTICE TILE TO FLY IN VR02";
break;
case DebugAction.GiveGrappler when interactions != null:
interactions.Inventory.SetState(0,7,1);interactions.Inventory.SelectGadget(7);
debugMenu.Message=simulation?.GadgetMode==7?"GRAPPLER EQUIPPED - FIRE ATTACH/REEL, JUMP DETACH":
"GRAPPLER GIVEN - SELECT ITS PRACTICE TILE TO USE IN VR08";
break;
case DebugAction.CameraObstruction when debugCameraRay != null:
debugCameraRay.Enabled = !debugCameraRay.Enabled; debugMenu.Message = "STATIC CAMERA QUERY TOGGLED"; break;
case DebugAction.MuteMusic or DebugAction.MuteSpeech or DebugAction.MuteEffects when sceneAudio != null:
@@ -964,6 +990,11 @@ internal static class Program
}
while (running)
{
grapplerFixture?.BeforeFrame(count,(key,down)=>
{
var e=new Sdl.Event{Type=down?Sdl.KeyDown:Sdl.KeyUp,Scancode=key,Down=down?(byte)1:(byte)0};
if(!Sdl.SDL_PushEvent(ref e))throw new InvalidOperationException(Sdl.Error);
},headless);
rocketFixture?.BeforeFrame(count,(key,down)=>
{
var e=new Sdl.Event{Type=down?Sdl.KeyDown:Sdl.KeyUp,Scancode=key,Down=down?(byte)1:(byte)0};
@@ -1030,6 +1061,8 @@ internal static class Program
}
while (!headless && Sdl.SDL_PollEvent(out var e))
{
if(grapplerSmoke&&e.Type==Sdl.KeyDown)
sawGrapplerKeys|=e.Scancode switch{80=>1,224=>2,82=>4,225=>8,60=>16,_=>0};
if(rocketSmoke&&e.Type==Sdl.KeyDown)
sawRocketKeys|=e.Scancode switch{82=>1,80=>2,40=>4,21=>8,43=>16,60=>32,_=>0};
if(baseballSmoke && e.Type==Sdl.KeyDown)
@@ -1160,12 +1193,13 @@ internal static class Program
}
}
if (debugMenu.Open) animationStarted += elapsed;
if (simulation != null && !debugMenu.Open && !inspecting && !practice.Active && gadgetScreen?.Open != true && (active || headless || walkSmoke || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || gadgetWindowSmoke || objectiveWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke))
if (simulation != null && !debugMenu.Open && !inspecting && !practice.Active && gadgetScreen?.Open != true && (active || headless || walkSmoke || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || grapplerSmoke || gadgetWindowSmoke || objectiveWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke))
{
var steps = headless || walkSmoke || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || gadgetWindowSmoke || practiceWindowSmoke || carlSmoke || controlPhaseSmoke || objectiveWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke ? 1 : stepClock.Advance(elapsed);
var steps = headless || walkSmoke || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || grapplerSmoke || gadgetWindowSmoke || practiceWindowSmoke || carlSmoke || controlPhaseSmoke || objectiveWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke ? 1 : stepClock.Advance(elapsed);
for (var step = 0; step < steps; step++)
{
var input = carlSmoke || controlPhaseSmoke ? new PlayerInput(true, false, true, false, true)
: grapplerSmoke && headless ? GrapplerSmoke.Input(count)
: rocketSmoke && headless ? RocketshipSmoke.Input(count)
: baseballSmoke && headless ? BaseballSmoke.Input(count)
: bubbleSmoke && headless ? BubbleSmoke.Input(count)
@@ -1178,7 +1212,7 @@ internal static class Program
keys.Contains(44) || keys.Contains(8), keys.Contains(224) || keys.Contains(228) || keys.Contains(20),
keys.Contains(4), keys.Contains(7), keys.Contains(225) || keys.Contains(229),
mouseFire || keys.Contains(40) || keys.Contains(88) || keys.Contains(224) || keys.Contains(228),
RocketTurn:keys.Contains(40)||keys.Contains(88)||keys.Contains(23),RocketRoll:keys.Contains(21),RocketMouseRise:mouseJump);
RocketTurn:keys.Contains(40)||keys.Contains(88)||keys.Contains(23),RocketRoll:keys.Contains(21),RocketMouseRise:mouseJump,GrapplerEnter:keys.Contains(40)||keys.Contains(88));
gadgets?.StepBodies(FixedStepClock.Step);
baseballs?.StepBodies(FixedStepClock.Step);
var before = simulation.Position;
@@ -1186,6 +1220,7 @@ internal static class Program
bool acceptsInput;
if (playerBinding != null) acceptsInput = playerBinding.Step(input);
else { simulation.Step(input); acceptsInput = true; }
grapplerFixture?.Received(input);
rocketFixture?.Received(input);
gadgets?.StepTimers(FixedStepClock.Step);
baseballs?.StepTargets(FixedStepClock.Step);
@@ -1212,7 +1247,7 @@ internal static class Program
objectivePanel?.Step(FixedStepClock.Step, director?.ControlledTag != null, practice.Active);
var switched = director is { Controlled: false } && !simulation.Noclip
? animations!.SelectAction(director.FindActor(level!.Player!.Tag!)!.Animation)
: animations!.SelectPose(simulation.Pose);
: simulation.Pose==PlayerPose.Swing ? false : animations!.SelectPose(simulation.Pose);
if (switched) poseTime = 0;
poseTime += FixedStepClock.Step;
actorVisuals?.Update(FixedStepClock.Step, mesh);
@@ -1263,6 +1298,8 @@ internal static class Program
baseballVisuals?.Update(mesh,simulation!.Baseball.Projectiles,renderEye,renderTarget);
baseballAim?.Update(mesh,simulation!.Baseball,renderer.Width,renderer.Height);
if(rocketship!=null)rocketshipVisuals?.Update(mesh,rocketship,rocketship.FrameSteps/60d,simulation!.Appearance);
if(simulation?.Grappler is{} grapplerRender)grapplerVisuals?.Update(mesh,grapplerRender,simulation.ActorRoot,
new(simulation.Pitch,simulation.Yaw,simulation.Roll),poseTime,simulation.Appearance,renderEye,renderTarget);
spriteVisuals?.FaceCamera(renderEye, renderTarget, mesh);
objectivePanel?.Key(keys.Contains(18) && !debugMenu.Open && !inspecting && !practice.Active && gadgetScreen?.Open != true
&& director is { Controlled: true, InventoryEnabled: true });
@@ -1296,6 +1333,7 @@ internal static class Program
BubblePhase = simulation?.Bubble.Active==true ? "ACTIVE" : simulation?.Bubble.Expanding==true ? "EXPAND"
: simulation?.Bubble.Collapsing==true ? "FADE" : "OFF",
BaseballState=simulation==null?"OFF":$"{(simulation.Baseball.Equipped?"ON":"OFF")} AIM {simulation.Baseball.SavedPitch:F1} PENDING {simulation.Baseball.PendingThrow} THROWS {simulation.Baseball.Throws}",
GrapplerState=simulation?.Grappler is{} g?$"{(g.Attached?"ON":"OFF")} LEN {g.Memory.Length:F1} FIRST {g.Memory.FirstLength:F1} HIT {g.Contacts}":null,
RocketshipState=rocketship==null?null:$"{(rocketship.Mounted?"ON":"OFF")} SPEED {rocketship.Steering.Speed:F1} VY {rocketship.Velocity.Y:F1} HIT {rocketship.Contacts}",
BodyRadius = simulation?.InteractionRadius ?? 60, BodyFactor=simulation?.BodyFactor ?? 1.265f,
Objective = interactions?.CurrentObjective ?? 0, ObjectiveTime = objectivePanel?.Elapsed ?? 0,
@@ -1328,7 +1366,7 @@ internal static class Program
}
if (simulation != null && characterDraw != null)
{
characterDraw.Visible=rocketship?.Mounted!=true;
characterDraw.Visible=rocketship?.Mounted!=true && simulation.Grappler?.SwingPose!=true;
PlayerGadgetMaterial.Apply(characterDraw,simulation.Appearance);
var color=simulation.Appearance.Color;
for(var i=0;i<animations!.Current.Base.Vertices.Length;i++)
@@ -1336,6 +1374,12 @@ internal static class Program
}
renderer.UpdateVertices(mesh.Vertices);
renderer.Render(view * projection);
if(grapplerFixture!=null)
{
grapplerFixture.AfterFrame(count);
if(GrapplerSmoke.StageName(count) is{} stage&&Option(args,"--screenshot") is{} capture)
renderer.SavePpm(Path.ChangeExtension(capture,$".{stage}.ppm"));
}
if(rocketFixture!=null)
{
rocketFixture.AfterFrame(count);
@@ -1634,6 +1678,12 @@ internal static class Program
if(!headless)Console.WriteLine($"Baseball SDL keys received: {sawBaseballKeys==15}.");
if(!baseballFixture.Passed || !headless && sawBaseballKeys!=15)return 2;
}
if(grapplerFixture!=null)
{
Console.WriteLine(grapplerFixture.Report);
if(!headless)Console.WriteLine($"Grappler SDL keys received: {sawGrapplerKeys==31}.");
if(!grapplerFixture.Passed||!headless&&sawGrapplerKeys!=31)return 2;
}
if(rocketFixture!=null)
{
Console.WriteLine(rocketFixture.Report);