Cut 5c-2: Godot IClientArenaSession cutover, F9 connect bar, and 2-client Sion verification
This commit is contained in:
parent
d8f5c49b8d
commit
8ab62655d5
9 changed files with 944 additions and 241 deletions
|
|
@ -2,12 +2,11 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Renders the 3D arena entities from <see cref="ArenaSession"/>:
|
||||
/// Renders the 3D arena entities from <see cref="IClientArenaSession"/>:
|
||||
/// cover ruins, shrinking Safe Circle ring, unified <see cref="MultiMeshPartPool"/> for all
|
||||
/// 15 Brokkr vehicles/mechs, mounted gear, salvage drops, and tumbling debris,
|
||||
/// live 1-draw-call <see cref="PomDecalPool"/> combat scars, and pooled multi-class weapon VFX.
|
||||
|
|
@ -319,9 +318,9 @@ public partial class ArenaRenderer : Node3D
|
|||
_assetCache?.Dispose();
|
||||
}
|
||||
|
||||
public void Sync(ArenaSession session, float elapsedSeconds, float dt = 1f / 60f, float alpha = 1f)
|
||||
public void Sync(IClientArenaSession session, float elapsedSeconds, float dt = 1f / 60f, float alpha = 1f)
|
||||
{
|
||||
var state = session.State;
|
||||
var state = session.ViewState;
|
||||
if (!ReferenceEquals(_builtForState, state))
|
||||
{
|
||||
RebuildStaticArena(state);
|
||||
|
|
@ -496,19 +495,23 @@ public partial class ArenaRenderer : Node3D
|
|||
_safeRingImm.SurfaceEnd();
|
||||
}
|
||||
|
||||
private void SyncContenders(ArenaSession session, float dt, float alpha, bool hasCam, Vector3 camPos)
|
||||
private void SyncContenders(IClientArenaSession session, float dt, float alpha, bool hasCam, Vector3 camPos)
|
||||
{
|
||||
var contenders = session.State.Contenders;
|
||||
var contenders = session.ViewState.Contenders;
|
||||
int localId = session.LocalContenderId;
|
||||
|
||||
for (int i = 0; i < contenders.Count; i++)
|
||||
{
|
||||
var c = contenders[i];
|
||||
if (!c.Alive)
|
||||
if (!c.Alive || !session.IsContenderVisible(c.Id))
|
||||
{
|
||||
if (_contenderVisuals.TryGetValue(c.Id, out var deadVis))
|
||||
if (_contenderVisuals.TryGetValue(c.Id, out var hiddenVis))
|
||||
{
|
||||
deadVis.Visual.SyncDamageAndHeat(c.Grid, _debris, Vector3.Zero);
|
||||
deadVis.Visual.Root.Visible = false;
|
||||
if (!c.Alive)
|
||||
{
|
||||
hiddenVis.Visual.SyncDamageAndHeat(c.Grid, _debris, Vector3.Zero);
|
||||
}
|
||||
hiddenVis.Visual.Root.Visible = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -520,7 +523,7 @@ public partial class ArenaRenderer : Node3D
|
|||
vis.Visual.Root.QueueFree();
|
||||
}
|
||||
|
||||
var role = c.Id == 0 ? VehicleVisualRole.Player : VehicleVisualRole.Rival;
|
||||
var role = c.Id == localId ? VehicleVisualRole.Player : VehicleVisualRole.Rival;
|
||||
var instance = VehicleVisualInstance.Create(_assetCache, c.Grid.Spec.Id, role);
|
||||
instance.SyncMountedGear(c.Grid);
|
||||
_actorsGroup.AddChild(instance.Root);
|
||||
|
|
@ -537,15 +540,15 @@ public partial class ArenaRenderer : Node3D
|
|||
vis.Visual.Root.Transform = new Transform3D(new Basis(q), pos);
|
||||
|
||||
float distSq = hasCam ? pos.DistanceSquaredTo(camPos) : 0f;
|
||||
bool castShadows = !hasCam || c.Id == 0 || distSq <= 75f * 75f;
|
||||
bool useStaticLod = hasCam && c.Id != 0 && !vis.Visual.HasAnyStrippedCell &&
|
||||
bool castShadows = !hasCam || c.Id == localId || distSq <= 75f * 75f;
|
||||
bool useStaticLod = hasCam && c.Id != localId && !vis.Visual.HasAnyStrippedCell &&
|
||||
(vis.Visual.IsStaticLod ? distSq > 64f * 64f : distSq > 68f * 68f);
|
||||
vis.Visual.SetLodState(useStaticLod, castShadows);
|
||||
|
||||
vis.Visual.SyncMountedGear(c.Grid);
|
||||
if (!useStaticLod)
|
||||
{
|
||||
if (!hasCam || c.Id == 0 || distSq <= 55f * 55f)
|
||||
if (!hasCam || c.Id == localId || distSq <= 55f * 55f)
|
||||
{
|
||||
vis.RigDtAccum = 0f;
|
||||
vis.RigSkipFrames = 0;
|
||||
|
|
@ -582,22 +585,25 @@ public partial class ArenaRenderer : Node3D
|
|||
}
|
||||
}
|
||||
|
||||
private void SyncSpectators(ArenaSession session, float elapsedSeconds, float dt, float alpha, bool hasCam, Vector3 camPos)
|
||||
private void SyncSpectators(IClientArenaSession session, float elapsedSeconds, float dt, float alpha, bool hasCam, Vector3 camPos)
|
||||
{
|
||||
var specs = session.State.Spectators.Spectators;
|
||||
var specs = session.ViewState.Spectators.Spectators;
|
||||
|
||||
for (int i = 0; i < specs.Count; i++)
|
||||
{
|
||||
var s = specs[i];
|
||||
if (!s.Alive)
|
||||
if (!s.Alive || !session.IsSpectatorVisible(s.Id))
|
||||
{
|
||||
if (_spectatorVisuals.TryGetValue(s.Id, out var deadVis))
|
||||
if (_spectatorVisuals.TryGetValue(s.Id, out var hiddenVis))
|
||||
{
|
||||
deadVis.Visual.SyncDamageAndHeat(s.Grid, _debris, Vector3.Zero);
|
||||
deadVis.Visual.Root.Visible = false;
|
||||
if (deadVis.LaserMesh is not null)
|
||||
if (!s.Alive)
|
||||
{
|
||||
deadVis.LaserMesh.Visible = false;
|
||||
hiddenVis.Visual.SyncDamageAndHeat(s.Grid, _debris, Vector3.Zero);
|
||||
}
|
||||
hiddenVis.Visual.Root.Visible = false;
|
||||
if (hiddenVis.LaserMesh is not null)
|
||||
{
|
||||
hiddenVis.LaserMesh.Visible = false;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
|
@ -647,15 +653,16 @@ public partial class ArenaRenderer : Node3D
|
|||
|
||||
ContenderState? target = s.TargetContenderId.HasValue &&
|
||||
s.TargetContenderId.Value >= 0 &&
|
||||
s.TargetContenderId.Value < session.State.Contenders.Count
|
||||
? session.State.Contenders[s.TargetContenderId.Value]
|
||||
s.TargetContenderId.Value < session.ViewState.Contenders.Count
|
||||
? session.ViewState.Contenders[s.TargetContenderId.Value]
|
||||
: null;
|
||||
|
||||
if (!useStaticLod)
|
||||
{
|
||||
float aimYawWorld = s.Yaw;
|
||||
float aimPitchDeg = 0f;
|
||||
if (s.Stance != SpectatorStance.Neutral && target is { Alive: true })
|
||||
if (s.Stance != SpectatorStance.Neutral && target is { Alive: true } &&
|
||||
(target.Id == session.LocalContenderId || session.IsContenderVisible(target.Id)))
|
||||
{
|
||||
float tdx = target.X - s.X;
|
||||
float tdz = target.Z - s.Z;
|
||||
|
|
@ -723,7 +730,8 @@ public partial class ArenaRenderer : Node3D
|
|||
// Lock-on laser beam when Cleared or Provoked
|
||||
if (vis.LaserMesh is not null)
|
||||
{
|
||||
if (s.Stance != SpectatorStance.Neutral && s.HasTargetLos && target is { Alive: true })
|
||||
if (s.Stance != SpectatorStance.Neutral && s.HasTargetLos && target is { Alive: true } &&
|
||||
(target.Id == session.LocalContenderId || session.IsContenderVisible(target.Id)))
|
||||
{
|
||||
Vector3 start = specPos + new Vector3(0f, s.Grid.Spec.HalfHeight * 0.7f, 0f);
|
||||
var (targetPos, _, _) = session.GetInterpolatedContenderPose(target.Id, alpha);
|
||||
|
|
|
|||
363
client/Hud.cs
363
client/Hud.cs
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ public partial class Hud : CanvasLayer
|
|||
private static readonly Color GoldCol = Color.FromHtml("#e6b838");
|
||||
private static readonly Color RedCol = Color.FromHtml("#d93829");
|
||||
|
||||
private readonly Func<ArenaSession?> _getSession;
|
||||
private readonly Func<IClientArenaSession?> _getSession;
|
||||
private readonly Action<int, string> _onEquipCargo;
|
||||
private readonly Func<float> _getCameraYaw;
|
||||
|
||||
|
|
@ -37,6 +37,7 @@ public partial class Hud : CanvasLayer
|
|||
private Label _statsLabel = null!;
|
||||
private Label _safeLabel = null!;
|
||||
private Label _detectionLabel = null!;
|
||||
private Label _netStatusLabel = null!;
|
||||
private Label _promptLabel = null!;
|
||||
private Label _controlsHint = null!;
|
||||
|
||||
|
|
@ -54,6 +55,13 @@ public partial class Hud : CanvasLayer
|
|||
private ChromePanel _bottomLeftPanel = null!;
|
||||
private ChromePanel _chyronPanel = null!;
|
||||
|
||||
private ChromePanel _netPanel = null!;
|
||||
private Label _netModeBadge = null!;
|
||||
private Label _netPanelStatus = null!;
|
||||
private LineEdit _callsignEdit = null!;
|
||||
private LineEdit _endpointEdit = null!;
|
||||
private string? _uiNetError;
|
||||
|
||||
private VBoxContainer _chyronBox = null!;
|
||||
private readonly Label[] _chyronLabels = new Label[3];
|
||||
private BroadcastFeed? _lastBroadcastFeed;
|
||||
|
|
@ -65,7 +73,12 @@ public partial class Hud : CanvasLayer
|
|||
private int _lastCargoHash = -1;
|
||||
private bool _garageExpanded;
|
||||
|
||||
public Hud(Func<ArenaSession?> getSession, Action<int, string> onEquipCargo, Func<float>? getCameraYaw = null)
|
||||
public event Action<string, string>? JoinRequested;
|
||||
public event Action<int, string>? HostRequested;
|
||||
public event Action? SoloRequested;
|
||||
public event Action<bool>? NetworkPanelToggled;
|
||||
|
||||
public Hud(Func<IClientArenaSession?> getSession, Action<int, string> onEquipCargo, Func<float>? getCameraYaw = null)
|
||||
{
|
||||
_getSession = getSession;
|
||||
_onEquipCargo = onEquipCargo;
|
||||
|
|
@ -74,6 +87,8 @@ public partial class Hud : CanvasLayer
|
|||
}
|
||||
|
||||
public bool GarageExpanded => _garageExpanded;
|
||||
public bool NetworkPanelOpen => _netPanel.Visible;
|
||||
public bool IsUiTextInputFocused => _netPanel.Visible && (_callsignEdit.HasFocus() || _endpointEdit.HasFocus());
|
||||
public InventoryGridControl Schematic => _schematic;
|
||||
internal int ActiveHitArcCount => _crosshair.ActiveHitArcCount;
|
||||
internal void PushTestHitArc(float sourceX, float sourceZ, WeaponVisualClass weaponClass) =>
|
||||
|
|
@ -88,6 +103,38 @@ public partial class Hud : CanvasLayer
|
|||
yield return _bottomLeftPanel.ChromeMaterial;
|
||||
yield return _chyronPanel.ChromeMaterial;
|
||||
yield return _outcomeBanner.ChromeMaterial;
|
||||
yield return _netPanel.ChromeMaterial;
|
||||
}
|
||||
|
||||
public void ToggleNetworkPanel() => SetNetworkPanelOpen(!_netPanel.Visible);
|
||||
|
||||
public void SetNetworkPanelOpen(bool open)
|
||||
{
|
||||
if (_netPanel.Visible == open) return;
|
||||
_netPanel.Visible = open;
|
||||
if (!open)
|
||||
{
|
||||
_callsignEdit.ReleaseFocus();
|
||||
_endpointEdit.ReleaseFocus();
|
||||
}
|
||||
NetworkPanelToggled?.Invoke(open);
|
||||
}
|
||||
|
||||
public void SetNetworkDefaults(string endpoint, string callsign)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(endpoint))
|
||||
{
|
||||
_endpointEdit.Text = endpoint.Trim();
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(callsign))
|
||||
{
|
||||
_callsignEdit.Text = callsign.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetNetworkError(string? err)
|
||||
{
|
||||
_uiNetError = string.IsNullOrWhiteSpace(err) ? null : err;
|
||||
}
|
||||
|
||||
public void ToggleGarage()
|
||||
|
|
@ -111,6 +158,7 @@ public partial class Hud : CanvasLayer
|
|||
BuildBottomLeftSchematic();
|
||||
BuildBottomCenterChyron();
|
||||
BuildOutcomeBanner();
|
||||
BuildNetworkPanel();
|
||||
}
|
||||
|
||||
public bool IsPointerOverInteractiveHud(Vector2 screenPos)
|
||||
|
|
@ -120,12 +168,13 @@ public partial class Hud : CanvasLayer
|
|||
|| (_bottomLeftPanel.Visible && _bottomLeftPanel.GetGlobalRect().HasPoint(screenPos))
|
||||
|| (_chyronPanel.Visible && _chyronPanel.GetGlobalRect().HasPoint(screenPos))
|
||||
|| (_chyronBox.Visible && _chyronBox.GetGlobalRect().HasPoint(screenPos))
|
||||
|| (_outcomeBanner.Visible && _outcomeBanner.GetGlobalRect().HasPoint(screenPos));
|
||||
|| (_outcomeBanner.Visible && _outcomeBanner.GetGlobalRect().HasPoint(screenPos))
|
||||
|| (_netPanel.Visible && _netPanel.GetGlobalRect().HasPoint(screenPos));
|
||||
}
|
||||
|
||||
public bool HasPanelOverlapOrClip(Vector2 viewportSize)
|
||||
{
|
||||
var panels = new[] { _topLeftPanel, _topRightPanel, _bottomLeftPanel, _chyronPanel };
|
||||
var panels = new[] { _topLeftPanel, _topRightPanel, _bottomLeftPanel, _chyronPanel, _netPanel };
|
||||
var bounds = new Rect2(Vector2.Zero, viewportSize + new Vector2(1f, 1f));
|
||||
for (int i = 0; i < panels.Length; i++)
|
||||
{
|
||||
|
|
@ -147,10 +196,11 @@ public partial class Hud : CanvasLayer
|
|||
return false;
|
||||
}
|
||||
|
||||
public void Sync(ArenaSession session)
|
||||
public void Sync(IClientArenaSession session)
|
||||
{
|
||||
var state = session.State;
|
||||
var player = state.Contenders[0];
|
||||
var state = session.ViewState;
|
||||
var player = session.LocalContender;
|
||||
var net = session.ConnectionStatus;
|
||||
|
||||
// Top-Left Status
|
||||
_chassisHeader.Text = player.Grid.Spec.Name.ToUpperInvariant();
|
||||
|
|
@ -171,12 +221,12 @@ public partial class Hud : CanvasLayer
|
|||
{
|
||||
float agl = MathF.Max(0f, player.Y - player.Grid.Spec.HalfHeight - state.Terrain.SampleHeight(player.X, player.Z));
|
||||
_statsLabel.Text = $"SPD {player.Speed:F1} m/s | ALT {agl:F1}m | ALIVE {aliveCount} / {state.Contenders.Count} | KILLS {player.Kills}";
|
||||
_controlsHint.Text = "WASD Fly | Space/C Alt | Mouse Aim | LMB Fire | E Bolt/Swap | Tab Garage | M Map";
|
||||
_controlsHint.Text = "WASD Fly | Space/C Alt | Mouse Aim | LMB Fire | E Bolt | Tab Garage | M Map | F9 Net";
|
||||
}
|
||||
else
|
||||
{
|
||||
_statsLabel.Text = $"SPD {player.Speed:F1} m/s | ALIVE {aliveCount} / {state.Contenders.Count} | KILLS {player.Kills}";
|
||||
_controlsHint.Text = "WASD Drive | Mouse Aim | LMB Fire | E Bolt/Swap | Tab Garage | M Map | Wheel Zoom";
|
||||
_controlsHint.Text = "WASD Drive | Mouse Aim | LMB Fire | E Bolt | Tab Garage | M Map | F9 Net | Wheel Zoom";
|
||||
}
|
||||
|
||||
_radarTitle.Text = state.MapKind == ArenaMapKind.Sion
|
||||
|
|
@ -202,7 +252,7 @@ public partial class Hud : CanvasLayer
|
|||
_safeLabel.Modulate = RedCol;
|
||||
}
|
||||
|
||||
int detectedBy = state.ObserverStates.TryGetValue(0, out var obs0) ? obs0.DetectedByCount : 0;
|
||||
int detectedBy = session.LocalDetectedByCount;
|
||||
if (detectedBy > 0)
|
||||
{
|
||||
_detectionLabel.Text = $"DETECTED BY {detectedBy}";
|
||||
|
|
@ -214,6 +264,35 @@ public partial class Hud : CanvasLayer
|
|||
_detectionLabel.Modulate = OliveCol;
|
||||
}
|
||||
|
||||
if (net.Mode == NetworkMode.Solo)
|
||||
{
|
||||
_netStatusLabel.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_netStatusLabel.Visible = true;
|
||||
if (net.Mode == NetworkMode.ListenHost)
|
||||
{
|
||||
_netStatusLabel.Text = $"{net.StateLabel} • HUMANS {net.ConnectedHumans}/{net.MaxHumans} • [F9] NET";
|
||||
_netStatusLabel.Modulate = CyanCol;
|
||||
}
|
||||
else if (net.Connected)
|
||||
{
|
||||
_netStatusLabel.Text = $"PING {net.PingMs} ms • HUMANS {net.ConnectedHumans}/{net.MaxHumans} • [F9] NET";
|
||||
_netStatusLabel.Modulate = net.PingMs > 120 ? OrangeCol : CyanCol;
|
||||
}
|
||||
else
|
||||
{
|
||||
_netStatusLabel.Text = $"{net.StateLabel} • [F9] NET";
|
||||
_netStatusLabel.Modulate = net.LastError is not null ? RedCol : OrangeCol;
|
||||
}
|
||||
}
|
||||
|
||||
if (_netPanel.Visible)
|
||||
{
|
||||
SyncNetworkPanel(net);
|
||||
}
|
||||
|
||||
_promptLabel.Text = BuildInteractionPrompt(state, player);
|
||||
_promptLabel.Visible = !string.IsNullOrEmpty(_promptLabel.Text);
|
||||
|
||||
|
|
@ -222,7 +301,7 @@ public partial class Hud : CanvasLayer
|
|||
_crosshair.QueueRedraw();
|
||||
|
||||
// Radar (heading-up with camera yaw)
|
||||
_radar.SetState(state, _getCameraYaw());
|
||||
_radar.SetState(session, _getCameraYaw());
|
||||
_radar.QueueRedraw();
|
||||
|
||||
// Schematic + Cargo
|
||||
|
|
@ -238,18 +317,25 @@ public partial class Hud : CanvasLayer
|
|||
SyncBroadcastChyron(state.Broadcast);
|
||||
|
||||
// Outcome
|
||||
if (state.Phase == MatchPhase.Completed && state.WinnerContenderId == 0)
|
||||
var outcome = session.LocalOutcome;
|
||||
if (outcome == ClientMatchOutcome.Victory)
|
||||
{
|
||||
_outcomeBanner.Visible = true;
|
||||
_outcomeBanner.ChromeMaterial.SetShaderParameter("accent_color", OliveCol);
|
||||
_outcomeLabel.Text = "VICTORY — LAST RIG STANDING\n[R] New Drop";
|
||||
_outcomeLabel.Text = net.Mode == NetworkMode.RemoteClient
|
||||
? "VICTORY — LAST RIG STANDING\nNext round starting soon..."
|
||||
: "VICTORY — LAST RIG STANDING\n[R] New Drop";
|
||||
_outcomeLabel.Modulate = OliveCol;
|
||||
}
|
||||
else if (!player.Alive || state.Phase == MatchPhase.Completed)
|
||||
else if (outcome == ClientMatchOutcome.Defeat)
|
||||
{
|
||||
_outcomeBanner.Visible = true;
|
||||
_outcomeBanner.ChromeMaterial.SetShaderParameter("accent_color", RedCol);
|
||||
_outcomeLabel.Text = "CHASSIS DESTROYED\n[R] Redeploy";
|
||||
string title = !player.Alive ? "CHASSIS DESTROYED" : "MATCH COMPLETED — DEFEAT";
|
||||
string sub = net.Mode == NetworkMode.RemoteClient
|
||||
? (state.Phase == MatchPhase.Completed ? "Waiting for server next round..." : "Spectating live match...")
|
||||
: "[R] Redeploy";
|
||||
_outcomeLabel.Text = $"{title}\n{sub}";
|
||||
_outcomeLabel.Modulate = RedCol;
|
||||
}
|
||||
else
|
||||
|
|
@ -329,6 +415,10 @@ public partial class Hud : CanvasLayer
|
|||
_detectionLabel.AddThemeFontSizeOverride("font_size", 13);
|
||||
vbox.AddChild(_detectionLabel);
|
||||
|
||||
_netStatusLabel = new Label { Text = "", Visible = false };
|
||||
_netStatusLabel.AddThemeFontSizeOverride("font_size", 12);
|
||||
vbox.AddChild(_netStatusLabel);
|
||||
|
||||
_promptLabel = new Label { Text = "", Visible = false };
|
||||
_promptLabel.AddThemeColorOverride("font_color", CyanCol);
|
||||
_promptLabel.AddThemeFontSizeOverride("font_size", 14);
|
||||
|
|
@ -510,11 +600,190 @@ public partial class Hud : CanvasLayer
|
|||
_outcomeBanner.AddChild(_outcomeLabel);
|
||||
}
|
||||
|
||||
private void BuildNetworkPanel()
|
||||
{
|
||||
_netPanel = CreateStyledPanel(CyanCol, cornerLen: 14f, borderPx: 1.5f);
|
||||
_netPanel.AnchorLeft = 0.5f;
|
||||
_netPanel.AnchorRight = 0.5f;
|
||||
_netPanel.AnchorTop = 0.32f;
|
||||
_netPanel.AnchorBottom = 0.32f;
|
||||
_netPanel.OffsetLeft = -188f;
|
||||
_netPanel.OffsetRight = 188f;
|
||||
_netPanel.OffsetTop = 0f;
|
||||
_netPanel.OffsetBottom = 0f;
|
||||
_netPanel.Visible = false;
|
||||
AddChild(_netPanel);
|
||||
|
||||
var vbox = new VBoxContainer();
|
||||
vbox.AddThemeConstantOverride("separation", 6);
|
||||
_netPanel.AddChild(vbox);
|
||||
|
||||
var headRow = new HBoxContainer();
|
||||
headRow.AddThemeConstantOverride("separation", 8);
|
||||
vbox.AddChild(headRow);
|
||||
|
||||
var title = new Label
|
||||
{
|
||||
Text = "MULTIPLAYER LINK [F9]",
|
||||
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
|
||||
};
|
||||
title.AddThemeColorOverride("font_color", CyanCol);
|
||||
title.AddThemeFontSizeOverride("font_size", 13);
|
||||
headRow.AddChild(title);
|
||||
|
||||
_netModeBadge = new Label { Text = "SOLO" };
|
||||
_netModeBadge.AddThemeColorOverride("font_color", OliveCol);
|
||||
_netModeBadge.AddThemeFontSizeOverride("font_size", 12);
|
||||
headRow.AddChild(_netModeBadge);
|
||||
|
||||
_netPanelStatus = new Label
|
||||
{
|
||||
Text = "LOCAL SOLO SESSION",
|
||||
AutowrapMode = TextServer.AutowrapMode.Word
|
||||
};
|
||||
_netPanelStatus.AddThemeColorOverride("font_color", TextMuted);
|
||||
_netPanelStatus.AddThemeFontSizeOverride("font_size", 11);
|
||||
vbox.AddChild(_netPanelStatus);
|
||||
|
||||
var nameRow = new HBoxContainer();
|
||||
nameRow.AddThemeConstantOverride("separation", 6);
|
||||
vbox.AddChild(nameRow);
|
||||
|
||||
var nameLbl = new Label { Text = "CALLSIGN", CustomMinimumSize = new Vector2(74f, 0f) };
|
||||
nameLbl.AddThemeColorOverride("font_color", TextMuted);
|
||||
nameLbl.AddThemeFontSizeOverride("font_size", 11);
|
||||
nameRow.AddChild(nameLbl);
|
||||
|
||||
_callsignEdit = new LineEdit
|
||||
{
|
||||
Text = "Pilot",
|
||||
MaxLength = 24,
|
||||
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
|
||||
PlaceholderText = "Callsign"
|
||||
};
|
||||
_callsignEdit.AddThemeFontSizeOverride("font_size", 12);
|
||||
nameRow.AddChild(_callsignEdit);
|
||||
|
||||
var epRow = new HBoxContainer();
|
||||
epRow.AddThemeConstantOverride("separation", 6);
|
||||
vbox.AddChild(epRow);
|
||||
|
||||
var epLbl = new Label { Text = "HOST:PORT", CustomMinimumSize = new Vector2(74f, 0f) };
|
||||
epLbl.AddThemeColorOverride("font_color", TextMuted);
|
||||
epLbl.AddThemeFontSizeOverride("font_size", 11);
|
||||
epRow.AddChild(epLbl);
|
||||
|
||||
_endpointEdit = new LineEdit
|
||||
{
|
||||
Text = "127.0.0.1:3076",
|
||||
MaxLength = 96,
|
||||
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
|
||||
PlaceholderText = "127.0.0.1:3076"
|
||||
};
|
||||
_endpointEdit.AddThemeFontSizeOverride("font_size", 12);
|
||||
epRow.AddChild(_endpointEdit);
|
||||
|
||||
var btnRow = new HBoxContainer();
|
||||
btnRow.AddThemeConstantOverride("separation", 6);
|
||||
vbox.AddChild(btnRow);
|
||||
|
||||
var hostBtn = new Button { Text = "Host", SizeFlagsHorizontal = Control.SizeFlags.ExpandFill, FocusMode = Control.FocusModeEnum.None };
|
||||
hostBtn.AddThemeFontSizeOverride("font_size", 12);
|
||||
hostBtn.Pressed += () =>
|
||||
{
|
||||
_uiNetError = null;
|
||||
int port = ParsePort(_endpointEdit.Text, 3076);
|
||||
HostRequested?.Invoke(port, _callsignEdit.Text);
|
||||
};
|
||||
btnRow.AddChild(hostBtn);
|
||||
|
||||
var joinBtn = new Button { Text = "Join", SizeFlagsHorizontal = Control.SizeFlags.ExpandFill, FocusMode = Control.FocusModeEnum.None };
|
||||
joinBtn.AddThemeFontSizeOverride("font_size", 12);
|
||||
joinBtn.Pressed += () =>
|
||||
{
|
||||
_uiNetError = null;
|
||||
JoinRequested?.Invoke(_endpointEdit.Text, _callsignEdit.Text);
|
||||
};
|
||||
btnRow.AddChild(joinBtn);
|
||||
|
||||
var soloBtn = new Button { Text = "Solo", SizeFlagsHorizontal = Control.SizeFlags.ExpandFill, FocusMode = Control.FocusModeEnum.None };
|
||||
soloBtn.AddThemeFontSizeOverride("font_size", 12);
|
||||
soloBtn.Pressed += () =>
|
||||
{
|
||||
_uiNetError = null;
|
||||
SoloRequested?.Invoke();
|
||||
};
|
||||
btnRow.AddChild(soloBtn);
|
||||
|
||||
var closeBtn = new Button { Text = "Close", FocusMode = Control.FocusModeEnum.None };
|
||||
closeBtn.AddThemeFontSizeOverride("font_size", 12);
|
||||
closeBtn.Pressed += () => SetNetworkPanelOpen(false);
|
||||
btnRow.AddChild(closeBtn);
|
||||
}
|
||||
|
||||
private void SyncNetworkPanel(NetworkStatusSnapshot net)
|
||||
{
|
||||
_netModeBadge.Text = net.Mode switch
|
||||
{
|
||||
NetworkMode.ListenHost => "HOST",
|
||||
NetworkMode.RemoteClient => "CLIENT",
|
||||
_ => "SOLO"
|
||||
};
|
||||
_netModeBadge.Modulate = net.Mode == NetworkMode.Solo ? OliveCol : CyanCol;
|
||||
|
||||
string? err = _uiNetError ?? net.LastError;
|
||||
if (!string.IsNullOrWhiteSpace(err))
|
||||
{
|
||||
_netPanelStatus.Text = $"ERROR: {err}";
|
||||
_netPanelStatus.AddThemeColorOverride("font_color", RedCol);
|
||||
return;
|
||||
}
|
||||
|
||||
if (net.Mode == NetworkMode.Solo)
|
||||
{
|
||||
_netPanelStatus.Text = "OFFLINE SOLO — ZERO NETWORK LATENCY";
|
||||
_netPanelStatus.AddThemeColorOverride("font_color", TextMuted);
|
||||
}
|
||||
else if (net.Mode == NetworkMode.ListenHost)
|
||||
{
|
||||
_netPanelStatus.Text = $"{net.StateLabel} • {net.ConnectedHumans}/{net.MaxHumans} HUMANS";
|
||||
_netPanelStatus.AddThemeColorOverride("font_color", CyanCol);
|
||||
}
|
||||
else if (net.Connected)
|
||||
{
|
||||
_netPanelStatus.Text = $"CONNECTED • PING {net.PingMs} ms • {net.ConnectedHumans}/{net.MaxHumans} HUMANS";
|
||||
_netPanelStatus.AddThemeColorOverride("font_color", OliveCol);
|
||||
}
|
||||
else
|
||||
{
|
||||
_netPanelStatus.Text = $"STATE: {net.StateLabel}...";
|
||||
_netPanelStatus.AddThemeColorOverride("font_color", OrangeCol);
|
||||
}
|
||||
}
|
||||
|
||||
private static int ParsePort(string text, int fallback)
|
||||
{
|
||||
string trimmed = (text ?? string.Empty).Trim();
|
||||
int colon = trimmed.LastIndexOf(':');
|
||||
if (colon >= 0 && colon + 1 < trimmed.Length &&
|
||||
int.TryParse(trimmed[(colon + 1)..], NumberStyles.Integer, CultureInfo.InvariantCulture, out int p) &&
|
||||
p is > 0 and <= 65535)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
if (int.TryParse(trimmed, NumberStyles.Integer, CultureInfo.InvariantCulture, out int direct) &&
|
||||
direct is > 0 and <= 65535)
|
||||
{
|
||||
return direct;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
private void OnHardpointClicked(string hardpointId)
|
||||
{
|
||||
var session = _getSession();
|
||||
if (session is null) return;
|
||||
var cargo = session.State.Contenders[0].Grid.Cargo;
|
||||
var cargo = session.LocalContender.Grid.Cargo;
|
||||
if (_selectedCargoIndex >= 0 && _selectedCargoIndex < cargo.Count)
|
||||
{
|
||||
_onEquipCargo(_selectedCargoIndex, hardpointId);
|
||||
|
|
@ -1003,12 +1272,12 @@ public partial class Hud : CanvasLayer
|
|||
|
||||
private sealed partial class RadarWidget : Control
|
||||
{
|
||||
private MatchState? _state;
|
||||
private IClientArenaSession? _session;
|
||||
private float _cameraYaw;
|
||||
|
||||
public void SetState(MatchState state, float cameraYaw)
|
||||
public void SetState(IClientArenaSession session, float cameraYaw)
|
||||
{
|
||||
_state = state;
|
||||
_session = session;
|
||||
_cameraYaw = cameraYaw;
|
||||
}
|
||||
|
||||
|
|
@ -1038,7 +1307,8 @@ public partial class Hud : CanvasLayer
|
|||
Vector2 center = Size * 0.5f;
|
||||
float radius = MathF.Min(Size.X, Size.Y) * 0.47f;
|
||||
float maxBlipRadius = MathF.Max(4f, radius - 3f);
|
||||
float arenaHalf = MathF.Max(1f, _state?.Terrain.MapHalfExtent ?? MatchState.ArenaHalfExtent);
|
||||
var state = _session?.ViewState;
|
||||
float arenaHalf = MathF.Max(1f, state?.Terrain.MapHalfExtent ?? MatchState.ArenaHalfExtent);
|
||||
float scale = radius / arenaHalf;
|
||||
|
||||
DrawCircle(center, radius, BgInner);
|
||||
|
|
@ -1046,16 +1316,18 @@ public partial class Hud : CanvasLayer
|
|||
// Forward-up indicator tick at top of radar
|
||||
DrawLine(center + new Vector2(0f, -radius), center + new Vector2(0f, -radius + 6f), CyanCol, 2.0f);
|
||||
|
||||
if (_state is null) return;
|
||||
if (_session is null || state is null) return;
|
||||
|
||||
int localId = _session.LocalContenderId;
|
||||
|
||||
// Safe Circle
|
||||
float safePx = MathF.Min(_state.Spectators.SafeRadius * scale, maxBlipRadius);
|
||||
float safePx = MathF.Min(state.Spectators.SafeRadius * scale, maxBlipRadius);
|
||||
DrawArc(center, safePx, 0f, MathF.Tau, 64, OrangeCol, 1.6f);
|
||||
|
||||
// Ground drops
|
||||
for (int i = 0; i < _state.GroundDrops.Count; i++)
|
||||
for (int i = 0; i < state.GroundDrops.Count; i++)
|
||||
{
|
||||
var d = _state.GroundDrops[i];
|
||||
var d = state.GroundDrops[i];
|
||||
if (d.PickedUp) continue;
|
||||
var p = ClampToRadarDisc(center, MathF.Max(4f, radius - 4f), WorldToRadar(center, scale, d.X, d.Z, _cameraYaw));
|
||||
if (d.Chassis is not null)
|
||||
|
|
@ -1069,22 +1341,28 @@ public partial class Hud : CanvasLayer
|
|||
}
|
||||
|
||||
// Spectator Wall (LOS / Tourist horizon rule / 5s ghost memory; hidden Exemplars vanish!)
|
||||
var obs0 = _state.GetOrCreateObserverState(0);
|
||||
var specs = _state.Spectators.Spectators;
|
||||
var contenderContacts = _session.LocalContenderContacts;
|
||||
var spectatorContacts = _session.LocalSpectatorContacts;
|
||||
var specs = state.Spectators.Spectators;
|
||||
for (int i = 0; i < specs.Count; i++)
|
||||
{
|
||||
var s = specs[i];
|
||||
if (!s.Alive) continue;
|
||||
|
||||
obs0.SpectatorContacts.TryGetValue(s.Id, out var mem);
|
||||
spectatorContacts.TryGetValue(s.Id, out var mem);
|
||||
if (!MatchState.IsContactOnRadar(mem))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool live = mem!.VisibleToPlayer;
|
||||
float drawX = live || mem.FaintHorizonPing ? s.X : mem.LastSeenX;
|
||||
float drawZ = live || mem.FaintHorizonPing ? s.Z : mem.LastSeenZ;
|
||||
bool hasLivePos = _session.IsSpectatorVisible(s.Id) && (live || mem.FaintHorizonPing);
|
||||
if (!hasLivePos && !mem.HasEverBeenSeen)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
float drawX = hasLivePos ? s.X : mem.LastSeenX;
|
||||
float drawZ = hasLivePos ? s.Z : mem.LastSeenZ;
|
||||
float blipR = 1.6f + s.RadarSignature * 3.1f;
|
||||
float specClampR = MathF.Max(4f, radius - blipR - 1f);
|
||||
var p = ClampToRadarDisc(center, specClampR, WorldToRadar(center, scale, drawX, drawZ, _cameraYaw));
|
||||
|
|
@ -1099,14 +1377,14 @@ public partial class Hud : CanvasLayer
|
|||
if (live && s.Stance != SpectatorStance.Neutral && s.HasTargetLos && s.TargetContenderId.HasValue)
|
||||
{
|
||||
int tid = s.TargetContenderId.Value;
|
||||
if (tid >= 0 && tid < _state.Contenders.Count && _state.Contenders[tid].Alive)
|
||||
if (tid >= 0 && tid < state.Contenders.Count && state.Contenders[tid].Alive)
|
||||
{
|
||||
var tgt = _state.Contenders[tid];
|
||||
bool targetVisible = tgt.Id == 0 ||
|
||||
(obs0.ContenderContacts.TryGetValue(tgt.Id, out var tgtMem) && tgtMem.VisibleToPlayer);
|
||||
var tgt = state.Contenders[tid];
|
||||
bool targetVisible = tgt.Id == localId ||
|
||||
(_session.IsContenderVisible(tgt.Id) && contenderContacts.TryGetValue(tgt.Id, out var tgtMem) && tgtMem.VisibleToPlayer);
|
||||
if (targetVisible)
|
||||
{
|
||||
float tgtClampR = MathF.Max(4f, radius - (tgt.Id == 0 ? 7.5f : 4.3f));
|
||||
float tgtClampR = MathF.Max(4f, radius - (tgt.Id == localId ? 7.5f : 4.3f));
|
||||
var tp = ClampToRadarDisc(center, tgtClampR, WorldToRadar(center, scale, tgt.X, tgt.Z, _cameraYaw));
|
||||
DrawLine(p, tp, new Color(RedCol.R, RedCol.G, RedCol.B, 0.65f), 1.3f);
|
||||
}
|
||||
|
|
@ -1131,15 +1409,16 @@ public partial class Hud : CanvasLayer
|
|||
// Contenders (player always live; rivals obey LOS + 5s ghost memory)
|
||||
float sinY = MathF.Sin(_cameraYaw);
|
||||
float cosY = MathF.Cos(_cameraYaw);
|
||||
for (int i = 0; i < _state.Contenders.Count; i++)
|
||||
for (int i = 0; i < state.Contenders.Count; i++)
|
||||
{
|
||||
var c = _state.Contenders[i];
|
||||
var c = state.Contenders[i];
|
||||
if (!c.Alive) continue;
|
||||
|
||||
if (c.Id == 0)
|
||||
if (c.Id == localId)
|
||||
{
|
||||
float playerClampR = MathF.Max(4f, radius - 6.5f - 1f);
|
||||
var p = ClampToRadarDisc(center, playerClampR, WorldToRadar(center, scale, c.X, c.Z, _cameraYaw));
|
||||
var (lPos, _, _) = _session.GetInterpolatedContenderPose(localId, 1f);
|
||||
var p = ClampToRadarDisc(center, playerClampR, WorldToRadar(center, scale, lPos.X, lPos.Z, _cameraYaw));
|
||||
var dir = new Vector2(
|
||||
-MathF.Sin(c.Yaw) * cosY + MathF.Cos(c.Yaw) * sinY,
|
||||
-(MathF.Sin(c.Yaw) * sinY + MathF.Cos(c.Yaw) * cosY));
|
||||
|
|
@ -1154,7 +1433,7 @@ public partial class Hud : CanvasLayer
|
|||
continue;
|
||||
}
|
||||
|
||||
obs0.ContenderContacts.TryGetValue(c.Id, out var mem);
|
||||
contenderContacts.TryGetValue(c.Id, out var mem);
|
||||
if (!MatchState.IsContactOnRadar(mem))
|
||||
{
|
||||
continue;
|
||||
|
|
@ -1163,7 +1442,9 @@ public partial class Hud : CanvasLayer
|
|||
if (mem!.VisibleToPlayer)
|
||||
{
|
||||
float rivalClampR = MathF.Max(4f, radius - 3.3f - 1f);
|
||||
var p = ClampToRadarDisc(center, rivalClampR, WorldToRadar(center, scale, c.X, c.Z, _cameraYaw));
|
||||
float rx = _session.IsContenderVisible(c.Id) ? c.X : mem.LastSeenX;
|
||||
float rz = _session.IsContenderVisible(c.Id) ? c.Z : mem.LastSeenZ;
|
||||
var p = ClampToRadarDisc(center, rivalClampR, WorldToRadar(center, scale, rx, rz, _cameraYaw));
|
||||
DrawCircle(p, 3.3f, OrangeCol);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
619
client/Main.cs
619
client/Main.cs
|
|
@ -1,18 +1,26 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Net;
|
||||
using RustToDust.Ymir;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Root Godot node for Rust to Dust.
|
||||
/// Godot physics is Dummy; <see cref="ArenaSession"/> owns 100% of vehicle, thermal, spectator, and terrain physics at 60 Hz.
|
||||
/// Godot physics is Dummy; <see cref="IClientArenaSession"/> drives Solo (<see cref="LocalArenaSession"/>),
|
||||
/// Listen-Host (<see cref="ListenHostArenaSession"/>), or Remote (<see cref="RemoteArenaSession"/>) play.
|
||||
/// </summary>
|
||||
public partial class Main : Node3D
|
||||
{
|
||||
private const ulong ContenderStableIdBase = 1000UL;
|
||||
private const int DefaultNetPort = 3076;
|
||||
|
||||
private TerrainRenderer _terrain = null!;
|
||||
private SionMapRenderer _sionMap = null!;
|
||||
private ArenaRenderer _arena = null!;
|
||||
|
|
@ -21,8 +29,12 @@ public partial class Main : Node3D
|
|||
private DirectionalLight3D _sun = null!;
|
||||
private ProceduralSkyMaterial _skyMat = null!;
|
||||
private Godot.Environment _env = null!;
|
||||
private ArenaSession? _session;
|
||||
private IClientArenaSession? _session;
|
||||
private MatchState? _boundViewState;
|
||||
private bool _wasNetConnected;
|
||||
private ArenaMapKind _mapKind = ArenaMapKind.Sion;
|
||||
private string _callsign = "Pilot";
|
||||
private string _lastEndpoint = $"127.0.0.1:{DefaultNetPort}";
|
||||
|
||||
private PlayerInput? _scriptedInput;
|
||||
private float _cameraYaw;
|
||||
|
|
@ -37,6 +49,7 @@ public partial class Main : Node3D
|
|||
// Temporary Step 1/Step 3 perf probe (enabled only when RTD_PERF_FRAMES is set)
|
||||
private int _perfTargetFrames;
|
||||
private int _perfFrameCount;
|
||||
private int _perfWaitConnectFrames;
|
||||
private int _perfPhysicsTicks;
|
||||
private long _perfLastFrameTick;
|
||||
private int _perfLastDirtyRebakes;
|
||||
|
|
@ -57,7 +70,7 @@ public partial class Main : Node3D
|
|||
private double _perfPendingArenaMs;
|
||||
private double _perfCamMsSum;
|
||||
|
||||
public ArenaSession Session => _session ?? throw new InvalidOperationException($"No active ArenaSession ({Failure ?? "uninitialized"})");
|
||||
public IClientArenaSession Session => _session ?? throw new InvalidOperationException($"No active IClientArenaSession ({Failure ?? "uninitialized"})");
|
||||
public TerrainRenderer Terrain => _terrain;
|
||||
public SionMapRenderer SionMap => _sionMap;
|
||||
public ArenaRenderer Arena => _arena;
|
||||
|
|
@ -91,27 +104,87 @@ public partial class Main : Node3D
|
|||
AddChild(_camera);
|
||||
|
||||
_hud = new Hud(() => _session, OnEquipCargo, () => _cameraYaw) { Name = "Hud" };
|
||||
_hud.JoinRequested += OnJoinRequested;
|
||||
_hud.HostRequested += OnHostRequested;
|
||||
_hud.SoloRequested += OnSoloRequested;
|
||||
_hud.NetworkPanelToggled += _ => SyncMouseMode();
|
||||
AddChild(_hud);
|
||||
|
||||
string? cliConnect = GetCliArg("--connect");
|
||||
string? cliHost = GetCliArg("--host", allowBareFlag: true);
|
||||
string? cliName = GetCliArg("--name");
|
||||
string? cliMap = GetCliArg("--map");
|
||||
string? cliSeed = GetCliArg("--seed");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(cliName))
|
||||
{
|
||||
_callsign = cliName.Trim();
|
||||
}
|
||||
else if (System.Environment.GetEnvironmentVariable("RTD_NAME") is { Length: > 0 } envName)
|
||||
{
|
||||
_callsign = envName.Trim();
|
||||
}
|
||||
|
||||
if (int.TryParse(cliSeed ?? System.Environment.GetEnvironmentVariable("RTD_SEED"), NumberStyles.Integer, CultureInfo.InvariantCulture, out int parsedSeed))
|
||||
{
|
||||
_seed = parsedSeed;
|
||||
}
|
||||
|
||||
if (InitialMapKindOverride.HasValue)
|
||||
{
|
||||
_mapKind = InitialMapKindOverride.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
string? envMap = System.Environment.GetEnvironmentVariable("RTD_MAP");
|
||||
_mapKind = string.Equals(envMap, "desert", StringComparison.OrdinalIgnoreCase)
|
||||
string? mapVal = cliMap ?? System.Environment.GetEnvironmentVariable("RTD_MAP");
|
||||
_mapKind = string.Equals(mapVal, "desert", StringComparison.OrdinalIgnoreCase)
|
||||
? ArenaMapKind.Desert
|
||||
: ArenaMapKind.Sion;
|
||||
}
|
||||
|
||||
string? connectTarget = !string.IsNullOrWhiteSpace(cliConnect)
|
||||
? cliConnect
|
||||
: System.Environment.GetEnvironmentVariable("RTD_CONNECT");
|
||||
|
||||
string? hostTarget = cliHost is not null
|
||||
? cliHost
|
||||
: (System.Environment.GetEnvironmentVariable("RTD_HOST_PORT") ?? System.Environment.GetEnvironmentVariable("RTD_HOST"));
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(connectTarget))
|
||||
{
|
||||
_lastEndpoint = connectTarget.Trim();
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(hostTarget))
|
||||
{
|
||||
_lastEndpoint = hostTarget.Contains(':', StringComparison.Ordinal)
|
||||
? hostTarget.Trim()
|
||||
: $"127.0.0.1:{hostTarget.Trim()}";
|
||||
}
|
||||
_hud.SetNetworkDefaults(_lastEndpoint, _callsign);
|
||||
|
||||
if (int.TryParse(System.Environment.GetEnvironmentVariable("RTD_PERF_FRAMES"), out int perfFrames) && perfFrames > 0)
|
||||
{
|
||||
_perfTargetFrames = perfFrames;
|
||||
ArenaSession.PerfEnabled = true;
|
||||
}
|
||||
else if (int.TryParse(System.Environment.GetEnvironmentVariable("RTD_AUTO_EXIT_FRAMES"), out int autoExitFrames) && autoExitFrames > 0)
|
||||
{
|
||||
_perfTargetFrames = autoExitFrames;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(connectTarget))
|
||||
{
|
||||
StartRemoteSession(connectTarget, _callsign);
|
||||
}
|
||||
else if (hostTarget is not null)
|
||||
{
|
||||
StartListenHostSession(hostTarget, _callsign);
|
||||
}
|
||||
else
|
||||
{
|
||||
Reset(_seed, _mapKind);
|
||||
}
|
||||
|
||||
Reset(_seed, _mapKind);
|
||||
if (_perfTargetFrames > 0 && System.Environment.GetEnvironmentVariable("RTD_PERF_COMBAT") == "1" && _session is not null)
|
||||
{
|
||||
SetupPerfCombatScenario(_session);
|
||||
|
|
@ -124,53 +197,69 @@ public partial class Main : Node3D
|
|||
VehicleVisualInstance.PerfMaterialDupCount = 0;
|
||||
}
|
||||
|
||||
private void SetupPerfCombatScenario(ArenaSession session)
|
||||
private void SetupPerfCombatScenario(IClientArenaSession session)
|
||||
{
|
||||
var p = session.State.Contenders[0];
|
||||
float fwdX = MathF.Sin(p.Yaw);
|
||||
float fwdZ = MathF.Cos(p.Yaw);
|
||||
float rightX = -fwdZ;
|
||||
float rightZ = fwdX;
|
||||
|
||||
for (int i = 1; i <= 8 && i < session.State.Contenders.Count; i++)
|
||||
if (session is LocalArenaSession local)
|
||||
{
|
||||
float dist = 65f + (i % 4) * 11f;
|
||||
float lat = (i - 4.5f) * 11f;
|
||||
float tx = p.X + fwdX * dist + rightX * lat;
|
||||
float tz = p.Z + fwdZ * dist + rightZ * lat;
|
||||
session.SetContenderPose(session.State.Contenders[i].Id, tx, tz, p.Yaw + MathF.PI);
|
||||
var inner = local.Inner;
|
||||
var p = inner.State.Contenders[0];
|
||||
float fwdX = MathF.Sin(p.Yaw);
|
||||
float fwdZ = MathF.Cos(p.Yaw);
|
||||
float rightX = -fwdZ;
|
||||
float rightZ = fwdX;
|
||||
|
||||
for (int i = 1; i <= 8 && i < inner.State.Contenders.Count; i++)
|
||||
{
|
||||
float dist = 65f + (i % 4) * 11f;
|
||||
float lat = (i - 4.5f) * 11f;
|
||||
float tx = p.X + fwdX * dist + rightX * lat;
|
||||
float tz = p.Z + fwdZ * dist + rightZ * lat;
|
||||
inner.SetContenderPose(inner.State.Contenders[i].Id, tx, tz, p.Yaw + MathF.PI);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 6 && i < inner.State.Spectators.Spectators.Count; i++)
|
||||
{
|
||||
var s = inner.State.Spectators.Spectators[i];
|
||||
float dist = 78f + (i % 3) * 12f;
|
||||
float lat = (i - 2.5f) * 16f;
|
||||
float sx = p.X + fwdX * dist + rightX * lat;
|
||||
float sz = p.Z + fwdZ * dist + rightZ * lat;
|
||||
inner.SetSpectatorPose(s.Id, sx, sz, p.Yaw + MathF.PI);
|
||||
inner.State.Spectators.OnSpectatorDamaged(s, p.Id);
|
||||
}
|
||||
|
||||
var aimTarget = inner.State.Contenders[1];
|
||||
_scriptedInput = new PlayerInput(
|
||||
Throttle: 0.4f,
|
||||
Steer: 0f,
|
||||
AimWorldX: aimTarget.X,
|
||||
AimWorldZ: aimTarget.Z,
|
||||
Fire: true,
|
||||
InteractPickup: false,
|
||||
Brake: false);
|
||||
|
||||
_arena.Sync(session, _elapsedSeconds, 0f, 1f);
|
||||
UpdateCamera(1f, 1f);
|
||||
_hud.Sync(session);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 6 && i < session.State.Spectators.Spectators.Count; i++)
|
||||
{
|
||||
var s = session.State.Spectators.Spectators[i];
|
||||
float dist = 78f + (i % 3) * 12f;
|
||||
float lat = (i - 2.5f) * 16f;
|
||||
float sx = p.X + fwdX * dist + rightX * lat;
|
||||
float sz = p.Z + fwdZ * dist + rightZ * lat;
|
||||
session.SetSpectatorPose(s.Id, sx, sz, p.Yaw + MathF.PI);
|
||||
session.State.Spectators.OnSpectatorDamaged(s, p.Id);
|
||||
}
|
||||
|
||||
var aimTarget = session.State.Contenders[1];
|
||||
var localC = session.LocalContender;
|
||||
_scriptedInput = new PlayerInput(
|
||||
Throttle: 0.4f,
|
||||
Steer: 0f,
|
||||
AimWorldX: aimTarget.X,
|
||||
AimWorldZ: aimTarget.Z,
|
||||
Steer: 0.12f,
|
||||
AimWorldX: localC.X + MathF.Sin(localC.Yaw) * 60f,
|
||||
AimWorldZ: localC.Z + MathF.Cos(localC.Yaw) * 60f,
|
||||
Fire: true,
|
||||
InteractPickup: false,
|
||||
Brake: false);
|
||||
|
||||
_arena.Sync(session, _elapsedSeconds, 0f, 1f);
|
||||
UpdateCamera(1f, 1f);
|
||||
_hud.Sync(session);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
_session?.Dispose();
|
||||
_session = null;
|
||||
_boundViewState = null;
|
||||
}
|
||||
|
||||
public void Reset(int seed, ArenaMapKind? mapKind = null)
|
||||
|
|
@ -183,53 +272,259 @@ public partial class Main : Node3D
|
|||
|
||||
_session?.Dispose();
|
||||
_session = null;
|
||||
_boundViewState = null;
|
||||
_wasNetConnected = false;
|
||||
Failure = null;
|
||||
_hud.SetNetworkError(null);
|
||||
|
||||
try
|
||||
{
|
||||
_session = new ArenaSession(seed, _mapKind, slot0Human: true);
|
||||
var p = _session.State.Contenders[0];
|
||||
_cameraYaw = p.Yaw;
|
||||
_cameraPitch = _mapKind == ArenaMapKind.Sion ? Mathf.DegToRad(5f) : Mathf.DegToRad(12f);
|
||||
_cameraZoom = 1.0f;
|
||||
_lastCamChassisId = null;
|
||||
_camera.Far = _mapKind == ArenaMapKind.Sion ? 4200f : 1800f;
|
||||
ApplyEnvironmentForMap(_mapKind);
|
||||
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_terrain.Visible = false;
|
||||
_sionMap.Visible = true;
|
||||
_sionMap.EnsureBuilt(_session.State.SionMap!, _session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f, 1f);
|
||||
UpdateCamera(1f, 1f);
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
_sionMap.Visible = false;
|
||||
_terrain.Visible = true;
|
||||
_terrain.InvalidateAll();
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f, 1f);
|
||||
UpdateCamera(1f, 1f);
|
||||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
}
|
||||
|
||||
_hud.Sync(_session);
|
||||
|
||||
if (DisplayServer.GetName() != "headless" && !_hud.GarageExpanded && _perfTargetFrames == 0)
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
}
|
||||
_session = new LocalArenaSession(seed, _mapKind, _callsign);
|
||||
BindSessionPresentation(resetCamera: true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Failure = ex.Message;
|
||||
GD.PushError("ArenaSession startup failed: " + ex);
|
||||
GD.PushError("LocalArenaSession startup failed: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void StartListenHostSession(string hostArg, string callsign)
|
||||
{
|
||||
_callsign = string.IsNullOrWhiteSpace(callsign) ? "Host" : callsign.Trim();
|
||||
_session?.Dispose();
|
||||
_session = null;
|
||||
_boundViewState = null;
|
||||
_wasNetConnected = false;
|
||||
Failure = null;
|
||||
_hud.SetNetworkError(null);
|
||||
|
||||
try
|
||||
{
|
||||
ParseBindAndPort(hostArg, IPAddress.Loopback, DefaultNetPort, out IPAddress bindIp, out int port);
|
||||
var hostSession = new ListenHostArenaSession(bindIp, port, _seed, _mapKind);
|
||||
hostSession.Host.Session.SetHumanSlot(0, true, _callsign);
|
||||
_session = hostSession;
|
||||
_lastEndpoint = $"{bindIp}:{hostSession.Host.BoundPort}";
|
||||
_hud.SetNetworkDefaults(_lastEndpoint, _callsign);
|
||||
BindSessionPresentation(resetCamera: true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Failure = ex.Message;
|
||||
_hud.SetNetworkError(ex.Message);
|
||||
GD.PushError("ListenHostArenaSession startup failed: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void StartRemoteSession(string endpointText, string callsign)
|
||||
{
|
||||
_callsign = string.IsNullOrWhiteSpace(callsign) ? "Pilot" : callsign.Trim();
|
||||
_session?.Dispose();
|
||||
_session = null;
|
||||
_boundViewState = null;
|
||||
_wasNetConnected = false;
|
||||
Failure = null;
|
||||
_hud.SetNetworkError(null);
|
||||
|
||||
try
|
||||
{
|
||||
IPEndPoint ep = ResolveEndPoint(endpointText, DefaultNetPort);
|
||||
var remote = new RemoteArenaSession(ep, _callsign);
|
||||
remote.PumpNetwork();
|
||||
_session = remote;
|
||||
_lastEndpoint = endpointText.Trim();
|
||||
_hud.SetNetworkDefaults(_lastEndpoint, _callsign);
|
||||
BindSessionPresentation(resetCamera: true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Failure = ex.Message;
|
||||
_hud.SetNetworkError(ex.Message);
|
||||
GD.PushError("RemoteArenaSession startup failed: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSoloRequested()
|
||||
{
|
||||
Reset(_seed, _mapKind);
|
||||
}
|
||||
|
||||
private void OnHostRequested(int port, string callsign)
|
||||
{
|
||||
string? envBind = System.Environment.GetEnvironmentVariable("RTD_BIND");
|
||||
string hostArg = !string.IsNullOrWhiteSpace(envBind) ? $"{envBind.Trim()}:{port}" : port.ToString(CultureInfo.InvariantCulture);
|
||||
StartListenHostSession(hostArg, callsign);
|
||||
}
|
||||
|
||||
private void OnJoinRequested(string endpointText, string callsign)
|
||||
{
|
||||
StartRemoteSession(endpointText, callsign);
|
||||
}
|
||||
|
||||
private void BindSessionPresentation(bool resetCamera)
|
||||
{
|
||||
if (_session is null) return;
|
||||
var state = _session.ViewState;
|
||||
_boundViewState = state;
|
||||
_mapKind = state.MapKind;
|
||||
_seed = state.Seed;
|
||||
_wasNetConnected = _session.ConnectionStatus.Connected;
|
||||
|
||||
if (resetCamera)
|
||||
{
|
||||
var p = _session.LocalContender;
|
||||
_cameraYaw = p.Yaw;
|
||||
_cameraPitch = _mapKind == ArenaMapKind.Sion ? Mathf.DegToRad(5f) : Mathf.DegToRad(12f);
|
||||
_cameraZoom = 1.0f;
|
||||
_lastCamChassisId = null;
|
||||
}
|
||||
|
||||
_camera.Far = _mapKind == ArenaMapKind.Sion ? 4200f : 1800f;
|
||||
ApplyEnvironmentForMap(_mapKind);
|
||||
|
||||
if (_mapKind == ArenaMapKind.Sion && state.SionMap is not null)
|
||||
{
|
||||
_terrain.Visible = false;
|
||||
_sionMap.Visible = true;
|
||||
_sionMap.EnsureBuilt(state.SionMap, state.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f, 1f);
|
||||
UpdateCamera(1f, 1f);
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
_sionMap.Visible = false;
|
||||
_terrain.Visible = true;
|
||||
_terrain.InvalidateAll();
|
||||
_terrain.Sync(state.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f, 1f);
|
||||
UpdateCamera(1f, 1f);
|
||||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
}
|
||||
|
||||
_hud.Sync(_session);
|
||||
SyncMouseMode();
|
||||
}
|
||||
|
||||
private void SyncMouseMode()
|
||||
{
|
||||
if (DisplayServer.GetName() == "headless" || _perfTargetFrames > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool uiOpen = _hud.GarageExpanded || _hud.NetworkPanelOpen;
|
||||
Input.MouseMode = uiOpen ? Input.MouseModeEnum.Visible : Input.MouseModeEnum.Captured;
|
||||
}
|
||||
|
||||
private static string? GetCliArg(string flag, bool allowBareFlag = false)
|
||||
{
|
||||
static string? SearchArgs(string[] args, string flagName, bool bare)
|
||||
{
|
||||
string prefix = flagName + "=";
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
string a = args[i];
|
||||
if (a.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return a[prefix.Length..];
|
||||
}
|
||||
if (a.Equals(flagName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (i + 1 < args.Length && !args[i + 1].StartsWith("-", StringComparison.Ordinal))
|
||||
{
|
||||
return args[i + 1];
|
||||
}
|
||||
if (bare)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return SearchArgs(OS.GetCmdlineUserArgs(), flag, allowBareFlag)
|
||||
?? SearchArgs(OS.GetCmdlineArgs(), flag, allowBareFlag);
|
||||
}
|
||||
|
||||
private static void ParseBindAndPort(string? raw, IPAddress defaultIp, int defaultPort, out IPAddress bindIp, out int port)
|
||||
{
|
||||
bindIp = defaultIp;
|
||||
port = defaultPort;
|
||||
string trimmed = (raw ?? string.Empty).Trim();
|
||||
if (string.IsNullOrEmpty(trimmed))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int colon = trimmed.LastIndexOf(':');
|
||||
if (colon >= 0)
|
||||
{
|
||||
string ipPart = trimmed[..colon].Trim();
|
||||
string portPart = trimmed[(colon + 1)..].Trim();
|
||||
if (!string.IsNullOrEmpty(ipPart) && IPAddress.TryParse(ipPart, out var parsedIp))
|
||||
{
|
||||
bindIp = parsedIp;
|
||||
}
|
||||
if (int.TryParse(portPart, NumberStyles.Integer, CultureInfo.InvariantCulture, out int p) && p is > 0 and <= 65535)
|
||||
{
|
||||
port = p;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (int.TryParse(trimmed, NumberStyles.Integer, CultureInfo.InvariantCulture, out int onlyPort) && onlyPort is > 0 and <= 65535)
|
||||
{
|
||||
port = onlyPort;
|
||||
}
|
||||
else if (IPAddress.TryParse(trimmed, out var onlyIp))
|
||||
{
|
||||
bindIp = onlyIp;
|
||||
}
|
||||
}
|
||||
|
||||
private static IPEndPoint ResolveEndPoint(string endpointText, int defaultPort)
|
||||
{
|
||||
string trimmed = (endpointText ?? string.Empty).Trim();
|
||||
if (string.IsNullOrEmpty(trimmed))
|
||||
{
|
||||
throw new ArgumentException("Server endpoint cannot be empty.");
|
||||
}
|
||||
|
||||
string host = trimmed;
|
||||
int port = defaultPort;
|
||||
int colon = trimmed.LastIndexOf(':');
|
||||
if (colon > 0 && trimmed[..colon].IndexOf(':') < 0)
|
||||
{
|
||||
host = trimmed[..colon].Trim();
|
||||
string portStr = trimmed[(colon + 1)..].Trim();
|
||||
if (!int.TryParse(portStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out port) || port is <= 0 or > 65535)
|
||||
{
|
||||
throw new FormatException($"Invalid port in endpoint '{endpointText}'.");
|
||||
}
|
||||
}
|
||||
|
||||
if (IPAddress.TryParse(host, out var ip))
|
||||
{
|
||||
return new IPEndPoint(ip, port);
|
||||
}
|
||||
|
||||
var addrs = Dns.GetHostAddresses(host);
|
||||
for (int i = 0; i < addrs.Length; i++)
|
||||
{
|
||||
if (addrs[i].AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
return new IPEndPoint(addrs[i], port);
|
||||
}
|
||||
}
|
||||
if (addrs.Length > 0)
|
||||
{
|
||||
return new IPEndPoint(addrs[0], port);
|
||||
}
|
||||
throw new SocketException((int)SocketError.HostNotFound);
|
||||
}
|
||||
|
||||
public void SetScriptedInput(PlayerInput? input) => _scriptedInput = input;
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
|
|
@ -246,6 +541,39 @@ public partial class Main : Node3D
|
|||
|
||||
if (@event is InputEventKey key && key.Pressed && !key.Echo)
|
||||
{
|
||||
if (key.Keycode == Key.F9)
|
||||
{
|
||||
_hud.ToggleNetworkPanel();
|
||||
SyncMouseMode();
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.Keycode == Key.Escape)
|
||||
{
|
||||
if (_hud.NetworkPanelOpen)
|
||||
{
|
||||
_hud.SetNetworkPanelOpen(false);
|
||||
SyncMouseMode();
|
||||
}
|
||||
else if (_hud.GarageExpanded)
|
||||
{
|
||||
_hud.ToggleGarage();
|
||||
SyncMouseMode();
|
||||
}
|
||||
else if (DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = Input.MouseMode == Input.MouseModeEnum.Captured
|
||||
? Input.MouseModeEnum.Visible
|
||||
: Input.MouseModeEnum.Captured;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (_hud.IsUiTextInputFocused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (key.Keycode)
|
||||
{
|
||||
case Key.E:
|
||||
|
|
@ -253,34 +581,13 @@ public partial class Main : Node3D
|
|||
break;
|
||||
case Key.Tab:
|
||||
_hud.ToggleGarage();
|
||||
if (DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = _hud.GarageExpanded
|
||||
? Input.MouseModeEnum.Visible
|
||||
: Input.MouseModeEnum.Captured;
|
||||
}
|
||||
SyncMouseMode();
|
||||
break;
|
||||
case Key.R:
|
||||
Reset(_seed + 1, _mapKind);
|
||||
_session?.RequestNewMatch(_seed + 1, _mapKind);
|
||||
break;
|
||||
case Key.M:
|
||||
Reset(_seed, _mapKind == ArenaMapKind.Sion ? ArenaMapKind.Desert : ArenaMapKind.Sion);
|
||||
break;
|
||||
case Key.Escape:
|
||||
if (_hud.GarageExpanded)
|
||||
{
|
||||
_hud.ToggleGarage();
|
||||
if (DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
}
|
||||
}
|
||||
else if (DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = Input.MouseMode == Input.MouseModeEnum.Captured
|
||||
? Input.MouseModeEnum.Visible
|
||||
: Input.MouseModeEnum.Captured;
|
||||
}
|
||||
_session?.RequestNewMatch(_seed, _mapKind == ArenaMapKind.Sion ? ArenaMapKind.Desert : ArenaMapKind.Sion);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -297,6 +604,7 @@ public partial class Main : Node3D
|
|||
else if (mb.ButtonIndex == MouseButton.Left &&
|
||||
Input.MouseMode == Input.MouseModeEnum.Visible &&
|
||||
!_hud.GarageExpanded &&
|
||||
!_hud.NetworkPanelOpen &&
|
||||
!_hud.IsPointerOverInteractiveHud(mb.Position) &&
|
||||
DisplayServer.GetName() != "headless")
|
||||
{
|
||||
|
|
@ -319,8 +627,7 @@ public partial class Main : Node3D
|
|||
if (_perfTargetFrames > 0)
|
||||
{
|
||||
long t0 = Stopwatch.GetTimestamp();
|
||||
_session.SetHumanInput(0, input);
|
||||
_session.Step();
|
||||
_session.SubmitLocalInput(in input, isPhysicsTick: true);
|
||||
long t1 = Stopwatch.GetTimestamp();
|
||||
double toMs = 1000.0 / Stopwatch.Frequency;
|
||||
_perfPendingStepMs += (t1 - t0) * toMs;
|
||||
|
|
@ -328,8 +635,7 @@ public partial class Main : Node3D
|
|||
}
|
||||
else
|
||||
{
|
||||
_session.SetHumanInput(0, input);
|
||||
_session.Step();
|
||||
_session.SubmitLocalInput(in input, isPhysicsTick: true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -341,14 +647,47 @@ public partial class Main : Node3D
|
|||
}
|
||||
|
||||
float alpha = Math.Clamp((float)Engine.GetPhysicsInterpolationFraction(), 0f, 1f);
|
||||
_session.BeginRenderFrame(delta, alpha);
|
||||
|
||||
bool nowConnected = _session.ConnectionStatus.Connected;
|
||||
if (!ReferenceEquals(_boundViewState, _session.ViewState) || (!_wasNetConnected && nowConnected))
|
||||
{
|
||||
BindSessionPresentation(resetCamera: true);
|
||||
if (_perfTargetFrames > 0 && !_wasNetConnected && nowConnected)
|
||||
{
|
||||
_perfFrameCount = 0;
|
||||
_perfPhysicsTicks = 0;
|
||||
_perfFrameMs.Clear();
|
||||
_perfPhysicsStepMs.Clear();
|
||||
_perfTerrainSyncMs.Clear();
|
||||
_perfArenaSyncMs.Clear();
|
||||
_perfHudMs.Clear();
|
||||
_perfDirtyRebakeDelta.Clear();
|
||||
_perfDrawCalls.Clear();
|
||||
_perfPrimitives.Clear();
|
||||
_perfObjects.Clear();
|
||||
_perfNodeCount.Clear();
|
||||
_perfTimeProcess.Clear();
|
||||
_perfTimePhysicsProcess.Clear();
|
||||
_perfCamMsSum = 0;
|
||||
_perfLastFrameTick = Stopwatch.GetTimestamp();
|
||||
}
|
||||
}
|
||||
_wasNetConnected = nowConnected;
|
||||
|
||||
if (_perfTargetFrames > 0)
|
||||
{
|
||||
if (_session.ConnectionStatus.Mode == NetworkMode.RemoteClient && !nowConnected && _perfWaitConnectFrames < 300)
|
||||
{
|
||||
_perfWaitConnectFrames++;
|
||||
_perfLastFrameTick = Stopwatch.GetTimestamp();
|
||||
return;
|
||||
}
|
||||
double toMs = 1000.0 / Stopwatch.Frequency;
|
||||
long tt0 = Stopwatch.GetTimestamp();
|
||||
if (_mapKind == ArenaMapKind.Desert)
|
||||
{
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_terrain.Sync(_session.ViewState.Terrain);
|
||||
}
|
||||
long tt1 = Stopwatch.GetTimestamp();
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta, alpha);
|
||||
|
|
@ -406,7 +745,7 @@ public partial class Main : Node3D
|
|||
{
|
||||
if (_mapKind == ArenaMapKind.Desert)
|
||||
{
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_terrain.Sync(_session.ViewState.Terrain);
|
||||
}
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta, alpha);
|
||||
UpdateCamera((float)delta, alpha);
|
||||
|
|
@ -467,8 +806,15 @@ public partial class Main : Node3D
|
|||
GD.Print($"TimeProcessMs: avg={Avg(_perfTimeProcess):F2}");
|
||||
GD.Print($"TimePhysicsProcessMs: avg={Avg(_perfTimePhysicsProcess):F2}");
|
||||
GD.Print($"UpdateCameraMs/frame: avg={_perfCamMsSum / _perfFrameMs.Count:F2}");
|
||||
GD.Print($"StepBreakdownMs/tick: ring={ArenaSession.PerfRingMs / _perfPhysicsTicks:F2} ai={ArenaSession.PerfAiMs / _perfPhysicsTicks:F2} drive={ArenaSession.PerfDriveMs / _perfPhysicsTicks:F2} world={ArenaSession.PerfWorldMs / _perfPhysicsTicks:F2} sync={ArenaSession.PerfBodySyncMs / _perfPhysicsTicks:F2} detect={ArenaSession.PerfDetectMs / _perfPhysicsTicks:F2} weapons={ArenaSession.PerfWeaponsMs / _perfPhysicsTicks:F2}");
|
||||
GD.Print($"CombatProbes: syncDamageHeatMsTotal={VehicleVisualInstance.PerfDamageHeatMs:F2} matDups={VehicleVisualInstance.PerfMaterialDupCount} bakeTileMsTotal={TerrainRenderer.PerfBakeTileMs:F2} bakeTileCalls={TerrainRenderer.PerfBakeTileCalls} debrisActive={_arena.Debris.ActiveCount} tracers={_session?.State.Tracers.Count ?? 0}");
|
||||
int ticks = Math.Max(1, _perfPhysicsTicks);
|
||||
GD.Print($"StepBreakdownMs/tick: ring={ArenaSession.PerfRingMs / ticks:F2} ai={ArenaSession.PerfAiMs / ticks:F2} drive={ArenaSession.PerfDriveMs / ticks:F2} world={ArenaSession.PerfWorldMs / ticks:F2} sync={ArenaSession.PerfBodySyncMs / ticks:F2} detect={ArenaSession.PerfDetectMs / ticks:F2} weapons={ArenaSession.PerfWeaponsMs / ticks:F2}");
|
||||
GD.Print($"CombatProbes: syncDamageHeatMsTotal={VehicleVisualInstance.PerfDamageHeatMs:F2} matDups={VehicleVisualInstance.PerfMaterialDupCount} bakeTileMsTotal={TerrainRenderer.PerfBakeTileMs:F2} bakeTileCalls={TerrainRenderer.PerfBakeTileCalls} debrisActive={_arena.Debris.ActiveCount} tracers={_session?.ViewState.Tracers.Count ?? 0}");
|
||||
if (_session is not null)
|
||||
{
|
||||
var net = _session.ConnectionStatus;
|
||||
uint snapSeq = _session is RemoteArenaSession remote ? remote.LastSnapshotSeq : 0u;
|
||||
GD.Print($"NetStatus: mode={net.Mode} connected={net.Connected} localSlot={_session.LocalContenderId} pingMs={net.PingMs} humans={net.ConnectedHumans}/{net.MaxHumans} snapshotSeq={snapSeq} label='{net.StateLabel}'");
|
||||
}
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
GD.Print($"SionMap: chunks={_sionMap.TerrainChunkCount} tiles={_sionMap.BuildingTileCount} lod1={_sionMap.ActiveLod1TileCount} lod2={_sionMap.ActiveLod2TileCount} culled={_sionMap.CulledTileCount}");
|
||||
|
|
@ -501,7 +847,11 @@ public partial class Main : Node3D
|
|||
GD.Print($" Paladin sample nodes: {string.Join(", ", names)}");
|
||||
}
|
||||
GD.Print("=== END PERF BENCHMARK ===");
|
||||
string? previewOut = System.Environment.GetEnvironmentVariable("RTD_CAPTURE_PREVIEW");
|
||||
string? previewOut = System.Environment.GetEnvironmentVariable("RTD_PREVIEW_OUT");
|
||||
if (string.IsNullOrWhiteSpace(previewOut))
|
||||
{
|
||||
previewOut = System.Environment.GetEnvironmentVariable("RTD_CAPTURE_PREVIEW");
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(previewOut) && DisplayServer.GetName() != "headless")
|
||||
{
|
||||
var img = GetViewport().GetTexture()?.GetImage();
|
||||
|
|
@ -530,6 +880,21 @@ public partial class Main : Node3D
|
|||
|
||||
private PlayerInput GatherPlayerInput()
|
||||
{
|
||||
var (aimX, aimY, aimZ) = ComputeCenterScreenAim();
|
||||
if (_hud.IsUiTextInputFocused)
|
||||
{
|
||||
return new PlayerInput(
|
||||
Throttle: 0f,
|
||||
Steer: 0f,
|
||||
AimWorldX: aimX,
|
||||
AimWorldZ: aimZ,
|
||||
Fire: false,
|
||||
InteractPickup: false,
|
||||
Brake: false,
|
||||
AimWorldY: aimY,
|
||||
VerticalThrottle: 0f);
|
||||
}
|
||||
|
||||
float throttle = 0f;
|
||||
if (Input.IsKeyPressed(Key.W) || Input.IsKeyPressed(Key.Up)) throttle += 1f;
|
||||
if (Input.IsKeyPressed(Key.S) || Input.IsKeyPressed(Key.Down)) throttle -= 1f;
|
||||
|
|
@ -538,17 +903,16 @@ public partial class Main : Node3D
|
|||
if (Input.IsKeyPressed(Key.D) || Input.IsKeyPressed(Key.Right)) steer += 1f;
|
||||
if (Input.IsKeyPressed(Key.A) || Input.IsKeyPressed(Key.Left)) steer -= 1f;
|
||||
|
||||
bool isVtol = Session.State.Contenders[0].Grid.Spec.IsVtol;
|
||||
bool isVtol = Session.LocalContender.Grid.Spec.IsVtol;
|
||||
float verticalThrottle = 0f;
|
||||
if (Input.IsKeyPressed(Key.Space)) verticalThrottle += 1f;
|
||||
if (Input.IsKeyPressed(Key.C) || Input.IsKeyPressed(Key.Ctrl)) verticalThrottle -= 1f;
|
||||
|
||||
bool brake = isVtol ? Input.IsKeyPressed(Key.Shift) : Input.IsKeyPressed(Key.Space);
|
||||
bool pointerOnHud = Input.MouseMode != Input.MouseModeEnum.Captured &&
|
||||
_hud.IsPointerOverInteractiveHud(GetViewport().GetMousePosition());
|
||||
(_hud.NetworkPanelOpen || _hud.IsPointerOverInteractiveHud(GetViewport().GetMousePosition()));
|
||||
bool fire = !pointerOnHud && Input.IsMouseButtonPressed(MouseButton.Left);
|
||||
|
||||
var (aimX, aimY, aimZ) = ComputeCenterScreenAim();
|
||||
return new PlayerInput(
|
||||
Throttle: throttle,
|
||||
Steer: steer,
|
||||
|
|
@ -563,7 +927,7 @@ public partial class Main : Node3D
|
|||
|
||||
private (float AimX, float AimY, float AimZ) ComputeCenterScreenAim()
|
||||
{
|
||||
var player = Session.State.Contenders[0];
|
||||
var player = Session.LocalContender;
|
||||
var spec = player.Grid.Spec;
|
||||
Vector2 screenSize = GetViewport().GetVisibleRect().Size;
|
||||
if (screenSize.X < 2f || screenSize.Y < 2f)
|
||||
|
|
@ -579,8 +943,9 @@ public partial class Main : Node3D
|
|||
Vector3 rayDir = _camera.ProjectRayNormal(center);
|
||||
|
||||
const float maxAimDist = 450f;
|
||||
ulong playerStableId = ArenaSession.ContenderStableIdBase + (ulong)player.Id;
|
||||
Vector3 playerCenter = new Vector3(player.X, player.Y, player.Z);
|
||||
ulong playerStableId = ContenderStableIdBase + (ulong)player.Id;
|
||||
var (pPos, _, _) = Session.GetInterpolatedContenderPose(player.Id, 1f);
|
||||
Vector3 playerCenter = new Vector3(pPos.X, pPos.Y, pPos.Z);
|
||||
float camToCenterProj = (playerCenter - rayOrigin).Dot(rayDir);
|
||||
float minForwardDot = -MathF.Max(spec.HalfWidth, spec.HalfLength) * 0.35f;
|
||||
|
||||
|
|
@ -594,12 +959,12 @@ public partial class Main : Node3D
|
|||
Vector3 boxHitPt = Vector3.Zero;
|
||||
bool hasBoxHit = false;
|
||||
|
||||
// Cast against Ymir world, skipping the player's own chassis and any surface behind the vehicle's forward plane.
|
||||
// Cast against session world, skipping the player's own chassis and any surface behind the vehicle's forward plane.
|
||||
for (int attempt = 0; attempt < 4 && remainingDist > 1f; attempt++)
|
||||
{
|
||||
var hit = Session.World.CastRayClosest(
|
||||
(castOrigin.X, castOrigin.Y, castOrigin.Z),
|
||||
(rayDir.X * remainingDist, rayDir.Y * remainingDist, rayDir.Z * remainingDist));
|
||||
var hit = Session.CastWorldRayClosest(
|
||||
new System.Numerics.Vector3(castOrigin.X, castOrigin.Y, castOrigin.Z),
|
||||
new System.Numerics.Vector3(rayDir.X * remainingDist, rayDir.Y * remainingDist, rayDir.Z * remainingDist));
|
||||
if (!hit.Hit)
|
||||
{
|
||||
break;
|
||||
|
|
@ -628,7 +993,7 @@ public partial class Main : Node3D
|
|||
{
|
||||
Vector3 tOrigin = rayOrigin + rayDir * terrainStartDist;
|
||||
float tMaxDist = boxDist - terrainStartDist;
|
||||
if (!Session.State.Terrain.Raycast(
|
||||
if (!Session.ViewState.Terrain.Raycast(
|
||||
tOrigin.X, tOrigin.Y, tOrigin.Z,
|
||||
rayDir.X, rayDir.Y, rayDir.Z,
|
||||
maxDistance: tMaxDist,
|
||||
|
|
@ -669,7 +1034,7 @@ public partial class Main : Node3D
|
|||
|
||||
private void UpdateCamera(float dt, float alpha)
|
||||
{
|
||||
var p = Session.State.Contenders[0];
|
||||
var p = Session.LocalContender;
|
||||
var spec = p.Grid.Spec;
|
||||
var (posInterp, _, _) = Session.GetInterpolatedContenderPose(p.Id, alpha);
|
||||
|
||||
|
|
@ -699,7 +1064,7 @@ public partial class Main : Node3D
|
|||
float effectiveRight = rightOffset;
|
||||
if (CastStaticCameraRay(pivot, camRight, rightOffset, out float rightHitDist))
|
||||
{
|
||||
effectiveRight = MathF.Min(effectiveRight, MathF.Max(0f, MathF.Min(rightHitDist - 0.35f, rightHitDist * 0.85f)));
|
||||
effectiveRight = MathF.Min(effectiveRight, SafeCameraPullbackDist(rightHitDist));
|
||||
}
|
||||
Vector3 shoulderPos = pivot + camRight * effectiveRight;
|
||||
|
||||
|
|
@ -712,7 +1077,7 @@ public partial class Main : Node3D
|
|||
|
||||
Vector3 camPos = shoulderPos - lookDir * effectiveBack;
|
||||
|
||||
float minTerrainY = Session.State.Terrain.SampleHeight(camPos.X, camPos.Z) + 1.2f;
|
||||
float minTerrainY = Session.ViewState.Terrain.SampleHeight(camPos.X, camPos.Z) + 1.2f;
|
||||
if (camPos.Y < minTerrainY)
|
||||
{
|
||||
camPos.Y = minTerrainY;
|
||||
|
|
@ -746,7 +1111,7 @@ public partial class Main : Node3D
|
|||
}
|
||||
|
||||
bool hasHit = false;
|
||||
if (Session.State.Terrain.Raycast(
|
||||
if (Session.ViewState.Terrain.Raycast(
|
||||
origin.X, origin.Y, origin.Z,
|
||||
dir.X, dir.Y, dir.Z,
|
||||
maxDist,
|
||||
|
|
@ -761,9 +1126,9 @@ public partial class Main : Node3D
|
|||
float remaining = hitDist;
|
||||
for (int attempt = 0; attempt < 16 && remaining > 0.05f; attempt++)
|
||||
{
|
||||
var hit = Session.World.CastRayClosest(
|
||||
(castOrigin.X, castOrigin.Y, castOrigin.Z),
|
||||
(dir.X * remaining, dir.Y * remaining, dir.Z * remaining));
|
||||
var hit = Session.CastWorldRayClosest(
|
||||
new System.Numerics.Vector3(castOrigin.X, castOrigin.Y, castOrigin.Z),
|
||||
new System.Numerics.Vector3(dir.X * remaining, dir.Y * remaining, dir.Z * remaining));
|
||||
if (!hit.Hit)
|
||||
{
|
||||
break;
|
||||
|
|
@ -771,7 +1136,7 @@ public partial class Main : Node3D
|
|||
|
||||
var pt = new Vector3(hit.Point.X, hit.Point.Y, hit.Point.Z);
|
||||
float distFromOrigin = origin.DistanceTo(pt);
|
||||
if (hit.StableId < ArenaSession.ContenderStableIdBase)
|
||||
if (hit.StableId < ContenderStableIdBase)
|
||||
{
|
||||
if (distFromOrigin < hitDist)
|
||||
{
|
||||
|
|
@ -796,7 +1161,7 @@ public partial class Main : Node3D
|
|||
|
||||
private void OnEquipCargo(int cargoIndex, string hardpointId)
|
||||
{
|
||||
_session?.TryEquipCargo(0, cargoIndex, hardpointId);
|
||||
_session?.RequestEquipCargo(cargoIndex, hardpointId);
|
||||
}
|
||||
|
||||
private void SetupLightingAndSky()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ using System;
|
|||
using System.IO;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
|
|
@ -121,12 +120,12 @@ public partial class PomDecalPool : Node3D
|
|||
}
|
||||
|
||||
public void Sync(
|
||||
ArenaSession session,
|
||||
IClientArenaSession session,
|
||||
float dt,
|
||||
Func<bool, int, VehicleVisualInstance?> getVisual)
|
||||
{
|
||||
EnsureInitialized();
|
||||
var state = session.State;
|
||||
var state = session.ViewState;
|
||||
if (!ReferenceEquals(_boundState, state))
|
||||
{
|
||||
_boundState = state;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\src\RustToDust.Ymir\RustToDust.Ymir.csproj" />
|
||||
<ProjectReference Include="..\src\RustToDust.Net\RustToDust.Net.csproj" />
|
||||
<ProjectReference Include="$(YmirRoot)/src/Ymir.Box3D/Ymir.Box3D.csproj" AdditionalProperties="YmirNativeConfiguration=$(YmirNativeConfiguration)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Net;
|
||||
using RustToDust.Ymir;
|
||||
|
||||
namespace RustToDust.Client.Tests;
|
||||
|
||||
|
|
@ -40,7 +43,7 @@ public partial class Smoke : Node
|
|||
|
||||
if (_main.Failure is { } failure)
|
||||
{
|
||||
Check(false, "Main failed to initialize ArenaSession: " + failure);
|
||||
Check(false, "Main failed to initialize IClientArenaSession: " + failure);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -62,7 +65,7 @@ public partial class Smoke : Node
|
|||
Check(!_main.GetWorld3D().Space.IsValid, "Godot should have no active 3D physics space");
|
||||
Check(_main.Terrain.BakedTileCount == 64, $"Expected 64 baked terrain tiles, got {_main.Terrain.BakedTileCount}");
|
||||
|
||||
var player = _main.Session.State.Contenders[0];
|
||||
var player = _main.Session.ViewState.Contenders[0];
|
||||
float startX = player.X;
|
||||
float startZ = player.Z;
|
||||
|
||||
|
|
@ -98,7 +101,7 @@ public partial class Smoke : Node
|
|||
|
||||
bool isHeadless = DisplayServer.GetName() == "headless";
|
||||
int rebakesBefore = _main.Terrain.DirtyRebakes;
|
||||
float cpuBefore = _main.Session.State.Terrain.SampleHeight(-96f, -96f);
|
||||
float cpuBefore = _main.Session.ViewState.Terrain.SampleHeight(-96f, -96f);
|
||||
float gpuBefore = 0f;
|
||||
if (!isHeadless)
|
||||
{
|
||||
|
|
@ -120,11 +123,11 @@ public partial class Smoke : Node
|
|||
// Verify brushed terrain relief (tallest Mesa/DuneRidge center) so a flat-map bug can never pass
|
||||
TerrainBrush? reliefBrush = null;
|
||||
float bestHillCpu = 0f;
|
||||
foreach (var b in _main.Session.State.Terrain.Brushes)
|
||||
foreach (var b in _main.Session.ViewState.Terrain.Brushes)
|
||||
{
|
||||
if (b.Kind == TerrainBrushKind.Mesa || (b.Kind == TerrainBrushKind.DuneRidge && b.HeightDelta > 0f))
|
||||
{
|
||||
float h = _main.Session.State.Terrain.SampleHeight(b.X, b.Z);
|
||||
float h = _main.Session.ViewState.Terrain.SampleHeight(b.X, b.Z);
|
||||
if (h > bestHillCpu)
|
||||
{
|
||||
bestHillCpu = h;
|
||||
|
|
@ -173,12 +176,12 @@ public partial class Smoke : Node
|
|||
Check(maxSeamErr < 0.01f, $"Expected tile seam error < 0.01m, got {maxSeamErr:F5}m");
|
||||
}
|
||||
|
||||
_main.Session.State.Terrain.StampCrater(-96f, -96f, radius: 5f, depth: 1.4f);
|
||||
_main.Terrain.Sync(_main.Session.State.Terrain);
|
||||
_main.Session.ViewState.Terrain.StampCrater(-96f, -96f, radius: 5f, depth: 1.4f);
|
||||
_main.Terrain.Sync(_main.Session.ViewState.Terrain);
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
|
||||
float cpuAfter = _main.Session.State.Terrain.SampleHeight(-96f, -96f);
|
||||
float cpuAfter = _main.Session.ViewState.Terrain.SampleHeight(-96f, -96f);
|
||||
Check(cpuAfter < cpuBefore - 0.8f,
|
||||
$"Expected CPU terrain height to drop after crater stamp (before {cpuBefore:F2}m, after {cpuAfter:F2}m)");
|
||||
Check(_main.Terrain.DirtyRebakes == rebakesBefore + 1,
|
||||
|
|
@ -203,9 +206,9 @@ public partial class Smoke : Node
|
|||
// and passive Track throttling preserves DirtyTileMask until all tiles are baked without skipping via _rebakeCursor.
|
||||
{
|
||||
// Flush any lingering track rebakes first so baseline is clean
|
||||
for (int flush = 0; flush < 32 && _main.Session.State.Terrain.DirtyTileMask != 0UL; flush++)
|
||||
for (int flush = 0; flush < 32 && _main.Session.ViewState.Terrain.DirtyTileMask != 0UL; flush++)
|
||||
{
|
||||
_main.Terrain.Sync(_main.Session.State.Terrain);
|
||||
_main.Terrain.Sync(_main.Session.ViewState.Terrain);
|
||||
}
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
|
||||
|
|
@ -221,11 +224,11 @@ public partial class Smoke : Node
|
|||
}
|
||||
|
||||
int rebakes4Before = _main.Terrain.DirtyRebakes;
|
||||
_main.Session.State.Terrain.StampCrater(0f, 0f, radius: 6f, depth: 1.4f);
|
||||
_main.Terrain.Sync(_main.Session.State.Terrain); // Sync#1
|
||||
_main.Session.ViewState.Terrain.StampCrater(0f, 0f, radius: 6f, depth: 1.4f);
|
||||
_main.Terrain.Sync(_main.Session.ViewState.Terrain); // Sync#1
|
||||
Check(_main.Terrain.DirtyRebakes == rebakes4Before + 4,
|
||||
$"Expected 4-tile boundary crater at (0,0) to bake all 4 tiles on Sync#1, got {_main.Terrain.DirtyRebakes - rebakes4Before}");
|
||||
Check(_main.Session.State.Terrain.StructuralDirtyTileMask == 0UL,
|
||||
Check(_main.Session.ViewState.Terrain.StructuralDirtyTileMask == 0UL,
|
||||
"Expected StructuralDirtyTileMask == 0 after Sync#1 on 4-tile boundary crater");
|
||||
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
|
|
@ -235,7 +238,7 @@ public partial class Smoke : Node
|
|||
{
|
||||
for (int q = 0; q < 4; q++)
|
||||
{
|
||||
float qCpu = _main.Session.State.Terrain.SampleHeight(quadrants[q].Qx, quadrants[q].Qz);
|
||||
float qCpu = _main.Session.ViewState.Terrain.SampleHeight(quadrants[q].Qx, quadrants[q].Qz);
|
||||
bool ok = _main.Terrain.TrySampleBakedHeight(quadrants[q].Qx, quadrants[q].Qz, out float qGpu);
|
||||
Check(ok, $"Expected GPU readback on quadrant {q} after 4-tile boundary crater");
|
||||
if (ok)
|
||||
|
|
@ -250,18 +253,18 @@ public partial class Smoke : Node
|
|||
|
||||
// Stamp 3 passive tracks in adjacent tiles so _rebakeCursor must advance across Sync#1 and Sync#2 without skipping
|
||||
int rebakesTrackBefore = _main.Terrain.DirtyRebakes;
|
||||
_main.Session.State.Terrain.StampTrack(-480f, -480f, 0f, 2f, 3f);
|
||||
_main.Session.State.Terrain.StampTrack(-288f, -480f, 0f, 2f, 3f);
|
||||
_main.Session.State.Terrain.StampTrack(-96f, -480f, 0f, 2f, 3f);
|
||||
_main.Terrain.Sync(_main.Session.State.Terrain);
|
||||
_main.Session.ViewState.Terrain.StampTrack(-480f, -480f, 0f, 2f, 3f);
|
||||
_main.Session.ViewState.Terrain.StampTrack(-288f, -480f, 0f, 2f, 3f);
|
||||
_main.Session.ViewState.Terrain.StampTrack(-96f, -480f, 0f, 2f, 3f);
|
||||
_main.Terrain.Sync(_main.Session.ViewState.Terrain);
|
||||
Check(_main.Terrain.DirtyRebakes == rebakesTrackBefore + 2,
|
||||
$"Expected Sync#1 to throttle 3 passive tracks to 2 rebakes, got {_main.Terrain.DirtyRebakes - rebakesTrackBefore}");
|
||||
Check(_main.Session.State.Terrain.DirtyTileMask != 0UL,
|
||||
Check(_main.Session.ViewState.Terrain.DirtyTileMask != 0UL,
|
||||
"Expected DirtyTileMask to stay non-zero while 1 passive track tile remains dirty");
|
||||
_main.Terrain.Sync(_main.Session.State.Terrain);
|
||||
_main.Terrain.Sync(_main.Session.ViewState.Terrain);
|
||||
Check(_main.Terrain.DirtyRebakes == rebakesTrackBefore + 3,
|
||||
$"Expected Sync#2 to bake remaining 3rd passive track tile without _rebakeCursor skip, got {_main.Terrain.DirtyRebakes - rebakesTrackBefore}");
|
||||
Check(_main.Session.State.Terrain.DirtyTileMask == 0UL,
|
||||
Check(_main.Session.ViewState.Terrain.DirtyTileMask == 0UL,
|
||||
"Expected DirtyTileMask == 0 after all passive track tiles baked");
|
||||
}
|
||||
|
||||
|
|
@ -287,7 +290,7 @@ public partial class Smoke : Node
|
|||
Check(mat.Shader is not null && !string.IsNullOrWhiteSpace(mat.Shader.Code),
|
||||
$"panel_chrome.gdshader failed to load on HUD panel #{chromeCount}");
|
||||
}
|
||||
Check(chromeCount == 5, $"Expected 5 ChromePanel materials on HUD, got {chromeCount}");
|
||||
Check(chromeCount == 6, $"Expected 6 ChromePanel materials on HUD, got {chromeCount}");
|
||||
|
||||
// Pack a real Ironclad chassis with mounted modules, thermal gradient, stripped cell, and active hit-pulse
|
||||
var testGrid = new ChassisGrid(Catalog.Ironclad);
|
||||
|
|
@ -371,6 +374,12 @@ public partial class Smoke : Node
|
|||
Check(!_main.Hud.HasPanelOverlapOrClip(vpSize), $"Garage HUD panels overlapped or clipped at {vpSize}");
|
||||
_main.Hud.ToggleGarage();
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
_main.Hud.ToggleNetworkPanel();
|
||||
_main.Hud.Sync(_main.Session);
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
Check(!_main.Hud.HasPanelOverlapOrClip(vpSize), $"F9 Network HUD panel overlapped or clipped at {vpSize}");
|
||||
_main.Hud.ToggleNetworkPanel();
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
|
||||
if (isHeadless)
|
||||
{
|
||||
|
|
@ -580,7 +589,7 @@ public partial class Smoke : Node
|
|||
}
|
||||
|
||||
// Seed realistic combat telemetry so the preview clearly showcases armor stripping, hit-flash, cargo rack, and thermal heat
|
||||
var player = _main.Session.State.Contenders[0];
|
||||
var player = _main.Session.ViewState.Contenders[0];
|
||||
var grid = player.Grid;
|
||||
grid.TryAddCargo(Catalog.TouringPlasma);
|
||||
grid.TryAddCargo(Catalog.GoldRadiator);
|
||||
|
|
@ -594,17 +603,17 @@ public partial class Smoke : Node
|
|||
float fwdZ = MathF.Cos(_main.CameraYaw);
|
||||
float rightX = -fwdZ;
|
||||
float rightZ = fwdX;
|
||||
if (_main.Session.State.Contenders.Count > 2)
|
||||
if (_main.Session is LocalArenaSession localPreview && localPreview.Inner.State.Contenders.Count > 2)
|
||||
{
|
||||
var r1 = _main.Session.State.Contenders[1];
|
||||
var r1 = localPreview.Inner.State.Contenders[1];
|
||||
if (r1.Alive)
|
||||
{
|
||||
_main.Session.SetContenderPose(r1.Id, player.X + fwdX * 19f - rightX * 5.5f, player.Z + fwdZ * 19f - rightZ * 5.5f, _main.CameraYaw + MathF.PI * 0.82f);
|
||||
localPreview.Inner.SetContenderPose(r1.Id, player.X + fwdX * 19f - rightX * 5.5f, player.Z + fwdZ * 19f - rightZ * 5.5f, _main.CameraYaw + MathF.PI * 0.82f);
|
||||
}
|
||||
var r2 = _main.Session.State.Contenders[2];
|
||||
var r2 = localPreview.Inner.State.Contenders[2];
|
||||
if (r2.Alive)
|
||||
{
|
||||
_main.Session.SetContenderPose(r2.Id, player.X + fwdX * 26f + rightX * 8.5f, player.Z + fwdZ * 26f + rightZ * 8.5f, _main.CameraYaw - MathF.PI * 0.72f);
|
||||
localPreview.Inner.SetContenderPose(r2.Id, player.X + fwdX * 26f + rightX * 8.5f, player.Z + fwdZ * 26f + rightZ * 8.5f, _main.CameraYaw - MathF.PI * 0.72f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -807,7 +816,7 @@ public partial class Smoke : Node
|
|||
{
|
||||
for (int s = 0; s < 25; s++)
|
||||
{
|
||||
debris.Step(1f / 60f, _main.Session.State.Terrain);
|
||||
debris.Step(1f / 60f, _main.Session.ViewState.Terrain);
|
||||
}
|
||||
debris.TryGetPiecePosition(0, out Vector3 p1);
|
||||
float moved = p1.DistanceTo(p0);
|
||||
|
|
@ -853,7 +862,7 @@ public partial class Smoke : Node
|
|||
|
||||
// 5. All 15 ChassisDrop salvage wrecks ground within 0.05m of terrain & PickedUp frees drops cleanly
|
||||
{
|
||||
var drops = _main.Session.State.GroundDrops;
|
||||
var drops = _main.Session.ViewState.GroundDrops;
|
||||
int baseCount = drops.Count;
|
||||
_main.Arena.Sync(_main.Session, 1.0f, 1f / 60f);
|
||||
int trackedBefore = _main.Arena.ActiveDropVisualCount;
|
||||
|
|
@ -884,7 +893,7 @@ public partial class Smoke : Node
|
|||
{
|
||||
dropVis.SetLodState(useStaticLod: false, castShadows: false);
|
||||
float minWorldY = dropVis.ComputeMinVertexY();
|
||||
float terrainY = _main.Session.State.Terrain.SampleHeight(d.X, d.Z);
|
||||
float terrainY = _main.Session.ViewState.Terrain.SampleHeight(d.X, d.Z);
|
||||
float err = MathF.Abs(minWorldY - terrainY);
|
||||
if (err > maxGroundErr) maxGroundErr = err;
|
||||
Check(err <= 0.05f,
|
||||
|
|
@ -902,7 +911,7 @@ public partial class Smoke : Node
|
|||
{
|
||||
dropVis.SetLodState(useStaticLod: true, castShadows: false);
|
||||
float minFarWorldY = dropVis.ComputeMinVertexY();
|
||||
float terrainY = _main.Session.State.Terrain.SampleHeight(d.X, d.Z);
|
||||
float terrainY = _main.Session.ViewState.Terrain.SampleHeight(d.X, d.Z);
|
||||
float err = MathF.Abs(minFarWorldY - terrainY);
|
||||
if (err > maxFarGroundErr) maxFarGroundErr = err;
|
||||
Check(err <= 0.05f,
|
||||
|
|
@ -923,9 +932,11 @@ public partial class Smoke : Node
|
|||
drops.RemoveRange(baseCount, added.Count);
|
||||
}
|
||||
|
||||
// 6. All 7 walkers (including Kestrel) walk through real ArenaSession + Hybrid B FK snapshot cleanly
|
||||
// 6. All 7 walkers (including Kestrel) walk through IClientArenaSession (LocalArenaSession) + Hybrid B FK snapshot cleanly
|
||||
{
|
||||
using var walkSession = new RustToDust.Ymir.ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
|
||||
using var localWalk = new LocalArenaSession(seed: 42, mapKind: ArenaMapKind.Desert);
|
||||
IClientArenaSession walkIface = localWalk;
|
||||
var walkSession = localWalk.Inner;
|
||||
for (int cIdx = 1; cIdx < walkSession.State.Contenders.Count; cIdx++)
|
||||
{
|
||||
walkSession.SetContenderPose(cIdx, 450f + cIdx * 18f, 450f);
|
||||
|
|
@ -946,9 +957,9 @@ public partial class Smoke : Node
|
|||
{
|
||||
var wSpec = Catalog.ChassisById[wId];
|
||||
walkSession.SetContenderPose(0, 0f, 0f, 0f);
|
||||
if (walkSession.State.Contenders[0].Grid.Spec.Id != wId)
|
||||
if (walkIface.LocalContender.Grid.Spec.Id != wId)
|
||||
{
|
||||
walkSession.State.SpawnChassisDrop(0f, 0f, wSpec);
|
||||
walkIface.ViewState.SpawnChassisDrop(0f, 0f, wSpec);
|
||||
Check(walkSession.TrySwapNearbyChassis(0), $"Failed to swap walkSession player to '{wId}'");
|
||||
}
|
||||
|
||||
|
|
@ -961,24 +972,23 @@ public partial class Smoke : Node
|
|||
Check(footNode is not null && pelvisNode is not null,
|
||||
$"Missing FK nodes '{footNodeName}'/'{pelvisNodeName}' on walker '{wId}'");
|
||||
|
||||
var player = walkSession.State.Contenders[0];
|
||||
var player = walkIface.LocalContender;
|
||||
for (int step = 0; step < 60; step++)
|
||||
{
|
||||
walkSession.SetHumanInput(0, new PlayerInput(
|
||||
walkIface.SubmitLocalInput(new PlayerInput(
|
||||
Throttle: 1f,
|
||||
Steer: 0f,
|
||||
AimWorldX: player.X,
|
||||
AimWorldZ: player.Z + 50f,
|
||||
Fire: false,
|
||||
InteractPickup: false,
|
||||
Brake: false));
|
||||
walkSession.Step();
|
||||
Brake: false), isPhysicsTick: true);
|
||||
|
||||
bool hasSnap = walkSession.TrySampleInterpolatedWalkerPose(true, player.Id, 1f, out var walkerSnap);
|
||||
bool hasSnap = walkIface.TrySampleInterpolatedWalkerPose(true, player.Id, 1f, out var walkerSnap);
|
||||
Check(hasSnap, $"Missing WalkerVisualSnapshot for '{wId}' at step {step}");
|
||||
if (!hasSnap) break;
|
||||
|
||||
var (interpPos, interpRot, interpVel) = walkSession.GetInterpolatedContenderPose(player.Id, 1f);
|
||||
var (interpPos, interpRot, interpVel) = walkIface.GetInterpolatedContenderPose(player.Id, 1f);
|
||||
var q = new Quaternion(interpRot.X, interpRot.Y, interpRot.Z, interpRot.W);
|
||||
vis.Root.Transform = new Transform3D(new Basis(q), new Vector3(interpPos.X, interpPos.Y, interpPos.Z));
|
||||
VehicleRigAnimator.Update(
|
||||
|
|
@ -1002,7 +1012,7 @@ public partial class Smoke : Node
|
|||
|
||||
Vector3 fInModel = TransformPointToAncestor(footNode, vis.ModelRoot, Vector3.Zero);
|
||||
Vector3 fWorld = vis.Root.Transform * (vis.ModelRoot.Transform * fInModel);
|
||||
float groundUnderFoot = walkSession.State.Terrain.SampleHeight(fWorld.X, fWorld.Z);
|
||||
float groundUnderFoot = walkIface.ViewState.Terrain.SampleHeight(fWorld.X, fWorld.Z);
|
||||
float relMinY = curMinWorldY - groundUnderFoot;
|
||||
if (relMinY < worstRelMinY) worstRelMinY = relMinY;
|
||||
}
|
||||
|
|
@ -1066,7 +1076,7 @@ public partial class Smoke : Node
|
|||
{
|
||||
_main.Arena.Sync(_main.Session, 1.5f, 1f / 60f);
|
||||
bool sawPatron = false;
|
||||
foreach (var s in _main.Session.State.Spectators.Spectators)
|
||||
foreach (var s in _main.Session.ViewState.Spectators.Spectators)
|
||||
{
|
||||
if (!s.Alive) continue;
|
||||
var vis = _main.Arena.GetSpectatorVisual(s.Id);
|
||||
|
|
@ -1133,8 +1143,9 @@ public partial class Smoke : Node
|
|||
|
||||
// 10. MultiMeshPartPool & PomDecalPool sanity: live arena submits into MultiMeshPartPool and PomDecalPool stamps impacts cleanly
|
||||
{
|
||||
var localC = _main.Session.LocalContender;
|
||||
_main.Arena.PomDecals.StampTestDecal(
|
||||
new Vector3(_main.Session.State.Contenders[0].X + 2f, _main.Session.State.Terrain.SampleHeight(_main.Session.State.Contenders[0].X + 2f, _main.Session.State.Contenders[0].Z) + 0.03f, _main.Session.State.Contenders[0].Z),
|
||||
new Vector3(localC.X + 2f, _main.Session.ViewState.Terrain.SampleHeight(localC.X + 2f, localC.Z) + 0.03f, localC.Z),
|
||||
Vector3.Up, 1.2f, tileIndex: 14);
|
||||
_main.Arena.Sync(_main.Session, 1.6f, 1f / 60f);
|
||||
Check(_main.Arena.PartPool.TotalSubmittedInstances > 0,
|
||||
|
|
@ -1142,7 +1153,7 @@ public partial class Smoke : Node
|
|||
Check(_main.Arena.PomDecals.ActiveCount >= 1,
|
||||
$"Expected PomDecalPool to hold >= 1 active decal, got {_main.Arena.PomDecals.ActiveCount}");
|
||||
|
||||
_main.Hud.PushTestHitArc(_main.Session.State.Contenders[0].X + 20f, _main.Session.State.Contenders[0].Z + 10f, WeaponVisualClass.Explosive);
|
||||
_main.Hud.PushTestHitArc(localC.X + 20f, localC.Z + 10f, WeaponVisualClass.Explosive);
|
||||
Check(_main.Hud.ActiveHitArcCount >= 1, "Expected CrosshairOverlay to accept incoming hit arc");
|
||||
}
|
||||
|
||||
|
|
@ -1218,13 +1229,14 @@ public partial class Smoke : Node
|
|||
|
||||
// 12. Finding 2: Monotonic TracerEvent.Id spawns muzzle flash + recoilless smoke puffs ONCE regardless of TTL or FPS
|
||||
{
|
||||
var tracers = _main.Session.State.Tracers;
|
||||
var tracers = _main.Session.ViewState.Tracers;
|
||||
tracers.Clear();
|
||||
_main.Arena.Sync(_main.Session, 1.69f, 0f);
|
||||
int vfxBefore = _main.Arena.TransientVfxCount;
|
||||
|
||||
int tracerId = _main.Session.State.AllocateTracerId();
|
||||
Vector3 pPos = new(_main.Session.State.Contenders[0].X, _main.Session.State.Contenders[0].Y, _main.Session.State.Contenders[0].Z);
|
||||
int tracerId = _main.Session.ViewState.AllocateTracerId();
|
||||
var localC = _main.Session.LocalContender;
|
||||
Vector3 pPos = new(localC.X, localC.Y, localC.Z);
|
||||
tracers.Add(new TracerEvent(
|
||||
pPos.X, pPos.Y + 1f, pPos.Z,
|
||||
pPos.X + 20f, pPos.Y + 1f, pPos.Z,
|
||||
|
|
@ -1247,6 +1259,30 @@ public partial class Smoke : Node
|
|||
tracers.Clear();
|
||||
}
|
||||
|
||||
// 13. Loopback IClientArenaSession check: ServerMatchHost + RemoteArenaSession join + snapshot sync
|
||||
{
|
||||
using var host = new ServerMatchHost(IPAddress.Loopback, port: 0, seed: 42, mapKind: ArenaMapKind.Desert);
|
||||
using var remote = new RemoteArenaSession(new IPEndPoint(IPAddress.Loopback, host.BoundPort), "SmokeClient");
|
||||
IClientArenaSession remoteIface = remote;
|
||||
|
||||
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
for (int t = 0; t < 15 && !remote.IsJoined; t++)
|
||||
{
|
||||
host.StepOnce(nowMs + t * 16);
|
||||
remoteIface.BeginRenderFrame(1.0 / 60.0, 1.0f);
|
||||
}
|
||||
Check(remote.IsJoined && remoteIface.ConnectionStatus.Connected,
|
||||
$"Expected RemoteArenaSession loopback connect inside Smoke, label='{remoteIface.ConnectionStatus.StateLabel}'");
|
||||
for (int t = 0; t < 6; t++)
|
||||
{
|
||||
remoteIface.SubmitLocalInput(new PlayerInput(0.5f, 0f, 10f, 10f, false, false, false), isPhysicsTick: true);
|
||||
host.StepOnce(nowMs + 300 + t * 16);
|
||||
remoteIface.BeginRenderFrame(1.0 / 60.0, 1.0f);
|
||||
}
|
||||
Check(remote.LastSnapshotSeq > 0, $"Expected loopback RemoteArenaSession to receive snapshots, got seq={remote.LastSnapshotSeq}");
|
||||
Check(remoteIface.LocalContender.Alive, "Expected loopback RemoteArenaSession LocalContender alive");
|
||||
}
|
||||
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
}
|
||||
|
||||
|
|
@ -1401,7 +1437,7 @@ public partial class Smoke : Node
|
|||
|
||||
private async Task VerifyMaxLoadPaladinGarageAsync()
|
||||
{
|
||||
var grid = _main.Session.State.Contenders[0].Grid;
|
||||
var grid = _main.Session.LocalContender.Grid;
|
||||
grid.SwapChassis(Catalog.Paladin);
|
||||
Check(grid.TryMount(Catalog.TouringPlasma, "hp.weapon.sh_l"), "Expected TouringPlasma on Paladin hp.weapon.sh_l");
|
||||
Check(grid.TryMount(Catalog.WeldedPlate, "hp.armor.torso"), "Expected WeldedPlate on Paladin hp.armor.torso");
|
||||
|
|
@ -1459,7 +1495,7 @@ public partial class Smoke : Node
|
|||
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
|
||||
var sionState = _main.Session.State;
|
||||
var sionState = _main.Session.ViewState;
|
||||
Check(_main.MapKind == ArenaMapKind.Sion && sionState.MapKind == ArenaMapKind.Sion, "Expected Sion map kind after Reset");
|
||||
Check(_main.SionMap.Visible && !_main.Terrain.Visible, "Expected SionMapRenderer visible and Desert TerrainRenderer hidden");
|
||||
Check(_main.SionMap.IsBuilt, "Expected SionMapRenderer.IsBuilt == true");
|
||||
|
|
|
|||
Loading…
Reference in a new issue