Fix Soul HUD/MP findings: camera-local offscreen arrows, panel avoidance, dead-observer clear, remote CoreHpRatio sync, and OFL notice staging

This commit is contained in:
Meta Vens 2026-12-05 23:39:17 +01:00
commit 02ad6d68cf
8 changed files with 270 additions and 48 deletions

View file

@ -38,7 +38,7 @@ public partial class Hud : CanvasLayer
private readonly Func<IClientArenaSession?> _getSession; private readonly Func<IClientArenaSession?> _getSession;
private readonly Action<int, string> _onEquipCargo; private readonly Action<int, string> _onEquipCargo;
private readonly Func<float> _getCameraYaw; private readonly Func<float> _getCameraYaw;
private readonly Func<System.Numerics.Vector3, (bool Visible, bool Behind, Vector2 ScreenPos)>? _projectWorld; private readonly Func<System.Numerics.Vector3, (bool Valid, bool InFront, Vector2 ScreenPos, System.Numerics.Vector3 CamLocal)>? _projectWorld;
private Label _chassisHeader = null!; private Label _chassisHeader = null!;
private Label _planeBadge = null!; private Label _planeBadge = null!;
@ -101,7 +101,7 @@ public partial class Hud : CanvasLayer
Func<IClientArenaSession?> getSession, Func<IClientArenaSession?> getSession,
Action<int, string> onEquipCargo, Action<int, string> onEquipCargo,
Func<float>? getCameraYaw = null, Func<float>? getCameraYaw = null,
Func<System.Numerics.Vector3, (bool Visible, bool Behind, Vector2 ScreenPos)>? projectWorld = null) Func<System.Numerics.Vector3, (bool Valid, bool InFront, Vector2 ScreenPos, System.Numerics.Vector3 CamLocal)>? projectWorld = null)
{ {
_getSession = getSession; _getSession = getSession;
_onEquipCargo = onEquipCargo; _onEquipCargo = onEquipCargo;
@ -300,6 +300,7 @@ public partial class Hud : CanvasLayer
BuildBottomCenterChyron(); BuildBottomCenterChyron();
BuildOutcomeBanner(); BuildOutcomeBanner();
BuildNetworkPanel(); BuildNetworkPanel();
_worldMarkers.SetAvoidPanels(_topLeftPanel, _topRightPanel, _bottomLeftPanel, _chyronPanel);
} }
public bool IsPointerOverInteractiveHud(Vector2 screenPos) public bool IsPointerOverInteractiveHud(Vector2 screenPos)
@ -1959,21 +1960,20 @@ public partial class Hud : CanvasLayer
private sealed partial class WorldMarkerOverlay : Control private sealed partial class WorldMarkerOverlay : Control
{ {
private const float BorderPad = 36f; private const float BorderPad = 36f;
private const float PanelAvoidPad = 18f;
private const float OffscreenHostileMaxDistance = 220f; private const float OffscreenHostileMaxDistance = 220f;
private const int MaxOffscreenHostileArrows = 6; private const int MaxOffscreenHostileArrows = 6;
private readonly struct OffscreenMarker private readonly struct OffscreenMarker
{ {
public readonly Vector2 ScreenPos; public readonly System.Numerics.Vector3 CamLocal;
public readonly bool Behind;
public readonly float Distance; public readonly float Distance;
public readonly Color Color; public readonly Color Color;
public readonly bool IsLockedOnLocal; public readonly bool IsLockedOnLocal;
public OffscreenMarker(Vector2 screenPos, bool behind, float distance, Color color, bool isLockedOnLocal) public OffscreenMarker(System.Numerics.Vector3 camLocal, float distance, Color color, bool isLockedOnLocal)
{ {
ScreenPos = screenPos; CamLocal = camLocal;
Behind = behind;
Distance = distance; Distance = distance;
Color = color; Color = color;
IsLockedOnLocal = isLockedOnLocal; IsLockedOnLocal = isLockedOnLocal;
@ -1981,15 +1981,21 @@ public partial class Hud : CanvasLayer
} }
private IClientArenaSession? _session; private IClientArenaSession? _session;
private Func<System.Numerics.Vector3, (bool Visible, bool Behind, Vector2 ScreenPos)>? _projectWorld; private Func<System.Numerics.Vector3, (bool Valid, bool InFront, Vector2 ScreenPos, System.Numerics.Vector3 CamLocal)>? _projectWorld;
private Control?[] _avoidPanels = Array.Empty<Control?>();
private readonly List<OffscreenMarker> _offscreenHostiles = new(16); private readonly List<OffscreenMarker> _offscreenHostiles = new(16);
private readonly Vector2[] _cornerBuf = new Vector2[3]; private readonly Vector2[] _cornerBuf = new Vector2[3];
private readonly Vector2[] _triBuf = new Vector2[3]; private readonly Vector2[] _triBuf = new Vector2[3];
private readonly Vector2[] _shadowTriBuf = new Vector2[3]; private readonly Vector2[] _shadowTriBuf = new Vector2[3];
public void SetAvoidPanels(params Control?[] panels)
{
_avoidPanels = panels ?? Array.Empty<Control?>();
}
public void SetState( public void SetState(
IClientArenaSession session, IClientArenaSession session,
Func<System.Numerics.Vector3, (bool Visible, bool Behind, Vector2 ScreenPos)>? projectWorld) Func<System.Numerics.Vector3, (bool Valid, bool InFront, Vector2 ScreenPos, System.Numerics.Vector3 CamLocal)>? projectWorld)
{ {
_session = session; _session = session;
_projectWorld = projectWorld; _projectWorld = projectWorld;
@ -2002,6 +2008,7 @@ public partial class Hud : CanvasLayer
int localId = _session.LocalContenderId; int localId = _session.LocalContenderId;
if (localId < 0 || localId >= state.Contenders.Count) return; if (localId < 0 || localId >= state.Contenders.Count) return;
if (!state.Contenders[localId].Alive) return;
Vector2 viewSize = Size; Vector2 viewSize = Size;
if (viewSize.X < 64f || viewSize.Y < 64f) return; if (viewSize.X < 64f || viewSize.Y < 64f) return;
@ -2024,10 +2031,10 @@ public partial class Hud : CanvasLayer
float dist = (allyPos - localPos).Length(); float dist = (allyPos - localPos).Length();
float headOffset = c.IsInDropPod ? 3.4f : (c.Grid.Spec.HalfHeight + 1.9f); float headOffset = c.IsInDropPod ? 3.4f : (c.Grid.Spec.HalfHeight + 1.9f);
var worldHead = new System.Numerics.Vector3(allyPos.X, allyPos.Y + headOffset, allyPos.Z); var worldHead = new System.Numerics.Vector3(allyPos.X, allyPos.Y + headOffset, allyPos.Z);
var (visible, behind, sp) = _projectWorld(worldHead); var (valid, inFront, sp, camLocal) = _projectWorld(worldHead);
if (!visible) continue; if (!valid) continue;
bool inFrame = !behind && bool inFrame = inFront &&
sp.X >= BorderPad && sp.X <= viewSize.X - BorderPad && sp.X >= BorderPad && sp.X <= viewSize.X - BorderPad &&
sp.Y >= BorderPad && sp.Y <= viewSize.Y - BorderPad; sp.Y >= BorderPad && sp.Y <= viewSize.Y - BorderPad;
@ -2049,22 +2056,15 @@ public partial class Hud : CanvasLayer
} }
else else
{ {
Vector2 dir = behind ? (center - sp) : (sp - center); Vector2 dir = ComputeOffscreenDirection(camLocal);
if (dir.LengthSquared() < 1e-4f) dir = Vector2.Up; Vector2 edge = ComputeSafeEdgePos(center, halfW, halfH, dir);
else dir = dir.Normalized();
float tx = MathF.Abs(dir.X) > 1e-4f ? halfW / MathF.Abs(dir.X) : float.PositiveInfinity;
float ty = MathF.Abs(dir.Y) > 1e-4f ? halfH / MathF.Abs(dir.Y) : float.PositiveInfinity;
Vector2 edge = center + dir * MathF.Min(tx, ty);
Vector2 perp = new(-dir.Y, dir.X); Vector2 perp = new(-dir.Y, dir.X);
_triBuf[0] = edge + dir * 7f; _triBuf[0] = edge + dir * 7f;
_triBuf[1] = edge - dir * 5f + perp * 5f; _triBuf[1] = edge - dir * 5f + perp * 5f;
_triBuf[2] = edge - dir * 5f - perp * 5f; _triBuf[2] = edge - dir * 5f - perp * 5f;
DrawColoredPolygon(_triBuf, new Color(AlliedCol.R, AlliedCol.G, AlliedCol.B, 0.88f)); DrawColoredPolygon(_triBuf, new Color(AlliedCol.R, AlliedCol.G, AlliedCol.B, 0.88f));
Vector2 textPos = new( Vector2 textPos = ComputeInwardLabelPos(edge, dir, viewSize, font, label);
Math.Clamp(edge.X - 32f, 10f, viewSize.X - 110f),
Math.Clamp(edge.Y + (dir.Y > 0f ? -12f : 18f), 16f, viewSize.Y - 12f));
DrawString( DrawString(
font, font,
textPos, textPos,
@ -2116,7 +2116,7 @@ public partial class Hud : CanvasLayer
var (pos, rot, _) = _session.GetInterpolatedSpectatorPose(s.Id, 1f); var (pos, rot, _) = _session.GetInterpolatedSpectatorPose(s.Id, 1f);
float dist = (pos - localPos).Length(); float dist = (pos - localPos).Length();
bool lockedOnLocal = s.TargetContenderId == localId && s.HasTargetLos; bool lockedOnLocal = s.TargetContenderId == localId;
float hpRatio = s.Grid.MaxCoreHp > 0f ? s.Grid.CoreHp / s.Grid.MaxCoreHp : 1f; float hpRatio = s.Grid.MaxCoreHp > 0f ? s.Grid.CoreHp / s.Grid.MaxCoreHp : 1f;
ProcessHostileTarget( ProcessHostileTarget(
@ -2155,10 +2155,10 @@ public partial class Hud : CanvasLayer
Vector2 viewSize, Vector2 viewSize,
Font font) Font font)
{ {
var (cVis, cBehind, cSp) = _projectWorld!(worldCenter); var (cValid, cInFront, cSp, cCamLocal) = _projectWorld!(worldCenter);
if (!cVis) return; if (!cValid) return;
bool inFrame = !cBehind && bool inFrame = cInFront &&
cSp.X >= BorderPad && cSp.X <= viewSize.X - BorderPad && cSp.X >= BorderPad && cSp.X <= viewSize.X - BorderPad &&
cSp.Y >= BorderPad && cSp.Y <= viewSize.Y - BorderPad; cSp.Y >= BorderPad && cSp.Y <= viewSize.Y - BorderPad;
@ -2166,7 +2166,7 @@ public partial class Hud : CanvasLayer
{ {
if (isLockedOnLocal || dist <= OffscreenHostileMaxDistance) if (isLockedOnLocal || dist <= OffscreenHostileMaxDistance)
{ {
_offscreenHostiles.Add(new OffscreenMarker(cSp, cBehind, dist, col, isLockedOnLocal)); _offscreenHostiles.Add(new OffscreenMarker(cCamLocal, dist, col, isLockedOnLocal));
} }
return; return;
} }
@ -2183,8 +2183,8 @@ public partial class Hud : CanvasLayer
{ {
var localCorner = new System.Numerics.Vector3(sx * halfBoundW, sy * halfBoundH, sz * halfBoundL); var localCorner = new System.Numerics.Vector3(sx * halfBoundW, sy * halfBoundH, sz * halfBoundL);
var worldCorner = worldCenter + System.Numerics.Vector3.Transform(localCorner, rot); var worldCorner = worldCenter + System.Numerics.Vector3.Transform(localCorner, rot);
var (vis, beh, sp) = _projectWorld(worldCorner); var (valid, inFront, sp, _) = _projectWorld(worldCorner);
if (!vis || beh) if (!valid || !inFront)
{ {
allCornersInFront = false; allCornersInFront = false;
break; break;
@ -2201,9 +2201,9 @@ public partial class Hud : CanvasLayer
if (!allCornersInFront) if (!allCornersInFront)
{ {
var (topVis, topBeh, topSp) = _projectWorld(worldCenter + new System.Numerics.Vector3(0f, halfBoundH, 0f)); var (topValid, topFront, topSp, _) = _projectWorld(worldCenter + new System.Numerics.Vector3(0f, halfBoundH, 0f));
var (botVis, botBeh, botSp) = _projectWorld(worldCenter - new System.Numerics.Vector3(0f, halfBoundH, 0f)); var (botValid, botFront, botSp, _) = _projectWorld(worldCenter - new System.Numerics.Vector3(0f, halfBoundH, 0f));
float rawH = (topVis && !topBeh && botVis && !botBeh) float rawH = (topValid && topFront && botValid && botFront)
? MathF.Abs(botSp.Y - topSp.Y) + 8f ? MathF.Abs(botSp.Y - topSp.Y) + 8f
: 44f; : 44f;
float horizRadius = MathF.Max(halfBoundW, halfBoundL); float horizRadius = MathF.Max(halfBoundW, halfBoundL);
@ -2286,13 +2286,8 @@ public partial class Hud : CanvasLayer
private void DrawOffscreenArrow(OffscreenMarker m, Vector2 viewSize, Vector2 center, float halfW, float halfH, Font font) private void DrawOffscreenArrow(OffscreenMarker m, Vector2 viewSize, Vector2 center, float halfW, float halfH, Font font)
{ {
Vector2 dir = m.Behind ? (center - m.ScreenPos) : (m.ScreenPos - center); Vector2 dir = ComputeOffscreenDirection(m.CamLocal);
if (dir.LengthSquared() < 1e-4f) dir = Vector2.Up; Vector2 edge = ComputeSafeEdgePos(center, halfW, halfH, dir);
else dir = dir.Normalized();
float tx = MathF.Abs(dir.X) > 1e-4f ? halfW / MathF.Abs(dir.X) : float.PositiveInfinity;
float ty = MathF.Abs(dir.Y) > 1e-4f ? halfH / MathF.Abs(dir.Y) : float.PositiveInfinity;
Vector2 edge = center + dir * MathF.Min(tx, ty);
Vector2 perp = new(-dir.Y, dir.X); Vector2 perp = new(-dir.Y, dir.X);
_shadowTriBuf[0] = edge + dir * 10f; _shadowTriBuf[0] = edge + dir * 10f;
@ -2307,13 +2302,146 @@ public partial class Hud : CanvasLayer
DrawColoredPolygon(_triBuf, arrowCol); DrawColoredPolygon(_triBuf, arrowCol);
string label = m.IsLockedOnLocal ? $"{m.Distance:F0}m !" : $"{m.Distance:F0}m"; string label = m.IsLockedOnLocal ? $"{m.Distance:F0}m !" : $"{m.Distance:F0}m";
Vector2 sz = font.GetStringSize(label, HorizontalAlignment.Left, -1, 10); Vector2 textPos = ComputeInwardLabelPos(edge, dir, viewSize, font, label);
Vector2 inward = edge - dir * 17f;
Vector2 textPos = new(
Math.Clamp(inward.X - sz.X * 0.5f, 10f, viewSize.X - sz.X - 10f),
Math.Clamp(inward.Y + sz.Y * 0.35f, 16f, viewSize.Y - 10f));
DrawString(font, textPos + new Vector2(1f, 1f), label, HorizontalAlignment.Left, -1, 10, new Color(0.04f, 0.05f, 0.04f, 0.90f)); DrawString(font, textPos + new Vector2(1f, 1f), label, HorizontalAlignment.Left, -1, 10, new Color(0.04f, 0.05f, 0.04f, 0.90f));
DrawString(font, textPos, label, HorizontalAlignment.Left, -1, 10, arrowCol); DrawString(font, textPos, label, HorizontalAlignment.Left, -1, 10, arrowCol);
} }
private static Vector2 ComputeOffscreenDirection(System.Numerics.Vector3 camLocal)
{
if (!float.IsFinite(camLocal.X) || !float.IsFinite(camLocal.Y) || !float.IsFinite(camLocal.Z))
{
return Vector2.Down;
}
Vector2 dir;
if (camLocal.Z >= 0f)
{
dir = new Vector2(camLocal.X, -camLocal.Y);
}
else
{
float horiz = MathF.Sqrt(camLocal.X * camLocal.X + camLocal.Z * camLocal.Z);
float t = Math.Clamp(-camLocal.Z / MathF.Max(1e-4f, horiz * 0.35f), 0f, 1f);
Vector2 sideDir = new(camLocal.X, -camLocal.Y);
Vector2 behindArcDir = new(camLocal.X, MathF.Max(-camLocal.Z, 0.35f * horiz));
dir = sideDir.Lerp(behindArcDir, t);
if (MathF.Abs(camLocal.X) < 0.35f * horiz)
{
float minDown = 0.25f * dir.Length();
if (dir.Y < minDown)
{
dir.Y = MathF.Max(minDown, 0.25f);
}
}
}
float lenSq = dir.LengthSquared();
if (!float.IsFinite(lenSq) || lenSq < 1e-6f)
{
return camLocal.Z < 0f ? Vector2.Down : Vector2.Up;
}
return dir / MathF.Sqrt(lenSq);
}
private Vector2 ComputeSafeEdgePos(Vector2 center, float halfW, float halfH, Vector2 dir)
{
float tx = MathF.Abs(dir.X) > 1e-4f ? halfW / MathF.Abs(dir.X) : float.PositiveInfinity;
float ty = MathF.Abs(dir.Y) > 1e-4f ? halfH / MathF.Abs(dir.Y) : float.PositiveInfinity;
float tBest = MathF.Min(tx, ty);
for (int i = 0; i < _avoidPanels.Length; i++)
{
var panel = _avoidPanels[i];
if (panel is null || !panel.Visible) continue;
Rect2 r = panel.GetGlobalRect().Grow(PanelAvoidPad);
if (r.HasPoint(center)) continue;
if (TryRayEnterRect(center, dir, r, out float tEnter) && tEnter > 24f && tEnter < tBest)
{
tBest = tEnter;
}
}
tBest = MathF.Max(24f, tBest);
return center + dir * tBest;
}
private static bool TryRayEnterRect(Vector2 origin, Vector2 dir, Rect2 r, out float tEnter)
{
float tMin = 0f;
float tMax = float.PositiveInfinity;
if (MathF.Abs(dir.X) < 1e-5f)
{
if (origin.X < r.Position.X || origin.X > r.End.X)
{
tEnter = 0f;
return false;
}
}
else
{
float invX = 1f / dir.X;
float t1 = (r.Position.X - origin.X) * invX;
float t2 = (r.End.X - origin.X) * invX;
if (t1 > t2) (t1, t2) = (t2, t1);
tMin = MathF.Max(tMin, t1);
tMax = MathF.Min(tMax, t2);
if (tMin > tMax)
{
tEnter = 0f;
return false;
}
}
if (MathF.Abs(dir.Y) < 1e-5f)
{
if (origin.Y < r.Position.Y || origin.Y > r.End.Y)
{
tEnter = 0f;
return false;
}
}
else
{
float invY = 1f / dir.Y;
float t1 = (r.Position.Y - origin.Y) * invY;
float t2 = (r.End.Y - origin.Y) * invY;
if (t1 > t2) (t1, t2) = (t2, t1);
tMin = MathF.Max(tMin, t1);
tMax = MathF.Min(tMax, t2);
if (tMin > tMax)
{
tEnter = 0f;
return false;
}
}
tEnter = tMin;
return true;
}
private static Vector2 ComputeInwardLabelPos(Vector2 edge, Vector2 dir, Vector2 viewSize, Font font, string label)
{
Vector2 sz = font.GetStringSize(label, HorizontalAlignment.Left, -1, 10);
Vector2 inward = edge - dir * 14f;
float textX;
float textY;
if (MathF.Abs(dir.X) >= MathF.Abs(dir.Y))
{
textX = dir.X > 0f ? (inward.X - sz.X - 4f) : (inward.X + 6f);
textY = inward.Y + sz.Y * 0.3f;
}
else
{
textX = inward.X - sz.X * 0.5f;
textY = dir.Y > 0f ? (inward.Y - 4f) : (inward.Y + sz.Y + 4f);
}
return new Vector2(
Math.Clamp(textX, 10f, MathF.Max(10f, viewSize.X - sz.X - 10f)),
Math.Clamp(textY, 16f, MathF.Max(16f, viewSize.Y - 10f)));
}
} }
} }

View file

@ -2104,15 +2104,32 @@ public partial class Main : Node3D
_session?.RequestEquipCargo(cargoIndex, hardpointId); _session?.RequestEquipCargo(cargoIndex, hardpointId);
} }
private (bool Visible, bool Behind, Vector2 ScreenPos) ProjectWorldToHud(System.Numerics.Vector3 worldPos) private (bool Valid, bool InFront, Vector2 ScreenPos, System.Numerics.Vector3 CamLocal) ProjectWorldToHud(System.Numerics.Vector3 worldPos)
{ {
if (_camera is null || !GodotObject.IsInstanceValid(_camera) || !_camera.IsInsideTree()) if (_camera is null || !GodotObject.IsInstanceValid(_camera) || !_camera.IsInsideTree())
{ {
return (false, false, Vector2.Zero); return (false, false, Vector2.Zero, System.Numerics.Vector3.Zero);
} }
var wp = new Vector3(worldPos.X, worldPos.Y, worldPos.Z); var wp = new Vector3(worldPos.X, worldPos.Y, worldPos.Z);
bool behind = _camera.IsPositionBehind(wp); Transform3D camXform = _camera.GlobalTransform;
Vector3 rel = wp - camXform.Origin;
Basis b = camXform.Basis;
// Godot Camera3D local axes: +X = right, +Y = up, -Z = forward
float localRight = rel.Dot(b.X);
float localUp = rel.Dot(b.Y);
float localForward = -rel.Dot(b.Z);
var camLocal = new System.Numerics.Vector3(localRight, localUp, localForward);
if (localForward <= 0.1f)
{
return (true, false, Vector2.Zero, camLocal);
}
Vector2 sp = _camera.UnprojectPosition(wp); Vector2 sp = _camera.UnprojectPosition(wp);
return (true, behind, sp); if (!float.IsFinite(sp.X) || !float.IsFinite(sp.Y))
{
return (true, false, Vector2.Zero, camLocal);
}
return (true, true, sp, camLocal);
} }
} }

View file

@ -890,6 +890,12 @@ namespace RustToDust.Core
UpdateMountedTelemetry(); UpdateMountedTelemetry();
} }
public void ApplyReplicatedCoreHpRatio(float coreHpRatio)
{
if (MaxCoreHp <= 0f) return;
CoreHp = Math.Clamp(coreHpRatio, 0f, 1f) * MaxCoreHp;
}
public void ApplyReplicatedThermal(ReadOnlySpan<byte> quantizedCellTemps, ReadOnlySpan<float> mountedTemps, ReadOnlySpan<float> mountedCooldowns) public void ApplyReplicatedThermal(ReadOnlySpan<byte> quantizedCellTemps, ReadOnlySpan<float> mountedTemps, ReadOnlySpan<float> mountedCooldowns)
{ {
int idx = 0; int idx = 0;

View file

@ -1433,6 +1433,7 @@ namespace RustToDust.Net
c.ThrottleCmd = nc.Throttle; c.ThrottleCmd = nc.Throttle;
c.SteerCmd = nc.Steer; c.SteerCmd = nc.Steer;
c.MaxThermalRatio = nc.MaxThermalRatio; c.MaxThermalRatio = nc.MaxThermalRatio;
c.Grid.ApplyReplicatedCoreHpRatio(nc.CoreHpRatio);
c.X = nc.Pos.X; c.Y = nc.Pos.Y; c.Z = nc.Pos.Z; c.X = nc.Pos.X; c.Y = nc.Pos.Y; c.Z = nc.Pos.Z;
c.CurrRotX = nc.Rot.X; c.CurrRotY = nc.Rot.Y; c.CurrRotZ = nc.Rot.Z; c.CurrRotW = nc.Rot.W; c.CurrRotX = nc.Rot.X; c.CurrRotY = nc.Rot.Y; c.CurrRotZ = nc.Rot.Z; c.CurrRotW = nc.Rot.W;
c.VelX = nc.Vel.X; c.VelY = nc.Vel.Y; c.VelZ = nc.Vel.Z; c.VelX = nc.Vel.X; c.VelY = nc.Vel.Y; c.VelZ = nc.Vel.Z;

View file

@ -2034,6 +2034,11 @@ namespace RustToDust.Ymir
for (int i = 0; i < State.Spectators.Spectators.Count; i++) for (int i = 0; i < State.Spectators.Spectators.Count; i++)
{ {
_spectatorPvs[obs.Id, i] = false; _spectatorPvs[obs.Id, i] = false;
if (memState.SpectatorContacts.TryGetValue(State.Spectators.Spectators[i].Id, out var smem))
{
smem.VisibleToPlayer = false;
smem.FaintHorizonPing = false;
}
} }
continue; continue;
} }

View file

@ -797,6 +797,40 @@ namespace RustToDust.Tests
"Client must receive Exemplar walker snapshot even under dense 12 quad-walker contention"); "Client must receive Exemplar walker snapshot even under dense 12 quad-walker contention");
} }
[Fact]
public void RemoteArenaSession_AppliesRemoteContenderCoreHpRatioOnPvsSnapshot()
{
using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Desert, maxHumans: 12, autoRestartSec: 0);
var ep = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
using var client = new RemoteArenaSession(ep, "HpProbe");
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
Assert.True(PumpUntil(host, new[] { client }, () => client.IsJoined, ref nowMs, 3000));
int localSlot = client.LocalContenderId;
int rivalSlot = localSlot == 0 ? 1 : 0;
var serverLocal = host.Session.State.Contenders[localSlot];
var serverRival = host.Session.State.Contenders[rivalSlot];
host.Session.SetContenderPose(localSlot, 0f, 0f, 0f);
host.Session.SetContenderPose(rivalSlot, 0f, 40f, MathF.PI);
float targetHp = serverRival.Grid.MaxCoreHp * 0.42f;
serverRival.Grid.ApplyReplicatedDamage(0, 0, 0f, 20f, targetHp, serverRival.Grid.HitSequence + 1);
float expectedRatio = serverRival.Grid.CoreHp / serverRival.Grid.MaxCoreHp;
bool synced = PumpUntil(host, new[] { client }, () =>
{
if (!client.IsContenderVisible(rivalSlot)) return false;
var c = client.ViewState.Contenders[rivalSlot];
float r = c.Grid.MaxCoreHp > 0f ? c.Grid.CoreHp / c.Grid.MaxCoreHp : 1f;
return MathF.Abs(r - expectedRatio) < 0.02f;
}, ref nowMs, 2500);
var clientRival = client.ViewState.Contenders[rivalSlot];
float actualRatio = clientRival.Grid.MaxCoreHp > 0f ? clientRival.Grid.CoreHp / clientRival.Grid.MaxCoreHp : 1f;
Assert.True(synced, $"Expected remote contender {rivalSlot} CoreHpRatio ~ {expectedRatio:F3}, got {actualRatio:F3}");
}
private static byte[] EncodeRudpLatestDatagram(byte[] frameBytes, uint sequence) => private static byte[] EncodeRudpLatestDatagram(byte[] frameBytes, uint sequence) =>
CultNetRudpPacketCodec.Encode(new CultNetRudpPacket CultNetRudpPacketCodec.Encode(new CultNetRudpPacket
{ {

View file

@ -584,5 +584,30 @@ namespace RustToDust.Tests
Assert.Equal(0, targetNearest.TargetContenderId); Assert.Equal(0, targetNearest.TargetContenderId);
} }
} }
[Fact]
public void DeadObserver_ClearsSpectatorContactsVisibleToPlayer()
{
using var session = new ArenaSession(seed: 12, slot0Human: true);
var player = session.State.Contenders[0];
var spec = session.State.Spectators.Spectators.First(s => s.Alive);
session.SetContenderPose(player.Id, 0f, 0f);
session.SetSpectatorPose(spec.Id, 0f, 35f);
session.State.Spectators.OnSpectatorDamaged(spec, player.Id);
session.Step();
var obs0 = session.State.GetOrCreateObserverState(0);
Assert.True(obs0.SpectatorContacts.TryGetValue(spec.Id, out var memBefore) && memBefore.VisibleToPlayer,
"Expected living observer in open LOS to mark provoked spectator VisibleToPlayer=true");
// Kill observer and step once; stale SpectatorContacts must clear VisibleToPlayer
player.Grid.ApplyReplicatedDamage(0, 0, 0f, 20f, 0f, player.Grid.HitSequence + 1);
Assert.False(player.Alive);
session.Step();
Assert.False(obs0.SpectatorContacts[spec.Id].VisibleToPlayer,
"Expected dead observer to clear SpectatorContacts.VisibleToPlayer");
}
} }
} }

