RustToDust Phase 2: Procedural brush terrain, 4-corner Ymir support, and Godot 4.7.2 Mono client

This commit is contained in:
Meta Vens 2026-12-04 13:57:44 +01:00
commit 215b5ea834
20 changed files with 3486 additions and 56 deletions

121
client/tests/Smoke.cs Normal file
View 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
View 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")