Fix Cut 1 findings: Polygon2D 256px terrain bake, spectator LOS memory leak, steep slope/biped physics, and HUD polish
This commit is contained in:
parent
76584473d4
commit
af6604da80
9 changed files with 458 additions and 69 deletions
|
|
@ -46,6 +46,8 @@ public partial class Hud : CanvasLayer
|
|||
private VBoxContainer _cargoList = null!;
|
||||
private Label _cargoHeader = null!;
|
||||
private Label _garageDetails = null!;
|
||||
private PanelContainer _topLeftPanel = null!;
|
||||
private PanelContainer _topRightPanel = null!;
|
||||
private PanelContainer _bottomLeftPanel = null!;
|
||||
|
||||
private VBoxContainer _chyronBox = null!;
|
||||
|
|
@ -89,7 +91,9 @@ public partial class Hud : CanvasLayer
|
|||
|
||||
public bool IsPointerOverInteractiveHud(Vector2 screenPos)
|
||||
{
|
||||
return _bottomLeftPanel.GetGlobalRect().HasPoint(screenPos);
|
||||
return (_topLeftPanel.Visible && _topLeftPanel.GetGlobalRect().HasPoint(screenPos))
|
||||
|| (_topRightPanel.Visible && _topRightPanel.GetGlobalRect().HasPoint(screenPos))
|
||||
|| (_bottomLeftPanel.Visible && _bottomLeftPanel.GetGlobalRect().HasPoint(screenPos));
|
||||
}
|
||||
|
||||
public void Sync(ArenaSession session)
|
||||
|
|
@ -195,6 +199,7 @@ public partial class Hud : CanvasLayer
|
|||
private void BuildTopLeft()
|
||||
{
|
||||
var panel = CreateStyledPanel();
|
||||
_topLeftPanel = panel;
|
||||
panel.AnchorLeft = 0f;
|
||||
panel.AnchorTop = 0f;
|
||||
panel.OffsetLeft = 14f;
|
||||
|
|
@ -268,6 +273,7 @@ public partial class Hud : CanvasLayer
|
|||
private void BuildTopRightRadar()
|
||||
{
|
||||
var panel = CreateStyledPanel();
|
||||
_topRightPanel = panel;
|
||||
panel.AnchorLeft = 1f;
|
||||
panel.AnchorRight = 1f;
|
||||
panel.AnchorTop = 0f;
|
||||
|
|
@ -679,10 +685,22 @@ public partial class Hud : CanvasLayer
|
|||
return center + new Vector2(rx, -fy) * scale;
|
||||
}
|
||||
|
||||
private static Vector2 ClampToRadarDisc(Vector2 center, float maxRadius, Vector2 pt)
|
||||
{
|
||||
Vector2 delta = pt - center;
|
||||
float dist = delta.Length();
|
||||
if (dist > maxRadius && dist > 1e-4f)
|
||||
{
|
||||
return center + delta * (maxRadius / dist);
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
Vector2 center = Size * 0.5f;
|
||||
float radius = MathF.Min(Size.X, Size.Y) * 0.47f;
|
||||
float maxBlipRadius = MathF.Max(4f, radius - 3f);
|
||||
float scale = radius / MatchState.ArenaHalfExtent;
|
||||
|
||||
DrawCircle(center, radius, BgInner);
|
||||
|
|
@ -693,7 +711,7 @@ public partial class Hud : CanvasLayer
|
|||
if (_state is null) return;
|
||||
|
||||
// Safe Circle
|
||||
float safePx = _state.Spectators.SafeRadius * scale;
|
||||
float safePx = MathF.Min(_state.Spectators.SafeRadius * scale, maxBlipRadius);
|
||||
DrawArc(center, safePx, 0f, MathF.Tau, 64, OrangeCol, 1.6f);
|
||||
|
||||
// Ground drops
|
||||
|
|
@ -701,7 +719,7 @@ public partial class Hud : CanvasLayer
|
|||
{
|
||||
var d = _state.GroundDrops[i];
|
||||
if (d.PickedUp) continue;
|
||||
var p = WorldToRadar(center, scale, d.X, d.Z, _cameraYaw);
|
||||
var p = ClampToRadarDisc(center, maxBlipRadius, WorldToRadar(center, scale, d.X, d.Z, _cameraYaw));
|
||||
if (d.Chassis is not null)
|
||||
{
|
||||
DrawRect(new Rect2(p - new Vector2(2.5f, 2.5f), new Vector2(5f, 5f)), CyanCol);
|
||||
|
|
@ -728,7 +746,7 @@ public partial class Hud : CanvasLayer
|
|||
bool live = mem!.VisibleToPlayer;
|
||||
float drawX = live || mem.FaintHorizonPing ? s.X : mem.LastSeenX;
|
||||
float drawZ = live || mem.FaintHorizonPing ? s.Z : mem.LastSeenZ;
|
||||
var p = WorldToRadar(center, scale, drawX, drawZ, _cameraYaw);
|
||||
var p = ClampToRadarDisc(center, maxBlipRadius, WorldToRadar(center, scale, drawX, drawZ, _cameraYaw));
|
||||
float blipR = 1.6f + s.RadarSignature * 3.1f;
|
||||
|
||||
Color col = s.Tier switch
|
||||
|
|
@ -744,7 +762,7 @@ public partial class Hud : CanvasLayer
|
|||
if (tid >= 0 && tid < _state.Contenders.Count && _state.Contenders[tid].Alive)
|
||||
{
|
||||
var tgt = _state.Contenders[tid];
|
||||
var tp = WorldToRadar(center, scale, tgt.X, tgt.Z, _cameraYaw);
|
||||
var tp = ClampToRadarDisc(center, maxBlipRadius, WorldToRadar(center, scale, tgt.X, tgt.Z, _cameraYaw));
|
||||
DrawLine(p, tp, new Color(RedCol.R, RedCol.G, RedCol.B, 0.65f), 1.3f);
|
||||
}
|
||||
col = RedCol;
|
||||
|
|
@ -774,7 +792,7 @@ public partial class Hud : CanvasLayer
|
|||
|
||||
if (c.IsPlayer)
|
||||
{
|
||||
var p = WorldToRadar(center, scale, c.X, c.Z, _cameraYaw);
|
||||
var p = ClampToRadarDisc(center, maxBlipRadius, WorldToRadar(center, scale, c.X, c.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));
|
||||
|
|
@ -797,12 +815,12 @@ public partial class Hud : CanvasLayer
|
|||
|
||||
if (mem!.VisibleToPlayer)
|
||||
{
|
||||
var p = WorldToRadar(center, scale, c.X, c.Z, _cameraYaw);
|
||||
var p = ClampToRadarDisc(center, maxBlipRadius, WorldToRadar(center, scale, c.X, c.Z, _cameraYaw));
|
||||
DrawCircle(p, 3.3f, OrangeCol);
|
||||
}
|
||||
else
|
||||
{
|
||||
var p = WorldToRadar(center, scale, mem.LastSeenX, mem.LastSeenZ, _cameraYaw);
|
||||
var p = ClampToRadarDisc(center, maxBlipRadius, WorldToRadar(center, scale, mem.LastSeenX, mem.LastSeenZ, _cameraYaw));
|
||||
float alpha = Math.Clamp((1f - mem.LastSeenAge / MatchState.ContactGhostDuration) * 0.48f, 0.08f, 0.48f);
|
||||
DrawCircle(p, 2.8f, new Color(OrangeCol.R, OrangeCol.G, OrangeCol.B, alpha));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,15 @@ public partial class Main : Node3D
|
|||
Reset(_seed + 1);
|
||||
break;
|
||||
case Key.Escape:
|
||||
if (DisplayServer.GetName() != "headless")
|
||||
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
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ namespace RustToDust.Client;
|
|||
/// </summary>
|
||||
public partial class TerrainRenderer : Node3D
|
||||
{
|
||||
private const int ViewportSize = 128;
|
||||
private const float InnerTexelSpan = 125.0f; // texel 1 center (1.5) .. texel 126 center (126.5)
|
||||
private const int ViewportSize = 256;
|
||||
private const float InnerTexelSpan = 253.0f; // texel 1 center (1.5) .. texel 254 center (254.5)
|
||||
private const float GutterCenterOffset = 1.5f;
|
||||
private const float PixelsPerMeter = InnerTexelSpan / TerrainField.TileSize;
|
||||
private const float HeightSpan = TerrainField.MaxWorldHeight - TerrainField.MinWorldHeight;
|
||||
|
|
@ -21,6 +21,13 @@ public partial class TerrainRenderer : Node3D
|
|||
|
||||
private static readonly Color HeightClearColor = new(BaseHeightNorm, 0.88f, 0.0f, 1.0f);
|
||||
private static readonly Color AlbedoClearColor = new(0.69f, 0.50f, 0.31f, 1.0f);
|
||||
private static readonly Vector2[] BrushUv =
|
||||
{
|
||||
new(0f, 0f),
|
||||
new(1f, 0f),
|
||||
new(1f, 1f),
|
||||
new(0f, 1f)
|
||||
};
|
||||
|
||||
private sealed class TileNode
|
||||
{
|
||||
|
|
@ -162,8 +169,8 @@ public partial class TerrainRenderer : Node3D
|
|||
var plane = new PlaneMesh
|
||||
{
|
||||
Size = new Vector2(TerrainField.TileSize, TerrainField.TileSize),
|
||||
SubdivideWidth = 40,
|
||||
SubdivideDepth = 40
|
||||
SubdivideWidth = 64,
|
||||
SubdivideDepth = 64
|
||||
};
|
||||
|
||||
var mat = new ShaderMaterial { Shader = _surfaceShader };
|
||||
|
|
@ -205,6 +212,8 @@ public partial class TerrainRenderer : Node3D
|
|||
Disable3D = true,
|
||||
UseHdr2D = useHdr,
|
||||
TransparentBg = false,
|
||||
Snap2DTransformsToPixel = false,
|
||||
Snap2DVerticesToPixel = false,
|
||||
RenderTargetClearMode = SubViewport.ClearMode.Always,
|
||||
RenderTargetUpdateMode = SubViewport.UpdateMode.Disabled
|
||||
};
|
||||
|
|
@ -227,19 +236,9 @@ public partial class TerrainRenderer : Node3D
|
|||
ClearCanvasChildren(tile.HeightCanvas);
|
||||
ClearCanvasChildren(tile.AlbedoCanvas);
|
||||
|
||||
// Full-tile base clear quads
|
||||
tile.HeightCanvas.AddChild(new ColorRect
|
||||
{
|
||||
Position = Vector2.Zero,
|
||||
Size = new Vector2(ViewportSize, ViewportSize),
|
||||
Color = HeightClearColor
|
||||
});
|
||||
tile.AlbedoCanvas.AddChild(new ColorRect
|
||||
{
|
||||
Position = Vector2.Zero,
|
||||
Size = new Vector2(ViewportSize, ViewportSize),
|
||||
Color = AlbedoClearColor
|
||||
});
|
||||
// Full-tile base clear quads (Polygon2D avoids GUI pixel snapping)
|
||||
tile.HeightCanvas.AddChild(CreateClearQuad(HeightClearColor));
|
||||
tile.AlbedoCanvas.AddChild(CreateClearQuad(AlbedoClearColor));
|
||||
|
||||
float tileMinX = -TerrainField.HalfExtent + tx * TerrainField.TileSize;
|
||||
float tileMinZ = -TerrainField.HalfExtent + tz * TerrainField.TileSize;
|
||||
|
|
@ -282,13 +281,7 @@ public partial class TerrainRenderer : Node3D
|
|||
}
|
||||
|
||||
// 2. Albedo brush pass
|
||||
var albedoQuad = new ColorRect
|
||||
{
|
||||
Position = new Vector2(px - rxPx, py - rzPx),
|
||||
Size = new Vector2(rxPx * 2f, rzPx * 2f),
|
||||
PivotOffset = new Vector2(rxPx, rzPx),
|
||||
Rotation = b.RotationRad
|
||||
};
|
||||
var albedoQuad = CreateOrientedQuad(px, py, rxPx, rzPx, b.RotationRad);
|
||||
var albedoMat = new ShaderMaterial { Shader = _brushAlbedoShader };
|
||||
albedoMat.SetShaderParameter("brush_kind", kindInt);
|
||||
albedoMat.SetShaderParameter("brush_albedo", new Vector3(b.AlbedoR, b.AlbedoG, b.AlbedoB));
|
||||
|
|
@ -301,7 +294,42 @@ public partial class TerrainRenderer : Node3D
|
|||
tile.AlbedoViewport.RenderTargetUpdateMode = SubViewport.UpdateMode.Once;
|
||||
}
|
||||
|
||||
private static ColorRect CreateBrushQuad(
|
||||
private static Polygon2D CreateClearQuad(Color color)
|
||||
{
|
||||
return new Polygon2D
|
||||
{
|
||||
Polygon = new[]
|
||||
{
|
||||
new Vector2(0f, 0f),
|
||||
new Vector2(ViewportSize, 0f),
|
||||
new Vector2(ViewportSize, ViewportSize),
|
||||
new Vector2(0f, ViewportSize)
|
||||
},
|
||||
Color = color
|
||||
};
|
||||
}
|
||||
|
||||
private static Polygon2D CreateOrientedQuad(
|
||||
float px, float py,
|
||||
float rxPx, float rzPx,
|
||||
float rotationRad)
|
||||
{
|
||||
return new Polygon2D
|
||||
{
|
||||
Position = new Vector2(px, py),
|
||||
Rotation = rotationRad,
|
||||
Polygon = new[]
|
||||
{
|
||||
new Vector2(-rxPx, -rzPx),
|
||||
new Vector2(rxPx, -rzPx),
|
||||
new Vector2(rxPx, rzPx),
|
||||
new Vector2(-rxPx, rzPx)
|
||||
},
|
||||
Uv = BrushUv
|
||||
};
|
||||
}
|
||||
|
||||
private static Polygon2D CreateBrushQuad(
|
||||
float px, float py,
|
||||
float rxPx, float rzPx,
|
||||
float rotationRad,
|
||||
|
|
@ -309,13 +337,7 @@ public partial class TerrainRenderer : Node3D
|
|||
int kindInt,
|
||||
float heightDelta)
|
||||
{
|
||||
var quad = new ColorRect
|
||||
{
|
||||
Position = new Vector2(px - rxPx, py - rzPx),
|
||||
Size = new Vector2(rxPx * 2f, rzPx * 2f),
|
||||
PivotOffset = new Vector2(rxPx, rzPx),
|
||||
Rotation = rotationRad
|
||||
};
|
||||
var quad = CreateOrientedQuad(px, py, rxPx, rzPx, rotationRad);
|
||||
var mat = new ShaderMaterial { Shader = shader };
|
||||
mat.SetShaderParameter("brush_kind", kindInt);
|
||||
mat.SetShaderParameter("height_delta", heightDelta);
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ uniform sampler2D albedo_tex : filter_linear, repeat_disable;
|
|||
uniform float height_min = -18.0;
|
||||
uniform float height_max = 52.0;
|
||||
uniform float tile_size = 192.0;
|
||||
uniform float inner_span = 125.0;
|
||||
uniform float tex_size = 128.0;
|
||||
uniform float inner_span = 253.0;
|
||||
uniform float tex_size = 256.0;
|
||||
uniform float gutter_offset = 1.5;
|
||||
|
||||
float decode_height(float h_norm) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue