Cut 5d-1: Haven audio curation, WetMix PcmSynth, WalkerFootstepTracker & ArenaAudioSystem
This commit is contained in:
parent
9081d2bb5c
commit
7f811c3011
41 changed files with 3067 additions and 10 deletions
|
|
@ -24,6 +24,7 @@ public partial class Main : Node3D
|
|||
private TerrainRenderer _terrain = null!;
|
||||
private SionMapRenderer _sionMap = null!;
|
||||
private ArenaRenderer _arena = null!;
|
||||
private ArenaAudioSystem _audio = null!;
|
||||
private Camera3D _camera = null!;
|
||||
private Hud _hud = null!;
|
||||
private DirectionalLight3D _sun = null!;
|
||||
|
|
@ -32,6 +33,9 @@ public partial class Main : Node3D
|
|||
private IClientArenaSession? _session;
|
||||
private MatchState? _boundViewState;
|
||||
private bool _wasNetConnected;
|
||||
private readonly WalkerFootstepTracker _footsteps = new();
|
||||
private readonly List<ISimEvent> _frameEvents = new(128);
|
||||
private readonly List<FootstepPulse> _frameFootsteps = new(32);
|
||||
private ArenaMapKind _mapKind = ArenaMapKind.Sion;
|
||||
private string _callsign = "Pilot";
|
||||
private string _lastEndpoint = $"127.0.0.1:{DefaultNetPort}";
|
||||
|
|
@ -74,6 +78,8 @@ public partial class Main : Node3D
|
|||
public TerrainRenderer Terrain => _terrain;
|
||||
public SionMapRenderer SionMap => _sionMap;
|
||||
public ArenaRenderer Arena => _arena;
|
||||
public ArenaAudioSystem Audio => _audio;
|
||||
public WalkerFootstepTracker Footsteps => _footsteps;
|
||||
public Hud Hud => _hud;
|
||||
public ArenaMapKind MapKind => _mapKind;
|
||||
public ArenaMapKind? InitialMapKindOverride { get; set; }
|
||||
|
|
@ -94,6 +100,9 @@ public partial class Main : Node3D
|
|||
_arena = new ArenaRenderer { Name = "Arena" };
|
||||
AddChild(_arena);
|
||||
|
||||
_audio = new ArenaAudioSystem { Name = "ArenaAudio" };
|
||||
AddChild(_audio);
|
||||
|
||||
_camera = new Camera3D
|
||||
{
|
||||
Name = "ShoulderCamera",
|
||||
|
|
@ -392,6 +401,10 @@ public partial class Main : Node3D
|
|||
_cameraPitch = _mapKind == ArenaMapKind.Sion ? Mathf.DegToRad(5f) : Mathf.DegToRad(12f);
|
||||
_cameraZoom = 1.0f;
|
||||
_lastCamChassisId = null;
|
||||
_footsteps.Clear();
|
||||
_frameEvents.Clear();
|
||||
_frameFootsteps.Clear();
|
||||
_audio.ClearAll();
|
||||
}
|
||||
|
||||
_camera.Far = _mapKind == ArenaMapKind.Sion ? 4200f : 1800f;
|
||||
|
|
@ -711,6 +724,7 @@ public partial class Main : Node3D
|
|||
|
||||
long tc0 = Stopwatch.GetTimestamp();
|
||||
UpdateCamera((float)delta, alpha);
|
||||
StepAudioAndFootsteps((float)delta, alpha);
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
|
|
@ -763,6 +777,7 @@ public partial class Main : Node3D
|
|||
}
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta, alpha);
|
||||
UpdateCamera((float)delta, alpha);
|
||||
StepAudioAndFootsteps((float)delta, alpha);
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
|
|
@ -775,6 +790,43 @@ public partial class Main : Node3D
|
|||
}
|
||||
}
|
||||
|
||||
private void StepAudioAndFootsteps(float dt, float alpha)
|
||||
{
|
||||
if (_session is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_frameEvents.Clear();
|
||||
_session.DrainSimEvents(_frameEvents);
|
||||
|
||||
_frameFootsteps.Clear();
|
||||
_footsteps.StepSession(_session, dt, alpha, _frameFootsteps, ResolveLiveWalkerFootWorld);
|
||||
|
||||
_audio.UpdateFrame(_session, _frameEvents, _frameFootsteps, _camera.GlobalPosition, dt, alpha);
|
||||
}
|
||||
|
||||
private System.Numerics.Vector3? ResolveLiveWalkerFootWorld(bool isContender, int id, int legIndex)
|
||||
{
|
||||
VehicleVisualInstance? vis = isContender
|
||||
? _arena.GetContenderVisual(id)
|
||||
: _arena.GetSpectatorVisual(id);
|
||||
if (vis is null || vis.IsStaticLod || vis.RigState?.WalkerRig is not { } rig)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if ((uint)legIndex >= (uint)rig.Legs.Length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Node3D footNode = rig.Legs[legIndex].Foot.Node;
|
||||
if (!GodotObject.IsInstanceValid(footNode) || !footNode.IsInsideTree())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Vector3 p = footNode.GlobalPosition;
|
||||
return new System.Numerics.Vector3(p.X, p.Y, p.Z);
|
||||
}
|
||||
|
||||
private void PrintPerfSummaryAndQuit()
|
||||
{
|
||||
static double Avg(List<double> v)
|
||||
|
|
|
|||
Loading…
Reference in a new issue