619 lines
28 KiB
C#
619 lines
28 KiB
C#
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 == 64, $"Expected 64 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");
|
|
|
|
// Pause physics during the isolated crater check so AI contender track stamps in other tiles do not race it.
|
|
_main.SetScriptedInput(null);
|
|
_main.SetPhysicsProcess(false);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
|
|
bool isHeadless = DisplayServer.GetName() == "headless";
|
|
int rebakesBefore = _main.Terrain.DirtyRebakes;
|
|
float cpuBefore = _main.Session.State.Terrain.SampleHeight(-96f, -96f);
|
|
float gpuBefore = 0f;
|
|
if (!isHeadless)
|
|
{
|
|
if (_main.Terrain.TryGetHeightImageFormat(out var imgFormat))
|
|
{
|
|
GD.Print($"SMOKE INFO: HeightViewport format={imgFormat}");
|
|
}
|
|
|
|
bool hasGpuBefore = _main.Terrain.TrySampleBakedHeight(-96f, -96f, out gpuBefore);
|
|
Check(hasGpuBefore, "Expected GPU HeightViewport readback to succeed before crater");
|
|
if (hasGpuBefore)
|
|
{
|
|
float beforeErr = MathF.Abs(gpuBefore - cpuBefore);
|
|
GD.Print($"SMOKE INFO: Crater-site pre-stamp cpu={cpuBefore:F4}m gpu={gpuBefore:F4}m err={beforeErr:F4}m");
|
|
Check(beforeErr <= 0.20f,
|
|
$"Expected baked GPU height ({gpuBefore:F4}m) to match CPU height ({cpuBefore:F4}m) before crater within 0.20m");
|
|
}
|
|
|
|
// Verify brushed terrain relief (tallest Mesa/DuneRidge center) so a flat-map bug can never pass
|
|
TerrainBrush? reliefBrush = null;
|
|
float bestHillCpu = 0f;
|
|
foreach (var b in _main.Session.State.Terrain.Brushes)
|
|
{
|
|
if (b.Kind == TerrainBrushKind.Mesa || (b.Kind == TerrainBrushKind.DuneRidge && b.HeightDelta > 0f))
|
|
{
|
|
float h = _main.Session.State.Terrain.SampleHeight(b.X, b.Z);
|
|
if (h > bestHillCpu)
|
|
{
|
|
bestHillCpu = h;
|
|
reliefBrush = b;
|
|
}
|
|
}
|
|
}
|
|
|
|
Check(reliefBrush.HasValue && bestHillCpu > 10f, "Expected brushed terrain relief > 10m in generated arena");
|
|
if (reliefBrush.HasValue)
|
|
{
|
|
var rb = reliefBrush.Value;
|
|
bool hasGpuHill = _main.Terrain.TrySampleBakedHeight(rb.X, rb.Z, out float gpuHill);
|
|
Check(hasGpuHill, "Expected GPU HeightViewport readback to succeed on brushed relief hill/mesa");
|
|
if (hasGpuHill)
|
|
{
|
|
float hillErr = MathF.Abs(gpuHill - bestHillCpu);
|
|
GD.Print($"SMOKE INFO: Relief {rb.Kind} at ({rb.X:F1},{rb.Z:F1}) cpu={bestHillCpu:F4}m gpu={gpuHill:F4}m err={hillErr:F4}m");
|
|
Check(gpuHill > 10f, $"Expected GPU baked hill height > 10m, got {gpuHill:F4}m");
|
|
Check(hillErr <= 0.20f,
|
|
$"Expected GPU hill height ({gpuHill:F4}m) to match CPU ({bestHillCpu:F4}m) within 0.20m");
|
|
}
|
|
}
|
|
|
|
// Verify tile seam continuity across interior tile boundaries (< 0.01m)
|
|
float maxSeamErr = 0f;
|
|
float[] boundaries = { -192f, 0f, 192f };
|
|
float[] offsets = { -280f, -96f, 96f, 280f };
|
|
foreach (float bCoord in boundaries)
|
|
{
|
|
foreach (float ortho in offsets)
|
|
{
|
|
if (_main.Terrain.TrySampleBakedHeight(bCoord - 0.0001f, ortho, out float hL) &&
|
|
_main.Terrain.TrySampleBakedHeight(bCoord + 0.0001f, ortho, out float hR))
|
|
{
|
|
maxSeamErr = MathF.Max(maxSeamErr, MathF.Abs(hL - hR));
|
|
}
|
|
if (_main.Terrain.TrySampleBakedHeight(ortho, bCoord - 0.0001f, out float hD) &&
|
|
_main.Terrain.TrySampleBakedHeight(ortho, bCoord + 0.0001f, out float hU))
|
|
{
|
|
maxSeamErr = MathF.Max(maxSeamErr, MathF.Abs(hD - hU));
|
|
}
|
|
}
|
|
}
|
|
GD.Print($"SMOKE INFO: Max tile seam error={maxSeamErr:F5}m");
|
|
Check(maxSeamErr < 0.01f, $"Expected tile seam error < 0.01m, got {maxSeamErr:F5}m");
|
|
}
|
|
|
|
_main.Session.State.Terrain.StampCrater(-96f, -96f, radius: 5f, depth: 1.4f);
|
|
_main.Terrain.Sync(_main.Session.State.Terrain);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
|
|
float cpuAfter = _main.Session.State.Terrain.SampleHeight(-96f, -96f);
|
|
Check(cpuAfter < cpuBefore - 0.8f,
|
|
$"Expected CPU terrain height to drop after crater stamp (before {cpuBefore:F2}m, after {cpuAfter:F2}m)");
|
|
Check(_main.Terrain.DirtyRebakes == rebakesBefore + 1,
|
|
$"Expected 1 dirty tile rebake from isolated crater stamp, got {_main.Terrain.DirtyRebakes - rebakesBefore}");
|
|
|
|
if (!isHeadless)
|
|
{
|
|
bool hasGpuAfter = _main.Terrain.TrySampleBakedHeight(-96f, -96f, out float gpuAfter);
|
|
Check(hasGpuAfter, "Expected GPU HeightViewport readback to succeed after crater");
|
|
if (hasGpuAfter)
|
|
{
|
|
float afterErr = MathF.Abs(gpuAfter - cpuAfter);
|
|
GD.Print($"SMOKE INFO: Crater-site post-stamp cpu={cpuAfter:F4}m gpu={gpuAfter:F4}m err={afterErr:F4}m");
|
|
Check(afterErr <= 0.20f,
|
|
$"Expected baked GPU height ({gpuAfter:F4}m) to match CPU height ({cpuAfter:F4}m) after crater within 0.20m");
|
|
Check(gpuAfter < gpuBefore - 0.8f,
|
|
$"Expected baked GPU height to drop after crater (before {gpuBefore:F4}m, after {gpuAfter:F4}m)");
|
|
}
|
|
}
|
|
|
|
_main.SetPhysicsProcess(true);
|
|
|
|
await VerifyHudAndShadersAsync(isHeadless);
|
|
await MaybeCapturePreviewAsync(isHeadless);
|
|
await VerifyMaxLoadPaladinGarageAsync();
|
|
}
|
|
|
|
private async Task VerifyHudAndShadersAsync(bool isHeadless)
|
|
{
|
|
var invShader = _main.Hud.Schematic.ShaderMaterial.Shader;
|
|
Check(invShader is not null && !string.IsNullOrWhiteSpace(invShader.Code),
|
|
"inventory_grid.gdshader failed to load");
|
|
|
|
int chromeCount = 0;
|
|
foreach (var mat in _main.Hud.GetChromeMaterials())
|
|
{
|
|
chromeCount++;
|
|
Check(mat.Shader is not null && !string.IsNullOrWhiteSpace(mat.Shader.Code),
|
|
$"panel_chrome.gdshader failed to load on HUD panel #{chromeCount}");
|
|
}
|
|
Check(chromeCount == 5, $"Expected 5 ChromePanel materials on HUD, got {chromeCount}");
|
|
|
|
// Pack a real Tank chassis with mounted modules, thermal gradient, stripped cell, and active hit-pulse
|
|
var testGrid = new ChassisGrid(Catalog.Tank);
|
|
Check(testGrid.TryMount(Catalog.Recoilless, "wpn_turret"), "Expected Recoilless to mount on wpn_turret");
|
|
Check(testGrid.TryMount(Catalog.Mg762, "wpn_coax"), "Expected Mg762 to mount on wpn_coax");
|
|
Check(testGrid.TryMount(Catalog.TurboCore, "eng_rear"), "Expected TurboCore to mount on eng_rear");
|
|
Check(testGrid.TryMount(Catalog.CopperRad, "rad_deck"), "Expected CopperRad to mount on rad_deck");
|
|
Check(testGrid.TryMount(Catalog.WeldedPlate, "arm_glacis"), "Expected WeldedPlate to mount on arm_glacis");
|
|
testGrid.InjectHardpointHeat("eng_rear", 1800f);
|
|
testGrid.InjectHardpointHeat("wpn_turret", 900f);
|
|
testGrid.StepHeat(0.25f);
|
|
testGrid.Armor[0, 0] = 0f; // stripped armor cell
|
|
|
|
var schematic = _main.Hud.Schematic;
|
|
schematic.SetGrid(testGrid);
|
|
schematic.TriggerHitPulse(1, 1, 1f);
|
|
|
|
// Hit-testing verification: center of cell (1, 1) must map to (1, 1) and hardpoint "wpn_turret"
|
|
schematic.ComputeCellLayout(out float cellSize, out Vector2 origin);
|
|
Check(cellSize > 10f, $"Expected InventoryGridControl cellSize > 10px, got {cellSize:F2}");
|
|
Vector2 probePos = origin + new Vector2(1.5f * cellSize, 1.5f * cellSize);
|
|
bool hitCell = schematic.TryGetCellAt(probePos, out var mappedCell);
|
|
Check(hitCell && mappedCell == new Vector2I(1, 1),
|
|
$"Expected TryGetCellAt to map center of (1,1) to (1,1), got hit={hitCell} cell={mappedCell}");
|
|
var mappedHp = schematic.GetHardpointAt(1, 1);
|
|
Check(mappedHp is { Id: "wpn_turret" },
|
|
$"Expected GetHardpointAt(1,1) to return wpn_turret, got {mappedHp?.Id ?? "null"}");
|
|
|
|
// Toggle thermal mode off -> on -> off
|
|
_main.Hud.SetThermalMode(true, instant: true);
|
|
Check(_main.Hud.ThermalMode && MathF.Abs(schematic.ThermalBlend - 1f) < 0.01f,
|
|
"Expected ThermalMode to activate immediately");
|
|
_main.Hud.SetThermalMode(false, instant: true);
|
|
Check(!_main.Hud.ThermalMode && MathF.Abs(schematic.ThermalBlend) < 0.01f,
|
|
"Expected ThermalMode to deactivate immediately");
|
|
|
|
// Regression check (Finding 3): same-dimension SwapChassis updates _hardpointLookup and clears hover state
|
|
schematic._GuiInput(new InputEventMouseMotion { Position = probePos });
|
|
Check(schematic.HoveredCell == new Vector2I(1, 1) && schematic.HoveredHardpoint is { Id: "wpn_turret" },
|
|
$"Expected hover on (1,1)/wpn_turret before SwapChassis, got cell={schematic.HoveredCell} hp={schematic.HoveredHardpoint?.Id ?? "null"}");
|
|
|
|
bool hoverResetEmitted = false;
|
|
void OnSwapHoverChanged(Vector2I? cell, HardpointSpec? hp)
|
|
{
|
|
if (cell is null && hp is null)
|
|
{
|
|
hoverResetEmitted = true;
|
|
}
|
|
}
|
|
schematic.HoverChanged += OnSwapHoverChanged;
|
|
var altTankSpec = Catalog.Tank with
|
|
{
|
|
Id = "tank_alt",
|
|
Hardpoints = new[]
|
|
{
|
|
new HardpointSpec("wpn_swapped", HardpointKind.Weapon, 1, 1, 2, 2, 18f)
|
|
}
|
|
};
|
|
testGrid.SwapChassis(altTankSpec);
|
|
schematic.SetGrid(testGrid);
|
|
schematic.HoverChanged -= OnSwapHoverChanged;
|
|
|
|
Check(schematic.GetHardpointAt(1, 1) is { Id: "wpn_swapped" },
|
|
$"Expected GetHardpointAt(1,1) to update to wpn_swapped after same-dimension SwapChassis, got {schematic.GetHardpointAt(1, 1)?.Id ?? "null"}");
|
|
Check(schematic.GetHardpointAt(0, 1) is null,
|
|
$"Expected old hardpoint wpn_coax at (0,1) to clear after SwapChassis, got {schematic.GetHardpointAt(0, 1)?.Id ?? "null"}");
|
|
Check(schematic.HoveredCell is null && schematic.HoveredHardpoint is null && hoverResetEmitted,
|
|
$"Expected SwapChassis to clear hover and emit HoverChanged(null, null), cell={schematic.HoveredCell} emitted={hoverResetEmitted}");
|
|
|
|
// Re-seed Tank grid for GPU tests below
|
|
testGrid = new ChassisGrid(Catalog.Tank);
|
|
Check(testGrid.TryMount(Catalog.Recoilless, "wpn_turret"), "Expected Recoilless to remount on wpn_turret");
|
|
Check(testGrid.TryMount(Catalog.Mg762, "wpn_coax"), "Expected Mg762 to remount on wpn_coax");
|
|
Check(testGrid.TryMount(Catalog.TurboCore, "eng_rear"), "Expected TurboCore to remount on eng_rear");
|
|
Check(testGrid.TryMount(Catalog.CopperRad, "rad_deck"), "Expected CopperRad to remount on rad_deck");
|
|
Check(testGrid.TryMount(Catalog.WeldedPlate, "arm_glacis"), "Expected WeldedPlate to remount on arm_glacis");
|
|
testGrid.InjectHardpointHeat("eng_rear", 1800f);
|
|
testGrid.InjectHardpointHeat("wpn_turret", 900f);
|
|
testGrid.StepHeat(0.25f);
|
|
testGrid.Armor[0, 0] = 0f;
|
|
|
|
// Restore live player grid to HUD and verify layout has no overlaps or clipping
|
|
_main.Hud.Sync(_main.Session);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
Vector2 vpSize = GetViewport().GetVisibleRect().Size;
|
|
Check(!_main.Hud.HasPanelOverlapOrClip(vpSize), $"Compact HUD panels overlapped or clipped at {vpSize}");
|
|
_main.Hud.ToggleGarage();
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
Check(!_main.Hud.HasPanelOverlapOrClip(vpSize), $"Garage HUD panels overlapped or clipped at {vpSize}");
|
|
_main.Hud.ToggleGarage();
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
|
|
if (isHeadless)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// GPU verification on OpenGL 3.3: render isolated InventoryGridControl (tactical + thermal) & panel_chrome.gdshader
|
|
var gridVp = new SubViewport
|
|
{
|
|
Size = new Vector2I(240, 240),
|
|
TransparentBg = true,
|
|
RenderTargetUpdateMode = SubViewport.UpdateMode.Always
|
|
};
|
|
var vpGrid = new InventoryGridControl
|
|
{
|
|
Size = new Vector2(240f, 240f),
|
|
CustomMinimumSize = new Vector2(240f, 240f)
|
|
};
|
|
gridVp.AddChild(vpGrid);
|
|
AddChild(gridVp);
|
|
|
|
vpGrid.SetGrid(testGrid);
|
|
vpGrid.TriggerHitPulse(1, 1, 1f);
|
|
vpGrid.SetThermalInstant(false);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
|
|
var tacticalImg = gridVp.GetTexture().GetImage();
|
|
int tacticalOpaque = CountNonZeroAlphaPixels(tacticalImg, 0.08f);
|
|
GD.Print($"SMOKE INFO: InventoryGrid GPU tactical opaque pixels={tacticalOpaque}");
|
|
Check(tacticalOpaque > 4000, $"Expected > 4000 rendered pixels from InventoryGrid tactical shader, got {tacticalOpaque}");
|
|
|
|
vpGrid.SetThermalInstant(true);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
|
|
var thermalImg = gridVp.GetTexture().GetImage();
|
|
int thermalOpaque = CountNonZeroAlphaPixels(thermalImg, 0.08f);
|
|
int modeDiff = CountDifferentPixels(tacticalImg, thermalImg, 0.05f);
|
|
GD.Print($"SMOKE INFO: InventoryGrid GPU thermal opaque={thermalOpaque}, diff vs tactical={modeDiff}");
|
|
Check(thermalOpaque > 4000, $"Expected > 4000 rendered pixels from InventoryGrid thermal shader, got {thermalOpaque}");
|
|
Check(modeDiff > 500, $"Expected thermal conduit toggle to visibly change > 500 pixels, got {modeDiff}");
|
|
|
|
// Finding 2 GPU check: overheated (350C+, thermal_mode = 1.0f) must obey blend_premul_alpha (out_rgb <= out_a)
|
|
testGrid.InjectHardpointHeat("eng_rear", 45000f);
|
|
testGrid.InjectHardpointHeat("wpn_turret", 25000f);
|
|
testGrid.StepHeat(0.05f);
|
|
float hotTemp = testGrid.Temperature[1, 3];
|
|
Check(hotTemp >= 350f, $"Expected overheated cell >= 350C for premul test, got {hotTemp:F1}C");
|
|
vpGrid.SetGrid(testGrid);
|
|
vpGrid.SetThermalInstant(true);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
|
|
var overheatImg = gridVp.GetTexture().GetImage();
|
|
int premulViolations = CountPremulViolations(overheatImg, 0.01f);
|
|
GD.Print($"SMOKE INFO: InventoryGrid GPU overheat ({hotTemp:F1}C) premul violations={premulViolations}");
|
|
Check(premulViolations == 0, $"Expected 0 blend_premul_alpha violations (max(RGB) > A + 0.01) on overheated grid, got {premulViolations}");
|
|
|
|
// Finding 1 GPU check: asymmetric Raptor chassis with thermal_mode = 1.0f must leave 0 lit pixels in inactive cell holes
|
|
var raptorGrid = new ChassisGrid(Catalog.Raptor);
|
|
Check(raptorGrid.TryMount(Catalog.CopperRad, "rad_lsh"), "Expected CopperRad on Raptor rad_lsh");
|
|
Check(raptorGrid.TryMount(Catalog.CopperRad, "rad_rsh"), "Expected CopperRad on Raptor rad_rsh");
|
|
Check(raptorGrid.TryMount(Catalog.Autocannon, "wpn_larm"), "Expected Autocannon on Raptor wpn_larm");
|
|
Check(raptorGrid.TryMount(Catalog.TurboCore, "eng_chest"), "Expected TurboCore on Raptor eng_chest");
|
|
Check(raptorGrid.TryMount(Catalog.Autocannon, "wpn_rarm"), "Expected Autocannon on Raptor wpn_rarm");
|
|
raptorGrid.InjectHardpointHeat("eng_chest", 1800f);
|
|
raptorGrid.StepHeat(0.25f);
|
|
|
|
vpGrid.SetGrid(raptorGrid);
|
|
vpGrid.SetThermalInstant(true);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
|
|
var raptorImg = gridVp.GetTexture().GetImage();
|
|
int raptorHoleScanned = 0;
|
|
int raptorHoleLit = 0;
|
|
int rw = raptorImg.GetWidth();
|
|
int rh = raptorImg.GetHeight();
|
|
for (int py = 0; py < rh; py++)
|
|
{
|
|
for (int px = 0; px < rw; px++)
|
|
{
|
|
if (vpGrid.TryGetCellAt(new Vector2(px + 0.5f, py + 0.5f), out var cell) && !Catalog.Raptor.IsActive(cell.X, cell.Y))
|
|
{
|
|
raptorHoleScanned++;
|
|
Color c = raptorImg.GetPixel(px, py);
|
|
if (MathF.Max(MathF.Max(c.R, c.G), MathF.Max(c.B, c.A)) > 0.001f)
|
|
{
|
|
raptorHoleLit++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
GD.Print($"SMOKE INFO: Asymmetric Raptor hole lit pixels={raptorHoleLit} (scanned {raptorHoleScanned} hole px)");
|
|
Check(raptorHoleScanned > 1000, $"Expected > 1000 inactive hole pixels scanned on Raptor, got {raptorHoleScanned}");
|
|
Check(raptorHoleLit == 0, $"Expected 0 lit/opaque pixels in inactive Raptor cell holes, got {raptorHoleLit}");
|
|
|
|
gridVp.QueueFree();
|
|
|
|
// GPU verification for panel_chrome.gdshader
|
|
var chromeVp = new SubViewport
|
|
{
|
|
Size = new Vector2I(240, 120),
|
|
TransparentBg = true,
|
|
RenderTargetUpdateMode = SubViewport.UpdateMode.Always
|
|
};
|
|
var chromeShader = GD.Load<Shader>("res://panel_chrome.gdshader");
|
|
var chromeMat = new ShaderMaterial { Shader = chromeShader };
|
|
chromeMat.SetShaderParameter("rect_size", new Vector2(240f, 120f));
|
|
chromeMat.SetShaderParameter("accent_color", Color.FromHtml("#e08a4a"));
|
|
var chromeImgTex = Image.CreateEmpty(1, 1, false, Image.Format.Rgba8);
|
|
chromeImgTex.SetPixel(0, 0, Colors.White);
|
|
var chromeRect = new TextureRect
|
|
{
|
|
Texture = ImageTexture.CreateFromImage(chromeImgTex),
|
|
Size = new Vector2(240f, 120f),
|
|
ExpandMode = TextureRect.ExpandModeEnum.IgnoreSize,
|
|
StretchMode = TextureRect.StretchModeEnum.Scale,
|
|
Material = chromeMat
|
|
};
|
|
chromeVp.AddChild(chromeRect);
|
|
AddChild(chromeVp);
|
|
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
|
|
var chromeImg = chromeVp.GetTexture().GetImage();
|
|
int chromeOpaque = CountNonZeroAlphaPixels(chromeImg, 0.08f);
|
|
Color cornerPx = chromeImg.GetPixel(2, 2);
|
|
Color centerPx = chromeImg.GetPixel(120, 60);
|
|
GD.Print($"SMOKE INFO: panel_chrome GPU opaque={chromeOpaque}, corner={cornerPx}, center={centerPx}");
|
|
Check(chromeOpaque > 10000, $"Expected > 10000 rendered pixels from panel_chrome.gdshader, got {chromeOpaque}");
|
|
Check(cornerPx.R > centerPx.R + 0.25f,
|
|
$"Expected L-bracket corner pixel ({cornerPx}) to be accented brighter than panel center ({centerPx})");
|
|
|
|
chromeVp.QueueFree();
|
|
}
|
|
|
|
private async Task MaybeCapturePreviewAsync(bool isHeadless)
|
|
{
|
|
if (isHeadless) return;
|
|
|
|
string? previewPath = null;
|
|
foreach (string arg in OS.GetCmdlineUserArgs())
|
|
{
|
|
const string prefix = "--capture-preview=";
|
|
if (arg.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
previewPath = arg[prefix.Length..];
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(previewPath))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!_main.Hud.GarageExpanded)
|
|
{
|
|
_main.Hud.ToggleGarage();
|
|
}
|
|
|
|
// Seed realistic combat telemetry so the preview clearly showcases armor stripping, hit-flash, cargo rack, and thermal heat
|
|
var grid = _main.Session.State.Player.Grid;
|
|
grid.TryAddCargo(Catalog.TouringPlasma);
|
|
grid.TryAddCargo(Catalog.GoldRadiator);
|
|
grid.InjectHardpointHeat("eng_mid", 1100f);
|
|
grid.InjectHardpointHeat("wpn_roof", 750f);
|
|
grid.StepHeat(0.15f);
|
|
grid.Armor[0, 0] = 0f;
|
|
_main.Hud.Sync(_main.Session);
|
|
_main.Hud.Schematic.TriggerHitPulse(1, 0, 0.9f);
|
|
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
|
|
var frameImg = GetViewport().GetTexture().GetImage();
|
|
var err = frameImg.SavePng(previewPath);
|
|
GD.Print($"SMOKE INFO: Saved preview screenshot ({frameImg.GetWidth()}x{frameImg.GetHeight()}) to {previewPath} (err={err})");
|
|
Check(err == Error.Ok, $"Failed to save preview screenshot to {previewPath}: {err}");
|
|
}
|
|
|
|
private async Task VerifyMaxLoadPaladinGarageAsync()
|
|
{
|
|
var grid = _main.Session.State.Player.Grid;
|
|
grid.SwapChassis(Catalog.Paladin);
|
|
Check(grid.TryMount(Catalog.TouringPlasma, "wpn_lsh"), "Expected TouringPlasma on Paladin wpn_lsh");
|
|
Check(grid.TryMount(Catalog.WeldedPlate, "arm_collar"), "Expected WeldedPlate on Paladin arm_collar");
|
|
Check(grid.TryMount(Catalog.TouringPlasma, "wpn_rsh"), "Expected TouringPlasma on Paladin wpn_rsh");
|
|
Check(grid.TryMount(Catalog.GildedLance, "wpn_larm"), "Expected GildedLance on Paladin wpn_larm");
|
|
Check(grid.TryMount(Catalog.NobleCore, "eng_core"), "Expected NobleCore on Paladin eng_core");
|
|
Check(grid.TryMount(Catalog.GildedLance, "wpn_rarm"), "Expected GildedLance on Paladin wpn_rarm");
|
|
Check(grid.TryMount(Catalog.GoldRadiator, "rad_l"), "Expected GoldRadiator on Paladin rad_l");
|
|
Check(grid.TryMount(Catalog.WeldedPlate, "arm_waist"), "Expected WeldedPlate on Paladin arm_waist");
|
|
Check(grid.TryMount(Catalog.GoldRadiator, "rad_r"), "Expected GoldRadiator on Paladin rad_r");
|
|
|
|
grid.Cargo.Clear();
|
|
var cargoSpecs = new[]
|
|
{
|
|
Catalog.TouringPlasma, Catalog.GoldRadiator, Catalog.GildedLance,
|
|
Catalog.NobleCore, Catalog.Recoilless, Catalog.Autocannon,
|
|
Catalog.TurboCore, Catalog.CopperRad, Catalog.WeldedPlate
|
|
};
|
|
for (int i = 0; i < cargoSpecs.Length; i++)
|
|
{
|
|
Check(grid.TryAddCargo(cargoSpecs[i]), $"Expected cargo slot #{i} ({cargoSpecs[i].Name}) to fit on Paladin");
|
|
}
|
|
|
|
if (!_main.Hud.GarageExpanded)
|
|
{
|
|
_main.Hud.ToggleGarage();
|
|
}
|
|
_main.Hud.Sync(_main.Session);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
|
|
Vector2 vpSize = GetViewport().GetVisibleRect().Size;
|
|
Rect2 blRect = _main.Hud.BottomLeftPanelRect;
|
|
Rect2 chyronRect = _main.Hud.ChyronPanelRect;
|
|
float chyronGap = chyronRect.Position.X - blRect.End.X;
|
|
GD.Print($"SMOKE INFO: Max-load Paladin Garage rect={blRect}, chyron gap={chyronGap:F1}px at {vpSize}");
|
|
|
|
Check(!_main.Hud.HasPanelOverlapOrClip(vpSize), $"Max-load Paladin Garage panels overlapped or clipped at {vpSize}");
|
|
Check(blRect.End.X <= 610f, $"Expected max-load Paladin Garage End.X <= 610px, got {blRect.End.X:F1}");
|
|
Check(!blRect.HasPoint(vpSize * 0.5f), $"Expected max-load Paladin Garage not to cover viewport center {vpSize * 0.5f}, rect={blRect}");
|
|
Check(chyronGap > 80f, $"Expected > 80px breathing room between Garage and Chyron, got {chyronGap:F1}px");
|
|
|
|
_main.Hud.ToggleGarage();
|
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
}
|
|
|
|
private static int CountPremulViolations(Image img, float tolerance)
|
|
{
|
|
int count = 0;
|
|
int w = img.GetWidth();
|
|
int h = img.GetHeight();
|
|
for (int y = 0; y < h; y++)
|
|
{
|
|
for (int x = 0; x < w; x++)
|
|
{
|
|
Color c = img.GetPixel(x, y);
|
|
float maxRgb = MathF.Max(c.R, MathF.Max(c.G, c.B));
|
|
if (maxRgb > c.A + tolerance)
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
private static int CountNonZeroAlphaPixels(Image img, float minAlpha)
|
|
{
|
|
int count = 0;
|
|
int w = img.GetWidth();
|
|
int h = img.GetHeight();
|
|
for (int y = 0; y < h; y++)
|
|
{
|
|
for (int x = 0; x < w; x++)
|
|
{
|
|
if (img.GetPixel(x, y).A > minAlpha) count++;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
private static int CountDifferentPixels(Image a, Image b, float threshold)
|
|
{
|
|
int count = 0;
|
|
int w = Math.Min(a.GetWidth(), b.GetWidth());
|
|
int h = Math.Min(a.GetHeight(), b.GetHeight());
|
|
for (int y = 0; y < h; y++)
|
|
{
|
|
for (int x = 0; x < w; x++)
|
|
{
|
|
Color ca = a.GetPixel(x, y);
|
|
Color cb = b.GetPixel(x, y);
|
|
float diff = MathF.Abs(ca.R - cb.R) + MathF.Abs(ca.G - cb.G) + MathF.Abs(ca.B - cb.B) + MathF.Abs(ca.A - cb.A);
|
|
if (diff > threshold) count++;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|