Cut 1: 1536m desert relief, terrain/cover LOS detection, tier positioning, 3P shoulder cam
This commit is contained in:
parent
3bd66c3b64
commit
3221ca1d0c
19 changed files with 1558 additions and 316 deletions
|
|
@ -173,8 +173,8 @@ public partial class ArenaRenderer : Node3D
|
|||
_safeRingImm.ClearSurfaces();
|
||||
_safeRingImm.SurfaceBegin(Mesh.PrimitiveType.Triangles);
|
||||
|
||||
const int segments = 96;
|
||||
const float halfThick = 0.65f;
|
||||
const int segments = 160;
|
||||
const float halfThick = 1.1f;
|
||||
float rInner = MathF.Max(2f, safeRadius - halfThick);
|
||||
float rOuter = safeRadius + halfThick;
|
||||
|
||||
|
|
@ -353,7 +353,7 @@ public partial class ArenaRenderer : Node3D
|
|||
? session.State.Contenders[s.TargetContenderId.Value]
|
||||
: null;
|
||||
|
||||
if (s.Stance != SpectatorStance.Neutral && target is { Alive: true })
|
||||
if (s.Stance != SpectatorStance.Neutral && s.HasTargetLos && target is { Alive: true })
|
||||
{
|
||||
Vector3 start = specPos + new Vector3(0f, s.Grid.Spec.HalfHeight * 0.7f, 0f);
|
||||
Vector3 end = new Vector3(target.X, target.Y + target.Grid.Spec.HalfHeight * 0.3f, target.Z);
|
||||
|
|
|
|||
184
client/Hud.cs
184
client/Hud.cs
|
|
@ -28,6 +28,7 @@ public partial class Hud : CanvasLayer
|
|||
|
||||
private readonly Func<ArenaSession?> _getSession;
|
||||
private readonly Action<int, string> _onEquipCargo;
|
||||
private readonly Func<float> _getCameraYaw;
|
||||
|
||||
private Label _chassisHeader = null!;
|
||||
private Label _planeBadge = null!;
|
||||
|
|
@ -35,10 +36,12 @@ public partial class Hud : CanvasLayer
|
|||
private Label _coreHpLabel = null!;
|
||||
private Label _statsLabel = null!;
|
||||
private Label _safeLabel = null!;
|
||||
private Label _detectionLabel = null!;
|
||||
private Label _promptLabel = null!;
|
||||
private Label _controlsHint = null!;
|
||||
|
||||
private RadarWidget _radar = null!;
|
||||
private CrosshairOverlay _crosshair = null!;
|
||||
private SchematicPanel _schematic = null!;
|
||||
private VBoxContainer _cargoList = null!;
|
||||
private Label _cargoHeader = null!;
|
||||
|
|
@ -56,10 +59,11 @@ public partial class Hud : CanvasLayer
|
|||
private int _lastCargoHash = -1;
|
||||
private bool _garageExpanded;
|
||||
|
||||
public Hud(Func<ArenaSession?> getSession, Action<int, string> onEquipCargo)
|
||||
public Hud(Func<ArenaSession?> getSession, Action<int, string> onEquipCargo, Func<float>? getCameraYaw = null)
|
||||
{
|
||||
_getSession = getSession;
|
||||
_onEquipCargo = onEquipCargo;
|
||||
_getCameraYaw = getCameraYaw ?? (() => 0f);
|
||||
Layer = 10;
|
||||
}
|
||||
|
||||
|
|
@ -75,6 +79,7 @@ public partial class Hud : CanvasLayer
|
|||
|
||||
public override void _Ready()
|
||||
{
|
||||
BuildCrosshair();
|
||||
BuildTopLeft();
|
||||
BuildTopRightRadar();
|
||||
BuildBottomLeftSchematic();
|
||||
|
|
@ -125,11 +130,26 @@ public partial class Hud : CanvasLayer
|
|||
_safeLabel.Modulate = RedCol;
|
||||
}
|
||||
|
||||
if (state.PlayerDetectedByCount > 0)
|
||||
{
|
||||
_detectionLabel.Text = $"DETECTED BY {state.PlayerDetectedByCount}";
|
||||
_detectionLabel.Modulate = RedCol;
|
||||
}
|
||||
else
|
||||
{
|
||||
_detectionLabel.Text = "CONCEALED (TERRAIN)";
|
||||
_detectionLabel.Modulate = OliveCol;
|
||||
}
|
||||
|
||||
_promptLabel.Text = BuildInteractionPrompt(state, player);
|
||||
_promptLabel.Visible = !string.IsNullOrEmpty(_promptLabel.Text);
|
||||
|
||||
// Radar
|
||||
_radar.SetState(state);
|
||||
// Crosshair + Heat Arc
|
||||
_crosshair.SetState(player);
|
||||
_crosshair.QueueRedraw();
|
||||
|
||||
// Radar (heading-up with camera yaw)
|
||||
_radar.SetState(state, _getCameraYaw());
|
||||
_radar.QueueRedraw();
|
||||
|
||||
// Schematic + Cargo
|
||||
|
|
@ -164,6 +184,14 @@ public partial class Hud : CanvasLayer
|
|||
}
|
||||
}
|
||||
|
||||
private void BuildCrosshair()
|
||||
{
|
||||
_crosshair = new CrosshairOverlay { Name = "Crosshair" };
|
||||
_crosshair.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
||||
_crosshair.MouseFilter = Control.MouseFilterEnum.Ignore;
|
||||
AddChild(_crosshair);
|
||||
}
|
||||
|
||||
private void BuildTopLeft()
|
||||
{
|
||||
var panel = CreateStyledPanel();
|
||||
|
|
@ -222,12 +250,16 @@ public partial class Hud : CanvasLayer
|
|||
_safeLabel.AddThemeFontSizeOverride("font_size", 13);
|
||||
vbox.AddChild(_safeLabel);
|
||||
|
||||
_detectionLabel = new Label { Text = "CONCEALED (TERRAIN)" };
|
||||
_detectionLabel.AddThemeFontSizeOverride("font_size", 13);
|
||||
vbox.AddChild(_detectionLabel);
|
||||
|
||||
_promptLabel = new Label { Text = "", Visible = false };
|
||||
_promptLabel.AddThemeColorOverride("font_color", CyanCol);
|
||||
_promptLabel.AddThemeFontSizeOverride("font_size", 14);
|
||||
vbox.AddChild(_promptLabel);
|
||||
|
||||
_controlsHint = new Label { Text = "WASD Drive | LMB Fire | E Loot/Swap | Tab Garage | R Reset" };
|
||||
_controlsHint = new Label { Text = "WASD Drive | Mouse Aim | LMB Fire | E Loot/Swap | Tab Garage | Wheel Zoom" };
|
||||
_controlsHint.AddThemeColorOverride("font_color", TextMuted);
|
||||
_controlsHint.AddThemeFontSizeOverride("font_size", 11);
|
||||
vbox.AddChild(_controlsHint);
|
||||
|
|
@ -566,15 +598,86 @@ public partial class Hud : CanvasLayer
|
|||
return panel;
|
||||
}
|
||||
|
||||
private sealed partial class CrosshairOverlay : Control
|
||||
{
|
||||
private ContenderState? _player;
|
||||
|
||||
public void SetState(ContenderState player) => _player = player;
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
Vector2 center = Size * 0.5f;
|
||||
float gap = 6f;
|
||||
float tick = 10f;
|
||||
Color retCol = new Color(TextLight.R, TextLight.G, TextLight.B, 0.88f);
|
||||
|
||||
// Clean 4-tick center crosshair + center pip
|
||||
DrawCircle(center, 1.8f, retCol);
|
||||
DrawLine(center + new Vector2(-gap - tick, 0f), center + new Vector2(-gap, 0f), retCol, 1.6f);
|
||||
DrawLine(center + new Vector2(gap, 0f), center + new Vector2(gap + tick, 0f), retCol, 1.6f);
|
||||
DrawLine(center + new Vector2(0f, -gap - tick), center + new Vector2(0f, -gap), retCol, 1.6f);
|
||||
DrawLine(center + new Vector2(0f, gap), center + new Vector2(0f, gap + tick), retCol, 1.6f);
|
||||
|
||||
if (_player is null || !_player.Alive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Thermal heat-arc indicator around crosshair
|
||||
float heatRatio = 0f;
|
||||
bool overPlateau = false;
|
||||
var mounted = _player.Grid.Mounted;
|
||||
for (int i = 0; i < mounted.Count; i++)
|
||||
{
|
||||
var m = mounted[i];
|
||||
if (m.Spec.Kind == HardpointKind.Weapon)
|
||||
{
|
||||
float r = Math.Clamp(
|
||||
(m.CurrentTemp - ChassisGrid.AmbientTemp) / MathF.Max(1f, m.Spec.MaxTemp - ChassisGrid.AmbientTemp),
|
||||
0f, 1f);
|
||||
if (r > heatRatio) heatRatio = r;
|
||||
if (m.CurrentTemp > m.Spec.OptimalTemp + m.Spec.PlateauWidth * 0.5f)
|
||||
{
|
||||
overPlateau = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float arcRadius = 21f;
|
||||
float startAngle = -MathF.PI * 0.75f;
|
||||
float maxSweep = MathF.PI * 1.5f;
|
||||
DrawArc(center, arcRadius, startAngle, startAngle + maxSweep, 24, new Color(BorderCol.R, BorderCol.G, BorderCol.B, 0.4f), 2.0f);
|
||||
|
||||
if (heatRatio > 0.01f)
|
||||
{
|
||||
Color heatCol = overPlateau
|
||||
? RedCol
|
||||
: (heatRatio > 0.65f ? OrangeCol : OliveCol);
|
||||
DrawArc(center, arcRadius, startAngle, startAngle + maxSweep * heatRatio, 24, heatCol, 2.4f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed partial class RadarWidget : Control
|
||||
{
|
||||
private MatchState? _state;
|
||||
private float _cameraYaw;
|
||||
|
||||
public void SetState(MatchState state) => _state = state;
|
||||
public void SetState(MatchState state, float cameraYaw)
|
||||
{
|
||||
_state = state;
|
||||
_cameraYaw = cameraYaw;
|
||||
}
|
||||
|
||||
private static Vector2 WorldToRadar(Vector2 center, float scale, float wx, float wz) =>
|
||||
// Match chase camera orientation: screen-up = +Z, screen-right = -X.
|
||||
center + new Vector2(-wx, -wz) * scale;
|
||||
private static Vector2 WorldToRadar(Vector2 center, float scale, float wx, float wz, float camYaw)
|
||||
{
|
||||
// Heading-up 3P radar: camera forward (sinY, cosY) is always UP (-screenY), camera right (-cosY, sinY) is RIGHT (+screenX).
|
||||
float sinY = MathF.Sin(camYaw);
|
||||
float cosY = MathF.Cos(camYaw);
|
||||
float rx = -wx * cosY + wz * sinY;
|
||||
float fy = wx * sinY + wz * cosY;
|
||||
return center + new Vector2(rx, -fy) * scale;
|
||||
}
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
|
|
@ -584,19 +687,21 @@ public partial class Hud : CanvasLayer
|
|||
|
||||
DrawCircle(center, radius, BgInner);
|
||||
DrawArc(center, radius, 0f, MathF.Tau, 48, BorderCol, 1.5f);
|
||||
// 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;
|
||||
|
||||
// Safe Circle
|
||||
float safePx = _state.Spectators.SafeRadius * scale;
|
||||
DrawArc(center, safePx, 0f, MathF.Tau, 56, OrangeCol, 1.6f);
|
||||
DrawArc(center, safePx, 0f, MathF.Tau, 64, OrangeCol, 1.6f);
|
||||
|
||||
// Ground drops
|
||||
for (int i = 0; i < _state.GroundDrops.Count; i++)
|
||||
{
|
||||
var d = _state.GroundDrops[i];
|
||||
if (d.PickedUp) continue;
|
||||
var p = WorldToRadar(center, scale, d.X, d.Z);
|
||||
var p = 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);
|
||||
|
|
@ -607,13 +712,23 @@ public partial class Hud : CanvasLayer
|
|||
}
|
||||
}
|
||||
|
||||
// Spectator Wall (scaled by RadarSignature) + red target lock lines
|
||||
// Spectator Wall (LOS / Tourist horizon rule / 5s ghost memory; hidden Exemplars vanish!)
|
||||
var specs = _state.Spectators.Spectators;
|
||||
for (int i = 0; i < specs.Count; i++)
|
||||
{
|
||||
var s = specs[i];
|
||||
if (!s.Alive) continue;
|
||||
var p = WorldToRadar(center, scale, s.X, s.Z);
|
||||
|
||||
_state.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;
|
||||
var p = WorldToRadar(center, scale, drawX, drawZ, _cameraYaw);
|
||||
float blipR = 1.6f + s.RadarSignature * 3.1f;
|
||||
|
||||
Color col = s.Tier switch
|
||||
|
|
@ -623,30 +738,46 @@ public partial class Hud : CanvasLayer
|
|||
_ => RedCol
|
||||
};
|
||||
|
||||
if (s.Stance != SpectatorStance.Neutral && s.TargetContenderId.HasValue)
|
||||
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)
|
||||
{
|
||||
var tgt = _state.Contenders[tid];
|
||||
var tp = WorldToRadar(center, scale, tgt.X, tgt.Z);
|
||||
var tp = 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;
|
||||
}
|
||||
|
||||
DrawCircle(p, blipR, col);
|
||||
if (!live)
|
||||
{
|
||||
float alpha = mem.FaintHorizonPing
|
||||
? 0.42f
|
||||
: Math.Clamp((1f - mem.LastSeenAge / MatchState.ContactGhostDuration) * 0.48f, 0.08f, 0.48f);
|
||||
Color ghostCol = mem.FaintHorizonPing ? GoldCol : col;
|
||||
DrawCircle(p, blipR, new Color(ghostCol.R, ghostCol.G, ghostCol.B, alpha));
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawCircle(p, blipR, col);
|
||||
}
|
||||
}
|
||||
|
||||
// Contenders
|
||||
// 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++)
|
||||
{
|
||||
var c = _state.Contenders[i];
|
||||
if (!c.Alive) continue;
|
||||
var p = WorldToRadar(center, scale, c.X, c.Z);
|
||||
|
||||
if (c.IsPlayer)
|
||||
{
|
||||
var dir = new Vector2(-MathF.Sin(c.Yaw), -MathF.Cos(c.Yaw));
|
||||
var p = 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));
|
||||
var perp = new Vector2(-dir.Y, dir.X);
|
||||
var pts = new[]
|
||||
{
|
||||
|
|
@ -655,10 +786,25 @@ public partial class Hud : CanvasLayer
|
|||
p - dir * 4.5f - perp * 4.2f
|
||||
};
|
||||
DrawColoredPolygon(pts, OliveCol);
|
||||
continue;
|
||||
}
|
||||
|
||||
_state.ContenderContacts.TryGetValue(c.Id, out var mem);
|
||||
if (!MatchState.IsContactOnRadar(mem))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mem!.VisibleToPlayer)
|
||||
{
|
||||
var p = WorldToRadar(center, scale, c.X, c.Z, _cameraYaw);
|
||||
DrawCircle(p, 3.3f, OrangeCol);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawCircle(p, 3.3f, OrangeCol);
|
||||
var p = 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
212
client/Main.cs
212
client/Main.cs
|
|
@ -18,8 +18,10 @@ public partial class Main : Node3D
|
|||
private ArenaSession? _session;
|
||||
|
||||
private PlayerInput? _scriptedInput;
|
||||
private float _cameraDistance = 30f;
|
||||
private Vector3 _cameraSmoothedTarget = Vector3.Zero;
|
||||
private float _cameraYaw;
|
||||
private float _cameraPitch = Mathf.DegToRad(12f);
|
||||
private float _cameraZoom = 1.0f;
|
||||
private Vector3 _cameraSmoothedAnchor = Vector3.Zero;
|
||||
private float _elapsedSeconds;
|
||||
private bool _interactQueued;
|
||||
private int _seed = 42;
|
||||
|
|
@ -30,6 +32,7 @@ public partial class Main : Node3D
|
|||
public Hud Hud => _hud;
|
||||
public string? Failure { get; private set; }
|
||||
public int Seed => _seed;
|
||||
public float CameraYaw => _cameraYaw;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -43,14 +46,14 @@ public partial class Main : Node3D
|
|||
|
||||
_camera = new Camera3D
|
||||
{
|
||||
Name = "TacticalCamera",
|
||||
Name = "ShoulderCamera",
|
||||
Current = true,
|
||||
Fov = 48f,
|
||||
Far = 520f
|
||||
Fov = 58f,
|
||||
Far = 1800f
|
||||
};
|
||||
AddChild(_camera);
|
||||
|
||||
_hud = new Hud(() => _session, OnEquipCargo) { Name = "Hud" };
|
||||
_hud = new Hud(() => _session, OnEquipCargo, () => _cameraYaw) { Name = "Hud" };
|
||||
AddChild(_hud);
|
||||
|
||||
Reset(_seed);
|
||||
|
|
@ -73,11 +76,21 @@ public partial class Main : Node3D
|
|||
{
|
||||
_session = new ArenaSession(seed);
|
||||
var p = _session.State.Player;
|
||||
_cameraSmoothedTarget = new Vector3(p.X, p.Y, p.Z);
|
||||
_cameraYaw = p.Yaw;
|
||||
_cameraPitch = Mathf.DegToRad(12f);
|
||||
_cameraZoom = 1.0f;
|
||||
_cameraSmoothedAnchor = ComputeTargetAnchor(p);
|
||||
|
||||
_terrain.InvalidateAll();
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds);
|
||||
UpdateCamera(1f);
|
||||
_hud.Sync(_session);
|
||||
|
||||
if (DisplayServer.GetName() != "headless" && !_hud.GarageExpanded)
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -90,6 +103,16 @@ public partial class Main : Node3D
|
|||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseMotion mm && Input.MouseMode == Input.MouseModeEnum.Captured)
|
||||
{
|
||||
_cameraYaw -= mm.Relative.X * 0.0028f;
|
||||
_cameraPitch = Math.Clamp(
|
||||
_cameraPitch + mm.Relative.Y * 0.0024f,
|
||||
Mathf.DegToRad(-18f),
|
||||
Mathf.DegToRad(38f));
|
||||
return;
|
||||
}
|
||||
|
||||
if (@event is InputEventKey key && key.Pressed && !key.Echo)
|
||||
{
|
||||
switch (key.Keycode)
|
||||
|
|
@ -99,14 +122,23 @@ 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;
|
||||
}
|
||||
break;
|
||||
case Key.R:
|
||||
Reset(_seed + 1);
|
||||
break;
|
||||
case Key.Escape:
|
||||
Input.MouseMode = Input.MouseMode == Input.MouseModeEnum.Confined
|
||||
? Input.MouseModeEnum.Visible
|
||||
: Input.MouseModeEnum.Confined;
|
||||
if (DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = Input.MouseMode == Input.MouseModeEnum.Captured
|
||||
? Input.MouseModeEnum.Visible
|
||||
: Input.MouseModeEnum.Captured;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -114,11 +146,19 @@ public partial class Main : Node3D
|
|||
{
|
||||
if (mb.ButtonIndex == MouseButton.WheelUp)
|
||||
{
|
||||
_cameraDistance = Math.Clamp(_cameraDistance - 2.5f, 16f, 58f);
|
||||
_cameraZoom = Math.Clamp(_cameraZoom - 0.08f, 0.75f, 1.6f);
|
||||
}
|
||||
else if (mb.ButtonIndex == MouseButton.WheelDown)
|
||||
{
|
||||
_cameraDistance = Math.Clamp(_cameraDistance + 2.5f, 16f, 58f);
|
||||
_cameraZoom = Math.Clamp(_cameraZoom + 0.08f, 0.75f, 1.6f);
|
||||
}
|
||||
else if (mb.ButtonIndex == MouseButton.Left &&
|
||||
Input.MouseMode == Input.MouseModeEnum.Visible &&
|
||||
!_hud.GarageExpanded &&
|
||||
!_hud.IsPointerOverInteractiveHud(mb.Position) &&
|
||||
DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -161,11 +201,11 @@ public partial class Main : Node3D
|
|||
if (Input.IsKeyPressed(Key.A) || Input.IsKeyPressed(Key.Left)) steer -= 1f;
|
||||
|
||||
bool brake = Input.IsKeyPressed(Key.Space);
|
||||
Vector2 mousePos = GetViewport().GetMousePosition();
|
||||
bool pointerOnHud = _hud.IsPointerOverInteractiveHud(mousePos);
|
||||
bool pointerOnHud = Input.MouseMode != Input.MouseModeEnum.Captured &&
|
||||
_hud.IsPointerOverInteractiveHud(GetViewport().GetMousePosition());
|
||||
bool fire = !pointerOnHud && Input.IsMouseButtonPressed(MouseButton.Left);
|
||||
|
||||
var (aimX, aimZ) = ComputeMouseTerrainAim(mousePos);
|
||||
var (aimX, aimY, aimZ) = ComputeCenterScreenAim();
|
||||
return new PlayerInput(
|
||||
Throttle: throttle,
|
||||
Steer: steer,
|
||||
|
|
@ -173,48 +213,135 @@ public partial class Main : Node3D
|
|||
AimWorldZ: aimZ,
|
||||
Fire: fire,
|
||||
InteractPickup: _interactQueued,
|
||||
Brake: brake);
|
||||
Brake: brake,
|
||||
AimWorldY: aimY);
|
||||
}
|
||||
|
||||
private (float AimX, float AimZ) ComputeMouseTerrainAim(Vector2 mousePos)
|
||||
private (float AimX, float AimY, float AimZ) ComputeCenterScreenAim()
|
||||
{
|
||||
var player = Session.State.Player;
|
||||
Vector3 rayOrigin = _camera.ProjectRayOrigin(mousePos);
|
||||
Vector3 rayDir = _camera.ProjectRayNormal(mousePos);
|
||||
|
||||
if (Session.State.Terrain.Raycast(
|
||||
rayOrigin.X, rayOrigin.Y, rayOrigin.Z,
|
||||
rayDir.X, rayDir.Y, rayDir.Z,
|
||||
maxDistance: 320f,
|
||||
out float hx, out _, out float hz, out _))
|
||||
Vector2 screenSize = GetViewport().GetVisibleRect().Size;
|
||||
if (screenSize.X < 2f || screenSize.Y < 2f)
|
||||
{
|
||||
return (hx, hz);
|
||||
return (
|
||||
player.X + MathF.Sin(_cameraYaw) * 40f,
|
||||
player.Y,
|
||||
player.Z + MathF.Cos(_cameraYaw) * 40f);
|
||||
}
|
||||
|
||||
if (MathF.Abs(rayDir.Y) > 1e-4f)
|
||||
Vector2 center = screenSize * 0.5f;
|
||||
Vector3 rayOrigin = _camera.ProjectRayOrigin(center);
|
||||
Vector3 rayDir = _camera.ProjectRayNormal(center);
|
||||
|
||||
const float maxAimDist = 450f;
|
||||
ulong playerStableId = ArenaSession.ContenderStableIdBase + (ulong)player.Id;
|
||||
|
||||
Vector3 castOrigin = rayOrigin;
|
||||
float remainingDist = maxAimDist;
|
||||
float boxDist = maxAimDist;
|
||||
Vector3 boxHitPt = Vector3.Zero;
|
||||
bool hasBoxHit = false;
|
||||
|
||||
// Cast against Ymir world, skipping the player's own chassis if hit along the shoulder ray.
|
||||
for (int attempt = 0; attempt < 2; attempt++)
|
||||
{
|
||||
float t = (player.Y - rayOrigin.Y) / rayDir.Y;
|
||||
if (t > 0f)
|
||||
var hit = Session.World.CastRayClosest(
|
||||
(castOrigin.X, castOrigin.Y, castOrigin.Z),
|
||||
(rayDir.X * remainingDist, rayDir.Y * remainingDist, rayDir.Z * remainingDist));
|
||||
if (!hit.Hit)
|
||||
{
|
||||
Vector3 p = rayOrigin + rayDir * t;
|
||||
return (p.X, p.Z);
|
||||
break;
|
||||
}
|
||||
|
||||
var pt = new Vector3(hit.Point.X, hit.Point.Y, hit.Point.Z);
|
||||
if (hit.StableId == playerStableId)
|
||||
{
|
||||
float skip = rayOrigin.DistanceTo(pt) + 0.4f;
|
||||
castOrigin = rayOrigin + rayDir * skip;
|
||||
remainingDist = MathF.Max(1f, maxAimDist - skip);
|
||||
continue;
|
||||
}
|
||||
|
||||
boxHitPt = pt;
|
||||
boxDist = rayOrigin.DistanceTo(pt);
|
||||
hasBoxHit = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return (player.X + MathF.Sin(player.Yaw) * 25f, player.Z + MathF.Cos(player.Yaw) * 25f);
|
||||
bool hasTerrainHit = Session.State.Terrain.Raycast(
|
||||
rayOrigin.X, rayOrigin.Y, rayOrigin.Z,
|
||||
rayDir.X, rayDir.Y, rayDir.Z,
|
||||
maxDistance: boxDist,
|
||||
out float tx, out float ty, out float tz, out float terrainDist);
|
||||
|
||||
if (hasTerrainHit && terrainDist <= boxDist)
|
||||
{
|
||||
return (tx, ty, tz);
|
||||
}
|
||||
|
||||
if (hasBoxHit)
|
||||
{
|
||||
return (boxHitPt.X, boxHitPt.Y, boxHitPt.Z);
|
||||
}
|
||||
|
||||
Vector3 farPt = rayOrigin + rayDir * 320f;
|
||||
return (farPt.X, farPt.Y, farPt.Z);
|
||||
}
|
||||
|
||||
private Vector3 ComputeTargetAnchor(ContenderState p)
|
||||
{
|
||||
var spec = p.Grid.Spec;
|
||||
float heightT = Math.Clamp((spec.HalfHeight - 0.75f) / (2.35f - 0.75f), 0f, 1.2f);
|
||||
float upOffset = Mathf.Lerp(3.2f, 6.5f, heightT);
|
||||
float rightOffset = Mathf.Lerp(1.6f, 2.8f, heightT);
|
||||
|
||||
var camRight = new Vector3(-MathF.Cos(_cameraYaw), 0f, MathF.Sin(_cameraYaw));
|
||||
return new Vector3(p.X, p.Y + (upOffset - spec.HalfHeight), p.Z) + camRight * rightOffset;
|
||||
}
|
||||
|
||||
private void UpdateCamera(float dt)
|
||||
{
|
||||
var p = Session.State.Player;
|
||||
var target = new Vector3(p.X, p.Y + 1.0f, p.Z);
|
||||
float blend = 1f - MathF.Exp(-dt * 9f);
|
||||
_cameraSmoothedTarget = _cameraSmoothedTarget.Lerp(target, blend);
|
||||
var spec = p.Grid.Spec;
|
||||
float heightT = Math.Clamp((spec.HalfHeight - 0.75f) / (2.35f - 0.75f), 0f, 1.2f);
|
||||
float backDist = Mathf.Lerp(7.5f, 12.5f, heightT) * _cameraZoom;
|
||||
|
||||
// Angled tactical 3rd-person desert chase view
|
||||
Vector3 offset = new Vector3(0f, _cameraDistance * 0.78f, -_cameraDistance * 0.72f);
|
||||
_camera.GlobalPosition = _cameraSmoothedTarget + offset;
|
||||
_camera.LookAt(_cameraSmoothedTarget, Vector3.Up);
|
||||
Vector3 targetAnchor = ComputeTargetAnchor(p);
|
||||
float blend = dt >= 1f ? 1f : 1f - MathF.Exp(-dt * 16f);
|
||||
_cameraSmoothedAnchor = _cameraSmoothedAnchor.Lerp(targetAnchor, blend);
|
||||
|
||||
var camFwdHoriz = new Vector3(MathF.Sin(_cameraYaw), 0f, MathF.Cos(_cameraYaw));
|
||||
var lookDir = (camFwdHoriz * MathF.Cos(_cameraPitch) - Vector3.UnitY * MathF.Sin(_cameraPitch)).Normalized();
|
||||
|
||||
// Pull camera forward along arm if terrain or static cover blocks the shoulder-to-camera ray
|
||||
float effectiveBack = backDist;
|
||||
if (Session.State.Terrain.Raycast(
|
||||
_cameraSmoothedAnchor.X, _cameraSmoothedAnchor.Y, _cameraSmoothedAnchor.Z,
|
||||
-lookDir.X, -lookDir.Y, -lookDir.Z,
|
||||
backDist,
|
||||
out _, out _, out _, out float terrainDist))
|
||||
{
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(1.6f, terrainDist - 0.6f));
|
||||
}
|
||||
|
||||
var boxHit = Session.World.CastRayClosest(
|
||||
(_cameraSmoothedAnchor.X, _cameraSmoothedAnchor.Y, _cameraSmoothedAnchor.Z),
|
||||
(-lookDir.X * effectiveBack, -lookDir.Y * effectiveBack, -lookDir.Z * effectiveBack));
|
||||
if (boxHit.Hit && boxHit.StableId < ArenaSession.ContenderStableIdBase)
|
||||
{
|
||||
var pt = new Vector3(boxHit.Point.X, boxHit.Point.Y, boxHit.Point.Z);
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(1.6f, _cameraSmoothedAnchor.DistanceTo(pt) - 0.5f));
|
||||
}
|
||||
|
||||
Vector3 camPos = _cameraSmoothedAnchor - lookDir * effectiveBack;
|
||||
float minTerrainY = Session.State.Terrain.SampleHeight(camPos.X, camPos.Z) + 1.2f;
|
||||
if (camPos.Y < minTerrainY)
|
||||
{
|
||||
camPos.Y = minTerrainY;
|
||||
}
|
||||
|
||||
_camera.GlobalPosition = camPos;
|
||||
_camera.LookAt(camPos + lookDir * 60f, Vector3.Up);
|
||||
}
|
||||
|
||||
private void OnEquipCargo(int cargoIndex, string hardpointId)
|
||||
|
|
@ -248,8 +375,11 @@ public partial class Main : Node3D
|
|||
AmbientLightSource = Godot.Environment.AmbientSource.Sky,
|
||||
AmbientLightEnergy = 0.55f,
|
||||
FogEnabled = true,
|
||||
FogLightColor = new Color(0.74f, 0.55f, 0.38f),
|
||||
FogDensity = 0.0022f
|
||||
FogMode = Godot.Environment.FogModeEnum.Depth,
|
||||
FogLightColor = new Color(0.76f, 0.57f, 0.39f),
|
||||
FogDensity = 0.72f,
|
||||
FogDepthBegin = 380f,
|
||||
FogDepthEnd = 1100f
|
||||
};
|
||||
AddChild(new WorldEnvironment { Name = "WorldEnv", Environment = env });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ namespace RustToDust.Client;
|
|||
|
||||
/// <summary>
|
||||
/// Top-down orthographic SubViewport brush-to-tile PBR + displacement terrain baker.
|
||||
/// Maintains a 4x4 grid of 96m x 96m terrain tiles covering [-192, +192] in X and Z.
|
||||
/// Maintains an 8x8 grid of 192m x 192m terrain tiles covering [-768, +768] in X and Z.
|
||||
/// Only tiles whose <see cref="TerrainField.TileVersions"/> changed are re-baked.
|
||||
/// </summary>
|
||||
public partial class TerrainRenderer : Node3D
|
||||
{
|
||||
private const int ViewportSize = 256;
|
||||
private const float InnerTexelSpan = 253.0f; // texel 1 center (1.5) .. texel 254 center (254.5)
|
||||
private const int ViewportSize = 128;
|
||||
private const float InnerTexelSpan = 125.0f; // texel 1 center (1.5) .. texel 126 center (126.5)
|
||||
private const float GutterCenterOffset = 1.5f;
|
||||
private const float PixelsPerMeter = InnerTexelSpan / TerrainField.TileSize;
|
||||
private const float HeightSpan = TerrainField.MaxWorldHeight - TerrainField.MinWorldHeight;
|
||||
|
|
@ -162,8 +162,8 @@ public partial class TerrainRenderer : Node3D
|
|||
var plane = new PlaneMesh
|
||||
{
|
||||
Size = new Vector2(TerrainField.TileSize, TerrainField.TileSize),
|
||||
SubdivideWidth = 48,
|
||||
SubdivideDepth = 48
|
||||
SubdivideWidth = 40,
|
||||
SubdivideDepth = 40
|
||||
};
|
||||
|
||||
var mat = new ShaderMaterial { Shader = _surfaceShader };
|
||||
|
|
@ -172,6 +172,9 @@ public partial class TerrainRenderer : Node3D
|
|||
mat.SetShaderParameter("height_min", TerrainField.MinWorldHeight);
|
||||
mat.SetShaderParameter("height_max", TerrainField.MaxWorldHeight);
|
||||
mat.SetShaderParameter("tile_size", TerrainField.TileSize);
|
||||
mat.SetShaderParameter("inner_span", InnerTexelSpan);
|
||||
mat.SetShaderParameter("tex_size", (float)ViewportSize);
|
||||
mat.SetShaderParameter("gutter_offset", GutterCenterOffset);
|
||||
|
||||
float centerX = -TerrainField.HalfExtent + (tx + 0.5f) * TerrainField.TileSize;
|
||||
float centerZ = -TerrainField.HalfExtent + (tz + 0.5f) * TerrainField.TileSize;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
shader_type canvas_item;
|
||||
render_mode blend_add;
|
||||
|
||||
// Encodes positive height deltas into R ([-12m, +16m] => span 28m),
|
||||
// Encodes positive height deltas into R ([-18m, +52m] => span 70m),
|
||||
// roughness delta into G, scorch/track wear into B, and ALWAYS A = 1.0
|
||||
// (required for gl_compatibility TransparentBg=false blend equations).
|
||||
uniform int brush_kind = 0;
|
||||
uniform float height_delta = 0.0;
|
||||
uniform float height_span = 28.0;
|
||||
uniform float height_span = 70.0;
|
||||
|
||||
void fragment() {
|
||||
vec2 uv_local = UV * 2.0 - 1.0;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ render_mode blend_sub;
|
|||
// Encodes negative height deltas (crater pits, dry washes, road ruts, tire ruts) into R.
|
||||
uniform int brush_kind = 0;
|
||||
uniform float height_delta = 0.0;
|
||||
uniform float height_span = 28.0;
|
||||
uniform float height_span = 70.0;
|
||||
|
||||
void fragment() {
|
||||
vec2 uv_local = UV * 2.0 - 1.0;
|
||||
|
|
|
|||
|
|
@ -3,9 +3,12 @@ render_mode cull_back, depth_draw_opaque;
|
|||
|
||||
uniform sampler2D height_tex : filter_linear, repeat_disable;
|
||||
uniform sampler2D albedo_tex : filter_linear, repeat_disable;
|
||||
uniform float height_min = -12.0;
|
||||
uniform float height_max = 16.0;
|
||||
uniform float tile_size = 96.0;
|
||||
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 gutter_offset = 1.5;
|
||||
|
||||
float decode_height(float h_norm) {
|
||||
return mix(height_min, height_max, clamp(h_norm, 0.0, 1.0));
|
||||
|
|
@ -18,7 +21,7 @@ float hash21(vec2 p) {
|
|||
}
|
||||
|
||||
vec2 to_baked_uv(vec2 mesh_uv) {
|
||||
return (mesh_uv * 253.0 + 1.5) / 256.0;
|
||||
return (mesh_uv * inner_span + gutter_offset) / tex_size;
|
||||
}
|
||||
|
||||
void vertex() {
|
||||
|
|
@ -28,8 +31,8 @@ void vertex() {
|
|||
|
||||
void fragment() {
|
||||
vec2 uv_baked = to_baked_uv(UV);
|
||||
const float texel_step = 1.0 / 256.0;
|
||||
float world_step = tile_size / 253.0;
|
||||
float texel_step = 1.0 / tex_size;
|
||||
float world_step = tile_size / inner_span;
|
||||
|
||||
float hL = decode_height(texture(height_tex, uv_baked - vec2(texel_step, 0.0)).r);
|
||||
float hR = decode_height(texture(height_tex, uv_baked + vec2(texel_step, 0.0)).r);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public partial class Smoke : Node
|
|||
Check(Engine.PhysicsTicksPerSecond == 60, $"Expected 60 physics ticks/sec, got {Engine.PhysicsTicksPerSecond}");
|
||||
Check((string)ProjectSettings.GetSetting("physics/3d/physics_engine") == "Dummy", "Godot 3D physics_engine is not Dummy");
|
||||
Check(!_main.GetWorld3D().Space.IsValid, "Godot should have no active 3D physics space");
|
||||
Check(_main.Terrain.BakedTileCount == 16, $"Expected 16 baked terrain tiles, got {_main.Terrain.BakedTileCount}");
|
||||
Check(_main.Terrain.BakedTileCount == 64, $"Expected 64 baked terrain tiles, got {_main.Terrain.BakedTileCount}");
|
||||
|
||||
var player = _main.Session.State.Player;
|
||||
float startX = player.X;
|
||||
|
|
@ -97,11 +97,11 @@ public partial class Smoke : Node
|
|||
|
||||
bool isHeadless = DisplayServer.GetName() == "headless";
|
||||
int rebakesBefore = _main.Terrain.DirtyRebakes;
|
||||
float cpuBefore = _main.Session.State.Terrain.SampleHeight(-48f, -48f);
|
||||
float cpuBefore = _main.Session.State.Terrain.SampleHeight(-96f, -96f);
|
||||
float gpuBefore = 0f;
|
||||
if (!isHeadless)
|
||||
{
|
||||
bool hasGpuBefore = _main.Terrain.TrySampleBakedHeight(-48f, -48f, out gpuBefore);
|
||||
bool hasGpuBefore = _main.Terrain.TrySampleBakedHeight(-96f, -96f, out gpuBefore);
|
||||
Check(hasGpuBefore, "Expected GPU HeightViewport readback to succeed before crater");
|
||||
if (hasGpuBefore)
|
||||
{
|
||||
|
|
@ -110,12 +110,12 @@ public partial class Smoke : Node
|
|||
}
|
||||
}
|
||||
|
||||
_main.Session.State.Terrain.StampCrater(-48f, -48f, radius: 5f, depth: 1.4f);
|
||||
_main.Session.State.Terrain.StampCrater(-96f, -96f, radius: 5f, depth: 1.4f);
|
||||
_main.Terrain.Sync(_main.Session.State.Terrain);
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
|
||||
float cpuAfter = _main.Session.State.Terrain.SampleHeight(-48f, -48f);
|
||||
float cpuAfter = _main.Session.State.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,
|
||||
|
|
@ -123,7 +123,7 @@ public partial class Smoke : Node
|
|||
|
||||
if (!isHeadless)
|
||||
{
|
||||
bool hasGpuAfter = _main.Terrain.TrySampleBakedHeight(-48f, -48f, out float gpuAfter);
|
||||
bool hasGpuAfter = _main.Terrain.TrySampleBakedHeight(-96f, -96f, out float gpuAfter);
|
||||
Check(hasGpuAfter, "Expected GPU HeightViewport readback to succeed after crater");
|
||||
if (hasGpuAfter)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue