Cut 5d-2: ParticlePool + OmniLight3D[4], CameraJuiceState, Hud hit-markers & vignette, unified SimEvent drain
This commit is contained in:
parent
7f811c3011
commit
323c02cf8d
12 changed files with 2294 additions and 320 deletions
119
client/Main.cs
119
client/Main.cs
|
|
@ -34,6 +34,7 @@ public partial class Main : Node3D
|
|||
private MatchState? _boundViewState;
|
||||
private bool _wasNetConnected;
|
||||
private readonly WalkerFootstepTracker _footsteps = new();
|
||||
private readonly CameraJuiceState _camJuice = new();
|
||||
private readonly List<ISimEvent> _frameEvents = new(128);
|
||||
private readonly List<FootstepPulse> _frameFootsteps = new(32);
|
||||
private ArenaMapKind _mapKind = ArenaMapKind.Sion;
|
||||
|
|
@ -46,6 +47,9 @@ public partial class Main : Node3D
|
|||
private float _cameraZoom = 1.0f;
|
||||
private float _smoothedShoulderY;
|
||||
private string? _lastCamChassisId;
|
||||
private Vector3 _baseCamPos;
|
||||
private Vector3 _baseLookDir = Vector3.Forward;
|
||||
private bool _hasBaseCamPose;
|
||||
private float _elapsedSeconds;
|
||||
private bool _interactQueued;
|
||||
private int _seed = 42;
|
||||
|
|
@ -80,12 +84,17 @@ public partial class Main : Node3D
|
|||
public ArenaRenderer Arena => _arena;
|
||||
public ArenaAudioSystem Audio => _audio;
|
||||
public WalkerFootstepTracker Footsteps => _footsteps;
|
||||
public CameraJuiceState CameraJuice => _camJuice;
|
||||
public Camera3D Camera => _camera;
|
||||
public Hud Hud => _hud;
|
||||
public ArenaMapKind MapKind => _mapKind;
|
||||
public ArenaMapKind? InitialMapKindOverride { get; set; }
|
||||
public string? Failure { get; private set; }
|
||||
public int Seed => _seed;
|
||||
public float CameraYaw => _cameraYaw;
|
||||
internal Vector3 BaseCameraPosition => _baseCamPos;
|
||||
internal Vector3 BaseCameraLookDir => _baseLookDir;
|
||||
internal (float AimX, float AimY, float AimZ) ProbeCenterScreenAim() => ComputeCenterScreenAim();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -401,10 +410,13 @@ public partial class Main : Node3D
|
|||
_cameraPitch = _mapKind == ArenaMapKind.Sion ? Mathf.DegToRad(5f) : Mathf.DegToRad(12f);
|
||||
_cameraZoom = 1.0f;
|
||||
_lastCamChassisId = null;
|
||||
_hasBaseCamPose = false;
|
||||
_camJuice.Reset();
|
||||
_footsteps.Clear();
|
||||
_frameEvents.Clear();
|
||||
_frameFootsteps.Clear();
|
||||
_audio.ClearAll();
|
||||
_hud.ResetFeedback();
|
||||
}
|
||||
|
||||
_camera.Far = _mapKind == ArenaMapKind.Sion ? 4200f : 1800f;
|
||||
|
|
@ -718,13 +730,14 @@ public partial class Main : Node3D
|
|||
}
|
||||
long tt1 = Stopwatch.GetTimestamp();
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta, alpha);
|
||||
DrainAndFanSimEvents((float)delta, alpha);
|
||||
long ta1 = Stopwatch.GetTimestamp();
|
||||
_perfPendingTerrainMs = (tt1 - tt0) * toMs;
|
||||
_perfPendingArenaMs = (ta1 - tt1) * toMs;
|
||||
|
||||
long tc0 = Stopwatch.GetTimestamp();
|
||||
UpdateCamera((float)delta, alpha);
|
||||
StepAudioAndFootsteps((float)delta, alpha);
|
||||
_audio.UpdateFrame(_session, _frameEvents, _frameFootsteps, _camera.GlobalPosition, (float)delta, alpha);
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
|
|
@ -734,6 +747,9 @@ public partial class Main : Node3D
|
|||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
}
|
||||
long th0 = Stopwatch.GetTimestamp();
|
||||
var localP = _session.LocalContender;
|
||||
float coreRatio = localP.Grid.MaxCoreHp > 0f ? localP.Grid.CoreHp / localP.Grid.MaxCoreHp : 1f;
|
||||
_hud.ConsumeEvents(_frameEvents, _session.LocalContenderId, coreRatio, localP.MaxThermalRatio);
|
||||
_hud.Sync(_session);
|
||||
long th1 = Stopwatch.GetTimestamp();
|
||||
_perfCamMsSum += (th0 - tc0) * toMs;
|
||||
|
|
@ -776,8 +792,9 @@ public partial class Main : Node3D
|
|||
_terrain.Sync(_session.ViewState.Terrain);
|
||||
}
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta, alpha);
|
||||
DrainAndFanSimEvents((float)delta, alpha);
|
||||
UpdateCamera((float)delta, alpha);
|
||||
StepAudioAndFootsteps((float)delta, alpha);
|
||||
_audio.UpdateFrame(_session, _frameEvents, _frameFootsteps, _camera.GlobalPosition, (float)delta, alpha);
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
|
|
@ -786,11 +803,14 @@ public partial class Main : Node3D
|
|||
{
|
||||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
}
|
||||
var localP = _session.LocalContender;
|
||||
float coreRatio = localP.Grid.MaxCoreHp > 0f ? localP.Grid.CoreHp / localP.Grid.MaxCoreHp : 1f;
|
||||
_hud.ConsumeEvents(_frameEvents, _session.LocalContenderId, coreRatio, localP.MaxThermalRatio);
|
||||
_hud.Sync(_session);
|
||||
}
|
||||
}
|
||||
|
||||
private void StepAudioAndFootsteps(float dt, float alpha)
|
||||
private void DrainAndFanSimEvents(float dt, float alpha)
|
||||
{
|
||||
if (_session is null)
|
||||
{
|
||||
|
|
@ -802,9 +822,22 @@ public partial class Main : Node3D
|
|||
_frameFootsteps.Clear();
|
||||
_footsteps.StepSession(_session, dt, alpha, _frameFootsteps, ResolveLiveWalkerFootWorld);
|
||||
|
||||
_audio.UpdateFrame(_session, _frameEvents, _frameFootsteps, _camera.GlobalPosition, dt, alpha);
|
||||
_arena.ConsumeEvents(_session, _frameEvents, _frameFootsteps, dt, SampleCurrentMapGroundTint);
|
||||
|
||||
var local = _session.LocalContender;
|
||||
var localPos = new System.Numerics.Vector3(local.X, local.Y, local.Z);
|
||||
_camJuice.ConsumeEvents(_frameEvents, _session.LocalContenderId, localPos);
|
||||
_camJuice.ConsumeFootsteps(_frameFootsteps, _session.LocalContenderId);
|
||||
_camJuice.Update(dt, local.Speed, local.Grid.Spec.IsVtol);
|
||||
}
|
||||
|
||||
private static readonly Color DesertDustTint = new(0.76f, 0.59f, 0.40f, 1.0f);
|
||||
|
||||
internal Color SampleCurrentMapGroundTint(float worldX, float worldZ) =>
|
||||
_mapKind == ArenaMapKind.Sion
|
||||
? _sionMap.SampleGroundTint(worldX, worldZ)
|
||||
: DesertDustTint;
|
||||
|
||||
private System.Numerics.Vector3? ResolveLiveWalkerFootWorld(bool isContender, int id, int legIndex)
|
||||
{
|
||||
VehicleVisualInstance? vis = isContender
|
||||
|
|
@ -874,7 +907,7 @@ public partial class Main : Node3D
|
|||
GD.Print($"UpdateCameraMs/frame: avg={_perfCamMsSum / _perfFrameMs.Count:F2}");
|
||||
int ticks = Math.Max(1, _perfPhysicsTicks);
|
||||
GD.Print($"StepBreakdownMs/tick: ring={ArenaSession.PerfRingMs / ticks:F2} ai={ArenaSession.PerfAiMs / ticks:F2} drive={ArenaSession.PerfDriveMs / ticks:F2} world={ArenaSession.PerfWorldMs / ticks:F2} sync={ArenaSession.PerfBodySyncMs / ticks:F2} detect={ArenaSession.PerfDetectMs / ticks:F2} weapons={ArenaSession.PerfWeaponsMs / ticks:F2}");
|
||||
GD.Print($"CombatProbes: syncDamageHeatMsTotal={VehicleVisualInstance.PerfDamageHeatMs:F2} matDups={VehicleVisualInstance.PerfMaterialDupCount} bakeTileMsTotal={TerrainRenderer.PerfBakeTileMs:F2} bakeTileCalls={TerrainRenderer.PerfBakeTileCalls} debrisActive={_arena.Debris.ActiveCount} tracers={_session?.ViewState.Tracers.Count ?? 0}");
|
||||
GD.Print($"CombatProbes: syncDamageHeatMsTotal={VehicleVisualInstance.PerfDamageHeatMs:F2} matDups={VehicleVisualInstance.PerfMaterialDupCount} bakeTileMsTotal={TerrainRenderer.PerfBakeTileMs:F2} bakeTileCalls={TerrainRenderer.PerfBakeTileCalls} debrisActive={_arena.Debris.ActiveCount} particlesActive={_arena.Particles.ActiveParticleCount} flashLightsPeak={_arena.Particles.PeakFlashLightCount} tracers={_session?.ViewState.Tracers.Count ?? 0}");
|
||||
if (_session is not null)
|
||||
{
|
||||
var net = _session.ConnectionStatus;
|
||||
|
|
@ -1005,8 +1038,12 @@ public partial class Main : Node3D
|
|||
}
|
||||
|
||||
Vector2 center = screenSize * 0.5f;
|
||||
Vector3 rayOrigin = _camera.ProjectRayOrigin(center);
|
||||
Vector3 rayDir = _camera.ProjectRayNormal(center);
|
||||
Vector3 rayOrigin = _hasBaseCamPose
|
||||
? _baseCamPos + _baseLookDir * _camera.Near
|
||||
: _camera.ProjectRayOrigin(center);
|
||||
Vector3 rayDir = _hasBaseCamPose
|
||||
? _baseLookDir
|
||||
: _camera.ProjectRayNormal(center);
|
||||
|
||||
const float maxAimDist = 450f;
|
||||
ulong playerStableId = ContenderStableIdBase + (ulong)player.Id;
|
||||
|
|
@ -1161,8 +1198,72 @@ public partial class Main : Node3D
|
|||
}
|
||||
}
|
||||
|
||||
_camera.GlobalPosition = camPos;
|
||||
_camera.LookAt(camPos + lookDir * 60f, Vector3.Up);
|
||||
_baseCamPos = camPos;
|
||||
_baseLookDir = lookDir;
|
||||
_hasBaseCamPose = true;
|
||||
|
||||
float targetFov = CameraJuiceState.BaseFovDeg + _camJuice.FovOffsetDeg;
|
||||
if (MathF.Abs(_camera.Fov - targetFov) > 0.005f)
|
||||
{
|
||||
_camera.Fov = targetFov;
|
||||
}
|
||||
|
||||
if (_camJuice.IsIdle)
|
||||
{
|
||||
_camera.GlobalPosition = camPos;
|
||||
_camera.LookAt(camPos + lookDir * 60f, Vector3.Up);
|
||||
return;
|
||||
}
|
||||
|
||||
_camJuice.ComputeOffsets(
|
||||
out System.Numerics.Vector3 jOff,
|
||||
out float pitchOffRad,
|
||||
out float yawOffRad,
|
||||
out float rollOffRad);
|
||||
|
||||
Vector3 juicedCamPos = camPos
|
||||
+ camRight * jOff.X
|
||||
+ Vector3.Up * jOff.Y
|
||||
- lookDir * jOff.Z;
|
||||
|
||||
Vector3 juiceDelta = juicedCamPos - camPos;
|
||||
float juiceDist = juiceDelta.Length();
|
||||
if (juiceDist > 0.02f)
|
||||
{
|
||||
Vector3 juiceDir = juiceDelta / juiceDist;
|
||||
if (CastStaticCameraRay(camPos, juiceDir, juiceDist, out float juiceHitDist))
|
||||
{
|
||||
juicedCamPos = camPos + juiceDir * SafeCameraPullbackDist(juiceHitDist);
|
||||
}
|
||||
}
|
||||
|
||||
float minJuicedY = Session.ViewState.Terrain.SampleHeight(juicedCamPos.X, juicedCamPos.Z) + 1.15f;
|
||||
if (juicedCamPos.Y < minJuicedY)
|
||||
{
|
||||
juicedCamPos.Y = minJuicedY;
|
||||
}
|
||||
|
||||
Vector3 juicedLookDir = lookDir;
|
||||
if (MathF.Abs(yawOffRad) > 1e-6f)
|
||||
{
|
||||
juicedLookDir = juicedLookDir.Rotated(Vector3.Up, yawOffRad);
|
||||
}
|
||||
if (MathF.Abs(pitchOffRad) > 1e-6f)
|
||||
{
|
||||
Vector3 pitchAxis = Vector3.Up.Cross(juicedLookDir);
|
||||
if (pitchAxis.LengthSquared() > 1e-6f)
|
||||
{
|
||||
juicedLookDir = juicedLookDir.Rotated(pitchAxis.Normalized(), pitchOffRad);
|
||||
}
|
||||
}
|
||||
juicedLookDir = juicedLookDir.Normalized();
|
||||
|
||||
Vector3 camUp = MathF.Abs(rollOffRad) > 1e-6f
|
||||
? Vector3.Up.Rotated(juicedLookDir, rollOffRad)
|
||||
: Vector3.Up;
|
||||
|
||||
_camera.GlobalPosition = juicedCamPos;
|
||||
_camera.LookAt(juicedCamPos + juicedLookDir * 60f, camUp);
|
||||
}
|
||||
|
||||
private static float SafeCameraPullbackDist(float rawDist) =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue