Implement evidence-backed VR02 Rocketship flight and ownership
This commit is contained in:
1 parent
312efccb77
commit
e77add5fdf
50 files changed
+4326
-66
No files matched your search
@@ -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));
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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;}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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; }
|
||||
|
||||
Reference in new issue
Block a user