Cut 5d-2: ParticlePool + OmniLight3D[4], CameraJuiceState, Hud hit-markers & vignette, unified SimEvent drain

This commit is contained in:
Meta Vens 2026-12-05 10:14:54 +01:00
commit 323c02cf8d
12 changed files with 2294 additions and 320 deletions

View file

@ -76,6 +76,7 @@ public partial class ArenaRenderer : Node3D
private MultiMeshPartPool _partPool = null!;
private PomDecalPool _pomDecals = null!;
private DebrisSystem _debris = null!;
private ParticlePool _particles = null!;
private MeshInstance3D _safeRingMesh = null!;
private ImmediateMesh _safeRingImm = null!;
@ -85,7 +86,7 @@ public partial class ArenaRenderer : Node3D
private MultiMesh _dropPillarMm = null!;
private MultiMeshInstance3D _dropPillarMmi = null!;
// Pooled weapon VFX MultiMeshes
// Pooled weapon VFX MultiMeshes (beams/tracers, explosive detonation cores, shockwave rings)
private ShaderMaterial _vfxMat = null!;
private MultiMesh _vfxBeamMm = null!;
private MultiMeshInstance3D _vfxBeamMmi = null!;
@ -93,10 +94,14 @@ public partial class ArenaRenderer : Node3D
private MultiMeshInstance3D _vfxSphereMmi = null!;
private MultiMesh _vfxRingMm = null!;
private MultiMeshInstance3D _vfxRingMmi = null!;
private readonly List<TransientVfx> _transientVfx = new(256);
private long _lastVfxHitId;
private int _lastSpawnedTracerId;
private uint _vfxRng = 0x51F15A3Du;
private readonly List<TransientVfx> _transientVfx = new(128);
private int _activeBeamCount;
// Continuous emitter rate limiters (keyed by (IsContender, EntityId))
private readonly Dictionary<(bool IsContender, int Id), float> _tireDustNextTime = new();
private readonly Dictionary<(bool IsContender, int Id), float> _thermalVentNextTime = new();
private readonly Dictionary<(bool IsContender, int Id), float> _damageSmokeNextTime = new();
private float _vfxClock;
private readonly Dictionary<int, ActorVisual> _contenderVisuals = new();
private readonly Dictionary<int, ActorVisual> _spectatorVisuals = new();
@ -111,6 +116,7 @@ public partial class ArenaRenderer : Node3D
public VehicleAssetCache AssetCache => _assetCache;
public DebrisSystem Debris => _debris;
public ParticlePool Particles => _particles;
internal MultiMeshPartPool PartPool => _partPool;
internal PomDecalPool PomDecals => _pomDecals;
@ -126,7 +132,6 @@ public partial class ArenaRenderer : Node3D
: null;
internal int ActiveDropVisualCount => _dropVisuals.Count;
internal int LastSpawnedTracerId => _lastSpawnedTracerId;
internal int TransientVfxCount => _transientVfx.Count;
internal bool TryGetChassisDropVisual(int dropId, out VehicleVisualInstance? visual, out float baseY)
@ -151,11 +156,13 @@ public partial class ArenaRenderer : Node3D
_partPool = new MultiMeshPartPool { Name = "PartPool" };
_pomDecals = new PomDecalPool { Name = "PomDecals" };
_debris = new DebrisSystem { Name = "Debris" };
_particles = new ParticlePool { Name = "ParticlePool" };
AddChild(_staticGroup);
AddChild(_actorsGroup);
AddChild(_partPool);
AddChild(_pomDecals);
AddChild(_debris);
AddChild(_particles);
_coverMat = new StandardMaterial3D { AlbedoColor = CoverRust, Roughness = 0.88f, Metallic = 0.25f };
_bermMat = new StandardMaterial3D { AlbedoColor = BermDark, Roughness = 0.94f, Metallic = 0.1f };
@ -341,8 +348,37 @@ public partial class ArenaRenderer : Node3D
_debris.SubmitToPool(_partPool);
_partPool.EndFrame();
_pomDecals.Sync(session, dt, ResolveEntityVisual);
SyncWeaponVfx(state, dt);
SyncTracerBeams(state);
}
public void ConsumeEvents(
IClientArenaSession session,
IReadOnlyList<ISimEvent> events,
IReadOnlyList<FootstepPulse> footsteps,
float dt,
Func<float, float, Color> sampleGroundTint)
{
Camera3D? cam = GetViewport()?.GetCamera3D();
bool hasCam = cam is not null && cam.IsInsideTree();
Vector3 camPos = hasCam ? cam!.GlobalPosition : Vector3.Zero;
float stepDt = float.IsFinite(dt) && dt > 0f ? Math.Clamp(dt, 0f, 0.05f) : 0f;
_vfxClock += stepDt;
var state = session.ViewState;
_pomDecals.ConsumeEvents(session, events, stepDt, ResolveEntityVisual);
_particles.ConsumeEvents(events, state, camPos, hasCam, sampleGroundTint);
for (int i = 0; i < footsteps.Count; i++)
{
FootstepPulse pulse = footsteps[i];
Color gTint = sampleGroundTint(pulse.WorldPos.X, pulse.WorldPos.Z);
_particles.EmitFootstepDust(in pulse, gTint, camPos, hasCam);
}
EmitContinuousActorParticles(session, hasCam, camPos, sampleGroundTint);
UpdateExplosiveRingsAndCores(events, stepDt);
_particles.AdvanceAndCommit(stepDt);
}
private VehicleVisualInstance? ResolveEntityVisual(bool isContender, int id) =>
@ -431,9 +467,28 @@ public partial class ArenaRenderer : Node3D
_partPool.ClearAll();
_pomDecals.ClearAll();
_debris.ClearAll();
_particles.ClearAll();
_transientVfx.Clear();
_lastVfxHitId = 0;
_lastSpawnedTracerId = 0;
_tireDustNextTime.Clear();
_thermalVentNextTime.Clear();
_damageSmokeNextTime.Clear();
_vfxClock = 0f;
_activeBeamCount = 0;
if (_vfxBeamMm is not null)
{
_vfxBeamMm.VisibleInstanceCount = 0;
_vfxBeamMmi.Visible = false;
}
if (_vfxSphereMm is not null)
{
_vfxSphereMm.VisibleInstanceCount = 0;
_vfxSphereMmi.Visible = false;
}
if (_vfxRingMm is not null)
{
_vfxRingMm.VisibleInstanceCount = 0;
_vfxRingMmi.Visible = false;
}
_contenderVisuals.Clear();
_spectatorVisuals.Clear();
foreach (var kv in _dropVisuals)
@ -950,52 +1005,13 @@ public partial class ArenaRenderer : Node3D
_dropPillarMmi.Visible = pillarCount > 0;
}
private void SyncWeaponVfx(MatchState state, float dt)
private void SyncTracerBeams(MatchState state)
{
float stepDt = float.IsFinite(dt) && dt > 0f ? Math.Clamp(dt, 0f, 0.05f) : 0f;
// 1. Advance existing transient bursts (sparks, muzzle flashes, flak puffs, detonations, shockwaves)
for (int i = _transientVfx.Count - 1; i >= 0; i--)
{
TransientVfx v = _transientVfx[i];
v.Age += stepDt;
if (v.Age >= v.Lifetime)
{
_transientVfx.RemoveAt(i);
continue;
}
v.Position += v.Velocity * stepDt;
_transientVfx[i] = v;
}
// 2. Spawn impact VFX once per HitFeedbackEvent
var hits = state.HitEvents;
for (int i = 0; i < hits.Count; i++)
{
var ev = hits[i];
if (ev.EventId <= _lastVfxHitId)
{
continue;
}
_lastVfxHitId = ev.EventId;
SpawnHitVfx(in ev);
}
// 3. Emit pooled beams/tracers + new-shot muzzle/smoke puffs from active TracerEvents
int beamIdx = 0;
int sphereIdx = 0;
int ringIdx = 0;
var tracers = state.Tracers;
for (int i = 0; i < tracers.Count; i++)
{
var t = tracers[i];
bool isNewShot = t.Id > _lastSpawnedTracerId;
if (isNewShot)
{
_lastSpawnedTracerId = t.Id;
}
Vector3 start = new(t.StartX, t.StartY, t.StartZ);
Vector3 end = new(t.EndX, t.EndY, t.EndZ);
Vector3 delta = end - start;
@ -1019,22 +1035,13 @@ public partial class ArenaRenderer : Node3D
? new Color(2.8f, 1.35f, 0.35f, 0.94f)
: new Color(2.6f, 2.35f, 1.15f, 0.92f);
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(isPd ? 0.09f : 0.06f, isPd ? 0.09f : 0.06f, dist), col);
if (isNewShot)
{
EmitMuzzleFlash(start, 0.32f, new Color(2.8f, 2.0f, 0.7f, 0.95f));
}
break;
}
case WeaponVisualClass.Autocannon:
{
// Thick dual-tone amber-orange heavy bolt (outer jacket + bright core)
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(0.20f, 0.20f, dist), new Color(2.5f, 0.85f, 0.14f, 0.72f));
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(0.08f, 0.08f, dist), new Color(3.6f, 2.7f, 1.3f, 0.98f));
if (isNewShot)
{
EmitMuzzleFlash(start, 0.68f, new Color(3.2f, 1.65f, 0.35f, 0.98f));
}
break;
}
@ -1043,29 +1050,6 @@ public partial class ArenaRenderer : Node3D
bool isRecoilless = string.Equals(t.WeaponId, "recoilless", StringComparison.Ordinal);
float w = isRecoilless ? 0.22f : 0.12f;
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(w, w, dist), new Color(3.2f, 1.25f, 0.25f, 0.96f));
if (isNewShot)
{
EmitMuzzleFlash(start, isRecoilless ? 1.15f : 0.58f, new Color(3.4f, 1.55f, 0.35f, 0.98f));
int puffs = isRecoilless ? 4 : 2;
for (int p = 1; p <= puffs; p++)
{
float frac = p / (float)(puffs + 1);
Vector3 smokePos = start.Lerp(end, frac);
AddTransient(new TransientVfx
{
Shape = VfxShape.Sphere,
Position = smokePos,
Velocity = new Vector3(0f, 1.4f, 0f),
BaseRotation = Basis.Identity,
StartScale = Vector3.One * (isRecoilless ? 0.45f : 0.28f),
EndScale = Vector3.One * (isRecoilless ? 1.55f : 0.85f),
ColorStart = new Color(0.62f, 0.56f, 0.48f, 0.65f),
ColorEnd = new Color(0.45f, 0.40f, 0.36f, 0.0f),
Age = 0f,
Lifetime = isRecoilless ? 0.48f : 0.32f
});
}
}
break;
}
@ -1082,16 +1066,85 @@ public partial class ArenaRenderer : Node3D
: new Color(2.4f, 3.4f, 3.8f, 0.98f);
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(outerW, outerW, dist), outerCol);
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(coreW, coreW, dist), coreCol);
if (isNewShot)
{
EmitMuzzleFlash(start, isLance ? 0.85f : 0.52f, outerCol with { A = 0.95f });
}
break;
}
}
}
// 4. Write active transient VFX into MultiMesh buffers
_activeBeamCount = beamIdx;
_vfxBeamMm.VisibleInstanceCount = beamIdx;
_vfxBeamMmi.Visible = beamIdx > 0;
}
private void UpdateExplosiveRingsAndCores(IReadOnlyList<ISimEvent> events, float stepDt)
{
for (int i = _transientVfx.Count - 1; i >= 0; i--)
{
TransientVfx v = _transientVfx[i];
v.Age += stepDt;
if (v.Age >= v.Lifetime)
{
_transientVfx.RemoveAt(i);
continue;
}
v.Position += v.Velocity * stepDt;
_transientVfx[i] = v;
}
for (int i = 0; i < events.Count; i++)
{
if (events[i] is not HitImpactEvent ev)
{
continue;
}
if ((WeaponVisualClass)ev.WeaponClass != WeaponVisualClass.Explosive || ev.IsAirburst)
{
continue;
}
Vector3 pos = new(ev.HitX, ev.HitY, ev.HitZ);
Vector3 normal = new(ev.NormalX, ev.NormalY, ev.NormalZ);
if (normal.LengthSquared() < 1e-4f) normal = Vector3.Up;
normal = normal.Normalized();
bool isRecoilless = string.Equals(ev.WeaponId, "recoilless", StringComparison.Ordinal);
float detSize = isRecoilless ? 3.2f : 1.7f;
float ringSize = isRecoilless ? 6.2f : 2.9f;
AddTransient(new TransientVfx
{
Shape = VfxShape.Sphere,
Position = pos + normal * 0.25f,
Velocity = normal * 1.4f,
BaseRotation = Basis.Identity,
StartScale = Vector3.One * 0.5f,
EndScale = Vector3.One * detSize,
ColorStart = new Color(3.6f, 2.0f, 0.55f, 0.92f),
ColorEnd = new Color(0.85f, 0.28f, 0.08f, 0.0f),
Age = 0f,
Lifetime = isRecoilless ? 0.28f : 0.20f
});
Vector3 upRef = MathF.Abs(normal.Y) > 0.92f ? Vector3.Forward : Vector3.Up;
Vector3 right = upRef.Cross(normal).Normalized();
Vector3 fwd = normal.Cross(right).Normalized();
Basis ringBasis = new(right, normal, fwd);
AddTransient(new TransientVfx
{
Shape = VfxShape.Ring,
Position = pos + normal * 0.18f,
Velocity = Vector3.Zero,
BaseRotation = ringBasis,
StartScale = new Vector3(0.7f, 1.0f, 0.7f),
EndScale = new Vector3(ringSize, 0.4f, ringSize),
ColorStart = new Color(3.2f, 1.65f, 0.45f, 0.92f),
ColorEnd = new Color(1.4f, 0.55f, 0.20f, 0.0f),
Age = 0f,
Lifetime = isRecoilless ? 0.32f : 0.22f
});
}
int sphereIdx = 0;
int ringIdx = 0;
for (int i = 0; i < _transientVfx.Count; i++)
{
TransientVfx v = _transientVfx[i];
@ -1100,13 +1153,7 @@ public partial class ArenaRenderer : Node3D
Color col = v.ColorStart.Lerp(v.ColorEnd, frac);
Transform3D xf = new(v.BaseRotation * Basis.FromScale(sc), v.Position);
if (v.Shape == VfxShape.Beam && beamIdx < MaxVfxBeams)
{
_vfxBeamMm.SetInstanceTransform(beamIdx, xf);
_vfxBeamMm.SetInstanceCustomData(beamIdx, col);
beamIdx++;
}
else if (v.Shape == VfxShape.Sphere && sphereIdx < MaxVfxSpheres)
if (v.Shape == VfxShape.Sphere && sphereIdx < MaxVfxSpheres)
{
_vfxSphereMm.SetInstanceTransform(sphereIdx, xf);
_vfxSphereMm.SetInstanceCustomData(sphereIdx, col);
@ -1120,161 +1167,148 @@ public partial class ArenaRenderer : Node3D
}
}
_vfxBeamMm.VisibleInstanceCount = beamIdx;
_vfxBeamMmi.Visible = beamIdx > 0;
_vfxSphereMm.VisibleInstanceCount = sphereIdx;
_vfxSphereMmi.Visible = sphereIdx > 0;
_vfxRingMm.VisibleInstanceCount = ringIdx;
_vfxRingMmi.Visible = ringIdx > 0;
}
private void SpawnHitVfx(in HitFeedbackEvent ev)
private void EmitContinuousActorParticles(
IClientArenaSession session,
bool hasCam,
Vector3 camPos,
Func<float, float, Color> sampleGroundTint)
{
Vector3 pos = new(ev.HitX, ev.HitY, ev.HitZ);
Vector3 normal = new(ev.NormalX, ev.NormalY, ev.NormalZ);
if (normal.LengthSquared() < 1e-4f) normal = Vector3.Up;
normal = normal.Normalized();
if (ev.IsAirburst || (ev.WeaponClass == WeaponVisualClass.KineticLight && string.Equals(ev.WeaponId, "pd_flak", StringComparison.Ordinal)))
var state = session.ViewState;
var contenders = state.Contenders;
for (int i = 0; i < contenders.Count; i++)
{
// Crisp dark-orange flak airburst puff + ember sparks
AddTransient(new TransientVfx
var c = contenders[i];
if (!c.Alive || !session.IsContenderVisible(c.Id))
{
Shape = VfxShape.Sphere,
Position = pos,
Velocity = Vector3.Zero,
BaseRotation = Basis.Identity,
StartScale = Vector3.One * 0.4f,
EndScale = Vector3.One * 2.3f,
ColorStart = new Color(2.4f, 0.72f, 0.14f, 0.92f),
ColorEnd = new Color(0.28f, 0.14f, 0.08f, 0.0f),
Age = 0f,
Lifetime = 0.28f
});
SpawnSparkBurst(pos, normal, 4, new Color(3.0f, 1.5f, 0.35f, 0.98f), 11f);
return;
}
switch (ev.WeaponClass)
{
case WeaponVisualClass.KineticLight:
SpawnSparkBurst(pos, normal, 3, new Color(3.2f, 2.6f, 1.1f, 0.98f), 9f);
break;
case WeaponVisualClass.Autocannon:
AddTransient(new TransientVfx
{
Shape = VfxShape.Sphere,
Position = pos + normal * 0.15f,
Velocity = normal * 2.2f,
BaseRotation = Basis.Identity,
StartScale = Vector3.One * 0.45f,
EndScale = Vector3.One * 1.55f,
ColorStart = new Color(1.5f, 0.95f, 0.55f, 0.85f),
ColorEnd = new Color(0.55f, 0.48f, 0.38f, 0.0f),
Age = 0f,
Lifetime = 0.26f
});
SpawnSparkBurst(pos, normal, 4, new Color(3.2f, 1.85f, 0.55f, 0.98f), 12f);
break;
case WeaponVisualClass.Explosive:
{
bool isRecoilless = string.Equals(ev.WeaponId, "recoilless", StringComparison.Ordinal);
float detSize = isRecoilless ? 4.4f : 2.1f;
float ringSize = isRecoilless ? 6.2f : 2.9f;
AddTransient(new TransientVfx
{
Shape = VfxShape.Sphere,
Position = pos + normal * 0.25f,
Velocity = normal * 1.6f,
BaseRotation = Basis.Identity,
StartScale = Vector3.One * 0.6f,
EndScale = Vector3.One * detSize,
ColorStart = new Color(3.8f, 2.1f, 0.65f, 0.98f),
ColorEnd = new Color(0.85f, 0.28f, 0.08f, 0.0f),
Age = 0f,
Lifetime = isRecoilless ? 0.34f : 0.24f
});
Vector3 upRef = MathF.Abs(normal.Y) > 0.92f ? Vector3.Forward : Vector3.Up;
Vector3 right = upRef.Cross(normal).Normalized();
Vector3 fwd = normal.Cross(right).Normalized();
Basis ringBasis = new(right, normal, fwd);
AddTransient(new TransientVfx
{
Shape = VfxShape.Ring,
Position = pos + normal * 0.18f,
Velocity = Vector3.Zero,
BaseRotation = ringBasis,
StartScale = new Vector3(0.7f, 1.0f, 0.7f),
EndScale = new Vector3(ringSize, 0.4f, ringSize),
ColorStart = new Color(3.2f, 1.65f, 0.45f, 0.92f),
ColorEnd = new Color(1.4f, 0.55f, 0.20f, 0.0f),
Age = 0f,
Lifetime = isRecoilless ? 0.32f : 0.22f
});
SpawnSparkBurst(pos, normal, isRecoilless ? 6 : 4, new Color(3.4f, 1.6f, 0.35f, 0.98f), 15f);
break;
continue;
}
case WeaponVisualClass.ThermalBeam:
AddTransient(new TransientVfx
{
Shape = VfxShape.Sphere,
Position = pos,
Velocity = Vector3.Zero,
BaseRotation = Basis.Identity,
StartScale = Vector3.One * 0.45f,
EndScale = Vector3.One * 1.65f,
ColorStart = new Color(1.6f, 3.4f, 3.8f, 0.95f),
ColorEnd = new Color(2.6f, 1.5f, 0.3f, 0.0f),
Age = 0f,
Lifetime = 0.22f
});
SpawnSparkBurst(pos, normal, 5, new Color(2.0f, 3.2f, 3.6f, 0.98f), 13f);
break;
}
}
private void SpawnSparkBurst(Vector3 pos, Vector3 normal, int count, Color color, float speed)
{
for (int i = 0; i < count; i++)
{
Vector3 rand = new(NextVfxSigned(), MathF.Abs(NextVfxSigned()) + 0.35f, NextVfxSigned());
Vector3 dir = (normal * 0.8f + rand).Normalized();
Vector3 up = MathF.Abs(dir.Dot(Vector3.Up)) > 0.95f ? Vector3.Right : Vector3.Up;
AddTransient(new TransientVfx
Vector3 pos = _contenderVisuals.TryGetValue(c.Id, out var av)
? av.Visual.Root.GlobalPosition
: new Vector3(c.X, c.Y, c.Z);
if (hasCam && pos.DistanceSquaredTo(camPos) > 125f * 125f)
{
Shape = VfxShape.Beam,
Position = pos,
Velocity = dir * (speed * (0.65f + 0.7f * NextVfxFloat())),
BaseRotation = Basis.LookingAt(dir, up),
StartScale = new Vector3(0.05f, 0.05f, 0.55f),
EndScale = new Vector3(0.02f, 0.02f, 0.12f),
ColorStart = color,
ColorEnd = color with { A = 0f },
Age = 0f,
Lifetime = 0.16f + 0.08f * NextVfxFloat()
});
continue;
}
var key = (true, c.Id);
float coreHpRatio = c.Grid.MaxCoreHp > 0f ? c.Grid.CoreHp / c.Grid.MaxCoreHp : 1f;
float thermalRatio = c.MaxThermalRatio > 0f ? c.MaxThermalRatio : c.Grid.ComputeMaxThermalRatio();
if ((c.Grid.Spec.Mobility == MobilityKind.Wheeled || c.Grid.Spec.Mobility == MobilityKind.Tracked) &&
c.Speed > 8.5f)
{
float nextDust = _tireDustNextTime.GetValueOrDefault(key);
if (_vfxClock >= nextDust)
{
_tireDustNextTime[key] = _vfxClock + 0.07f; // ~14 Hz
float sinY = MathF.Sin(c.Yaw);
float cosY = MathF.Cos(c.Yaw);
Vector3 rearPos = pos - new Vector3(sinY, 0f, cosY) * (c.Grid.Spec.HalfLength * 0.72f);
rearPos.Y = state.Terrain.SampleHeight(rearPos.X, rearPos.Z) + 0.12f;
Vector3 vel = new(c.VelX, 0f, c.VelZ);
_particles.EmitTireDust(
rearPos,
vel,
sampleGroundTint(rearPos.X, rearPos.Z),
Math.Clamp(c.Speed / 16f, 0.7f, 1.35f),
camPos,
hasCam);
}
}
if (thermalRatio >= 0.85f)
{
float nextVent = _thermalVentNextTime.GetValueOrDefault(key);
if (_vfxClock >= nextVent)
{
_thermalVentNextTime[key] = _vfxClock + 0.10f; // 10 Hz
Vector3 ventPos = ResolveHotAnchorWorld(av?.Visual, c.Grid, pos, c.Grid.Spec.HalfHeight);
_particles.EmitThermalVent(ventPos, thermalRatio, camPos, hasCam);
}
}
if (coreHpRatio < 0.35f)
{
float nextSmoke = _damageSmokeNextTime.GetValueOrDefault(key);
if (_vfxClock >= nextSmoke)
{
_damageSmokeNextTime[key] = _vfxClock + 0.10f; // 10 Hz
Vector3 dmgPos = pos + new Vector3(0f, c.Grid.Spec.HalfHeight * 0.6f, 0f);
_particles.EmitDamageSmokeAndFire(dmgPos, coreHpRatio, camPos, hasCam);
}
}
}
var specs = state.Spectators.Spectators;
for (int i = 0; i < specs.Count; i++)
{
var s = specs[i];
if (!s.Alive || !session.IsSpectatorVisible(s.Id))
{
continue;
}
Vector3 pos = _spectatorVisuals.TryGetValue(s.Id, out var av)
? av.Visual.Root.GlobalPosition
: new Vector3(s.X, s.Y, s.Z);
if (hasCam && pos.DistanceSquaredTo(camPos) > 125f * 125f)
{
continue;
}
var key = (false, s.Id);
float coreHpRatio = s.Grid.MaxCoreHp > 0f ? s.Grid.CoreHp / s.Grid.MaxCoreHp : 1f;
float thermalRatio = s.Grid.ComputeMaxThermalRatio();
if (thermalRatio >= 0.85f)
{
float nextVent = _thermalVentNextTime.GetValueOrDefault(key);
if (_vfxClock >= nextVent)
{
_thermalVentNextTime[key] = _vfxClock + 0.11f;
Vector3 ventPos = ResolveHotAnchorWorld(av?.Visual, s.Grid, pos, s.Grid.Spec.HalfHeight);
_particles.EmitThermalVent(ventPos, thermalRatio, camPos, hasCam);
}
}
if (coreHpRatio < 0.35f)
{
float nextSmoke = _damageSmokeNextTime.GetValueOrDefault(key);
if (_vfxClock >= nextSmoke)
{
_damageSmokeNextTime[key] = _vfxClock + 0.11f;
Vector3 dmgPos = pos + new Vector3(0f, s.Grid.Spec.HalfHeight * 0.6f, 0f);
_particles.EmitDamageSmokeAndFire(dmgPos, coreHpRatio, camPos, hasCam);
}
}
}
}
private void EmitMuzzleFlash(Vector3 pos, float size, Color color)
private static Vector3 ResolveHotAnchorWorld(VehicleVisualInstance? vis, ChassisGrid grid, Vector3 fallbackPos, float halfHeight)
{
AddTransient(new TransientVfx
if (vis is not null && !vis.IsStaticLod)
{
Shape = VfxShape.Sphere,
Position = pos,
Velocity = Vector3.Zero,
BaseRotation = Basis.Identity,
StartScale = Vector3.One * size,
EndScale = Vector3.One * (size * 0.25f),
ColorStart = color,
ColorEnd = color with { A = 0f },
Age = 0f,
Lifetime = 0.065f
});
var hps = grid.Spec.Hardpoints;
for (int i = 0; i < hps.Length; i++)
{
if (hps[i].Kind == HardpointKind.Radiator || hps[i].Kind == HardpointKind.Engine)
{
Node3D? anchor = vis.GetHardpointAnchorNode(hps[i].Id);
if (anchor is not null && GodotObject.IsInstanceValid(anchor) && anchor.IsInsideTree())
{
return anchor.GlobalPosition;
}
}
}
}
return fallbackPos + new Vector3(0f, halfHeight * 0.7f, 0f);
}
private void EmitBeam(ref int beamIdx, Basis lookBasis, Vector3 mid, Vector3 scale, Color color)
@ -1290,25 +1324,13 @@ public partial class ArenaRenderer : Node3D
private void AddTransient(in TransientVfx vfx)
{
if (_transientVfx.Count >= 512)
if (_transientVfx.Count >= 256)
{
_transientVfx.RemoveAt(0);
}
_transientVfx.Add(vfx);
}
private float NextVfxFloat()
{
uint x = _vfxRng;
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
_vfxRng = x;
return (x & 0x00FFFFFFu) / 16777216f;
}
private float NextVfxSigned() => NextVfxFloat() * 2f - 1f;
private static void ClearChildren(Node parent)
{
for (int i = parent.GetChildCount() - 1; i >= 0; i--)