feat(core): Phase B.3 — CellPortal-based indoor/outdoor transitions in PhysicsEngine

Replace the disabled if(false) outdoor→indoor branch with real portal-plane
crossing logic. LandblockPhysics now carries IReadOnlyList<PortalPlane> Portals
(populated at load time; GameWindow passes Array.Empty for now until Task 3).

Resolve logic:
- Outdoor player: tests all portals where TargetCellId==0xFFFF (outside-facing);
  crossing enters the portal's OwnerCellId.
- Indoor player: tests portals where OwnerCellId==currentCell; crossing to
  TargetCellId==0xFFFF exits to terrain, otherwise transitions room-to-room.
- Landblock boundary crossing: unchanged — candidatePos landblock lookup already
  picks the adjacent block's terrain naturally.

Tests: renamed disabled test → Resolve_OutdoorThroughPortal_TransitionsToIndoor;
added Resolve_IndoorThroughExitPortal_TransitionsToOutdoor and
Resolve_LandblockBoundary_PicksAdjacentTerrain. 274 tests green.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-12 18:22:55 +02:00
parent cb46d892d5
commit 8252523b8b
5 changed files with 318 additions and 62 deletions

View file

@ -15,7 +15,8 @@ public readonly record struct MovementInput(
bool TurnLeft = false,
bool TurnRight = false,
bool Run = false,
float MouseDeltaX = 0f);
float MouseDeltaX = 0f,
bool Jump = false);
/// <summary>
/// Result of a single frame's movement update.
@ -53,6 +54,12 @@ public sealed class PlayerMovementController
/// </summary>
public float StepUpHeight { get; set; } = 5.0f;
public float VerticalVelocity { get; private set; }
public bool IsAirborne { get; private set; }
public float JumpImpulse { get; set; } = 10f;
public float GravityAccel { get; set; } = 20f;
public float AirControlFactor { get; set; } = 0.2f;
public float Yaw { get; set; }
public Vector3 Position { get; private set; }
public uint CellId { get; private set; }
@ -104,11 +111,59 @@ public sealed class PlayerMovementController
if (input.StrafeRight) { dx += rightX * speed * dt * 0.5f; dy += rightY * speed * dt * 0.5f; }
if (input.StrafeLeft) { dx -= rightX * speed * dt * 0.5f; dy -= rightY * speed * dt * 0.5f; }
var delta = new Vector3(dx, dy, 0f);
// While airborne, reduce horizontal authority.
float airFactor = IsAirborne ? AirControlFactor : 1f;
var delta = new Vector3(dx * airFactor, dy * airFactor, 0f);
// 3. Resolve via physics engine.
var result = _physics.Resolve(Position, CellId, delta, StepUpHeight);
Position = result.Position;
// 4. Jump + gravity + falling (vertical axis).
float resolvedGroundZ = result.Position.Z;
// Initiate jump when grounded and Space pressed.
if (input.Jump && result.IsOnGround && !IsAirborne)
{
VerticalVelocity = JumpImpulse;
IsAirborne = true;
}
float newZ;
if (IsAirborne)
{
// Apply gravity and integrate vertical position.
VerticalVelocity -= GravityAccel * dt;
float candidateZ = Position.Z + VerticalVelocity * dt;
if (candidateZ <= resolvedGroundZ)
{
// Landed on terrain/floor.
newZ = resolvedGroundZ;
IsAirborne = false;
VerticalVelocity = 0f;
}
else
{
// Still airborne — override terrain Z with ballistic Z.
newZ = candidateZ;
}
}
else
{
// Detect walking off a ledge: terrain dropped more than StepUpHeight.
if (resolvedGroundZ < Position.Z - StepUpHeight)
{
IsAirborne = true;
VerticalVelocity = 0f;
newZ = Position.Z; // stay at current Z this frame; gravity will pull us down next frame
}
else
{
newZ = resolvedGroundZ;
}
}
Position = new Vector3(result.Position.X, result.Position.Y, newZ);
CellId = result.CellId;
// 4. Determine current motion commands.
@ -180,9 +235,9 @@ public sealed class PlayerMovementController
}
return new MovementResult(
Position: result.Position,
CellId: result.CellId,
IsOnGround: result.IsOnGround,
Position: Position,
CellId: CellId,
IsOnGround: !IsAirborne,
MotionStateChanged: changed,
ForwardCommand: forwardCmd,
SidestepCommand: sidestepCmd,