Implement source-backed Scooter vehicle in tutorial and outside

This commit is contained in:
UnixNight committed 2026-11-04 18:06:09 -05:00
1 parent 8df5e81070
commit 62c07a3d59
44 files changed
+3135 -174

No files matched your search

+7 -6
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, GiveRocketship, GiveGrappler }
GiveInvisible, UnequipGadget, GiveBubble, GiveBaseball, GiveAllGadgets, GiveRocketship, GiveGrappler, GiveScooter }
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? ScooterState { get; init; }
public string? GrapplerState { get; init; }
public string? RocketshipState { get; init; }
public float BodyRadius { get; init; } = 60;
@@ -58,7 +59,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 => 17, 2 => 9, _ => ItemCount };
public int PageItems => Page switch { 1 => 18, 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];
@@ -122,7 +123,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,15=>DebugAction.GiveRocketship,16=>DebugAction.GiveGrappler, _ => DebugAction.None
13 => DebugAction.GiveBaseball, 14 => DebugAction.GiveAllGadgets,15=>DebugAction.GiveRocketship,16=>DebugAction.GiveGrappler,17=>DebugAction.GiveScooter, _ => DebugAction.None
};
if (Page == 2) return Selected switch
{
@@ -162,7 +163,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)}",
system.GrapplerState is{} grapple?$"GRAPPLER {grapple}":system.RocketshipState is{} rocket?$"ROCKET {rocket}":$"BASEBALL {system.BaseballState}"];
system.ScooterState is{} scooter?$"SCOOTER {scooter}":system.GrapplerState is{} grapple?$"GRAPPLER {grapple}":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",
@@ -170,13 +171,13 @@ 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 / SELECT ROCKETSHIP (VR02)", "GIVE / SELECT GRAPPLER (VR08)"] : [
"GIVE ALL GADGETS", "GIVE / SELECT ROCKETSHIP (VR02)", "GIVE / SELECT GRAPPLER (VR08)", "GIVE / SELECT SCOOTER (VR05 / OUTSIDE)"] : [
$"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"];
return new([.. header, .. items, "TAB NEXT PAGE UP/DOWN SELECT ENTER APPLY",
Page == 1 ? "FLY: WASD/ARROWS SPACE/E UP CTRL/Q DOWN SHIFT FAST" : "CHECKPOINT: DEBUG-CHECKPOINT.TSK BESIDE EXECUTABLE",
"F1 / ESC CLOSE - ACTIONS USE EXISTING SYSTEMS", Message], header.Length + Selected);
Message], header.Length + Selected);
}
return new([
"NEUTRON DEBUG MENU - F1",
+75
View File
@@ -0,0 +1,75 @@
using System.Numerics;
using GamePort.Game;
namespace GamePort.Application;
/// <summary>Ordinary input replay at the authored tutorial/outside start. Extra
/// body/input/frame ticks reuse received input; no root, speed or timer seeding.</summary>
public sealed class ScooterSmoke
{
private readonly LabSimulation player;
private readonly PlayerSceneBinding binding;
private readonly SceneDirector director;
private readonly SceneInteractions interactions;
private readonly Scooter scooter;
private readonly string level;
private readonly bool[] checks=new bool[10];
private PlayerInput last;private Vector3 mountedRoot;private float yaw,speed;private int extra;
public ScooterSmoke(LabSimulation p,PlayerSceneBinding b,SceneDirector d,SceneInteractions i,string level)
{player=p;binding=b;director=d;interactions=i;scooter=b.Scooter!;this.level=level;i.Inventory.SetState(0,4,1);i.Inventory.SelectGadget(4);}
public void BeforeFrame(int frame,Action<uint,bool> key,bool headless)
{
if(frame==0&&!headless)key(81,true);
if(frame==1)
{
for(int i=0;i<120&&!scooter.Mounted;i++)Advance(1);
if(!headless){key(81,false);key(82,true);if(level=="LEV1")key(80,true);}mountedRoot=scooter.Root;
}
if(frame==2){Advance(90);yaw=scooter.Rotation.Y;if(!headless)key(80,true);}
if(frame==3){Advance(15);speed=scooter.Steering.Speed;if(!headless){key(82,false);key(80,false);key(81,true);}}
if(frame==4)
{
Advance(12);for(int i=0;i<120&&!scooter.Supported;i++)Advance(1);
if(!headless){key(81,false);key(225,true);}
}
if(frame==5){Advance(120);if(headless)interactions.Inventory.SelectGadget(-1);else{key(225,false);key(43,true);}}
if(frame==6){if(!headless)key(43,false);interactions.Inventory.SelectGadget(4);}
if(frame==7){if(level=="VR05")director.Trigger("scooter");else director.ReleasePlayerGadget();}
if(frame==8)
{
director.Skip();interactions.Inventory.SelectGadget(4);
if(headless)player.SetNoclip(true);else key(60,true);
}
if(frame==9)
{
if(headless){binding.ResetVehicle();player.Reset();}
else {key(60,false);key(21,true);}
}
}
public void Received(PlayerInput input)=>last=input;
private void Advance(int ticks)
{
for(int i=0;i<ticks;i++)
{
binding.Step(last);
interactions.Update(player.ActorRoot,player.InteractionRadius,scooter.Mounted?scooter.Actor:null);
interactions.UpdateEnergy(player.Energy);director.Step(FixedStepClock.Step);extra++;
}
}
public void AfterFrame(int frame)
{
Console.WriteLine($"Scooter {StageName(frame)}: root={scooter.Root}, rotation={scooter.Rotation}, velocity={scooter.Velocity}, scalar={scooter.Steering.Speed}, supported={scooter.Supported}, wheels={scooter.FrontSupports}/{scooter.RearSupports}, impact={scooter.ImpactActive}, contacts={scooter.Contacts}, jumps={scooter.Jumps}.");
if(frame==0)checks[0]=scooter.Spawned&&!scooter.Mounted&&player.GadgetMode==4;
if(frame==1)checks[1]=scooter.Mounted&&binding.InventoryControlled&&director.AuthoredControlledTag==scooter.Actor.Tag;
if(frame==2)checks[2]=scooter.Mounted&&Vector3.Distance(scooter.Root,mountedRoot)>100&&scooter.Steering.Speed>100;
if(frame==3)checks[3]=scooter.Rotation.Y!=yaw&&scooter.Steering.Angle>0;
if(frame==4)checks[4]=scooter.Steering.Speed<speed&&scooter.Jumps>0;
if(frame==5)checks[5]=!scooter.Spawned&&!scooter.Mounted&&!scooter.EnginePlaying&&director.Controlled;
if(frame==6)checks[6]=scooter.Mounted&&player.GadgetMode==4;
if(frame==7)checks[7]=!scooter.Spawned&&!scooter.EnginePlaying&&player.GadgetMode==-1;
if(frame==8)checks[8]=player.Noclip&&!scooter.Spawned&&interactions.Inventory.SelectedGadget==-1;
if(frame==9)checks[9]=!player.Noclip&&!scooter.Spawned&&scooter.BodySteps==0;
}
public bool Passed=>checks.All(v=>v);
public string Report=>$"Scooter {level}: summon={checks[0]}, contact mount={checks[1]}, drive={checks[2]}, steer={checks[3]}, brake/jump={checks[4]}, dismount={checks[5]}, remount={checks[6]}, authored cleanup={checks[7]}, noclip={checks[8]}, reset={checks[9]}, extra ordinary ticks={extra}.";
public static PlayerInput Input(int frame,string level)=>new(frame is 1 or 2,frame is 0 or 3,frame==2||frame==1&&level=="LEV1",false,frame==4);
public static string? StageName(int frame)=>frame switch{0=>"summoned",1=>"mounted",2=>"driving",3=>"steer",4=>"jump",5=>"dismounted",6=>"remounted",7=>"cleanup",8=>"noclip",9=>"reset",_=>null};
}
@@ -0,0 +1,73 @@
using System.Numerics;
using System.Text.Json;
using GamePort.Assets;
using GamePort.Game;
namespace GamePort.Application;
/// <summary>Original scooter.omt shape0 and four shape1 wheels, plus exact
/// HISCOOT/HISCOOTSTOP source-pivot morphs. Null-material faces stay undrawn.</summary>
public sealed class ScooterVisuals
{
private sealed record Static(Mesh Source,int Offset,MeshDraw[] Draws);
private sealed record Clip(MorphAnimation Source,int Offset,MeshDraw Draw);
private readonly Static body;
private readonly Static[] wheels;
private readonly Clip scoot,stop;
public Mesh Mesh{get;}
public ScooterVisuals(Mesh combined,string preparedRoot)
{
var root=Path.GetFullPath(Path.Combine(preparedRoot,"scooter"));
using var document=JsonDocument.Parse(File.ReadAllBytes(Path.Combine(root,"scooter.json")));
var data=document.RootElement;
if(data.GetProperty("schema").GetInt32()!=1)throw new InvalidDataException("Unknown Scooter schema");
string Resource(string key)
{
var path=Path.GetFullPath(Path.Combine(root,data.GetProperty(key).GetString()!));
if(!path.StartsWith(root+Path.DirectorySeparatorChar,StringComparison.Ordinal))throw new InvalidDataException("Scooter path escapes resources");
return path;
}
Static Append(Mesh source)
{
var textures=new Dictionary<int,PngImage>(combined.Textures);var ids=new Dictionary<int,int>();
int next=int.MinValue;foreach(var pair in source.Textures)
{while(textures.ContainsKey(next))next++;ids[pair.Key]=next;textures.Add(next++,pair.Value);}
int offset=combined.Vertices.Length;uint indexOffset=(uint)combined.Indices.Length;
var draws=source.Draws.Select(d=>new MeshDraw(d.FirstIndex+indexOffset,d.IndexCount,d.TextureId==-1?-1:ids[d.TextureId])
{Visible=false,Blend=d.Blend,Opacity=d.Opacity}).ToArray();
combined=new([..combined.Vertices,..source.Vertices],[..combined.Indices,..source.Indices.Select(i=>i+(uint)offset)])
{HasExplicitDraws=true,Textures=textures,Draws=[..combined.Draws,..draws],CollisionPolygons=combined.CollisionPolygons,
HasCollisionMaterialIds=combined.HasCollisionMaterialIds};
return new(source,offset,draws);
}
Clip Load(string key)
{
var source=new MorphAnimation(Resource(key));int offset=combined.Vertices.Length,id=int.MinValue;
while(combined.Textures.ContainsKey(id))id++;combined=source.AppendTo(combined,id);
var draw=combined.Draws[^1];draw.Visible=false;return new(source,offset,draw);
}
body=Append(Mesh.LoadSceneJson(Resource("bodyMesh")));
var wheel=Mesh.LoadSceneJson(Resource("wheelMesh"));wheels=Enumerable.Range(0,4).Select(_=>Append(wheel)).ToArray();
scoot=Load("scootAnimation");stop=Load("stopAnimation");Mesh=combined;
}
public void Update(Mesh destination,Scooter vehicle,double time,PlayerAppearance appearance)
{
Draw(body,vehicle.Root,vehicle.Rotation,vehicle.Spawned);
for(int i=0;i<4;i++)Draw(wheels[i],vehicle.WheelRoots[i],vehicle.WheelRotations[i],vehicle.Spawned);
Pose(scoot,vehicle.Mounted&&!vehicle.RiderStopped);Pose(stop,vehicle.Mounted&&vehicle.RiderStopped);
void Draw(Static visual,Vector3 root,Vector3 angles,bool visible)
{
foreach(var draw in visual.Draws)draw.Visible=visible;
if(!visible)return;var model=RocketOrientation.Model(angles,root,Vector3.One);
for(int i=0;i<visual.Source.Vertices.Length;i++)
{var v=visual.Source.Vertices[i];v.Position=Vector3.Transform(v.Position,model);destination.Vertices[visual.Offset+i]=v;}
}
void Pose(Clip clip,bool visible)
{
clip.Draw.Visible=visible;if(!visible)return;
clip.Source.Sample(time,destination.Vertices.AsSpan(clip.Offset,clip.Source.Base.Vertices.Length),
RocketOrientation.Model(vehicle.RiderRotation,vehicle.Root,Vector3.One));
PlayerGadgetMaterial.Apply(clip.Draw,appearance);var color=appearance.Color;
for(int i=0;i<clip.Source.Base.Vertices.Length;i++)destination.Vertices[clip.Offset+i].Color*=new Vector3(color.X,color.Y,color.Z);
}
}
}
+2
View File
@@ -54,6 +54,8 @@ public sealed class SceneAudio : IDisposable
loops.Add(loopOwner, new(wave.Path, true, Paused, EffectsMuted));
}
}
public void TuneLoop(string owner,Func<int,int> frequency)
{if(loops.TryGetValue(owner,out var stream))stream.SetFrequency(frequency(stream.SourceFrequency));}
public void StopLoop(string owner)
{
if (loops.Remove(owner, out var stream)) stream.Dispose();
+7
View File
@@ -10,6 +10,7 @@ public sealed class SdlAudio : IDisposable
private int length;
private readonly bool loop;
private bool audioInitialized;
public int SourceFrequency {get;private set;}
public bool Paused { get; private set; }
public bool Muted { get; private set; }
public int QueuedBytes
@@ -28,6 +29,7 @@ public sealed class SdlAudio : IDisposable
try
{
if(!Sdl.SDL_LoadWAV(Path.GetFullPath(path),out var spec,out data,out var size))throw new InvalidOperationException(Sdl.Error);
SourceFrequency=spec.Frequency;
length=checked((int)size);
stream=Sdl.SDL_OpenAudioDeviceStream(uint.MaxValue,ref spec,0,0);
if(stream==0)throw new InvalidOperationException(Sdl.Error);
@@ -55,6 +57,11 @@ public sealed class SdlAudio : IDisposable
if (!Sdl.SDL_SetAudioStreamGain(stream, muted ? 0 : 1)) throw new InvalidOperationException(Sdl.Error);
Muted = muted;
}
public void SetFrequency(int frequency)
{
ObjectDisposedException.ThrowIf(stream==0,this);
if(frequency<=0||!Sdl.SDL_SetAudioStreamFrequencyRatio(stream,(float)frequency/SourceFrequency))throw new InvalidOperationException(Sdl.Error);
}
private void Queue(){if(!Sdl.SDL_PutAudioStreamData(stream,data,length))throw new InvalidOperationException(Sdl.Error);}
public void Pump(){if(!Paused && loop && QueuedBytes<length)Queue();}
public void Dispose()
+23 -3
View File
@@ -37,7 +37,8 @@ public sealed class ActorPatrol
public float WaitRemaining { get; private set; }
public string? CurrentWaypoint => waypoint?.Tag;
public string? PreviousWaypoint => previousWaypoint?.Tag;
public bool SupportedState => actor.AIstate is 1 or 3 or 7 or 9 || actor.Kind == "3CAR" && actor.AIstate == 6;
public bool FollowPlayer {get;set;}
public bool SupportedState => actor.AIstate is 1 or 3 or 7 or 9 || actor.Kind == "3CAR" && actor.AIstate == 6 || FollowPlayer&&actor.Kind=="3DOG"&&actor.AIstate==4;
public ActorPatrol(DirectorActor actor, Func<string, DirectorActor?> findActor,
Func<PatrolBodyState, float, PatrolBodyState> integrateBody,
@@ -86,7 +87,7 @@ public sealed class ActorPatrol
if (!float.IsFinite(dt) || dt < 0 || dt > 1) throw new ArgumentOutOfRangeException(nameof(dt));
SynchronizeAuthoredState();
if (!SupportedState) return false;
if (!actor.Active) return true;
if (!actor.Active||!actor.MovementEnabled) return true;
if (!float.IsFinite(actor.Speed)) throw new InvalidOperationException("Nonfinite Goddard speed");
// EXE408023->40E050: the body consumes the *previous* velocity first.
@@ -104,6 +105,7 @@ public sealed class ActorPatrol
{
case 1: Velocity = Vector3.Zero; break; // EXE40835D, after body integration.
case 3: StepPatrol(); break;
case 4: StepFollow(); break;
case 7: StepWait(dt); break;
// State9 jumps directly to the common finisher408911. State6 calls
// sensing409CC0 first; source player-contact dispatch is implemented
@@ -112,12 +114,30 @@ public sealed class ActorPatrol
}
// States1/6/7 return before selecting a destination angle (409186..19B).
// Retain the old destination on a waypoint change, as the source does.
if (actor.AIstate == 3 && DestinationDelta.X * DestinationDelta.X + DestinationDelta.Z * DestinationDelta.Z > 0)
if (actor.AIstate is 3 or 4 && DestinationDelta.X * DestinationDelta.X + DestinationDelta.Z * DestinationDelta.Z > 0)
desiredYaw = MathF.Atan2(-DestinationDelta.X, DestinationDelta.Z) * (180 / MathF.PI);
Publish();
return true;
}
private void StepFollow()
{
var target=findActor("JIM1");if(target==null||!target.Active)return;
DestinationDelta=target.Position-actor.Position;DestinationDistance=DestinationDelta.Length();
var length=magnitude(DestinationDelta);
float multiplier=DestinationDistance>=2000?3:DestinationDistance>=1000?1.7f:1;
Velocity=Arrived||length==0?Vector3.Zero:DestinationDelta/length*(actor.Speed*multiplier);
if(DestinationDistance<ArrivalDistance)Arrived=true;
else if(DestinationDistance>ArrivalDistance*1.5f)Arrived=false;
actor.Speed=DestinationDistance>440?600:450;
if(DestinationDistance>1500)
{
actor.Position=target.Position+RocketOrientation.Rotate(new(0,0,-800),target.Rotation);
Velocity=Vector3.Zero;
}
actor.Animation=magnitude(Velocity)>20?"RUN":"WAG";
}
private void StepPatrol()
{
waypoint ??= findActor(actor.Patrol ?? "none");
+15 -1
View File
@@ -238,7 +238,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, Action? afterPhysics = null)
public void Step(PlayerInput input, bool controlled = true, bool? anyControlled = null, Action? afterPhysics = null,Func<bool>? controlledAfterPhysics=null)
{
if (Noclip)
{
@@ -251,6 +251,7 @@ public sealed class LabSimulation
// scene registry, original cadence or original collision response.
StepPhysics();
afterPhysics?.Invoke();
if(controlledAfterPhysics!=null)controlled=controlledAfterPhysics();
if (controlled && !InputAfterPlayerUpdate) StepInput(input);
//42469F..4246DC runs independently of raw ownership.
if (Grounded)
@@ -288,6 +289,19 @@ public sealed class LabSimulation
forceFall=true;CameraEye=sharedEye;
}
public void EnterScooter()
{
CancelPoweredFlight(); //425120 only cancels mode1 jump/effect.
TracksBubbleOrientation=true;
}
public void ApplyScooterTransform(Vector3 root,Vector3 rotation)
{ApplyAuthoredTransform(root,rotation.Y);Pitch=rotation.X;Roll=rotation.Z;targetPitch=Pitch;targetRoll=Roll;targetYaw=Yaw;}
public void LeaveScooter(Vector3 root,Vector3 rotation,Vector3 eye)
{
ApplyScooterTransform(root+Vector3.UnitY*40,rotation);
Velocity=Vector3.Zero;extraAirAcceleration=0;CameraEye=eye;
}
public void RocketImpact()
{
AdjustEnergy(-1);ScoreChanged?.Invoke(-1);CancelPoweredFlight();
+7 -1
View File
@@ -50,7 +50,8 @@ public sealed class OriginalBodyPhysics
public OrdinaryBodyStep Step(OrdinaryBodyState body, float seconds,
float radius = OriginalBodySupport.JimmyRadius, float factor = OriginalBodySupport.JimmyFactor,
float friction = .8f, float suppressionScale = .5f, bool geometryEnabled = true,
BodyResponseProfile profile = BodyResponseProfile.Jimmy)
BodyResponseProfile profile = BodyResponseProfile.Jimmy,
Func<OrdinaryBodyState,CameraRayPolygon,OrdinaryBodyState>? wallContact = null)
{
Finite(body.Position); Finite(body.Velocity); Finite(body.Acceleration); Finite(body.Impulse);
Finite(body.AngularVelocity); Finite(body.Rotation);
@@ -111,6 +112,11 @@ public sealed class OriginalBodyPhysics
}
}
var position = move.Position;
if(wallContact!=null&&move.CallbackPolygon is{StoredNormal.Y:>-.7f}terminal)
{
body=wallContact(body with{Position=position,Velocity=velocity,Acceleration=acceleration,Impulse=impulse},terminal);
position=body.Position;velocity=body.Velocity;acceleration=body.Acceleration;impulse=body.Impulse;
}
if (horizontalFirst) position.Y += delta.Y;
position.Y = MathF.Max(position.Y, -25000);
body = body with { Position = position, Velocity = velocity, Acceleration = acceleration, Impulse = impulse };
+1 -1
View File
@@ -69,7 +69,7 @@ public sealed class OriginalCameraRay
public static OriginalCameraRay FromRouteScene(Mesh mesh, string levelCode)
{
ArgumentNullException.ThrowIfNull(mesh);
if (levelCode is not ("LV1B" or "VR01" or "VR02" or "VR04" or "VR07" or "VR08" or "LEV1"))
if (levelCode is not ("LV1B" or "VR01" or "VR02" or "VR04" or "VR05" or "VR07" or "VR08" or "LEV1"))
throw new NotSupportedException("Static camera game-filter recovery covers only selected route/tutorial scenes");
if (mesh.Indices.Length % 3 != 0 || mesh.CollisionPolygons.Length != mesh.Indices.Length / 3)
throw new InvalidDataException("Original camera query requires source polygon metadata");
+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 "VR02" or "VR04" or "VR07" or "VR08" or "LEV1"))
if (level is not ("LV1B" or "VR01" or "VR02" or "VR04" or "VR05" or "VR07" or "VR08" 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");
+53 -10
View File
@@ -10,16 +10,18 @@ public sealed class PlayerSceneBinding : IDisposable
private readonly LabSimulation player;
private readonly SceneInventory inventory;
private readonly string tag;
public Scooter? Scooter {get;}
public Rocketship? Rocketship { get; }
public bool InventoryControlled=>director.InventoryEnabled&&(director.Controlled||
Rocketship is{Mounted:true} rocket&&director.ControlledTag==rocket.Actor.Tag);
Rocketship is{Mounted:true} rocket&&director.ControlledTag==rocket.Actor.Tag||
Scooter is{Mounted:true} scooter&&director.ControlledTag==scooter.Actor.Tag);
public int UnsupportedGadgetCleanups { get; private set; }
public PlayerSceneBinding(SceneDirector director, LabSimulation player, SceneInventory inventory, string tag,
Rocketship? rocketship=null)
Rocketship? rocketship=null,Scooter? scooter=null)
{
this.director = director; this.player = player; this.inventory = inventory; this.tag = tag;
Rocketship=rocketship;
Rocketship=rocketship;Scooter=scooter;
if(rocketship!=null)rocketship.RiderHit+=player.RocketImpact;
director.ActorPreparing += Prepare;
director.AuthoredTransformChanged += Transform;
@@ -34,12 +36,31 @@ public sealed class PlayerSceneBinding : IDisposable
public bool Step(PlayerInput input)
{
if(player.Noclip&&Rocketship?.Mounted==true)inventory.SelectGadget(-1);
if(player.Noclip&&(Rocketship?.Mounted==true||Scooter?.Spawned==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();
bool ScooterControl()=>Scooter is{Mounted:true}s&&(director.AuthoredControlledTag==s.Actor.Tag||director.DebugForceControl);
var acceptsInput = director.Controlled || player.Noclip || VehicleControl()||ScooterControl();
Scooter?.StepBody(FixedStepClock.Step,input);
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);});
bool JimmyControl()=>(director.Controlled&&Rocketship?.Mounted!=true&&Scooter?.Mounted!=true)||player.Noclip;
player.Step(input,JimmyControl(),director.ControlledTag!=null,()=>
{
if(Scooter is{Spawned:true,Mounted:false}s&&!player.Noclip&&s.TryMount(player.ActorRoot,player.InteractionRadius))
{player.EnterScooter();director.TransferControl(s.Actor);}
if(!player.InputAfterPlayerUpdate)
{
if(VehicleControl())Rocketship!.StepInput(input,FixedStepClock.Step);
if(ScooterControl())Scooter!.StepInput(input,FixedStepClock.Step);
}
},JimmyControl);
Scooter?.StepFrame(input,FixedStepClock.Step);
if(Scooter is{Mounted:true}scooter)
{
player.ApplyScooterTransform(scooter.Root,scooter.Rotation);
director.TransferControl(scooter.Actor);
if(player.InputAfterPlayerUpdate&&ScooterControl())scooter.StepInput(input,FixedStepClock.Step);
}
Scooter?.StepWheels();
Rocketship?.StepFrame(input,FixedStepClock.Step);
if(Rocketship is{Mounted:true} rocket)
{
@@ -69,13 +90,25 @@ 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 1 or 2 or 6 or 7 || inventory.SelectedGadget is -1 or 3)
if (player.GadgetMode is 0 or 1 or 2 or 4 or 6 or 7 || inventory.SelectedGadget is -1 or 3)
{ inventory.SelectGadget(-1); player.GadgetMode = -1; }
else if (player.GadgetMode != -1) UnsupportedGadgetCleanups++;
}
private void Selected(int item)
{
if(Scooter is{Spawned:true}scooter)
{
bool mounted=scooter.Mounted;
if(director.FindActor("C3DGODDARD") is{} dog)
{dog.Position=scooter.Root;dog.Rotation=scooter.Rotation;dog.Visible=dog.BodyEnabled=dog.MovementEnabled=true;}
scooter.Release();
if(mounted)
{
player.LeaveScooter(scooter.Root,scooter.Rotation,scooter.CameraEye);
if(director.FindActor(tag) is{} rider){rider.Animation="RUN";director.TransferControl(rider);}
}
}
if(Rocketship?.Mounted==true)
{
Rocketship.Release();
@@ -85,7 +118,16 @@ public sealed class PlayerSceneBinding : IDisposable
if (item==0 && director.FindActor(tag) is{} actor) player.SeedBubbleTilt(actor.Rotation);
//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);
player.GadgetMode=item==1&&Rocketship==null||item==4&&Scooter==null?-1:GadgetScreen.EquippedMode(item);
if(item==4&&Scooter!=null)
{
if(director.FindActor("C3DGODDARD") is{} dog&&dog.BodyEnabled)
{
Scooter.Summon(dog.Position,dog.Rotation,player.CameraEye);
dog.Visible=dog.BodyEnabled=dog.MovementEnabled=false;
}
else player.GadgetMode=-1;
}
if(item==1&&Rocketship!=null)
{
var rider=director.FindActor(tag)!;
@@ -97,8 +139,9 @@ public sealed class PlayerSceneBinding : IDisposable
public void ResetVehicle()
{
if(Rocketship?.Mounted==true)inventory.SelectGadget(-1);
if(Rocketship?.Mounted==true||Scooter?.Spawned==true)inventory.SelectGadget(-1);
Rocketship?.Reset();
Scooter?.Reset();
}
private void DefaultGadget() => inventory.SelectGadget(-1);
+12
View File
@@ -183,6 +183,18 @@ public sealed class SceneDirector
public DirectorActor? FindActor(string tag) => actors.GetValueOrDefault(tag);
internal DirectorActor AddOwnedActor(string tag,string kind,Vector3 root)
{
if(actors.TryGetValue(tag,out var existing))return existing;
var actor=new DirectorActor(null,tag,kind,root);Actors.Add(actor);actors.Add(tag,actor);return actor;
}
public DirectorActor EnsureCompanion(Vector3 root,Vector3 rotation)
{
var actor=AddOwnedActor("C3DGODDARD","3DOG",root);
actor.Position=root;actor.Rotation=rotation;actor.AIstate=4;actor.Speed=450;return actor;
}
internal void TransferControl(DirectorActor actor)
{
if(!Actors.Contains(actor))throw new ArgumentException("Control requires a registered actor",nameof(actor));
+3 -3
View File
@@ -81,7 +81,7 @@ public sealed class SceneInteractions
{
if (!float.IsFinite(activePlayerRoot.X + activePlayerRoot.Y + activePlayerRoot.Z)
|| !float.IsFinite(playerRadius) || playerRadius < 0) throw new ArgumentOutOfRangeException(nameof(activePlayerRoot));
bool VehicleControlled()=>vehicle is{Kind:"3ROC"}&&director.AuthoredControlledTag==vehicle.Tag;
bool VehicleControlled()=>vehicle is{Kind:"3ROC" or "3JEE"}&&director.AuthoredControlledTag==vehicle.Tag;
bool Controlled()=>director.Controlled||VehicleControlled();
if (!Controlled()) return;
HideCollected();
@@ -97,9 +97,9 @@ public sealed class SceneInteractions
if (!director.Controlled) break;
}
// Carl InitObject413E2F..45 sets radius100 and support factor0.75.
//435D08 pickups require the raw controlled ship.457EE6 LOAD requires
//435D08 pickups require the raw controlled actor.457EE6 LOAD requires
//the real Jimmy passenger; the coincident actors keep distinct radii.
var contactRadius=source.Kind=="3PIC"&&VehicleControlled()?50:playerRadius;
var contactRadius=source.Kind=="3PIC"&&VehicleControlled()?(vehicle!.Kind=="3JEE"?150: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;
+155
View File
@@ -0,0 +1,155 @@
using System.Numerics;
using GamePort.Assets;
namespace GamePort.Game;
/// <summary>Jimmy's owned C3DJEEP, summoned at Goddard and mounted by contact.
/// Ordinary source vehicle/wheel profile is admitted in VR05 and outsideLEV1.</summary>
public sealed class Scooter : IDisposable
{
private readonly OriginalStaticCollision world;
private readonly OriginalBodyPhysics physics;
private readonly Dictionary<(int,int),Vector3> normals;
private readonly ScooterWheels wheels=new();
private OrdinaryBodyState body;
private Vector3 destination;
private float poseClock,faceRate=5,impactTime;
private bool jumpLatch;
private Vector3? supportNormal;
public DirectorActor Actor{get;}
public bool Spawned{get;private set;}
public bool Mounted{get;private set;}
public bool ImpactActive{get;private set;}
public bool RiderStopped{get;private set;}
public bool EnginePlaying{get;private set;}
public Vector3 Root=>body.Position;
public Vector3 Rotation{get;private set;}
public Vector3 RiderRotation{get;private set;}
public Vector3 Velocity=>body.Velocity;
public Vector3 PendingImpulse=>body.Impulse;
public bool Supported=>body.Supported;
public ScooterSteering Steering{get;private set;}
public IReadOnlyList<Vector3> WheelRoots=>wheels.Roots;
public IReadOnlyList<Vector3> WheelRotations=>wheels.Rotations;
public int FrontSupports=>wheels.Front;
public int RearSupports=>wheels.Rear;
public int BodySteps{get;private set;}
public int InputSteps{get;private set;}
public int FrameSteps{get;private set;}
public int Contacts{get;private set;}
public int Jumps{get;private set;}
public Vector3 CameraEye{get;private set;}
public Vector3 CameraTarget{get;private set;}
public Func<Vector3,Vector3,float,Vector3>? DynamicRootResolver{get;set;}
public event Action? EngineStarted;
public event Action? EngineStopped;
public event Action<float>? EngineSpeedChanged;
public event Action? MountedChanged;
public Scooter(DirectorActor actor,Mesh mesh,string level)
{
if(level is not("VR05" or "LEV1"))throw new NotSupportedException("Scooter body profile covers VR05 and outsideLEV1");
Actor=actor;world=OriginalStaticCollision.FromRouteScene(mesh,level);
//421910 ordinary callback is independent of Jimmy's special materials.
physics=new(world,allowSpecialMaterials:true);
normals=mesh.CollisionPolygons.ToDictionary(p=>(p.ShapeId,p.PolygonIndex),p=>p.Normal);
Reset();
}
public void Reset()
{
Release();body=default;Steering=default;RiderRotation=Rotation=destination=Vector3.Zero;
faceRate=5;poseClock=impactTime=0;ImpactActive=jumpLatch=RiderStopped=false;wheels.Reset();
BodySteps=InputSteps=FrameSteps=Contacts=Jumps=0;
}
public void Summon(Vector3 root,Vector3 rotation,Vector3 eye)
{
body=body with{Position=root};RiderRotation=Rotation=destination=rotation;CameraEye=eye;CameraTarget=eye+Vector3.UnitZ*200;
Spawned=true;Actor.Visible=Actor.BodyEnabled=Actor.MovementEnabled=true;Sync();
}
public bool TryMount(Vector3 jimmyRoot,float radius)
{
if(!Spawned||Mounted||OriginalBodySupport.QuickMagnitude(Root-jimmyRoot)>=150+radius)return false;
Mounted=true;RiderStopped=false;poseClock=0;MountedChanged?.Invoke();return true;
}
public void Release()
{
Spawned=Mounted=false;Actor.Visible=Actor.BodyEnabled=Actor.MovementEnabled=false;
if(EnginePlaying){EnginePlaying=false;EngineStopped?.Invoke();}
}
public void StepBody(float dt,PlayerInput input)
{
if(!Spawned)return;
var result=physics.Step(body,dt,150,.2f,friction:.9f,suppressionScale:1,wallContact:(current,wall)=>
{body=current;Contact(wall.StoredNormal,input,dt);return body with{PublishedSpeed=Steering.Speed};});
body=result.Body;BodySteps++;
if(DynamicRootResolver!=null)body=body with{Position=DynamicRootResolver(result.PreviousPosition,Root,150)};
if(result.SupportHit is{} hit&&normals.TryGetValue((hit.ShapeId,hit.PolygonId),out var normal))
supportNormal=normal;
Sync();
}
public void StepInput(PlayerInput input,float dt)
{
if(!Mounted)return;InputSteps++;
var next=ScooterMotion.Input(Steering,input,RearSupports,dt);
Steering=ImpactActive?Steering with{Angle=next.Angle,KeyboardTurn=next.KeyboardTurn}:next;
var camera=ScooterCamera.Follow(Root,Rotation,CameraEye,dt,(start,end)=>
{
var context=physics.LastStaticContext??new(64.9519043f);
context.Nearest=context.Nearest with{FaceDistance=130000};
//413870 pushes false: camera reclip tests faces, not wheel/body edges.
return world.Move(start,end-start,64.9519043f,context,edges:false).Position;
},impact:ImpactActive);
CameraEye=camera.Eye;CameraTarget=camera.Target;
}
public void StepFrame(PlayerInput input,float dt)
{
if(!Spawned)return;
Rotation=ScooterWheels.Face(Rotation,destination,faceRate,dt);
if(ImpactActive)
{
var impact=ScooterMotion.Impact(Velocity,body.AngularVelocity,impactTime,dt);
impactTime=impact.Time;ImpactActive=impact.Active;
body=body with{Velocity=impact.Velocity,AngularVelocity=impact.AngularVelocity};
if(!ImpactActive)Steering=Steering with{Speed=0};
}
else
{
var drive=ScooterMotion.Apply(Steering,Velocity,Rotation,Supported,FrontSupports,RearSupports,dt,.9f);
Steering=drive.Steering;Rotation=drive.Rotation;body=body with{Velocity=drive.Velocity};
}
FrameSteps++;
if(Mounted)
{
if(!input.Jump)jumpLatch=false;
else if(!jumpLatch&&Supported){body=body with{Impulse=new(0,700,0)};jumpLatch=true;Jumps++;}
poseClock+=dt;
if((double)poseClock>.3){RiderStopped=Steering.Speed<10;poseClock=0;}
}
else {Steering=Steering with{Speed=0};faceRate=10;}
body=body with{PublishedSpeed=Steering.Speed};
//Jimmy copies the parent's Euler before the later wheel/lean phase.
RiderRotation=Rotation;
if(!EnginePlaying){EnginePlaying=true;EngineStarted?.Invoke();}
else EngineSpeedChanged?.Invoke(Steering.Speed);
Sync();
}
public void StepWheels()
{
if(!Spawned)return;
Rotation=Rotation with{Z=Steering.Angle*-.5f};
//Counts used by465220 are from the preceding wheel pass.
var oldFront=FrontSupports;var oldRear=RearSupports;
wheels.Update(Root,Rotation,Steering.Angle,Steering.Speed,Steering.Braking,ImpactActive,world);
if(oldFront+oldRear==0){destination=new(340,Rotation.Y,0);faceRate=2;}
else if(supportNormal is{} normal)destination=ScooterWheels.TerrainTarget(normal,Rotation.Y);
Sync();
}
private void Contact(Vector3 normal,PlayerInput input,float dt)
{
Contacts++;
var result=ScooterMotion.Contact(Steering.Speed,Velocity,Rotation,normal,body.Acceleration,ImpactActive,input.Forward||input.Fire,dt);
if(!ImpactActive&&result.Impact)impactTime=0;
ImpactActive=result.Impact;Steering=Steering with{Speed=result.Speed};body=body with{Acceleration=result.Acceleration};
}
private void Sync(){Actor.Position=Root;Actor.Rotation=Rotation;Actor.Speed=Steering.Speed;}
public void Dispose()=>Release();
}
+25
View File
@@ -0,0 +1,25 @@
using System.Numerics;
namespace GamePort.Game;
public readonly record struct ScooterCameraResult(Vector3 Eye,Vector3 Target,Vector3 DesiredEye,Vector3 Look,float Gain);
/// <summary>4130A0 default mode1. Clipping follows smoothing and uses a sphere,
/// then look minus NEW eye determines source signed14-bit aim.</summary>
public static class ScooterCamera
{
public static ScooterCameraResult Follow(Vector3 root,Vector3 rotation,Vector3 oldEye,float dt,Func<Vector3,Vector3,Vector3>? clip=null,bool impact=false)
{
var desired=root+RocketOrientation.Rotate(new(-30,0,-200),rotation)+Vector3.UnitY*50;
var delta=desired-oldEye;var distance=OriginalBodySupport.QuickMagnitude(delta);
float gain=distance>400?2.8f:distance>200?1.7f:1;
var eye=oldEye+delta*dt*gain;
if(impact)
{
//413157..4131C0: approach root X/Z at .3; leave eye Y unchanged.
desired=new(root.X,oldEye.Y,root.Z);gain=.3f;eye=oldEye+(desired-oldEye)*dt*gain;
}
if(clip!=null)eye=clip(root,eye);
var look=impact?root:root+RocketOrientation.Rotate(new(0,50,100),rotation);
var(p,y)=OriginalHeading.Angles(look-eye);
var direction=RocketOrientation.Rotate(Vector3.UnitZ,new(p*.02197265625f,y*.02197265625f,0));
return new(eye,eye+direction*200,desired,look,gain);
}
}
+102
View File
@@ -0,0 +1,102 @@
using System.Numerics;
namespace GamePort.Game;
public readonly record struct ScooterSteering(float Speed=0,float Angle=0,bool KeyboardTurn=false,bool Reverse=false,
bool Braking=false,bool Throttle=false,float BrakeTime=0,float YawRate=0,float Blend=0);
public readonly record struct ScooterDrive(ScooterSteering Steering,Vector3 Velocity,Vector3 Rotation);
public readonly record struct ScooterContact(float Speed,Vector3 Acceleration,bool Impact);
public readonly record struct ScooterImpact(Vector3 Velocity,Vector3 AngularVelocity,float Time,bool Active);
/// <summary>465830 keyboard prefix and465220 ordinary non-AI/non-sprint drive.
/// Wheel/body support is observed independently; never fabricated here.</summary>
public static class ScooterMotion
{
public const float Maximum=1485;
/// <summary>421910 with the constructor's disabled bounce flag.</summary>
public static ScooterContact Contact(float speed,Vector3 velocity,Vector3 rotation,Vector3 normal,
Vector3 acceleration,bool impact,bool throttle,float dt)
{
float length=OriginalBodySupport.QuickMagnitude(velocity with{Y=0});
var forward=RocketOrientation.Rotate(Vector3.UnitZ,rotation);
if(!impact&&length>20&&MathF.Abs(Vector3.Dot(forward,normal))>=.9f)
return new(0,Vector3.Zero,true);
if(impact||speed<=0||length==0)return new(speed,acceleration,impact);
float dot=Vector3.Dot(velocity/OriginalBodySupport.QuickMagnitude(velocity),normal);
dot*=dot<-.85f?3.5f:1.5f;
if(dot<0&&throttle)speed=MathF.Max(230,speed-MathF.Abs(dot)*1200*dt);
return new(speed,acceleration,impact);
}
/// <summary>4669F0 ordinary enabled-body impact suffix.</summary>
public static ScooterImpact Impact(Vector3 velocity,Vector3 angular,float time,float dt)
{
time+=dt;
return time>=4?new(Vector3.Zero,Vector3.Zero,time,false):
new(velocity+new Vector3(-velocity.X*dt,0,-velocity.Z*dt),angular-angular*dt,time,true);
}
public static ScooterSteering Input(ScooterSteering state,PlayerInput input,int rear,float dt)
{
var angle=state.Angle;var keyboard=state.KeyboardTurn;
if(input.Left){angle+=200*dt;keyboard=true;}
else if(input.Right){angle-=200*dt;keyboard=true;}
else if(keyboard)angle=angle>0?MathF.Max(0,angle-200*dt):MathF.Min(0,angle+200*dt);
angle=Math.Clamp(angle,-45,45);float speed=state.Speed;bool reverse=state.Reverse,brake=state.Braking;
bool throttle=rear>0&&(input.Forward||input.Fire);
if(throttle){if(speed<Maximum)speed=MathF.Min(Maximum,speed+700*dt);reverse=false;}
if(rear>0&&input.Backward)
{
if(!reverse)
{
reverse=true;
if(speed>0){speed=MathF.Max(0,speed-1200*dt);brake=true;}
else if(speed<0){speed=MathF.Min(0,speed+1200*dt);brake=true;}
}
else speed=MathF.Max(-Maximum*.4f,speed-1200*dt);
}
else {brake=false;reverse=false;}
return state with{Speed=speed,Angle=angle,KeyboardTurn=keyboard,Reverse=reverse,Braking=brake,Throttle=throttle};
}
public static ScooterDrive Apply(ScooterSteering state,Vector3 velocity,Vector3 rotation,bool supported,int front,int rear,float dt,float friction=.9f)
{
float speed=state.Speed,rate=state.YawRate,blend=state.Blend,timer=state.BrakeTime;
var horizontal=velocity with{Y=0};var magnitude=OriginalBodySupport.QuickMagnitude(horizontal);
if(magnitude>0)
{
if(front>0)
{
rate=front*state.Angle*MathF.Min(magnitude*.005f,1);
var direction=horizontal/magnitude;var forward=RocketOrientation.Rotate(Vector3.UnitZ,rotation);
var delta=rate*dt*(Vector3.Dot(direction,forward)<0?-1:1);
rotation=RocketOrientation.Add(rotation,new(0,delta,0));
}
if(front+rear!=0)
{
if(!state.Throttle&&!state.Reverse)
{speed=(float)(speed-speed*.5f*dt);if(speed>=-1&&speed<=1)speed=0;}
if(!state.Braking)speed=(float)(speed-Math.Abs(state.Angle)*(1.0/45)*(speed*.8f)*dt);
speed=(float)(speed-Math.Sin(rotation.X*.01745329238474369f)*500*dt);
}
}
if(supported&&front+rear>=2)
{
var forward=RocketOrientation.Rotate(Vector3.UnitZ,rotation);var direction=forward;
var liveMagnitude=OriginalBodySupport.QuickMagnitude(velocity);
if(speed>0&&liveMagnitude!=0)
{
direction=velocity/liveMagnitude;
if(Vector3.Dot(direction,forward)<0)direction=forward;
if(!state.Braking)
{
var factor=(float)(2250*.6600000262260437f*.20000000298023224f/speed);
blend=MathF.Min(friction,friction*factor);
direction=new(direction.X+forward.X*blend,forward.Y,direction.Z+forward.Z*blend);
}
timer=0;
}
else if(state.Braking){timer+=dt;if(timer<1)speed=0;}
var next=direction*speed;
if(velocity.Y<0)next.Y+=velocity.Y;
velocity=next;
}
return new(state with{Speed=speed,YawRate=rate,Blend=blend,BrakeTime=timer},velocity,rotation);
}
}
+65
View File
@@ -0,0 +1,65 @@
using System.Numerics;
namespace GamePort.Game;
/// <summary>412A90 four-child setup and467080 post-normal wheel positioning.
/// Child support is queried manually; children have no independent integrator.</summary>
public sealed class ScooterWheels
{
public const float Radius=23.769514083862305f;
public static readonly Vector3[] Offsets=[new(-3,1,73),new(3,1,73),new(-3,1,-30),new(3,1,-30)];
private readonly Vector3[] roots=new Vector3[4],angles=new Vector3[4];
private readonly float[] spins=new float[4];
private readonly bool[] supported=new bool[4];
public IReadOnlyList<Vector3> Roots=>roots;
public IReadOnlyList<Vector3> Rotations=>angles;
public int Front=>supported.Take(2).Count(v=>v);
public int Rear=>supported.Skip(2).Count(v=>v);
public void Reset(){Array.Clear(roots);Array.Clear(angles);Array.Clear(spins);Array.Clear(supported);}
public void Update(Vector3 root,Vector3 rotation,float steering,float speed,bool braking,bool crash,OriginalStaticCollision world)
{
var forward=RocketOrientation.Rotate(Vector3.UnitZ,rotation);
for(int i=0;i<4;i++)
{
var before=roots[i];var local=Offsets[i];var desired=root+RocketOrientation.Rotate(local,rotation);
if(!crash)
{
var result=OriginalBodySupport.Resolve(new(desired,before,Vector3.Zero,Vector3.Zero,Radius,1,PreventLowering:false),
supported[i],(a,b,s)=>world.TraceSupport(a,b,s));
supported[i]=result.Supported;
var anchor=result.Supported?result.SupportAnchor.Y:-25000;
local.Y=Math.Clamp(local.Y+anchor-desired.Y,Offsets[i].Y-15,Offsets[i].Y+15);
}
roots[i]=root+RocketOrientation.Rotate(local,rotation);
var delta=(roots[i]-before) with{Y=0};var distance=OriginalBodySupport.QuickMagnitude(delta);
if(distance!=0&&(speed<0||!braking))
spins[i]=RocketOrientation.AddAxis(spins[i],(float)(distance/Radius*57.295776f)*(Vector3.Dot(delta,forward)>0?1:-1));
angles[i]=i%2==0
?new(rotation.Z,RocketOrientation.AddAxis(rotation.Y,90),RocketOrientation.AddAxis(rotation.X,-spins[i]))
:new(RocketOrientation.AddAxis(0,-rotation.Z),RocketOrientation.AddAxis(rotation.Y,-90),RocketOrientation.AddAxis(rotation.X,spins[i]));
if(i<2)angles[i]=RocketOrientation.Add(angles[i],RocketOrientation.Rotate(new(0,steering,0),rotation));
}
}
public static Vector3 TerrainTarget(Vector3 normal,float yaw)
{
var(_,x)=OriginalHeading.Angles(new(normal.X,0,normal.Y));
var(_,z)=OriginalHeading.Angles(new(normal.Z,0,normal.Y));
var index=(int)((double)yaw*45.511112213134766)&16383;
var(sine,cosine)=RocketOrientation.Units(index);
//Source table cardinal endpoints are exact, rather than Math.Cos(pi/2)'s residue.
if((index&4095)==0){sine=index switch{4096=>1,12288=>-1,_=>0};cosine=index switch{0=>1,8192=>-1,_=>0};}
var components=new Vector3((float)(-x*(double)cosine-z*(double)sine),0,
(float)(-z*(double)cosine+x*(double)sine))*.02197265625f;
return new(RocketOrientation.AddAxis(0,-components.Z),yaw,RocketOrientation.AddAxis(0,components.X));
}
public static Vector3 Face(Vector3 rotation,Vector3 target,float rate,float dt)
{
float Axis(float current,float desired)
{
float delta=desired-current;
if(delta>=180)delta-=360;else if(delta< -180)delta+=360;
float gain=dt*rate;float step=delta*gain;
return MathF.Abs(step)<gain?desired:current+step;
}
return new(Axis(rotation.X,target.X),Axis(rotation.Y,target.Y),Axis(rotation.Z,target.Z));
}
}
+1
View File
@@ -66,6 +66,7 @@ internal static unsafe class Sdl
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_PutAudioStreamData(nint stream,nint buffer,int length);
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern int SDL_GetAudioStreamQueued(nint stream);
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_SetAudioStreamGain(nint stream,float gain);
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_SetAudioStreamFrequencyRatio(nint stream,float ratio);
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern void SDL_DestroyAudioStream(nint stream);
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern void SDL_Delay(uint ms);
}
+83 -10
View File
@@ -33,6 +33,8 @@ internal static class Program
catch (Exception error) { Console.Error.WriteLine(error); return 1; }
}
private static int ScooterEngineFrequency(int baseFrequency,float speed)=>Math.Max(7000,(int)(baseFrequency+(double)speed*(1/1.9)*51));
private static string? Option(string[] args, string name)
{
var i = Array.IndexOf(args, name);
@@ -90,6 +92,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-scooter VR05 / outside summon-drive-cleanup replay
--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
@@ -265,6 +268,7 @@ internal static class Program
var invisibleSmoke = args.Contains("--smoke-invisible");
var bubbleSmoke = args.Contains("--smoke-bubble");
var baseballSmoke = args.Contains("--smoke-baseball");
var scooterSmoke=args.Contains("--smoke-scooter");
var grapplerSmoke = args.Contains("--smoke-grappler");
var rocketSmoke = args.Contains("--smoke-rocketship");
var carlSmoke = args.Contains("--smoke-carl-cutscene");
@@ -287,7 +291,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 || grapplerSmoke || gadgetWindowSmoke || practiceWindowSmoke || practiceReturnSmoke || carlSmoke || controlPhaseSmoke || objectiveSmoke;
|| args.Contains("--skip-intro") || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || grapplerSmoke || scooterSmoke || 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.");
@@ -320,6 +324,8 @@ internal static class Program
SceneBaseballs? baseballs = null;
BaseballVisuals? baseballVisuals = null;
BaseballAimOverlay? baseballAim = null;
Scooter? scooter=null;
ScooterVisuals? scooterVisuals=null;
Rocketship? rocketship = null;
RocketshipVisuals? rocketshipVisuals = null;
GrapplerVisuals? grapplerVisuals = null;
@@ -351,7 +357,7 @@ 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 "VR08" or "LEV1"
var cameraRay = level!.Code is "LV1B" or "VR01" or "VR02" or "VR04" or "VR05" 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,
@@ -398,13 +404,23 @@ internal static class Program
simulation!.Energy = interactions.Energy;
simulation.JetpackInventoryState = () => interactions.Inventory.State(0, 3);
simulation.ScoreChanged += interactions.ChangeScore;
if(level.Code is "VR05" or "LEV1")
{
if(director.FindActor("C3DGODDARD")==null)
{
var behind=simulation.ActorRoot+RocketOrientation.Rotate(new(0,0,-250),new(0,simulation.Yaw,0));
var ray=OriginalCameraRay.FromRouteScene(world,level.Code);
director.EnsureCompanion(ray.TraceGeometry(simulation.ActorRoot,behind)==null?behind:originalStart!.Position,Vector3.Zero);
}
scooter=new(director.AddOwnedActor("C3DJEEP","3JEE",Vector3.Zero),world,level.Code);
}
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);
gadgets.ScoreAwarded += interactions.ChangeScore;
}
if(level.Code is "LV1B" or "VR01" or "VR04" or "VR07" or "VR08" or "LEV1")
if(level.Code is "LV1B" or "VR01" or "VR04" or "VR05" or "VR07" or "VR08" or "LEV1")
{
baseballs=new(director,simulation,world);
baseballs.ScoreAwarded+=interactions.ChangeScore;
@@ -437,6 +453,7 @@ internal static class Program
grounded = resolved.Supported;
return new(resolved.Body.Position, resolved.Body.Velocity);
});
patrol.FollowPlayer=actor.Kind=="3DOG"&&level!.Code is "VR05" or "LEV1";
patrols.Add(actor.Tag, patrol);
director.RegisterPatrolConsumer(actor.Tag);
director.ActorChanged += changed => { if (ReferenceEquals(changed, actor)) patrol.SynchronizeAuthoredState(); };
@@ -461,6 +478,11 @@ internal static class Program
}
else simulation.DynamicRootResolver = (previous, position, radius) =>
DynamicBodyResponse.Resolve(staticVisuals.DoorColliders(), previous, position, radius);
if(scooter!=null)
{
scooter.DynamicRootResolver=(a,b,r)=>DynamicBodyResponse.Resolve(staticVisuals.DoorColliders(),a,b,r);
scooterVisuals=new(mesh,Path.GetFullPath(Path.Combine(Path.GetDirectoryName(scene!)!,"..")));mesh=scooterVisuals.Mesh;
}
jetpackVisuals = new JetpackVisuals(mesh, Path.GetFullPath(Path.Combine(Path.GetDirectoryName(scene!)!, "..")));
mesh = jetpackVisuals.Mesh;
bubbleVisuals = new(mesh,Path.GetFullPath(Path.Combine(Path.GetDirectoryName(scene!)!,"..")));
@@ -520,7 +542,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") ?? (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"));
var frames = int.Parse(Option(args, "--frames") ?? (scooterSmoke ? "10" : 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))
@@ -531,6 +553,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(scooterSmoke&&(scooter==null||frames<10||loadedSave!=null))
throw new ArgumentException("Scooter replay requires fresh VR05 or outsideLEV1 and10 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))
@@ -559,7 +583,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!,rocketship);
: new PlayerSceneBinding(director, simulation!, interactions!.Inventory, level!.Player!.Tag!,rocketship,scooter);
var renderer = presentation.LoadScene(mesh, texture, headless,
walking ? WalkTitle : animations?.WindowTitle ?? "Jimmy Neutron — scene preview | C camera",
width, height, !args.Contains("--no-validation"));
@@ -570,6 +594,8 @@ internal static class Program
InvisibleSmoke? invisibleFixture = null;
BubbleSmoke? bubbleFixture = null;
BaseballSmoke? baseballFixture = null;
ScooterSmoke? scooterFixture=null;
var sawScooterKeys=0;
GrapplerSmoke? grapplerFixture=null;
RocketshipSmoke? rocketFixture=null;
var sawRocketKeys=0;
@@ -581,6 +607,7 @@ 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 scooterLifetime=scooter;
using var grapplerLifetime = simulation?.Grappler;
if(simulation?.Grappler is{} grapplerAudio)
{
@@ -593,6 +620,12 @@ internal static class Program
simulation.GadgetSound += (id,loop) => sceneAudio?.Effect(id,loop?"bubble":null);
simulation.BubbleSoundStopped += () => sceneAudio?.StopLoop("bubble");
}
if(scooter!=null)
{
scooter.EngineStarted+=()=>sceneAudio?.Effect(46,"scooter");
scooter.EngineStopped+=()=>sceneAudio?.StopLoop("scooter");
scooter.EngineSpeedChanged+=speed=>sceneAudio?.TuneLoop("scooter",baseFrequency=>ScooterEngineFrequency(baseFrequency,speed));
}
if(baseballs!=null)baseballs.Sound+=id=>sceneAudio?.Effect(id);
if(rocketship!=null)
{
@@ -643,7 +676,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 || grapplerSmoke || gadgetWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke || controlPhaseSmoke) { sceneAudio?.StopSpeech(); director.Skip(); }
if (args.Contains("--skip-intro") || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || grapplerSmoke || scooterSmoke || gadgetWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke || controlPhaseSmoke) { sceneAudio?.StopSpeech(); director.Skip(); }
if (gadgetWindowSmoke) { interactions!.Inventory.SetState(0,3,1); interactions.Inventory.SelectGadget(3); }
if (controlPhaseSmoke)
{
@@ -725,6 +758,7 @@ internal static class Program
}
if (invisibleSmoke) invisibleFixture = new(simulation!,interactions!.Inventory);
if(baseballSmoke)baseballFixture=new(simulation!,playerBinding!,interactions!.Inventory,baseballs!,director);
if(scooterSmoke)scooterFixture=new(simulation!,playerBinding!,director,interactions!,level!.Code);
if(grapplerSmoke)grapplerFixture=new(simulation!,playerBinding!,director,interactions!);
if(rocketSmoke)rocketFixture=new(simulation!,playerBinding!,director,interactions!);
if (bubbleSmoke) bubbleFixture = new(simulation!,interactions!.Inventory);
@@ -820,6 +854,12 @@ internal static class Program
if (practice.Active) practice.Key(17, Vector2.Zero);
playerBinding?.ResetVehicle();simulation.Reset(); poseTime = 0; sceneAudio?.StopSpeech(); director?.Begin(originalStart!);
rocketship?.Reset();
if(scooter!=null)
{
var behind=simulation.ActorRoot+RocketOrientation.Rotate(new(0,0,-250),new(0,simulation.Yaw,0));
var ray=OriginalCameraRay.FromRouteScene(world,level!.Code);
director!.EnsureCompanion(ray.TraceGeometry(simulation.ActorRoot,behind)==null?behind:originalStart!.Position,Vector3.Zero);
}
interactions?.Reset(); mechanisms?.Reset(); gadgets?.Reset(); baseballs?.Reset(); mouseFire = false;
director?.SyncActor(level!.Player!.Tag!, simulation.ActorRoot, new Vector3(0, simulation.Yaw, 0));
}
@@ -920,6 +960,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.GiveScooter when interactions != null:
interactions.Inventory.SetState(0,4,1);interactions.Inventory.SelectGadget(4);
debugMenu.Message=scooter?.Spawned==true?"SCOOTER SUMMONED AT GODDARD - WALK INTO IT TO MOUNT":
"SCOOTER GIVEN - AVAILABLE IN VR05 AND OUTSIDE";
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":
@@ -990,6 +1035,11 @@ internal static class Program
}
while (running)
{
scooterFixture?.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);
grapplerFixture?.BeforeFrame(count,(key,down)=>
{
var e=new Sdl.Event{Type=down?Sdl.KeyDown:Sdl.KeyUp,Scancode=key,Down=down?(byte)1:(byte)0};
@@ -1061,6 +1111,8 @@ internal static class Program
}
while (!headless && Sdl.SDL_PollEvent(out var e))
{
if(scooterSmoke&&e.Type==Sdl.KeyDown)
sawScooterKeys|=e.Scancode switch{81=>1,82=>2,80=>4,225=>8,43=>16,60=>32,21=>64,_=>0};
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)
@@ -1193,12 +1245,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 || grapplerSmoke || 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 || scooterSmoke || gadgetWindowSmoke || objectiveWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke))
{
var steps = headless || walkSmoke || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || grapplerSmoke || gadgetWindowSmoke || practiceWindowSmoke || carlSmoke || controlPhaseSmoke || objectiveWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke ? 1 : stepClock.Advance(elapsed);
var steps = headless || walkSmoke || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || grapplerSmoke || scooterSmoke || 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)
: scooterSmoke && headless ? ScooterSmoke.Input(count,level!.Code)
: grapplerSmoke && headless ? GrapplerSmoke.Input(count)
: rocketSmoke && headless ? RocketshipSmoke.Input(count)
: baseballSmoke && headless ? BaseballSmoke.Input(count)
@@ -1220,6 +1273,7 @@ internal static class Program
bool acceptsInput;
if (playerBinding != null) acceptsInput = playerBinding.Step(input);
else { simulation.Step(input); acceptsInput = true; }
scooterFixture?.Received(input);
grapplerFixture?.Received(input);
rocketFixture?.Received(input);
gadgets?.StepTimers(FixedStepClock.Step);
@@ -1235,7 +1289,7 @@ internal static class Program
if (!simulation.Noclip)
{
director?.Touch(level!.Player!.Tag!, simulation.ActorRoot);
interactions?.Update(simulation.ActorRoot, simulation.InteractionRadius,rocketship is{Mounted:true}?rocketship.Actor:null);
interactions?.Update(simulation.ActorRoot, simulation.InteractionRadius,rocketship is{Mounted:true}?rocketship.Actor:scooter is{Mounted:true}?scooter.Actor:null);
}
if (practice.Active) { keys.Clear(); mouseJump = false; stepClock.Reset(); break; }
if (!simulation.Noclip) mechanisms?.Update(simulation.ActorRoot, simulation.InteractionRadius);
@@ -1278,6 +1332,11 @@ internal static class Program
view = Matrix4x4.CreateLookAtLeftHanded(simulation.CameraEye, simulation.CameraTarget, Vector3.UnitY);
renderEye = simulation.CameraEye; renderTarget = simulation.CameraTarget;
}
if(!inspecting&&scooter is{Mounted:true})
{
renderEye=scooter.CameraEye;renderTarget=scooter.CameraTarget;
view=Matrix4x4.CreateLookAtLeftHanded(renderEye,renderTarget,Vector3.UnitY);
}
if(!inspecting&&rocketship is{Mounted:true})
{
renderEye=rocketship.CameraEye;renderTarget=rocketship.CameraTarget;
@@ -1300,6 +1359,7 @@ internal static class Program
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);
if(scooter!=null)scooterVisuals?.Update(mesh,scooter,scooter.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 });
@@ -1334,6 +1394,7 @@ internal static class Program
: 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,
ScooterState=scooter==null?null:$"{(scooter.Mounted?"RIDE":scooter.Spawned?"PARK":"OFF")} SPEED {scooter.Steering.Speed:F1} WHEELS {scooter.FrontSupports}/{scooter.RearSupports}",
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,
@@ -1366,7 +1427,7 @@ internal static class Program
}
if (simulation != null && characterDraw != null)
{
characterDraw.Visible=rocketship?.Mounted!=true && simulation.Grappler?.SwingPose!=true;
characterDraw.Visible=rocketship?.Mounted!=true && scooter?.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++)
@@ -1374,6 +1435,12 @@ internal static class Program
}
renderer.UpdateVertices(mesh.Vertices);
renderer.Render(view * projection);
if(scooterFixture!=null)
{
scooterFixture.AfterFrame(count);
if(ScooterSmoke.StageName(count) is{} stage&&Option(args,"--screenshot") is{} capture)
renderer.SavePpm(Path.ChangeExtension(capture,$".{stage}.ppm"));
}
if(grapplerFixture!=null)
{
grapplerFixture.AfterFrame(count);
@@ -1678,6 +1745,12 @@ internal static class Program
if(!headless)Console.WriteLine($"Baseball SDL keys received: {sawBaseballKeys==15}.");
if(!baseballFixture.Passed || !headless && sawBaseballKeys!=15)return 2;
}
if(scooterFixture!=null)
{
Console.WriteLine(scooterFixture.Report);
if(!headless)Console.WriteLine($"Scooter SDL keys received: {sawScooterKeys==127}.");
if(!scooterFixture.Passed||!headless&&sawScooterKeys!=127)return 2;
}
if(grapplerFixture!=null)
{
Console.WriteLine(grapplerFixture.Report);