RustToDust Phase 2: Procedural brush terrain, 4-corner Ymir support, and Godot 4.7.2 Mono client
This commit is contained in:
parent
32b040a59b
commit
215b5ea834
20 changed files with 3486 additions and 56 deletions
766
client/ArenaRenderer.cs
Normal file
766
client/ArenaRenderer.cs
Normal file
|
|
@ -0,0 +1,766 @@
|
|||
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"/>:
|
||||
/// cover ruins, shrinking Safe Circle ring, 6 distinct chassis silhouettes,
|
||||
/// 3 alien spectator tiers + status halos/lock lasers, salvage drops, and weapon tracers.
|
||||
/// </summary>
|
||||
public partial class ArenaRenderer : Node3D
|
||||
{
|
||||
private static readonly Color OlivePaint = Color.FromHtml("#9bb06a");
|
||||
private static readonly Color SignalOrange = Color.FromHtml("#e08a4a");
|
||||
private static readonly Color RivalSteel = Color.FromHtml("#6a584b");
|
||||
private static readonly Color RivalAccent = Color.FromHtml("#b64a32");
|
||||
private static readonly Color TouristGold = Color.FromHtml("#e6b838");
|
||||
private static readonly Color TouristIvory = Color.FromHtml("#f2ead8");
|
||||
private static readonly Color PatronTeal = Color.FromHtml("#2d7a78");
|
||||
private static readonly Color PatronBronze = Color.FromHtml("#a86c36");
|
||||
private static readonly Color ExemplarObsidian = Color.FromHtml("#18181d");
|
||||
private static readonly Color ExemplarCrimson = Color.FromHtml("#c92a2a");
|
||||
private static readonly Color CyanSalvage = Color.FromHtml("#44d9e8");
|
||||
private static readonly Color CoverRust = Color.FromHtml("#4d433b");
|
||||
private static readonly Color BermDark = Color.FromHtml("#2c2723");
|
||||
|
||||
private sealed class ActorVisual
|
||||
{
|
||||
public Node3D Root = null!;
|
||||
public Node3D? AimPivot;
|
||||
public StandardMaterial3D HeatMat = null!;
|
||||
public MeshInstance3D? HaloMesh;
|
||||
public StandardMaterial3D? HaloMat;
|
||||
public MeshInstance3D? LaserMesh;
|
||||
public StandardMaterial3D? LaserMat;
|
||||
public string ChassisId = "";
|
||||
}
|
||||
|
||||
private Node3D _staticGroup = null!;
|
||||
private Node3D _actorsGroup = null!;
|
||||
private Node3D _dropsGroup = null!;
|
||||
private Node3D _tracersGroup = null!;
|
||||
private MeshInstance3D _safeRingMesh = null!;
|
||||
private ImmediateMesh _safeRingImm = null!;
|
||||
|
||||
private readonly Dictionary<int, ActorVisual> _contenderVisuals = new();
|
||||
private readonly Dictionary<int, ActorVisual> _spectatorVisuals = new();
|
||||
private readonly Dictionary<int, Node3D> _dropVisuals = new();
|
||||
private readonly List<MeshInstance3D> _tracerPool = new();
|
||||
|
||||
private StandardMaterial3D _safeRingMat = null!;
|
||||
private StandardMaterial3D _coverMat = null!;
|
||||
private StandardMaterial3D _bermMat = null!;
|
||||
private StandardMaterial3D _humanCrateMat = null!;
|
||||
private StandardMaterial3D _imperialCrateMat = null!;
|
||||
private StandardMaterial3D _cyanBeaconMat = null!;
|
||||
private MatchState? _builtForState;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_staticGroup = new Node3D { Name = "StaticArena" };
|
||||
_actorsGroup = new Node3D { Name = "Actors" };
|
||||
_dropsGroup = new Node3D { Name = "GroundDrops" };
|
||||
_tracersGroup = new Node3D { Name = "Tracers" };
|
||||
AddChild(_staticGroup);
|
||||
AddChild(_actorsGroup);
|
||||
AddChild(_dropsGroup);
|
||||
AddChild(_tracersGroup);
|
||||
|
||||
_coverMat = new StandardMaterial3D { AlbedoColor = CoverRust, Roughness = 0.88f, Metallic = 0.25f };
|
||||
_bermMat = new StandardMaterial3D { AlbedoColor = BermDark, Roughness = 0.94f, Metallic = 0.1f };
|
||||
_humanCrateMat = new StandardMaterial3D { AlbedoColor = OlivePaint, Roughness = 0.65f, Metallic = 0.3f };
|
||||
_imperialCrateMat = new StandardMaterial3D
|
||||
{
|
||||
AlbedoColor = TouristGold,
|
||||
Roughness = 0.35f,
|
||||
Metallic = 0.8f,
|
||||
EmissionEnabled = true,
|
||||
Emission = TouristGold,
|
||||
EmissionEnergyMultiplier = 1.4f
|
||||
};
|
||||
_cyanBeaconMat = new StandardMaterial3D
|
||||
{
|
||||
AlbedoColor = CyanSalvage,
|
||||
EmissionEnabled = true,
|
||||
Emission = CyanSalvage,
|
||||
EmissionEnergyMultiplier = 1.5f,
|
||||
Transparency = BaseMaterial3D.TransparencyEnum.Alpha
|
||||
};
|
||||
_cyanBeaconMat.AlbedoColor = new Color(CyanSalvage.R, CyanSalvage.G, CyanSalvage.B, 0.72f);
|
||||
|
||||
_safeRingImm = new ImmediateMesh();
|
||||
_safeRingMat = new StandardMaterial3D
|
||||
{
|
||||
AlbedoColor = new Color(1.0f, 0.38f, 0.14f, 0.78f),
|
||||
EmissionEnabled = true,
|
||||
Emission = new Color(1.0f, 0.32f, 0.08f),
|
||||
EmissionEnergyMultiplier = 1.6f,
|
||||
Transparency = BaseMaterial3D.TransparencyEnum.Alpha,
|
||||
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
|
||||
CullMode = BaseMaterial3D.CullModeEnum.Disabled
|
||||
};
|
||||
_safeRingMesh = new MeshInstance3D
|
||||
{
|
||||
Name = "SafeRing",
|
||||
Mesh = _safeRingImm,
|
||||
MaterialOverride = _safeRingMat,
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
};
|
||||
AddChild(_safeRingMesh);
|
||||
}
|
||||
|
||||
public void Sync(ArenaSession session, float elapsedSeconds)
|
||||
{
|
||||
var state = session.State;
|
||||
if (!ReferenceEquals(_builtForState, state))
|
||||
{
|
||||
RebuildStaticArena(state);
|
||||
ClearDynamicVisuals();
|
||||
_builtForState = state;
|
||||
}
|
||||
|
||||
UpdateSafeCircleRing(state.Terrain, state.Spectators.SafeRadius);
|
||||
SyncContenders(session);
|
||||
SyncSpectators(session, elapsedSeconds);
|
||||
SyncGroundDrops(state, elapsedSeconds);
|
||||
SyncTracers(state.Tracers);
|
||||
}
|
||||
|
||||
private void RebuildStaticArena(MatchState state)
|
||||
{
|
||||
ClearChildren(_staticGroup);
|
||||
|
||||
for (int i = 0; i < state.ArenaCoverBoxes.Count; i++)
|
||||
{
|
||||
var b = state.ArenaCoverBoxes[i];
|
||||
var mesh = new MeshInstance3D
|
||||
{
|
||||
Mesh = new BoxMesh { Size = new Vector3(b.HalfX * 2f, b.HalfY * 2f, b.HalfZ * 2f) },
|
||||
MaterialOverride = _coverMat,
|
||||
Position = new Vector3(b.X, b.Y, b.Z)
|
||||
};
|
||||
_staticGroup.AddChild(mesh);
|
||||
}
|
||||
|
||||
for (int i = 0; i < state.ArenaBoundaryBoxes.Count; i++)
|
||||
{
|
||||
var b = state.ArenaBoundaryBoxes[i];
|
||||
var mesh = new MeshInstance3D
|
||||
{
|
||||
Mesh = new BoxMesh { Size = new Vector3(b.HalfX * 2f, b.HalfY * 2f, b.HalfZ * 2f) },
|
||||
MaterialOverride = _bermMat,
|
||||
Position = new Vector3(b.X, b.Y, b.Z)
|
||||
};
|
||||
_staticGroup.AddChild(mesh);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearDynamicVisuals()
|
||||
{
|
||||
ClearChildren(_actorsGroup);
|
||||
ClearChildren(_dropsGroup);
|
||||
_contenderVisuals.Clear();
|
||||
_spectatorVisuals.Clear();
|
||||
_dropVisuals.Clear();
|
||||
}
|
||||
|
||||
private void UpdateSafeCircleRing(TerrainField terrain, float safeRadius)
|
||||
{
|
||||
_safeRingImm.ClearSurfaces();
|
||||
_safeRingImm.SurfaceBegin(Mesh.PrimitiveType.Triangles);
|
||||
|
||||
const int segments = 96;
|
||||
const float halfThick = 0.65f;
|
||||
float rInner = MathF.Max(2f, safeRadius - halfThick);
|
||||
float rOuter = safeRadius + halfThick;
|
||||
|
||||
for (int i = 0; i < segments; i++)
|
||||
{
|
||||
float a0 = (i / (float)segments) * MathF.Tau;
|
||||
float a1 = ((i + 1) / (float)segments) * MathF.Tau;
|
||||
float c0 = MathF.Cos(a0), s0 = MathF.Sin(a0);
|
||||
float c1 = MathF.Cos(a1), s1 = MathF.Sin(a1);
|
||||
|
||||
float x0i = c0 * rInner, z0i = s0 * rInner;
|
||||
float x0o = c0 * rOuter, z0o = s0 * rOuter;
|
||||
float x1i = c1 * rInner, z1i = s1 * rInner;
|
||||
float x1o = c1 * rOuter, z1o = s1 * rOuter;
|
||||
|
||||
float y0 = terrain.SampleHeight(c0 * safeRadius, s0 * safeRadius) + 0.42f;
|
||||
float y1 = terrain.SampleHeight(c1 * safeRadius, s1 * safeRadius) + 0.42f;
|
||||
|
||||
var p0i = new Vector3(x0i, y0, z0i);
|
||||
var p0o = new Vector3(x0o, y0, z0o);
|
||||
var p1i = new Vector3(x1i, y1, z1i);
|
||||
var p1o = new Vector3(x1o, y1, z1o);
|
||||
|
||||
_safeRingImm.SurfaceAddVertex(p0i);
|
||||
_safeRingImm.SurfaceAddVertex(p0o);
|
||||
_safeRingImm.SurfaceAddVertex(p1o);
|
||||
|
||||
_safeRingImm.SurfaceAddVertex(p0i);
|
||||
_safeRingImm.SurfaceAddVertex(p1o);
|
||||
_safeRingImm.SurfaceAddVertex(p1i);
|
||||
}
|
||||
|
||||
_safeRingImm.SurfaceEnd();
|
||||
}
|
||||
|
||||
private void SyncContenders(ArenaSession session)
|
||||
{
|
||||
var view = session.World.View;
|
||||
var contenders = session.State.Contenders;
|
||||
|
||||
for (int i = 0; i < contenders.Count; i++)
|
||||
{
|
||||
var c = contenders[i];
|
||||
if (!c.Alive)
|
||||
{
|
||||
if (_contenderVisuals.TryGetValue(c.Id, out var deadVis))
|
||||
{
|
||||
deadVis.Root.Visible = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_contenderVisuals.TryGetValue(c.Id, out var vis) || vis.ChassisId != c.Grid.Spec.Id)
|
||||
{
|
||||
if (vis is not null)
|
||||
{
|
||||
vis.Root.QueueFree();
|
||||
}
|
||||
vis = BuildChassisVisual(
|
||||
c.Grid.Spec.Id,
|
||||
primary: c.IsPlayer ? OlivePaint : RivalSteel,
|
||||
accent: c.IsPlayer ? SignalOrange : RivalAccent,
|
||||
isSpectator: false,
|
||||
tier: SpectatorTier.Patron);
|
||||
_actorsGroup.AddChild(vis.Root);
|
||||
_contenderVisuals[c.Id] = vis;
|
||||
}
|
||||
|
||||
vis.Root.Visible = true;
|
||||
var body = session.GetContenderBody(c.Id);
|
||||
if (body is { } h)
|
||||
{
|
||||
int lane = h.Lane;
|
||||
var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
vis.Root.Transform = new Transform3D(new Basis(q), pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
vis.Root.Position = new Vector3(c.X, c.Y, c.Z);
|
||||
vis.Root.Rotation = new Vector3(0f, c.Yaw, 0f);
|
||||
}
|
||||
|
||||
if (vis.AimPivot is not null)
|
||||
{
|
||||
float aimYawWorld = MathF.Atan2(c.AimX - c.X, c.AimZ - c.Z);
|
||||
float relYaw = MatchRules.NormalizeAngle(aimYawWorld - c.Yaw);
|
||||
vis.AimPivot.Rotation = new Vector3(0f, relYaw, 0f);
|
||||
}
|
||||
|
||||
UpdateHeatGlow(vis.HeatMat, c.Grid);
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncSpectators(ArenaSession session, float elapsedSeconds)
|
||||
{
|
||||
var view = session.World.View;
|
||||
var specs = session.State.Spectators.Spectators;
|
||||
|
||||
for (int i = 0; i < specs.Count; i++)
|
||||
{
|
||||
var s = specs[i];
|
||||
if (!s.Alive)
|
||||
{
|
||||
if (_spectatorVisuals.TryGetValue(s.Id, out var deadVis))
|
||||
{
|
||||
deadVis.Root.Visible = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_spectatorVisuals.TryGetValue(s.Id, out var vis))
|
||||
{
|
||||
var (primary, accent) = s.Tier switch
|
||||
{
|
||||
SpectatorTier.Tourist => (TouristGold, TouristIvory),
|
||||
SpectatorTier.Patron => (PatronTeal, PatronBronze),
|
||||
_ => (ExemplarObsidian, ExemplarCrimson)
|
||||
};
|
||||
vis = BuildChassisVisual(s.Grid.Spec.Id, primary, accent, isSpectator: true, tier: s.Tier);
|
||||
_actorsGroup.AddChild(vis.Root);
|
||||
_spectatorVisuals[s.Id] = vis;
|
||||
}
|
||||
|
||||
vis.Root.Visible = true;
|
||||
var body = session.GetSpectatorBody(s.Id);
|
||||
Vector3 specPos;
|
||||
if (body is { } h)
|
||||
{
|
||||
int lane = h.Lane;
|
||||
specPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
vis.Root.Transform = new Transform3D(new Basis(q), specPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
specPos = new Vector3(s.X, s.Y, s.Z);
|
||||
vis.Root.Position = specPos;
|
||||
vis.Root.Rotation = new Vector3(0f, s.Yaw, 0f);
|
||||
}
|
||||
|
||||
// Status halo
|
||||
if (vis.HaloMat is not null && vis.HaloMesh is not null)
|
||||
{
|
||||
if (s.Stance == SpectatorStance.Neutral)
|
||||
{
|
||||
vis.HaloMat.AlbedoColor = new Color(0.88f, 0.65f, 0.25f, 0.45f);
|
||||
vis.HaloMat.Emission = new Color(0.88f, 0.65f, 0.25f);
|
||||
vis.HaloMat.EmissionEnergyMultiplier = 0.6f;
|
||||
}
|
||||
else if (s.Stance == SpectatorStance.Cleared)
|
||||
{
|
||||
vis.HaloMat.AlbedoColor = new Color(1.0f, 0.22f, 0.18f, 0.9f);
|
||||
vis.HaloMat.Emission = new Color(1.0f, 0.2f, 0.15f);
|
||||
vis.HaloMat.EmissionEnergyMultiplier = 2.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
float pulse = 1.6f + 1.2f * MathF.Sin(elapsedSeconds * 10f);
|
||||
vis.HaloMat.AlbedoColor = new Color(1.0f, 0.1f, 0.1f, 0.95f);
|
||||
vis.HaloMat.Emission = new Color(1.0f, 0.08f, 0.08f);
|
||||
vis.HaloMat.EmissionEnergyMultiplier = pulse;
|
||||
}
|
||||
}
|
||||
|
||||
// Lock-on laser beam when Cleared or Provoked
|
||||
if (vis.LaserMesh is not null)
|
||||
{
|
||||
ContenderState? target = s.TargetContenderId.HasValue &&
|
||||
s.TargetContenderId.Value >= 0 &&
|
||||
s.TargetContenderId.Value < session.State.Contenders.Count
|
||||
? session.State.Contenders[s.TargetContenderId.Value]
|
||||
: null;
|
||||
|
||||
if (s.Stance != SpectatorStance.Neutral && 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);
|
||||
float dist = start.DistanceTo(end);
|
||||
if (dist > 0.5f)
|
||||
{
|
||||
vis.LaserMesh.Visible = true;
|
||||
vis.LaserMesh.GlobalPosition = (start + end) * 0.5f;
|
||||
vis.LaserMesh.LookAt(end, Vector3.Up);
|
||||
vis.LaserMesh.Scale = new Vector3(1f, 1f, dist);
|
||||
}
|
||||
else
|
||||
{
|
||||
vis.LaserMesh.Visible = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vis.LaserMesh.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateHeatGlow(vis.HeatMat, s.Grid);
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncGroundDrops(MatchState state, float elapsedSeconds)
|
||||
{
|
||||
for (int i = 0; i < state.GroundDrops.Count; i++)
|
||||
{
|
||||
var d = state.GroundDrops[i];
|
||||
if (d.PickedUp)
|
||||
{
|
||||
if (_dropVisuals.TryGetValue(d.Id, out var pickedNode))
|
||||
{
|
||||
pickedNode.Visible = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_dropVisuals.TryGetValue(d.Id, out var node))
|
||||
{
|
||||
node = BuildGroundDropVisual(d, state.Terrain);
|
||||
_dropsGroup.AddChild(node);
|
||||
_dropVisuals[d.Id] = node;
|
||||
}
|
||||
|
||||
node.Visible = true;
|
||||
float bob = d.Module is not null ? MathF.Sin(elapsedSeconds * 2.5f + d.Id) * 0.12f : 0f;
|
||||
float baseY = state.Terrain.SampleHeight(d.X, d.Z);
|
||||
node.Position = new Vector3(d.X, baseY + bob, d.Z);
|
||||
if (d.Module is not null)
|
||||
{
|
||||
node.Rotation = new Vector3(0f, elapsedSeconds * 0.9f + d.Id, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncTracers(IReadOnlyList<TracerEvent> tracers)
|
||||
{
|
||||
while (_tracerPool.Count < tracers.Count)
|
||||
{
|
||||
var mat = new StandardMaterial3D
|
||||
{
|
||||
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
|
||||
EmissionEnabled = true
|
||||
};
|
||||
var mesh = new MeshInstance3D
|
||||
{
|
||||
Mesh = new BoxMesh { Size = new Vector3(0.14f, 0.14f, 1.0f) },
|
||||
MaterialOverride = mat,
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
};
|
||||
_tracersGroup.AddChild(mesh);
|
||||
_tracerPool.Add(mesh);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _tracerPool.Count; i++)
|
||||
{
|
||||
var m = _tracerPool[i];
|
||||
if (i >= tracers.Count)
|
||||
{
|
||||
m.Visible = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
var t = tracers[i];
|
||||
var start = new Vector3(t.StartX, t.StartY, t.StartZ);
|
||||
var end = new Vector3(t.EndX, t.EndY, t.EndZ);
|
||||
float dist = start.DistanceTo(end);
|
||||
if (dist < 0.1f)
|
||||
{
|
||||
m.Visible = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
m.Visible = true;
|
||||
m.Position = (start + end) * 0.5f;
|
||||
Vector3 dir = (end - start).Normalized();
|
||||
Vector3 up = MathF.Abs(dir.Dot(Vector3.Up)) > 0.95f ? Vector3.Right : Vector3.Up;
|
||||
m.LookAt(end, up);
|
||||
m.Scale = new Vector3(1f, 1f, dist);
|
||||
|
||||
var col = new Color(
|
||||
((t.ColorRgba >> 24) & 0xFF) / 255f,
|
||||
((t.ColorRgba >> 16) & 0xFF) / 255f,
|
||||
((t.ColorRgba >> 8) & 0xFF) / 255f,
|
||||
1f);
|
||||
if (m.MaterialOverride is StandardMaterial3D sm)
|
||||
{
|
||||
sm.AlbedoColor = col;
|
||||
sm.Emission = col;
|
||||
sm.EmissionEnergyMultiplier = 2.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Node3D BuildGroundDropVisual(GroundDrop drop, TerrainField terrain)
|
||||
{
|
||||
var root = new Node3D { Name = $"Drop_{drop.Id}" };
|
||||
if (drop.Module is { } mod)
|
||||
{
|
||||
var mat = mod.IsImperial ? _imperialCrateMat : _humanCrateMat;
|
||||
root.AddChild(new MeshInstance3D
|
||||
{
|
||||
Mesh = new BoxMesh { Size = new Vector3(1.1f, 0.8f, 1.1f) },
|
||||
MaterialOverride = mat,
|
||||
Position = new Vector3(0f, 0.5f, 0f)
|
||||
});
|
||||
if (mod.IsImperial)
|
||||
{
|
||||
root.AddChild(new MeshInstance3D
|
||||
{
|
||||
Mesh = new CylinderMesh { TopRadius = 0.08f, BottomRadius = 0.25f, Height = 5.5f, RadialSegments = 8 },
|
||||
MaterialOverride = _imperialCrateMat,
|
||||
Position = new Vector3(0f, 3.0f, 0f)
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (drop.Chassis is { } ch)
|
||||
{
|
||||
var hull = BuildChassisVisual(ch.Id, new Color(0.32f, 0.35f, 0.36f), CyanSalvage, isSpectator: false, tier: SpectatorTier.Patron);
|
||||
hull.Root.Position = new Vector3(0f, ch.HalfHeight * 0.85f, 0f);
|
||||
hull.Root.Scale = new Vector3(0.85f, 0.85f, 0.85f);
|
||||
root.AddChild(hull.Root);
|
||||
|
||||
var ring = new MeshInstance3D
|
||||
{
|
||||
Mesh = new CylinderMesh { TopRadius = 2.6f, BottomRadius = 2.8f, Height = 0.14f, RadialSegments = 18 },
|
||||
MaterialOverride = _cyanBeaconMat,
|
||||
Position = new Vector3(0f, 0.15f, 0f)
|
||||
};
|
||||
root.AddChild(ring);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
private ActorVisual BuildChassisVisual(
|
||||
string chassisId,
|
||||
Color primary,
|
||||
Color accent,
|
||||
bool isSpectator,
|
||||
SpectatorTier tier)
|
||||
{
|
||||
var root = new Node3D { Name = $"Chassis_{chassisId}" };
|
||||
var bodyMat = new StandardMaterial3D { AlbedoColor = primary, Roughness = 0.55f, Metallic = 0.45f };
|
||||
var accentMat = new StandardMaterial3D { AlbedoColor = accent, Roughness = 0.45f, Metallic = 0.55f };
|
||||
var darkMat = new StandardMaterial3D { AlbedoColor = new Color(0.14f, 0.15f, 0.14f), Roughness = 0.8f, Metallic = 0.35f };
|
||||
var heatMat = new StandardMaterial3D
|
||||
{
|
||||
AlbedoColor = accent,
|
||||
Roughness = 0.4f,
|
||||
Metallic = 0.6f,
|
||||
EmissionEnabled = true,
|
||||
Emission = new Color(1.0f, 0.35f, 0.1f),
|
||||
EmissionEnergyMultiplier = 0.0f
|
||||
};
|
||||
|
||||
var aimPivot = new Node3D { Name = "AimPivot" };
|
||||
root.AddChild(aimPivot);
|
||||
|
||||
switch (chassisId)
|
||||
{
|
||||
case "buggy":
|
||||
BuildBuggyParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
|
||||
break;
|
||||
case "technical":
|
||||
BuildTechnicalParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
|
||||
break;
|
||||
case "tank":
|
||||
BuildTankParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
|
||||
break;
|
||||
case "manticore":
|
||||
BuildManticoreParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
|
||||
break;
|
||||
case "raptor":
|
||||
case "exemplar_frame":
|
||||
BuildRaptorParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat, isExemplar: chassisId == "exemplar_frame");
|
||||
break;
|
||||
case "paladin":
|
||||
BuildPaladinParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat, isTourist: isSpectator && tier == SpectatorTier.Tourist);
|
||||
break;
|
||||
default:
|
||||
BuildBuggyParts(root, aimPivot, bodyMat, accentMat, darkMat, heatMat);
|
||||
break;
|
||||
}
|
||||
|
||||
var vis = new ActorVisual
|
||||
{
|
||||
Root = root,
|
||||
AimPivot = aimPivot,
|
||||
HeatMat = heatMat,
|
||||
ChassisId = chassisId
|
||||
};
|
||||
|
||||
if (isSpectator)
|
||||
{
|
||||
var haloMat = new StandardMaterial3D
|
||||
{
|
||||
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
|
||||
EmissionEnabled = true,
|
||||
Transparency = BaseMaterial3D.TransparencyEnum.Alpha
|
||||
};
|
||||
var halo = new MeshInstance3D
|
||||
{
|
||||
Mesh = new CylinderMesh { TopRadius = 2.4f, BottomRadius = 2.4f, Height = 0.1f, RadialSegments = 16 },
|
||||
MaterialOverride = haloMat,
|
||||
Position = new Vector3(0f, 3.3f, 0f),
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
};
|
||||
root.AddChild(halo);
|
||||
vis.HaloMesh = halo;
|
||||
vis.HaloMat = haloMat;
|
||||
|
||||
var laserMat = new StandardMaterial3D
|
||||
{
|
||||
AlbedoColor = new Color(1f, 0.15f, 0.15f, 0.85f),
|
||||
EmissionEnabled = true,
|
||||
Emission = new Color(1f, 0.12f, 0.1f),
|
||||
EmissionEnergyMultiplier = 2.2f,
|
||||
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
|
||||
Transparency = BaseMaterial3D.TransparencyEnum.Alpha
|
||||
};
|
||||
var laser = new MeshInstance3D
|
||||
{
|
||||
Mesh = new BoxMesh { Size = new Vector3(0.08f, 0.08f, 1.0f) },
|
||||
MaterialOverride = laserMat,
|
||||
Visible = false,
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
};
|
||||
_actorsGroup.AddChild(laser);
|
||||
vis.LaserMesh = laser;
|
||||
vis.LaserMat = laserMat;
|
||||
}
|
||||
|
||||
return vis;
|
||||
}
|
||||
|
||||
private static void BuildBuggyParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat)
|
||||
{
|
||||
AddBox(root, new Vector3(1.5f, 0.45f, 2.9f), new Vector3(0f, -0.25f, 0f), bodyMat);
|
||||
AddBox(root, new Vector3(1.1f, 0.45f, 1.3f), new Vector3(0f, 0.25f, -0.2f), accentMat); // rollcage canopy
|
||||
AddBox(root, new Vector3(0.8f, 0.32f, 0.5f), new Vector3(0f, 0.15f, -1.35f), heatMat); // rear radiator
|
||||
// 4 wheels
|
||||
AddWheel(root, new Vector3(-0.98f, -0.45f, 1.05f), 0.36f, 0.32f, darkMat);
|
||||
AddWheel(root, new Vector3( 0.98f, -0.45f, 1.05f), 0.36f, 0.32f, darkMat);
|
||||
AddWheel(root, new Vector3(-0.98f, -0.45f, -1.05f), 0.36f, 0.32f, darkMat);
|
||||
AddWheel(root, new Vector3( 0.98f, -0.45f, -1.05f), 0.36f, 0.32f, darkMat);
|
||||
// Roof MG turret
|
||||
aimPivot.Position = new Vector3(0f, 0.6f, 0f);
|
||||
AddBox(aimPivot, new Vector3(0.45f, 0.26f, 0.55f), Vector3.Zero, darkMat);
|
||||
AddBox(aimPivot, new Vector3(0.12f, 0.12f, 1.25f), new Vector3(0f, 0.04f, 0.65f), accentMat);
|
||||
}
|
||||
|
||||
private static void BuildTechnicalParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat)
|
||||
{
|
||||
AddBox(root, new Vector3(2.0f, 0.55f, 4.2f), new Vector3(0f, -0.25f, 0f), bodyMat);
|
||||
AddBox(root, new Vector3(1.85f, 0.72f, 1.5f), new Vector3(0f, 0.35f, 0.85f), accentMat); // armored cab
|
||||
AddBox(root, new Vector3(1.9f, 0.38f, 2.0f), new Vector3(0f, 0.20f, -0.95f), bodyMat); // bed walls
|
||||
AddBox(root, new Vector3(1.2f, 0.30f, 0.4f), new Vector3(0f, 0.20f, -2.0f), heatMat); // tail radiator
|
||||
AddWheel(root, new Vector3(-1.12f, -0.55f, 1.45f), 0.44f, 0.36f, darkMat);
|
||||
AddWheel(root, new Vector3( 1.12f, -0.55f, 1.45f), 0.44f, 0.36f, darkMat);
|
||||
AddWheel(root, new Vector3(-1.12f, -0.55f, -1.45f), 0.44f, 0.36f, darkMat);
|
||||
AddWheel(root, new Vector3( 1.12f, -0.55f, -1.45f), 0.44f, 0.36f, darkMat);
|
||||
aimPivot.Position = new Vector3(0f, 0.72f, -0.8f);
|
||||
AddBox(aimPivot, new Vector3(0.65f, 0.4f, 0.7f), Vector3.Zero, darkMat);
|
||||
AddBox(aimPivot, new Vector3(0.14f, 0.14f, 1.7f), new Vector3(-0.18f, 0.08f, 0.8f), accentMat);
|
||||
AddBox(aimPivot, new Vector3(0.14f, 0.14f, 1.7f), new Vector3( 0.18f, 0.08f, 0.8f), accentMat);
|
||||
}
|
||||
|
||||
private static void BuildTankParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat)
|
||||
{
|
||||
AddBox(root, new Vector3(2.4f, 0.85f, 4.6f), new Vector3(0f, -0.2f, 0f), bodyMat);
|
||||
AddBox(root, new Vector3(0.55f, 0.72f, 4.9f), new Vector3(-1.32f, -0.45f, 0f), darkMat); // left track pod
|
||||
AddBox(root, new Vector3(0.55f, 0.72f, 4.9f), new Vector3( 1.32f, -0.45f, 0f), darkMat); // right track pod
|
||||
AddBox(root, new Vector3(1.6f, 0.35f, 0.7f), new Vector3(0f, 0.25f, -1.7f), heatMat); // rear engine deck
|
||||
aimPivot.Position = new Vector3(0f, 0.65f, 0.2f);
|
||||
AddBox(aimPivot, new Vector3(1.75f, 0.68f, 2.2f), Vector3.Zero, accentMat);
|
||||
AddBox(aimPivot, new Vector3(0.24f, 0.24f, 3.0f), new Vector3(0f, 0.05f, 2.0f), darkMat); // main cannon
|
||||
}
|
||||
|
||||
private static void BuildManticoreParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat)
|
||||
{
|
||||
// Wide dorsal carapace + 4 splayed articulated legs + radiator flanks
|
||||
AddBox(root, new Vector3(2.2f, 0.75f, 2.8f), new Vector3(0f, 0.25f, 0f), bodyMat);
|
||||
AddBox(root, new Vector3(1.3f, 0.55f, 1.2f), new Vector3(0f, 0.45f, 1.2f), accentMat); // chin armor
|
||||
AddBox(root, new Vector3(0.45f, 0.45f, 1.4f), new Vector3(-1.25f, 0.45f, -0.4f), heatMat);
|
||||
AddBox(root, new Vector3(0.45f, 0.45f, 1.4f), new Vector3( 1.25f, 0.45f, -0.4f), heatMat);
|
||||
|
||||
Vector3[] legAnchors =
|
||||
{
|
||||
new(-1.35f, -0.35f, 1.25f),
|
||||
new( 1.35f, -0.35f, 1.25f),
|
||||
new(-1.35f, -0.35f, -1.25f),
|
||||
new( 1.35f, -0.35f, -1.25f)
|
||||
};
|
||||
for (int i = 0; i < legAnchors.Length; i++)
|
||||
{
|
||||
AddBox(root, new Vector3(0.42f, 1.35f, 0.42f), legAnchors[i], darkMat);
|
||||
AddBox(root, new Vector3(0.68f, 0.26f, 0.68f), legAnchors[i] + new Vector3(0f, -0.7f, 0f), accentMat);
|
||||
}
|
||||
|
||||
aimPivot.Position = new Vector3(0f, 0.8f, 0.2f);
|
||||
AddBox(aimPivot, new Vector3(0.9f, 0.38f, 1.0f), Vector3.Zero, darkMat);
|
||||
AddBox(aimPivot, new Vector3(0.18f, 0.18f, 1.7f), new Vector3(-0.6f, 0f, 0.75f), accentMat);
|
||||
AddBox(aimPivot, new Vector3(0.18f, 0.18f, 1.7f), new Vector3( 0.6f, 0f, 0.75f), accentMat);
|
||||
}
|
||||
|
||||
private static void BuildRaptorParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat, bool isExemplar)
|
||||
{
|
||||
float scale = isExemplar ? 0.78f : 1.0f;
|
||||
// Tall bipedal legs
|
||||
AddBox(root, new Vector3(0.42f * scale, 1.85f * scale, 0.52f * scale), new Vector3(-0.62f * scale, -0.8f * scale, 0f), darkMat);
|
||||
AddBox(root, new Vector3(0.42f * scale, 1.85f * scale, 0.52f * scale), new Vector3( 0.62f * scale, -0.8f * scale, 0f), darkMat);
|
||||
// Angled torso + head sensor
|
||||
AddBox(root, new Vector3(1.55f * scale, 1.15f * scale, 1.25f * scale), new Vector3(0f, 0.45f * scale, 0f), bodyMat);
|
||||
AddBox(root, new Vector3(0.65f * scale, 0.45f * scale, 0.85f * scale), new Vector3(0f, 1.25f * scale, 0.25f * scale), accentMat);
|
||||
AddBox(root, new Vector3(0.95f * scale, 0.55f * scale, 0.35f * scale), new Vector3(0f, 0.6f * scale, -0.75f * scale), heatMat);
|
||||
|
||||
aimPivot.Position = new Vector3(0f, 0.5f * scale, 0f);
|
||||
AddBox(aimPivot, new Vector3(0.32f * scale, 0.35f * scale, 1.55f * scale), new Vector3(-1.05f * scale, 0f, 0.55f * scale), accentMat);
|
||||
AddBox(aimPivot, new Vector3(0.32f * scale, 0.35f * scale, 1.55f * scale), new Vector3( 1.05f * scale, 0f, 0.55f * scale), accentMat);
|
||||
}
|
||||
|
||||
private static void BuildPaladinParts(Node3D root, Node3D aimPivot, Material bodyMat, Material accentMat, Material darkMat, Material heatMat, bool isTourist)
|
||||
{
|
||||
// Broad heavy bipedal silhouette + shoulder pods + chest reactor
|
||||
AddBox(root, new Vector3(0.68f, 2.0f, 0.82f), new Vector3(-0.85f, -1.1f, 0f), darkMat);
|
||||
AddBox(root, new Vector3(0.68f, 2.0f, 0.82f), new Vector3( 0.85f, -1.1f, 0f), darkMat);
|
||||
AddBox(root, new Vector3(2.25f, 1.65f, 1.65f), new Vector3(0f, 0.45f, 0f), bodyMat);
|
||||
AddBox(root, new Vector3(0.85f, 0.75f, 0.35f), new Vector3(0f, 0.55f, 0.85f), heatMat); // chest reactor
|
||||
// Twin shoulder pods
|
||||
AddBox(root, new Vector3(0.75f, 0.72f, 1.15f), new Vector3(-1.35f, 1.45f, 0f), accentMat);
|
||||
AddBox(root, new Vector3(0.75f, 0.72f, 1.15f), new Vector3( 1.35f, 1.45f, 0f), accentMat);
|
||||
|
||||
if (isTourist)
|
||||
{
|
||||
// Gaudy gilded luxury dome on top so Tourists are unmistakable loot pinatas
|
||||
var dome = new MeshInstance3D
|
||||
{
|
||||
Mesh = new CylinderMesh { TopRadius = 0.5f, BottomRadius = 0.95f, Height = 0.75f, RadialSegments = 12 },
|
||||
MaterialOverride = bodyMat,
|
||||
Position = new Vector3(0f, 1.65f, 0f)
|
||||
};
|
||||
root.AddChild(dome);
|
||||
}
|
||||
|
||||
aimPivot.Position = new Vector3(0f, 0.45f, 0f);
|
||||
AddBox(aimPivot, new Vector3(0.45f, 0.48f, 2.0f), new Vector3(-1.45f, 0f, 0.65f), accentMat);
|
||||
AddBox(aimPivot, new Vector3(0.45f, 0.48f, 2.0f), new Vector3( 1.45f, 0f, 0.65f), accentMat);
|
||||
}
|
||||
|
||||
private static void AddBox(Node3D parent, Vector3 size, Vector3 pos, Material mat)
|
||||
{
|
||||
parent.AddChild(new MeshInstance3D
|
||||
{
|
||||
Mesh = new BoxMesh { Size = size },
|
||||
MaterialOverride = mat,
|
||||
Position = pos
|
||||
});
|
||||
}
|
||||
|
||||
private static void AddWheel(Node3D parent, Vector3 pos, float radius, float width, Material mat)
|
||||
{
|
||||
parent.AddChild(new MeshInstance3D
|
||||
{
|
||||
Mesh = new CylinderMesh { TopRadius = radius, BottomRadius = radius, Height = width, RadialSegments = 12 },
|
||||
MaterialOverride = mat,
|
||||
Position = pos,
|
||||
Rotation = new Vector3(0f, 0f, MathF.PI * 0.5f)
|
||||
});
|
||||
}
|
||||
|
||||
private static void UpdateHeatGlow(StandardMaterial3D heatMat, ChassisGrid grid)
|
||||
{
|
||||
float maxTemp = ChassisGrid.AmbientTemp;
|
||||
for (int i = 0; i < grid.Mounted.Count; i++)
|
||||
{
|
||||
maxTemp = MathF.Max(maxTemp, grid.Mounted[i].CurrentTemp);
|
||||
}
|
||||
float glow = Math.Clamp((maxTemp - 65f) / 110f, 0f, 1f);
|
||||
heatMat.EmissionEnergyMultiplier = glow * 2.6f;
|
||||
}
|
||||
|
||||
private static void ClearChildren(Node parent)
|
||||
{
|
||||
for (int i = parent.GetChildCount() - 1; i >= 0; i--)
|
||||
{
|
||||
var child = parent.GetChild(i);
|
||||
parent.RemoveChild(child);
|
||||
child.QueueFree();
|
||||
}
|
||||
}
|
||||
}
|
||||
761
client/Hud.cs
Normal file
761
client/Hud.cs
Normal file
|
|
@ -0,0 +1,761 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Rust to Dust industrial HUD:
|
||||
/// - Top-Left: Chassis badge (DORSAL/CORONAL), Core HP, Speed, Contenders Alive, Safe Circle status, Pickup prompt.
|
||||
/// - Top-Right: Tactical Radar (Safe Circle, RadarSignature-scaled Spectator Wall, lock lines, contenders, salvage).
|
||||
/// - Bottom-Left: Live clickable Aetheria Hardpoint & Heat Schematic + Cargo Salvage Rack (Tab expands Garage details).
|
||||
/// - Bottom-Center: Imperial Broadcast Chyron (Weksa commentary).
|
||||
/// </summary>
|
||||
public partial class Hud : CanvasLayer
|
||||
{
|
||||
private static readonly Color BgDark = Color.FromHtml("#131613");
|
||||
private static readonly Color BgInner = Color.FromHtml("#1b1f1b");
|
||||
private static readonly Color BorderCol = Color.FromHtml("#3e4638");
|
||||
private static readonly Color OliveCol = Color.FromHtml("#9bb06a");
|
||||
private static readonly Color OrangeCol = Color.FromHtml("#e08a4a");
|
||||
private static readonly Color TextLight = Color.FromHtml("#e4dfd2");
|
||||
private static readonly Color TextMuted = Color.FromHtml("#989487");
|
||||
private static readonly Color CyanCol = Color.FromHtml("#44d9e8");
|
||||
private static readonly Color GoldCol = Color.FromHtml("#e6b838");
|
||||
private static readonly Color RedCol = Color.FromHtml("#d93829");
|
||||
|
||||
private readonly Func<ArenaSession?> _getSession;
|
||||
private readonly Action<int, string> _onEquipCargo;
|
||||
|
||||
private Label _chassisHeader = null!;
|
||||
private Label _planeBadge = null!;
|
||||
private ProgressBar _coreHpBar = null!;
|
||||
private Label _coreHpLabel = null!;
|
||||
private Label _statsLabel = null!;
|
||||
private Label _safeLabel = null!;
|
||||
private Label _promptLabel = null!;
|
||||
private Label _controlsHint = null!;
|
||||
|
||||
private RadarWidget _radar = null!;
|
||||
private SchematicPanel _schematic = null!;
|
||||
private VBoxContainer _cargoList = null!;
|
||||
private Label _cargoHeader = null!;
|
||||
private Label _garageDetails = null!;
|
||||
private PanelContainer _bottomLeftPanel = null!;
|
||||
|
||||
private VBoxContainer _chyronBox = null!;
|
||||
private PanelContainer _outcomeBanner = null!;
|
||||
private Label _outcomeLabel = null!;
|
||||
|
||||
private int _selectedCargoIndex = -1;
|
||||
private int _lastCargoHash = -1;
|
||||
private bool _garageExpanded;
|
||||
|
||||
public Hud(Func<ArenaSession?> getSession, Action<int, string> onEquipCargo)
|
||||
{
|
||||
_getSession = getSession;
|
||||
_onEquipCargo = onEquipCargo;
|
||||
Layer = 10;
|
||||
}
|
||||
|
||||
public bool GarageExpanded => _garageExpanded;
|
||||
|
||||
public void ToggleGarage()
|
||||
{
|
||||
_garageExpanded = !_garageExpanded;
|
||||
_garageDetails.Visible = _garageExpanded;
|
||||
_schematic.CustomMinimumSize = _garageExpanded ? new Vector2(236f, 250f) : new Vector2(180f, 190f);
|
||||
_schematic.QueueRedraw();
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
BuildTopLeft();
|
||||
BuildTopRightRadar();
|
||||
BuildBottomLeftSchematic();
|
||||
BuildBottomCenterChyron();
|
||||
BuildOutcomeBanner();
|
||||
}
|
||||
|
||||
public bool IsPointerOverInteractiveHud(Vector2 screenPos)
|
||||
{
|
||||
return _bottomLeftPanel.GetGlobalRect().HasPoint(screenPos);
|
||||
}
|
||||
|
||||
public void Sync(ArenaSession session)
|
||||
{
|
||||
var state = session.State;
|
||||
var player = state.Player;
|
||||
|
||||
// Top-Left Status
|
||||
_chassisHeader.Text = player.Grid.Spec.Name.ToUpperInvariant();
|
||||
bool isCoronal = player.Grid.Spec.Plane == GridPlane.Coronal;
|
||||
_planeBadge.Text = isCoronal ? "CORONAL" : "DORSAL";
|
||||
_planeBadge.Modulate = isCoronal ? CyanCol : OliveCol;
|
||||
|
||||
_coreHpBar.MaxValue = Math.Max(1f, player.Grid.MaxCoreHp);
|
||||
_coreHpBar.Value = Math.Max(0f, player.Grid.CoreHp);
|
||||
_coreHpLabel.Text = $"CORE {player.Grid.CoreHp:F0} / {player.Grid.MaxCoreHp:F0}";
|
||||
|
||||
int aliveCount = 0;
|
||||
for (int i = 0; i < state.Contenders.Count; i++)
|
||||
{
|
||||
if (state.Contenders[i].Alive) aliveCount++;
|
||||
}
|
||||
_statsLabel.Text = $"SPD {player.Speed:F1} m/s | ALIVE {aliveCount} / {state.Contenders.Count} | KILLS {player.Kills}";
|
||||
|
||||
float distCenter = MathF.Sqrt(player.X * player.X + player.Z * player.Z);
|
||||
float outside = distCenter - state.Spectators.SafeRadius;
|
||||
int cleared = state.Spectators.CountClearedFor(player.Id);
|
||||
int provoked = state.Spectators.CountProvokedFor(player.Id);
|
||||
|
||||
if (outside <= 0f)
|
||||
{
|
||||
_safeLabel.Text = $"RING SAFE ({-outside:F0}m margin)" + (provoked > 0 ? $" • {provoked} PROVOKED!" : "");
|
||||
_safeLabel.Modulate = provoked > 0 ? OrangeCol : OliveCol;
|
||||
}
|
||||
else
|
||||
{
|
||||
_safeLabel.Text = $"OUTSIDE +{outside:F0}m — {cleared} CLEARED" + (provoked > 0 ? $" / {provoked} PROVOKED!" : "!");
|
||||
_safeLabel.Modulate = RedCol;
|
||||
}
|
||||
|
||||
_promptLabel.Text = BuildInteractionPrompt(state, player);
|
||||
_promptLabel.Visible = !string.IsNullOrEmpty(_promptLabel.Text);
|
||||
|
||||
// Radar
|
||||
_radar.SetState(state);
|
||||
_radar.QueueRedraw();
|
||||
|
||||
// Schematic + Cargo
|
||||
_schematic.SetGrid(player.Grid, _selectedCargoIndex);
|
||||
_schematic.QueueRedraw();
|
||||
SyncCargoButtons(player.Grid);
|
||||
|
||||
if (_garageExpanded)
|
||||
{
|
||||
_garageDetails.Text = BuildGarageDetails(player.Grid);
|
||||
}
|
||||
|
||||
// Broadcast Chyron
|
||||
SyncBroadcastChyron(state.Broadcast.Lines);
|
||||
|
||||
// Outcome
|
||||
if (state.Phase == MatchPhase.Victory)
|
||||
{
|
||||
_outcomeBanner.Visible = true;
|
||||
_outcomeLabel.Text = "VICTORY — LAST RIG STANDING\n[R] New Drop";
|
||||
_outcomeLabel.Modulate = OliveCol;
|
||||
}
|
||||
else if (state.Phase == MatchPhase.Defeat)
|
||||
{
|
||||
_outcomeBanner.Visible = true;
|
||||
_outcomeLabel.Text = "CHASSIS DESTROYED\n[R] Redeploy";
|
||||
_outcomeLabel.Modulate = RedCol;
|
||||
}
|
||||
else
|
||||
{
|
||||
_outcomeBanner.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildTopLeft()
|
||||
{
|
||||
var panel = CreateStyledPanel();
|
||||
panel.AnchorLeft = 0f;
|
||||
panel.AnchorTop = 0f;
|
||||
panel.OffsetLeft = 14f;
|
||||
panel.OffsetTop = 14f;
|
||||
panel.CustomMinimumSize = new Vector2(360f, 0f);
|
||||
AddChild(panel);
|
||||
|
||||
var vbox = new VBoxContainer { Theme = null };
|
||||
vbox.AddThemeConstantOverride("separation", 5);
|
||||
panel.AddChild(vbox);
|
||||
|
||||
var headRow = new HBoxContainer();
|
||||
headRow.AddThemeConstantOverride("separation", 10);
|
||||
vbox.AddChild(headRow);
|
||||
|
||||
_chassisHeader = new Label { Text = "DUNE BUGGY", SizeFlagsHorizontal = Control.SizeFlags.ExpandFill };
|
||||
_chassisHeader.AddThemeColorOverride("font_color", TextLight);
|
||||
_chassisHeader.AddThemeFontSizeOverride("font_size", 17);
|
||||
headRow.AddChild(_chassisHeader);
|
||||
|
||||
_planeBadge = new Label { Text = "DORSAL" };
|
||||
_planeBadge.AddThemeFontSizeOverride("font_size", 13);
|
||||
headRow.AddChild(_planeBadge);
|
||||
|
||||
var hpRow = new HBoxContainer();
|
||||
hpRow.AddThemeConstantOverride("separation", 8);
|
||||
vbox.AddChild(hpRow);
|
||||
|
||||
_coreHpBar = new ProgressBar
|
||||
{
|
||||
ShowPercentage = false,
|
||||
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
|
||||
CustomMinimumSize = new Vector2(180f, 16f)
|
||||
};
|
||||
var barBg = new StyleBoxFlat { BgColor = BgInner, BorderColor = BorderCol };
|
||||
barBg.SetBorderWidthAll(1);
|
||||
var barFill = new StyleBoxFlat { BgColor = OliveCol };
|
||||
_coreHpBar.AddThemeStyleboxOverride("background", barBg);
|
||||
_coreHpBar.AddThemeStyleboxOverride("fill", barFill);
|
||||
hpRow.AddChild(_coreHpBar);
|
||||
|
||||
_coreHpLabel = new Label { Text = "CORE 100 / 100" };
|
||||
_coreHpLabel.AddThemeColorOverride("font_color", TextLight);
|
||||
_coreHpLabel.AddThemeFontSizeOverride("font_size", 13);
|
||||
hpRow.AddChild(_coreHpLabel);
|
||||
|
||||
_statsLabel = new Label { Text = "SPD 0.0 m/s" };
|
||||
_statsLabel.AddThemeColorOverride("font_color", TextMuted);
|
||||
_statsLabel.AddThemeFontSizeOverride("font_size", 13);
|
||||
vbox.AddChild(_statsLabel);
|
||||
|
||||
_safeLabel = new Label { Text = "RING SAFE" };
|
||||
_safeLabel.AddThemeFontSizeOverride("font_size", 13);
|
||||
vbox.AddChild(_safeLabel);
|
||||
|
||||
_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.AddThemeColorOverride("font_color", TextMuted);
|
||||
_controlsHint.AddThemeFontSizeOverride("font_size", 11);
|
||||
vbox.AddChild(_controlsHint);
|
||||
}
|
||||
|
||||
private void BuildTopRightRadar()
|
||||
{
|
||||
var panel = CreateStyledPanel();
|
||||
panel.AnchorLeft = 1f;
|
||||
panel.AnchorRight = 1f;
|
||||
panel.AnchorTop = 0f;
|
||||
panel.OffsetLeft = -246f;
|
||||
panel.OffsetRight = -14f;
|
||||
panel.OffsetTop = 14f;
|
||||
AddChild(panel);
|
||||
|
||||
var vbox = new VBoxContainer();
|
||||
vbox.AddThemeConstantOverride("separation", 4);
|
||||
panel.AddChild(vbox);
|
||||
|
||||
var title = new Label { Text = "GALLERY & ARENA RADAR", HorizontalAlignment = HorizontalAlignment.Center };
|
||||
title.AddThemeColorOverride("font_color", OrangeCol);
|
||||
title.AddThemeFontSizeOverride("font_size", 12);
|
||||
vbox.AddChild(title);
|
||||
|
||||
_radar = new RadarWidget
|
||||
{
|
||||
CustomMinimumSize = new Vector2(214f, 214f)
|
||||
};
|
||||
vbox.AddChild(_radar);
|
||||
}
|
||||
|
||||
private void BuildBottomLeftSchematic()
|
||||
{
|
||||
_bottomLeftPanel = CreateStyledPanel();
|
||||
_bottomLeftPanel.AnchorLeft = 0f;
|
||||
_bottomLeftPanel.AnchorTop = 1f;
|
||||
_bottomLeftPanel.AnchorBottom = 1f;
|
||||
_bottomLeftPanel.OffsetLeft = 14f;
|
||||
_bottomLeftPanel.OffsetTop = -248f;
|
||||
_bottomLeftPanel.OffsetBottom = -14f;
|
||||
AddChild(_bottomLeftPanel);
|
||||
|
||||
var hbox = new HBoxContainer();
|
||||
hbox.AddThemeConstantOverride("separation", 10);
|
||||
_bottomLeftPanel.AddChild(hbox);
|
||||
|
||||
var leftCol = new VBoxContainer();
|
||||
leftCol.AddThemeConstantOverride("separation", 4);
|
||||
hbox.AddChild(leftCol);
|
||||
|
||||
var title = new Label { Text = "AETHERIA HEAT & HARDPOINTS" };
|
||||
title.AddThemeColorOverride("font_color", OrangeCol);
|
||||
title.AddThemeFontSizeOverride("font_size", 12);
|
||||
leftCol.AddChild(title);
|
||||
|
||||
_schematic = new SchematicPanel(OnHardpointClicked)
|
||||
{
|
||||
CustomMinimumSize = new Vector2(180f, 190f)
|
||||
};
|
||||
leftCol.AddChild(_schematic);
|
||||
|
||||
var rightCol = new VBoxContainer { CustomMinimumSize = new Vector2(178f, 0f) };
|
||||
rightCol.AddThemeConstantOverride("separation", 4);
|
||||
hbox.AddChild(rightCol);
|
||||
|
||||
_cargoHeader = new Label { Text = "SALVAGE CARGO (0/4)" };
|
||||
_cargoHeader.AddThemeColorOverride("font_color", OliveCol);
|
||||
_cargoHeader.AddThemeFontSizeOverride("font_size", 12);
|
||||
rightCol.AddChild(_cargoHeader);
|
||||
|
||||
_cargoList = new VBoxContainer();
|
||||
_cargoList.AddThemeConstantOverride("separation", 3);
|
||||
rightCol.AddChild(_cargoList);
|
||||
|
||||
_garageDetails = new Label { Visible = false, AutowrapMode = TextServer.AutowrapMode.Word };
|
||||
_garageDetails.AddThemeColorOverride("font_color", TextMuted);
|
||||
_garageDetails.AddThemeFontSizeOverride("font_size", 11);
|
||||
_garageDetails.CustomMinimumSize = new Vector2(200f, 0f);
|
||||
hbox.AddChild(_garageDetails);
|
||||
}
|
||||
|
||||
private void BuildBottomCenterChyron()
|
||||
{
|
||||
var panel = CreateStyledPanel();
|
||||
panel.AnchorLeft = 0.5f;
|
||||
panel.AnchorRight = 0.5f;
|
||||
panel.AnchorTop = 1f;
|
||||
panel.AnchorBottom = 1f;
|
||||
panel.OffsetLeft = -150f;
|
||||
panel.OffsetRight = 460f;
|
||||
panel.OffsetTop = -104f;
|
||||
panel.OffsetBottom = -14f;
|
||||
AddChild(panel);
|
||||
|
||||
var vbox = new VBoxContainer();
|
||||
vbox.AddThemeConstantOverride("separation", 3);
|
||||
panel.AddChild(vbox);
|
||||
|
||||
var header = new Label { Text = "IMPERIAL BROADCAST FEED" };
|
||||
header.AddThemeColorOverride("font_color", GoldCol);
|
||||
header.AddThemeFontSizeOverride("font_size", 11);
|
||||
vbox.AddChild(header);
|
||||
|
||||
_chyronBox = new VBoxContainer();
|
||||
_chyronBox.AddThemeConstantOverride("separation", 2);
|
||||
vbox.AddChild(_chyronBox);
|
||||
}
|
||||
|
||||
private void BuildOutcomeBanner()
|
||||
{
|
||||
_outcomeBanner = CreateStyledPanel();
|
||||
_outcomeBanner.AnchorLeft = 0.5f;
|
||||
_outcomeBanner.AnchorRight = 0.5f;
|
||||
_outcomeBanner.AnchorTop = 0.28f;
|
||||
_outcomeBanner.AnchorBottom = 0.28f;
|
||||
_outcomeBanner.OffsetLeft = -210f;
|
||||
_outcomeBanner.OffsetRight = 210f;
|
||||
_outcomeBanner.OffsetTop = -40f;
|
||||
_outcomeBanner.OffsetBottom = 40f;
|
||||
_outcomeBanner.Visible = false;
|
||||
AddChild(_outcomeBanner);
|
||||
|
||||
_outcomeLabel = new Label
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
};
|
||||
_outcomeLabel.AddThemeFontSizeOverride("font_size", 22);
|
||||
_outcomeBanner.AddChild(_outcomeLabel);
|
||||
}
|
||||
|
||||
private void OnHardpointClicked(string hardpointId)
|
||||
{
|
||||
var session = _getSession();
|
||||
if (session is null) return;
|
||||
var cargo = session.State.Player.Grid.Cargo;
|
||||
if (_selectedCargoIndex >= 0 && _selectedCargoIndex < cargo.Count)
|
||||
{
|
||||
_onEquipCargo(_selectedCargoIndex, hardpointId);
|
||||
_selectedCargoIndex = -1;
|
||||
_lastCargoHash = -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncCargoButtons(ChassisGrid grid)
|
||||
{
|
||||
int hash = grid.Cargo.Count * 97 + (_selectedCargoIndex + 10);
|
||||
for (int i = 0; i < grid.Cargo.Count; i++)
|
||||
{
|
||||
hash = HashCode.Combine(hash, grid.Cargo[i].Id);
|
||||
}
|
||||
if (hash == _lastCargoHash) return;
|
||||
_lastCargoHash = hash;
|
||||
|
||||
_cargoHeader.Text = $"SALVAGE CARGO ({grid.Cargo.Count}/{grid.Spec.CargoCapacity})";
|
||||
for (int i = _cargoList.GetChildCount() - 1; i >= 0; i--)
|
||||
{
|
||||
var c = _cargoList.GetChild(i);
|
||||
_cargoList.RemoveChild(c);
|
||||
c.QueueFree();
|
||||
}
|
||||
|
||||
if (grid.Cargo.Count == 0)
|
||||
{
|
||||
var empty = new Label { Text = "No modules in rack.\nPress [E] near crates." };
|
||||
empty.AddThemeColorOverride("font_color", TextMuted);
|
||||
empty.AddThemeFontSizeOverride("font_size", 11);
|
||||
_cargoList.AddChild(empty);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < grid.Cargo.Count; i++)
|
||||
{
|
||||
int idx = i;
|
||||
var mod = grid.Cargo[i];
|
||||
var row = new HBoxContainer();
|
||||
row.AddThemeConstantOverride("separation", 4);
|
||||
|
||||
var selectBtn = new Button
|
||||
{
|
||||
Text = $"{(mod.IsImperial ? "★ " : "")}{mod.Name}",
|
||||
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
|
||||
Alignment = HorizontalAlignment.Left
|
||||
};
|
||||
selectBtn.AddThemeFontSizeOverride("font_size", 11);
|
||||
if (_selectedCargoIndex == idx)
|
||||
{
|
||||
selectBtn.Modulate = OrangeCol;
|
||||
}
|
||||
else if (mod.IsImperial)
|
||||
{
|
||||
selectBtn.Modulate = GoldCol;
|
||||
}
|
||||
selectBtn.Pressed += () =>
|
||||
{
|
||||
_selectedCargoIndex = (_selectedCargoIndex == idx) ? -1 : idx;
|
||||
_lastCargoHash = -1;
|
||||
};
|
||||
row.AddChild(selectBtn);
|
||||
|
||||
var fitBtn = new Button { Text = "FIT" };
|
||||
fitBtn.AddThemeFontSizeOverride("font_size", 11);
|
||||
fitBtn.Pressed += () => AutoFitCargo(grid, idx);
|
||||
row.AddChild(fitBtn);
|
||||
|
||||
_cargoList.AddChild(row);
|
||||
}
|
||||
}
|
||||
|
||||
private void AutoFitCargo(ChassisGrid grid, int cargoIndex)
|
||||
{
|
||||
if (cargoIndex < 0 || cargoIndex >= grid.Cargo.Count) return;
|
||||
var mod = grid.Cargo[cargoIndex];
|
||||
for (int i = 0; i < grid.Spec.Hardpoints.Length; i++)
|
||||
{
|
||||
var hp = grid.Spec.Hardpoints[i];
|
||||
if (ChassisGrid.CanFit(hp, mod))
|
||||
{
|
||||
_onEquipCargo(cargoIndex, hp.Id);
|
||||
_selectedCargoIndex = -1;
|
||||
_lastCargoHash = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncBroadcastChyron(IReadOnlyList<BroadcastLine> lines)
|
||||
{
|
||||
for (int i = _chyronBox.GetChildCount() - 1; i >= 0; i--)
|
||||
{
|
||||
var c = _chyronBox.GetChild(i);
|
||||
_chyronBox.RemoveChild(c);
|
||||
c.QueueFree();
|
||||
}
|
||||
|
||||
int start = Math.Max(0, lines.Count - 3);
|
||||
for (int i = start; i < lines.Count; i++)
|
||||
{
|
||||
var line = lines[i];
|
||||
bool isLatest = i == lines.Count - 1;
|
||||
var lbl = new Label
|
||||
{
|
||||
Text = $"[{line.Timestamp:00.0}s] {line.Text}",
|
||||
AutowrapMode = TextServer.AutowrapMode.Word
|
||||
};
|
||||
lbl.AddThemeFontSizeOverride("font_size", isLatest ? 12 : 11);
|
||||
lbl.AddThemeColorOverride("font_color", isLatest ? TextLight : TextMuted);
|
||||
_chyronBox.AddChild(lbl);
|
||||
}
|
||||
}
|
||||
|
||||
private static string BuildInteractionPrompt(MatchState state, ContenderState player)
|
||||
{
|
||||
GroundDrop? nearest = null;
|
||||
float bestD2 = MatchState.PickupRadius * MatchState.PickupRadius;
|
||||
for (int i = 0; i < state.GroundDrops.Count; i++)
|
||||
{
|
||||
var d = state.GroundDrops[i];
|
||||
if (d.PickedUp) continue;
|
||||
float dx = d.X - player.X;
|
||||
float dz = d.Z - player.Z;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 <= bestD2)
|
||||
{
|
||||
bestD2 = d2;
|
||||
nearest = d;
|
||||
}
|
||||
}
|
||||
|
||||
if (nearest is null) return "";
|
||||
if (nearest.Module is { } mod)
|
||||
{
|
||||
return $"[E] Loot {(mod.IsImperial ? "IMPERIAL " : "")}{mod.Name}";
|
||||
}
|
||||
if (nearest.Chassis is { } ch)
|
||||
{
|
||||
return $"[E] Swap to {ch.Name} ({ch.Plane})";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static string BuildGarageDetails(ChassisGrid grid)
|
||||
{
|
||||
var lines = new List<string>
|
||||
{
|
||||
$"CONDUCTIVITY {grid.Spec.HullConductivity:F1} | THRUST {grid.ComputeDriveThrust():F0} N",
|
||||
"MOUNTED:"
|
||||
};
|
||||
for (int i = 0; i < grid.Mounted.Count; i++)
|
||||
{
|
||||
var m = grid.Mounted[i];
|
||||
lines.Add($"• {m.HardpointId}: {m.Spec.Name} ({m.CurrentTemp:F0}°C, {(m.CurrentPerformance * 100f):F0}%)");
|
||||
}
|
||||
return string.Join("\n", lines);
|
||||
}
|
||||
|
||||
private static PanelContainer CreateStyledPanel()
|
||||
{
|
||||
var panel = new PanelContainer();
|
||||
var style = new StyleBoxFlat
|
||||
{
|
||||
BgColor = new Color(BgDark.R, BgDark.G, BgDark.B, 0.88f),
|
||||
BorderColor = BorderCol,
|
||||
ContentMarginLeft = 10,
|
||||
ContentMarginRight = 10,
|
||||
ContentMarginTop = 8,
|
||||
ContentMarginBottom = 8
|
||||
};
|
||||
style.SetBorderWidthAll(2);
|
||||
style.SetCornerRadiusAll(3);
|
||||
panel.AddThemeStyleboxOverride("panel", style);
|
||||
return panel;
|
||||
}
|
||||
|
||||
private sealed partial class RadarWidget : Control
|
||||
{
|
||||
private MatchState? _state;
|
||||
|
||||
public void SetState(MatchState state) => _state = state;
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
Vector2 center = Size * 0.5f;
|
||||
float radius = MathF.Min(Size.X, Size.Y) * 0.47f;
|
||||
float scale = radius / MatchState.ArenaHalfExtent;
|
||||
|
||||
DrawCircle(center, radius, BgInner);
|
||||
DrawArc(center, radius, 0f, MathF.Tau, 48, BorderCol, 1.5f);
|
||||
|
||||
if (_state is null) return;
|
||||
|
||||
// Safe Circle
|
||||
float safePx = _state.Spectators.SafeRadius * scale;
|
||||
DrawArc(center, safePx, 0f, MathF.Tau, 56, 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 = center + new Vector2(d.X, d.Z) * scale;
|
||||
if (d.Chassis is not null)
|
||||
{
|
||||
DrawRect(new Rect2(p - new Vector2(2.5f, 2.5f), new Vector2(5f, 5f)), CyanCol);
|
||||
}
|
||||
else if (d.Module is { IsImperial: true })
|
||||
{
|
||||
DrawCircle(p, 3.0f, GoldCol);
|
||||
}
|
||||
}
|
||||
|
||||
// Spectator Wall (scaled by RadarSignature) + red target lock lines
|
||||
var specs = _state.Spectators.Spectators;
|
||||
for (int i = 0; i < specs.Count; i++)
|
||||
{
|
||||
var s = specs[i];
|
||||
if (!s.Alive) continue;
|
||||
var p = center + new Vector2(s.X, s.Z) * scale;
|
||||
float blipR = 1.6f + s.RadarSignature * 3.1f;
|
||||
|
||||
Color col = s.Tier switch
|
||||
{
|
||||
SpectatorTier.Tourist => GoldCol,
|
||||
SpectatorTier.Patron => PatronColor,
|
||||
_ => RedCol
|
||||
};
|
||||
|
||||
if (s.Stance != SpectatorStance.Neutral && 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 = center + new Vector2(tgt.X, tgt.Z) * scale;
|
||||
DrawLine(p, tp, new Color(RedCol.R, RedCol.G, RedCol.B, 0.65f), 1.3f);
|
||||
}
|
||||
col = RedCol;
|
||||
}
|
||||
|
||||
DrawCircle(p, blipR, col);
|
||||
}
|
||||
|
||||
// Contenders
|
||||
for (int i = 0; i < _state.Contenders.Count; i++)
|
||||
{
|
||||
var c = _state.Contenders[i];
|
||||
if (!c.Alive) continue;
|
||||
var p = center + new Vector2(c.X, c.Z) * scale;
|
||||
if (c.IsPlayer)
|
||||
{
|
||||
var dir = new Vector2(MathF.Sin(c.Yaw), MathF.Cos(c.Yaw));
|
||||
var perp = new Vector2(-dir.Y, dir.X);
|
||||
var pts = new[]
|
||||
{
|
||||
p + dir * 6.5f,
|
||||
p - dir * 4.5f + perp * 4.2f,
|
||||
p - dir * 4.5f - perp * 4.2f
|
||||
};
|
||||
DrawColoredPolygon(pts, OliveCol);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawCircle(p, 3.3f, OrangeCol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Color PatronColor = Color.FromHtml("#4ba8a5");
|
||||
}
|
||||
|
||||
private sealed partial class SchematicPanel : Control
|
||||
{
|
||||
private readonly Action<string> _onHardpointClick;
|
||||
private readonly List<(Rect2 Rect, string HardpointId)> _hitBoxes = new();
|
||||
private ChassisGrid? _grid;
|
||||
private int _selectedCargoIndex = -1;
|
||||
|
||||
public SchematicPanel(Action<string> onHardpointClick)
|
||||
{
|
||||
_onHardpointClick = onHardpointClick;
|
||||
}
|
||||
|
||||
public void SetGrid(ChassisGrid grid, int selectedCargoIndex)
|
||||
{
|
||||
_grid = grid;
|
||||
_selectedCargoIndex = selectedCargoIndex;
|
||||
}
|
||||
|
||||
public override void _GuiInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseButton mb && mb.Pressed && mb.ButtonIndex == MouseButton.Left)
|
||||
{
|
||||
for (int i = 0; i < _hitBoxes.Count; i++)
|
||||
{
|
||||
if (_hitBoxes[i].Rect.HasPoint(mb.Position))
|
||||
{
|
||||
_onHardpointClick(_hitBoxes[i].HardpointId);
|
||||
AcceptEvent();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
_hitBoxes.Clear();
|
||||
if (_grid is null) return;
|
||||
|
||||
var spec = _grid.Spec;
|
||||
float cellSize = MathF.Min((Size.X - 8f) / spec.Width, (Size.Y - 8f) / spec.Height);
|
||||
float originX = (Size.X - spec.Width * cellSize) * 0.5f;
|
||||
float originY = (Size.Y - spec.Height * cellSize) * 0.5f;
|
||||
|
||||
for (int y = 0; y < spec.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < spec.Width; x++)
|
||||
{
|
||||
if (!spec.IsActive(x, y)) continue;
|
||||
var rect = new Rect2(originX + x * cellSize + 1.5f, originY + y * cellSize + 1.5f, cellSize - 3f, cellSize - 3f);
|
||||
|
||||
float temp = _grid.Temperature[x, y];
|
||||
Color fill = TempToColor(temp);
|
||||
DrawRect(rect, fill);
|
||||
|
||||
// Armor bar at bottom of cell
|
||||
float maxArm = MathF.Max(1f, _grid.MaxArmor[x, y]);
|
||||
float armRatio = Math.Clamp(_grid.Armor[x, y] / maxArm, 0f, 1f);
|
||||
var armRect = new Rect2(rect.Position.X + 2f, rect.End.Y - 5f, (rect.Size.X - 4f) * armRatio, 3f);
|
||||
DrawRect(armRect, OliveCol);
|
||||
|
||||
// Border radiator highlight
|
||||
Color border = _grid.BorderCells[x, y] ? CyanCol : BorderCol;
|
||||
DrawRect(rect, border, filled: false, width: _grid.BorderCells[x, y] ? 1.5f : 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
// Hardpoints & mounted module temperature badges
|
||||
ModuleSpec? selectedCargo = _selectedCargoIndex >= 0 && _selectedCargoIndex < _grid.Cargo.Count
|
||||
? _grid.Cargo[_selectedCargoIndex]
|
||||
: null;
|
||||
|
||||
for (int i = 0; i < spec.Hardpoints.Length; i++)
|
||||
{
|
||||
var hp = spec.Hardpoints[i];
|
||||
var rect = new Rect2(
|
||||
originX + hp.X * cellSize + 2f,
|
||||
originY + hp.Y * cellSize + 2f,
|
||||
hp.Width * cellSize - 4f,
|
||||
hp.Height * cellSize - 4f);
|
||||
_hitBoxes.Add((rect, hp.Id));
|
||||
|
||||
bool compatible = selectedCargo is not null && ChassisGrid.CanFit(hp, selectedCargo);
|
||||
Color hpBorder = compatible ? GoldCol : TextLight;
|
||||
DrawRect(rect, hpBorder, filled: false, width: compatible ? 2.4f : 1.4f);
|
||||
|
||||
var mounted = _grid.GetMountedOn(hp.Id);
|
||||
string tag = mounted is not null
|
||||
? $"{mounted.Spec.Kind.ToString()[..1]}:{mounted.CurrentTemp:F0}°"
|
||||
: hp.Kind.ToString()[..3].ToUpperInvariant();
|
||||
DrawString(
|
||||
ThemeDB.FallbackFont,
|
||||
rect.Position + new Vector2(3f, 13f),
|
||||
tag,
|
||||
HorizontalAlignment.Left,
|
||||
rect.Size.X - 4f,
|
||||
10,
|
||||
mounted is { Spec.IsImperial: true } ? GoldCol : TextLight);
|
||||
}
|
||||
}
|
||||
|
||||
private static Color TempToColor(float temp)
|
||||
{
|
||||
if (temp < 45f)
|
||||
{
|
||||
float t = Math.Clamp((temp - 20f) / 25f, 0f, 1f);
|
||||
return new Color(0.18f, 0.23f, 0.26f).Lerp(new Color(0.32f, 0.45f, 0.28f), t);
|
||||
}
|
||||
if (temp < 95f)
|
||||
{
|
||||
float t = Math.Clamp((temp - 45f) / 50f, 0f, 1f);
|
||||
return new Color(0.32f, 0.45f, 0.28f).Lerp(new Color(0.62f, 0.69f, 0.36f), t);
|
||||
}
|
||||
if (temp < 140f)
|
||||
{
|
||||
float t = Math.Clamp((temp - 95f) / 45f, 0f, 1f);
|
||||
return new Color(0.62f, 0.69f, 0.36f).Lerp(OrangeCol, t);
|
||||
}
|
||||
float hotT = Math.Clamp((temp - 140f) / 60f, 0f, 1f);
|
||||
return OrangeCol.Lerp(RedCol, hotT);
|
||||
}
|
||||
}
|
||||
}
|
||||
256
client/Main.cs
Normal file
256
client/Main.cs
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
using System;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
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.
|
||||
/// </summary>
|
||||
public partial class Main : Node3D
|
||||
{
|
||||
private TerrainRenderer _terrain = null!;
|
||||
private ArenaRenderer _arena = null!;
|
||||
private Camera3D _camera = null!;
|
||||
private Hud _hud = null!;
|
||||
private ArenaSession? _session;
|
||||
|
||||
private PlayerInput? _scriptedInput;
|
||||
private float _cameraDistance = 30f;
|
||||
private Vector3 _cameraSmoothedTarget = Vector3.Zero;
|
||||
private float _elapsedSeconds;
|
||||
private bool _interactQueued;
|
||||
private int _seed = 42;
|
||||
|
||||
public ArenaSession Session => _session ?? throw new InvalidOperationException($"No active ArenaSession ({Failure ?? "uninitialized"})");
|
||||
public TerrainRenderer Terrain => _terrain;
|
||||
public ArenaRenderer Arena => _arena;
|
||||
public Hud Hud => _hud;
|
||||
public string? Failure { get; private set; }
|
||||
public int Seed => _seed;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
SetupLightingAndSky();
|
||||
|
||||
_terrain = new TerrainRenderer { Name = "Terrain" };
|
||||
AddChild(_terrain);
|
||||
|
||||
_arena = new ArenaRenderer { Name = "Arena" };
|
||||
AddChild(_arena);
|
||||
|
||||
_camera = new Camera3D
|
||||
{
|
||||
Name = "TacticalCamera",
|
||||
Current = true,
|
||||
Fov = 48f,
|
||||
Far = 520f
|
||||
};
|
||||
AddChild(_camera);
|
||||
|
||||
_hud = new Hud(() => _session, OnEquipCargo) { Name = "Hud" };
|
||||
AddChild(_hud);
|
||||
|
||||
Reset(_seed);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
_session?.Dispose();
|
||||
_session = null;
|
||||
}
|
||||
|
||||
public void Reset(int seed)
|
||||
{
|
||||
_seed = seed;
|
||||
_session?.Dispose();
|
||||
_session = null;
|
||||
Failure = null;
|
||||
|
||||
try
|
||||
{
|
||||
_session = new ArenaSession(seed);
|
||||
var p = _session.State.Player;
|
||||
_cameraSmoothedTarget = new Vector3(p.X, p.Y, p.Z);
|
||||
_terrain.InvalidateAll();
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds);
|
||||
_hud.Sync(_session);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Failure = ex.Message;
|
||||
GD.PushError("ArenaSession startup failed: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetScriptedInput(PlayerInput? input) => _scriptedInput = input;
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventKey key && key.Pressed && !key.Echo)
|
||||
{
|
||||
switch (key.Keycode)
|
||||
{
|
||||
case Key.E:
|
||||
_interactQueued = true;
|
||||
break;
|
||||
case Key.Tab:
|
||||
_hud.ToggleGarage();
|
||||
break;
|
||||
case Key.R:
|
||||
Reset(_seed + 1);
|
||||
break;
|
||||
case Key.Escape:
|
||||
Input.MouseMode = Input.MouseMode == Input.MouseModeEnum.Confined
|
||||
? Input.MouseModeEnum.Visible
|
||||
: Input.MouseModeEnum.Confined;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (@event is InputEventMouseButton mb && mb.Pressed)
|
||||
{
|
||||
if (mb.ButtonIndex == MouseButton.WheelUp)
|
||||
{
|
||||
_cameraDistance = Math.Clamp(_cameraDistance - 2.5f, 16f, 58f);
|
||||
}
|
||||
else if (mb.ButtonIndex == MouseButton.WheelDown)
|
||||
{
|
||||
_cameraDistance = Math.Clamp(_cameraDistance + 2.5f, 16f, 58f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (_session is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_elapsedSeconds += (float)delta;
|
||||
var input = _scriptedInput ?? GatherPlayerInput();
|
||||
_interactQueued = false;
|
||||
|
||||
_session.Step(input);
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_session is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateCamera((float)delta);
|
||||
_hud.Sync(_session);
|
||||
}
|
||||
|
||||
private PlayerInput GatherPlayerInput()
|
||||
{
|
||||
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;
|
||||
|
||||
float steer = 0f;
|
||||
if (Input.IsKeyPressed(Key.D) || Input.IsKeyPressed(Key.Right)) steer += 1f;
|
||||
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 fire = !pointerOnHud && Input.IsMouseButtonPressed(MouseButton.Left);
|
||||
|
||||
var (aimX, aimZ) = ComputeMouseTerrainAim(mousePos);
|
||||
return new PlayerInput(
|
||||
Throttle: throttle,
|
||||
Steer: steer,
|
||||
AimWorldX: aimX,
|
||||
AimWorldZ: aimZ,
|
||||
Fire: fire,
|
||||
InteractPickup: _interactQueued,
|
||||
Brake: brake);
|
||||
}
|
||||
|
||||
private (float AimX, float AimZ) ComputeMouseTerrainAim(Vector2 mousePos)
|
||||
{
|
||||
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 _))
|
||||
{
|
||||
return (hx, hz);
|
||||
}
|
||||
|
||||
if (MathF.Abs(rayDir.Y) > 1e-4f)
|
||||
{
|
||||
float t = (player.Y - rayOrigin.Y) / rayDir.Y;
|
||||
if (t > 0f)
|
||||
{
|
||||
Vector3 p = rayOrigin + rayDir * t;
|
||||
return (p.X, p.Z);
|
||||
}
|
||||
}
|
||||
|
||||
return (player.X + MathF.Sin(player.Yaw) * 25f, player.Z + MathF.Cos(player.Yaw) * 25f);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
private void OnEquipCargo(int cargoIndex, string hardpointId)
|
||||
{
|
||||
_session?.TryEquipCargo(cargoIndex, hardpointId);
|
||||
}
|
||||
|
||||
private void SetupLightingAndSky()
|
||||
{
|
||||
var sun = new DirectionalLight3D
|
||||
{
|
||||
Name = "DesertSun",
|
||||
LightColor = new Color(1.0f, 0.92f, 0.78f),
|
||||
LightEnergy = 1.45f,
|
||||
ShadowEnabled = true,
|
||||
RotationDegrees = new Vector3(-48f, 32f, 0f)
|
||||
};
|
||||
AddChild(sun);
|
||||
|
||||
var skyMat = new ProceduralSkyMaterial
|
||||
{
|
||||
SkyTopColor = new Color(0.24f, 0.34f, 0.44f),
|
||||
SkyHorizonColor = new Color(0.76f, 0.56f, 0.37f),
|
||||
GroundBottomColor = new Color(0.32f, 0.22f, 0.14f),
|
||||
GroundHorizonColor = new Color(0.70f, 0.50f, 0.33f)
|
||||
};
|
||||
var env = new Godot.Environment
|
||||
{
|
||||
BackgroundMode = Godot.Environment.BGMode.Sky,
|
||||
Sky = new Sky { SkyMaterial = skyMat },
|
||||
AmbientLightSource = Godot.Environment.AmbientSource.Sky,
|
||||
AmbientLightEnergy = 0.55f,
|
||||
FogEnabled = true,
|
||||
FogLightColor = new Color(0.74f, 0.55f, 0.38f),
|
||||
FogDensity = 0.0022f
|
||||
};
|
||||
AddChild(new WorldEnvironment { Name = "WorldEnv", Environment = env });
|
||||
}
|
||||
}
|
||||
6
client/Main.tscn
Normal file
6
client/Main.tscn
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://Main.cs" id="1"]
|
||||
|
||||
[node name="Main" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
43
client/NativeLibraries.cs
Normal file
43
client/NativeLibraries.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Godot;
|
||||
using Ymir.Box3D;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Finds ymir_box3d for Ymir.Box3D's DllImports. Godot loads game assemblies into its own load context, so the
|
||||
/// default probing does not look beside them. A run from the editor or <c>--path</c> loads the library from the
|
||||
/// project's build directory; an exported run from the data folder Godot puts beside the executable.
|
||||
/// </summary>
|
||||
internal static class NativeLibraries
|
||||
{
|
||||
private const string Library = "ymir_box3d";
|
||||
|
||||
#pragma warning disable CA2255 // application code: the resolver must exist before the first DllImport
|
||||
[ModuleInitializer]
|
||||
internal static void Register() =>
|
||||
NativeLibrary.SetDllImportResolver(typeof(Box3DSoaWorld).Assembly, Resolve);
|
||||
|
||||
private static IntPtr Resolve(string name, Assembly assembly, DllImportSearchPath? searchPath)
|
||||
{
|
||||
if (name != Library) return IntPtr.Zero;
|
||||
string dir = OS.HasFeature("template")
|
||||
? Path.Combine(Path.GetDirectoryName(OS.GetExecutablePath())!, $"data_RustToDust.Client_{Platform()}_{Arch()}")
|
||||
: ProjectSettings.GlobalizePath("res://.godot/mono/temp/bin/Debug");
|
||||
string path = Path.Combine(dir, FileName());
|
||||
return File.Exists(path) && NativeLibrary.TryLoad(path, out var handle) ? handle : IntPtr.Zero;
|
||||
}
|
||||
|
||||
private static string FileName() =>
|
||||
OperatingSystem.IsWindows() ? "ymir_box3d.dll" : OperatingSystem.IsMacOS() ? "libymir_box3d.dylib" : "libymir_box3d.so";
|
||||
|
||||
private static string Platform() =>
|
||||
OperatingSystem.IsWindows() ? "windows" : OperatingSystem.IsMacOS() ? "macos" : "linuxbsd";
|
||||
|
||||
private static string Arch() =>
|
||||
RuntimeInformation.ProcessArchitecture == System.Runtime.InteropServices.Architecture.Arm64 ? "arm64" : "x86_64";
|
||||
}
|
||||
13
client/RustToDust.Client.csproj
Normal file
13
client/RustToDust.Client.csproj
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Godot.NET.Sdk/4.7.2">
|
||||
<!-- The Godot client: presentation and input over ArenaSession. Building it builds Ymir (cmake and a C compiler) and RustToDust into .godot/mono/temp/bin/Debug. -->
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
<Nullable>enable</Nullable>
|
||||
<AssemblyName>RustToDust.Client</AssemblyName>
|
||||
<RootNamespace>RustToDust.Client</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\src\RustToDust.Ymir\RustToDust.Ymir.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
286
client/TerrainRenderer.cs
Normal file
286
client/TerrainRenderer.cs
Normal file
|
|
@ -0,0 +1,286 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
|
||||
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.
|
||||
/// 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 PixelsPerMeter = ViewportSize / TerrainField.TileSize;
|
||||
private const float HeightSpan = TerrainField.MaxWorldHeight - TerrainField.MinWorldHeight;
|
||||
private const float BaseHeightNorm = (0f - TerrainField.MinWorldHeight) / HeightSpan;
|
||||
|
||||
private static readonly Color HeightClearColor = new(BaseHeightNorm, 0.88f, 0.02f, 0.0f);
|
||||
private static readonly Color AlbedoClearColor = new(0.69f, 0.50f, 0.31f, 1.0f);
|
||||
|
||||
private sealed class TileNode
|
||||
{
|
||||
public SubViewport HeightViewport = null!;
|
||||
public Node2D HeightCanvas = null!;
|
||||
public SubViewport AlbedoViewport = null!;
|
||||
public Node2D AlbedoCanvas = null!;
|
||||
public MeshInstance3D SurfaceMesh = null!;
|
||||
public int BakedVersion = -1;
|
||||
}
|
||||
|
||||
private readonly TileNode[,] _tiles = new TileNode[TerrainField.TileGridCount, TerrainField.TileGridCount];
|
||||
private Shader _brushAddShader = null!;
|
||||
private Shader _brushSubShader = null!;
|
||||
private Shader _brushAlbedoShader = null!;
|
||||
private Shader _surfaceShader = null!;
|
||||
private TerrainField? _lastTerrain;
|
||||
|
||||
public int BakedTileCount { get; private set; }
|
||||
public int DirtyRebakes { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_brushAddShader = GD.Load<Shader>("res://terrain_brush.gdshader");
|
||||
_brushSubShader = GD.Load<Shader>("res://terrain_brush_sub.gdshader");
|
||||
_brushAlbedoShader = GD.Load<Shader>("res://terrain_brush_albedo.gdshader");
|
||||
_surfaceShader = GD.Load<Shader>("res://terrain_surface.gdshader");
|
||||
|
||||
BuildTileGrid();
|
||||
}
|
||||
|
||||
public void InvalidateAll()
|
||||
{
|
||||
for (int tz = 0; tz < TerrainField.TileGridCount; tz++)
|
||||
{
|
||||
for (int tx = 0; tx < TerrainField.TileGridCount; tx++)
|
||||
{
|
||||
_tiles[tx, tz].BakedVersion = -1;
|
||||
}
|
||||
}
|
||||
BakedTileCount = 0;
|
||||
DirtyRebakes = 0;
|
||||
_lastTerrain = null;
|
||||
}
|
||||
|
||||
public void Sync(TerrainField terrain)
|
||||
{
|
||||
if (!ReferenceEquals(_lastTerrain, terrain))
|
||||
{
|
||||
InvalidateAll();
|
||||
_lastTerrain = terrain;
|
||||
}
|
||||
|
||||
for (int tz = 0; tz < TerrainField.TileGridCount; tz++)
|
||||
{
|
||||
for (int tx = 0; tx < TerrainField.TileGridCount; tx++)
|
||||
{
|
||||
var tile = _tiles[tx, tz];
|
||||
int version = terrain.TileVersions[tx, tz];
|
||||
if (tile.BakedVersion != version)
|
||||
{
|
||||
BakeTile(tx, tz, tile, terrain);
|
||||
if (tile.BakedVersion < 0)
|
||||
{
|
||||
BakedTileCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
DirtyRebakes++;
|
||||
}
|
||||
tile.BakedVersion = version;
|
||||
}
|
||||
}
|
||||
}
|
||||
terrain.ClearDirtyMask();
|
||||
}
|
||||
|
||||
private void BuildTileGrid()
|
||||
{
|
||||
for (int tz = 0; tz < TerrainField.TileGridCount; tz++)
|
||||
{
|
||||
for (int tx = 0; tx < TerrainField.TileGridCount; tx++)
|
||||
{
|
||||
var tile = new TileNode();
|
||||
|
||||
tile.HeightViewport = CreateOrthoViewport($"Tile_{tx}_{tz}_Height", useHdr: true, out var heightCanvas);
|
||||
tile.HeightCanvas = heightCanvas;
|
||||
AddChild(tile.HeightViewport);
|
||||
|
||||
tile.AlbedoViewport = CreateOrthoViewport($"Tile_{tx}_{tz}_Albedo", useHdr: false, out var albedoCanvas);
|
||||
tile.AlbedoCanvas = albedoCanvas;
|
||||
AddChild(tile.AlbedoViewport);
|
||||
|
||||
var plane = new PlaneMesh
|
||||
{
|
||||
Size = new Vector2(TerrainField.TileSize, TerrainField.TileSize),
|
||||
SubdivideWidth = 48,
|
||||
SubdivideDepth = 48
|
||||
};
|
||||
|
||||
var mat = new ShaderMaterial { Shader = _surfaceShader };
|
||||
mat.SetShaderParameter("height_tex", tile.HeightViewport.GetTexture());
|
||||
mat.SetShaderParameter("albedo_tex", tile.AlbedoViewport.GetTexture());
|
||||
mat.SetShaderParameter("height_min", TerrainField.MinWorldHeight);
|
||||
mat.SetShaderParameter("height_max", TerrainField.MaxWorldHeight);
|
||||
mat.SetShaderParameter("tile_size", TerrainField.TileSize);
|
||||
|
||||
float centerX = -TerrainField.HalfExtent + (tx + 0.5f) * TerrainField.TileSize;
|
||||
float centerZ = -TerrainField.HalfExtent + (tz + 0.5f) * TerrainField.TileSize;
|
||||
|
||||
tile.SurfaceMesh = new MeshInstance3D
|
||||
{
|
||||
Name = $"Tile_{tx}_{tz}_Mesh",
|
||||
Mesh = plane,
|
||||
MaterialOverride = mat,
|
||||
Position = new Vector3(centerX, 0f, centerZ),
|
||||
CustomAabb = new Aabb(
|
||||
new Vector3(-TerrainField.TileSize * 0.5f, TerrainField.MinWorldHeight - 2f, -TerrainField.TileSize * 0.5f),
|
||||
new Vector3(TerrainField.TileSize, HeightSpan + 4f, TerrainField.TileSize))
|
||||
};
|
||||
AddChild(tile.SurfaceMesh);
|
||||
|
||||
_tiles[tx, tz] = tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static SubViewport CreateOrthoViewport(string name, bool useHdr, out Node2D canvas)
|
||||
{
|
||||
var vp = new SubViewport
|
||||
{
|
||||
Name = name,
|
||||
Size = new Vector2I(ViewportSize, ViewportSize),
|
||||
Disable3D = true,
|
||||
UseHdr2D = useHdr,
|
||||
TransparentBg = false,
|
||||
RenderTargetClearMode = SubViewport.ClearMode.Always,
|
||||
RenderTargetUpdateMode = SubViewport.UpdateMode.Disabled
|
||||
};
|
||||
|
||||
var cam = new Camera2D
|
||||
{
|
||||
AnchorMode = Camera2D.AnchorModeEnum.FixedTopLeft,
|
||||
Position = Vector2.Zero,
|
||||
Enabled = true
|
||||
};
|
||||
vp.AddChild(cam);
|
||||
|
||||
canvas = new Node2D { Name = "Canvas" };
|
||||
vp.AddChild(canvas);
|
||||
return vp;
|
||||
}
|
||||
|
||||
private void BakeTile(int tx, int tz, TileNode tile, TerrainField terrain)
|
||||
{
|
||||
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
|
||||
});
|
||||
|
||||
float tileMinX = -TerrainField.HalfExtent + tx * TerrainField.TileSize;
|
||||
float tileMinZ = -TerrainField.HalfExtent + tz * TerrainField.TileSize;
|
||||
IReadOnlyList<int> indices = terrain.GetTileBrushIndices(tx, tz);
|
||||
var brushes = terrain.Brushes;
|
||||
|
||||
for (int i = 0; i < indices.Count; i++)
|
||||
{
|
||||
var b = brushes[indices[i]];
|
||||
if (b.RadiusX <= 0.05f || b.RadiusZ <= 0.05f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float px = (b.X - tileMinX) * PixelsPerMeter;
|
||||
float py = (b.Z - tileMinZ) * PixelsPerMeter;
|
||||
float rxPx = b.RadiusX * PixelsPerMeter;
|
||||
float rzPx = b.RadiusZ * PixelsPerMeter;
|
||||
int kindInt = (int)b.Kind;
|
||||
|
||||
// 1. Height+Material brush pass(es)
|
||||
if (b.Kind == TerrainBrushKind.Crater)
|
||||
{
|
||||
// Crater uses subtractive pit + additive ejecta rim/scorch
|
||||
tile.HeightCanvas.AddChild(CreateBrushQuad(px, py, rxPx, rzPx, b.RotationRad, _brushSubShader, kindInt, b.HeightDelta));
|
||||
tile.HeightCanvas.AddChild(CreateBrushQuad(px, py, rxPx, rzPx, b.RotationRad, _brushAddShader, kindInt, b.HeightDelta));
|
||||
}
|
||||
else if (b.Kind == TerrainBrushKind.Track)
|
||||
{
|
||||
tile.HeightCanvas.AddChild(CreateBrushQuad(px, py, rxPx, rzPx, b.RotationRad, _brushSubShader, kindInt, b.HeightDelta));
|
||||
tile.HeightCanvas.AddChild(CreateBrushQuad(px, py, rxPx, rzPx, b.RotationRad, _brushAddShader, kindInt, b.HeightDelta));
|
||||
}
|
||||
else if (b.Kind == TerrainBrushKind.Road || b.HeightDelta < 0f)
|
||||
{
|
||||
tile.HeightCanvas.AddChild(CreateBrushQuad(px, py, rxPx, rzPx, b.RotationRad, _brushSubShader, kindInt, b.HeightDelta));
|
||||
}
|
||||
else
|
||||
{
|
||||
tile.HeightCanvas.AddChild(CreateBrushQuad(px, py, rxPx, rzPx, b.RotationRad, _brushAddShader, kindInt, b.HeightDelta));
|
||||
}
|
||||
|
||||
// 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 albedoMat = new ShaderMaterial { Shader = _brushAlbedoShader };
|
||||
albedoMat.SetShaderParameter("brush_kind", kindInt);
|
||||
albedoMat.SetShaderParameter("brush_albedo", new Vector3(b.AlbedoR, b.AlbedoG, b.AlbedoB));
|
||||
albedoMat.SetShaderParameter("height_delta", b.HeightDelta);
|
||||
albedoQuad.Material = albedoMat;
|
||||
tile.AlbedoCanvas.AddChild(albedoQuad);
|
||||
}
|
||||
|
||||
tile.HeightViewport.RenderTargetUpdateMode = SubViewport.UpdateMode.Once;
|
||||
tile.AlbedoViewport.RenderTargetUpdateMode = SubViewport.UpdateMode.Once;
|
||||
}
|
||||
|
||||
private static ColorRect CreateBrushQuad(
|
||||
float px, float py,
|
||||
float rxPx, float rzPx,
|
||||
float rotationRad,
|
||||
Shader shader,
|
||||
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 mat = new ShaderMaterial { Shader = shader };
|
||||
mat.SetShaderParameter("brush_kind", kindInt);
|
||||
mat.SetShaderParameter("height_delta", heightDelta);
|
||||
mat.SetShaderParameter("height_span", HeightSpan);
|
||||
quad.Material = mat;
|
||||
return quad;
|
||||
}
|
||||
|
||||
private static void ClearCanvasChildren(Node2D canvas)
|
||||
{
|
||||
for (int i = canvas.GetChildCount() - 1; i >= 0; i--)
|
||||
{
|
||||
var child = canvas.GetChild(i);
|
||||
canvas.RemoveChild(child);
|
||||
child.QueueFree();
|
||||
}
|
||||
}
|
||||
}
|
||||
33
client/project.godot
Normal file
33
client/project.godot
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
|
||||
config_version=5
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Rust to Dust"
|
||||
run/main_scene="res://Main.tscn"
|
||||
config/features=PackedStringArray("4.7", "C#")
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=1280
|
||||
window/size/viewport_height=720
|
||||
window/stretch/mode="canvas_items"
|
||||
|
||||
[dotnet]
|
||||
|
||||
project/assembly_name="RustToDust.Client"
|
||||
|
||||
[physics]
|
||||
|
||||
; Godot's physics is switched off: Ymir is the only physics world. ArenaSession ticks at 60 Hz.
|
||||
3d/physics_engine="Dummy"
|
||||
common/physics_ticks_per_second=60
|
||||
common/physics_interpolation=true
|
||||
|
||||
[rendering]
|
||||
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
renderer/rendering_method.mobile="gl_compatibility"
|
||||
71
client/terrain_brush.gdshader
Normal file
71
client/terrain_brush.gdshader
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
shader_type canvas_item;
|
||||
render_mode blend_add;
|
||||
|
||||
// Encodes positive height deltas into R ([-12m, +16m] => span 28m),
|
||||
// plus positive roughness delta (G), metallic (B), and scorch/wear (A).
|
||||
uniform int brush_kind = 0;
|
||||
uniform float height_delta = 0.0;
|
||||
uniform float height_span = 28.0;
|
||||
|
||||
void fragment() {
|
||||
vec2 uv_local = UV * 2.0 - 1.0;
|
||||
float u = uv_local.x;
|
||||
float v = uv_local.y;
|
||||
float r2 = u * u + v * v;
|
||||
if (r2 >= 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
float dh = 0.0;
|
||||
float dg = 0.0;
|
||||
float db = 0.0;
|
||||
float da = 0.0;
|
||||
|
||||
if (brush_kind == 0) {
|
||||
// DuneRidge (positive)
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
float ridge = max(0.0, 1.0 - u * u);
|
||||
float asym = 1.0 + 0.32 * u;
|
||||
dh = max(0.0, height_delta) * env * (0.35 + 0.65 * ridge) * asym;
|
||||
dg = 0.02 * env;
|
||||
} else if (brush_kind == 1) {
|
||||
// Mesa
|
||||
float r = sqrt(r2);
|
||||
float t = clamp((1.0 - r) / 0.45, 0.0, 1.0);
|
||||
float plateau = t * t * (3.0 - 2.0 * t);
|
||||
dh = max(0.0, height_delta) * plateau;
|
||||
db = 0.05 * plateau;
|
||||
} else if (brush_kind == 2) {
|
||||
// SalvagePad (positive part)
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
dh = max(0.0, height_delta) * env;
|
||||
db = 0.03 * env;
|
||||
} else if (brush_kind == 4) {
|
||||
// Crater ejecta rim + slag/scorch
|
||||
float r = sqrt(r2);
|
||||
float depth = abs(height_delta);
|
||||
float rim_t = sin(3.14159265 * clamp((r - 0.55) / 0.45, 0.0, 1.0));
|
||||
dh = 0.32 * depth * rim_t * rim_t;
|
||||
float pit_t = clamp(1.0 - r / 0.65, 0.0, 1.0);
|
||||
dg = 0.04 * (1.0 - r);
|
||||
db = 0.10 * pit_t;
|
||||
da = 0.78 * clamp(1.0 - r * 0.9, 0.0, 1.0);
|
||||
} else if (brush_kind == 5) {
|
||||
// Track wear
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
da = 0.32 * env;
|
||||
} else if (brush_kind == 6) {
|
||||
// Scorch
|
||||
float r = sqrt(r2);
|
||||
float mask = clamp(1.0 - r, 0.0, 1.0);
|
||||
mask = mask * mask;
|
||||
dg = 0.02 * mask;
|
||||
db = 0.08 * mask;
|
||||
da = 0.85 * mask;
|
||||
}
|
||||
|
||||
COLOR = vec4(dh / height_span, dg, db, da);
|
||||
}
|
||||
73
client/terrain_brush_albedo.gdshader
Normal file
73
client/terrain_brush_albedo.gdshader
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
shader_type canvas_item;
|
||||
render_mode blend_mix;
|
||||
|
||||
uniform int brush_kind = 0;
|
||||
uniform vec3 brush_albedo = vec3(0.72, 0.53, 0.33);
|
||||
uniform float height_delta = 0.0;
|
||||
|
||||
void fragment() {
|
||||
vec2 uv_local = UV * 2.0 - 1.0;
|
||||
float u = uv_local.x;
|
||||
float v = uv_local.y;
|
||||
float r2 = u * u + v * v;
|
||||
if (r2 >= 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec3 col = brush_albedo;
|
||||
float alpha = 0.0;
|
||||
|
||||
if (brush_kind == 0) {
|
||||
// DuneRidge: windward sunlit crest vs dry wash
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
float ridge = max(0.0, 1.0 - u * u);
|
||||
col = mix(brush_albedo * 0.90, brush_albedo * 1.12, ridge);
|
||||
alpha = env * 0.72;
|
||||
} else if (brush_kind == 1) {
|
||||
// Mesa: rust-basalt plateau + stratified skirt
|
||||
float r = sqrt(r2);
|
||||
float t = clamp((1.0 - r) / 0.45, 0.0, 1.0);
|
||||
float plateau = t * t * (3.0 - 2.0 * t);
|
||||
float cliff_band = clamp(1.0 - abs(r - 0.74) * 5.0, 0.0, 1.0);
|
||||
col = mix(brush_albedo, brush_albedo * 0.68, cliff_band);
|
||||
alpha = clamp(plateau + cliff_band * 0.5, 0.0, 0.94);
|
||||
} else if (brush_kind == 2) {
|
||||
// SalvagePad: compacted gravel & weathered concrete slab
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
float border = smoothstep(0.75, 0.92, sqrt(r2));
|
||||
col = mix(brush_albedo, vec3(0.32, 0.28, 0.24), border * 0.45);
|
||||
alpha = clamp(env * 1.15, 0.0, 0.88);
|
||||
} else if (brush_kind == 3) {
|
||||
// Road: twin packed dirt ruts
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
float rut = smoothstep(0.15, 0.45, abs(u)) * (1.0 - smoothstep(0.60, 0.92, abs(u)));
|
||||
col = mix(brush_albedo, brush_albedo * 0.76, rut);
|
||||
alpha = env * (0.45 + 0.35 * rut);
|
||||
} else if (brush_kind == 4) {
|
||||
// Crater: charred pit center + bright rust ejecta rim
|
||||
float r = sqrt(r2);
|
||||
float pit = clamp(1.0 - r / 0.62, 0.0, 1.0);
|
||||
float rim = sin(3.14159265 * clamp((r - 0.55) / 0.45, 0.0, 1.0));
|
||||
vec3 ejecta = vec3(0.62, 0.38, 0.22);
|
||||
col = mix(ejecta, brush_albedo, clamp(pit * 1.3, 0.0, 1.0));
|
||||
alpha = clamp(max(pit * 0.94, rim * rim * 0.72), 0.0, 0.95);
|
||||
} else if (brush_kind == 5) {
|
||||
// Track: twin tire ruts along local X
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
float treads = smoothstep(0.18, 0.45, abs(v)) * (1.0 - smoothstep(0.62, 0.92, abs(v)));
|
||||
col = brush_albedo;
|
||||
alpha = env * treads * 0.62;
|
||||
} else if (brush_kind == 6) {
|
||||
// Scorch
|
||||
float r = sqrt(r2);
|
||||
float mask = clamp(1.0 - r, 0.0, 1.0);
|
||||
col = brush_albedo;
|
||||
alpha = mask * mask * 0.88;
|
||||
}
|
||||
|
||||
COLOR = vec4(col, alpha);
|
||||
}
|
||||
40
client/terrain_brush_sub.gdshader
Normal file
40
client/terrain_brush_sub.gdshader
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
shader_type canvas_item;
|
||||
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;
|
||||
|
||||
void fragment() {
|
||||
vec2 uv_local = UV * 2.0 - 1.0;
|
||||
float u = uv_local.x;
|
||||
float v = uv_local.y;
|
||||
float r2 = u * u + v * v;
|
||||
if (r2 >= 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
float neg_dh = 0.0;
|
||||
if (brush_kind == 0) {
|
||||
// Dry wash (negative DuneRidge)
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
float ridge = max(0.0, 1.0 - u * u);
|
||||
float asym = 1.0 + 0.32 * u;
|
||||
neg_dh = max(0.0, -height_delta) * env * (0.35 + 0.65 * ridge) * asym;
|
||||
} else if (brush_kind == 2 || brush_kind == 3 || brush_kind == 5) {
|
||||
// SalvagePad (<0), Road, Track rut
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
neg_dh = max(0.0, -height_delta) * env;
|
||||
} else if (brush_kind == 4) {
|
||||
// Crater pit
|
||||
float r = sqrt(r2);
|
||||
float depth = abs(height_delta);
|
||||
float pit_t = clamp(1.0 - r / 0.62, 0.0, 1.0);
|
||||
neg_dh = depth * pit_t * pit_t * (3.0 - 2.0 * pit_t);
|
||||
}
|
||||
|
||||
COLOR = vec4(neg_dh / height_span, 0.0, 0.0, 0.0);
|
||||
}
|
||||
48
client/terrain_surface.gdshader
Normal file
48
client/terrain_surface.gdshader
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
shader_type spatial;
|
||||
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;
|
||||
|
||||
float decode_height(float h_norm) {
|
||||
return mix(height_min, height_max, clamp(h_norm, 0.0, 1.0));
|
||||
}
|
||||
|
||||
float hash21(vec2 p) {
|
||||
p = fract(p * vec2(123.34, 456.21));
|
||||
p += dot(p, p + 45.32);
|
||||
return fract(p.x * p.y);
|
||||
}
|
||||
|
||||
void vertex() {
|
||||
float h_norm = textureLod(height_tex, UV, 0.0).r;
|
||||
VERTEX.y += decode_height(h_norm);
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
const float texel_step = 1.0 / 256.0;
|
||||
float world_step = tile_size / 256.0;
|
||||
|
||||
float hL = decode_height(texture(height_tex, UV - vec2(texel_step, 0.0)).r);
|
||||
float hR = decode_height(texture(height_tex, UV + vec2(texel_step, 0.0)).r);
|
||||
float hD = decode_height(texture(height_tex, UV - vec2(0.0, texel_step)).r);
|
||||
float hU = decode_height(texture(height_tex, UV + vec2(0.0, texel_step)).r);
|
||||
|
||||
vec3 world_normal = normalize(vec3(hL - hR, 2.0 * world_step, hD - hU));
|
||||
NORMAL = normalize((VIEW_MATRIX * vec4(world_normal, 0.0)).xyz);
|
||||
|
||||
vec4 mat = texture(height_tex, UV);
|
||||
vec3 alb = texture(albedo_tex, UV).rgb;
|
||||
|
||||
// Subtle desert sand grain so dunes read crisply under sunlight
|
||||
float grain = (hash21(floor(UV * 768.0)) - 0.5) * 0.045;
|
||||
float scorch = clamp(mat.a, 0.0, 1.0);
|
||||
alb = clamp(alb + vec3(grain), 0.0, 1.0) * (1.0 - 0.30 * scorch);
|
||||
|
||||
ALBEDO = alb;
|
||||
ROUGHNESS = clamp(mat.g, 0.2, 0.98);
|
||||
METALLIC = clamp(mat.b, 0.0, 0.85);
|
||||
}
|
||||
121
client/tests/Smoke.cs
Normal file
121
client/tests/Smoke.cs
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
|
||||
namespace RustToDust.Client.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Headless Godot smoke test: instantiates Main, drives 60 frames with throttle + fire + crater stamp,
|
||||
/// verifies terrain tile baking and Ymir physics integration, and exits with code 0 on pass.
|
||||
/// <c>godot --headless --path client res://tests/Smoke.tscn</c>
|
||||
/// </summary>
|
||||
public partial class Smoke : Node
|
||||
{
|
||||
private const double WatchdogSeconds = 60.0;
|
||||
|
||||
private readonly List<string> _failures = new();
|
||||
private Main _main = null!;
|
||||
private bool _done;
|
||||
|
||||
public override void _Ready() => _ = RunAsync();
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!_done && Time.GetTicksMsec() > WatchdogSeconds * 1000.0)
|
||||
{
|
||||
Check(false, $"Smoke watchdog timed out after {WatchdogSeconds}s");
|
||||
Finish();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_main = GD.Load<PackedScene>("res://Main.tscn").Instantiate<Main>();
|
||||
AddChild(_main);
|
||||
|
||||
if (_main.Failure is { } failure)
|
||||
{
|
||||
Check(false, "Main failed to initialize ArenaSession: " + failure);
|
||||
}
|
||||
else
|
||||
{
|
||||
await RunScenarioAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Check(false, ex.ToString());
|
||||
}
|
||||
|
||||
Finish();
|
||||
}
|
||||
|
||||
private async Task RunScenarioAsync()
|
||||
{
|
||||
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}");
|
||||
|
||||
var player = _main.Session.State.Player;
|
||||
float startX = player.X;
|
||||
float startZ = player.Z;
|
||||
|
||||
_main.SetScriptedInput(new PlayerInput(
|
||||
Throttle: 1f,
|
||||
Steer: 0.25f,
|
||||
AimWorldX: startX + 35f,
|
||||
AimWorldZ: startZ + 10f,
|
||||
Fire: true,
|
||||
InteractPickup: false,
|
||||
Brake: false));
|
||||
|
||||
for (int i = 0; i < 60; i++)
|
||||
{
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.PhysicsFrame);
|
||||
if (_main.Failure is { } f)
|
||||
{
|
||||
Check(false, "Session failure during physics loop: " + f);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
float dx = player.X - startX;
|
||||
float dz = player.Z - startZ;
|
||||
float displacement = MathF.Sqrt(dx * dx + dz * dz);
|
||||
Check(displacement > 3f, $"Expected player displacement > 3m after 60 frames, got {displacement:F2}m");
|
||||
Check(!float.IsNaN(player.X) && !float.IsNaN(player.Y) && !float.IsNaN(player.Z), "Player position became NaN");
|
||||
|
||||
int rebakesBefore = _main.Terrain.DirtyRebakes;
|
||||
_main.Session.State.Terrain.StampCrater(-48f, -48f, radius: 5f, depth: 1.4f);
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.PhysicsFrame);
|
||||
Check(_main.Terrain.DirtyRebakes == rebakesBefore + 1,
|
||||
$"Expected 1 dirty tile rebake from isolated crater stamp, got {_main.Terrain.DirtyRebakes - rebakesBefore}");
|
||||
|
||||
_main.SetScriptedInput(null);
|
||||
}
|
||||
|
||||
private void Check(bool condition, string message)
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
_failures.Add(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void Finish()
|
||||
{
|
||||
if (_done) return;
|
||||
_done = true;
|
||||
foreach (var f in _failures)
|
||||
{
|
||||
GD.PrintErr("SMOKE FAIL: " + f);
|
||||
}
|
||||
GD.Print(_failures.Count == 0 ? "SMOKE PASS" : $"SMOKE FAILED ({_failures.Count})");
|
||||
GetTree().Quit(_failures.Count == 0 ? 0 : 1);
|
||||
}
|
||||
}
|
||||
6
client/tests/Smoke.tscn
Normal file
6
client/tests/Smoke.tscn
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://tests/Smoke.cs" id="1"]
|
||||
|
||||
[node name="Smoke" type="Node"]
|
||||
script = ExtResource("1")
|
||||
Loading…
Reference in a new issue