diff --git a/client/Hud.cs b/client/Hud.cs index a8df0f5..385d499 100644 --- a/client/Hud.cs +++ b/client/Hud.cs @@ -75,6 +75,8 @@ public partial class Hud : CanvasLayer public bool GarageExpanded => _garageExpanded; public bool ThermalMode => _schematic.ThermalEnabled; public InventoryGridControl Schematic => _schematic; + internal Rect2 BottomLeftPanelRect => _bottomLeftPanel.GetGlobalRect(); + internal Rect2 ChyronPanelRect => _chyronPanel.GetGlobalRect(); public IEnumerable GetChromeMaterials() { @@ -89,7 +91,7 @@ public partial class Hud : CanvasLayer { _garageExpanded = !_garageExpanded; _garageDetails.Visible = _garageExpanded; - _schematic.CustomMinimumSize = _garageExpanded ? new Vector2(228f, 232f) : new Vector2(180f, 188f); + _schematic.CustomMinimumSize = _garageExpanded ? new Vector2(198f, 208f) : new Vector2(180f, 188f); _schematic.QueueRedraw(); } @@ -370,7 +372,7 @@ public partial class Hud : CanvasLayer AddChild(_bottomLeftPanel); var hbox = new HBoxContainer(); - hbox.AddThemeConstantOverride("separation", 10); + hbox.AddThemeConstantOverride("separation", 8); _bottomLeftPanel.AddChild(hbox); var leftCol = new VBoxContainer(); @@ -419,23 +421,23 @@ public partial class Hud : CanvasLayer _hoverLabel.AddThemeFontSizeOverride("font_size", 10); leftCol.AddChild(_hoverLabel); - var rightCol = new VBoxContainer { CustomMinimumSize = new Vector2(176f, 0f) }; - rightCol.AddThemeConstantOverride("separation", 4); + var rightCol = new VBoxContainer { CustomMinimumSize = new Vector2(156f, 0f) }; + rightCol.AddThemeConstantOverride("separation", 3); hbox.AddChild(rightCol); _cargoHeader = new Label { Text = "SALVAGE CARGO (0/4)" }; _cargoHeader.AddThemeColorOverride("font_color", OliveCol); - _cargoHeader.AddThemeFontSizeOverride("font_size", 12); + _cargoHeader.AddThemeFontSizeOverride("font_size", 11); rightCol.AddChild(_cargoHeader); _cargoList = new VBoxContainer(); - _cargoList.AddThemeConstantOverride("separation", 3); + _cargoList.AddThemeConstantOverride("separation", 2); 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(204f, 0f); + _garageDetails.AddThemeFontSizeOverride("font_size", 10); + _garageDetails.CustomMinimumSize = new Vector2(178f, 0f); hbox.AddChild(_garageDetails); } @@ -588,9 +590,11 @@ public partial class Hud : CanvasLayer Text = $"{(mod.IsImperial ? "★ " : "")}{mod.Name}", SizeFlagsHorizontal = Control.SizeFlags.ExpandFill, Alignment = HorizontalAlignment.Left, - FocusMode = Control.FocusModeEnum.None + FocusMode = Control.FocusModeEnum.None, + ClipText = true, + CustomMinimumSize = new Vector2(114f, 0f) }; - selectBtn.AddThemeFontSizeOverride("font_size", 11); + selectBtn.AddThemeFontSizeOverride("font_size", 10); if (_selectedCargoIndex == idx) { selectBtn.Modulate = OrangeCol; @@ -607,7 +611,7 @@ public partial class Hud : CanvasLayer row.AddChild(selectBtn); var fitBtn = new Button { Text = "FIT", FocusMode = Control.FocusModeEnum.None }; - fitBtn.AddThemeFontSizeOverride("font_size", 11); + fitBtn.AddThemeFontSizeOverride("font_size", 10); fitBtn.Pressed += () => AutoFitCargo(grid, idx); row.AddChild(fitBtn); @@ -700,13 +704,13 @@ public partial class Hud : CanvasLayer { var lines = new List { - $"CONDUCTIVITY {grid.Spec.HullConductivity:F1} | THRUST {grid.ComputeDriveThrust():F0} N", + $"COND {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}%)"); + lines.Add($"• {m.HardpointId}: {m.Spec.Name} {m.CurrentTemp:F0}°C ({(m.CurrentPerformance * 100f):F0}%)"); } return string.Join("\n", lines); } diff --git a/client/InventoryGridControl.cs b/client/InventoryGridControl.cs index 863f42e..87f5bea 100644 --- a/client/InventoryGridControl.cs +++ b/client/InventoryGridControl.cs @@ -49,6 +49,7 @@ public partial class InventoryGridControl : Control private int _gridWidth; private int _gridHeight; private ChassisGrid? _grid; + private ChassisSpec? _spec; private int _selectedCargoIndex = -1; private int _lastHitSequence = -1; @@ -205,10 +206,12 @@ public partial class InventoryGridControl : Control if (grid is null) throw new ArgumentNullException(nameof(grid)); bool gridIdentityChanged = !ReferenceEquals(_grid, grid) + || !ReferenceEquals(_spec, grid.Spec) || _gridWidth != grid.Spec.Width || _gridHeight != grid.Spec.Height; _grid = grid; + _spec = grid.Spec; _selectedCargoIndex = selectedCargoIndex; if (gridIdentityChanged) @@ -338,6 +341,7 @@ public partial class InventoryGridControl : Control } } _lastHitSequence = grid.HitSequence; + bool hadHover = _hoveredCell.HasValue; _hoveredCell = null; if (dimsChanged) @@ -354,6 +358,11 @@ public partial class InventoryGridControl : Control _material.SetShaderParameter("grid_size", new Vector2(w, h)); _material.SetShaderParameter("thermal_mode", _thermalBlend); + + if (hadHover) + { + HoverChanged?.Invoke(null, null); + } } private void DetectHits(ChassisGrid grid) @@ -398,9 +407,10 @@ public partial class InventoryGridControl : Control { if (!spec.IsActive(x, y)) { - _dataImage.SetPixel(x * 3 + 0, y, Colors.Transparent); - _dataImage.SetPixel(x * 3 + 1, y, Colors.Transparent); - _dataImage.SetPixel(x * 3 + 2, y, Colors.Transparent); + var zero = new Color(0f, 0f, 0f, 0f); + _dataImage.SetPixel(x * 3 + 0, y, zero); + _dataImage.SetPixel(x * 3 + 1, y, zero); + _dataImage.SetPixel(x * 3 + 2, y, zero); continue; } diff --git a/client/inventory_grid.gdshader b/client/inventory_grid.gdshader index 2649773..10aaa68 100644 --- a/client/inventory_grid.gdshader +++ b/client/inventory_grid.gdshader @@ -161,6 +161,10 @@ void fragment() { vec2 origin = (rect_size - grid_px) * 0.5; vec2 local_px = UV * rect_size - origin; + // Hoist derivatives and implicit-LOD texture lookup above non-uniform branches (GLSL 330 helper quads) + float aa_px = clamp(max(fwidth(UV.x) * rect_size.x, fwidth(UV.y) * rect_size.y), 0.2, 2.0); + vec4 temp_sample = texture(temp_tex, clamp(local_px / max(grid_px, vec2(1.0)), vec2(0.0), vec2(1.0))); + vec2 cellf = floor(local_px / S); if (cellf.x < 0.0 || cellf.y < 0.0 || cellf.x >= safe_grid.x || cellf.y >= safe_grid.y) { COLOR = vec4(0.0); @@ -188,9 +192,6 @@ void fragment() { bool is_damaged = (flags & 8u) != 0u; bool is_compatible = (flags & 16u) != 0u; - float aa_px = clamp(fwidth(UV.x) * rect_size.x, 0.2, 2.0); - - vec4 temp_sample = texture(temp_tex, local_px / grid_px); float norm_temp = temp_sample.r; float plateau_stress = temp_sample.g; vec3 heat_col = thermal_ramp(norm_temp); @@ -212,6 +213,7 @@ void fragment() { // Thermal plateau glow over hot cells float overheat_glow = max(plateau_stress - 0.5, 0.0) * 2.0; base_rgb += heat_col * (0.12 * norm_temp + 0.22 * overheat_glow); + base_rgb = clamp(base_rgb, vec3(0.0), vec3(1.0)); if (is_hover) { base_rgb = mix(base_rgb, vec3(0.95, 0.94, 0.88), 0.16); @@ -219,7 +221,7 @@ void fragment() { // Active hit-pulse impact flash vec3 flash_col = vec3(1.0, 0.76, 0.38); - base_rgb = mix(base_rgb, flash_col, hit_pulse * 0.85); + base_rgb = clamp(mix(base_rgb, flash_col, hit_pulse * 0.85), vec3(0.0), vec3(1.0)); vec3 accent_rgb = border_accent.rgb; if (is_damaged) { @@ -234,14 +236,15 @@ void fragment() { accent_rgb = mix(accent_rgb, vec3(1.0), 0.35); a_rules = clamp(a_rules * 1.25, 0.0, 1.0); } - accent_rgb = mix(accent_rgb, flash_col, hit_pulse * 0.90); + accent_rgb = clamp(mix(accent_rgb, flash_col, hit_pulse * 0.90), vec3(0.0), vec3(1.0)); - float icon_alpha = mix(a_rules * border_accent.a, max(a_rules * 0.26, a_pipes), thermal_mode); - vec3 pipe_rgb = mix(accent_rgb, heat_col * 1.2 + vec3(0.14), 0.72); - vec3 icon_rgb = mix(accent_rgb, pipe_rgb, thermal_mode * clamp(a_pipes * 1.2, 0.0, 1.0)); + float icon_alpha = clamp(mix(a_rules * border_accent.a, max(a_rules * 0.26, a_pipes), thermal_mode), 0.0, 1.0); + vec3 pipe_rgb = clamp(mix(accent_rgb, heat_col * 1.2 + vec3(0.14), 0.72), vec3(0.0), vec3(1.0)); + vec3 icon_rgb = clamp(mix(accent_rgb, pipe_rgb, thermal_mode * clamp(a_pipes * 1.2, 0.0, 1.0)), vec3(0.0), vec3(1.0)); - vec3 out_rgb = icon_rgb * icon_alpha + base_rgb * a_bg * (1.0 - icon_alpha); float out_a = clamp(icon_alpha + a_bg * (1.0 - icon_alpha), 0.0, 1.0); + vec3 out_rgb = min(icon_rgb * icon_alpha + base_rgb * a_bg * (1.0 - icon_alpha), vec3(out_a)); + out_rgb = max(out_rgb, vec3(0.0)); COLOR = vec4(out_rgb, out_a); } } diff --git a/client/panel_chrome.gdshader b/client/panel_chrome.gdshader index b178469..2aa8a0f 100644 --- a/client/panel_chrome.gdshader +++ b/client/panel_chrome.gdshader @@ -32,7 +32,7 @@ float box_profile(float x, float lo, float hi, float soft) { void fragment() { vec2 size = max(rect_size, vec2(4.0)); vec2 p = UV * size; - float aa = clamp(fwidth(UV.x) * size.x, 0.2, 2.0); + float aa = clamp(max(fwidth(UV.x) * size.x, fwidth(UV.y) * size.y), 0.2, 2.0); // Fold into nearest corner quadrant (1x1 cell, all 4 cardinal edges active) bool left = p.x < size.x * 0.5; @@ -45,11 +45,11 @@ void fragment() { float fy = box_profile(y, fill_inset, FAR, aa); float fill_mask = fx * fy; - // Hairline border and corner L-brackets + // Hairline border and corner L-brackets (logical thickness stays fixed in rect_size units) float ri = rule_inset; float half_w = max(border_px - 1.0, 0.0) * 0.5; - float rlo = ri - half_w * aa; - float rhi = ri + half_w * aa; + float rlo = ri - half_w; + float rhi = ri + half_w; float rx = box_profile(x, rlo, rhi, aa); float ry = box_profile(y, rlo, rhi, aa); diff --git a/client/tests/Smoke.cs b/client/tests/Smoke.cs index a5358b2..c4665fd 100644 --- a/client/tests/Smoke.cs +++ b/client/tests/Smoke.cs @@ -202,6 +202,7 @@ public partial class Smoke : Node await VerifyHudAndShadersAsync(isHeadless); await MaybeCapturePreviewAsync(isHeadless); + await VerifyMaxLoadPaladinGarageAsync(); } private async Task VerifyHudAndShadersAsync(bool isHeadless) @@ -254,6 +255,51 @@ public partial class Smoke : Node 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); @@ -307,6 +353,61 @@ public partial class Smoke : Node 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 @@ -394,6 +495,75 @@ public partial class Smoke : Node 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;