Implement evidence-backed VR02 Rocketship flight and ownership

This commit is contained in:
UnixNight committed 2026-11-03 16:42:09 -05:00
1 parent 312efccb77
commit e77add5fdf
50 files changed
+4326 -66

No files matched your search

+6 -5
View File
@@ -8,7 +8,7 @@ public sealed record DebugScene(string LevelFile, string Code, string[] Starts);
public enum DebugAction { None, Resume, Camera, SkipCutscene, RefillEnergy, GiveJetpack, ApplySceneTask, LoadScene, Reset, ForceControl, ToggleOverlay,
Noclip, NoclipSpeed, StopMotion, ShowObjective, ReturnNoclipEntry, LevelAvailability, InputOrder, ApplyJetpackState,
CameraObstruction, MuteMusic, MuteSpeech, MuteEffects, RestartMusic, StopEffects, SaveCheckpoint, LoadCheckpoint, Practice,
GiveInvisible, UnequipGadget, GiveBubble, GiveBaseball, GiveAllGadgets }
GiveInvisible, UnequipGadget, GiveBubble, GiveBaseball, GiveAllGadgets, GiveRocketship }
public sealed record DebugMenuView(string[] Lines, int SelectedLine);
public sealed record DebugStatus(string Level, string Start, Vector3 Root, float Yaw, float Speed,
bool Grounded, float Energy, int Score, int SceneTask, string Cutscene, bool Controlled,
@@ -31,6 +31,7 @@ public sealed record DebugSystems
public bool Targetable { get; init; } = true;
public string BubblePhase { get; init; } = "OFF";
public string BaseballState { get; init; } = "OFF";
public string? RocketshipState { get; init; }
public float BodyRadius { get; init; } = 60;
public float BodyFactor { get; init; } = 1.265f;
public int Objective { get; init; }
@@ -56,7 +57,7 @@ public sealed class DebugMenu
public const int ItemCount = 12;
public const int PageCount = 3;
public int Page { get; private set; }
public int PageItems => Page switch { 1 => 15, 2 => 9, _ => ItemCount };
public int PageItems => Page switch { 1 => 16, 2 => 9, _ => ItemCount };
private static readonly float[] FlySpeeds = [300, 600, 1200, 2400];
private int flySpeedIndex = 1, jetpackStateIndex = 1;
private static readonly int[] JetpackStates = [0, 1, 4];
@@ -120,7 +121,7 @@ public sealed class DebugMenu
5 => DebugAction.LevelAvailability, 6 => DebugAction.InputOrder,
8 => DebugAction.ApplyJetpackState, 9 => DebugAction.RefillEnergy,
10 => DebugAction.GiveInvisible, 11 => DebugAction.UnequipGadget, 12 => DebugAction.GiveBubble,
13 => DebugAction.GiveBaseball, 14 => DebugAction.GiveAllGadgets, _ => DebugAction.None
13 => DebugAction.GiveBaseball, 14 => DebugAction.GiveAllGadgets,15=>DebugAction.GiveRocketship, _ => DebugAction.None
};
if (Page == 2) return Selected switch
{
@@ -160,7 +161,7 @@ public sealed class DebugMenu
$"OBJECTIVE {system.Objective} TIME {F(system.ObjectiveTime)} GADGET STATE {system.JetpackAvailability}",
$"INVISIBLE {F(system.InvisibleRemaining)} RECHARGE {F(system.InvisibleRecharge)}/7 TARGETABLE {system.Targetable}",
$"BUBBLE {system.BubblePhase} BODY R {F(system.BodyRadius)} FACTOR {system.BodyFactor.ToString("0.000",c)}",
$"BASEBALL {system.BaseballState}", ""];
system.RocketshipState is{} rocket?$"ROCKET {rocket}":$"BASEBALL {system.BaseballState}"];
string[] items = Page == 1 ? [
$"NOCLIP (F3): {system.Noclip} (ENTER TOGGLE)",
$"FLY SPEED: {F(FlySpeed)} LIVE {F(system.NoclipSpeed)} (ENTER APPLIES)", "STOP MOTION / CLEAR QUEUED JUMP", "SHOW CURRENT OBJECTIVE",
@@ -168,7 +169,7 @@ public sealed class DebugMenu
$"INPUT AFTER PLAYER: {system.InputAfterPlayer} (TOGGLE)",
$"JET PACK STATE: {JetpackState} (0 NONE / 1 OWNED / 4 DISABLED)", "APPLY JET PACK STATE", "REFILL ENERGY TO 100",
"GIVE / SELECT INVISIBLE", "UNEQUIP CURRENT GADGET", "GIVE / SELECT BUBBLE", "GIVE / SELECT BASEBALL",
"GIVE ALL GADGETS"] : [
"GIVE ALL GADGETS", "GIVE / SELECT ROCKETSHIP (VR02)"] : [
$"STATIC CAMERA OBSTRUCTION: {(system.CameraObstruction?.ToString() ?? "UNAVAILABLE")}",
$"MUTE MUSIC: {system.MusicMuted}", $"MUTE SPEECH: {system.SpeechMuted}", $"MUTE EFFECTS: {system.EffectsMuted}",
"RESTART SELECTED MUSIC", "STOP ALL EFFECTS / LOOPS", "SAVE DEBUG CHECKPOINT", "LOAD DEBUG CHECKPOINT", "SHOW JET PACK PRACTICE PROMPT"];
@@ -0,0 +1,86 @@
using System.Numerics;
using GamePort.Game;
namespace GamePort.Application;
/// <summary>VR02 ordinary-phase replay; extra ticks reuse the last received
/// input. No actor relocation, velocity seeding or timer modification.</summary>
public sealed class RocketshipSmoke
{
private readonly LabSimulation player;
private readonly PlayerSceneBinding binding;
private readonly SceneInventory inventory;
private readonly SceneDirector director;
private readonly SceneInteractions interactions;
private readonly Rocketship ship;
private readonly bool[] checks=new bool[10];
private readonly Vector3 initial;
private readonly float energy;
private PlayerInput last;
private int extra;
private float turnYaw;
public RocketshipSmoke(LabSimulation player,PlayerSceneBinding binding,SceneDirector director,SceneInteractions interactions)
{
this.player=player;this.binding=binding;this.director=director;this.interactions=interactions;
inventory=interactions.Inventory;ship=binding.Rocketship!;
energy=player.Energy;initial=player.ActorRoot;
inventory.SetState(0,1,1);inventory.SelectGadget(1);
}
public void BeforeFrame(int count,Action<uint,bool> key,bool headless)
{
if(count==0&&!headless)key(82,true);
if(count==1)Advance(90);
if(count==2&&!headless)key(80,true);
if(count==3)
{
Advance(45);
if(!headless){key(80,false);key(82,false);}
}
if(count==4)
{
Advance(30);turnYaw=ship.Rotation.Y;
if(!headless)key(40,true);
}
if(count==5)
{
Advance(65);
if(!headless){key(40,false);key(21,true);}
}
if(count==6){Advance(35);if(!headless)key(21,false);}
if(count==7)
{
Advance(30);
if(headless)inventory.SelectGadget(-1);else key(43,true);
}
if(count==8){if(!headless)key(43,false);inventory.SelectGadget(1);}
if(count==9){if(headless)player.SetNoclip(true);else key(60,true);}
}
public void Received(PlayerInput input)=>last=input;
private void Advance(int count)
{
for(var i=0;i<count;i++)
{
if(binding.Step(last))interactions.Update(player.ActorRoot,player.InteractionRadius,ship.Mounted?ship.Actor:null);
interactions.UpdateEnergy(player.Energy);director.Step(FixedStepClock.Step);extra++;
}
}
public void AfterFrame(int count)
{
if(count==0)checks[0]=ship.Mounted&&player.GadgetMode==1&&!director.Controlled&&binding.InventoryControlled;
if(count==1)checks[1]=Vector3.Distance(ship.Root,initial)>100&&ship.Root.Y>initial.Y+30&&ship.FireVisible&&ship.BodySteps>80;
if(count==2)checks[2]=ship.Steering.Bank>0;
if(count==3)checks[3]=ship.Rotation.Y!=0&&ship.Steering.Bank>10;
if(count==4)checks[4]=ship.Maneuver.TurnRemaining>.9f;
if(count==5)checks[5]=ship.Maneuver.TurnRemaining==0&&MathF.Abs(MathF.IEEERemainder(ship.Rotation.Y-turnYaw,360))>90&&ship.Maneuver.RollRemaining>.9f;
if(count==6)checks[6]=ship.Maneuver.RollRemaining>0&&ship.Rotation.Z>60;
if(count==7)checks[7]=!ship.Mounted&&player.GadgetMode==-1&&director.Controlled&&ship.EngineMode==0&&!ship.FireVisible;
if(count==8)checks[8]=ship.Mounted&&player.GadgetMode==1;
if(count==9)checks[9]=!ship.Mounted&&player.Noclip&&director.Controlled&&ship.EngineMode==0;
}
public bool Passed=>checks.All(x=>x)&&player.Energy==energy;
public string Report=>$"Rocketship fixture: mount={checks[0]}, fly={checks[1]}, bank={checks[2]}, turn={checks[3]}, maneuver={checks[4]}, finish/roll={checks[5]}, barrel={checks[6]}, release={checks[7]}, remount={checks[8]}, noclip cleanup={checks[9]}, extra ordinary ticks={extra}, energy={player.Energy}/{energy}.";
public static PlayerInput Input(int count)=>new(count<=2,false,count==2,false,false,RocketTurn:count==4,RocketRoll:count==5);
public static string? StageName(int count)=>count switch
{0=>"mounted",1=>"flying",2=>"bank",3=>"turn",4=>"maneuver",5=>"roll-start",6=>"barrel",7=>"released",8=>"remounted",9=>"noclip",_=>null};
}
@@ -0,0 +1,53 @@
using System.Numerics;
using System.Text.Json;
using GamePort.Assets;
using GamePort.Game;
namespace GamePort.Application;
/// <summary>Original Strato, HIDRIVE, HIROCK and additive FireStrato resources.
/// Uses source local pivots/transforms without standing-sole correction.</summary>
public sealed class RocketshipVisuals
{
private sealed record Clip(MorphAnimation Animation,int Offset,MeshDraw Draw);
private readonly Clip ship,rider,dog,fire;
public Mesh Mesh { get; }
public RocketshipVisuals(Mesh combined,string preparedRoot)
{
var root=Path.Combine(preparedRoot,"rocketship");
using var doc=JsonDocument.Parse(File.ReadAllText(Path.Combine(root,"rocketship.json")));
if(doc.RootElement.GetProperty("schema").GetInt32()!=1)throw new InvalidDataException("Unknown Rocketship resource schema");
Clip Load(string name)
{
var animation=new MorphAnimation(Path.Combine(root,name,"animation.json"));
var offset=combined.Vertices.Length;
var id=int.MinValue;while(combined.Textures.ContainsKey(id))id++;
combined=animation.AppendTo(combined,id);
var draw=combined.Draws[^1];draw.Visible=false;
return new(animation,offset,draw);
}
ship=Load("strato");rider=Load("jimdrive");dog=Load("godrocket");fire=Load("firestrato");
fire.Draw.Blend=MeshBlend.Additive;fire.Draw.Opacity=1;
Mesh=combined;
}
public void Update(Mesh mesh,Rocketship vehicle,double time,PlayerAppearance appearance)
{
var ordinary=RocketOrientation.Model(vehicle.Rotation,vehicle.Root,Vector3.One);
Draw(ship,RocketOrientation.Model(vehicle.Rotation,vehicle.Root,vehicle.ShapeScale),vehicle.Mounted);
Draw(rider,ordinary,vehicle.Mounted);
Draw(dog,RocketOrientation.Model(vehicle.Rotation,vehicle.CompanionRoot,Vector3.One),vehicle.Mounted);
Draw(fire,ordinary,vehicle.Mounted&&vehicle.FireVisible);
PlayerGadgetMaterial.Apply(rider.Draw,appearance);
var color=appearance.Color;
for(var i=0;i<rider.Animation.Base.Vertices.Length;i++)
mesh.Vertices[rider.Offset+i].Color*=new Vector3(color.X,color.Y,color.Z);
void Draw(Clip clip,Matrix4x4 model,bool visible)
{
clip.Draw.Visible=visible;
if(visible)clip.Animation.Sample(time,mesh.Vertices.AsSpan(clip.Offset,clip.Animation.Base.Vertices.Length),model);
}
}
}
+16 -2
View File
@@ -4,7 +4,8 @@ using GamePort.Assets;
namespace GamePort.Game;
public readonly record struct PlayerInput(bool Forward, bool Backward, bool Left, bool Right, bool Jump,
bool Rise = false, bool Descend = false, bool StrafeLeft = false, bool StrafeRight = false, bool Fast = false, bool Fire = false);
bool Rise = false, bool Descend = false, bool StrafeLeft = false, bool StrafeRight = false, bool Fast = false, bool Fire = false,
bool RocketTurn = false, bool RocketRoll = false, bool RocketMouseRise = false);
public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall, Fly, Shoot }
/// <summary>
@@ -226,7 +227,7 @@ public sealed class LabSimulation
return ((float)Math.Sin(radians), (float)Math.Cos(radians));
}
public void Step(PlayerInput input, bool controlled = true, bool? anyControlled = null)
public void Step(PlayerInput input, bool controlled = true, bool? anyControlled = null, Action? afterPhysics = null)
{
if (Noclip)
{
@@ -238,6 +239,7 @@ public sealed class LabSimulation
// This reconstructs the player/input/fire partial order, not the full
// scene registry, original cadence or original collision response.
StepPhysics();
afterPhysics?.Invoke();
if (controlled && !InputAfterPlayerUpdate) StepInput(input);
//42469F..4246DC runs independently of raw ownership.
if (Grounded)
@@ -268,6 +270,18 @@ public sealed class LabSimulation
Speed = 0; Velocity = Vector3.Zero;
}
public void LeaveRocketship(Vector3 sharedEye)
{
//4285..4286 cleanup leaves the last copied root and enters air/FALL.
Velocity=Vector3.Zero;extraAirAcceleration=0;Speed=0;movementMode=1;
forceFall=true;CameraEye=sharedEye;
}
public void RocketImpact()
{
AdjustEnergy(-1);ScoreChanged?.Invoke(-1);CancelPoweredFlight();
}
public void StopForPrimaryFire() => Speed = 0;
public void SetShooting(bool shooting) => Shooting = shooting;
public void AdjustEnergy(float delta) => energy.Adjust(delta, LevelCode, id => EnergySound?.Invoke(id));
+9 -4
View File
@@ -13,7 +13,7 @@ public readonly record struct OrdinaryBodyStep(OrdinaryBodyState Body, Vector3 P
Vector3 SupportAnchor, SupportHit? SupportHit, BodyLandingObservation? Landing,
CameraRayPolygon? Contact, int CollisionPasses, int TriangleTests);
public enum BodyResponseProfile { Jimmy, Baseball }
public enum BodyResponseProfile { Jimmy, Baseball, Rocketship }
/// <summary>
/// Bounded479D20 composition: enabled integration/support/pairs/static flags,
@@ -77,8 +77,13 @@ public sealed class OriginalBodyPhysics
// post-callback previous/live-root equality test permits publication.
if (move.CallbackPolygon is { } contact && contact.StoredNormal.Y <= -.7f)
{
if (velocity.Y > 0) velocity.Y = 0;
if (acceleration.Y > 0) acceleration.Y = 0;
if (profile == BodyResponseProfile.Rocketship)
velocity.Y = -120; //43EB70: unconditional; acceleration survives.
else
{
if (velocity.Y > 0) velocity.Y = 0;
if (acceleration.Y > 0) acceleration.Y = 0;
}
}
else if (profile == BodyResponseProfile.Baseball && move.CallbackPolygon is { } wall)
{
@@ -105,7 +110,7 @@ public sealed class OriginalBodyPhysics
if (geometryEnabled)
{
var support = OriginalBodySupport.Resolve(new(position, previous, velocity, acceleration, radius, factor,
PreventLowering: profile == BodyResponseProfile.Jimmy),
PreventLowering: profile != BodyResponseProfile.Baseball),
wasSupported, (start, end, sides) => collision.TraceSupport(start, end, sides));
if (support.Supported)
{
+3 -2
View File
@@ -58,14 +58,15 @@ public sealed class OriginalCameraRay
}
/// <summary>
/// LV1B/VR01/VR04/LEV1 complete game slot134 is475CD0 (false), so only the proven
/// Route/tutorial complete game slot134 is475CD0 (false), including VR02's
///4CDD30 table (rocketship.md), 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 "VR01" or "VR04" or "VR07" or "LEV1"))
if (levelCode is not ("LV1B" or "VR01" or "VR02" or "VR04" or "VR07" 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");
+26 -1
View File
@@ -8,6 +8,9 @@ public static class OriginalHeading
private static readonly ushort[] halfAcos = BuildHalfAcos();
public static float Degrees(Vector3 vector)
=> HeadingUnits(vector) * 0.02197265625f;
private static int HeadingUnits(Vector3 vector)
{
if (!float.IsFinite(vector.X) || !float.IsFinite(vector.Y) || !float.IsFinite(vector.Z))
throw new ArgumentOutOfRangeException(nameof(vector), "A finite direction is required.");
@@ -24,7 +27,29 @@ public static class OriginalHeading
angle = x < 0 ? 8192 + angle : 8192 - angle;
else if (x < 0)
angle = 16384 - angle;
return ((-angle) & 0x3fff) * 0.02197265625f;
return (-angle) & 0x3fff;
}
/// <summary>Copied OMT2 vector::angles pitch/yaw, in signed14-bit circle units.</summary>
public static (int Pitch,int Yaw) Angles(Vector3 vector)
{
var heading=HeadingUnits(vector);
var radians=((-heading)&16383)*(Math.Tau/16384);
float sine=(float)Math.Sin(radians), cosine=(float)Math.Cos(radians);
var h=(double)vector.X*sine+(double)vector.Z*cosine;
double y=vector.Y;
int value=0;
if (h!=0||y!=0)
{
var index=(int)(16384*y*y/(h*h+y*y));
value=halfAcos[Math.Clamp(index,0,16384)];
if(y<0) value=h<0 ? 8192+value : 8192-value;
else if(h<0) value=16384-value;
}
var pitch=(4096-value)&16383;
if(pitch>8192)pitch-=16384;
if(heading>8192)heading-=16384;
return (pitch,heading);
}
private static ushort[] BuildHalfAcos()
+1 -1
View File
@@ -61,7 +61,7 @@ public sealed class OriginalStaticCollision
public static OriginalStaticCollision FromRouteScene(Mesh mesh, string level)
{
ArgumentNullException.ThrowIfNull(mesh);
if (level is not ("LV1B" or "VR01" or "VR04" or "VR07" or "LEV1"))
if (level is not ("LV1B" or "VR01" or "VR02" or "VR04" or "VR07" 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");
+46 -6
View File
@@ -10,11 +10,17 @@ public sealed class PlayerSceneBinding : IDisposable
private readonly LabSimulation player;
private readonly SceneInventory inventory;
private readonly string tag;
public Rocketship? Rocketship { get; }
public bool InventoryControlled=>director.InventoryEnabled&&(director.Controlled||
Rocketship is{Mounted:true} rocket&&director.ControlledTag==rocket.Actor.Tag);
public int UnsupportedGadgetCleanups { get; private set; }
public PlayerSceneBinding(SceneDirector director, LabSimulation player, SceneInventory inventory, string tag)
public PlayerSceneBinding(SceneDirector director, LabSimulation player, SceneInventory inventory, string tag,
Rocketship? rocketship=null)
{
this.director = director; this.player = player; this.inventory = inventory; this.tag = tag;
Rocketship=rocketship;
if(rocketship!=null)rocketship.RiderHit+=player.RocketImpact;
director.ActorPreparing += Prepare;
director.AuthoredTransformChanged += Transform;
director.GadgetReleaseRequested += Release;
@@ -27,11 +33,23 @@ public sealed class PlayerSceneBinding : IDisposable
public bool Step(PlayerInput input)
{
var acceptsInput = director.Controlled || player.Noclip;
player.Step(input, acceptsInput, director.ControlledTag != null);
if(player.Noclip&&Rocketship?.Mounted==true)inventory.SelectGadget(-1);
bool VehicleControl()=>Rocketship is{Mounted:true} r&&(director.AuthoredControlledTag==r.Actor.Tag||director.DebugForceControl);
var acceptsInput = director.Controlled || player.Noclip || VehicleControl();
Rocketship?.StepBody(FixedStepClock.Step);
player.Step(input,(director.Controlled&&Rocketship?.Mounted!=true)||player.Noclip,director.ControlledTag!=null,
()=>{if(!player.InputAfterPlayerUpdate&&VehicleControl())Rocketship!.StepInput(input,FixedStepClock.Step);});
Rocketship?.StepFrame(input,FixedStepClock.Step);
if(Rocketship is{Mounted:true} rocket)
{
//43DF70 copies passenger transforms and reasserts ship ownership.
player.ApplyAuthoredTransform(rocket.Root,rocket.Rotation.Y);
director.TransferControl(rocket.Actor);
if(player.InputAfterPlayerUpdate&&VehicleControl())rocket.StepInput(input,FixedStepClock.Step);
}
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
director.SyncActor(tag,player.ActorRoot,Rocketship is{Mounted:true} vehicle?vehicle.Rotation:player.TracksBubbleOrientation
? new(player.Pitch,player.Yaw,player.Roll) : rotation with{Y=player.Yaw});
return acceptsInput;
}
@@ -50,15 +68,36 @@ 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 is 0 or 2 or 6 || inventory.SelectedGadget is -1 or 3)
if (player.GadgetMode is 0 or 1 or 2 or 6 || inventory.SelectedGadget is -1 or 3)
{ inventory.SelectGadget(-1); player.GadgetMode = -1; }
else if (player.GadgetMode != -1) UnsupportedGadgetCleanups++;
}
private void Selected(int item)
{
if(Rocketship?.Mounted==true)
{
Rocketship.Release();
player.LeaveRocketship(Rocketship.CameraEye);
if(director.FindActor(tag) is{} rider){rider.Animation="FALL";director.TransferControl(rider);}
}
if (item==0 && director.FindActor(tag) is{} actor) player.SeedBubbleTilt(actor.Rotation);
player.GadgetMode=GadgetScreen.EquippedMode(item);
//The display tile remains available for Practice outside the bounded
//live scene; unsupported selection must not invent a Jimmy flight mode.
player.GadgetMode=item==1&&Rocketship==null?-1:GadgetScreen.EquippedMode(item);
if(item==1&&Rocketship!=null)
{
var rider=director.FindActor(tag)!;
Rocketship.Mount(player.ActorRoot,rider.Rotation with{Y=player.Yaw},player.CameraEye);
rider.Animation="DRIVE";
director.TransferControl(Rocketship.Actor);
}
}
public void ResetVehicle()
{
if(Rocketship?.Mounted==true)inventory.SelectGadget(-1);
Rocketship?.Reset();
}
private void DefaultGadget() => inventory.SelectGadget(-1);
@@ -93,5 +132,6 @@ public sealed class PlayerSceneBinding : IDisposable
player.Invisible.EquippedChanged -= InvisibleEquipped;
player.Baseball.EquippedChanged -= BaseballEquipped;
player.DefaultGadgetRequested -= DefaultGadget;
if(Rocketship!=null)Rocketship.RiderHit-=player.RocketImpact;
}
}
+3 -2
View File
@@ -11,9 +11,10 @@ public readonly record struct RocketVerticalStep(RocketVerticalState State, floa
/// <summary>
/// Bounded ordinary keyboard branch of C3DFlyingObject41A6C0. Input updates
/// retained scalars/flags after41A140's application in the ordinary update. Mouse,
/// retained scalars/flags separately from41A140's application; registry order
/// determines which callback comes first. Mouse,
/// analog, boost/roll, camera and body integration are separate contracts.
/// See gameplay/rocketship.md; this component does not enable a live vehicle.
/// The VR02 scene adapter composes this component with body and ownership phases.
/// </summary>
public static class RocketFlight
{
+79
View File
@@ -0,0 +1,79 @@
using System.Numerics;
namespace GamePort.Game;
public readonly record struct RocketManeuver(float TurnRemaining=0,float RollRemaining=0,
bool TurnLatched=false,bool RollLatched=false);
public readonly record struct RocketHorizontal(Vector3 Velocity,Vector3 Rotation,float PreviousBank,RocketManeuver Maneuver);
public readonly record struct RocketCamera(Vector3 Eye,Vector3 Target,Vector3 Look,Vector3 DesiredEye,int Pitch,int Yaw);
/// <summary>41A140 horizontal/auxiliary publication and41AC0E follow camera.
/// Callers own body integration, facing and registry input placement.</summary>
public static class RocketMotion
{
public static RocketHorizontal Apply(Vector3 velocity,Vector3 rotation,float speed,float bank,
float previousBank,float seconds,RocketManeuver maneuver=default,bool turnPressed=false,
bool rollPressed=false,bool suppressed=false,float friction=.8f)
{
Validate(seconds);Finite(velocity);Finite(rotation);
if(!float.IsFinite(speed)||!float.IsFinite(bank)||!float.IsFinite(previousBank)||!float.IsFinite(friction)
||!float.IsFinite(maneuver.TurnRemaining)||!float.IsFinite(maneuver.RollRemaining))
throw new ArgumentOutOfRangeException(nameof(speed));
bool moving=velocity!=Vector3.Zero;
float turn=maneuver.TurnRemaining,roll=maneuver.RollRemaining;
bool turnLatch=maneuver.TurnLatched,rollLatch=maneuver.RollLatched;
if(!suppressed)
{
if(!turnPressed)turnLatch=false;
else if(moving&&!turnLatch){turnLatch=true;if(turn<=0)turn=1;}
if(!rollPressed)rollLatch=false;
else if(moving&&!rollLatch){rollLatch=true;if(roll<=0)roll=1;}
}
if(turn>0)
{
rotation=rotation with{Y=RocketOrientation.AddAxis(rotation.Y,180*seconds)};
turn=MathF.Max(0,turn-seconds);
}
else if(moving)
{
previousBank=bank;
rotation=rotation with{Y=RocketOrientation.AddAxis(rotation.Y,bank*seconds)};
}
if(roll>0)
{
roll=MathF.Max(0,roll-seconds);
rotation=rotation with{Z=RocketOrientation.AddAxis(rotation.Z,270*seconds)};
}
if(turn<=0)
{
var forward=RocketOrientation.Rotate(new(0,0,speed),rotation);
float side=moving?(float)((double)previousBank*.0181818176060915f*(1-(double)friction)*speed):0;
var(sin,cos)=RocketOrientation.Trig(rotation.Y);
velocity=new(forward.X+cos*side,velocity.Y,forward.Z+sin*side);
}
return new(velocity,rotation,previousBank,new(turn,roll,turnLatch,rollLatch));
}
public static RocketCamera Follow(Vector3 root,Vector3 rotation,Vector3 oldEye,float seconds,
Func<Vector3,Vector3,SupportHit?>? ray=null,int detail=0)
{
Validate(seconds);Finite(root);Finite(rotation);Finite(oldEye);
var desired=root+RocketOrientation.Rotate(new(0,200,-500),rotation);
var look=root+RocketOrientation.Rotate(new(0,50,200),rotation);
float gain=1;
if(ray?.Invoke(look,desired) is{} hit){desired=look-(look-hit.Position)*.75f;gain=2;}
var eye=oldEye+(desired-oldEye)*(gain*seconds*(detail<=1?.6f:1.2f));
var(pitch,yaw)=OriginalHeading.Angles(look-oldEye);
var direction=RocketOrientation.Rotate(Vector3.UnitZ,new(pitch*.02197265625f,yaw*.02197265625f,0));
return new(eye,eye+direction*200,look,desired,pitch,yaw);
}
private static void Validate(float seconds)
{
if(!float.IsFinite(seconds)||seconds<=0||seconds>=1)throw new ArgumentOutOfRangeException(nameof(seconds));
}
private static void Finite(Vector3 value)
{
if(!float.IsFinite(value.X)||!float.IsFinite(value.Y)||!float.IsFinite(value.Z))throw new ArgumentOutOfRangeException(nameof(value));
}
}
+70
View File
@@ -0,0 +1,70 @@
using System.Numerics;
namespace GamePort.Game;
/// <summary>472B10/472480/41ADF0. Lookup angles and the source's asymmetric
/// negative seam are intentional. Numeric original references accompany the
/// Rocketship tests; double intermediates approximate x87, not its full ABI.</summary>
public static class RocketOrientation
{
public static (float Sin, float Cos) Trig(float degrees)
{
if (!float.IsFinite(degrees) || Math.Abs(degrees) > 40000000)
throw new ArgumentOutOfRangeException(nameof(degrees));
var index = (int)((double)degrees * 45.511112213134766) & 16383;
return Units(index);
}
public static (float Sin, float Cos) Units(int index)
{
var radians = (index & 16383) * (Math.Tau / 16384);
return ((float)Math.Sin(radians), (float)Math.Cos(radians));
}
public static Vector3 Rotate(Vector3 vector, Vector3 euler)
{
Finite(vector); Finite(euler);
var (sx,cx)=Trig(euler.X); var (sy,cy)=Trig(euler.Y); var (sz,cz)=Trig(euler.Z);
var a=(float)((double)cz*vector.Y-(double)sz*vector.X);
var b=(double)cz*vector.X+(double)sz*vector.Y;
var c=(double)cx*vector.Z-(double)a*sx;
return new((float)(b*cy-c*sy),(float)((double)a*cx+(double)sx*vector.Z),(float)(c*cy+b*sy));
}
public static float AddAxis(float value, float delta)
{
var total=(double)value+delta;
if (!double.IsFinite(total) || Math.Abs(total)>int.MaxValue)
throw new ArgumentOutOfRangeException(nameof(delta));
if (total<0) total=360-Math.Abs(Math.Truncate(total));
else if (total>360) total-=360;
return (float)total;
}
public static Vector3 Add(Vector3 angles, Vector3 delta) =>
new(AddAxis(angles.X,delta.X),AddAxis(angles.Y,delta.Y),AddAxis(angles.Z,delta.Z));
public static Vector3 Face(Vector3 rotation, Vector3 destination, float seconds, bool barrelRolling=false)
{
Finite(rotation); Finite(destination);
if (!float.IsFinite(seconds) || seconds<=0 || seconds>=1)
throw new ArgumentOutOfRangeException(nameof(seconds));
if (barrelRolling) return rotation;
var difference=destination-rotation;
float Arc(float value,bool yaw=false) => value>180 ? value-360 : !yaw&&value< -180 ? value+360 : value;
return Add(rotation,new(Arc(difference.X)*seconds*2,Arc(difference.Y,true)*seconds*4,Arc(difference.Z)*seconds*3));
}
public static Matrix4x4 Model(Vector3 euler, Vector3 root, Vector3 scale)
{
Finite(root); Finite(scale);
var x=Rotate(Vector3.UnitX,euler);var y=Rotate(Vector3.UnitY,euler);var z=Rotate(Vector3.UnitZ,euler);
return Matrix4x4.CreateScale(scale)*new Matrix4x4(x.X,x.Y,x.Z,0,y.X,y.Y,y.Z,0,z.X,z.Y,z.Z,0,root.X,root.Y,root.Z,1);
}
private static void Finite(Vector3 value)
{
if (!float.IsFinite(value.X)||!float.IsFinite(value.Y)||!float.IsFinite(value.Z))
throw new ArgumentOutOfRangeException(nameof(value));
}
}
+143
View File
@@ -0,0 +1,143 @@
using System.Numerics;
using GamePort.Assets;
namespace GamePort.Game;
/// <summary>Jimmy's owned/reused3ROC. Bounded to the recovered VR02 static
/// scene; caller places body, registry and input phases explicitly.</summary>
public sealed class Rocketship
{
private readonly OriginalBodyPhysics physics;
private readonly OriginalCameraRay cameraRay;
private readonly RocketFlightTuning tuning;
private readonly float accelerationLean,decelerationLean;
private OrdinaryBodyState body;
private bool facing;
private float verticalCommand,previousBank;
private Vector3 destination;
public DirectorActor Actor { get; }
public bool Mounted { get; private set; }
public Vector3 Root=>body.Position;
public Vector3 Velocity=>body.Velocity;
public Vector3 Acceleration=>body.Acceleration;
public Vector3 Rotation { get; private set; }
public bool Supported=>body.Supported;
public RocketSteering Steering { get; private set; }
public RocketManeuver Maneuver { get; private set; }
public Vector3 CameraEye { get; private set; }
public Vector3 CameraTarget { get; private set; }
public Vector3 CompanionRoot=>Root+RocketOrientation.Rotate(new(0,10,-25),Rotation);
public bool FireVisible { get; private set; }
public Vector3 ShapeScale { get; private set; }=Vector3.One;
public bool ImpactActive { get; private set; }
public float ImpactTime { get; private set; }
public int Contacts { get; private set; }
public int BodySteps { get; private set; }
public int FrameSteps { get; private set; }
public int InputSteps { get; private set; }
public int EngineMode { get; private set; }
public event Action<int>? EngineSound;
public event Action? EngineStopped;
public event Action<int>? Sound;
public event Action? RiderHit;
public Rocketship(DirectorActor actor,Mesh world,string level)
{
if(level!="VR02"||actor.Kind!="3ROC"||actor.SourceGam is not{} source)
throw new NotSupportedException("Live Rocketship requires the authored VR02 ship");
Actor=actor;
float Required(string name)=>source.Properties.TryGetValue(name,out var p)?p.Float:
throw new InvalidDataException($"Missing authored Rocketship {name}");
tuning=new(Required("AccelRate"),Required("DecelRate"),Required("MaxSpeed"),3900,
Required("UpRate"),Required("DownRate"),Required("MaxVertVelocity"));
accelerationLean=Required("AccelLean");decelerationLean=Required("DecelLean");
if(world.CollisionPolygons.Any(p=>p.MaterialId is{} id&&id is not(0 or 2 or 3 or 5)))
throw new NotSupportedException("Rocketship VR02 contact materials require their recovered profile");
physics=new(OriginalStaticCollision.FromRouteScene(world,level));
cameraRay=OriginalCameraRay.FromRouteScene(world,level);
Reset();
}
public void Reset()
{
if(EngineMode!=0)SetEngine(0);
Mounted=FireVisible=facing=ImpactActive=false;
body=new(Actor.SourceGam!.Position,Vector3.Zero,Vector3.Zero,Vector3.Zero);
Rotation=Actor.SourceGam.Rotation;destination=Rotation;
Steering=default;Maneuver=default;verticalCommand=previousBank=ImpactTime=0;
ShapeScale=Vector3.One;Contacts=BodySteps=FrameSteps=InputSteps=0;
Actor.BodyEnabled=Actor.Visible=false;
}
public void Mount(Vector3 root,Vector3 rotation,Vector3 sharedEye)
{
//42944D copies transforms and flags; it does not reset retained motion.
body=body with{Position=root};Rotation=rotation;CameraEye=sharedEye;
CameraTarget=sharedEye+Vector3.UnitZ*200;
Mounted=true;Actor.BodyEnabled=Actor.Visible=true;SyncActor();
}
public void Release()
{
//428541 disables integration and explicitly stops43EA80 before hiding.
Mounted=FireVisible=false;Actor.BodyEnabled=Actor.Visible=false;SetEngine(0);
}
public void StepBody(float seconds)
{
if(!Mounted)return;
var step=physics.Step(body,seconds,50,.6f,profile:BodyResponseProfile.Rocketship);
body=step.Body;BodySteps++;
//43E8D0 ordinary VR02 material path; null material has no side effects.
if(step.Contact is{} wall&&wall.StoredNormal.Y>-.7f&&wall.MaterialId.HasValue&&!ImpactActive)
{
ImpactActive=true;ImpactTime=0;Contacts++;
RiderHit?.Invoke();Sound?.Invoke(197);
}
}
public void StepFrame(PlayerInput input,float seconds)
{
if(facing)Rotation=RocketOrientation.Face(Rotation,destination,seconds,Maneuver.RollRemaining>0);
var motion=RocketMotion.Apply(body.Velocity,Rotation,Steering.Speed,Steering.Bank,previousBank,seconds,
Maneuver,input.RocketTurn,input.RocketRoll);
Rotation=motion.Rotation;previousBank=motion.PreviousBank;Maneuver=motion.Maneuver;
var vertical=RocketFlight.StepVertical(new(Root.Y,motion.Velocity.Y,verticalCommand),Steering,tuning,RecoveredMotion.Gravity.Y);
verticalCommand=vertical.State.CommandedAcceleration;
body=body with{Position=Root with{Y=vertical.State.Height},Velocity=motion.Velocity with{Y=vertical.State.Velocity},
Acceleration=body.Acceleration with{Y=vertical.BodyAcceleration}};
FrameSteps++;
if(!Mounted){Steering=Steering with{Speed=0};return;}
FireVisible=!Steering.Down&&Steering.Speed>0;
if(ImpactActive)
{
double time=(double)ImpactTime+seconds;
ImpactTime=(float)time;
if(time>1){ImpactActive=false;ShapeScale=Vector3.One;}
else {float pulse=(float)((Math.Sin(time*20)+1)*.5);ShapeScale=new(1,pulse,pulse);}
}
SyncActor();
}
public void StepInput(PlayerInput input,float seconds)
{
if(!Mounted)return;
Steering=RocketFlight.StepKeyboardInput(Steering,input with{Forward=input.Forward||input.RocketMouseRise},Supported,seconds,tuning);
destination=new(Steering.Up?accelerationLean:Steering.Down?decelerationLean:0,Rotation.Y,
Steering.Up||Steering.Down||Steering.Speed>0?-Steering.Bank:0);
facing=true;
SetEngine(Steering.Up?2:Steering.Down||Steering.Speed<=0?0:1);
var camera=RocketMotion.Follow(Root,Rotation,CameraEye,seconds,(a,b)=>cameraRay.Trace(a,b));
CameraEye=camera.Eye;CameraTarget=camera.Target;InputSteps++;
}
private void SetEngine(int mode)
{
if(EngineMode==mode)return;
if(EngineMode!=0)EngineStopped?.Invoke();
EngineMode=mode;
if(mode!=0)EngineSound?.Invoke(mode==1?195:196);
}
private void SyncActor(){Actor.Position=Root;Actor.Rotation=Rotation;Actor.Speed=Steering.Speed;}
}
+6
View File
@@ -183,6 +183,12 @@ public sealed class SceneDirector
public DirectorActor? FindActor(string tag) => actors.GetValueOrDefault(tag);
internal void TransferControl(DirectorActor actor)
{
if(!Actors.Contains(actor))throw new ArgumentException("Control requires a registered actor",nameof(actor));
ControlledTag=actor.Tag;
}
public void RegisterPatrolConsumer(string tag) => patrolConsumers.Add(tag);
public void SyncActor(string tag, Vector3 position, Vector3 rotation)
+9 -4
View File
@@ -77,15 +77,17 @@ public sealed class SceneInteractions
&& id > 0 && id < itemStates.Length && itemStates[id] != 0) actor.Active = actor.Visible = false;
}
public void Update(Vector3 activePlayerRoot, float playerRadius = 60)
public void Update(Vector3 activePlayerRoot, float playerRadius = 60, DirectorActor? vehicle = null)
{
if (!float.IsFinite(activePlayerRoot.X + activePlayerRoot.Y + activePlayerRoot.Z)
|| !float.IsFinite(playerRadius) || playerRadius < 0) throw new ArgumentOutOfRangeException(nameof(activePlayerRoot));
if (!director.Controlled) return;
bool VehicleControlled()=>vehicle is{Kind:"3ROC"}&&director.AuthoredControlledTag==vehicle.Tag;
bool Controlled()=>director.Controlled||VehicleControlled();
if (!Controlled()) return;
HideCollected();
foreach (var actor in director.Actors)
{
if (!director.Controlled) break;
if (!Controlled()) break;
if (actor.SourceGam is not { } source || source.Kind is not ("3PIC" or "3TRO" or "LOAD" or "3CAR")) continue;
// C3DFriend update41B972..988 calls the talk dispatcher every update
// in state0, even when a prior contact found no matching TalkTrigger.
@@ -95,7 +97,10 @@ public sealed class SceneInteractions
if (!director.Controlled) break;
}
// Carl InitObject413E2F..45 sets radius100 and support factor0.75.
var radius = playerRadius + (source.Kind == "3TRO" ? 20 : source.Kind == "3CAR" ? 100 : source.Number("Radius"));
//435D08 pickups require the raw controlled ship.457EE6 LOAD requires
//the real Jimmy passenger; the coincident actors keep distinct radii.
var contactRadius=source.Kind=="3PIC"&&VehicleControlled()?50:playerRadius;
var radius = contactRadius + (source.Kind == "3TRO" ? 20 : source.Kind == "3CAR" ? 100 : source.Number("Radius"));
var overlaps = actor.Active && (source.Kind!="3TRO" || actor.BodyEnabled)
&& OriginalBodySupport.QuickMagnitude(activePlayerRoot - actor.Position) < radius;
if (!overlaps) { contacts.Remove(source.Offset); continue; }
+74 -17
View File
@@ -89,6 +89,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-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
--smoke-gadget-menu SDL menu input/pause/selection/practice/Return check (24 frames)
@@ -262,6 +263,7 @@ internal static class Program
var invisibleSmoke = args.Contains("--smoke-invisible");
var bubbleSmoke = args.Contains("--smoke-bubble");
var baseballSmoke = args.Contains("--smoke-baseball");
var rocketSmoke = args.Contains("--smoke-rocketship");
var carlSmoke = args.Contains("--smoke-carl-cutscene");
var controlPhaseSmoke = args.Contains("--smoke-control-phases");
var objectiveWindowSmoke = args.Contains("--smoke-objective-window");
@@ -282,7 +284,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 || gadgetWindowSmoke || practiceWindowSmoke || practiceReturnSmoke || carlSmoke || controlPhaseSmoke || objectiveSmoke;
|| args.Contains("--skip-intro") || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || 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.");
@@ -315,6 +317,8 @@ internal static class Program
SceneBaseballs? baseballs = null;
BaseballVisuals? baseballVisuals = null;
BaseballAimOverlay? baseballAim = null;
Rocketship? rocketship = null;
RocketshipVisuals? rocketshipVisuals = null;
var practice = new PracticePrompt();
ObjectivePanel? objectivePanel = null;
var patrols = new Dictionary<string, ActorPatrol>(StringComparer.OrdinalIgnoreCase);
@@ -343,13 +347,13 @@ 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 "VR04" or "VR07" or "LEV1"
var cameraRay = level!.Code is "LV1B" or "VR01" or "VR02" or "VR04" or "VR07" 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 "VR04" or "VR07" ? OriginalStaticCollision.FromRouteScene(world,level.Code) : null, energy)
level.Code is "VR01" or "VR02" or "VR04" or "VR07" ? OriginalStaticCollision.FromRouteScene(world,level.Code) : null, energy)
{ LevelCode = level.Code, InputAfterPlayerUpdate = carriedSave != null };
if (carriedPlayer != null)
{
@@ -389,6 +393,7 @@ internal static class Program
simulation!.Energy = interactions.Energy;
simulation.JetpackInventoryState = () => interactions.Inventory.State(0, 3);
simulation.ScoreChanged += interactions.ChangeScore;
if(level.Code=="VR02")rocketship=new(director.Actors.Single(a=>a.Kind=="3ROC"),world,level.Code);
if (level.Code is "LV1B" or "VR04" or "LEV1")
{
gadgets = new SceneGadgets(director,interactions.Inventory,simulation,world);
@@ -457,6 +462,11 @@ internal static class Program
mesh = bubbleVisuals.Mesh;
baseballVisuals = new(mesh,Path.GetFullPath(Path.Combine(Path.GetDirectoryName(scene!)!,"..")));
mesh = baseballVisuals.Mesh;
if(rocketship!=null)
{
rocketshipVisuals=new(mesh,Path.GetFullPath(Path.Combine(Path.GetDirectoryName(scene!)!,"..")));
mesh=rocketshipVisuals.Mesh;
}
if (gadgets != null)
{
rayVisuals = new ShrinkRayVisuals(mesh,Path.GetFullPath(Path.Combine(Path.GetDirectoryName(scene!)!, "..")),root);
@@ -500,7 +510,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") ?? (walkSmoke ? "240" : jetpackSmoke ? "300" : shrinkSmoke ? "90" : invisibleSmoke || bubbleSmoke || baseballSmoke ? "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") ?? (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))
@@ -511,6 +521,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(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))
throw new ArgumentException("Control-phase fixture needs a fresh lab and at least32 frames");
if (toolsSmoke && (headless || frames < 16 || director == null || level?.Code != "LV1B" || loadedSave != null || debugMenu.Open))
@@ -535,7 +547,7 @@ internal static class Program
var height = uint.Parse(Option(args, "--height") ?? "720");
if (width is < 64 or > 8192 || height is < 64 or > 8192) throw new ArgumentException("Viewport dimensions must be64..8192");
using var playerBinding = director == null ? null
: new PlayerSceneBinding(director, simulation!, interactions!.Inventory, level!.Player!.Tag!);
: new PlayerSceneBinding(director, simulation!, interactions!.Inventory, level!.Player!.Tag!,rocketship);
var renderer = presentation.LoadScene(mesh, texture, headless,
walking ? WalkTitle : animations?.WindowTitle ?? "Jimmy Neutron — scene preview | C camera",
width, height, !args.Contains("--no-validation"));
@@ -546,6 +558,8 @@ internal static class Program
InvisibleSmoke? invisibleFixture = null;
BubbleSmoke? bubbleFixture = null;
BaseballSmoke? baseballFixture = null;
RocketshipSmoke? rocketFixture=null;
var sawRocketKeys=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}.");
@@ -560,6 +574,12 @@ internal static class Program
simulation.BubbleSoundStopped += () => sceneAudio?.StopLoop("bubble");
}
if(baseballs!=null)baseballs.Sound+=id=>sceneAudio?.Effect(id);
if(rocketship!=null)
{
rocketship.Sound+=id=>sceneAudio?.Effect(id);
rocketship.EngineSound+=id=>sceneAudio?.Effect(id,"rocket-engine");
rocketship.EngineStopped+=()=>sceneAudio?.StopLoop("rocket-engine");
}
if (gadgets != null)
{
gadgets.Sound += (id,loop) => sceneAudio?.Effect(id,loop ? "shrink-ray" : null);
@@ -603,7 +623,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 || gadgetWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke || controlPhaseSmoke) { sceneAudio?.StopSpeech(); director.Skip(); }
if (args.Contains("--skip-intro") || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || gadgetWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke || controlPhaseSmoke) { sceneAudio?.StopSpeech(); director.Skip(); }
if (gadgetWindowSmoke) { interactions!.Inventory.SetState(0,3,1); interactions.Inventory.SelectGadget(3); }
if (controlPhaseSmoke)
{
@@ -685,6 +705,7 @@ internal static class Program
}
if (invisibleSmoke) invisibleFixture = new(simulation!,interactions!.Inventory);
if(baseballSmoke)baseballFixture=new(simulation!,playerBinding!,interactions!.Inventory,baseballs!,director);
if(rocketSmoke)rocketFixture=new(simulation!,playerBinding!,director,interactions!);
if (bubbleSmoke) bubbleFixture = new(simulation!,interactions!.Inventory);
if (shrinkSmoke)
{
@@ -776,7 +797,8 @@ internal static class Program
gadgetScreen?.Close();
if (simulation == null) { debugMenu.Message = "RESET REQUIRES PLAY MODE"; return; }
if (practice.Active) practice.Key(17, Vector2.Zero);
simulation.Reset(); poseTime = 0; sceneAudio?.StopSpeech(); director?.Begin(originalStart!);
playerBinding?.ResetVehicle();simulation.Reset(); poseTime = 0; sceneAudio?.StopSpeech(); director?.Begin(originalStart!);
rocketship?.Reset();
interactions?.Reset(); mechanisms?.Reset(); gadgets?.Reset(); baseballs?.Reset(); mouseFire = false;
director?.SyncActor(level!.Player!.Tag!, simulation.ActorRoot, new Vector3(0, simulation.Yaw, 0));
}
@@ -804,7 +826,7 @@ internal static class Program
case DebugAction.Resume: debugMenu.Close(); break;
case DebugAction.Camera: ToggleCamera(); debugMenu.Close(); break;
case DebugAction.SkipCutscene:
if (director is { Playing: true } or { Blocked: true } or { Controlled: false })
if (director is { Playing: true } or { Blocked: true }||director is{Controlled:false}&&rocketship?.Mounted!=true)
{ sceneAudio?.StopSpeech(); director.Skip(); debugMenu.Message = "CUTSCENE SKIPPED"; }
else debugMenu.Message = "NO ACTIVE CUTSCENE";
break;
@@ -872,6 +894,11 @@ internal static class Program
for (var item = 0; item < 8; item++) interactions.Inventory.SetState(0,item,1);
debugMenu.Message = "ALL 8 GADGETS GIVEN - TAB/SPACE OPENS GADGETS DURING PLAY";
break;
case DebugAction.GiveRocketship when interactions != null:
interactions.Inventory.SetState(0,1,1);interactions.Inventory.SelectGadget(1);
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.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:
@@ -937,6 +964,11 @@ internal static class Program
}
while (running)
{
rocketFixture?.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);
baseballFixture?.BeforeFrame(count,(key,down)=>
{
var e=new Sdl.Event{Type=down?Sdl.KeyDown:Sdl.KeyUp,Scancode=key,Down=down?(byte)1:(byte)0};
@@ -998,6 +1030,8 @@ internal static class Program
}
while (!headless && Sdl.SDL_PollEvent(out var e))
{
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)
sawBaseballKeys|=e.Scancode switch{224=>1,80=>2,82=>4,43=>8,_=>0};
if (bubbleSmoke && e.Type==Sdl.KeyDown)
@@ -1049,11 +1083,11 @@ internal static class Program
}
if (e.Type == Sdl.KeyDown && e.Scancode is 43 or 44
&& !inspecting && simulation?.Noclip != true && !practice.Active && gadgetScreen != null
&& (gadgetScreen.Open || director is { Controlled: true, InventoryEnabled: true }))
&& (gadgetScreen.Open || playerBinding?.InventoryControlled==true))
{
var first = gadgetHeldKeys.Count == 0;
gadgetHeldKeys.Add(e.Scancode);
if (first && e.Repeat == 0) gadgetScreen.Toggle(director is { Controlled: true, InventoryEnabled: true });
if (first && e.Repeat == 0) gadgetScreen.Toggle(playerBinding?.InventoryControlled==true);
debugCapturedKeys.UnionWith(keys);
keys.Clear(); mouseJump = mouseFire = false; stepClock.Reset(); continue;
}
@@ -1083,7 +1117,7 @@ internal static class Program
if (walkSmoke) sawWalkKeys |= e.Scancode == 82 ? 1 : e.Scancode == 79 ? 2 : e.Scancode == jumpScancode ? 4 : 0;
if (jetpackSmoke) sawJetpackKeys |= e.Scancode == 82 ? 1 : e.Scancode == 81 ? 2 : e.Scancode == 80 ? 4 : e.Scancode == jumpScancode ? 8 : 0;
if (smoke && e.Scancode == 79) sawKey = true;
if (e.Scancode is 41 or 44 && e.Repeat == 0 && director is { Controlled: false }
if (e.Scancode is 41 or 44 && e.Repeat == 0 && director is { Controlled: false }&&rocketship?.Mounted!=true
&& (e.Scancode != 44 || simulation?.Noclip != true))
{ sceneAudio?.StopSpeech(); director.Skip(); keys.Clear(); mouseJump = false; }
else if (e.Scancode == 41) running = false;
@@ -1097,7 +1131,7 @@ internal static class Program
{
ToggleCamera(); keys.Clear(); mouseJump = false; stepClock.Reset();
}
if (!inspecting && e.Scancode == 21 && e.Repeat == 0)
if (!inspecting && e.Scancode == 21 && e.Repeat == 0 && rocketship?.Mounted!=true)
{
ResetScene();
}
@@ -1126,12 +1160,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 || 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 || gadgetWindowSmoke || objectiveWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke))
{
var steps = headless || walkSmoke || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || gadgetWindowSmoke || practiceWindowSmoke || carlSmoke || controlPhaseSmoke || objectiveWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke ? 1 : stepClock.Advance(elapsed);
var steps = headless || walkSmoke || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || 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)
: rocketSmoke && headless ? RocketshipSmoke.Input(count)
: baseballSmoke && headless ? BaseballSmoke.Input(count)
: bubbleSmoke && headless ? BubbleSmoke.Input(count)
: invisibleSmoke && headless ? new PlayerInput(false,false,false,false,false,Fire:count==1)
@@ -1142,7 +1177,8 @@ internal static class Program
mouseJump || keys.Contains(225) || keys.Contains(229) || keys.Contains(73) || keys.Contains(98),
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));
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);
gadgets?.StepBodies(FixedStepClock.Step);
baseballs?.StepBodies(FixedStepClock.Step);
var before = simulation.Position;
@@ -1150,6 +1186,7 @@ internal static class Program
bool acceptsInput;
if (playerBinding != null) acceptsInput = playerBinding.Step(input);
else { simulation.Step(input); acceptsInput = true; }
rocketFixture?.Received(input);
gadgets?.StepTimers(FixedStepClock.Step);
baseballs?.StepTargets(FixedStepClock.Step);
if (jetpackSmoke && powered)
@@ -1163,7 +1200,7 @@ internal static class Program
if (!simulation.Noclip)
{
director?.Touch(level!.Player!.Tag!, simulation.ActorRoot);
interactions?.Update(simulation.ActorRoot, simulation.InteractionRadius);
interactions?.Update(simulation.ActorRoot, simulation.InteractionRadius,rocketship is{Mounted:true}?rocketship.Actor:null);
}
if (practice.Active) { keys.Clear(); mouseJump = false; stepClock.Reset(); break; }
if (!simulation.Noclip) mechanisms?.Update(simulation.ActorRoot, simulation.InteractionRadius);
@@ -1206,6 +1243,11 @@ internal static class Program
view = Matrix4x4.CreateLookAtLeftHanded(simulation.CameraEye, simulation.CameraTarget, Vector3.UnitY);
renderEye = simulation.CameraEye; renderTarget = simulation.CameraTarget;
}
if(!inspecting&&rocketship is{Mounted:true})
{
renderEye=rocketship.CameraEye;renderTarget=rocketship.CameraTarget;
view=Matrix4x4.CreateLookAtLeftHanded(renderEye,renderTarget,Vector3.UnitY);
}
if (!inspecting && simulation?.Noclip != true && director?.CameraEye is { } storyEye && director.CameraTarget is { } storyTarget)
{
view = Matrix4x4.CreateLookAtLeftHanded(storyEye, storyTarget, Vector3.UnitY);
@@ -1220,6 +1262,7 @@ internal static class Program
bubbleVisuals?.Update(mesh,simulation!.Bubble,simulation.BubbleRoot,renderEye,renderTarget);
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);
spriteVisuals?.FaceCamera(renderEye, renderTarget, mesh);
objectivePanel?.Key(keys.Contains(18) && !debugMenu.Open && !inspecting && !practice.Active && gadgetScreen?.Open != true
&& director is { Controlled: true, InventoryEnabled: true });
@@ -1234,7 +1277,7 @@ internal static class Program
}
var gameplayProjection = originalCamera || simulation != null && !inspecting;
var cameraMode = simulation?.Noclip == true && !inspecting ? "NOCLIP" : !inspecting && director?.CameraEye != null ? "CUTSCENE"
: simulation != null && !inspecting ? "GAMEPLAY" : originalCamera ? "STRT" : "ORBIT";
: rocketship?.Mounted==true&&!inspecting?"ROCKETSHIP":simulation != null && !inspecting ? "GAMEPLAY" : originalCamera ? "STRT" : "ORBIT";
var debugStatus = new DebugStatus(level?.Code ?? "PREVIEW", originalStart?.Tag ?? "NONE",
simulation?.ActorRoot ?? Vector3.Zero, simulation?.Yaw ?? 0, simulation?.Speed ?? 0,
simulation?.Grounded ?? false, simulation?.Energy ?? 0, interactions?.Score ?? 0,
@@ -1253,6 +1296,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}",
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,
CameraObstruction = debugCameraRay?.Enabled, CameraPolygons = debugCameraRay?.PolygonCount ?? 0,
@@ -1284,6 +1328,7 @@ internal static class Program
}
if (simulation != null && characterDraw != null)
{
characterDraw.Visible=rocketship?.Mounted!=true;
PlayerGadgetMaterial.Apply(characterDraw,simulation.Appearance);
var color=simulation.Appearance.Color;
for(var i=0;i<animations!.Current.Base.Vertices.Length;i++)
@@ -1291,6 +1336,12 @@ internal static class Program
}
renderer.UpdateVertices(mesh.Vertices);
renderer.Render(view * projection);
if(rocketFixture!=null)
{
rocketFixture.AfterFrame(count);
if(RocketshipSmoke.StageName(count) is{} stage&&Option(args,"--screenshot") is{} capture)
renderer.SavePpm(Path.ChangeExtension(capture,$".{stage}.ppm"));
}
if(baseballFixture!=null)
{
baseballFixture.AfterFrame(count);
@@ -1583,6 +1634,12 @@ internal static class Program
if(!headless)Console.WriteLine($"Baseball SDL keys received: {sawBaseballKeys==15}.");
if(!baseballFixture.Passed || !headless && sawBaseballKeys!=15)return 2;
}
if(rocketFixture!=null)
{
Console.WriteLine(rocketFixture.Report);
if(!headless)Console.WriteLine($"Rocketship SDL keys received: {sawRocketKeys==63}.");
if(!rocketFixture.Passed||!headless&&sawRocketKeys!=63)return 2;
}
if (bubbleFixture!=null)
{
Console.WriteLine(bubbleFixture.Report);