View file

@ -323,6 +323,12 @@ Write-Host "`n[3/5] Staging Release ymir_box3d.dll and runtime assets/..."
Copy-Item -Path $ymirDllPath -Destination (Join-Path $StageDir "ymir_box3d.dll") -Force Copy-Item -Path $ymirDllPath -Destination (Join-Path $StageDir "ymir_box3d.dll") -Force
Copy-Item -Path $ymirDllPath -Destination (Join-Path $stagedDataDir "ymir_box3d.dll") -Force Copy-Item -Path $ymirDllPath -Destination (Join-Path $stagedDataDir "ymir_box3d.dll") -Force
$fontLicenseSrc = Join-Path $ClientDir "fonts\MONASPACE_LICENSE.txt"
if (-not (Test-Path $fontLicenseSrc)) {
throw "Required font license notice missing: '$fontLicenseSrc'."
}
Copy-Item -Path $fontLicenseSrc -Destination (Join-Path $StageDir "MONASPACE_LICENSE.txt") -Force
$stagedAssetsDir = Join-Path $StageDir "assets" $stagedAssetsDir = Join-Path $StageDir "assets"
$vCount = Copy-FilteredTree -SourceDir (Join-Path $AssetsSrcDir "vehicles") -DestDir (Join-Path $stagedAssetsDir "vehicles") -IncludeExtensions @(".glb", ".cc", ".json") $vCount = Copy-FilteredTree -SourceDir (Join-Path $AssetsSrcDir "vehicles") -DestDir (Join-Path $stagedAssetsDir "vehicles") -IncludeExtensions @(".glb", ".cc", ".json")
$gCount = Copy-FilteredTree -SourceDir (Join-Path $AssetsSrcDir "gear") -DestDir (Join-Path $stagedAssetsDir "gear") -IncludeExtensions @(".glb") $gCount = Copy-FilteredTree -SourceDir (Join-Path $AssetsSrcDir "gear") -DestDir (Join-Path $stagedAssetsDir "gear") -IncludeExtensions @(".glb")