Implement Baseball aiming, pooled projectiles and VR07 targets

This commit is contained in:
UnixNight committed 2026-11-02 22:54:19 -05:00
1 parent 50fcb87d90
commit d6ca417e9e
50 files changed
+3149 -32

No files matched your search

+138
View File
@@ -0,0 +1,138 @@
using System.Numerics;
namespace GamePort.Game;
/// <summary>Jimmy's raw6 aim/release state (42659F/426744). The twenty owned
/// projectiles survive unequip; this object is reset only with the modern scene.
/// Source evidence and precision boundaries: gameplay/baseball.md.</summary>
public sealed class BaseballGadget
{
public const int PoolSize = 20;
private readonly BaseballProjectile[] projectiles = Enumerable.Range(0, PoolSize).Select(_ => new BaseballProjectile()).ToArray();
public IReadOnlyList<BaseballProjectile> Projectiles => projectiles;
public bool Equipped { get; private set; }
public bool PendingThrow { get; private set; }
public bool AimVisible { get; private set; }
public float CameraPitch { get; private set; } = 10;
public float CameraHeight { get; private set; } = 200;
public float SavedPitch { get; private set; }
public float DisplayPitch { get; private set; }
public int NextSlot { get; private set; }
public int Throws { get; private set; }
public event Action<bool>? EquippedChanged;
public event Action? Thrown;
public void Equip()
{
Equipped = true;
CameraHeight += 30; //429707..429713 complete7CC; cleanup resets its defaults.
EquippedChanged?.Invoke(true);
}
public void Release()
{
Equipped = AimVisible = false;
CameraPitch = 0;
CameraHeight = 200;
//42871D does not write Jimmy1E26/1E28 or destroy its AB4 pool.
EquippedChanged?.Invoke(false);
}
public void StepInput(PlayerInput input, Vector3 root, Vector3 euler, bool supported,
float energy, bool exempt, Action stop, Action<bool> shooting, Action<float> adjustEnergy)
{
if (!input.Fire)
{
AimVisible = false;
shooting(false);
if (!PendingThrow) return;
Thrown?.Invoke(); //4265A9 requests10 before the launch virtual.
projectiles[NextSlot].Launch(root, euler, SavedPitch);
NextSlot = (NextSlot + 1) % PoolSize;
PendingThrow = false;
Throws++;
adjustEnergy(-1);
return;
}
if (!Equipped) return;
stop();
if (energy <= 0 && !exempt || !supported) return;
shooting(true);
AimVisible = true;
DisplayPitch = SavedPitch;
if (!PendingThrow)
{
PendingThrow = true;
return; //First hold arms without refreshing the saved pitch.
}
CameraPitch = Math.Clamp(CameraPitch, 0, 45);
SavedPitch = CameraPitch;
}
public void StepCameraInput(PlayerInput input)
{
if (!Equipped) { CameraPitch=10; return; }
if (!input.Fire) return;
if (input.Backward) CameraPitch -= 20 * FixedStepClock.Step;
else if (input.Forward) CameraPitch += 20 * FixedStepClock.Step;
}
public void Reset()
{
if (Equipped) Release();
PendingThrow = AimVisible = false;
CameraPitch = 10; SavedPitch = DisplayPitch = 0;
CameraHeight = 200;
NextSlot = Throws = 0;
foreach (var projectile in projectiles) projectile.Reset();
}
}
/// <summary>C3DBaseball owned pool entry. No invented ammo count or lifetime.</summary>
public sealed class BaseballProjectile
{
public Vector3 Position { get; private set; }
public Vector3 PreviousPosition { get; private set; }
public Vector3 Velocity { get; private set; }
public Vector3 PendingImpulse { get; private set; }
public bool Supported { get; private set; }
public bool Visible { get; private set; }
public int CanvasId => 2; //40FB50 initializes2; a sequence caller is not recovered.
public int Landings { get; private set; }
public void Launch(Vector3 root, Vector3 euler, float pitch)
{
if (!float.IsFinite(root.X + root.Y + root.Z + euler.X + euler.Y + euler.Z + pitch)
|| pitch < 0 || pitch > 45) throw new ArgumentOutOfRangeException(nameof(pitch));
//384/38C use the player's full local transform. This bridge matches the
//port's recovered Bubble Euler convention; generic original Euler remains
//a declared precision/ownership boundary. Upright yaw is the tested path.
var rotation = Matrix4x4.CreateRotationZ(-euler.Z * MathF.PI / 180)
* Matrix4x4.CreateRotationX(-euler.X * MathF.PI / 180)
* Matrix4x4.CreateRotationY(-euler.Y * MathF.PI / 180);
Position = root + Vector3.Transform(new Vector3(0, 80, 50), rotation);
var direction = Vector3.Transform(new Vector3(0, pitch * .02222222276031971f, 1), rotation);
Velocity = direction / OriginalBodySupport.QuickMagnitude(direction) * 1800;
//429A30 does not clear a reused entry's impulse/support state.
PreviousPosition = Position;
Visible = true;
}
public void Step(OriginalBodyPhysics physics, float seconds)
{
if (!Visible) return;
PreviousPosition = Position;
var result = physics.Step(new(Position, Velocity, Vector3.Zero, PendingImpulse, Supported), seconds,
radius: 15, factor: 1, friction: .46f, profile: BodyResponseProfile.Baseball);
Position = result.Body.Position; Velocity = result.Body.Velocity;
PendingImpulse = result.Body.Impulse; Supported = result.Body.Supported;
if (result.Landing != null) Landings++;
}
public void Hide() => Visible = false; //Source disables integration/pairs and hides, retaining body state.
public void Reset()
{
Visible=Supported=false; Position=PreviousPosition=Velocity=PendingImpulse=Vector3.Zero;
Landings=0;
}
}
+11 -2
View File
@@ -41,6 +41,7 @@ public sealed class LabSimulation
public string LevelCode { get; set; } = "LV1B";
public InvisibleGadget Invisible { get; } = new();
public BubbleEffect Bubble { get; } = new();
public BaseballGadget Baseball { get; } = new();
public PlayerAppearance Appearance { get; } = new();
public Vr01FloorState FloorState { get; } = new();
public Vector3 BubbleRoot { get; private set; }
@@ -58,6 +59,7 @@ public sealed class LabSimulation
var previousPose=Pose;
if (gadgetMode == 0) ReleaseBubble();
if (gadgetMode == 2) Invisible.Release();
if (gadgetMode == 6) Baseball.Release();
gadgetMode = -1;
if (value == 0)
{
@@ -70,6 +72,7 @@ public sealed class LabSimulation
return;
}
if (value == 2 && !Invisible.Equip(Energy, IgnoresGadgetEnergy)) return;
if (value == 6) Baseball.Equip();
gadgetMode = value;
}
}
@@ -124,7 +127,7 @@ public sealed class LabSimulation
public Func<Vector3, Vector3, float, Vector3>? DynamicRootResolver { get; set; }
public Vector3 ActorRoot => Position + Vector3.UnitY * rootHeight;
public Vector3 CameraEye { get; private set; }
public Vector3 CameraTarget => ActorRoot + new Vector3(0, 99, 0);
public Vector3 CameraTarget => ActorRoot + new Vector3(0, 80 + 1.9f * Baseball.CameraPitch, 0);
public Matrix4x4 Model => Matrix4x4.CreateRotationZ(-(TracksBubbleOrientation?Roll:0) * MathF.PI / 180)
* Matrix4x4.CreateRotationX(-(TracksBubbleOrientation?Pitch:0) * MathF.PI / 180) * Matrix4x4.CreateRotationY(-Yaw * MathF.PI / 180)
* Matrix4x4.CreateTranslation(Position - new Vector3(0, modelMinimumY, 0));
@@ -141,6 +144,7 @@ public sealed class LabSimulation
this.energy = energy ?? new PlayerEnergy();
Invisible.AlphaRequested += Appearance.SetAlpha;
Invisible.BlendRequested += Appearance.SetBlend;
Baseball.Thrown += () => GadgetSound?.Invoke(10,false);
sourceStart = start;
startYaw = yaw;
var bounds = standingPose.Bounds();
@@ -161,6 +165,8 @@ public sealed class LabSimulation
if (gadgetMode == 0) { GadgetMode=-1; DefaultGadgetRequested?.Invoke(); }
if (gadgetMode == 2) gadgetMode = -1;
Invisible.Reset();
Baseball.Reset();
if (gadgetMode == 6) gadgetMode = -1;
Bubble.Reset(); FloorState.Reset(); Appearance.Reset(); retainedSupportMaterial=null;
Pitch=Roll=targetPitch=targetRoll=0; BubbleBounces=0;
TracksBubbleOrientation=false;
@@ -404,6 +410,7 @@ public sealed class LabSimulation
//438011..43802B adds the independent turn rate directly to yaw.
targetYaw = Yaw;
}
Baseball.StepCameraInput(input);
StepCamera(); //438BC0/439900 input path owns follow; still provisional geometry/state.
if (movementMode==2)
{
@@ -415,6 +422,8 @@ public sealed class LabSimulation
BubbleRoot=ActorRoot+Vector3.UnitY*50-direction*80;
}
InputActions?.Invoke(input);
Baseball.StepInput(input,ActorRoot,new(Pitch,Yaw,Roll),Grounded,Energy,IgnoresGadgetEnergy,
StopForPrimaryFire,SetShooting,AdjustEnergy);
}
private void StepPlayer(PlayerInput input)
@@ -541,7 +550,7 @@ public sealed class LabSimulation
private (Vector3 Eye, float Gain) DesiredEye()
{
var (sin, cos) = Trig(Yaw);
var eye = ActorRoot + new Vector3(sin * 350, 180, -cos * 350);
var eye = ActorRoot + new Vector3(sin * 350, Baseball.CameraHeight - 2 * Baseball.CameraPitch, -cos * 350);
if (Noclip) return (eye, 1); // Debug exploration also bypasses camera obstruction.
if (cameraRay == null) return (collision.ClipCamera(CameraTarget, eye), 1);
//43B820: query from the computed look target; first accepted static hit
+31 -5
View File
@@ -13,6 +13,8 @@ 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 }
/// <summary>
/// Bounded479D20 composition: enabled integration/support/pairs/static flags,
/// prevent-lowering true, ordinary Jimmy370/374/37C and no dynamic body pass.
@@ -26,10 +28,10 @@ public sealed class OriginalBodyPhysics
{
private readonly OriginalStaticCollision collision;
public OriginalBodyPhysics(OriginalStaticCollision collision)
public OriginalBodyPhysics(OriginalStaticCollision collision, bool allowSpecialMaterials = false)
{
ArgumentNullException.ThrowIfNull(collision);
if (collision.HasSpecialPlayerContacts)
if (collision.HasSpecialPlayerContacts && !allowSpecialMaterials)
throw new NotSupportedException("Ordinary body composition requires recovered special-contact policies for this scene");
this.collision = collision;
}
@@ -38,7 +40,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)
float friction = .8f, float suppressionScale = .5f, bool geometryEnabled = true,
BodyResponseProfile profile = BodyResponseProfile.Jimmy)
{
Finite(body.Position); Finite(body.Velocity); Finite(body.Acceleration); Finite(body.Impulse);
Finite(body.AngularVelocity); Finite(body.Rotation);
@@ -77,6 +80,21 @@ public sealed class OriginalBodyPhysics
if (velocity.Y > 0) velocity.Y = 0;
if (acceleration.Y > 0) acceleration.Y = 0;
}
else if (profile == BodyResponseProfile.Baseball && move.CallbackPolygon is { } wall)
{
//40FEE0 ->458890 ->472750: reflect horizontal direction, keep Y,
//then damp horizontal components by1-.46. Its angular tail does not
//change position/velocity; sprite/Euler side effects remain separate.
var horizontal = velocity with {Y=0};
var magnitude = OriginalBodySupport.QuickMagnitude(horizontal);
if (magnitude > 0)
{
var direction = horizontal / magnitude;
var reflected = direction - 2 * Vector3.Dot(direction, wall.StoredNormal) * wall.StoredNormal;
velocity = new(reflected.X * magnitude * (1-.46f), velocity.Y,
reflected.Z * magnitude * (1-.46f));
}
}
var position = move.Position;
if (horizontalFirst) position.Y += delta.Y;
position.Y = MathF.Max(position.Y, -25000);
@@ -86,13 +104,21 @@ public sealed class OriginalBodyPhysics
BodyLandingObservation? landing = null;
if (geometryEnabled)
{
var support = OriginalBodySupport.Resolve(new(position, previous, velocity, acceleration, radius, factor),
var support = OriginalBodySupport.Resolve(new(position, previous, velocity, acceleration, radius, factor,
PreventLowering: profile == BodyResponseProfile.Jimmy),
wasSupported, (start, end, sides) => collision.TraceSupport(start, end, sides));
if (support.Supported)
{
//37C observes new root/zero acceleration but old velocity/support.
//Jimmy's inherited37C is a no-op; the observation is diagnostic.
if (support.Landed) landing = new(support.Body.Position, velocity, support.Body.Acceleration, false);
if (support.Landed)
{
landing = new(support.Body.Position, velocity, support.Body.Acceleration, false);
//40FF80 receives old live velocity after root/acceleration
//publication and writes impulse288, before support zeros Y.
if (profile == BodyResponseProfile.Baseball)
body = body with {Impulse = new(velocity.X, velocity.Y * -.65f, velocity.Z)};
}
body = body with { Position = support.Body.Position, Velocity = support.Body.Velocity,
Acceleration = support.Body.Acceleration, Supported = true };
anchor = support.SupportAnchor;
+1 -1
View File
@@ -65,7 +65,7 @@ public sealed class OriginalCameraRay
public static OriginalCameraRay FromRouteScene(Mesh mesh, string levelCode)
{
ArgumentNullException.ThrowIfNull(mesh);
if (levelCode is not ("LV1B" or "VR01" or "VR04" or "LEV1"))
if (levelCode is not ("LV1B" or "VR01" 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");
+1 -1
View File
@@ -61,7 +61,7 @@ public sealed class OriginalStaticCollision
public static OriginalStaticCollision FromRouteScene(Mesh mesh, string level)
{
ArgumentNullException.ThrowIfNull(mesh);
if (level is not ("LV1B" or "VR01" or "VR04" or "LEV1"))
if (level is not ("LV1B" or "VR01" 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 -1
View File
@@ -20,6 +20,7 @@ public sealed class PlayerSceneBinding : IDisposable
director.GadgetReleaseRequested += Release;
inventory.GadgetSelected += Selected;
player.Invisible.EquippedChanged += InvisibleEquipped;
player.Baseball.EquippedChanged += BaseballEquipped;
player.DefaultGadgetRequested += DefaultGadget;
Selected(inventory.SelectedGadget);
}
@@ -49,7 +50,7 @@ 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 || inventory.SelectedGadget is -1 or 3)
if (player.GadgetMode is 0 or 2 or 6 || inventory.SelectedGadget is -1 or 3)
{ inventory.SelectGadget(-1); player.GadgetMode = -1; }
else if (player.GadgetMode != -1) UnsupportedGadgetCleanups++;
}
@@ -70,6 +71,13 @@ public sealed class PlayerSceneBinding : IDisposable
companion.Visible = companion.MovementEnabled = companion.BodyEnabled = !equipped;
}
private void BaseballEquipped(bool equipped)
{
//Raw6 cleanup42871D has no Invisible's complete9E8 restoration veto.
if(director.FindActor("C3DGODDARD") is {} companion)
companion.Visible=companion.MovementEnabled=companion.BodyEnabled=!equipped;
}
private void Transform(DirectorActor actor)
{
if (string.Equals(actor.Tag, tag, StringComparison.OrdinalIgnoreCase))
@@ -83,6 +91,7 @@ public sealed class PlayerSceneBinding : IDisposable
director.GadgetReleaseRequested -= Release;
inventory.GadgetSelected -= Selected;
player.Invisible.EquippedChanged -= InvisibleEquipped;
player.Baseball.EquippedChanged -= BaseballEquipped;
player.DefaultGadgetRequested -= DefaultGadget;
}
}
+149
View File
@@ -0,0 +1,149 @@
using System.Numerics;
using GamePort.Assets;
namespace GamePort.Game;
/// <summary>Owned Baseball bodies and source3TAR callbacks. Pair discovery uses
/// a bounded sphere-overlap adapter; original pair scheduling remains unported.</summary>
public sealed class SceneBaseballs
{
private readonly LabSimulation player;
private readonly OriginalBodyPhysics physics;
private readonly SceneDirector director;
private readonly Dictionary<DirectorActor,int> parentHits = [];
public IReadOnlyList<MovingBaseballTarget> Targets { get; }
public int Hits { get; private set; }
public int Recovered { get; private set; }
public event Action<int>? Sound;
public event Action<int>? ScoreAwarded;
public SceneBaseballs(SceneDirector director, LabSimulation player, Mesh world)
{
this.director=director; this.player=player;
physics=new(OriginalStaticCollision.FromRouteScene(world,player.LevelCode),allowSpecialMaterials:true);
Targets=director.Actors.Where(a=>a.Kind=="3TAR").Select(a=>new MovingBaseballTarget(a)).ToArray();
InitializeTrophyContacts();
}
public void StepBodies(float seconds)
{
foreach(var target in Targets) target.StepBody(seconds);
foreach(var ball in player.Baseball.Projectiles)
{
ball.Step(physics,seconds);
if(!ball.Visible) continue;
//This modern discovery adapter supplies real source callback rules.
//It does not claim original47A580 pair ordering or swept contacts.
foreach(var target in Targets)
if(target.Actor.BodyEnabled && Vector3.DistanceSquared(ball.Position,target.Actor.Position)<90*90
&& target.Hit())
{
Hits++; ScoreAwarded?.Invoke(target.Points);
ActivateParent(target);
}
if(Vector3.DistanceSquared(ball.Position,player.ActorRoot)<(15+player.InteractionRadius)*(15+player.InteractionRadius))
{ ball.Hide(); Recovered++; }
}
}
public void StepTargets(float seconds)
{
foreach(var target in Targets) target.StepFrame(seconds);
}
private void ActivateParent(MovingBaseballTarget target)
{
var parent=director.FindActor(target.ActivateObject);
if(parent==null) { Sound?.Invoke(198); return; }
if(parent.Kind is not ("3TRO" or "3PIC")) return;
var count=parentHits.GetValueOrDefault(parent)+1;
if(count>target.HitsRequired)
{
parentHits[parent]=0;
//The source invokes parent428(1), not the trigger interpreter.
parent.Visible=true;
if(parent.SourceGam?.Integer("HasCollision",-1)!=0)parent.BodyEnabled=true;
Sound?.Invoke(199);
}
else parentHits[parent]=count;
}
public void Reset()
{
Hits=Recovered=0; parentHits.Clear();
foreach(var target in Targets) target.Reset();
InitializeTrophyContacts();
}
private void InitializeTrophyContacts()
{
if(player.LevelCode!="VR07")return;
foreach(var trophy in director.Actors.Where(a=>a.Kind=="3TRO"))
trophy.BodyEnabled=trophy.Visible && trophy.SourceGam?.Integer("HasCollision",-1)!=0;
}
}
/// <summary>Factory45CA06's C3DMOVINGTARGET, not Jimmy's C3DTarget helper.</summary>
public sealed class MovingBaseballTarget
{
public DirectorActor Actor { get; }
private readonly Vector3 initial;
private readonly bool initialVisible;
public Vector3 Start { get; }
public Vector3 Destination { get; }
public Vector3 Velocity { get; private set; }
public float Speed { get; }
public float Remaining { get; private set; }
public float RespawnTime { get; }
public int Points { get; }
public int HitsRequired { get; }
public string ActivateObject { get; }
public MovingBaseballTarget(DirectorActor actor)
{
Actor=actor;
if(actor.Kind!="3TAR" || actor.SourceGam is not {} source)
throw new ArgumentException("Moving target needs its actual source entity",nameof(actor));
initial=actor.Position;
initialVisible=actor.Visible;
Start=new(source.Number("StartPosX"),source.Number("StartPosY"),source.Number("StartPosZ"));
Destination=new(source.Number("DestPosX"),source.Number("DestPosY"),source.Number("DestPosZ"));
Speed=source.Number("Speed",100); RespawnTime=source.Number("RespawnTime",15);
Points=source.Integer("NumPoints",10); HitsRequired=source.Integer("HitsRequired",5);
ActivateObject=source.Text("ActivateObject")??"none";
}
public void StepBody(float seconds)
{
if(!Actor.BodyEnabled) return;
//Source target disables world response and support. Preserve the common
//integrate-before-frame partial order. Full registry/global-flag timing
//remains a separate boundary; this is not a new general actor scheduler.
Velocity+=RecoveredMotion.Gravity*seconds;
Actor.Position+=Velocity*seconds;
}
public void StepFrame(float seconds)
{
if(!float.IsFinite(seconds)||seconds<0||seconds>=1)throw new ArgumentOutOfRangeException(nameof(seconds));
if(Remaining>0)
{
Remaining-=seconds;
if(Remaining<=0) { Remaining=0; Actor.Visible=true; }
}
var delta=Destination-Actor.Position;
var distance=delta.Length(); //Source tests ordinary sqrt distance, normalizes with quick magnitude.
var magnitude=OriginalBodySupport.QuickMagnitude(delta);
Velocity=magnitude>0?delta/magnitude*Speed:Vector3.Zero;
if(distance<100) Actor.Position=Start; //430826 teleports to Start, it does not exchange endpoints.
}
public bool Hit()
{
if(Remaining>0) return false;
Actor.Visible=false; Remaining=RespawnTime;
return true;
}
public void Reset() { Actor.Position=initial; Actor.Visible=initialVisible; Velocity=Vector3.Zero; Remaining=0; }
}
+2 -1
View File
@@ -96,7 +96,8 @@ public sealed class SceneInteractions
}
// Carl InitObject413E2F..45 sets radius100 and support factor0.75.
var radius = playerRadius + (source.Kind == "3TRO" ? 20 : source.Kind == "3CAR" ? 100 : source.Number("Radius"));
var overlaps = actor.Active && OriginalBodySupport.QuickMagnitude(activePlayerRoot - actor.Position) < radius;
var overlaps = actor.Active && (source.Kind!="3TRO" || actor.BodyEnabled)
&& OriginalBodySupport.QuickMagnitude(activePlayerRoot - actor.Position) < radius;
if (!overlaps) { contacts.Remove(source.Offset); continue; }
if (!contacts.Add(source.Offset)) continue;
switch (source.Kind)