Cut 6b: Brokkr drop_pod.glb, petal blow-off, retro VFX/audio/juice, drop HUD/camera, and GL3 Sion captures

This commit is contained in:
Meta Vens 2026-12-05 11:45:04 +01:00
commit 5af5d87e06
15 changed files with 1847 additions and 94 deletions

View file

@ -47,6 +47,9 @@ public partial class Main : Node3D
private float _cameraZoom = 1.0f;
private float _smoothedShoulderY;
private string? _lastCamChassisId;
private float _orbitalPodCamBlend;
private ContenderLifecycle _prevLocalLifecycle = ContenderLifecycle.Active;
private MeshInstance3D _dropReticleMesh = null!;
private Vector3 _baseCamPos;
private Vector3 _baseLookDir = Vector3.Forward;
private bool _hasBaseCamPose;
@ -89,6 +92,7 @@ public partial class Main : Node3D
public Hud Hud => _hud;
public ArenaMapKind MapKind => _mapKind;
public ArenaMapKind? InitialMapKindOverride { get; set; }
public bool InitialSkipDropOverride { get; set; }
public string? Failure { get; private set; }
public int Seed => _seed;
public float CameraYaw => _cameraYaw;
@ -108,6 +112,7 @@ public partial class Main : Node3D
_arena = new ArenaRenderer { Name = "Arena" };
AddChild(_arena);
_arena.AssetCache.PreloadAll();
_audio = new ArenaAudioSystem { Name = "ArenaAudio" };
AddChild(_audio);
@ -128,6 +133,24 @@ public partial class Main : Node3D
_hud.NetworkPanelToggled += _ => SyncMouseMode();
AddChild(_hud);
var reticleMat = new StandardMaterial3D
{
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
Transparency = BaseMaterial3D.TransparencyEnum.Alpha,
AlbedoColor = new Color(0.27f, 0.85f, 0.91f, 0.82f),
NoDepthTest = false,
CullMode = BaseMaterial3D.CullModeEnum.Disabled
};
_dropReticleMesh = new MeshInstance3D
{
Name = "DropLandingReticle",
Mesh = new TorusMesh { InnerRadius = 2.5f, OuterRadius = 3.05f, Rings = 28, RingSegments = 8 },
MaterialOverride = reticleMat,
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off,
Visible = false
};
AddChild(_dropReticleMesh);
string? cliConnect = GetCliArg("--connect");
string? cliHost = GetCliArg("--host", allowBareFlag: true);
string? cliName = GetCliArg("--name");
@ -190,6 +213,9 @@ public partial class Main : Node3D
_perfTargetFrames = autoExitFrames;
}
bool perfCombat = _perfTargetFrames > 0 && System.Environment.GetEnvironmentVariable("RTD_PERF_COMBAT") == "1";
bool skipInitialDrop = InitialSkipDropOverride || perfCombat;
if (!string.IsNullOrWhiteSpace(connectTarget))
{
StartRemoteSession(connectTarget, _callsign);
@ -200,10 +226,10 @@ public partial class Main : Node3D
}
else
{
Reset(_seed, _mapKind);
Reset(_seed, _mapKind, skipInitialDrop);
}
if (_perfTargetFrames > 0 && System.Environment.GetEnvironmentVariable("RTD_PERF_COMBAT") == "1" && _session is not null)
if (perfCombat && _session is not null)
{
SetupPerfCombatScenario(_session);
}
@ -280,7 +306,7 @@ public partial class Main : Node3D
_boundViewState = null;
}
public void Reset(int seed, ArenaMapKind? mapKind = null)
public void Reset(int seed, ArenaMapKind? mapKind = null, bool skipInitialDrop = false)
{
_seed = seed;
if (mapKind.HasValue)
@ -297,7 +323,7 @@ public partial class Main : Node3D
try
{
_session = new LocalArenaSession(seed, _mapKind, _callsign);
_session = new LocalArenaSession(seed, _mapKind, _callsign, skipInitialDrop);
BindSessionPresentation(resetCamera: true);
}
catch (Exception ex)
@ -407,7 +433,17 @@ public partial class Main : Node3D
{
var p = _session.LocalContender;
_cameraYaw = p.Yaw;
_cameraPitch = _mapKind == ArenaMapKind.Sion ? Mathf.DegToRad(5f) : Mathf.DegToRad(12f);
_prevLocalLifecycle = p.Lifecycle;
if (p.IsInDropPod)
{
_cameraPitch = Mathf.DegToRad(36f);
_orbitalPodCamBlend = 1.0f;
}
else
{
_cameraPitch = _mapKind == ArenaMapKind.Sion ? Mathf.DegToRad(5f) : Mathf.DegToRad(12f);
_orbitalPodCamBlend = 0f;
}
_cameraZoom = 1.0f;
_lastCamChassisId = null;
_hasBaseCamPose = false;
@ -835,9 +871,30 @@ public partial class Main : Node3D
_arena.ConsumeEvents(_session, _frameEvents, _frameFootsteps, dt, SampleCurrentMapGroundTint);
var local = _session.LocalContender;
if (local.Lifecycle == ContenderLifecycle.Deploying && _prevLocalLifecycle != ContenderLifecycle.Deploying)
{
_cameraPitch = Mathf.DegToRad(36f);
_orbitalPodCamBlend = 1.0f;
}
_prevLocalLifecycle = local.Lifecycle;
var localPos = new System.Numerics.Vector3(local.X, local.Y, local.Z);
_camJuice.ConsumeEvents(_frameEvents, _session.LocalContenderId, localPos, _session);
_camJuice.ConsumeFootsteps(_frameFootsteps, _session.LocalContenderId);
if (local.IsInDropPod)
{
var pods = _session.ActivePods;
for (int i = 0; i < pods.Count; i++)
{
if (pods[i].PodKind == OrbitalPodKind.Contender &&
pods[i].ContenderId == _session.LocalContenderId &&
pods[i].Phase == OrbitalPodPhase.RetroBurn)
{
_camJuice.ApplyOrbitalBurnRumble(1.0f);
break;
}
}
}
_camJuice.Update(dt, local.Speed, local.Grid.Spec.IsVtol);
}
@ -989,8 +1046,13 @@ public partial class Main : Node3D
private PlayerInput GatherPlayerInput()
{
var (aimX, aimY, aimZ) = ComputeCenterScreenAim();
if (_hud.IsUiTextInputFocused)
var local = Session.LocalContender;
bool inPod = local.IsInDropPod;
var (aimX, aimY, aimZ) = inPod
? (local.X + MathF.Sin(_cameraYaw) * 120f, local.Y - 40f, local.Z + MathF.Cos(_cameraYaw) * 120f)
: ComputeCenterScreenAim();
if (_hud.IsUiTextInputFocused || local.WaitingForRespawn)
{
return new PlayerInput(
Throttle: 0f,
@ -1012,15 +1074,18 @@ public partial class Main : Node3D
if (Input.IsKeyPressed(Key.D) || Input.IsKeyPressed(Key.Right)) steer += 1f;
if (Input.IsKeyPressed(Key.A) || Input.IsKeyPressed(Key.Left)) steer -= 1f;
bool isVtol = Session.LocalContender.Grid.Spec.IsVtol;
bool isVtol = !inPod && local.Grid.Spec.IsVtol;
float verticalThrottle = 0f;
if (Input.IsKeyPressed(Key.Space)) verticalThrottle += 1f;
if (Input.IsKeyPressed(Key.C) || Input.IsKeyPressed(Key.Ctrl)) verticalThrottle -= 1f;
if (!inPod)
{
if (Input.IsKeyPressed(Key.Space)) verticalThrottle += 1f;
if (Input.IsKeyPressed(Key.C) || Input.IsKeyPressed(Key.Ctrl)) verticalThrottle -= 1f;
}
bool brake = isVtol ? Input.IsKeyPressed(Key.Shift) : Input.IsKeyPressed(Key.Space);
bool brake = !inPod && (isVtol ? Input.IsKeyPressed(Key.Shift) : Input.IsKeyPressed(Key.Space));
bool pointerOnHud = Input.MouseMode != Input.MouseModeEnum.Captured &&
(_hud.NetworkPanelOpen || _hud.IsPointerOverInteractiveHud(GetViewport().GetMousePosition()));
bool fire = !pointerOnHud && Input.IsMouseButtonPressed(MouseButton.Left);
bool fire = !inPod && !pointerOnHud && Input.IsMouseButtonPressed(MouseButton.Left);
return new PlayerInput(
Throttle: throttle,
@ -1028,7 +1093,7 @@ public partial class Main : Node3D
AimWorldX: aimX,
AimWorldZ: aimZ,
Fire: fire,
InteractPickup: _interactQueued,
InteractPickup: !inPod && _interactQueued,
Brake: brake,
AimWorldY: aimY,
VerticalThrottle: verticalThrottle);
@ -1151,60 +1216,140 @@ public partial class Main : Node3D
var spec = p.Grid.Spec;
var (posInterp, _, _) = Session.GetInterpolatedContenderPose(p.Id, alpha);
float rightOffset = MathF.Max(1.6f, spec.HalfWidth * 1.15f + 0.8f);
float heightOffset = spec.HalfHeight * 1.45f + 1.4f;
float boundingR = MathF.Max(spec.HalfWidth, MathF.Max(spec.HalfHeight * 0.72f, spec.HalfLength * 0.90f));
float backDist = Math.Clamp(boundingR * 2.15f + 4.2f, 7.2f, 19.5f) * _cameraZoom;
float targetShoulderY = (posInterp.Y - spec.HalfHeight) + heightOffset;
Vector3 camRight = new(-MathF.Cos(_cameraYaw), 0f, MathF.Sin(_cameraYaw));
Vector3 camFwdHoriz = new(MathF.Sin(_cameraYaw), 0f, MathF.Cos(_cameraYaw));
if (_lastCamChassisId != spec.Id || dt >= 1f)
Vector3 camPos;
Vector3 lookDir;
if (p.WaitingForRespawn)
{
_smoothedShoulderY = targetShoulderY;
_lastCamChassisId = spec.Id;
_dropReticleMesh.Visible = false;
float orbitRadius = MathF.Min(Session.ViewState.Spectators.SafeRadius * 0.45f, 165f);
float orbitAngle = _elapsedSeconds * 0.14f + _cameraYaw;
float ox = MathF.Cos(orbitAngle) * orbitRadius;
float oz = MathF.Sin(orbitAngle) * orbitRadius;
float oy = Session.ViewState.Terrain.SampleHeight(ox, oz) + 75f;
camPos = new Vector3(ox, MathF.Max(oy, 110f), oz);
float centerY = Session.ViewState.Terrain.SampleHeight(0f, 0f) + 12f;
lookDir = (new Vector3(0f, centerY, 0f) - camPos).Normalized();
}
else if (p.IsInDropPod)
{
// Live landing ring reticle directly under the descending pod
float surfY = Session.ViewState.Terrain.SampleHeight(posInterp.X, posInterp.Z);
var (nx, ny, nz) = Session.ViewState.Terrain.SampleNormal(posInterp.X, posInterp.Z);
if (_mapKind == ArenaMapKind.Sion && Session.ViewState.SionMap is { } sm &&
sm.TryGetBuildingAt(posInterp.X, posInterp.Z, 1.6f, out var bldg))
{
if (bldg.RoofY > surfY && posInterp.Y >= bldg.RoofY - 1.0f)
{
surfY = bldg.RoofY;
nx = 0f; ny = 1f; nz = 0f;
}
}
Vector3 surfNorm = new Vector3(nx, ny, nz).Normalized();
if (surfNorm.LengthSquared() < 1e-4f) surfNorm = Vector3.Up;
Vector3 upRef = MathF.Abs(surfNorm.Y) > 0.92f ? Vector3.Forward : Vector3.Up;
Vector3 rRight = upRef.Cross(surfNorm).Normalized();
Vector3 rFwd = surfNorm.Cross(rRight).Normalized();
float pulse = 1.0f + 0.08f * MathF.Sin(_elapsedSeconds * 7.5f);
_dropReticleMesh.Visible = true;
_dropReticleMesh.GlobalTransform = new Transform3D(
new Basis(rRight, surfNorm, rFwd) * Basis.FromScale(new Vector3(pulse, 1f, pulse)),
new Vector3(posInterp.X, surfY + 0.35f, posInterp.Z));
_orbitalPodCamBlend = 1.0f;
float backDist = 23.0f * _cameraZoom;
Vector3 pivot = new(posInterp.X, posInterp.Y + 3.2f, posInterp.Z);
lookDir = (camFwdHoriz * MathF.Cos(_cameraPitch) - Vector3.Up * MathF.Sin(_cameraPitch)).Normalized();
float effectiveRight = 2.6f;
if (CastStaticCameraRay(pivot, camRight, effectiveRight, out float rightHitDist))
{
effectiveRight = MathF.Min(effectiveRight, SafeCameraPullbackDist(rightHitDist));
}
Vector3 shoulderPos = pivot + camRight * effectiveRight;
float effectiveBack = backDist;
if (CastStaticCameraRay(shoulderPos, -lookDir, backDist, out float backHitDist))
{
effectiveBack = MathF.Min(effectiveBack, SafeCameraPullbackDist(backHitDist));
}
camPos = shoulderPos - lookDir * effectiveBack;
float minTerrainY = Session.ViewState.Terrain.SampleHeight(camPos.X, camPos.Z) + 2.2f;
if (camPos.Y < minTerrainY) camPos.Y = minTerrainY;
_smoothedShoulderY = pivot.Y;
}
else
{
float yBlend = 1f - MathF.Exp(-dt * 24f);
_smoothedShoulderY = Mathf.Lerp(_smoothedShoulderY, targetShoulderY, yBlend);
}
var pivot = new Vector3(posInterp.X, _smoothedShoulderY, posInterp.Z);
var camRight = new Vector3(-MathF.Cos(_cameraYaw), 0f, MathF.Sin(_cameraYaw));
var camFwdHoriz = new Vector3(MathF.Sin(_cameraYaw), 0f, MathF.Cos(_cameraYaw));
var lookDir = (camFwdHoriz * MathF.Cos(_cameraPitch) - Vector3.Up * MathF.Sin(_cameraPitch)).Normalized();
// Segment 1: sweep terrain + static Box3D (StableId < ContenderStableIdBase) from pivot along camRight * rightOffset
float effectiveRight = rightOffset;
if (CastStaticCameraRay(pivot, camRight, rightOffset, out float rightHitDist))
{
effectiveRight = MathF.Min(effectiveRight, SafeCameraPullbackDist(rightHitDist));
}
Vector3 shoulderPos = pivot + camRight * effectiveRight;
// Segment 2: sweep terrain + static Box3D from shoulderPos along -lookDir * backDist
float effectiveBack = backDist;
if (CastStaticCameraRay(shoulderPos, -lookDir, backDist, out float backHitDist))
{
effectiveBack = MathF.Min(effectiveBack, SafeCameraPullbackDist(backHitDist));
}
Vector3 camPos = shoulderPos - lookDir * effectiveBack;
float minTerrainY = Session.ViewState.Terrain.SampleHeight(camPos.X, camPos.Z) + 1.2f;
if (camPos.Y < minTerrainY)
{
camPos.Y = minTerrainY;
}
// Segment 3: verify direct pivot -> camPos LOS against static terrain/buildings so stepped wings cannot occlude player
Vector3 pivotToCam = camPos - pivot;
float pivotToCamDist = pivotToCam.Length();
if (pivotToCamDist > 0.05f)
{
Vector3 pivotToCamDir = pivotToCam / pivotToCamDist;
if (CastStaticCameraRay(pivot, pivotToCamDir, pivotToCamDist, out float wingHitDist))
_dropReticleMesh.Visible = false;
if (_orbitalPodCamBlend > 0.001f && dt > 0f && dt < 0.5f)
{
camPos = pivot + pivotToCamDir * SafeCameraPullbackDist(wingHitDist);
float targetPitch = _mapKind == ArenaMapKind.Sion ? Mathf.DegToRad(8f) : Mathf.DegToRad(12f);
_cameraPitch = Mathf.Lerp(_cameraPitch, targetPitch, 1f - MathF.Exp(-dt * 4.0f));
_orbitalPodCamBlend *= MathF.Exp(-dt * 4.5f);
if (_orbitalPodCamBlend < 0.005f) _orbitalPodCamBlend = 0f;
}
float rightOffset = MathF.Max(1.6f, spec.HalfWidth * 1.15f + 0.8f);
float heightOffset = spec.HalfHeight * 1.45f + 1.4f;
float boundingR = MathF.Max(spec.HalfWidth, MathF.Max(spec.HalfHeight * 0.72f, spec.HalfLength * 0.90f));
float backDist = Math.Clamp(boundingR * 2.15f + 4.2f, 7.2f, 19.5f) * _cameraZoom;
if (_orbitalPodCamBlend > 0f)
{
backDist = Mathf.Lerp(backDist, 22.0f * _cameraZoom, _orbitalPodCamBlend);
heightOffset = Mathf.Lerp(heightOffset, heightOffset + 2.2f, _orbitalPodCamBlend);
}
float targetShoulderY = (posInterp.Y - spec.HalfHeight) + heightOffset;
if (_lastCamChassisId != spec.Id || dt >= 1f)
{
_smoothedShoulderY = targetShoulderY;
_lastCamChassisId = spec.Id;
}
else
{
float yBlend = 1f - MathF.Exp(-dt * 24f);
_smoothedShoulderY = Mathf.Lerp(_smoothedShoulderY, targetShoulderY, yBlend);
}
var pivot = new Vector3(posInterp.X, _smoothedShoulderY, posInterp.Z);
lookDir = (camFwdHoriz * MathF.Cos(_cameraPitch) - Vector3.Up * MathF.Sin(_cameraPitch)).Normalized();
// Segment 1: sweep terrain + static Box3D (StableId < ContenderStableIdBase) from pivot along camRight * rightOffset
float effectiveRight = rightOffset;
if (CastStaticCameraRay(pivot, camRight, rightOffset, out float rightHitDist))
{
effectiveRight = MathF.Min(effectiveRight, SafeCameraPullbackDist(rightHitDist));
}
Vector3 shoulderPos = pivot + camRight * effectiveRight;
// Segment 2: sweep terrain + static Box3D from shoulderPos along -lookDir * backDist
float effectiveBack = backDist;
if (CastStaticCameraRay(shoulderPos, -lookDir, backDist, out float backHitDist))
{
effectiveBack = MathF.Min(effectiveBack, SafeCameraPullbackDist(backHitDist));
}
camPos = shoulderPos - lookDir * effectiveBack;
float minTerrainY = Session.ViewState.Terrain.SampleHeight(camPos.X, camPos.Z) + 1.2f;
if (camPos.Y < minTerrainY)
{
camPos.Y = minTerrainY;
}
// Segment 3: verify direct pivot -> camPos LOS against static terrain/buildings so stepped wings cannot occlude player
Vector3 pivotToCam = camPos - pivot;
float pivotToCamDist = pivotToCam.Length();
if (pivotToCamDist > 0.05f)
{
Vector3 pivotToCamDir = pivotToCam / pivotToCamDist;
if (CastStaticCameraRay(pivot, pivotToCamDir, pivotToCamDist, out float wingHitDist))
{
camPos = pivot + pivotToCamDir * SafeCameraPullbackDist(wingHitDist);
}
}
}