Apply recovered player phases, static camera query and level availability
This commit is contained in:
1 parent
117db77c7b
commit
09cf1172bf
33 files changed
+1500
-99
No files matched your search
@@ -21,8 +21,8 @@ public readonly record struct JetpackEffectResult(
|
||||
|
||||
/// <summary>
|
||||
/// The jump/jetpack branches of EXE437F90 and effect timer of EXE421FB0.
|
||||
/// Controller and effect phases are separate: their full-scene order has not
|
||||
/// been recovered. The caller must explicitly choose an order. Horizontal
|
||||
/// Controller and effect phases are separate. The normal route registry places
|
||||
/// Jimmy before his retained fire; other full-scene phases remain incomplete. Horizontal
|
||||
/// movement, shadow queries, visuals and sound callbacks belong to the caller.
|
||||
/// </summary>
|
||||
public static class JetpackBurst
|
||||
|
||||
@@ -15,9 +15,12 @@ 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 Vector3 sourceStart;
|
||||
private readonly float startYaw, modelMinimumY, rootHeight, startFloor;
|
||||
private float targetYaw, extraAirAcceleration, shadowDistance;
|
||||
private float targetYaw, extraAirAcceleration, shadowDistance, lateralContribution;
|
||||
private Vector3 pendingImpulse;
|
||||
private int movementMode;
|
||||
private JetpackBurstState jumpState;
|
||||
private bool forceFall;
|
||||
public Func<int>? JetpackInventoryState { get; set; }
|
||||
@@ -31,11 +34,17 @@ public sealed class LabSimulation
|
||||
public float BodyHeight { get; }
|
||||
public Vector3 Position { get; private set; } // Feet, not original actor root.
|
||||
public Vector3 Velocity { get; private set; }
|
||||
public Vector3 PendingImpulse => pendingImpulse;
|
||||
public int MovementMode => movementMode;
|
||||
// Fresh game registers before Jimmy. A retained Jimmy precedes the newly
|
||||
// appended destination game, whose input callback therefore runs later.
|
||||
public bool InputAfterPlayerUpdate { get; set; }
|
||||
public float Yaw { get; private set; }
|
||||
public float Speed { get; private set; }
|
||||
public float TurnRate { get; private set; }
|
||||
public bool Grounded { get; private set; }
|
||||
public PlayerPose Pose => Grounded ? Speed < -1 ? PlayerPose.Backpedal : Speed > 1 ? PlayerPose.Run : PlayerPose.Idle
|
||||
public PlayerPose Pose => pendingImpulse.Y > 0 ? PlayerPose.Jump
|
||||
: Grounded ? Speed < -1 ? PlayerPose.Backpedal : Speed > 1 ? PlayerPose.Run : PlayerPose.Idle
|
||||
: jumpState.JumpState == 3 && jumpState.EffectRemaining > 0 ? PlayerPose.Fly
|
||||
: !forceFall && Velocity.Y > 0 ? PlayerPose.Jump : PlayerPose.Fall;
|
||||
public int Steps { get; private set; }
|
||||
@@ -51,9 +60,11 @@ public sealed class LabSimulation
|
||||
public Matrix4x4 Model => Matrix4x4.CreateRotationY(-Yaw * MathF.PI / 180)
|
||||
* Matrix4x4.CreateTranslation(Position - new Vector3(0, modelMinimumY, 0));
|
||||
|
||||
public LabSimulation(SceneCollision collision, Mesh standingPose, Vector3 start, float yaw)
|
||||
public LabSimulation(SceneCollision collision, Mesh standingPose, Vector3 start, float yaw,
|
||||
Func<Vector3, Vector3, SupportHit?>? cameraRay = null)
|
||||
{
|
||||
this.collision = collision;
|
||||
this.cameraRay = cameraRay;
|
||||
sourceStart = start;
|
||||
startYaw = yaw;
|
||||
var bounds = standingPose.Bounds();
|
||||
@@ -76,13 +87,14 @@ public sealed class LabSimulation
|
||||
Velocity = Vector3.Zero;
|
||||
Yaw = targetYaw = startYaw;
|
||||
Speed = TurnRate = extraAirAcceleration = shadowDistance = 0;
|
||||
lateralContribution = 0; pendingImpulse = Vector3.Zero; movementMode = 0;
|
||||
jumpState = default;
|
||||
forceFall = JetpackEffectVisible = false;
|
||||
InteractionRadius = 60; Bursts = 0;
|
||||
Grounded = true;
|
||||
Steps = Jumps = Landings = WallHits = 0;
|
||||
Travel = MaximumRise = 0;
|
||||
CameraEye = DesiredEye();
|
||||
CameraEye = DesiredEye().Eye;
|
||||
}
|
||||
|
||||
/// <summary>Jimmy PostLoad423A90..423ABF restores the saved RETURN root.
|
||||
@@ -92,7 +104,7 @@ public sealed class LabSimulation
|
||||
if (!float.IsFinite(root.X) || !float.IsFinite(root.Y) || !float.IsFinite(root.Z))
|
||||
throw new ArgumentOutOfRangeException(nameof(root));
|
||||
Position = root - Vector3.UnitY * rootHeight;
|
||||
CameraEye = DesiredEye();
|
||||
CameraEye = DesiredEye().Eye;
|
||||
}
|
||||
|
||||
// EXE 0x47F940 truncates, then degree lookup masks to the 16384-entry table.
|
||||
@@ -105,19 +117,29 @@ public sealed class LabSimulation
|
||||
}
|
||||
|
||||
public void Step(PlayerInput input)
|
||||
{
|
||||
//47E554 global body integration precedes473740 registry callbacks.
|
||||
// This reconstructs the player/input/fire partial order, not the full
|
||||
// scene registry, original cadence or original collision response.
|
||||
StepPhysics();
|
||||
if (!InputAfterPlayerUpdate) StepInput(input);
|
||||
StepPlayer(input);
|
||||
var effect = JetpackBurst.StepEffect(jumpState, Grounded, FixedStepClock.Step, Energy, LevelCode);
|
||||
jumpState = effect.State; Energy = effect.Energy; JetpackEffectVisible = effect.Visible;
|
||||
if (InputAfterPlayerUpdate) StepInput(input);
|
||||
Steps++;
|
||||
}
|
||||
|
||||
private void StepInput(PlayerInput input)
|
||||
{
|
||||
const float dt = FixedStepClock.Step;
|
||||
var wasGrounded = Grounded;
|
||||
float lateral = 0;
|
||||
if (Grounded)
|
||||
lateralContribution = 0;
|
||||
//438A60 dispatches by stored movement mode, not current support.
|
||||
if (movementMode == 0)
|
||||
{
|
||||
//437B9E..437BAC uses an interface pointer: interface+614 is
|
||||
//complete+6D4. Normal grounded/released input clears air turn.
|
||||
if (!input.Jump) TurnRate = 0;
|
||||
InteractionRadius = 60; // Jimmy's ordinary grounded update42469B.
|
||||
float yawDelta = 0;
|
||||
if (input.Left) { yawDelta += 20; lateral = -1000; Speed = RecoveredMotion.AddSpeed(Speed); }
|
||||
else if (input.Right) { yawDelta -= 20; lateral = 1000; Speed = RecoveredMotion.AddSpeed(Speed); }
|
||||
if (input.Left) { yawDelta += 20; lateralContribution = -1000; Speed = RecoveredMotion.AddSpeed(Speed); }
|
||||
else if (input.Right) { yawDelta -= 20; lateralContribution = 1000; Speed = RecoveredMotion.AddSpeed(Speed); }
|
||||
if (input.Forward) { yawDelta *= 0.5f; Speed = RecoveredMotion.AddSpeed(Speed); }
|
||||
if (yawDelta != 0) targetYaw = Yaw + yawDelta;
|
||||
if (input.Backward) Speed = MathF.Max(Speed - 52.5f, -300);
|
||||
@@ -131,15 +153,29 @@ public sealed class LabSimulation
|
||||
//438011..43802B adds the independent turn rate directly to yaw.
|
||||
targetYaw = Yaw;
|
||||
}
|
||||
StepCamera(); //438BC0/439900 input path owns follow; still provisional geometry/state.
|
||||
}
|
||||
|
||||
private void StepPlayer(PlayerInput input)
|
||||
{
|
||||
const float dt = FixedStepClock.Step;
|
||||
var yawError = MathF.IEEERemainder(targetYaw - Yaw, 360);
|
||||
Yaw = (Yaw + yawError * dt * 3.7f) % 360;
|
||||
if (Velocity.LengthSquared() != 0 || Grounded && lateral != 0)
|
||||
//437A96 selects air mode on held jump;437B9E..BAC resets jump/mode/turn
|
||||
//only in the player's grounded/released update, after input when fresh.
|
||||
if (input.Jump) movementMode = 1;
|
||||
else if (Grounded)
|
||||
{
|
||||
movementMode = 0; TurnRate = 0;
|
||||
}
|
||||
if (Grounded) InteractionRadius = 60;
|
||||
if (Velocity.LengthSquared() != 0 || movementMode == 0 && lateralContribution != 0)
|
||||
Yaw = (Yaw + TurnRate * dt) % 360;
|
||||
var (sin, cos) = Trig(Yaw);
|
||||
var velocity = new Vector3(-sin * Speed, Velocity.Y, cos * Speed);
|
||||
//437CDx ground uses /45 then dt;43803B air uses /55 without dt.
|
||||
const float friction = .8f;
|
||||
var sideSpeed = Grounded ? (TurnRate * (1 - friction) * Speed / 45 + lateral) * dt
|
||||
var sideSpeed = movementMode == 0 ? (TurnRate * (1 - friction) * Speed / 45 + lateralContribution) * dt
|
||||
: TurnRate * (1 - friction) * Speed * .0181818176060915f;
|
||||
velocity += new Vector3(cos, 0, sin) * sideSpeed;
|
||||
if (collision.GroundHeight(ActorRoot, 2500) is { } shadowFloor)
|
||||
@@ -147,14 +183,26 @@ public sealed class LabSimulation
|
||||
var air = JetpackBurst.Step(jumpState, new(Grounded, input.Jump, velocity.Y, shadowDistance,
|
||||
JetpackInventoryState?.Invoke() ?? 0, Energy, LevelCode, GadgetMode, dt, extraAirAcceleration));
|
||||
jumpState = air.State; extraAirAcceleration = air.ExtraAccelerationY;
|
||||
var impulse = new Vector3(0, air.ImpulseY, 0);
|
||||
if (air.ImpulseY != 0) { Grounded = false; Jumps++; }
|
||||
pendingImpulse += new Vector3(0, air.ImpulseY, 0);
|
||||
if (air.ImpulseY != 0) Jumps++;
|
||||
if (air.MovementModeOverride is { } mode) movementMode = mode;
|
||||
if (air.VelocityYOverride is { } vertical) velocity.Y = vertical;
|
||||
if (air.RadiusOverride is { } radius) InteractionRadius = radius;
|
||||
if (air.Pose == JetpackPose.Fall) forceFall = true;
|
||||
else if (air.Pose is JetpackPose.Jump or JetpackPose.Fly) forceFall = false;
|
||||
if (air.StartGadget) Bursts++;
|
||||
var displacement = RecoveredMotion.Integrate(ref velocity, ref impulse,
|
||||
Velocity = velocity; // Produced body state is consumed by the next physics pass.
|
||||
}
|
||||
|
||||
private void StepPhysics()
|
||||
{
|
||||
const float dt = FixedStepClock.Step;
|
||||
var wasGrounded = Grounded;
|
||||
var velocity = Velocity;
|
||||
// Keep the existing capsule/gravity adapter until C4 recovers Jimmy's
|
||||
// pre-integration support/response. Source479DF7..479E54 can cancel
|
||||
// gravity before a supported impulse; this adapter does not model that.
|
||||
var displacement = RecoveredMotion.Integrate(ref velocity, ref pendingImpulse,
|
||||
Vector3.UnitY * extraAirAcceleration, RecoveredMotion.Gravity, dt);
|
||||
var before = Position;
|
||||
var result = collision.Move(Position, displacement, BodyRadius, BodyHeight);
|
||||
@@ -175,24 +223,30 @@ public sealed class LabSimulation
|
||||
if (Grounded && velocity.Y < 0 || result.HitCeiling && velocity.Y > 0) velocity.Y = 0;
|
||||
if (Grounded) { extraAirAcceleration = 0; forceFall = false; }
|
||||
Velocity = velocity;
|
||||
// Explicit port phase policy: controller, collision, then effect update.
|
||||
// Original global object iteration order has not yet been matched.
|
||||
var effect = JetpackBurst.StepEffect(jumpState, Grounded, dt, Energy, LevelCode);
|
||||
jumpState = effect.State; Energy = effect.Energy; JetpackEffectVisible = effect.Visible;
|
||||
if (!wasGrounded && Grounded) Landings++;
|
||||
if (result.HitWall) WallHits++;
|
||||
Travel += Vector2.Distance(new(before.X, before.Z), new(Position.X, Position.Z));
|
||||
MaximumRise = Math.Max(MaximumRise, Position.Y - startFloor);
|
||||
Steps++;
|
||||
var desired = DesiredEye();
|
||||
var delta = (desired - CameraEye) * new Vector3(1.6f, 1.2f, 1.6f) * dt;
|
||||
CameraEye = collision.ClipCamera(CameraTarget, CameraEye + delta);
|
||||
}
|
||||
|
||||
private Vector3 DesiredEye()
|
||||
private void StepCamera()
|
||||
{
|
||||
const float dt = FixedStepClock.Step;
|
||||
var desired = DesiredEye();
|
||||
var delta = (desired.Eye - CameraEye) * new Vector3(1.6f, 1.2f, 1.6f) * desired.Gain * dt;
|
||||
CameraEye = cameraRay == null ? collision.ClipCamera(CameraTarget, CameraEye + delta) : CameraEye + delta;
|
||||
}
|
||||
|
||||
private (Vector3 Eye, float Gain) DesiredEye()
|
||||
{
|
||||
var (sin, cos) = Trig(Yaw);
|
||||
return collision.ClipCamera(CameraTarget, ActorRoot + new Vector3(sin * 350, 180, -cos * 350));
|
||||
var eye = ActorRoot + new Vector3(sin * 350, 180, -cos * 350);
|
||||
if (cameraRay == null) return (collision.ClipCamera(CameraTarget, eye), 1);
|
||||
//43B820: query from the computed look target; first accepted static hit
|
||||
//moves desired eye25% toward look and returns follow gain1.5. No radius
|
||||
//or second sweep after interpolation occurs in that source callback.
|
||||
return cameraRay(CameraTarget, eye) is { } hit
|
||||
? (CameraTarget - (CameraTarget - hit.Position) * .75f, 1.5f) : (eye, 1);
|
||||
}
|
||||
|
||||
public static PlayerInput SmokeInput(int step) => new(step < 120, false, false,
|
||||
|
||||
@@ -107,35 +107,53 @@ public static class OriginalBodySupport
|
||||
var nearestDistance = length;
|
||||
foreach (var triangle in triangles)
|
||||
{
|
||||
RequireFinite(triangle.A); RequireFinite(triangle.B); RequireFinite(triangle.C);
|
||||
var edge1 = triangle.B - triangle.A;
|
||||
var edge2 = triangle.C - triangle.A;
|
||||
var p = Cross(direction, edge2);
|
||||
var determinant = Dot(edge1, p);
|
||||
// Source indices use the opposite sign from a conventional right-
|
||||
// handed visible-front-face test. Preserve the actual serialized order.
|
||||
if (twoSided ? MathF.Abs(determinant) < TriangleEpsilon : determinant > -TriangleEpsilon)
|
||||
continue;
|
||||
var inverse = 1 / determinant;
|
||||
var relative = start - triangle.A;
|
||||
var u = Dot(relative, p) * inverse;
|
||||
if (u < 0 || u > 1) continue;
|
||||
var q = Cross(relative, edge1);
|
||||
var v = Dot(q, direction) * inverse;
|
||||
if (v < 0 || u + v > 1) continue;
|
||||
var distance = Dot(q, edge2) * inverse;
|
||||
// Source accepts the beginning, but rejects its endpoint and equal
|
||||
// distance candidates. No invented extra ray distance or skin is used.
|
||||
if (distance < 0 || distance >= length) continue;
|
||||
var position = start + direction * distance;
|
||||
var fromStart = QuickMagnitude(position - start);
|
||||
if (fromStart >= nearestDistance) continue;
|
||||
nearestDistance = fromStart;
|
||||
nearest = new SupportHit(position, triangle.ShapeId, triangle.PolygonId, fromStart);
|
||||
var hit = IntersectSegment(triangle, start, direction, length, twoSided);
|
||||
if (hit is not { } candidate || candidate.Distance >= nearestDistance) continue;
|
||||
nearestDistance = candidate.Distance;
|
||||
nearest = candidate;
|
||||
}
|
||||
return nearest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EXE469B70's individual source-winding triangle test, without47C6E0's
|
||||
/// nearest-hit reduction. Camera47C210 instead accepts the first grid hit.
|
||||
/// </summary>
|
||||
public static SupportHit? IntersectSegment(SupportTriangle triangle,
|
||||
Vector3 start, Vector3 end, bool twoSided = false)
|
||||
{
|
||||
RequireFinite(start); RequireFinite(end);
|
||||
var direction = end - start;
|
||||
var length = QuickMagnitude(direction);
|
||||
if (length == 0) return null;
|
||||
return IntersectSegment(triangle, start, direction / length, length, twoSided);
|
||||
}
|
||||
|
||||
private static SupportHit? IntersectSegment(SupportTriangle triangle,
|
||||
Vector3 start, Vector3 direction, float length, bool twoSided)
|
||||
{
|
||||
RequireFinite(triangle.A); RequireFinite(triangle.B); RequireFinite(triangle.C);
|
||||
var edge1 = triangle.B - triangle.A;
|
||||
var edge2 = triangle.C - triangle.A;
|
||||
var p = Cross(direction, edge2);
|
||||
var determinant = Dot(edge1, p);
|
||||
// Preserve serialized winding, opposite to the conventional visible front.
|
||||
if (twoSided ? MathF.Abs(determinant) < TriangleEpsilon : determinant > -TriangleEpsilon)
|
||||
return null;
|
||||
var inverse = 1 / determinant;
|
||||
var relative = start - triangle.A;
|
||||
var u = Dot(relative, p) * inverse;
|
||||
if (u < 0 || u > 1) return null;
|
||||
var q = Cross(relative, edge1);
|
||||
var v = Dot(q, direction) * inverse;
|
||||
if (v < 0 || u + v > 1) return null;
|
||||
var distance = Dot(q, edge2) * inverse;
|
||||
// Beginning accepted, endpoint rejected; no invented camera radius/skin.
|
||||
if (distance < 0 || distance >= length) return null;
|
||||
var position = start + direction * distance;
|
||||
return new SupportHit(position, triangle.ShapeId, triangle.PolygonId, QuickMagnitude(position - start));
|
||||
}
|
||||
|
||||
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 Vector3 Cross(Vector3 a, Vector3 b) => new(
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
using System.Numerics;
|
||||
using GamePort.Assets;
|
||||
|
||||
namespace GamePort.Game;
|
||||
|
||||
public readonly record struct CameraRayPolygon(SupportTriangle Triangle, Vector3 StoredNormal,
|
||||
string? ShapeName = null, string? MaterialName = null);
|
||||
public readonly record struct CameraRayResult(Vector3 Eye, float Gain, SupportHit? Hit);
|
||||
|
||||
/// <summary>
|
||||
/// Source47C210 static camera predicate: first accepted wall-grid polygon, then
|
||||
/// first general-grid polygon. Cell rectangle order and FIFO registration matter;
|
||||
/// this is not the support query's nearest-hit reducer or a camera sphere sweep.
|
||||
/// See checkpoint/camera-ray-predicate.md for addresses and approximation limits.
|
||||
/// </summary>
|
||||
public sealed class OriginalCameraRay
|
||||
{
|
||||
public const int GridSize = 260;
|
||||
public const float CellScale = 0.0020000000949949026f; //4D6A04.
|
||||
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 int PolygonCount { get; }
|
||||
public int WallPolygonCount { get; }
|
||||
/// <summary>Modern query diagnostic; repeated cells are intentionally counted.</summary>
|
||||
public int LastTriangleTests { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Caller supplies raw, untranslated static source triangles. Registration
|
||||
/// follows shape resource ID then polygon array index, not render-draw order.
|
||||
/// Game-specific polygon exclusion must be resolved by the caller.
|
||||
/// </summary>
|
||||
public OriginalCameraRay(IEnumerable<CameraRayPolygon> polygons)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(polygons);
|
||||
var identities = new HashSet<(int Shape, int Polygon)>();
|
||||
foreach (var polygon in polygons.OrderBy(p => p.Triangle.ShapeId).ThenBy(p => p.Triangle.PolygonId))
|
||||
{
|
||||
if (polygon.ShapeName?.StartsWith("nc", StringComparison.OrdinalIgnoreCase) == true
|
||||
|| IsCheckpoint(polygon.MaterialName)) continue;
|
||||
var triangle = polygon.Triangle;
|
||||
RequireFinite(triangle.A); RequireFinite(triangle.B); RequireFinite(triangle.C);
|
||||
RequireFinite(polygon.StoredNormal);
|
||||
if (!identities.Add((triangle.ShapeId, triangle.PolygonId)))
|
||||
throw new InvalidDataException("Camera query needs one source triangle per polygon; fan-triangulated polygons are unsupported");
|
||||
var wall = polygon.StoredNormal.Y < .7f; //4798B3; equality excluded.
|
||||
var min = Vector3.Min(triangle.A, Vector3.Min(triangle.B, triangle.C));
|
||||
var max = Vector3.Max(triangle.A, Vector3.Max(triangle.B, triangle.C));
|
||||
foreach (var cell in CellsBetween(min, max))
|
||||
{
|
||||
Append(all, cell, triangle);
|
||||
if (wall) Append(walls, cell, triangle);
|
||||
}
|
||||
PolygonCount++;
|
||||
if (wall) WallPolygonCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LV1B/VR04/LEV1 complete game slot134 is475CD0 (false), 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 "VR04" or "LEV1"))
|
||||
throw new NotSupportedException("Static camera game-filter recovery currently covers LV1B, VR04 and LEV1");
|
||||
if (mesh.Indices.Length % 3 != 0 || mesh.CollisionPolygons.Length != mesh.Indices.Length / 3)
|
||||
throw new InvalidDataException("Original camera query requires source polygon metadata");
|
||||
var polygons = new CameraRayPolygon[mesh.CollisionPolygons.Length];
|
||||
for (var i = 0; i < polygons.Length; i++)
|
||||
{
|
||||
var source = mesh.CollisionPolygons[i];
|
||||
var a = mesh.Indices[i * 3]; var b = mesh.Indices[i * 3 + 1]; var c = mesh.Indices[i * 3 + 2];
|
||||
if (a >= mesh.Vertices.Length || b >= mesh.Vertices.Length || c >= mesh.Vertices.Length)
|
||||
throw new InvalidDataException("Camera triangle index outside vertex table");
|
||||
polygons[i] = new(new(mesh.Vertices[a].Position, mesh.Vertices[b].Position, mesh.Vertices[c].Position,
|
||||
source.ShapeId, source.PolygonIndex), source.Normal, source.ShapeName, source.MaterialName);
|
||||
}
|
||||
return new(polygons);
|
||||
}
|
||||
|
||||
/// <summary>47C210/47C280/47C4B0: increasing X, increasing Z, FIFO first hit.</summary>
|
||||
public SupportHit? Trace(Vector3 start, Vector3 end, bool twoSided = false)
|
||||
{
|
||||
RequireFinite(start); RequireFinite(end);
|
||||
LastTriangleTests = 0;
|
||||
if (!Enabled) return null;
|
||||
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 (OriginalBodySupport.IntersectSegment(triangle, start, end, twoSided) is { } hit)
|
||||
return hit;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>43B820: ray originates at computed look target, never actor root.</summary>
|
||||
public CameraRayResult Constrain(Vector3 lookPoint, Vector3 desiredEye)
|
||||
{
|
||||
var hit = Trace(lookPoint, desiredEye);
|
||||
return hit is { } accepted
|
||||
? new(lookPoint - (lookPoint - accepted.Position) * .75f, 1.5f, accepted)
|
||||
: new(desiredEye, 1, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///47F940 truncation then signed16. Double intermediates approximate source
|
||||
/// x87, not bit-exact boundary emulation. Conversion overflow is unsupported.
|
||||
/// </summary>
|
||||
public static short CellCoordinate(float value)
|
||||
{
|
||||
if (!float.IsFinite(value)) throw new ArgumentOutOfRangeException(nameof(value));
|
||||
var scaled = (double)value * CellScale + CellOrigin;
|
||||
if (scaled <= long.MinValue || scaled >= long.MaxValue)
|
||||
throw new ArgumentOutOfRangeException(nameof(value), "Original x87 integer-overflow behavior is not recovered");
|
||||
return unchecked((short)(long)Math.Truncate(scaled));
|
||||
}
|
||||
|
||||
private static IEnumerable<int> CellsBetween(Vector3 a, Vector3 b)
|
||||
{
|
||||
var ax = (int)CellCoordinate(a.X); var bx = (int)CellCoordinate(b.X);
|
||||
var az = (int)CellCoordinate(a.Z); var bz = (int)CellCoordinate(b.Z);
|
||||
var minX = Math.Max(0, Math.Min(ax, bx)); var maxX = Math.Min(GridSize - 1, Math.Max(ax, bx));
|
||||
var minZ = Math.Max(0, Math.Min(az, bz)); var maxZ = Math.Min(GridSize - 1, Math.Max(az, bz));
|
||||
for (var x = minX; x <= maxX; x++)
|
||||
for (var z = minZ; z <= maxZ; z++) yield return GridSize * x + z;
|
||||
}
|
||||
|
||||
private static void Append(Dictionary<int, List<SupportTriangle>> grid, int cell, SupportTriangle triangle)
|
||||
{
|
||||
if (!grid.TryGetValue(cell, out var list)) grid.Add(cell, list = []);
|
||||
list.Add(triangle);
|
||||
}
|
||||
|
||||
private static bool IsCheckpoint(string? material) => material is not null
|
||||
&& (material.Equals("cstart", StringComparison.OrdinalIgnoreCase)
|
||||
|| material.Length == 7 && material.StartsWith("ccheck", StringComparison.OrdinalIgnoreCase)
|
||||
&& material[6] is >= '1' and <= '9');
|
||||
|
||||
private static void RequireFinite(Vector3 vector)
|
||||
{
|
||||
if (!float.IsFinite(vector.X) || !float.IsFinite(vector.Y) || !float.IsFinite(vector.Z))
|
||||
throw new ArgumentOutOfRangeException(nameof(vector), "Finite source coordinates required");
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,24 @@ public sealed class SceneInventory
|
||||
|
||||
public void SetState(int group, int item, int state) => states[Offset(group, item)] = state;
|
||||
|
||||
/// <summary>
|
||||
/// Jimmy PostLoad423DEF..423EC1: enable these eight owned gadgets, then
|
||||
/// disable them in numeric VR01..VR08. State4 is unavailable ownership,
|
||||
/// distinct from unowned0. Other wire values and item8 remain unchanged.
|
||||
/// </summary>
|
||||
public void ApplyLevelAvailability(string levelCode)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(levelCode);
|
||||
ReadOnlySpan<int> items = [7, 3, 0, 5, 1, 6, 2, 4];
|
||||
foreach (var item in items)
|
||||
if (states[item] == 4) states[item] = 1;
|
||||
// Exactly the eight original FourCC values in the source numeric range.
|
||||
if (levelCode.Length == 4 && levelCode.StartsWith("VR0", StringComparison.Ordinal)
|
||||
&& levelCode[3] is >= '1' and <= '8')
|
||||
foreach (var item in items)
|
||||
if (states[item] == 1) states[item] = 4;
|
||||
}
|
||||
|
||||
public void SelectGadget(int item)
|
||||
{
|
||||
if (item != -1 && (item is < 0 or >= 9 || State(0, item) == 0))
|
||||
|
||||
Reference in new issue
Block a user