Cut 7b: 16 modular Brokkr weapon parts, mfg paint bands 10..14, ClientOrdnanceMirror, audio & tooltips
This commit is contained in:
parent
6f6bfe3c46
commit
6447155efb
27 changed files with 2420 additions and 74 deletions
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
|
|
@ -102,6 +103,7 @@ public partial class ArenaAudioSystem : Node3D
|
|||
|
||||
private readonly Dictionary<(bool IsSpectator, int ShooterId, string WeaponId), float> _shotDedupeExpiry = new();
|
||||
private readonly Dictionary<(byte TargetKind, int TargetId), float> _impactDedupeExpiry = new();
|
||||
private readonly Dictionary<(byte Kind, int ShooterId, byte NodeIdx), float> _ordnanceDedupeExpiry = new();
|
||||
private readonly Dictionary<int, string> _lastContenderChassis = new();
|
||||
private readonly Dictionary<int, int> _lastContenderLoadoutVer = new();
|
||||
private readonly List<(float X, float Z, float Expiry)> _recentExplosionPoints = new(16);
|
||||
|
|
@ -292,6 +294,7 @@ public partial class ArenaAudioSystem : Node3D
|
|||
|
||||
_shotDedupeExpiry.Clear();
|
||||
_impactDedupeExpiry.Clear();
|
||||
_ordnanceDedupeExpiry.Clear();
|
||||
_lastContenderChassis.Clear();
|
||||
_lastContenderLoadoutVer.Clear();
|
||||
_recentExplosionPoints.Clear();
|
||||
|
|
@ -489,6 +492,10 @@ public partial class ArenaAudioSystem : Node3D
|
|||
case DropPodEvent dpe:
|
||||
HandleDropPodEvent(dpe, localId, listenerPos);
|
||||
break;
|
||||
|
||||
case OrdnanceNodeEvent ord:
|
||||
HandleOrdnanceNodeEvent(ord, localId, listenerPos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -771,6 +778,108 @@ public partial class ArenaAudioSystem : Node3D
|
|||
}
|
||||
}
|
||||
|
||||
private void HandleOrdnanceNodeEvent(OrdnanceNodeEvent ord, int localId, Vector3 listenerPos)
|
||||
{
|
||||
var dedupeKey = (ord.Kind, ord.ShooterId, ord.NodeDefIndex);
|
||||
if (_ordnanceDedupeExpiry.TryGetValue(dedupeKey, out float expiry) && _audioTime < expiry)
|
||||
{
|
||||
DedupedCount++;
|
||||
return;
|
||||
}
|
||||
_ordnanceDedupeExpiry[dedupeKey] = _audioTime + 0.065f;
|
||||
PruneExpiredMap(_ordnanceDedupeExpiry);
|
||||
|
||||
OrdnanceNodeDef? def = null;
|
||||
if (ord.WeaponKey is { } wk)
|
||||
{
|
||||
var spec = ProceduralWeaponGenerator.Generate(wk);
|
||||
def = ord.NodeDefIndex < spec.FlattenedNodes.Length ? spec.FlattenedNodes[ord.NodeDefIndex] : spec.RootNode;
|
||||
}
|
||||
|
||||
var kind = (OrdnanceEventKind)ord.Kind;
|
||||
bool isLocal = !ord.IsSpectatorShooter && ord.ShooterId == localId;
|
||||
Vector3 pos = new(ord.PosX, ord.PosY, ord.PosZ);
|
||||
float distSq = pos.DistanceSquaredTo(listenerPos);
|
||||
int priority = isLocal
|
||||
? PriorityLocalAction
|
||||
: (distSq <= 90f * 90f ? PriorityNearCombat : PriorityDistantCombat);
|
||||
|
||||
string? clipKey = null;
|
||||
float volDb = isLocal ? -2.0f : -4.2f;
|
||||
float pitch = NextPitchJitter(0.94f, 1.06f);
|
||||
uint v = _variantCounter++;
|
||||
|
||||
switch (kind)
|
||||
{
|
||||
case OrdnanceEventKind.Spawned:
|
||||
if (ord.ParentOrdnanceId != 0)
|
||||
{
|
||||
return; // Split event already provides audio cue
|
||||
}
|
||||
clipKey = SelectAudioClassClip(def?.AudioClass ?? OrdnanceAudioClass.RocketSalvo, v);
|
||||
break;
|
||||
|
||||
case OrdnanceEventKind.StageTransition:
|
||||
if (def?.Motion is OrdnanceMotion.RocketBoosted or OrdnanceMotion.HomingMissile)
|
||||
{
|
||||
clipKey = (v & 1) == 0 ? "rocket_salvo_01" : "rocket_salvo_02";
|
||||
volDb = isLocal ? -1.5f : -3.5f;
|
||||
}
|
||||
else if (def?.Motion == OrdnanceMotion.LoiterOrbit)
|
||||
{
|
||||
clipKey = "pd_laser";
|
||||
pitch = NextPitchJitter(1.12f, 1.24f);
|
||||
volDb = -5.5f;
|
||||
}
|
||||
else if (def?.Motion == OrdnanceMotion.StationaryMine)
|
||||
{
|
||||
clipKey = "mech_quick_bolt";
|
||||
pitch = NextPitchJitter(1.25f, 1.38f);
|
||||
volDb = -6.5f;
|
||||
}
|
||||
break;
|
||||
|
||||
case OrdnanceEventKind.Split:
|
||||
clipKey = (v & 1) == 0 ? "flak_blast_01" : "pod_petal_pop";
|
||||
volDb = isLocal ? -2.5f : -4.5f;
|
||||
break;
|
||||
|
||||
case OrdnanceEventKind.Detonated:
|
||||
if (def?.AudioClass == OrdnanceAudioClass.PlasmaPpc)
|
||||
{
|
||||
clipKey = "plasma_ppc_02";
|
||||
}
|
||||
else
|
||||
{
|
||||
clipKey = "impact_explosion";
|
||||
RecordExplosionPoint(pos.X, pos.Z);
|
||||
}
|
||||
volDb = isLocal ? -2.0f : -3.8f;
|
||||
break;
|
||||
|
||||
case OrdnanceEventKind.Intercepted:
|
||||
clipKey = "mech_eject";
|
||||
volDb = -5.5f;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(clipKey))
|
||||
{
|
||||
PlayOneShot3D(clipKey, pos, listenerPos, priority, volDb, pitch, isLocal, ord.ShooterId);
|
||||
}
|
||||
}
|
||||
|
||||
private static string SelectAudioClassClip(OrdnanceAudioClass audioClass, uint variant) => audioClass switch
|
||||
{
|
||||
OrdnanceAudioClass.CannonLight => (variant & 1) == 0 ? "ac_light_01" : "ac_light_02",
|
||||
OrdnanceAudioClass.CannonHeavy => (variant & 1) == 0 ? "cannon_heavy_01" : "cannon_heavy_02",
|
||||
OrdnanceAudioClass.RocketSalvo => (variant & 1) == 0 ? "rocket_salvo_01" : "rocket_salvo_02",
|
||||
OrdnanceAudioClass.LaserHeavy => "laser_heavy_01",
|
||||
OrdnanceAudioClass.GaussRail => "gauss_rail_01",
|
||||
OrdnanceAudioClass.PlasmaPpc => (variant & 1) == 0 ? "plasma_ppc_01" : "plasma_ppc_02",
|
||||
_ => "rocket_salvo_01"
|
||||
};
|
||||
|
||||
private void UpdateLoopSlots(IClientArenaSession session, Vector3 listenerPos, float alpha)
|
||||
{
|
||||
var state = session.ViewState;
|
||||
|
|
@ -1176,6 +1285,12 @@ public partial class ArenaAudioSystem : Node3D
|
|||
private string SelectWeaponClipKey(string? weaponId, WeaponVisualClass weaponClass)
|
||||
{
|
||||
uint v = _variantCounter++;
|
||||
if (ProceduralWeaponGenerator.TryParseId(weaponId, out ProceduralWeaponKey pKey))
|
||||
{
|
||||
var spec = ProceduralWeaponGenerator.Generate(pKey);
|
||||
return SelectAudioClassClip(spec.AudioClass, v);
|
||||
}
|
||||
|
||||
string id = (weaponId ?? string.Empty).ToLowerInvariant();
|
||||
return id switch
|
||||
{
|
||||
|
|
@ -1201,6 +1316,10 @@ public partial class ArenaAudioSystem : Node3D
|
|||
WeaponVisualClass.Autocannon => "ac_light_01",
|
||||
WeaponVisualClass.Explosive => "cannon_heavy_01",
|
||||
WeaponVisualClass.ThermalBeam => "lance_beam_01",
|
||||
WeaponVisualClass.GaussRail => "gauss_rail_01",
|
||||
WeaponVisualClass.PlasmaPpc => (v & 1) == 0 ? "plasma_ppc_01" : "plasma_ppc_02",
|
||||
WeaponVisualClass.RocketSalvo => (v & 1) == 0 ? "rocket_salvo_01" : "rocket_salvo_02",
|
||||
WeaponVisualClass.SwarmSmart => "pd_laser",
|
||||
_ => "mg_shot_01"
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ public partial class ArenaRenderer : Node3D
|
|||
{
|
||||
public VehicleVisualInstance? ChassisVisual;
|
||||
public ArrayMesh? GearMesh;
|
||||
public VehicleVisualInstance.ModularWeaponPartBinding[]? ModularParts;
|
||||
public float ManufacturerRoleIndex;
|
||||
public Color DropBeaconColor;
|
||||
public Vector3 GearScale;
|
||||
public float GearYOffset;
|
||||
public bool IsModule;
|
||||
|
|
@ -95,6 +98,9 @@ public partial class ArenaRenderer : Node3D
|
|||
private MultiMesh _vfxRingMm = null!;
|
||||
private MultiMeshInstance3D _vfxRingMmi = null!;
|
||||
private readonly List<TransientVfx> _transientVfx = new(128);
|
||||
private readonly ClientOrdnanceMirror _ordnanceMirror = new();
|
||||
private readonly List<(Transform3D Xf, Color Col)> _mirrorSpheres = new(64);
|
||||
private readonly List<(Transform3D Xf, Color Col)> _mirrorRings = new(128);
|
||||
private int _activeBeamCount;
|
||||
|
||||
// Continuous emitter rate limiters (keyed by (IsContender, EntityId))
|
||||
|
|
@ -122,6 +128,7 @@ public partial class ArenaRenderer : Node3D
|
|||
public ParticlePool Particles => _particles;
|
||||
internal MultiMeshPartPool PartPool => _partPool;
|
||||
internal PomDecalPool PomDecals => _pomDecals;
|
||||
internal ClientOrdnanceMirror OrdnanceMirror => _ordnanceMirror;
|
||||
|
||||
public VehicleVisualInstance? GetContenderVisual(int contenderId) =>
|
||||
_contenderVisuals.TryGetValue(contenderId, out var vis) ? vis.Visual : null;
|
||||
|
|
@ -348,6 +355,19 @@ public partial class ArenaRenderer : Node3D
|
|||
SyncSpectators(session, elapsedSeconds, dt, alpha, hasCam, camPos);
|
||||
SyncGroundDrops(state, elapsedSeconds, hasCam, camPos);
|
||||
SyncOrbitalPods(session, alpha, hasCam, camPos);
|
||||
_mirrorSpheres.Clear();
|
||||
_mirrorRings.Clear();
|
||||
_ordnanceMirror.StepAndSubmit(
|
||||
dt,
|
||||
session,
|
||||
_assetCache,
|
||||
_partPool,
|
||||
_particles,
|
||||
state.Terrain,
|
||||
hasCam,
|
||||
camPos,
|
||||
(xf, col) => _mirrorRings.Add((xf, col)),
|
||||
(xf, col) => _mirrorSpheres.Add((xf, col)));
|
||||
_debris.Step(dt, state.Terrain);
|
||||
_debris.SubmitToPool(_partPool);
|
||||
_partPool.EndFrame();
|
||||
|
|
@ -372,6 +392,26 @@ public partial class ArenaRenderer : Node3D
|
|||
var state = session.ViewState;
|
||||
_pomDecals.ConsumeEvents(session, events, stepDt, ResolveEntityVisual);
|
||||
_particles.ConsumeEvents(session, events, camPos, hasCam, sampleGroundTint);
|
||||
_ordnanceMirror.ConsumeEvents(
|
||||
events,
|
||||
_assetCache,
|
||||
_debris,
|
||||
_particles,
|
||||
hasCam,
|
||||
camPos,
|
||||
spec => AddTransient(new TransientVfx
|
||||
{
|
||||
Shape = spec.IsSphere ? VfxShape.Sphere : VfxShape.Ring,
|
||||
Position = spec.Position,
|
||||
Velocity = spec.Velocity,
|
||||
BaseRotation = spec.Rotation,
|
||||
StartScale = spec.StartScale,
|
||||
EndScale = spec.EndScale,
|
||||
ColorStart = spec.ColorStart,
|
||||
ColorEnd = spec.ColorEnd,
|
||||
Age = 0f,
|
||||
Lifetime = spec.Lifetime
|
||||
}));
|
||||
|
||||
for (int i = 0; i < footsteps.Count; i++)
|
||||
{
|
||||
|
|
@ -474,6 +514,9 @@ public partial class ArenaRenderer : Node3D
|
|||
_debris.ClearAll();
|
||||
_particles.ClearAll();
|
||||
_transientVfx.Clear();
|
||||
_ordnanceMirror.Clear();
|
||||
_mirrorSpheres.Clear();
|
||||
_mirrorRings.Clear();
|
||||
_tireDustNextTime.Clear();
|
||||
_thermalVentNextTime.Clear();
|
||||
_damageSmokeNextTime.Clear();
|
||||
|
|
@ -901,19 +944,48 @@ public partial class ArenaRenderer : Node3D
|
|||
float baseY = state.Terrain.SampleHeight(d.X, d.Z);
|
||||
if (d.Module is { } mod)
|
||||
{
|
||||
VehicleVisualInstance.ResolveDropGearVisual(_assetCache, mod, out ArrayMesh gMesh, out Vector3 gScale, out float gYOff);
|
||||
entry = new DropVisualEntry
|
||||
if (mod.Procedural is { } proc)
|
||||
{
|
||||
IsModule = true,
|
||||
IsImperial = mod.IsImperial,
|
||||
GearMesh = gMesh,
|
||||
GearScale = gScale * 1.45f,
|
||||
GearYOffset = gYOff * 1.45f + 0.35f,
|
||||
BaseY = baseY,
|
||||
TileX = tx,
|
||||
TileZ = tz,
|
||||
TileVersion = state.Terrain.TileVersions[tx, tz]
|
||||
};
|
||||
VehicleVisualInstance.BuildModularWeaponAssembly(
|
||||
_assetCache,
|
||||
proc.Assembly,
|
||||
out var modParts,
|
||||
out _,
|
||||
out _,
|
||||
out float minY);
|
||||
float sc = proc.Assembly.VisualScale * 1.45f;
|
||||
entry = new DropVisualEntry
|
||||
{
|
||||
IsModule = true,
|
||||
IsImperial = mod.IsImperial,
|
||||
ModularParts = modParts,
|
||||
ManufacturerRoleIndex = 10f + (float)proc.Manufacturer,
|
||||
DropBeaconColor = ResolveManufacturerBeaconColor(proc.Manufacturer),
|
||||
GearScale = Vector3.One * sc,
|
||||
GearYOffset = -minY * sc + 0.35f,
|
||||
BaseY = baseY,
|
||||
TileX = tx,
|
||||
TileZ = tz,
|
||||
TileVersion = state.Terrain.TileVersions[tx, tz]
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
VehicleVisualInstance.ResolveDropGearVisual(_assetCache, mod, out ArrayMesh gMesh, out Vector3 gScale, out float gYOff);
|
||||
entry = new DropVisualEntry
|
||||
{
|
||||
IsModule = true,
|
||||
IsImperial = mod.IsImperial,
|
||||
GearMesh = gMesh,
|
||||
DropBeaconColor = mod.IsImperial ? TouristGold * 2.2f : OlivePaint * 1.5f,
|
||||
GearScale = gScale * 1.45f,
|
||||
GearYOffset = gYOff * 1.45f + 0.35f,
|
||||
BaseY = baseY,
|
||||
TileX = tx,
|
||||
TileZ = tz,
|
||||
TileVersion = state.Terrain.TileVersions[tx, tz]
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -962,20 +1034,27 @@ public partial class ArenaRenderer : Node3D
|
|||
float bob = MathF.Sin(elapsedSeconds * 2.5f + d.Id) * 0.12f;
|
||||
float yaw = elapsedSeconds * 0.9f + d.Id;
|
||||
|
||||
if (entry.GearMesh is not null)
|
||||
var gearXf = new Transform3D(
|
||||
new Basis(Vector3.Up, yaw) * Basis.FromScale(entry.GearScale),
|
||||
new Vector3(d.X, entry.BaseY + bob + entry.GearYOffset, d.Z));
|
||||
if (entry.ModularParts is { } modParts)
|
||||
{
|
||||
Color custom = new(0f, 0f, entry.ManufacturerRoleIndex, 1f);
|
||||
for (int p = 0; p < modParts.Length; p++)
|
||||
{
|
||||
Transform3D partXf = gearXf * modParts[p].LocalToGearPivot;
|
||||
_partPool.Submit(modParts[p].Mesh, in partXf, in custom, wantsShadow: false);
|
||||
}
|
||||
}
|
||||
else if (entry.GearMesh is not null)
|
||||
{
|
||||
var gearXf = new Transform3D(
|
||||
new Basis(Vector3.Up, yaw) * Basis.FromScale(entry.GearScale),
|
||||
new Vector3(d.X, entry.BaseY + bob + entry.GearYOffset, d.Z));
|
||||
_partPool.Submit(entry.GearMesh, in gearXf, new Color(0f, 0f, 5f, 1f), wantsShadow: false);
|
||||
}
|
||||
|
||||
if (discCount < _dropDiscMm.InstanceCount)
|
||||
{
|
||||
_dropDiscMm.SetInstanceTransform(discCount, new Transform3D(Basis.Identity, new Vector3(d.X, entry.BaseY + bob + 0.08f, d.Z)));
|
||||
Color dCol = entry.IsImperial
|
||||
? new Color(TouristGold.R * 2.2f, TouristGold.G * 2.2f, TouristGold.B * 2.2f, 0.82f)
|
||||
: new Color(OlivePaint.R * 1.5f, OlivePaint.G * 1.5f, OlivePaint.B * 1.5f, 0.72f);
|
||||
Color dCol = entry.DropBeaconColor with { A = entry.IsImperial ? 0.82f : 0.72f };
|
||||
_dropDiscMm.SetInstanceCustomData(discCount, dCol);
|
||||
discCount++;
|
||||
}
|
||||
|
|
@ -1271,6 +1350,33 @@ public partial class ArenaRenderer : Node3D
|
|||
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(coreW, coreW, dist), coreCol);
|
||||
break;
|
||||
}
|
||||
|
||||
case WeaponVisualClass.GaussRail:
|
||||
{
|
||||
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(0.30f, 0.30f, dist), new Color(0.25f, 1.85f, 3.4f, 0.68f));
|
||||
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(0.10f, 0.10f, dist), new Color(2.2f, 3.6f, 4.0f, 0.98f));
|
||||
break;
|
||||
}
|
||||
|
||||
case WeaponVisualClass.PlasmaPpc:
|
||||
{
|
||||
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(0.36f, 0.36f, dist), new Color(0.18f, 2.25f, 2.65f, 0.65f));
|
||||
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(0.14f, 0.14f, dist), new Color(1.2f, 3.5f, 3.8f, 0.98f));
|
||||
break;
|
||||
}
|
||||
|
||||
case WeaponVisualClass.RocketSalvo:
|
||||
{
|
||||
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(0.22f, 0.22f, dist), new Color(3.2f, 1.45f, 0.30f, 0.92f));
|
||||
break;
|
||||
}
|
||||
|
||||
case WeaponVisualClass.SwarmSmart:
|
||||
{
|
||||
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(0.16f, 0.16f, dist), new Color(1.4f, 2.8f, 0.45f, 0.85f));
|
||||
EmitBeam(ref beamIdx, lookBasis, mid, new Vector3(0.07f, 0.07f, dist), new Color(2.0f, 0.95f, 3.2f, 0.96f));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1300,7 +1406,8 @@ public partial class ArenaRenderer : Node3D
|
|||
{
|
||||
continue;
|
||||
}
|
||||
if ((WeaponVisualClass)ev.WeaponClass != WeaponVisualClass.Explosive || ev.IsAirburst)
|
||||
var wClass = (WeaponVisualClass)ev.WeaponClass;
|
||||
if (ev.IsAirburst || wClass is not (WeaponVisualClass.Explosive or WeaponVisualClass.RocketSalvo or WeaponVisualClass.PlasmaPpc or WeaponVisualClass.SwarmSmart))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1311,8 +1418,20 @@ public partial class ArenaRenderer : Node3D
|
|||
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;
|
||||
float detSize = isRecoilless || wClass == WeaponVisualClass.RocketSalvo ? 3.2f : 1.9f;
|
||||
float ringSize = isRecoilless || wClass == WeaponVisualClass.RocketSalvo ? 6.2f : 3.4f;
|
||||
Color coreStart = wClass switch
|
||||
{
|
||||
WeaponVisualClass.PlasmaPpc => new Color(0.35f, 3.2f, 3.6f, 0.92f),
|
||||
WeaponVisualClass.SwarmSmart => new Color(1.9f, 3.2f, 0.6f, 0.90f),
|
||||
_ => new Color(3.6f, 2.0f, 0.55f, 0.92f)
|
||||
};
|
||||
Color coreEnd = wClass switch
|
||||
{
|
||||
WeaponVisualClass.PlasmaPpc => new Color(0.10f, 0.55f, 0.85f, 0f),
|
||||
WeaponVisualClass.SwarmSmart => new Color(0.55f, 0.25f, 0.85f, 0f),
|
||||
_ => new Color(0.85f, 0.28f, 0.08f, 0f)
|
||||
};
|
||||
AddTransient(new TransientVfx
|
||||
{
|
||||
Shape = VfxShape.Sphere,
|
||||
|
|
@ -1321,10 +1440,10 @@ public partial class ArenaRenderer : Node3D
|
|||
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),
|
||||
ColorStart = coreStart,
|
||||
ColorEnd = coreEnd,
|
||||
Age = 0f,
|
||||
Lifetime = isRecoilless ? 0.28f : 0.20f
|
||||
Lifetime = isRecoilless ? 0.28f : 0.22f
|
||||
});
|
||||
|
||||
Vector3 upRef = MathF.Abs(normal.Y) > 0.92f ? Vector3.Forward : Vector3.Up;
|
||||
|
|
@ -1339,15 +1458,28 @@ public partial class ArenaRenderer : Node3D
|
|||
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),
|
||||
ColorStart = coreStart,
|
||||
ColorEnd = coreEnd,
|
||||
Age = 0f,
|
||||
Lifetime = isRecoilless ? 0.32f : 0.22f
|
||||
Lifetime = isRecoilless ? 0.32f : 0.24f
|
||||
});
|
||||
}
|
||||
|
||||
int sphereIdx = 0;
|
||||
int ringIdx = 0;
|
||||
for (int i = 0; i < _mirrorSpheres.Count && sphereIdx < MaxVfxSpheres; i++)
|
||||
{
|
||||
_vfxSphereMm.SetInstanceTransform(sphereIdx, _mirrorSpheres[i].Xf);
|
||||
_vfxSphereMm.SetInstanceCustomData(sphereIdx, _mirrorSpheres[i].Col);
|
||||
sphereIdx++;
|
||||
}
|
||||
for (int i = 0; i < _mirrorRings.Count && ringIdx < MaxVfxRings; i++)
|
||||
{
|
||||
_vfxRingMm.SetInstanceTransform(ringIdx, _mirrorRings[i].Xf);
|
||||
_vfxRingMm.SetInstanceCustomData(ringIdx, _mirrorRings[i].Col);
|
||||
ringIdx++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _transientVfx.Count; i++)
|
||||
{
|
||||
TransientVfx v = _transientVfx[i];
|
||||
|
|
@ -1574,6 +1706,16 @@ public partial class ArenaRenderer : Node3D
|
|||
_transientVfx.Add(vfx);
|
||||
}
|
||||
|
||||
private static Color ResolveManufacturerBeaconColor(ManufacturerId mfg) => mfg switch
|
||||
{
|
||||
ManufacturerId.ScrapFrontier => new Color(2.1f, 1.35f, 0.40f, 0.82f),
|
||||
ManufacturerId.KorrathiIronworks => new Color(2.6f, 1.15f, 0.22f, 0.86f),
|
||||
ManufacturerId.AuralianOptics => new Color(0.55f, 2.25f, 2.65f, 0.86f),
|
||||
ManufacturerId.VexNineCollective => new Color(1.45f, 2.55f, 0.45f, 0.86f),
|
||||
ManufacturerId.ThalassanForge => new Color(0.35f, 1.95f, 2.85f, 0.86f),
|
||||
_ => TouristGold * 2.2f
|
||||
};
|
||||
|
||||
private static void ClearChildren(Node parent)
|
||||
{
|
||||
for (int i = parent.GetChildCount() - 1; i >= 0; i--)
|
||||
|
|
|
|||
627
client/ClientOrdnanceMirror.cs
Normal file
627
client/ClientOrdnanceMirror.cs
Normal file
|
|
@ -0,0 +1,627 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Client-side kinematic mirror of active <see cref="OrdnanceRuntime"/> projectiles, loitering drones,
|
||||
/// proximity mines, and thermal pools driven strictly by <c>[Union(13)]</c> <see cref="OrdnanceNodeEvent"/>
|
||||
/// (identical behavior in Solo and RemoteClient multiplayer, zero per-projectile <see cref="Node3D"/>s,
|
||||
/// zero material clones).
|
||||
/// </summary>
|
||||
public sealed class ClientOrdnanceMirror
|
||||
{
|
||||
public const int PoolCapacity = OrdnanceRuntime.PoolCapacity;
|
||||
|
||||
public readonly record struct TransientVfxSpec(
|
||||
bool IsSphere,
|
||||
Vector3 Position,
|
||||
Vector3 Velocity,
|
||||
Basis Rotation,
|
||||
Vector3 StartScale,
|
||||
Vector3 EndScale,
|
||||
Color ColorStart,
|
||||
Color ColorEnd,
|
||||
float Lifetime);
|
||||
|
||||
private struct MirroredSlot
|
||||
{
|
||||
public bool Active;
|
||||
public int OrdnanceId;
|
||||
public int ParentOrdnanceId;
|
||||
public ProceduralWeaponKey? WeaponKey;
|
||||
public byte NodeDefIndex;
|
||||
public OrdnanceNodeDef? Def;
|
||||
public OrdnanceVisualShape VisualShape;
|
||||
public Color Color;
|
||||
public float ManufacturerRoleIndex;
|
||||
public Vector3 Pos;
|
||||
public Vector3 Vel;
|
||||
public Vector3 AnchorPos;
|
||||
public int TargetEntityId;
|
||||
public bool TargetIsSpectator;
|
||||
public float Age;
|
||||
public float StageAge;
|
||||
public float OrbitAngle;
|
||||
public float TrailTimer;
|
||||
public float EmberTimer;
|
||||
public bool Armed;
|
||||
}
|
||||
|
||||
private readonly MirroredSlot[] _slots = new MirroredSlot[PoolCapacity];
|
||||
private readonly Dictionary<int, int> _slotById = new(PoolCapacity);
|
||||
private int _activeCount;
|
||||
|
||||
public int ActiveCount => _activeCount;
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Array.Clear(_slots, 0, _slots.Length);
|
||||
_slotById.Clear();
|
||||
_activeCount = 0;
|
||||
}
|
||||
|
||||
public bool TryGetMirroredPose(int ordnanceId, out Vector3 pos, out OrdnanceVisualShape shape)
|
||||
{
|
||||
if (_slotById.TryGetValue(ordnanceId, out int idx) && _slots[idx].Active)
|
||||
{
|
||||
pos = _slots[idx].Pos;
|
||||
shape = _slots[idx].VisualShape;
|
||||
return true;
|
||||
}
|
||||
pos = Vector3.Zero;
|
||||
shape = OrdnanceVisualShape.None;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ConsumeEvents(
|
||||
IReadOnlyList<ISimEvent> events,
|
||||
VehicleAssetCache cache,
|
||||
DebrisSystem debris,
|
||||
ParticlePool particles,
|
||||
bool hasCam,
|
||||
Vector3 camPos,
|
||||
Action<TransientVfxSpec> emitTransient)
|
||||
{
|
||||
for (int i = 0; i < events.Count; i++)
|
||||
{
|
||||
if (events[i] is MatchResetEvent)
|
||||
{
|
||||
Clear();
|
||||
continue;
|
||||
}
|
||||
if (events[i] is not OrdnanceNodeEvent ev)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var kind = (OrdnanceEventKind)ev.Kind;
|
||||
Vector3 pos = new(ev.PosX, ev.PosY, ev.PosZ);
|
||||
Vector3 vel = new(ev.VelX, ev.VelY, ev.VelZ);
|
||||
Color col = DecodeColorRgba(ev.ColorRgba);
|
||||
OrdnanceNodeDef? def = ResolveNodeDef(ev.WeaponKey, ev.NodeDefIndex);
|
||||
var shape = (OrdnanceVisualShape)ev.VisualShape;
|
||||
if (shape == OrdnanceVisualShape.None && def is not null)
|
||||
{
|
||||
shape = def.VisualShape;
|
||||
}
|
||||
|
||||
switch (kind)
|
||||
{
|
||||
case OrdnanceEventKind.Spawned:
|
||||
UpsertSlot(ev, pos, vel, col, def, shape);
|
||||
break;
|
||||
|
||||
case OrdnanceEventKind.StageTransition:
|
||||
{
|
||||
bool wasSabot = false;
|
||||
if (ev.ParentOrdnanceId != 0 && _slotById.TryGetValue(ev.ParentOrdnanceId, out int parentIdx) && _slots[parentIdx].Active)
|
||||
{
|
||||
wasSabot = _slots[parentIdx].VisualShape == OrdnanceVisualShape.SabotCarrier;
|
||||
RemoveAtSlot(parentIdx);
|
||||
}
|
||||
UpsertSlot(ev, pos, vel, col, def, shape);
|
||||
|
||||
if (wasSabot)
|
||||
{
|
||||
float roleIdx = ev.WeaponKey is { } wk ? 10f + Math.Clamp((int)wk.Manufacturer, 0, 4) : 11f;
|
||||
var petalTpl = cache.GetOrLoadWeaponPart("mz_slotted_brake");
|
||||
Vector3 dir = vel.LengthSquared() > 1e-3f ? vel.Normalized() : Vector3.Forward;
|
||||
Vector3 right = dir.Cross(Vector3.Up);
|
||||
if (right.LengthSquared() < 1e-4f) right = Vector3.Right;
|
||||
right = right.Normalized();
|
||||
|
||||
for (int side = -1; side <= 1; side += 2)
|
||||
{
|
||||
Vector3 pPos = pos + right * (side * 0.28f);
|
||||
Transform3D petalXf = new(Basis.FromScale(Vector3.One * 0.65f), pPos);
|
||||
debris.SpawnDetachedPart(
|
||||
petalTpl.SingleSurfaceMesh,
|
||||
petalXf,
|
||||
pos - right * (side * 0.45f),
|
||||
vel * 0.35f,
|
||||
roleIdx,
|
||||
impulseScale: 0.75f,
|
||||
applyScorch: true,
|
||||
lifetime: 2.2f);
|
||||
}
|
||||
particles.EmitOrdnanceBurst(pos, col, sparkCount: 4, radiusScale: 0.65f, camPos, hasCam);
|
||||
}
|
||||
else if (def?.Motion == OrdnanceMotion.LoiterOrbit)
|
||||
{
|
||||
emitTransient(new TransientVfxSpec(
|
||||
IsSphere: false,
|
||||
Position: pos,
|
||||
Velocity: Vector3.Zero,
|
||||
Rotation: Basis.Identity,
|
||||
StartScale: new Vector3(0.6f, 1.0f, 0.6f),
|
||||
EndScale: new Vector3(3.6f, 0.5f, 3.6f),
|
||||
ColorStart: (col * 2.4f) with { A = 0.85f },
|
||||
ColorEnd: col with { A = 0f },
|
||||
Lifetime: 0.30f));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case OrdnanceEventKind.Split:
|
||||
RemoveById(ev.OrdnanceId);
|
||||
particles.EmitOrdnanceBurst(pos, col, sparkCount: 6, radiusScale: 1.05f, camPos, hasCam);
|
||||
emitTransient(new TransientVfxSpec(
|
||||
IsSphere: false,
|
||||
Position: pos,
|
||||
Velocity: Vector3.Zero,
|
||||
Rotation: Basis.Identity,
|
||||
StartScale: new Vector3(0.7f, 1.0f, 0.7f),
|
||||
EndScale: new Vector3(5.2f, 0.5f, 5.2f),
|
||||
ColorStart: (col * 2.8f) with { A = 0.92f },
|
||||
ColorEnd: col with { A = 0f },
|
||||
Lifetime: 0.28f));
|
||||
break;
|
||||
|
||||
case OrdnanceEventKind.Detonated:
|
||||
{
|
||||
RemoveById(ev.OrdnanceId);
|
||||
float splashR = def is not null && def.SplashRadius > 0.5f ? def.SplashRadius : 4.2f;
|
||||
particles.EmitOrdnanceBurst(pos, col, sparkCount: 6, radiusScale: Math.Clamp(splashR / 4.5f, 0.7f, 1.6f), camPos, hasCam);
|
||||
emitTransient(new TransientVfxSpec(
|
||||
IsSphere: true,
|
||||
Position: pos + Vector3.Up * 0.2f,
|
||||
Velocity: Vector3.Up * 1.2f,
|
||||
Rotation: Basis.Identity,
|
||||
StartScale: Vector3.One * 0.55f,
|
||||
EndScale: Vector3.One * Math.Clamp(splashR * 0.75f, 1.8f, 4.8f),
|
||||
ColorStart: new Color(col.R * 3.2f, col.G * 3.2f, col.B * 3.2f, 0.92f),
|
||||
ColorEnd: new Color(col.R * 0.8f, col.G * 0.3f, col.B * 0.2f, 0f),
|
||||
Lifetime: 0.26f));
|
||||
emitTransient(new TransientVfxSpec(
|
||||
IsSphere: false,
|
||||
Position: pos + Vector3.Up * 0.16f,
|
||||
Velocity: Vector3.Zero,
|
||||
Rotation: Basis.Identity,
|
||||
StartScale: new Vector3(0.7f, 1f, 0.7f),
|
||||
EndScale: new Vector3(Math.Clamp(splashR * 1.35f, 2.8f, 8.5f), 0.4f, Math.Clamp(splashR * 1.35f, 2.8f, 8.5f)),
|
||||
ColorStart: new Color(col.R * 2.9f, col.G * 2.9f, col.B * 2.9f, 0.90f),
|
||||
ColorEnd: col with { A = 0f },
|
||||
Lifetime: 0.30f));
|
||||
break;
|
||||
}
|
||||
|
||||
case OrdnanceEventKind.Intercepted:
|
||||
RemoveById(ev.OrdnanceId);
|
||||
particles.EmitOrdnanceBurst(pos, new Color(1.0f, 0.75f, 0.28f), sparkCount: 5, radiusScale: 0.7f, camPos, hasCam);
|
||||
break;
|
||||
|
||||
case OrdnanceEventKind.Expired:
|
||||
RemoveById(ev.OrdnanceId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StepAndSubmit(
|
||||
float dt,
|
||||
IClientArenaSession session,
|
||||
VehicleAssetCache cache,
|
||||
MultiMeshPartPool partPool,
|
||||
ParticlePool particles,
|
||||
TerrainField terrain,
|
||||
bool hasCam,
|
||||
Vector3 camPos,
|
||||
Action<Transform3D, Color> submitActiveRing,
|
||||
Action<Transform3D, Color> submitActiveSphere)
|
||||
{
|
||||
if (_activeCount == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float stepDt = float.IsFinite(dt) && dt > 0f ? Math.Clamp(dt, 0f, 0.05f) : 0f;
|
||||
var state = session.ViewState;
|
||||
|
||||
var sabotMesh = cache.GetOrLoadWeaponPart("brl_sabot_rail").SingleSurfaceMesh;
|
||||
var rocketMesh = cache.GetOrLoadWeaponPart("mz_mirv_warhead").SingleSurfaceMesh;
|
||||
var droneMesh = cache.GetOrLoadWeaponPart("mz_loiter_aero_fin").SingleSurfaceMesh;
|
||||
var brakeMesh = cache.GetOrLoadWeaponPart("mz_slotted_brake").SingleSurfaceMesh;
|
||||
|
||||
for (int i = 0; i < PoolCapacity; i++)
|
||||
{
|
||||
if (!_slots[i].Active)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ref MirroredSlot s = ref _slots[i];
|
||||
var def = s.Def;
|
||||
float maxLife = def is not null && def.MaxLifetime > 0f ? def.MaxLifetime : 30f;
|
||||
|
||||
if (stepDt > 0f)
|
||||
{
|
||||
s.Age += stepDt;
|
||||
s.StageAge += stepDt;
|
||||
if (s.Age > maxLife + 2.5f)
|
||||
{
|
||||
RemoveAtSlot(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (def is not null && !s.Armed && s.StageAge >= def.ArmDelay)
|
||||
{
|
||||
s.Armed = true;
|
||||
}
|
||||
|
||||
AdvanceSlotKinematics(ref s, def, state, terrain, stepDt);
|
||||
}
|
||||
|
||||
if (hasCam && s.Pos.DistanceSquaredTo(camPos) > 340f * 340f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool isThermalPool = (def?.IsThermalPool == true) || s.VisualShape == OrdnanceVisualShape.Pool;
|
||||
if (isThermalPool)
|
||||
{
|
||||
float radius = def is not null && def.WhileAlive is { RadialRadius: > 0.5f }
|
||||
? def.WhileAlive.RadialRadius
|
||||
: (def is not null && def.SplashRadius > 0.5f ? def.SplashRadius : 5.5f);
|
||||
float pulse = 0.88f + 0.14f * MathF.Sin(s.StageAge * 7.5f + s.OrdnanceId);
|
||||
float groundY = terrain.SampleHeight(s.Pos.X, s.Pos.Z);
|
||||
Vector3 poolPos = new(s.Pos.X, MathF.Max(s.Pos.Y, groundY + 0.14f), s.Pos.Z);
|
||||
|
||||
Transform3D ringXf = new(Basis.FromScale(new Vector3(radius * 2f * pulse, 0.35f, radius * 2f * pulse)), poolPos);
|
||||
submitActiveRing(ringXf, new Color(s.Color.R * 2.6f, s.Color.G * 2.6f, s.Color.B * 2.6f, 0.78f));
|
||||
|
||||
Transform3D discXf = new(Basis.FromScale(new Vector3(radius * 1.4f * pulse, 0.14f, radius * 1.4f * pulse)), poolPos - new Vector3(0f, 0.04f, 0f));
|
||||
submitActiveSphere(discXf, new Color(s.Color.R * 2.1f, s.Color.G * 2.1f, s.Color.B * 2.1f, 0.42f));
|
||||
|
||||
if (stepDt > 0f)
|
||||
{
|
||||
s.EmberTimer += stepDt;
|
||||
if (s.EmberTimer >= 0.11f)
|
||||
{
|
||||
s.EmberTimer = 0f;
|
||||
particles.EmitThermalPoolEmber(poolPos, radius, s.Color, camPos, hasCam);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s.VisualShape == OrdnanceVisualShape.Mine || def?.Motion == OrdnanceMotion.StationaryMine)
|
||||
{
|
||||
float groundY = terrain.SampleHeight(s.Pos.X, s.Pos.Z);
|
||||
Vector3 minePos = new(s.Pos.X, MathF.Max(s.Pos.Y, groundY + 0.10f), s.Pos.Z);
|
||||
Basis upright = new Basis(Vector3.Right, -MathF.PI * 0.5f) * Basis.FromScale(Vector3.One * 1.05f);
|
||||
Transform3D mineXf = new(upright, minePos);
|
||||
float blink = s.Armed ? (0.45f + 0.55f * MathF.Max(0f, MathF.Sin(s.StageAge * 9.5f + s.OrdnanceId))) : 0f;
|
||||
partPool.Submit(rocketMesh, in mineXf, new Color(0f, blink * 0.6f, s.ManufacturerRoleIndex, 1f), wantsShadow: false);
|
||||
|
||||
if (s.Armed)
|
||||
{
|
||||
float proxR = def is not null && def.ProximityRadius > 0.5f ? def.ProximityRadius : 6.0f;
|
||||
float ringPulse = 0.92f + 0.08f * MathF.Sin(s.StageAge * 6f);
|
||||
Transform3D warnXf = new(Basis.FromScale(new Vector3(proxR * 0.55f * ringPulse, 0.18f, proxR * 0.55f * ringPulse)), minePos + new Vector3(0f, 0.08f, 0f));
|
||||
submitActiveRing(warnXf, new Color(s.Color.R * 2.2f, s.Color.G * 2.2f, s.Color.B * 2.2f, 0.25f + 0.35f * blink));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s.VisualShape == OrdnanceVisualShape.Drone || def?.Motion == OrdnanceMotion.LoiterOrbit)
|
||||
{
|
||||
Vector3 dir = s.Vel.LengthSquared() > 1e-3f ? s.Vel.Normalized() : Vector3.Forward;
|
||||
Vector3 up = MathF.Abs(dir.Dot(Vector3.Up)) > 0.95f ? Vector3.Right : Vector3.Up;
|
||||
Basis orient = Basis.LookingAt(-dir, up);
|
||||
if (def?.Motion == OrdnanceMotion.LoiterOrbit)
|
||||
{
|
||||
orient *= new Basis(Vector3.Forward, 0.32f);
|
||||
}
|
||||
Transform3D droneXf = new(orient * Basis.FromScale(Vector3.One * 2.4f), s.Pos);
|
||||
partPool.Submit(droneMesh, in droneXf, new Color(0f, 0.35f, s.ManufacturerRoleIndex, 1f), wantsShadow: false);
|
||||
|
||||
if (def?.Motion == OrdnanceMotion.LoiterOrbit)
|
||||
{
|
||||
float scanPulse = 0.85f + 0.15f * MathF.Sin(s.StageAge * 8f);
|
||||
Transform3D haloXf = new(Basis.FromScale(new Vector3(2.4f * scanPulse, 0.25f, 2.4f * scanPulse)), s.Pos - new Vector3(0f, 0.45f, 0f));
|
||||
submitActiveRing(haloXf, new Color(s.Color.R * 2.5f, s.Color.G * 2.5f, s.Color.B * 2.5f, 0.58f));
|
||||
}
|
||||
|
||||
if (stepDt > 0f)
|
||||
{
|
||||
s.TrailTimer += stepDt;
|
||||
if (s.TrailTimer >= 0.055f)
|
||||
{
|
||||
s.TrailTimer = 0f;
|
||||
particles.EmitOrdnanceTrail(s.Pos, s.Vel, s.Color, isRocket: def?.Motion != OrdnanceMotion.LoiterOrbit, camPos, hasCam);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Rocket, SabotCarrier, or Bolt projectile in flight
|
||||
{
|
||||
Vector3 dir = s.Vel.LengthSquared() > 1e-3f ? s.Vel.Normalized() : Vector3.Forward;
|
||||
Vector3 up = MathF.Abs(dir.Dot(Vector3.Up)) > 0.95f ? Vector3.Right : Vector3.Up;
|
||||
Basis orient = Basis.LookingAt(-dir, up);
|
||||
|
||||
ArrayMesh projMesh = s.VisualShape switch
|
||||
{
|
||||
OrdnanceVisualShape.SabotCarrier => sabotMesh,
|
||||
OrdnanceVisualShape.Rocket => rocketMesh,
|
||||
_ => brakeMesh
|
||||
};
|
||||
float projScale = s.VisualShape switch
|
||||
{
|
||||
OrdnanceVisualShape.SabotCarrier => 1.15f,
|
||||
OrdnanceVisualShape.Rocket => 1.55f,
|
||||
_ => 1.0f
|
||||
};
|
||||
|
||||
Transform3D projXf = new(orient * Basis.FromScale(Vector3.One * projScale), s.Pos);
|
||||
bool isRocket = s.VisualShape == OrdnanceVisualShape.Rocket ||
|
||||
def?.Motion is OrdnanceMotion.RocketBoosted or OrdnanceMotion.HomingMissile;
|
||||
partPool.Submit(projMesh, in projXf, new Color(0f, isRocket ? 0.65f : 0.25f, s.ManufacturerRoleIndex, 1f), wantsShadow: false);
|
||||
|
||||
if (isRocket)
|
||||
{
|
||||
Transform3D thrusterXf = new(Basis.FromScale(Vector3.One * 0.42f), s.Pos - dir * 0.22f);
|
||||
submitActiveSphere(thrusterXf, new Color(s.Color.R * 3.2f, s.Color.G * 3.2f, s.Color.B * 3.2f, 0.90f));
|
||||
}
|
||||
|
||||
if (stepDt > 0f)
|
||||
{
|
||||
s.TrailTimer += stepDt;
|
||||
if (s.TrailTimer >= (isRocket ? 0.035f : 0.055f))
|
||||
{
|
||||
s.TrailTimer = 0f;
|
||||
particles.EmitOrdnanceTrail(s.Pos - dir * 0.18f, s.Vel, s.Color, isRocket, camPos, hasCam);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AdvanceSlotKinematics(
|
||||
ref MirroredSlot s,
|
||||
OrdnanceNodeDef? def,
|
||||
MatchState state,
|
||||
TerrainField terrain,
|
||||
float dt)
|
||||
{
|
||||
OrdnanceMotion motion = def?.Motion ?? OrdnanceMotion.Ballistic;
|
||||
switch (motion)
|
||||
{
|
||||
case OrdnanceMotion.Ballistic:
|
||||
s.Vel.Y -= 19.6f * (def?.GravityScale ?? 1f) * dt;
|
||||
s.Pos += s.Vel * dt;
|
||||
break;
|
||||
|
||||
case OrdnanceMotion.RocketBoosted:
|
||||
{
|
||||
float burnTime = def?.BurnTime ?? 1.4f;
|
||||
if (s.StageAge <= burnTime && (def?.ThrustAccel ?? 0f) > 0f)
|
||||
{
|
||||
Vector3 dir = s.Vel.LengthSquared() > 1e-4f ? s.Vel.Normalized() : Vector3.Forward;
|
||||
float speed = s.Vel.Length();
|
||||
float maxSpd = def!.MaxSpeed > 0f ? def.MaxSpeed : 360f;
|
||||
float nextSpd = MathF.Min(maxSpd, speed + def.ThrustAccel * dt);
|
||||
s.Vel = dir * nextSpd;
|
||||
}
|
||||
else
|
||||
{
|
||||
s.Vel.Y -= 19.6f * (def?.GravityScale ?? 0.25f) * dt;
|
||||
}
|
||||
s.Pos += s.Vel * dt;
|
||||
break;
|
||||
}
|
||||
|
||||
case OrdnanceMotion.HomingMissile:
|
||||
{
|
||||
if (s.TargetEntityId >= 0)
|
||||
{
|
||||
Vector3 targetPt = Vector3.Zero;
|
||||
bool hasTarget = false;
|
||||
if (!s.TargetIsSpectator && s.TargetEntityId < state.Contenders.Count)
|
||||
{
|
||||
var tc = state.Contenders[s.TargetEntityId];
|
||||
if (tc.IsGroundedActive)
|
||||
{
|
||||
targetPt = new Vector3(tc.X, tc.Y + tc.Grid.Spec.HalfHeight * 0.35f, tc.Z);
|
||||
hasTarget = true;
|
||||
}
|
||||
}
|
||||
else if (s.TargetIsSpectator)
|
||||
{
|
||||
for (int k = 0; k < state.Spectators.Spectators.Count; k++)
|
||||
{
|
||||
var sp = state.Spectators.Spectators[k];
|
||||
if (sp.Id == s.TargetEntityId && sp.Alive)
|
||||
{
|
||||
targetPt = new Vector3(sp.X, sp.Y + sp.Grid.Spec.HalfHeight * 0.35f, sp.Z);
|
||||
hasTarget = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasTarget && (targetPt - s.Pos).LengthSquared() > 1e-3f)
|
||||
{
|
||||
Vector3 desiredDir = (targetPt - s.Pos).Normalized();
|
||||
Vector3 curDir = s.Vel.LengthSquared() > 1e-4f ? s.Vel.Normalized() : desiredDir;
|
||||
float maxTurn = (def?.TurnRateRad ?? 4.5f) * dt;
|
||||
float dot = Math.Clamp(curDir.Dot(desiredDir), -1f, 1f);
|
||||
float angle = MathF.Acos(dot);
|
||||
Vector3 newDir = angle <= maxTurn || angle < 1e-4f
|
||||
? desiredDir
|
||||
: curDir.Lerp(desiredDir, maxTurn / angle).Normalized();
|
||||
float spd = s.Vel.Length();
|
||||
float maxSpd = def is not null && def.MaxSpeed > 0f ? def.MaxSpeed : MathF.Max(spd, 115f);
|
||||
spd = MathF.Min(maxSpd, spd + (def?.ThrustAccel ?? 90f) * dt);
|
||||
s.Vel = newDir * spd;
|
||||
}
|
||||
}
|
||||
s.Pos += s.Vel * dt;
|
||||
break;
|
||||
}
|
||||
|
||||
case OrdnanceMotion.LoiterOrbit:
|
||||
{
|
||||
float orbitSpeed = def?.LoiterOrbitSpeedRad ?? 1.45f;
|
||||
float radius = def?.LoiterOrbitRadius ?? 15f;
|
||||
float agl = def?.LoiterAltitudeAgl ?? 35f;
|
||||
s.OrbitAngle += orbitSpeed * dt;
|
||||
float ox = s.AnchorPos.X + MathF.Cos(s.OrbitAngle) * radius;
|
||||
float oz = s.AnchorPos.Z + MathF.Sin(s.OrbitAngle) * radius;
|
||||
float oy = terrain.SampleHeight(ox, oz) + agl;
|
||||
Vector3 nextPos = new(ox, oy, oz);
|
||||
s.Vel = (nextPos - s.Pos) / MathF.Max(1e-4f, dt);
|
||||
s.Pos = nextPos;
|
||||
break;
|
||||
}
|
||||
|
||||
case OrdnanceMotion.StationaryMine:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpsertSlot(
|
||||
OrdnanceNodeEvent ev,
|
||||
Vector3 pos,
|
||||
Vector3 vel,
|
||||
Color col,
|
||||
OrdnanceNodeDef? def,
|
||||
OrdnanceVisualShape shape)
|
||||
{
|
||||
if (_slotById.TryGetValue(ev.OrdnanceId, out int existing))
|
||||
{
|
||||
ref var slot = ref _slots[existing];
|
||||
slot.Pos = pos;
|
||||
slot.Vel = vel;
|
||||
slot.AnchorPos = pos;
|
||||
slot.TargetEntityId = ev.TargetEntityId;
|
||||
slot.TargetIsSpectator = ev.TargetIsSpectator;
|
||||
slot.Def = def;
|
||||
slot.VisualShape = shape;
|
||||
slot.Color = col;
|
||||
return;
|
||||
}
|
||||
|
||||
int freeIdx = -1;
|
||||
for (int i = 0; i < PoolCapacity; i++)
|
||||
{
|
||||
if (!_slots[i].Active)
|
||||
{
|
||||
freeIdx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (freeIdx < 0)
|
||||
{
|
||||
// Evict oldest slot to stay strictly bounded under PoolCapacity
|
||||
float maxAge = -1f;
|
||||
int oldest = 0;
|
||||
for (int i = 0; i < PoolCapacity; i++)
|
||||
{
|
||||
if (_slots[i].Age > maxAge)
|
||||
{
|
||||
maxAge = _slots[i].Age;
|
||||
oldest = i;
|
||||
}
|
||||
}
|
||||
RemoveAtSlot(oldest);
|
||||
freeIdx = oldest;
|
||||
}
|
||||
|
||||
float mfgRole = ev.WeaponKey is { } wk ? 10f + Math.Clamp((int)wk.Manufacturer, 0, 4) : 5f;
|
||||
_slots[freeIdx] = new MirroredSlot
|
||||
{
|
||||
Active = true,
|
||||
OrdnanceId = ev.OrdnanceId,
|
||||
ParentOrdnanceId = ev.ParentOrdnanceId,
|
||||
WeaponKey = ev.WeaponKey,
|
||||
NodeDefIndex = ev.NodeDefIndex,
|
||||
Def = def,
|
||||
VisualShape = shape,
|
||||
Color = col,
|
||||
ManufacturerRoleIndex = mfgRole,
|
||||
Pos = pos,
|
||||
Vel = vel,
|
||||
AnchorPos = pos,
|
||||
TargetEntityId = ev.TargetEntityId,
|
||||
TargetIsSpectator = ev.TargetIsSpectator,
|
||||
Age = 0f,
|
||||
StageAge = 0f,
|
||||
OrbitAngle = 0f,
|
||||
TrailTimer = 0f,
|
||||
EmberTimer = 0f,
|
||||
Armed = def is null || def.ArmDelay <= 0f
|
||||
};
|
||||
_slotById[ev.OrdnanceId] = freeIdx;
|
||||
_activeCount++;
|
||||
}
|
||||
|
||||
private void RemoveById(int ordnanceId)
|
||||
{
|
||||
if (_slotById.TryGetValue(ordnanceId, out int idx))
|
||||
{
|
||||
RemoveAtSlot(idx);
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveAtSlot(int idx)
|
||||
{
|
||||
if (!_slots[idx].Active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_slotById.Remove(_slots[idx].OrdnanceId);
|
||||
_slots[idx] = default;
|
||||
_activeCount = Math.Max(0, _activeCount - 1);
|
||||
}
|
||||
|
||||
private static OrdnanceNodeDef? ResolveNodeDef(ProceduralWeaponKey? key, byte nodeDefIndex)
|
||||
{
|
||||
if (!key.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var spec = ProceduralWeaponGenerator.Generate(key.Value);
|
||||
if (nodeDefIndex < spec.FlattenedNodes.Length)
|
||||
{
|
||||
return spec.FlattenedNodes[nodeDefIndex];
|
||||
}
|
||||
return spec.RootNode;
|
||||
}
|
||||
|
||||
private static Color DecodeColorRgba(uint rgba)
|
||||
{
|
||||
if (rgba == 0)
|
||||
{
|
||||
return new Color(1.0f, 0.72f, 0.28f, 1.0f);
|
||||
}
|
||||
float r = ((rgba >> 24) & 0xFF) / 255f;
|
||||
float g = ((rgba >> 16) & 0xFF) / 255f;
|
||||
float b = ((rgba >> 8) & 0xFF) / 255f;
|
||||
return new Color(r, g, b, 1.0f);
|
||||
}
|
||||
}
|
||||
125
client/Hud.cs
125
client/Hud.cs
|
|
@ -87,6 +87,7 @@ public partial class Hud : CanvasLayer
|
|||
private int _selectedCargoIndex = -1;
|
||||
private int _lastCargoHash = -1;
|
||||
private bool _garageExpanded;
|
||||
private Vector2I? _lastHoveredCell;
|
||||
|
||||
public event Action<string, string>? JoinRequested;
|
||||
public event Action<int, string>? HostRequested;
|
||||
|
|
@ -125,6 +126,10 @@ public partial class Hud : CanvasLayer
|
|||
}
|
||||
internal Rect2 BottomLeftPanelRect => _bottomLeftPanel.GetGlobalRect();
|
||||
internal Rect2 ChyronPanelRect => _chyronPanel.GetGlobalRect();
|
||||
internal string HoverLabelText => _hoverLabel.Text;
|
||||
internal string PromptLabelText => _promptLabel.Text;
|
||||
internal string GarageDetailsText => _garageDetails.Text;
|
||||
internal void SimulateCellHover(Vector2I? cell, HardpointSpec? hp) => OnSchematicHoverChanged(cell, hp);
|
||||
|
||||
public IEnumerable<ShaderMaterial> GetChromeMaterials()
|
||||
{
|
||||
|
|
@ -217,8 +222,11 @@ public partial class Hud : CanvasLayer
|
|||
case HitImpactEvent hit:
|
||||
if (hit.TargetKind == (byte)HitTargetKind.Contender && hit.TargetId == localContenderId)
|
||||
{
|
||||
_crosshair?.PushTestHitArc(hit.SourceX, hit.SourceZ, (WeaponVisualClass)hit.WeaponClass);
|
||||
float pulse = (WeaponVisualClass)hit.WeaponClass == WeaponVisualClass.Explosive ? 0.95f : 0.62f;
|
||||
var wc = (WeaponVisualClass)hit.WeaponClass;
|
||||
_crosshair?.PushTestHitArc(hit.SourceX, hit.SourceZ, wc);
|
||||
float pulse = wc is WeaponVisualClass.Explosive or WeaponVisualClass.RocketSalvo or WeaponVisualClass.GaussRail
|
||||
? 0.95f
|
||||
: 0.62f;
|
||||
_damagePulse = MathF.Max(_damagePulse, pulse);
|
||||
}
|
||||
bool targetIsVehicle = hit.TargetKind == (byte)HitTargetKind.Contender
|
||||
|
|
@ -472,9 +480,14 @@ public partial class Hud : CanvasLayer
|
|||
_schematic.SetGrid(player.Grid, _selectedCargoIndex);
|
||||
SyncCargoButtons(player.Grid);
|
||||
|
||||
if (_lastHoveredCell is null)
|
||||
{
|
||||
UpdateCargoSelectionTooltip(player.Grid);
|
||||
}
|
||||
|
||||
if (_garageExpanded)
|
||||
{
|
||||
_garageDetails.Text = BuildGarageDetails(player.Grid);
|
||||
_garageDetails.Text = BuildGarageDetails(player.Grid, _selectedCargoIndex);
|
||||
}
|
||||
|
||||
// Broadcast Chyron
|
||||
|
|
@ -609,9 +622,15 @@ public partial class Hud : CanvasLayer
|
|||
_netStatusLabel.AddThemeFontSizeOverride("font_size", 12);
|
||||
vbox.AddChild(_netStatusLabel);
|
||||
|
||||
_promptLabel = new Label { Text = "", Visible = false };
|
||||
_promptLabel = new Label
|
||||
{
|
||||
Text = "",
|
||||
Visible = false,
|
||||
AutowrapMode = TextServer.AutowrapMode.Word,
|
||||
CustomMinimumSize = new Vector2(336f, 0f)
|
||||
};
|
||||
_promptLabel.AddThemeColorOverride("font_color", CyanCol);
|
||||
_promptLabel.AddThemeFontSizeOverride("font_size", 14);
|
||||
_promptLabel.AddThemeFontSizeOverride("font_size", 13);
|
||||
vbox.AddChild(_promptLabel);
|
||||
|
||||
_controlsHint = new Label { Text = "WASD Drive | Mouse Aim | LMB Fire | E Loot/Swap | Tab Garage | Wheel Zoom" };
|
||||
|
|
@ -697,8 +716,8 @@ public partial class Hud : CanvasLayer
|
|||
_hoverLabel = new Label
|
||||
{
|
||||
Text = "HOVER CELL FOR TELEMETRY",
|
||||
ClipText = true,
|
||||
CustomMinimumSize = new Vector2(180f, 15f)
|
||||
AutowrapMode = TextServer.AutowrapMode.Word,
|
||||
CustomMinimumSize = new Vector2(180f, 28f)
|
||||
};
|
||||
_hoverLabel.AddThemeColorOverride("font_color", TextMuted);
|
||||
_hoverLabel.AddThemeFontSizeOverride("font_size", 10);
|
||||
|
|
@ -984,11 +1003,15 @@ public partial class Hud : CanvasLayer
|
|||
|
||||
private void OnSchematicHoverChanged(Vector2I? cell, HardpointSpec? hp)
|
||||
{
|
||||
_lastHoveredCell = cell;
|
||||
var grid = _schematic.Grid;
|
||||
if (cell is null || grid is null)
|
||||
{
|
||||
_hoverLabel.Text = "HOVER CELL FOR TELEMETRY";
|
||||
_hoverLabel.AddThemeColorOverride("font_color", TextMuted);
|
||||
if (!UpdateCargoSelectionTooltip(grid))
|
||||
{
|
||||
_hoverLabel.Text = "HOVER CELL FOR TELEMETRY";
|
||||
_hoverLabel.AddThemeColorOverride("font_color", TextMuted);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1001,10 +1024,19 @@ public partial class Hud : CanvasLayer
|
|||
var mounted = grid.GetMountedOn(hp.Id);
|
||||
bool strippedHp = !grid.IsHardpointOperational(hp);
|
||||
string hpStatus = strippedHp ? " [STRIPPED]" : "";
|
||||
_hoverLabel.Text = mounted is not null
|
||||
? $"{hp.Kind.ToString().ToUpperInvariant()}: {mounted.Spec.Name} {mounted.CurrentTemp:F0}°C ({mounted.CurrentPerformance * 100f:F0}%){hpStatus}"
|
||||
: $"{hp.Kind.ToString().ToUpperInvariant()} SLOT [{hp.Width}x{hp.Height}] EMPTY{hpStatus}";
|
||||
_hoverLabel.AddThemeColorOverride("font_color", (arm <= 0.01f || strippedHp) ? RedCol : TextLight);
|
||||
if (mounted is not null && mounted.Spec.Procedural is { } proc)
|
||||
{
|
||||
_hoverLabel.Text = $"[{proc.ManufacturerLabel}] {proc.SummaryLine1}{hpStatus}\n{proc.SummaryLine2}";
|
||||
_hoverLabel.AddThemeColorOverride("font_color",
|
||||
(arm <= 0.01f || strippedHp) ? RedCol : ResolveManufacturerHudColor(proc.Manufacturer));
|
||||
}
|
||||
else
|
||||
{
|
||||
_hoverLabel.Text = mounted is not null
|
||||
? $"{hp.Kind.ToString().ToUpperInvariant()}: {mounted.Spec.Name} {mounted.CurrentTemp:F0}°C ({mounted.CurrentPerformance * 100f:F0}%){hpStatus}"
|
||||
: $"{hp.Kind.ToString().ToUpperInvariant()} SLOT [{hp.Width}x{hp.Height}] EMPTY{hpStatus}";
|
||||
_hoverLabel.AddThemeColorOverride("font_color", (arm <= 0.01f || strippedHp) ? RedCol : TextLight);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1015,6 +1047,36 @@ public partial class Hud : CanvasLayer
|
|||
}
|
||||
}
|
||||
|
||||
private bool UpdateCargoSelectionTooltip(ChassisGrid? grid)
|
||||
{
|
||||
if (grid is null || _selectedCargoIndex < 0 || _selectedCargoIndex >= grid.Cargo.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var mod = grid.Cargo[_selectedCargoIndex];
|
||||
if (mod.Procedural is { } proc)
|
||||
{
|
||||
_hoverLabel.Text = $"[{proc.ManufacturerLabel}] {proc.SummaryLine1}\n{proc.SummaryLine2}";
|
||||
_hoverLabel.AddThemeColorOverride("font_color", ResolveManufacturerHudColor(proc.Manufacturer));
|
||||
}
|
||||
else
|
||||
{
|
||||
_hoverLabel.Text = $"CARGO: {mod.Name} [{mod.Width}x{mod.Height}]";
|
||||
_hoverLabel.AddThemeColorOverride("font_color", mod.IsImperial ? GoldCol : TextLight);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Color ResolveManufacturerHudColor(ManufacturerId mfg) => mfg switch
|
||||
{
|
||||
ManufacturerId.ScrapFrontier => Color.FromHtml("#ffaa33"),
|
||||
ManufacturerId.KorrathiIronworks => Color.FromHtml("#f2c422"),
|
||||
ManufacturerId.AuralianOptics => Color.FromHtml("#38e8ff"),
|
||||
ManufacturerId.VexNineCollective => Color.FromHtml("#7cf230"),
|
||||
ManufacturerId.ThalassanForge => Color.FromHtml("#2cb8ff"),
|
||||
_ => GoldCol
|
||||
};
|
||||
|
||||
private void SyncCargoButtons(ChassisGrid grid)
|
||||
{
|
||||
int hash = HashCode.Combine(grid.Cargo.Count, grid.Spec.CargoCapacity, _selectedCargoIndex);
|
||||
|
|
@ -1141,6 +1203,13 @@ public partial class Hud : CanvasLayer
|
|||
if (nearest.Module is { } mod)
|
||||
{
|
||||
var freeHp = player.Grid.FindFirstEmptyCompatibleHardpoint(mod);
|
||||
if (mod.Procedural is { } proc)
|
||||
{
|
||||
string action = freeHp is not null
|
||||
? $"[E] Bolt [{proc.ManufacturerLabel}] {mod.Name} -> {freeHp.Id}"
|
||||
: $"[E] Loot [{proc.ManufacturerLabel}] {mod.Name}";
|
||||
return $"{action}\n{proc.SummaryLine1} | {proc.SummaryLine2}";
|
||||
}
|
||||
return freeHp is not null
|
||||
? $"[E] Bolt {(mod.IsImperial ? "IMPERIAL " : "")}{mod.Name} -> {freeHp.Id}"
|
||||
: $"[E] Loot {(mod.IsImperial ? "IMPERIAL " : "")}{mod.Name}";
|
||||
|
|
@ -1152,7 +1221,7 @@ public partial class Hud : CanvasLayer
|
|||
return "";
|
||||
}
|
||||
|
||||
private static string BuildGarageDetails(ChassisGrid grid)
|
||||
private static string BuildGarageDetails(ChassisGrid grid, int selectedCargoIndex = -1)
|
||||
{
|
||||
var lines = new List<string>
|
||||
{
|
||||
|
|
@ -1163,7 +1232,23 @@ public partial class Hud : CanvasLayer
|
|||
{
|
||||
var m = grid.Mounted[i];
|
||||
string stateTag = grid.IsHardpointOperational(m.HardpointId) ? "" : " [STRIPPED]";
|
||||
lines.Add($"• {m.HardpointId}: {m.Spec.Name} {m.CurrentTemp:F0}°C ({(m.CurrentPerformance * 100f):F0}%){stateTag}");
|
||||
if (m.Spec.Procedural is { } proc)
|
||||
{
|
||||
lines.Add($"• [{proc.ManufacturerLabel}] {m.Spec.Name} {m.CurrentTemp:F0}°C{stateTag}");
|
||||
lines.Add($" {proc.SummaryLine1}");
|
||||
lines.Add($" {proc.SummaryLine2}");
|
||||
}
|
||||
else
|
||||
{
|
||||
lines.Add($"• {m.HardpointId}: {m.Spec.Name} {m.CurrentTemp:F0}°C ({(m.CurrentPerformance * 100f):F0}%){stateTag}");
|
||||
}
|
||||
}
|
||||
if (selectedCargoIndex >= 0 && selectedCargoIndex < grid.Cargo.Count &&
|
||||
grid.Cargo[selectedCargoIndex].Procedural is { } cargoProc)
|
||||
{
|
||||
lines.Add($"SEL [{cargoProc.ManufacturerLabel}]:");
|
||||
lines.Add($" {cargoProc.SummaryLine1}");
|
||||
lines.Add($" {cargoProc.SummaryLine2}");
|
||||
}
|
||||
return string.Join("\n", lines);
|
||||
}
|
||||
|
|
@ -1512,14 +1597,18 @@ public partial class Hud : CanvasLayer
|
|||
Color arcCol = arc.WeaponClass switch
|
||||
{
|
||||
WeaponVisualClass.Explosive => new Color(1.0f, 0.36f, 0.12f, alpha * 0.96f),
|
||||
WeaponVisualClass.RocketSalvo => new Color(1.0f, 0.56f, 0.14f, alpha * 0.96f),
|
||||
WeaponVisualClass.ThermalBeam => new Color(0.30f, 0.90f, 1.0f, alpha * 0.96f),
|
||||
WeaponVisualClass.GaussRail => new Color(0.24f, 0.78f, 1.0f, alpha * 0.98f),
|
||||
WeaponVisualClass.PlasmaPpc => new Color(0.18f, 0.92f, 0.96f, alpha * 0.96f),
|
||||
WeaponVisualClass.SwarmSmart => new Color(0.56f, 0.96f, 0.28f, alpha * 0.96f),
|
||||
_ => new Color(0.96f, 0.72f, 0.22f, alpha * 0.94f)
|
||||
};
|
||||
|
||||
const float hitR = 39f;
|
||||
const float halfSpan = 0.34f;
|
||||
DrawArc(center, hitR, angle - halfSpan, angle + halfSpan, 14, arcCol, 4.2f);
|
||||
if (arc.WeaponClass == WeaponVisualClass.ThermalBeam)
|
||||
if (arc.WeaponClass is WeaponVisualClass.ThermalBeam or WeaponVisualClass.GaussRail or WeaponVisualClass.PlasmaPpc)
|
||||
{
|
||||
DrawArc(center, hitR - 3.5f, angle - halfSpan * 0.75f, angle + halfSpan * 0.75f, 10,
|
||||
new Color(GoldCol.R, GoldCol.G, GoldCol.B, alpha * 0.90f), 2.0f);
|
||||
|
|
@ -1539,7 +1628,11 @@ public partial class Hud : CanvasLayer
|
|||
{
|
||||
WeaponVisualClass.Autocannon => ("20MM IMPACT", new Color(0.98f, 0.70f, 0.20f, tagAlpha)),
|
||||
WeaponVisualClass.Explosive => ("BLAST IMPACT", new Color(1.0f, 0.38f, 0.14f, tagAlpha)),
|
||||
WeaponVisualClass.RocketSalvo => ("ROCKET HIT", new Color(1.0f, 0.58f, 0.18f, tagAlpha)),
|
||||
WeaponVisualClass.ThermalBeam => ("THERMAL HIT", new Color(0.36f, 0.92f, 1.0f, tagAlpha)),
|
||||
WeaponVisualClass.GaussRail => ("GAUSS RAIL", new Color(0.28f, 0.84f, 1.0f, tagAlpha)),
|
||||
WeaponVisualClass.PlasmaPpc => ("PLASMA BURN", new Color(0.24f, 0.94f, 0.98f, tagAlpha)),
|
||||
WeaponVisualClass.SwarmSmart => ("SWARM HIT", new Color(0.58f, 0.96f, 0.30f, tagAlpha)),
|
||||
_ => ("KINETIC HIT", new Color(0.96f, 0.78f, 0.28f, tagAlpha))
|
||||
};
|
||||
DrawString(
|
||||
|
|
|
|||
|
|
@ -746,6 +746,116 @@ public partial class ParticlePool : Node3D
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WeaponVisualClass.GaussRail:
|
||||
{
|
||||
Color gaussCol = new(0.22f, 0.78f, 1.0f, 0.98f);
|
||||
SpawnParticle(new ParticleSlot
|
||||
{
|
||||
Active = true,
|
||||
Mode = ModeMuzzleStarburst,
|
||||
Position = start,
|
||||
Velocity = Vector3.Zero,
|
||||
StartSize = 1.45f,
|
||||
EndSize = 0.50f,
|
||||
AspectY = 1f,
|
||||
Rotation = NextFloat() * MathF.Tau,
|
||||
Emissive = 3.8f,
|
||||
ColorStart = new Color(0.75f, 0.96f, 1.0f, 1.0f),
|
||||
ColorEnd = gaussCol with { A = 0f },
|
||||
Lifetime = 0.095f
|
||||
});
|
||||
SpawnSparkBurst(start, (end - start).Normalized(), 4, gaussCol, 14f);
|
||||
if (!hasCam || start.DistanceSquaredTo(camPos) <= 65f * 65f)
|
||||
{
|
||||
SpawnFlashLight(start, gaussCol with { A = 1f }, 4.2f, 14f, 0.11f, priority: 5);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WeaponVisualClass.PlasmaPpc:
|
||||
{
|
||||
Color plasmaCol = new(0.16f, 0.88f, 0.95f, 0.96f);
|
||||
SpawnParticle(new ParticleSlot
|
||||
{
|
||||
Active = true,
|
||||
Mode = ModeSteamFire,
|
||||
Position = start,
|
||||
Velocity = (end - start).Normalized() * 3.5f,
|
||||
StartSize = 0.85f,
|
||||
EndSize = 2.0f,
|
||||
AspectY = 1f,
|
||||
Rotation = NextFloat() * MathF.Tau,
|
||||
Emissive = 3.2f,
|
||||
ColorStart = plasmaCol,
|
||||
ColorEnd = new Color(0.08f, 0.45f, 0.65f, 0f),
|
||||
Lifetime = 0.24f
|
||||
});
|
||||
if (!hasCam || start.DistanceSquaredTo(camPos) <= 55f * 55f)
|
||||
{
|
||||
SpawnFlashLight(start, plasmaCol with { A = 1f }, 3.4f, 12f, 0.12f, priority: 4);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WeaponVisualClass.RocketSalvo:
|
||||
{
|
||||
SpawnParticle(new ParticleSlot
|
||||
{
|
||||
Active = true,
|
||||
Mode = ModeMuzzleStarburst,
|
||||
Position = start,
|
||||
Velocity = Vector3.Zero,
|
||||
StartSize = 1.15f,
|
||||
EndSize = 0.55f,
|
||||
AspectY = 1f,
|
||||
Rotation = NextFloat() * MathF.Tau,
|
||||
Emissive = 3.0f,
|
||||
ColorStart = new Color(1.0f, 0.72f, 0.24f, 0.96f),
|
||||
ColorEnd = new Color(0.95f, 0.35f, 0.08f, 0f),
|
||||
Lifetime = 0.10f
|
||||
});
|
||||
SpawnParticle(new ParticleSlot
|
||||
{
|
||||
Active = true,
|
||||
Mode = ModeDustSmoke,
|
||||
Position = start,
|
||||
Velocity = new Vector3(NextSigned() * 1.2f, 1.4f, NextSigned() * 1.2f),
|
||||
Gravity = -0.15f,
|
||||
Drag = 1.8f,
|
||||
StartSize = 0.55f,
|
||||
EndSize = 1.85f,
|
||||
AspectY = 1f,
|
||||
Rotation = NextFloat() * MathF.Tau,
|
||||
AngularVel = NextSigned() * 1.3f,
|
||||
Emissive = 0f,
|
||||
ColorStart = new Color(0.62f, 0.58f, 0.52f, 0.55f),
|
||||
ColorEnd = new Color(0.45f, 0.42f, 0.38f, 0f),
|
||||
Lifetime = 0.42f
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case WeaponVisualClass.SwarmSmart:
|
||||
{
|
||||
Color swarmCol = new(0.56f, 0.96f, 0.28f, 0.96f);
|
||||
SpawnParticle(new ParticleSlot
|
||||
{
|
||||
Active = true,
|
||||
Mode = ModeMuzzleStarburst,
|
||||
Position = start,
|
||||
Velocity = Vector3.Zero,
|
||||
StartSize = 0.78f,
|
||||
EndSize = 0.36f,
|
||||
AspectY = 1f,
|
||||
Rotation = NextFloat() * MathF.Tau,
|
||||
Emissive = 2.6f,
|
||||
ColorStart = swarmCol,
|
||||
ColorEnd = new Color(0.55f, 0.28f, 0.88f, 0f),
|
||||
Lifetime = 0.085f
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -873,9 +983,187 @@ public partial class ParticlePool : Node3D
|
|||
});
|
||||
SpawnSparkBurst(pos, normal, 4, new Color(0.55f, 0.92f, 1.0f, 0.98f), 12f);
|
||||
break;
|
||||
|
||||
case WeaponVisualClass.GaussRail:
|
||||
EmitImpactDustPlume(pos, normal, groundTint, count: 3, size: 1.65f);
|
||||
SpawnSparkBurst(pos, normal, 6, new Color(0.30f, 0.84f, 1.0f, 0.98f), 17f);
|
||||
if (!hasCam || pos.DistanceSquaredTo(camPos) <= 65f * 65f)
|
||||
{
|
||||
SpawnFlashLight(pos + normal * 0.35f, new Color(0.28f, 0.82f, 1.0f), 4.0f, 13f, 0.12f, priority: 6);
|
||||
}
|
||||
break;
|
||||
|
||||
case WeaponVisualClass.PlasmaPpc:
|
||||
SpawnParticle(new ParticleSlot
|
||||
{
|
||||
Active = true,
|
||||
Mode = ModeSteamFire,
|
||||
Position = pos + normal * 0.2f,
|
||||
Velocity = normal * 1.6f,
|
||||
StartSize = 0.90f,
|
||||
EndSize = 2.6f,
|
||||
AspectY = 1f,
|
||||
Rotation = NextFloat() * MathF.Tau,
|
||||
Emissive = 3.2f,
|
||||
ColorStart = new Color(0.20f, 0.88f, 1.0f, 0.95f),
|
||||
ColorEnd = new Color(0.12f, 0.38f, 0.52f, 0f),
|
||||
Lifetime = 0.42f
|
||||
});
|
||||
SpawnSparkBurst(pos, normal, 5, new Color(0.32f, 0.94f, 1.0f, 0.98f), 12.5f);
|
||||
break;
|
||||
|
||||
case WeaponVisualClass.RocketSalvo:
|
||||
EmitImpactDustPlume(pos, normal, groundTint, count: 4, size: 1.75f);
|
||||
SpawnParticle(new ParticleSlot
|
||||
{
|
||||
Active = true,
|
||||
Mode = ModeSteamFire,
|
||||
Position = pos + normal * 0.25f,
|
||||
Velocity = normal * 2.2f,
|
||||
Gravity = -0.25f,
|
||||
Drag = 1.6f,
|
||||
StartSize = 0.95f,
|
||||
EndSize = 2.95f,
|
||||
AspectY = 1f,
|
||||
Rotation = NextFloat() * MathF.Tau,
|
||||
Emissive = 2.8f,
|
||||
ColorStart = new Color(1.0f, 0.62f, 0.18f, 0.96f),
|
||||
ColorEnd = new Color(0.28f, 0.16f, 0.12f, 0f),
|
||||
Lifetime = 0.38f
|
||||
});
|
||||
SpawnSparkBurst(pos, normal, 5, new Color(1.0f, 0.68f, 0.22f, 0.98f), 14.5f);
|
||||
if (!hasCam || pos.DistanceSquaredTo(camPos) <= 75f * 75f)
|
||||
{
|
||||
SpawnFlashLight(pos + normal * 0.45f, new Color(1.0f, 0.56f, 0.16f), 4.5f, 14f, 0.14f, priority: 7);
|
||||
}
|
||||
break;
|
||||
|
||||
case WeaponVisualClass.SwarmSmart:
|
||||
EmitImpactDustPlume(pos, normal, groundTint, count: 2, size: 1.25f);
|
||||
SpawnSparkBurst(pos, normal, 4, new Color(0.56f, 0.96f, 0.32f, 0.98f), 12f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void EmitOrdnanceTrail(Vector3 pos, Vector3 vel, Color accentCol, bool isRocket, Vector3 camPos, bool hasCam)
|
||||
{
|
||||
EnsureInitialized();
|
||||
if (hasCam && pos.DistanceSquaredTo(camPos) > 220f * 220f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 backVel = vel.LengthSquared() > 1f ? -vel.Normalized() * 4.5f : Vector3.Up * 1.2f;
|
||||
if (isRocket)
|
||||
{
|
||||
SpawnParticle(new ParticleSlot
|
||||
{
|
||||
Active = true,
|
||||
Mode = ModeMuzzleStarburst,
|
||||
Position = pos,
|
||||
Velocity = backVel * 0.4f,
|
||||
StartSize = 0.58f,
|
||||
EndSize = 0.20f,
|
||||
AspectY = 1f,
|
||||
Rotation = NextFloat() * MathF.Tau,
|
||||
Emissive = 2.8f,
|
||||
ColorStart = new Color(1.0f, 0.72f, 0.24f, 0.92f),
|
||||
ColorEnd = accentCol with { A = 0f },
|
||||
Lifetime = 0.12f
|
||||
});
|
||||
SpawnParticle(new ParticleSlot
|
||||
{
|
||||
Active = true,
|
||||
Mode = ModeDustSmoke,
|
||||
Position = pos,
|
||||
Velocity = backVel * 0.25f + new Vector3(NextSigned() * 0.6f, 0.7f, NextSigned() * 0.6f),
|
||||
Gravity = -0.15f,
|
||||
Drag = 1.8f,
|
||||
StartSize = 0.32f,
|
||||
EndSize = 1.25f,
|
||||
AspectY = 1f,
|
||||
Rotation = NextFloat() * MathF.Tau,
|
||||
AngularVel = NextSigned() * 1.4f,
|
||||
Emissive = 0f,
|
||||
ColorStart = new Color(0.58f, 0.54f, 0.48f, 0.46f),
|
||||
ColorEnd = new Color(0.40f, 0.38f, 0.36f, 0f),
|
||||
Lifetime = 0.42f
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
SpawnParticle(new ParticleSlot
|
||||
{
|
||||
Active = true,
|
||||
Mode = ModeSparkStreak,
|
||||
Position = pos,
|
||||
Velocity = backVel * 0.25f,
|
||||
StartSize = 0.24f,
|
||||
EndSize = 0.08f,
|
||||
AspectY = 1.4f,
|
||||
Rotation = NextFloat() * MathF.Tau,
|
||||
Emissive = 2.4f,
|
||||
ColorStart = accentCol with { A = 0.90f },
|
||||
ColorEnd = accentCol with { A = 0f },
|
||||
Lifetime = 0.16f
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void EmitOrdnanceBurst(Vector3 pos, Color accentCol, int sparkCount, float radiusScale, Vector3 camPos, bool hasCam)
|
||||
{
|
||||
EnsureInitialized();
|
||||
if (hasCam && pos.DistanceSquaredTo(camPos) > 220f * 220f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SpawnParticle(new ParticleSlot
|
||||
{
|
||||
Active = true,
|
||||
Mode = ModeSteamFire,
|
||||
Position = pos,
|
||||
Velocity = Vector3.Up * 1.5f,
|
||||
StartSize = 0.65f * radiusScale,
|
||||
EndSize = 2.2f * radiusScale,
|
||||
AspectY = 1f,
|
||||
Rotation = NextFloat() * MathF.Tau,
|
||||
Emissive = 2.8f,
|
||||
ColorStart = accentCol with { A = 0.94f },
|
||||
ColorEnd = new Color(0.24f, 0.16f, 0.14f, 0f),
|
||||
Lifetime = 0.34f
|
||||
});
|
||||
SpawnSparkBurst(pos, Vector3.Up, Math.Clamp(sparkCount, 1, 8), accentCol with { A = 0.98f }, 12f * radiusScale);
|
||||
}
|
||||
|
||||
public void EmitThermalPoolEmber(Vector3 pos, float radius, Color accentCol, Vector3 camPos, bool hasCam)
|
||||
{
|
||||
EnsureInitialized();
|
||||
if (hasCam && pos.DistanceSquaredTo(camPos) > 150f * 150f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float ang = NextFloat() * MathF.Tau;
|
||||
float r = MathF.Sqrt(NextFloat()) * MathF.Max(0.5f, radius * 0.85f);
|
||||
Vector3 p = pos + new Vector3(MathF.Cos(ang) * r, 0.18f, MathF.Sin(ang) * r);
|
||||
SpawnParticle(new ParticleSlot
|
||||
{
|
||||
Active = true,
|
||||
Mode = ModeSteamFire,
|
||||
Position = p,
|
||||
Velocity = new Vector3(NextSigned() * 0.5f, 1.8f + NextFloat() * 1.4f, NextSigned() * 0.5f),
|
||||
Gravity = -0.3f,
|
||||
Drag = 1.2f,
|
||||
StartSize = 0.36f,
|
||||
EndSize = 0.92f,
|
||||
AspectY = 1.25f,
|
||||
Rotation = NextFloat() * MathF.Tau,
|
||||
Emissive = 2.9f,
|
||||
ColorStart = accentCol with { A = 0.88f },
|
||||
ColorEnd = accentCol with { A = 0f },
|
||||
Lifetime = 0.45f
|
||||
});
|
||||
}
|
||||
|
||||
private void EmitChassisExplosion(
|
||||
Vector3 pos,
|
||||
float massKg,
|
||||
|
|
|
|||
|
|
@ -95,17 +95,39 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
public required float MaxY { get; init; }
|
||||
}
|
||||
|
||||
public sealed class WeaponPartTemplate
|
||||
{
|
||||
public required string Id { get; init; }
|
||||
public required string Slot { get; init; }
|
||||
public required string GlbPath { get; init; }
|
||||
public required Node3D SceneTemplate { get; init; }
|
||||
public required ArrayMesh SingleSurfaceMesh { get; init; }
|
||||
public required Vector3 Size { get; init; }
|
||||
public required float MinY { get; init; }
|
||||
public required IReadOnlyDictionary<string, Transform3D> SocketsLocal { get; init; }
|
||||
}
|
||||
|
||||
public static readonly string[] ExpectedGearIds =
|
||||
{
|
||||
"mg_762", "autocannon", "recoilless", "copper_rad", "gilded_lance", "gold_radiator"
|
||||
};
|
||||
|
||||
public static readonly string[] ExpectedWeaponPartIds =
|
||||
{
|
||||
"rx_salvage_frame", "rx_korrathi_cradle", "rx_auralian_prism", "rx_vex_pod_rack",
|
||||
"brl_autocannon", "brl_sabot_rail", "brl_prism_lance", "brl_missile_tube",
|
||||
"fd_belt_drum", "fd_rotary_loader", "fd_capacitor_bank", "fd_swarm_magazine",
|
||||
"mz_slotted_brake", "mz_mirv_warhead", "mz_loiter_aero_fin", "mz_plasma_diffuser"
|
||||
};
|
||||
|
||||
private readonly Dictionary<string, VehicleTemplate> _vehicles = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, GearTemplate> _gear = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, WeaponPartTemplate> _weaponParts = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, ArrayMesh> _gearVariantMeshes = new(StringComparer.OrdinalIgnoreCase);
|
||||
private DropPodTemplate? _dropPod;
|
||||
private readonly string _vehiclesDir;
|
||||
private readonly string _gearDir;
|
||||
private readonly string _weaponPartsDir;
|
||||
private bool _disposed;
|
||||
|
||||
public VehicleAssetCache()
|
||||
|
|
@ -118,10 +140,12 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
{
|
||||
throw new DirectoryNotFoundException($"Could not locate gear directory '{_gearDir}'.");
|
||||
}
|
||||
_weaponPartsDir = Path.Combine(_gearDir, "parts");
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<string, VehicleTemplate> Vehicles => _vehicles;
|
||||
public IReadOnlyDictionary<string, GearTemplate> Gear => _gear;
|
||||
public IReadOnlyDictionary<string, WeaponPartTemplate> WeaponParts => _weaponParts;
|
||||
|
||||
public void PreloadAll()
|
||||
{
|
||||
|
|
@ -133,9 +157,32 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
{
|
||||
GetOrLoadGear(gearId);
|
||||
}
|
||||
foreach (string partId in ExpectedWeaponPartIds)
|
||||
{
|
||||
GetOrLoadWeaponPart(partId);
|
||||
}
|
||||
GetOrLoadDropPod();
|
||||
}
|
||||
|
||||
public WeaponPartTemplate GetOrLoadWeaponPart(string partId)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
if (_weaponParts.TryGetValue(partId, out var cached))
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
string glbPath = Path.Combine(_weaponPartsDir, $"{partId}.glb");
|
||||
if (!File.Exists(glbPath))
|
||||
{
|
||||
throw new FileNotFoundException($"Missing modular weapon part GLB '{partId}': {glbPath}", glbPath);
|
||||
}
|
||||
|
||||
var template = LoadWeaponPartTemplate(partId, glbPath);
|
||||
_weaponParts[partId] = template;
|
||||
return template;
|
||||
}
|
||||
|
||||
public DropPodTemplate GetOrLoadDropPod()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
|
@ -597,6 +644,89 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
};
|
||||
}
|
||||
|
||||
private static WeaponPartTemplate LoadWeaponPartTemplate(string partId, string glbPath)
|
||||
{
|
||||
var doc = new GltfDocument();
|
||||
var state = new GltfState();
|
||||
Error err = doc.AppendFromFile(glbPath, state, flags: 0, basePath: Path.GetDirectoryName(glbPath) ?? string.Empty);
|
||||
if (err != Error.Ok)
|
||||
{
|
||||
throw new InvalidOperationException($"GltfDocument.AppendFromFile failed for weapon part '{glbPath}': {err}");
|
||||
}
|
||||
|
||||
Node? generated = doc.GenerateScene(state);
|
||||
if (generated is not Node3D sceneRoot)
|
||||
{
|
||||
generated?.QueueFree();
|
||||
throw new InvalidOperationException($"GltfDocument.GenerateScene did not return a Node3D for weapon part '{glbPath}'.");
|
||||
}
|
||||
ClearOwnerRecursive(sceneRoot);
|
||||
|
||||
var modelTransforms = new Dictionary<Node, Transform3D>();
|
||||
CollectModelTransforms(sceneRoot, Transform3D.Identity, modelTransforms);
|
||||
|
||||
string partSlot = "unknown";
|
||||
var sockets = new Dictionary<string, Transform3D>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
byte[] jsonBytes = ReadGlbJsonChunk(glbPath);
|
||||
using (var jsonDoc = JsonDocument.Parse(jsonBytes))
|
||||
{
|
||||
if (jsonDoc.RootElement.TryGetProperty("nodes", out JsonElement jsonNodes) &&
|
||||
jsonNodes.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
var gltfNodes = state.Nodes;
|
||||
int nodeCount = Math.Min(gltfNodes.Count, jsonNodes.GetArrayLength());
|
||||
for (int i = 0; i < nodeCount; i++)
|
||||
{
|
||||
JsonElement jn = jsonNodes[i];
|
||||
if (!jn.TryGetProperty("extras", out JsonElement extras) || extras.ValueKind != JsonValueKind.Object)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
GltfNode gn = gltfNodes[i];
|
||||
string origName = !string.IsNullOrEmpty(gn.OriginalName)
|
||||
? gn.OriginalName
|
||||
: (jn.TryGetProperty("name", out var nm) ? nm.GetString() ?? $"node_{i}" : $"node_{i}");
|
||||
Node? resolved = ResolveSceneNode(sceneRoot, gn.GetSceneNodePath(state), origName);
|
||||
if (resolved is not Node3D n3d)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (extras.TryGetProperty("rtd.part_slot", out var slotEl) && slotEl.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
partSlot = slotEl.GetString() ?? partSlot;
|
||||
}
|
||||
if (extras.TryGetProperty("rtd.socket", out var sockEl) && sockEl.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
string? sockName = sockEl.GetString();
|
||||
if (!string.IsNullOrWhiteSpace(sockName) && modelTransforms.TryGetValue(n3d, out Transform3D sockXf))
|
||||
{
|
||||
sockets[sockName] = sockXf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ComputeSceneMeshBounds(sceneRoot, out Vector3 bMin, out Vector3 bMax);
|
||||
ArrayMesh bakedMesh = BuildBakedStaticMesh(sceneRoot, coarseMaterials: false);
|
||||
ArrayMesh singleSurfaceMesh = CollapseToSingleSurfaceMechPaintMesh(bakedMesh);
|
||||
|
||||
return new WeaponPartTemplate
|
||||
{
|
||||
Id = partId,
|
||||
Slot = partSlot,
|
||||
GlbPath = glbPath,
|
||||
SceneTemplate = sceneRoot,
|
||||
SingleSurfaceMesh = singleSurfaceMesh,
|
||||
Size = bMax - bMin,
|
||||
MinY = bMin.Y,
|
||||
SocketsLocal = sockets
|
||||
};
|
||||
}
|
||||
|
||||
private static DropPodTemplate LoadDropPodTemplate(string glbPath)
|
||||
{
|
||||
var doc = new GltfDocument();
|
||||
|
|
@ -1453,6 +1583,33 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
string mName = (sm.ResourceName ?? string.Empty).ToLowerInvariant();
|
||||
roughness = Math.Clamp(sm.Roughness, 0.08f, 0.90f);
|
||||
|
||||
if (mName.Contains("mfg_primary"))
|
||||
{
|
||||
Color b = sm.AlbedoColor.SrgbToLinear();
|
||||
linearColor = new Vector3(b.R, b.G, b.B);
|
||||
band = 3;
|
||||
roughness = 0.50f;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mName.Contains("mfg_accent"))
|
||||
{
|
||||
Color b = sm.AlbedoColor.SrgbToLinear();
|
||||
linearColor = new Vector3(b.R, b.G, b.B);
|
||||
band = 4;
|
||||
roughness = 0.38f;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mName.Contains("mfg_glow"))
|
||||
{
|
||||
Color eCol = (sm.EmissionEnabled ? sm.Emission : sm.AlbedoColor).SrgbToLinear();
|
||||
linearColor = new Vector3(eCol.R, eCol.G, eCol.B);
|
||||
band = 5;
|
||||
roughness = 0.22f;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mName.Contains("lamp") || mName.Contains("glow") || mName.Contains("cyan") ||
|
||||
mName.Contains("amber") || mName.Contains("optic_red"))
|
||||
{
|
||||
|
|
@ -2229,8 +2386,16 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
g.SceneTemplate.QueueFree();
|
||||
}
|
||||
}
|
||||
foreach (var wp in _weaponParts.Values)
|
||||
{
|
||||
if (GodotObject.IsInstanceValid(wp.SceneTemplate))
|
||||
{
|
||||
wp.SceneTemplate.QueueFree();
|
||||
}
|
||||
}
|
||||
_vehicles.Clear();
|
||||
_gear.Clear();
|
||||
_weaponParts.Clear();
|
||||
if (_dropPod is not null && GodotObject.IsInstanceValid(_dropPod.SceneTemplate))
|
||||
{
|
||||
_dropPod.SceneTemplate.QueueFree();
|
||||
|
|
|
|||
|
|
@ -38,6 +38,11 @@ public sealed class VehicleVisualInstance
|
|||
public required ArrayMesh Mesh;
|
||||
}
|
||||
|
||||
public readonly record struct ModularWeaponPartBinding(
|
||||
ArrayMesh Mesh,
|
||||
Transform3D LocalToGearPivot,
|
||||
string Slot);
|
||||
|
||||
private sealed class BoundHardpoint
|
||||
{
|
||||
public required HardpointSpec Spec;
|
||||
|
|
@ -47,6 +52,10 @@ public sealed class VehicleVisualInstance
|
|||
public Node3D? GearNode;
|
||||
public ArrayMesh? GearMesh;
|
||||
public VehicleAssetCache.GearTemplate? GearTemplate;
|
||||
public ModularWeaponPartBinding[]? ModularParts;
|
||||
public float ManufacturerRoleIndex;
|
||||
public Vector3 ModularMuzzleTipLocal;
|
||||
public Vector3 ModularReceiverCenterLocal;
|
||||
public float HeatGlow;
|
||||
}
|
||||
|
||||
|
|
@ -384,8 +393,20 @@ public sealed class VehicleVisualInstance
|
|||
rearInModel = Vector3.Zero;
|
||||
if (!_hardpoints.TryGetValue(hardpointId, out var bh) ||
|
||||
bh.GearNode is null ||
|
||||
!GodotObject.IsInstanceValid(bh.GearNode) ||
|
||||
bh.GearTemplate is null)
|
||||
!GodotObject.IsInstanceValid(bh.GearNode))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Transform3D gearToModel = ComputeRelativeTransform(bh.GearNode, ModelRoot);
|
||||
if (bh.ModularParts is not null)
|
||||
{
|
||||
frontInModel = gearToModel * bh.ModularMuzzleTipLocal;
|
||||
rearInModel = gearToModel * bh.ModularReceiverCenterLocal;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (bh.GearTemplate is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -395,12 +416,52 @@ public sealed class VehicleVisualInstance
|
|||
return false;
|
||||
}
|
||||
|
||||
Transform3D gearToModel = ComputeRelativeTransform(bh.GearNode, ModelRoot);
|
||||
frontInModel = gearToModel * fLocal;
|
||||
rearInModel = gearToModel * rLocal;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void BuildModularWeaponAssembly(
|
||||
VehicleAssetCache cache,
|
||||
ModularWeaponAssembly assembly,
|
||||
out ModularWeaponPartBinding[] parts,
|
||||
out Vector3 muzzleTipLocal,
|
||||
out Vector3 receiverCenterLocal,
|
||||
out float minY)
|
||||
{
|
||||
var rxTpl = cache.GetOrLoadWeaponPart(assembly.ReceiverPartName);
|
||||
var brlTpl = cache.GetOrLoadWeaponPart(assembly.BarrelPartName);
|
||||
var fdTpl = cache.GetOrLoadWeaponPart(assembly.FeedPartName);
|
||||
var mzTpl = cache.GetOrLoadWeaponPart(assembly.MuzzlePartName);
|
||||
|
||||
Transform3D rxXf = Transform3D.Identity;
|
||||
Transform3D brlXf = rxTpl.SocketsLocal.TryGetValue("barrel", out var bx)
|
||||
? bx
|
||||
: new Transform3D(Basis.Identity, new Vector3(0f, 0.20f, 0.24f));
|
||||
Transform3D fdXf = rxTpl.SocketsLocal.TryGetValue("feed", out var fx)
|
||||
? fx
|
||||
: new Transform3D(Basis.Identity, new Vector3(0.14f, 0.20f, 0f));
|
||||
Transform3D brlMuzzle = brlTpl.SocketsLocal.TryGetValue("muzzle", out var mx)
|
||||
? mx
|
||||
: new Transform3D(Basis.Identity, new Vector3(0f, 0f, 0.55f));
|
||||
Transform3D mzXf = brlXf * brlMuzzle;
|
||||
Transform3D mzTip = mzTpl.SocketsLocal.TryGetValue("muzzle_tip", out var tx)
|
||||
? tx
|
||||
: new Transform3D(Basis.Identity, new Vector3(0f, 0f, 0.22f));
|
||||
|
||||
muzzleTipLocal = (mzXf * mzTip).Origin;
|
||||
receiverCenterLocal = new Vector3(0f, rxTpl.Size.Y * 0.5f, 0f);
|
||||
minY = rxTpl.MinY;
|
||||
|
||||
parts = new[]
|
||||
{
|
||||
new ModularWeaponPartBinding(rxTpl.SingleSurfaceMesh, rxXf, "receiver"),
|
||||
new ModularWeaponPartBinding(brlTpl.SingleSurfaceMesh, brlXf, "barrel"),
|
||||
new ModularWeaponPartBinding(fdTpl.SingleSurfaceMesh, fdXf, "feed"),
|
||||
new ModularWeaponPartBinding(mzTpl.SingleSurfaceMesh, mzXf, "muzzle")
|
||||
};
|
||||
}
|
||||
|
||||
public static void ResolveDropGearVisual(
|
||||
VehicleAssetCache cache,
|
||||
ModuleSpec mod,
|
||||
|
|
@ -443,6 +504,8 @@ public sealed class VehicleVisualInstance
|
|||
bh.GearNode = null;
|
||||
bh.GearMesh = null;
|
||||
bh.GearTemplate = null;
|
||||
bh.ModularParts = null;
|
||||
bh.ManufacturerRoleIndex = 0f;
|
||||
bh.HeatGlow = 0f;
|
||||
bh.MountedModuleId = desiredId;
|
||||
|
||||
|
|
@ -451,16 +514,46 @@ public sealed class VehicleVisualInstance
|
|||
continue;
|
||||
}
|
||||
|
||||
Node3D gearNode = CreateGearPivotForHardpoint(
|
||||
mounted.Spec,
|
||||
bh.Spec,
|
||||
bh.AnchorInfo,
|
||||
out ArrayMesh gearMesh,
|
||||
out VehicleAssetCache.GearTemplate gearTemplate);
|
||||
bh.AnchorNode.AddChild(gearNode);
|
||||
bh.GearNode = gearNode;
|
||||
bh.GearMesh = gearMesh;
|
||||
bh.GearTemplate = gearTemplate;
|
||||
if (mounted.Spec.Procedural is { } proc)
|
||||
{
|
||||
BuildModularWeaponAssembly(
|
||||
_cache,
|
||||
proc.Assembly,
|
||||
out var modParts,
|
||||
out Vector3 muzzleTipLocal,
|
||||
out Vector3 receiverCenterLocal,
|
||||
out float minY);
|
||||
Transform3D mountXf = ComputeHardpointMountTransform(
|
||||
bh.Spec,
|
||||
bh.AnchorInfo,
|
||||
Vector3.One * proc.Assembly.VisualScale,
|
||||
localModelForwardZ: 1f,
|
||||
minY);
|
||||
var gearNode = new Node3D
|
||||
{
|
||||
Name = $"Mounted_{mounted.Spec.Id}_{bh.Spec.Id}",
|
||||
Transform = mountXf
|
||||
};
|
||||
bh.AnchorNode.AddChild(gearNode);
|
||||
bh.GearNode = gearNode;
|
||||
bh.ModularParts = modParts;
|
||||
bh.ManufacturerRoleIndex = 10f + (float)proc.Manufacturer;
|
||||
bh.ModularMuzzleTipLocal = muzzleTipLocal;
|
||||
bh.ModularReceiverCenterLocal = receiverCenterLocal;
|
||||
}
|
||||
else
|
||||
{
|
||||
Node3D gearNode = CreateGearPivotForHardpoint(
|
||||
mounted.Spec,
|
||||
bh.Spec,
|
||||
bh.AnchorInfo,
|
||||
out ArrayMesh gearMesh,
|
||||
out VehicleAssetCache.GearTemplate gearTemplate);
|
||||
bh.AnchorNode.AddChild(gearNode);
|
||||
bh.GearNode = gearNode;
|
||||
bh.GearMesh = gearMesh;
|
||||
bh.GearTemplate = gearTemplate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -533,21 +626,43 @@ public sealed class VehicleVisualInstance
|
|||
{
|
||||
_shearedHardpoints.Add(bh.Spec.Id);
|
||||
_hasAnyStrippedCell = true;
|
||||
if (bh.GearNode is not null && GodotObject.IsInstanceValid(bh.GearNode) && bh.GearMesh is not null)
|
||||
if (bh.GearNode is not null && GodotObject.IsInstanceValid(bh.GearNode))
|
||||
{
|
||||
Transform3D worldXf = bh.GearNode.IsInsideTree()
|
||||
? bh.GearNode.GlobalTransform
|
||||
: ComputeWorldTransformFallback(bh.GearNode);
|
||||
ArrayMesh gearMesh = bh.GearMesh;
|
||||
ModularWeaponPartBinding[]? modParts = bh.ModularParts;
|
||||
float mfgRole = bh.ManufacturerRoleIndex;
|
||||
ArrayMesh? gearMesh = bh.GearMesh;
|
||||
Node3D sheared = bh.GearNode;
|
||||
bh.GearNode = null;
|
||||
bh.GearMesh = null;
|
||||
bh.GearTemplate = null;
|
||||
bh.ModularParts = null;
|
||||
bh.ManufacturerRoleIndex = 0f;
|
||||
bh.MountedModuleId = null;
|
||||
bh.HeatGlow = 0f;
|
||||
sheared.GetParent()?.RemoveChild(sheared);
|
||||
sheared.QueueFree();
|
||||
debris.SpawnDetachedPart(gearMesh, worldXf, blastOrigin, vehicleVelocity, _roleIndex, impulseScale: 1.15f, applyScorch: true);
|
||||
|
||||
if (modParts is not null)
|
||||
{
|
||||
for (int p = 0; p < modParts.Length; p++)
|
||||
{
|
||||
debris.SpawnDetachedPart(
|
||||
modParts[p].Mesh,
|
||||
worldXf * modParts[p].LocalToGearPivot,
|
||||
blastOrigin,
|
||||
vehicleVelocity,
|
||||
mfgRole,
|
||||
impulseScale: 1.15f,
|
||||
applyScorch: true);
|
||||
}
|
||||
}
|
||||
else if (gearMesh is not null)
|
||||
{
|
||||
debris.SpawnDetachedPart(gearMesh, worldXf, blastOrigin, vehicleVelocity, _roleIndex, impulseScale: 1.15f, applyScorch: true);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -620,12 +735,24 @@ public sealed class VehicleVisualInstance
|
|||
for (int i = 0; i < _hardpointList.Count; i++)
|
||||
{
|
||||
var bh = _hardpointList[i];
|
||||
if (bh.GearNode is null || bh.GearMesh is null || !GodotObject.IsInstanceValid(bh.GearNode))
|
||||
if (bh.GearNode is null || !GodotObject.IsInstanceValid(bh.GearNode))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Transform3D xf = bh.GearNode.IsInsideTree() ? bh.GearNode.GlobalTransform : ComputeWorldTransformFallback(bh.GearNode);
|
||||
pool.Submit(bh.GearMesh, in xf, new Color(0f, bh.HeatGlow, _roleIndex, 1f), wantsShadow: false);
|
||||
if (bh.ModularParts is { } modParts)
|
||||
{
|
||||
Color custom = new(0f, bh.HeatGlow, bh.ManufacturerRoleIndex, 1f);
|
||||
for (int p = 0; p < modParts.Length; p++)
|
||||
{
|
||||
Transform3D partXf = xf * modParts[p].LocalToGearPivot;
|
||||
pool.Submit(modParts[p].Mesh, in partXf, in custom, wantsShadow: false);
|
||||
}
|
||||
}
|
||||
else if (bh.GearMesh is not null)
|
||||
{
|
||||
pool.Submit(bh.GearMesh, in xf, new Color(0f, bh.HeatGlow, _roleIndex, 1f), wantsShadow: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -712,8 +839,26 @@ public sealed class VehicleVisualInstance
|
|||
GearVisualRecipe recipe = ResolveGearRecipe(mod);
|
||||
gearTemplate = _cache.GetOrLoadGear(recipe.GearGlbId);
|
||||
gearMesh = _cache.GetOrBuildGearVariantMesh(mod.Id, recipe.GearGlbId, recipe.PaintTint, recipe.AccentTint);
|
||||
var gearNode = new Node3D { Name = $"Mounted_{mod.Id}_{hp.Id}" };
|
||||
Transform3D xf = ComputeHardpointMountTransform(
|
||||
hp,
|
||||
anchorInfo,
|
||||
recipe.VariantScale,
|
||||
gearTemplate.LocalModelForward.Z,
|
||||
gearTemplate.MinY);
|
||||
return new Node3D
|
||||
{
|
||||
Name = $"Mounted_{mod.Id}_{hp.Id}",
|
||||
Transform = xf
|
||||
};
|
||||
}
|
||||
|
||||
private static Transform3D ComputeHardpointMountTransform(
|
||||
HardpointSpec hp,
|
||||
VehicleAssetCache.GlbAnchorInfo anchorInfo,
|
||||
Vector3 variantScale,
|
||||
float localModelForwardZ,
|
||||
float minY)
|
||||
{
|
||||
Basis anchorModelBasis = anchorInfo.ModelSpaceTransform.Basis.Orthonormalized();
|
||||
Vector3 upOut = anchorModelBasis.Y.Normalized();
|
||||
if (upOut.LengthSquared() < 1e-6f) upOut = Vector3.Up;
|
||||
|
|
@ -755,7 +900,7 @@ public sealed class VehicleVisualInstance
|
|||
desiredGearFwd = rightX.Cross(upOut).Normalized();
|
||||
var desiredModelBasis = new Basis(rightX, upOut, desiredGearFwd);
|
||||
|
||||
if (gearTemplate.LocalModelForward.Z < 0f)
|
||||
if (localModelForwardZ < 0f)
|
||||
{
|
||||
desiredModelBasis *= new Basis(Vector3.Up, MathF.PI);
|
||||
}
|
||||
|
|
@ -768,7 +913,7 @@ public sealed class VehicleVisualInstance
|
|||
if (hp.Kind == HardpointKind.Weapon)
|
||||
{
|
||||
float baseScale = Math.Clamp(MathF.Min(sx, sy) / 0.56f, 0.72f, 1.75f);
|
||||
fitScale = recipe.VariantScale * baseScale;
|
||||
fitScale = variantScale * baseScale;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -776,15 +921,15 @@ public sealed class VehicleVisualInstance
|
|||
float scaleZ = Math.Clamp(sy / 0.45f, 0.72f, 2.15f);
|
||||
float scaleY = Math.Clamp(0.5f * (scaleX + scaleZ), 0.72f, 1.85f);
|
||||
fitScale = new Vector3(
|
||||
recipe.VariantScale.X * scaleX,
|
||||
recipe.VariantScale.Y * scaleY,
|
||||
recipe.VariantScale.Z * scaleZ);
|
||||
variantScale.X * scaleX,
|
||||
variantScale.Y * scaleY,
|
||||
variantScale.Z * scaleZ);
|
||||
}
|
||||
|
||||
gearNode.Basis = localBasis * Basis.FromScale(fitScale);
|
||||
float ySeat = -gearTemplate.MinY * fitScale.Y;
|
||||
gearNode.Position = (anchorModelBasis.Inverse() * upOut) * ySeat;
|
||||
return gearNode;
|
||||
Basis finalBasis = localBasis * Basis.FromScale(fitScale);
|
||||
float ySeat = -minY * fitScale.Y;
|
||||
Vector3 pos = (anchorModelBasis.Inverse() * upOut) * ySeat;
|
||||
return new Transform3D(finalBasis, pos);
|
||||
}
|
||||
|
||||
private static GearVisualRecipe ResolveGearRecipe(ModuleSpec mod)
|
||||
|
|
@ -886,9 +1031,22 @@ public sealed class VehicleVisualInstance
|
|||
for (int i = 0; i < _hardpointList.Count; i++)
|
||||
{
|
||||
var bh = _hardpointList[i];
|
||||
if (bh.GearNode is not null && bh.GearMesh is not null && GodotObject.IsInstanceValid(bh.GearNode))
|
||||
if (bh.GearNode is null || !GodotObject.IsInstanceValid(bh.GearNode))
|
||||
{
|
||||
AccumulateMeshMinMaxY(bh.GearMesh, ComputeRelativeTransform(bh.GearNode, Root), out _, out float gyMax);
|
||||
continue;
|
||||
}
|
||||
Transform3D gearRel = ComputeRelativeTransform(bh.GearNode, Root);
|
||||
if (bh.ModularParts is { } modParts)
|
||||
{
|
||||
for (int p = 0; p < modParts.Length; p++)
|
||||
{
|
||||
AccumulateMeshMinMaxY(modParts[p].Mesh, gearRel * modParts[p].LocalToGearPivot, out _, out float pyMax);
|
||||
if (pyMax > maxY) maxY = pyMax;
|
||||
}
|
||||
}
|
||||
else if (bh.GearMesh is not null)
|
||||
{
|
||||
AccumulateMeshMinMaxY(bh.GearMesh, gearRel, out _, out float gyMax);
|
||||
if (gyMax > maxY) maxY = gyMax;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,6 +142,16 @@ void resolve_role_armor(int role, out vec3 col, out float met, out float rgh) {
|
|||
col = vec3(0.011, 0.011, 0.016); met = 0.45; rgh = 0.42; // SpectatorExemplar (#1b1b22)
|
||||
} else if (role == 5) {
|
||||
col = vec3(0.089, 0.105, 0.107); met = 0.55; rgh = 0.48; // SalvageDrop (#545b5c)
|
||||
} else if (role == 10) {
|
||||
col = vec3(0.076, 0.095, 0.051); met = 0.30; rgh = 0.58; // ScrapFrontier (#4e5740)
|
||||
} else if (role == 11) {
|
||||
col = vec3(0.017, 0.019, 0.022); met = 0.72; rgh = 0.40; // KorrathiIronworks (#232629)
|
||||
} else if (role == 12) {
|
||||
col = vec3(0.888, 0.823, 0.687); met = 0.18; rgh = 0.34; // AuralianOptics (#f2ead8)
|
||||
} else if (role == 13) {
|
||||
col = vec3(0.023, 0.028, 0.039); met = 0.50; rgh = 0.38; // VexNineCollective (#2a2f38)
|
||||
} else if (role == 14) {
|
||||
col = vec3(0.013, 0.127, 0.138); met = 0.56; rgh = 0.36; // ThalassanForge (#1e6468)
|
||||
} else {
|
||||
col = vec3(0.076, 0.095, 0.051); met = 0.28; rgh = 0.58; // Player (#4e5740)
|
||||
}
|
||||
|
|
@ -159,11 +169,35 @@ void resolve_role_accent(int role, out vec3 col, out float met, out float rgh, o
|
|||
col = vec3(0.584, 0.023, 0.023); met = 0.25; rgh = 0.36; emit_e = 0.65; // SpectatorExemplar (#c92a2a)
|
||||
} else if (role == 5) {
|
||||
col = vec3(0.058, 0.694, 0.807); met = 0.22; rgh = 0.34; emit_e = 0.45; // SalvageDrop (#44d9e8)
|
||||
} else if (role == 10) {
|
||||
col = vec3(0.258, 0.068, 0.024); met = 0.34; rgh = 0.52; // ScrapFrontier rust (#8b4a2b)
|
||||
} else if (role == 11) {
|
||||
col = vec3(0.753, 0.048, 0.010); met = 0.22; rgh = 0.42; // KorrathiIronworks hazard-red (#e13e1a)
|
||||
} else if (role == 12) {
|
||||
col = vec3(0.791, 0.479, 0.039); met = 0.88; rgh = 0.26; // AuralianOptics gold (#e6b838)
|
||||
} else if (role == 13) {
|
||||
col = vec3(0.258, 0.061, 0.658); met = 0.32; rgh = 0.36; emit_e = 0.15; // VexNineCollective violet (#8b46d4)
|
||||
} else if (role == 14) {
|
||||
col = vec3(0.578, 0.168, 0.039); met = 0.86; rgh = 0.30; // ThalassanForge copper-brass (#c87238)
|
||||
} else {
|
||||
col = vec3(0.694, 0.150, 0.020); met = 0.18; rgh = 0.44; // Player (#d96c27)
|
||||
}
|
||||
}
|
||||
|
||||
void resolve_role_glow(int role, inout vec3 col) {
|
||||
if (role == 10) {
|
||||
col = vec3(1.000, 0.402, 0.033); // ScrapFrontier amber (#ffaa33)
|
||||
} else if (role == 11) {
|
||||
col = vec3(0.888, 0.552, 0.016); // KorrathiIronworks hazard-yellow (#f2c422)
|
||||
} else if (role == 12) {
|
||||
col = vec3(0.039, 0.807, 1.000); // AuralianOptics cyan (#38e8ff)
|
||||
} else if (role == 13) {
|
||||
col = vec3(0.201, 0.888, 0.030); // VexNineCollective lime-optic (#7cf230)
|
||||
} else if (role == 14) {
|
||||
col = vec3(0.025, 0.479, 1.000); // ThalassanForge electric-blue (#2cb8ff)
|
||||
}
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
if (v_alpha < 0.99) {
|
||||
float dither = fract(sin(dot(floor(FRAGCOORD.xy), vec2(12.9898, 78.233))) * 43758.5453);
|
||||
|
|
@ -194,6 +228,9 @@ void fragment() {
|
|||
} else if (band == 4) {
|
||||
resolve_role_accent(role, mat_base_col, mat_metal, mat_rough, mat_static_emit);
|
||||
} else if (band == 5) {
|
||||
if (role >= 10 && role <= 14) {
|
||||
resolve_role_glow(role, mat_base_col);
|
||||
}
|
||||
mat_metal = 0.15;
|
||||
mat_static_emit = 1.85;
|
||||
mat_wear = 0.0;
|
||||
|
|
|
|||
|
|
@ -277,6 +277,7 @@ public partial class Smoke : Node
|
|||
await VerifyMaxLoadPaladinGarageAsync();
|
||||
await VerifySionMapAsync();
|
||||
await VerifyOrbitalDropSequenceAsync();
|
||||
await VerifyCut7bModularOrdnanceAsync();
|
||||
}
|
||||
|
||||
private async Task VerifyHudAndShadersAsync(bool isHeadless)
|
||||
|
|
@ -2006,6 +2007,275 @@ public partial class Smoke : Node
|
|||
GD.Print($"SMOKE INFO: Cut 6b OrbitalDrop verified (touchdownTick={touchdownTick}, debris={debrisAtTouchdown}, postDisp={postDisp:F2}m, bucketsDelta={bucketsDuringDrop - bucketsBefore}, matDups={VehicleVisualInstance.PerfMaterialDupCount})");
|
||||
}
|
||||
|
||||
private async Task VerifyCut7bModularOrdnanceAsync()
|
||||
{
|
||||
var cache = _main.Arena.AssetCache;
|
||||
var partPool = _main.Arena.PartPool;
|
||||
|
||||
// 1. All 16 modular weapon sub-parts loaded with single-surface COLOR_0 meshes and required sockets
|
||||
Check(cache.WeaponParts.Count == 16, $"Expected 16 cached modular weapon parts, got {cache.WeaponParts.Count}");
|
||||
foreach (string pid in VehicleAssetCache.ExpectedWeaponPartIds)
|
||||
{
|
||||
var wp = cache.GetOrLoadWeaponPart(pid);
|
||||
Check(wp.SingleSurfaceMesh.GetSurfaceCount() == 1,
|
||||
$"Expected 1 surface on modular part '{pid}', got {wp.SingleSurfaceMesh.GetSurfaceCount()}");
|
||||
var arr = wp.SingleSurfaceMesh.SurfaceGetArrays(0);
|
||||
Check(arr.Count > (int)Mesh.ArrayType.Color && arr[(int)Mesh.ArrayType.Color].VariantType == Variant.Type.PackedColorArray,
|
||||
$"Modular part '{pid}' missing COLOR_0 attribute");
|
||||
if (wp.Slot == "receiver")
|
||||
{
|
||||
Check(wp.SocketsLocal.ContainsKey("barrel") && wp.SocketsLocal.ContainsKey("feed"),
|
||||
$"Receiver '{pid}' missing barrel/feed sockets");
|
||||
}
|
||||
else if (wp.Slot == "barrel")
|
||||
{
|
||||
Check(wp.SocketsLocal.ContainsKey("muzzle"), $"Barrel '{pid}' missing muzzle socket");
|
||||
}
|
||||
else if (wp.Slot == "muzzle")
|
||||
{
|
||||
Check(wp.SocketsLocal.ContainsKey("muzzle_tip"), $"Muzzle '{pid}' missing muzzle_tip socket");
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Mount 50 distinct procedural weapons across all 5 manufacturers & 20 archetypes -> <= 16 new PartPool buckets, 0 matDups
|
||||
VehicleVisualInstance.PerfMaterialDupCount = 0;
|
||||
var testVis = VehicleVisualInstance.Create(cache, "anvil", VehicleVisualRole.Player);
|
||||
AddChild(testVis.Root);
|
||||
var testGrid = Catalog.CreateWithDefaultLoadout(Catalog.Anvil);
|
||||
string? weaponHpId = null;
|
||||
for (int i = 0; i < testGrid.Spec.Hardpoints.Length; i++)
|
||||
{
|
||||
if (testGrid.Spec.Hardpoints[i].Kind == HardpointKind.Weapon &&
|
||||
testGrid.Spec.Hardpoints[i].Height >= 2)
|
||||
{
|
||||
weaponHpId = testGrid.Spec.Hardpoints[i].Id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Check(weaponHpId is not null, "Expected Anvil to have a 1x2 weapon hardpoint for modular assembly test");
|
||||
|
||||
// Pre-warm baseline Anvil chassis/cell buckets in PartPool so bucketDelta measures ONLY modular weapon parts
|
||||
if (weaponHpId is not null)
|
||||
{
|
||||
testGrid.Mounted.RemoveAll(m => m.HardpointId == weaponHpId);
|
||||
}
|
||||
testVis.SyncMountedGear(testGrid);
|
||||
partPool.BeginFrame(null);
|
||||
testVis.SubmitToPool(partPool);
|
||||
partPool.EndFrame();
|
||||
int bucketsBefore = partPool.BucketCount;
|
||||
|
||||
partPool.BeginFrame(null);
|
||||
if (weaponHpId is not null)
|
||||
{
|
||||
for (int w = 0; w < 50; w++)
|
||||
{
|
||||
byte mfg = (byte)(w % 5);
|
||||
byte arch = (byte)(mfg * 4 + (w % 4));
|
||||
var pSpec = ProceduralWeaponGenerator.Generate(new ProceduralWeaponKey((ulong)(0xA100 + w), mfg, arch, (byte)(w & 3), 0));
|
||||
testGrid.Mounted.RemoveAll(m => m.HardpointId == weaponHpId);
|
||||
Check(testGrid.TryMount(pSpec.Module, weaponHpId), $"Failed to mount procedural weapon '{pSpec.DisplayName}' on '{weaponHpId}'");
|
||||
testVis.SyncMountedGear(testGrid);
|
||||
testVis.SubmitToPool(partPool);
|
||||
|
||||
if (w < 5)
|
||||
{
|
||||
bool hasAim = testVis.TryGetMountedWeaponCentroidsInModel(weaponHpId, "muzzle", "receiver", out Vector3 frontC, out Vector3 rearC);
|
||||
Check(hasAim && (frontC.Z > rearC.Z + 0.35f),
|
||||
$"Expected modular weapon '{pSpec.DisplayName}' muzzle ({frontC}) forward of receiver ({rearC})");
|
||||
}
|
||||
}
|
||||
}
|
||||
partPool.EndFrame();
|
||||
|
||||
int bucketDelta = partPool.BucketCount - bucketsBefore;
|
||||
Check(bucketDelta <= 16, $"Expected 50 procedural weapons to add <= 16 PartPool buckets, added {bucketDelta}");
|
||||
Check(VehicleVisualInstance.PerfMaterialDupCount == 0, $"Expected 0 material duplications, got {VehicleVisualInstance.PerfMaterialDupCount}");
|
||||
Check(CountMeshInstances(testVis.Root) == 0, $"Expected 0 MeshInstance3D children on modular vehicle rig, got {CountMeshInstances(testVis.Root)}");
|
||||
|
||||
// Verify shearing a modular weapon hardpoint spawns all 4 sub-parts into DebrisSystem
|
||||
if (weaponHpId is not null)
|
||||
{
|
||||
var testDebris = new DebrisSystem { Name = "SmokeModularShearDebris" };
|
||||
AddChild(testDebris);
|
||||
var hp = testGrid.FindHardpoint(weaponHpId)!;
|
||||
for (int dy = 0; dy < hp.Height; dy++)
|
||||
{
|
||||
for (int dx = 0; dx < hp.Width; dx++)
|
||||
{
|
||||
testGrid.Armor[hp.X + dx, hp.Y + dy] = 0f;
|
||||
}
|
||||
}
|
||||
testVis.SyncDamageAndHeat(testGrid, testDebris, Vector3.Zero);
|
||||
Check(testDebris.ActiveCount >= 4, $"Expected >= 4 sheared modular sub-parts in DebrisSystem, got {testDebris.ActiveCount}");
|
||||
testDebris.QueueFree();
|
||||
}
|
||||
testVis.Root.QueueFree();
|
||||
|
||||
// 3. Procedural weapon GroundDrops render with modular parts & clean up on pickup
|
||||
_main.Reset(77, ArenaMapKind.Desert, skipInitialDrop: true);
|
||||
_main.SetPhysicsProcess(false);
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
|
||||
var state = _main.Session.ViewState;
|
||||
var player = _main.Session.LocalContender;
|
||||
int dropsBefore = state.GroundDrops.Count;
|
||||
_main.Arena.Sync(_main.Session, 1.0f, 1f / 60f, 1f);
|
||||
int trackedBefore = _main.Arena.ActiveDropVisualCount;
|
||||
|
||||
var procDrops = new List<GroundDrop>(5);
|
||||
for (int m = 0; m < 5; m++)
|
||||
{
|
||||
var pSpec = ProceduralWeaponGenerator.RollForManufacturer((ManufacturerId)m, tier: 2, seed: (ulong)(0x7700 + m));
|
||||
var gd = new GroundDrop(95000 + m, player.X + 4f + m * 6f, player.Z + 8f, null, pSpec.Module);
|
||||
state.GroundDrops.Add(gd);
|
||||
procDrops.Add(gd);
|
||||
}
|
||||
_main.Arena.Sync(_main.Session, 1.1f, 1f / 60f, 1f);
|
||||
Check(_main.Arena.ActiveDropVisualCount == trackedBefore + 5,
|
||||
$"Expected {trackedBefore + 5} tracked drops after adding 5 mfg drops, got {_main.Arena.ActiveDropVisualCount}");
|
||||
|
||||
// 4. HUD 6 chrome panels, 2-line Borderlands tooltips (Garage + Hover + Pickup Prompt), zero overlap at 1280x720
|
||||
var sabotDream = ProceduralWeaponGenerator.CreateDreamSabotSled();
|
||||
var droneDream = ProceduralWeaponGenerator.CreateDreamLoiteringDrone();
|
||||
var mirvDream = ProceduralWeaponGenerator.CreateDreamMirvMineBlanket();
|
||||
|
||||
var pGrid = player.Grid;
|
||||
string? pWeaponHp = null;
|
||||
HardpointSpec? pWeaponHpSpec = null;
|
||||
for (int i = 0; i < pGrid.Spec.Hardpoints.Length; i++)
|
||||
{
|
||||
if (pGrid.Spec.Hardpoints[i].Kind == HardpointKind.Weapon && pGrid.Spec.Hardpoints[i].Height >= 2)
|
||||
{
|
||||
pWeaponHp = pGrid.Spec.Hardpoints[i].Id;
|
||||
pWeaponHpSpec = pGrid.Spec.Hardpoints[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pWeaponHp is not null && pWeaponHpSpec is not null)
|
||||
{
|
||||
pGrid.Mounted.RemoveAll(m => m.HardpointId == pWeaponHp);
|
||||
Check(pGrid.TryMount(sabotDream.Module, pWeaponHp), "Expected Dream Sabot Sled to mount on player");
|
||||
if (!_main.Hud.GarageExpanded) _main.Hud.ToggleGarage();
|
||||
_main.Hud.Sync(_main.Session);
|
||||
_main.Hud.SimulateCellHover(new Vector2I(pWeaponHpSpec.X, pWeaponHpSpec.Y), pWeaponHpSpec);
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
|
||||
int chromeCount = 0;
|
||||
foreach (var _ in _main.Hud.GetChromeMaterials()) chromeCount++;
|
||||
Check(chromeCount == 6, $"Expected 6 HUD chrome panels, got {chromeCount}");
|
||||
Check(_main.Hud.HoverLabelText.Contains(sabotDream.ManufacturerLabel) && _main.Hud.HoverLabelText.Contains('\n'),
|
||||
$"Expected 2-line Borderlands hover tooltip with manufacturer badge, got: {_main.Hud.HoverLabelText}");
|
||||
Check(_main.Hud.GarageDetailsText.Contains(sabotDream.SummaryLine1) && _main.Hud.GarageDetailsText.Contains(sabotDream.SummaryLine2),
|
||||
$"Expected Garage details to contain SummaryLine1 & SummaryLine2, got: {_main.Hud.GarageDetailsText}");
|
||||
|
||||
// Check nearby pickup prompt 2-line display
|
||||
var nearbyDrop = new GroundDrop(95999, player.X + 1.0f, player.Z + 1.0f, null, droneDream.Module);
|
||||
state.GroundDrops.Add(nearbyDrop);
|
||||
_main.Hud.Sync(_main.Session);
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
Check(_main.Hud.PromptLabelText.Contains(droneDream.ManufacturerLabel) && _main.Hud.PromptLabelText.Contains('\n'),
|
||||
$"Expected 2-line pickup prompt with manufacturer & summary, got: {_main.Hud.PromptLabelText}");
|
||||
|
||||
Vector2 vpSize = GetViewport().GetVisibleRect().Size;
|
||||
Check(!_main.Hud.HasPanelOverlapOrClip(vpSize), $"HUD overlapped or clipped with procedural tooltip at {vpSize}");
|
||||
|
||||
nearbyDrop.PickedUp = true;
|
||||
state.GroundDrops.Remove(nearbyDrop);
|
||||
if (_main.Hud.GarageExpanded) _main.Hud.ToggleGarage();
|
||||
}
|
||||
|
||||
for (int i = 0; i < procDrops.Count; i++) procDrops[i].PickedUp = true;
|
||||
_main.Arena.Sync(_main.Session, 1.2f, 1f / 60f, 1f);
|
||||
state.GroundDrops.RemoveRange(dropsBefore, procDrops.Count);
|
||||
|
||||
// 5. ClientOrdnanceMirror + Haven MWO Audio Hooks across Sabot, Loitering Drone, and MIRV Mines
|
||||
var localSession = (_main.Session as LocalArenaSession)!;
|
||||
var sim = localSession.Inner;
|
||||
for (int cIdx = 1; cIdx < sim.State.Contenders.Count; cIdx++)
|
||||
{
|
||||
sim.SetContenderPose(cIdx, 480f + cIdx * 12f, 480f);
|
||||
}
|
||||
sim.SetContenderPose(0, 0f, 0f, 0f);
|
||||
sim.SetContenderPose(1, 0f, 125f, MathF.PI); // target Anvil/rival 125m ahead
|
||||
|
||||
int audioShotsBefore = _main.Audio.Total3DPlaysRequested;
|
||||
bool sawMirrorRocket = false;
|
||||
bool sawSabotTransition = false;
|
||||
bool sawMirrorDrone = false;
|
||||
bool sawMirrorMines = false;
|
||||
|
||||
// 5a: Sabot Rocket Sled
|
||||
if (pWeaponHp is not null)
|
||||
{
|
||||
pGrid.Mounted.RemoveAll(m => m.HardpointId == pWeaponHp);
|
||||
pGrid.TryMount(sabotDream.Module, pWeaponHp);
|
||||
for (int t = 0; t < 35; t++)
|
||||
{
|
||||
var inp = new PlayerInput(0f, 0f, 0f, 125f, Fire: t == 0, InteractPickup: false, Brake: true);
|
||||
_main.Session.SubmitLocalInput(in inp, isPhysicsTick: true);
|
||||
var evs = new List<ISimEvent>(16);
|
||||
_main.Session.DrainSimEvents(evs);
|
||||
for (int e = 0; e < evs.Count; e++)
|
||||
{
|
||||
if (evs[e] is OrdnanceNodeEvent oe && (OrdnanceEventKind)oe.Kind == OrdnanceEventKind.StageTransition)
|
||||
{
|
||||
sawSabotTransition = true;
|
||||
}
|
||||
}
|
||||
_main.Arena.Sync(_main.Session, 2.0f + t / 60f, 1f / 60f, 1f);
|
||||
_main.Arena.ConsumeEvents(_main.Session, evs, Array.Empty<FootstepPulse>(), 1f / 60f, _main.SampleCurrentMapGroundTint);
|
||||
_main.Audio.UpdateFrame(_main.Session, evs, Array.Empty<FootstepPulse>(), _main.Camera.GlobalPosition, 1f / 60f, 1f);
|
||||
if (_main.Arena.OrdnanceMirror.ActiveCount > 0) sawMirrorRocket = true;
|
||||
}
|
||||
|
||||
// 5b: Loitering Laser Drone
|
||||
pGrid.Mounted.RemoveAll(m => m.HardpointId == pWeaponHp);
|
||||
pGrid.TryMount(droneDream.Module, pWeaponHp);
|
||||
for (int t = 0; t < 95; t++)
|
||||
{
|
||||
var inp = new PlayerInput(0f, 0f, 0f, 125f, Fire: t == 0, InteractPickup: false, Brake: true);
|
||||
_main.Session.SubmitLocalInput(in inp, isPhysicsTick: true);
|
||||
var evs = new List<ISimEvent>(16);
|
||||
_main.Session.DrainSimEvents(evs);
|
||||
_main.Arena.Sync(_main.Session, 3.0f + t / 60f, 1f / 60f, 1f);
|
||||
_main.Arena.ConsumeEvents(_main.Session, evs, Array.Empty<FootstepPulse>(), 1f / 60f, _main.SampleCurrentMapGroundTint);
|
||||
_main.Audio.UpdateFrame(_main.Session, evs, Array.Empty<FootstepPulse>(), _main.Camera.GlobalPosition, 1f / 60f, 1f);
|
||||
if (t > 70 && _main.Arena.OrdnanceMirror.ActiveCount > 0) sawMirrorDrone = true;
|
||||
}
|
||||
|
||||
// 5c: MIRV Minefield Blanket
|
||||
pGrid.Mounted.RemoveAll(m => m.HardpointId == pWeaponHp);
|
||||
pGrid.TryMount(mirvDream.Module, pWeaponHp);
|
||||
for (int t = 0; t < 160; t++)
|
||||
{
|
||||
var inp = new PlayerInput(0f, 0f, 0f, 85f, Fire: t == 0, InteractPickup: false, Brake: true);
|
||||
_main.Session.SubmitLocalInput(in inp, isPhysicsTick: true);
|
||||
var evs = new List<ISimEvent>(32);
|
||||
_main.Session.DrainSimEvents(evs);
|
||||
_main.Arena.Sync(_main.Session, 5.0f + t / 60f, 1f / 60f, 1f);
|
||||
_main.Arena.ConsumeEvents(_main.Session, evs, Array.Empty<FootstepPulse>(), 1f / 60f, _main.SampleCurrentMapGroundTint);
|
||||
_main.Audio.UpdateFrame(_main.Session, evs, Array.Empty<FootstepPulse>(), _main.Camera.GlobalPosition, 1f / 60f, 1f);
|
||||
if (_main.Arena.OrdnanceMirror.ActiveCount >= 6) sawMirrorMines = true;
|
||||
}
|
||||
}
|
||||
|
||||
Check(sawMirrorRocket && sawSabotTransition,
|
||||
$"Expected ClientOrdnanceMirror to track Sabot rocket & StageTransition (rocket={sawMirrorRocket}, trans={sawSabotTransition})");
|
||||
Check(sawMirrorDrone, "Expected ClientOrdnanceMirror to maintain active Loitering Laser Drone after climb");
|
||||
Check(sawMirrorMines, "Expected ClientOrdnanceMirror to mirror >= 6 MIRV mines after Split");
|
||||
Check(_main.Audio.Total3DPlaysRequested > audioShotsBefore,
|
||||
$"Expected ArenaAudioSystem Haven MWO ordnance cues to trigger (before={audioShotsBefore}, after={_main.Audio.Total3DPlaysRequested})");
|
||||
|
||||
// Verify MatchResetEvent clears ClientOrdnanceMirror cleanly
|
||||
_main.Arena.ConsumeEvents(_main.Session, new ISimEvent[] { new MatchResetEvent() }, Array.Empty<FootstepPulse>(), 1f / 60f, _main.SampleCurrentMapGroundTint);
|
||||
Check(_main.Arena.OrdnanceMirror.ActiveCount == 0,
|
||||
$"Expected MatchResetEvent to clear ClientOrdnanceMirror, got {_main.Arena.OrdnanceMirror.ActiveCount}");
|
||||
|
||||
_main.SetPhysicsProcess(true);
|
||||
GD.Print($"SMOKE INFO: Cut 7b verified (16 parts, bucketDelta={bucketDelta}, matDups={VehicleVisualInstance.PerfMaterialDupCount}, audioPlays={_main.Audio.Total3DPlaysRequested - audioShotsBefore})");
|
||||
}
|
||||
|
||||
private static int CountPremulViolations(Image img, float tolerance)
|
||||
{
|
||||
int count = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue