Recover sphere response and correct Jimmy ceiling cancellation

This commit is contained in:
UnixNight committed 2026-10-26 16:09:19 -04:00
1 parent 6a7a53c90d
commit 57dfcc64bb
37 files changed
+1324 -18

No files matched your search

+24 -5
View File
@@ -17,6 +17,7 @@ public sealed class LabSimulation
public const float BodyRadius = 24; // Provisional, not a recovered collider dimension.
private readonly SceneCollision collision;
private readonly Func<Vector3, Vector3, SupportHit?>? cameraRay;
private readonly Func<Vector3, Vector3, SupportHit?>? ceilingRay;
private readonly Vector3 sourceStart;
private readonly float startYaw, modelMinimumY, rootHeight, startFloor;
private float targetYaw, extraAirAcceleration, shadowDistance, lateralContribution;
@@ -60,6 +61,7 @@ public sealed class LabSimulation
public int PhysicsSteps { get; private set; }
public int ControllerSteps { get; private set; }
public int EffectSteps { get; private set; }
public int CeilingHits { get; private set; }
public int Jumps { get; private set; }
public int Landings { get; private set; }
public int WallHits { get; private set; }
@@ -73,10 +75,12 @@ public sealed class LabSimulation
* Matrix4x4.CreateTranslation(Position - new Vector3(0, modelMinimumY, 0));
public LabSimulation(SceneCollision collision, Mesh standingPose, Vector3 start, float yaw,
Func<Vector3, Vector3, SupportHit?>? cameraRay = null)
Func<Vector3, Vector3, SupportHit?>? cameraRay = null,
Func<Vector3, Vector3, SupportHit?>? ceilingRay = null)
{
this.collision = collision;
this.cameraRay = cameraRay;
this.ceilingRay = ceilingRay;
sourceStart = start;
startYaw = yaw;
var bounds = standingPose.Bounds();
@@ -106,7 +110,7 @@ public sealed class LabSimulation
Grounded = true;
Noclip = HasNoclipEntry = false;
Steps = Jumps = Landings = WallHits = 0;
PhysicsSteps = ControllerSteps = EffectSteps = 0;
PhysicsSteps = ControllerSteps = EffectSteps = CeilingHits = 0;
Travel = MaximumRise = 0;
CameraEye = DesiredEye().Eye;
}
@@ -155,10 +159,12 @@ public sealed class LabSimulation
// This reconstructs the player/input/fire partial order, not the full
// scene registry, original cadence or original collision response.
StepPhysics();
if (controlled && !InputAfterPlayerUpdate) StepInput(input);
//42469F..4246DC reasserts ordinary grounded radius before ownership
//checks. The scooter's separate radius160 policy remains unimplemented.
if (Grounded) InteractionRadius = 60;
if (controlled && !InputAfterPlayerUpdate) StepInput(input);
//424BE0..424C34 runs this wrapper before437940's ownership gate.
StepCeiling();
if (controlled) StepPlayer(input);
var effect = JetpackBurst.StepEffect(jumpState, Grounded, FixedStepClock.Step, Energy, LevelCode);
jumpState = effect.State; Energy = effect.Energy; JetpackEffectVisible = effect.Visible;
@@ -174,6 +180,19 @@ public sealed class LabSimulation
Speed = 0; Velocity = Vector3.Zero;
}
private void StepCeiling()
{
if (Velocity.Y <= 0 || ceilingRay == null
|| ceilingRay(ActorRoot, ActorRoot + Vector3.UnitY * 150) == null) return;
Velocity = Velocity with { Y = (float)Math.Min(-Velocity.Y * .6, -85) };
CeilingHits++;
//425120 leaves hold, mode, pending impulse and acceleration intact.
//Full sound/selected-gadget cleanup callbacks remain a separate gap.
if (movementMode != 1) return;
jumpState = jumpState with { JumpState = 0, EffectRemaining = 0 };
forceFall = true;
}
/// <summary>Authored AI root/Euler writes. They do not reset body motion or
/// destination yaw61C; the full logical/render Euler model remains separate.</summary>
public void ApplyAuthoredTransform(Vector3 root, float yaw)
@@ -326,7 +345,7 @@ public sealed class LabSimulation
}
}
Grounded = result.Grounded && velocity.Y <= 0;
if (Grounded && velocity.Y < 0 || result.HitCeiling && velocity.Y > 0) velocity.Y = 0;
if (Grounded && velocity.Y < 0 || result.HitCeiling && velocity.Y > 0 && ceilingRay == null) velocity.Y = 0;
if (Grounded) { extraAirAcceleration = 0; forceFall = false; }
Velocity = velocity;
if (!wasGrounded && Grounded) Landings++;
@@ -363,5 +382,5 @@ public sealed class LabSimulation
step is >= 80 and < 120, step is >= 60 and < 95, false, step < 180);
public bool SmokePassed => Steps >= 240 && Travel > 50 && MaximumRise > 20 && Jumps > 0 && Landings > 0 && Grounded;
public string Report => $"Walk checkpoint: steps={Steps}, controller={ControllerSteps}, physics={PhysicsSteps}, effect={EffectSteps}, travel={Travel:F2}, jumps={Jumps}, landings={Landings}, max rise={MaximumRise:F2}, wall hits={WallHits}, grounded={Grounded}, feet={Position}.";
public string Report => $"Walk checkpoint: steps={Steps}, controller={ControllerSteps}, physics={PhysicsSteps}, effect={EffectSteps}, travel={Travel:F2}, jumps={Jumps}, landings={Landings}, max rise={MaximumRise:F2}, wall hits={WallHits}, ceiling hits={CeilingHits}, grounded={Grounded}, feet={Position}.";
}
+15 -2
View File
@@ -20,7 +20,7 @@ public sealed class OriginalCameraRay
public const float CellOrigin = 130; //49B1FC.
private readonly Dictionary<int, List<SupportTriangle>> walls = [];
private readonly Dictionary<int, List<SupportTriangle>> all = [];
public bool Enabled { get; set; } = true; //4F69E5.
public bool Enabled { get; set; } = true; // Modern camera-only debug override.
public int PolygonCount { get; }
public int WallPolygonCount { get; }
/// <summary>Modern query diagnostic; repeated cells are intentionally counted.</summary>
@@ -88,12 +88,25 @@ public sealed class OriginalCameraRay
RequireFinite(start); RequireFinite(end);
LastTriangleTests = 0;
if (!Enabled) return null;
return TraceCore(start, end, twoSided, diagnostic: true);
}
/// <summary>425170 also uses47C210. Camera-only debug controls must not
/// disable physical ceiling checks or overwrite camera-query diagnostics.</summary>
public SupportHit? TraceGeometry(Vector3 start, Vector3 end, bool twoSided = false)
{
RequireFinite(start); RequireFinite(end);
return TraceCore(start, end, twoSided, diagnostic: false);
}
private SupportHit? TraceCore(Vector3 start, Vector3 end, bool twoSided, bool diagnostic)
{
foreach (var grid in new[] { walls, all })
foreach (var cell in CellsBetween(start, end))
if (grid.TryGetValue(cell, out var triangles))
foreach (var triangle in triangles)
{
LastTriangleTests++;
if (diagnostic) LastTriangleTests++;
if (OriginalBodySupport.IntersectSegment(triangle, start, end, twoSided) is { } hit)
return hit;
}
@@ -0,0 +1,81 @@
using System.Numerics;
namespace GamePort.Game;
public readonly record struct SphereResponseState(float FaceDistance, float EdgeDistance, Vector3? Hit)
{
public static SphereResponseState Begin(float radius) => new(-1, radius, null);
}
public enum SphereContact { None, Face, Edge }
public readonly record struct SphereResponseResult(Vector3 Position, SphereResponseState State, SphereContact Contact);
/// <summary>
/// Bounded EXE47BD80 kernel over one supplied source triangle. Callers own grid
/// order, persistent nearest-hit state, callbacks and subsequent support. This
/// component does not replace the port's capsule or reconstruct the whole solver.
/// </summary>
public static class OriginalSphereResponse
{
public static SphereResponseResult Resolve(SupportTriangle triangle, Vector3 normal,
Vector3 previous, Vector3 position, float radius, SphereResponseState state,
bool edges = true, bool allowLowerEdges = false)
{
Finite(triangle.A); Finite(triangle.B); Finite(triangle.C);
Finite(normal); Finite(previous); Finite(position);
if (!float.IsFinite(radius) || radius <= 0 || !float.IsFinite(state.FaceDistance)
|| !float.IsFinite(state.EdgeDistance)) throw new ArgumentOutOfRangeException(nameof(radius));
var unchanged = new SphereResponseResult(position, state, SphereContact.None);
var offset = normal * radius;
var endpoint = position - offset;
endpoint.Y = MathF.Max(endpoint.Y, position.Y);
if (OriginalBodySupport.IntersectSegment(triangle, previous, endpoint) is { } face)
{
// A farther face returns immediately; it must not fall into edges.
if (state.FaceDistance != -1 && face.Distance >= state.FaceDistance) return unchanged;
var resolved = face.Position + offset;
if (normal.Y >= -.7f) resolved.Y = position.Y;
return new(resolved, state with { FaceDistance = face.Distance, Hit = face.Position }, SphereContact.Face);
}
if (!edges || normal.Y <= -.7f || normal.Y >= .7f) return unchanged;
//4695B0 considers only the three edges, including their endpoints.
var ab = NearestOnSegment(position, triangle.A, triangle.B);
var bc = NearestOnSegment(position, triangle.B, triangle.C);
var ca = NearestOnSegment(position, triangle.C, triangle.A);
var da = OriginalBodySupport.QuickMagnitude(position - ab);
var db = OriginalBodySupport.QuickMagnitude(position - bc);
var dc = OriginalBodySupport.QuickMagnitude(position - ca);
var nearest = db <= da ? db < dc ? bc : ca : da < dc ? ab : ca;
if (!allowLowerEdges && nearest.Y < position.Y) return unchanged;
var toEdge = nearest - position;
var distance = OriginalBodySupport.QuickMagnitude(toEdge);
// Exact overlap would normalize zero in the source. Keep that undefined
// arithmetic outside this bounded finite-input reconstruction.
if (distance == 0) return unchanged;
var direction = toEdge / distance;
if (Dot(direction, normal) >= 0 || state.EdgeDistance != -1 && distance >= state.EdgeDistance)
return unchanged;
var edgePosition = nearest - direction * radius;
edgePosition.Y = position.Y;
return new(edgePosition, state with { EdgeDistance = distance, Hit = nearest }, SphereContact.Edge);
}
private static Vector3 NearestOnSegment(Vector3 point, Vector3 a, Vector3 b)
{
var edge = b - a;
var length = OriginalBodySupport.QuickMagnitude(edge);
if (length == 0) return a;
var direction = edge / length;
var projection = Dot(point - a, direction);
return projection < 0 ? a : projection > length ? b : a + direction * projection;
}
private static float Dot(Vector3 a, Vector3 b) =>
(float)((double)a.X * b.X + (double)a.Y * b.Y + (double)a.Z * b.Z);
private static void Finite(Vector3 value)
{
if (!float.IsFinite(value.X) || !float.IsFinite(value.Y) || !float.IsFinite(value.Z))
throw new ArgumentOutOfRangeException(nameof(value));
}
}