Merge remote-tracking branch 'origin/client'

This commit is contained in:
2026-02-28 23:34:36 +01:00
19 changed files with 1281 additions and 75 deletions
+5 -3
View File
@@ -55,7 +55,9 @@ func test_fog_visibility_forward_tile() -> void:
func test_fog_visibility_peripheral_tile() -> void:
# P1 #4: Peripheral-sector tile writes VIS_PERIPHERAL (180) to _vis_bytes.
# P1 #4: Server simplified to forward-only (Sprint 22, #569). All visible
# tiles are now written as VIS_FORWARD regardless of visibility_sectors value.
# Peripheral sector is no longer a distinct visual state.
var fog = _get_fog_state()
if fog == null:
return
@@ -65,8 +67,8 @@ func test_fog_visibility_peripheral_tile() -> void:
GameState.visibility_sectors = {Vector2i(10, 8): "Peripheral"}
fog.update_from_state()
assert_that(fog._vis_bytes[8 * 64 + 10]).override_failure_message(
"Peripheral tile at (10,8) should be VIS_PERIPHERAL=%d" % FogState.VIS_PERIPHERAL
).is_equal(FogState.VIS_PERIPHERAL)
"All visible tiles write VIS_FORWARD after forward-only simplification"
).is_equal(FogState.VIS_FORWARD)
GameState.visible_positions.clear()
GameState.visibility_sectors.clear()
+238
View File
@@ -0,0 +1,238 @@
## Sprint 22 — Entanglement ratio configuration acceptance tests (#175, #178)
##
## Test-first stubs for the client-side surface of the world_seed feature.
## These tests will warn-and-skip until the implementation lands (Tyre, #175).
##
## Client-side acceptance criteria (#175):
## - GameState carries a world_seed field (stores the seed for this session)
## - SessionManager.new_game() generates and stores a world_seed
## - The IPC startup payload carries world_seed so the server can seed SimRng
##
## Server-side acceptance criteria (#178) are in:
## - server/src/content/entanglement.rs (Rust unit tests)
##
## Spec: D-029 (30/50/20 entanglement ratio, variable per seed), D-010 (deterministic sim)
## Tickets: #175, #178
class_name TestEntanglementSprint22
extends GdUnitTestSuite
# -- Client-side: GameState.world_seed field (#175) ---------------------------
func test_game_state_has_world_seed_field() -> void:
# #175 client-side: GameState must store the world_seed for this session.
# The seed is set by SessionManager.new_game() and read by SimBridge to
# carry it in the session startup IPC message.
if not "world_seed" in GameState:
push_warning("TestEntanglementSprint22: GameState.world_seed not found — test-first stub (awaiting #175)")
return
# Field exists — verify it is numeric (int or null are both acceptable initial states)
var seed_val = GameState.get("world_seed")
assert_bool(seed_val == null or seed_val is int).override_failure_message(
"GameState.world_seed must be int or null"
).is_true()
func test_game_state_world_seed_can_be_set_and_read() -> void:
if not "world_seed" in GameState:
push_warning("TestEntanglementSprint22: GameState.world_seed missing — skipped (#175 not yet implemented)")
return
var orig = GameState.get("world_seed")
GameState.world_seed = 0xDEADBEEF
assert_int(GameState.world_seed).is_equal(0xDEADBEEF)
# Restore
GameState.world_seed = orig
func test_game_state_world_seed_default_is_null_or_zero() -> void:
# Before a session starts, world_seed should be null (no session) or 0 (unset).
if not "world_seed" in GameState:
push_warning("TestEntanglementSprint22: GameState.world_seed missing — skipped")
return
var seed_val = GameState.get("world_seed")
assert_bool(seed_val == null or seed_val == 0).override_failure_message(
"GameState.world_seed should be null or 0 before any session starts"
).is_true()
# -- Client-side: SessionManager seed generation (#175) -----------------------
func test_session_manager_exists() -> void:
var sm = get_node_or_null("/root/SessionManager")
if sm == null:
push_warning("TestEntanglementSprint22: SessionManager autoload not found — skipped")
return
assert_that(sm).is_not_null()
func test_session_manager_new_game_generates_world_seed() -> void:
# #175: new_game() must generate and store world_seed in GameState.
# The seed is a non-zero u64 that will be sent to the server on startup.
var sm = get_node_or_null("/root/SessionManager")
if sm == null:
push_warning("TestEntanglementSprint22: SessionManager not found — skipped")
return
if not "world_seed" in GameState:
push_warning("TestEntanglementSprint22: GameState.world_seed missing — test-first stub")
return
# Call new_game() (will create a save dir — acceptable in test environment)
var orig_seed = GameState.get("world_seed")
var orig_game_id: String = GameState.current_game_id
sm.new_game()
var generated_seed = GameState.get("world_seed")
# world_seed must have been set to a non-null, non-zero value
assert_bool(generated_seed != null).override_failure_message(
"SessionManager.new_game() must set GameState.world_seed (#175)"
).is_true()
if generated_seed != null:
assert_bool(generated_seed != 0).override_failure_message(
"Generated world_seed must be non-zero"
).is_true()
# Restore state
GameState.current_game_id = orig_game_id
GameState.world_seed = orig_seed
func test_session_manager_same_game_id_has_same_seed() -> void:
# Resuming a session must restore the original world_seed (not generate a new one).
# This ensures deterministic replays work correctly (D-010).
var sm = get_node_or_null("/root/SessionManager")
if sm == null:
push_warning("TestEntanglementSprint22: SessionManager not found — skipped")
return
if not sm.has_method("resume_game"):
push_warning("TestEntanglementSprint22: resume_game() missing — skipped")
return
if not "world_seed" in GameState:
push_warning("TestEntanglementSprint22: GameState.world_seed missing — test-first stub")
return
# Set a known seed and game_id, then resume — seed must not be clobbered
GameState.world_seed = 12345678
var orig_game_id: String = GameState.current_game_id
sm.resume_game("20260228-120000-abc123")
# resume_game() must NOT overwrite world_seed
assert_int(GameState.world_seed).override_failure_message(
"resume_game() must not overwrite world_seed — seed is loaded from the save, not regenerated"
).is_equal(12345678)
GameState.current_game_id = orig_game_id
# -- IPC startup message: world_seed field (#175) ----------------------------
func test_protocol_encode_startup_message_has_world_seed_field() -> void:
# #175 acceptance: startup IPC message must carry "world_seed" key.
# Verifies Protocol.encode_startup_message encodes the seed so the server
# can deserialize it as StartupMessage { world_seed: u64 }.
var seed: int = 0xDEADBEEF # 3735928559 — fits in u32, safely maps to Rust u64
var bytes: PackedByteArray = Protocol.encode_startup_message(seed)
assert_bool(bytes.size() > 0).override_failure_message(
"Protocol.encode_startup_message must return non-empty bytes"
).is_true()
var decoded = Messagepack.decode(bytes)
assert_that(decoded.status).override_failure_message(
"encode_startup_message output must be valid msgpack: %s" % str(decoded.status)
).is_null()
var msg = decoded.value
assert_bool(msg is Dictionary and msg.has("world_seed")).override_failure_message(
"StartupMessage wire payload must contain 'world_seed' key, got: %s" % str(msg)
).is_true()
assert_int(msg["world_seed"]).override_failure_message(
"world_seed must round-trip through msgpack unchanged"
).is_equal(seed)
func test_protocol_encode_startup_message_zero_seed() -> void:
# Edge case: seed=0 must still encode a valid payload (world_seed: 0).
var bytes: PackedByteArray = Protocol.encode_startup_message(0)
assert_bool(bytes.size() > 0).is_true()
var decoded = Messagepack.decode(bytes)
assert_that(decoded.status).is_null()
assert_int(decoded.value["world_seed"]).is_equal(0)
func test_sim_bridge_can_send_world_seed_in_startup() -> void:
# #175 acceptance: "startup IPC message carries a world_seed field"
# The client must be able to include world_seed in the session startup payload.
# Test-first: verify the API exists (method or field), else warn-and-skip.
var sim_bridge = get_node_or_null("/root/SimBridge")
if sim_bridge == null:
push_warning("TestEntanglementSprint22: SimBridge not found — skipped")
return
# Option A: SimBridge has a world_seed property that is sent during startup
if "world_seed" in sim_bridge:
sim_bridge.world_seed = 99999
assert_int(sim_bridge.world_seed).is_equal(99999)
sim_bridge.world_seed = 0
return
# Option B: SimBridge has a set_world_seed() method
if sim_bridge.has_method("set_world_seed"):
# Method exists — this is the expected API
sim_bridge.set_world_seed(99999)
return
# Neither found — test-first stub
push_warning(
"TestEntanglementSprint22: SimBridge has no world_seed field or set_world_seed() — " +
"test-first stub awaiting #175 implementation"
)
# -- Protocol: world_seed flows from client to server (#175) ------------------
func test_apply_snapshot_does_not_clobber_world_seed() -> void:
# world_seed is set at session start and must persist across all subsequent snapshots.
# Snapshots must not overwrite or clear the world_seed that was set at startup.
if not "world_seed" in GameState:
push_warning("TestEntanglementSprint22: GameState.world_seed missing — test-first stub")
return
GameState.world_seed = 42000
GameState.apply_snapshot({"tick": 5, "visible_tiles": []})
assert_int(GameState.world_seed).override_failure_message(
"apply_snapshot() must not clear or overwrite world_seed — seed is set once at session start"
).is_equal(42000)
GameState.world_seed = null
# -- Seed variation property (#178, informational — full test is Rust-side) ---
func test_different_seeds_produce_different_configs_informational() -> void:
# D-029: "entanglement rate varies per seed to prevent metagaming calibration"
# The definitive acceptance test for this is Rust-side (server/src/content/entanglement.rs):
# - EntanglementConfig::from_rng(seed_A) == EntanglementConfig::from_rng(seed_A) [deterministic]
# - EntanglementConfig::from_rng(seed_A) != EntanglementConfig::from_rng(seed_B) [variable, >=90%]
#
# This test only verifies the client side: world_seed is a u64 large enough to
# have sufficient entropy. A 24-bit game_id hex component alone has 16M combinations;
# the full u64 seed provides 2^64 possibilities.
#
# We verify that two calls to new_game() produce different seeds.
var sm = get_node_or_null("/root/SessionManager")
if sm == null:
push_warning("TestEntanglementSprint22: SessionManager not found — skipped")
return
if not "world_seed" in GameState:
push_warning("TestEntanglementSprint22: GameState.world_seed missing — test-first stub")
return
var orig_game_id: String = GameState.current_game_id
sm.new_game()
var seed_a = GameState.get("world_seed")
sm.new_game()
var seed_b = GameState.get("world_seed")
if seed_a == null or seed_b == null:
push_warning("TestEntanglementSprint22: new_game() did not set world_seed — test-first stub")
GameState.current_game_id = orig_game_id
return
# Two different sessions should produce different seeds
assert_bool(seed_a != seed_b).override_failure_message(
"Two calls to new_game() must produce different world_seeds (D-029 anti-metagaming)"
).is_true()
GameState.current_game_id = orig_game_id
+517
View File
@@ -0,0 +1,517 @@
## Sprint 22 — Fog system acceptance tests (#569)
##
## Validates FogState data management against the Sprint 22 acceptance criteria:
## - Explored tiles never revert to unexplored black (EXP_EXPLORED persistence)
## - Bounds grow-only invariant (explored tiles behind player stay in texture)
## - All visible tiles written as Forward (server simplified to Forward-only)
## - Exploration data survives texture resize (grow-only bounds copy)
## - Shader file present with correct fog_alpha constant
##
## Spec: D-059 (fog shader), D-015 (vision cone), D-066 (dual-scale grid, 6-8 tile gradient)
## Ticket: #569
class_name TestFogSprint22
extends GdUnitTestSuite
func _get_fog_state() -> Node:
var node = get_node_or_null("/root/FogState")
if node == null:
push_warning("TestFogSprint22: FogState autoload not found — test skipped (awaiting #569)")
return node
func before_test() -> void:
GameState.visible_positions.clear()
GameState.visible_tiles.clear()
GameState.visibility_sectors.clear()
func after_test() -> void:
GameState.visible_positions.clear()
GameState.visible_tiles.clear()
GameState.visibility_sectors.clear()
# -- Spec constants (D-059) ---------------------------------------------------
func test_exp_explored_constant_is_128() -> void:
# EXP_EXPLORED = 128 → shader reads this as ~0.502.
# smoothstep(0.0, 0.2, 0.502) = 1.0 → exp_fade fully applied.
# If EXP_EXPLORED were 0, explored tiles would render as solid unexplored black.
var fog_state = _get_fog_state()
if fog_state == null:
return
assert_int(fog_state.EXP_EXPLORED).override_failure_message(
"EXP_EXPLORED must be 128 — shader exp_fade requires explored value > 0.2 to avoid unexplored-black rendering"
).is_equal(128)
func test_exp_unexplored_constant_is_0() -> void:
var fog_state = _get_fog_state()
if fog_state == null:
return
assert_int(fog_state.EXP_UNEXPLORED).is_equal(0)
func test_exp_visible_constant_is_255() -> void:
# EXP_VISIBLE = 255 → shader reads 1.0, full art visibility (currently in LOS)
var fog_state = _get_fog_state()
if fog_state == null:
return
assert_int(fog_state.EXP_VISIBLE).is_equal(255)
func test_vis_forward_constant_is_255() -> void:
# D-059: VIS_FORWARD = 255 → clear vision, nearly transparent fog overlay
var fog_state = _get_fog_state()
if fog_state == null:
return
assert_int(fog_state.VIS_FORWARD).is_equal(255)
func test_vis_hidden_constant_is_0() -> void:
# D-059: VIS_HIDDEN = 0 → no vision, fog fully opaque
var fog_state = _get_fog_state()
if fog_state == null:
return
assert_int(fog_state.VIS_HIDDEN).is_equal(0)
func test_unexplored_color_spec_value() -> void:
# D-059: Unexplored = solid near-black #12141a
# Verify the hex value decodes to the expected channel values.
var c := Color("#12141a")
assert_float(c.r).is_equal_approx(18.0 / 255.0, 0.003)
assert_float(c.g).is_equal_approx(20.0 / 255.0, 0.003)
assert_float(c.b).is_equal_approx(26.0 / 255.0, 0.003)
# Sanity: it IS very dark (all channels < 0.12)
assert_float(c.r).is_less(0.12)
assert_float(c.g).is_less(0.12)
assert_float(c.b).is_less(0.12)
# -- Acceptance: explored tiles persist after leaving LOS (criterion 3) ------
func test_explored_tile_becomes_exp_explored_after_leaving_los() -> void:
# ACCEPTANCE CRITERION: "Explored tiles never revert to unexplored black"
# When tile (5,5) was in LOS (frame 1) and then leaves LOS (frame 2),
# its exploration byte must be EXP_EXPLORED (128), not EXP_UNEXPLORED (0).
var fog_state = _get_fog_state()
if fog_state == null:
return
if not fog_state.has_method("update_from_state"):
push_warning("TestFogSprint22: update_from_state missing — skipped")
return
# Frame 1: tile (5,5) is visible
GameState.visible_positions = {Vector2i(5, 5): true}
GameState.visible_tiles = [{"x": 5, "y": 5, "z": 0, "visibility": "Forward"}]
fog_state.update_from_state()
# Frame 2: tile (5,5) leaves LOS
GameState.visible_positions.clear()
GameState.visible_tiles = []
fog_state.update_from_state()
# Internal state check: _exp_bytes[tile(5,5)] must be EXP_EXPLORED (128)
var exp_bytes = fog_state.get("_exp_bytes")
if exp_bytes == null:
push_warning("TestFogSprint22: _exp_bytes not accessible — data path untestable headlessly")
return
var ox: int = fog_state.map_bounds.position.x
var oy: int = fog_state.map_bounds.position.y
var w: int = fog_state.get("_width") if fog_state.get("_width") != null else -1
if w <= 0:
push_warning("TestFogSprint22: _width inaccessible — data path untestable")
return
var px := 5 - ox
var py := 5 - oy
if px < 0 or py < 0 or px >= w:
push_warning("TestFogSprint22: tile (5,5) out of bounds after update — check grow_bounds margin")
return
var idx := py * w + px
if idx < 0 or idx >= exp_bytes.size():
push_warning("TestFogSprint22: idx %d out of exp_bytes range %d" % [idx, exp_bytes.size()])
return
assert_int(exp_bytes[idx]).override_failure_message(
"Tile (5,5) must be EXP_EXPLORED=128 after leaving LOS — not EXP_UNEXPLORED=0 (#569 regression)"
).is_equal(fog_state.EXP_EXPLORED)
func test_explored_tile_is_exp_visible_while_in_los() -> void:
# While in LOS, tile exploration byte must be EXP_VISIBLE (255)
var fog_state = _get_fog_state()
if fog_state == null:
return
if not fog_state.has_method("update_from_state"):
return
GameState.visible_positions = {Vector2i(3, 3): true}
GameState.visible_tiles = [{"x": 3, "y": 3, "z": 0, "visibility": "Forward"}]
fog_state.update_from_state()
var exp_bytes = fog_state.get("_exp_bytes")
if exp_bytes == null:
return
var ox: int = fog_state.map_bounds.position.x
var oy: int = fog_state.map_bounds.position.y
var w: int = fog_state.get("_width") if fog_state.get("_width") != null else -1
if w <= 0:
return
var px := 3 - ox
var py := 3 - oy
if px < 0 or py < 0 or px >= w:
return
var idx := py * w + px
if idx >= 0 and idx < exp_bytes.size():
assert_int(exp_bytes[idx]).is_equal(fog_state.EXP_VISIBLE)
func test_unexplored_tile_stays_exp_unexplored() -> void:
# Tile (7, 8) was never seen — must remain EXP_UNEXPLORED (0)
var fog_state = _get_fog_state()
if fog_state == null:
return
if not fog_state.has_method("update_from_state"):
return
# See only (5, 5) — tile (7, 8) is not in LOS
GameState.visible_positions = {Vector2i(5, 5): true}
GameState.visible_tiles = [{"x": 5, "y": 5, "z": 0, "visibility": "Forward"}]
fog_state.update_from_state()
var exp_bytes = fog_state.get("_exp_bytes")
if exp_bytes == null:
return
var ox: int = fog_state.map_bounds.position.x
var oy: int = fog_state.map_bounds.position.y
var w: int = fog_state.get("_width") if fog_state.get("_width") != null else -1
if w <= 0:
return
var px := 7 - ox
var py := 8 - oy
if px < 0 or py < 0 or px >= w:
return
var idx := py * w + px
if idx >= 0 and idx < exp_bytes.size():
assert_int(exp_bytes[idx]).is_equal(fog_state.EXP_UNEXPLORED)
# -- Acceptance: bounds grow-only invariant ------------------------------------
func test_bounds_never_shrink() -> void:
# ACCEPTANCE CRITERION: "Explored tiles never revert to unexplored black"
# Requires grow-only bounds: once a tile is in the texture, it stays there.
var fog_state = _get_fog_state()
if fog_state == null:
return
if not fog_state.has_method("update_from_state"):
return
# Frame 1: see (10, 10) → establishes initial bounds
GameState.visible_positions = {Vector2i(10, 10): true}
GameState.visible_tiles = [{"x": 10, "y": 10, "z": 0, "visibility": "Forward"}]
fog_state.update_from_state()
var b1: Rect2i = fog_state.map_bounds
# Frame 2: see (30, 30) → bounds must expand to include both
GameState.visible_positions = {Vector2i(30, 30): true}
GameState.visible_tiles = [{"x": 30, "y": 30, "z": 0, "visibility": "Forward"}]
fog_state.update_from_state()
var b2: Rect2i = fog_state.map_bounds
# Frame 3: back to (10, 10) → bounds must NOT shrink
GameState.visible_positions = {Vector2i(10, 10): true}
GameState.visible_tiles = [{"x": 10, "y": 10, "z": 0, "visibility": "Forward"}]
fog_state.update_from_state()
var b3: Rect2i = fog_state.map_bounds
assert_bool(b2.size.x >= b1.size.x).override_failure_message(
"Bounds must grow when player moves to larger region"
).is_true()
assert_bool(b2.size.y >= b1.size.y).is_true()
assert_bool(b3.size.x >= b2.size.x).override_failure_message(
"Bounds must not shrink when player returns to previous position (grow-only invariant)"
).is_true()
assert_bool(b3.size.y >= b2.size.y).is_true()
func test_bounds_include_margin_for_gradient_bleed() -> void:
# D-066: 6-8 tile gradient at cone edge requires texture margin.
# _grow_bounds adds 8-tile margin on each side (accommodates 7x7 Gaussian
# kernel at 2-texel intervals = ±6 tile reach). After seeing (10,10),
# bounds should extend at least 4 tiles beyond the visible tile.
var fog_state = _get_fog_state()
if fog_state == null:
return
if not fog_state.has_method("update_from_state"):
return
GameState.visible_positions = {Vector2i(10, 10): true}
GameState.visible_tiles = [{"x": 10, "y": 10, "z": 0, "visibility": "Forward"}]
fog_state.update_from_state()
var b: Rect2i = fog_state.map_bounds
# With 4-tile margin: bounds.position.x <= 10 - 4 = 6
assert_bool(b.position.x <= 6).override_failure_message(
"FogState bounds must include 4-tile margin for gradient bleed (D-066 gradient spec)"
).is_true()
assert_bool(b.position.y <= 6).is_true()
# -- Acceptance: Forward-only visibility (Sprint 22 server simplification) ----
func test_visible_tiles_written_as_vis_forward() -> void:
# Sprint 22: server sends only Forward tiles (Peripheral sector removed).
# FogState writes VIS_FORWARD (255) for all tiles in visible_positions.
var fog_state = _get_fog_state()
if fog_state == null:
return
if not fog_state.has_method("update_from_state"):
return
GameState.visible_positions = {Vector2i(5, 5): true, Vector2i(6, 5): true}
GameState.visible_tiles = [
{"x": 5, "y": 5, "z": 0, "visibility": "Forward"},
{"x": 6, "y": 5, "z": 0, "visibility": "Forward"},
]
fog_state.update_from_state()
var vis_bytes = fog_state.get("_vis_bytes")
if vis_bytes == null:
return
var ox: int = fog_state.map_bounds.position.x
var oy: int = fog_state.map_bounds.position.y
var w: int = fog_state.get("_width") if fog_state.get("_width") != null else -1
if w <= 0:
return
for pos in [Vector2i(5, 5), Vector2i(6, 5)]:
var px := pos.x - ox
var py := pos.y - oy
if px < 0 or py < 0 or px >= w:
continue
var idx := py * w + px
if idx >= 0 and idx < vis_bytes.size():
assert_int(vis_bytes[idx]).override_failure_message(
"All visible tiles should be VIS_FORWARD=255 — server is Forward-only in Sprint 22"
).is_equal(fog_state.VIS_FORWARD)
func test_tiles_outside_los_written_as_vis_hidden() -> void:
# Tiles in bounds but not in visible_positions must be VIS_HIDDEN (0)
var fog_state = _get_fog_state()
if fog_state == null:
return
if not fog_state.has_method("update_from_state"):
return
GameState.visible_positions = {Vector2i(5, 5): true}
GameState.visible_tiles = [{"x": 5, "y": 5, "z": 0, "visibility": "Forward"}]
fog_state.update_from_state()
# (5, 7) is inside the padded bounds but not visible — must be VIS_HIDDEN
var vis_bytes = fog_state.get("_vis_bytes")
if vis_bytes == null:
return
var ox: int = fog_state.map_bounds.position.x
var oy: int = fog_state.map_bounds.position.y
var w: int = fog_state.get("_width") if fog_state.get("_width") != null else -1
if w <= 0:
return
var px := 5 - ox
var py := 7 - oy
if px >= 0 and py >= 0 and px < w:
var idx := py * w + px
if idx >= 0 and idx < vis_bytes.size():
assert_int(vis_bytes[idx]).is_equal(fog_state.VIS_HIDDEN)
# -- Acceptance: exploration survives texture resize --------------------------
func test_exploration_data_preserved_across_bounds_growth() -> void:
# D-059: Texture resize must copy old exploration bytes into new texture.
# Without this, tiles seen before a resize appear as EXP_UNEXPLORED (black).
var fog_state = _get_fog_state()
if fog_state == null:
return
if not fog_state.has_method("update_from_state"):
return
# Frame 1: see (5, 5), then leave
GameState.visible_positions = {Vector2i(5, 5): true}
GameState.visible_tiles = [{"x": 5, "y": 5, "z": 0, "visibility": "Forward"}]
fog_state.update_from_state()
GameState.visible_positions.clear()
GameState.visible_tiles = []
fog_state.update_from_state() # (5,5) → EXP_EXPLORED
# Frame 2: move far away — forces bounds growth (resize)
GameState.visible_positions = {Vector2i(80, 80): true}
GameState.visible_tiles = [{"x": 80, "y": 80, "z": 0, "visibility": "Forward"}]
fog_state.update_from_state()
# (5,5) must still be EXP_EXPLORED after the resize
var exp_bytes = fog_state.get("_exp_bytes")
if exp_bytes == null:
return
var ox: int = fog_state.map_bounds.position.x
var oy: int = fog_state.map_bounds.position.y
var w: int = fog_state.get("_width") if fog_state.get("_width") != null else -1
if w <= 0:
return
var px := 5 - ox
var py := 5 - oy
if px < 0 or py < 0 or px >= w:
push_warning("TestFogSprint22: (5,5) not in bounds after resize — is copy-on-resize working?")
return
var idx := py * w + px
if idx >= 0 and idx < exp_bytes.size():
assert_int(exp_bytes[idx]).override_failure_message(
"Exploration data at (5,5) must survive bounds growth — EXP_EXPLORED (128) expected after resize"
).is_greater_equal(fog_state.EXP_EXPLORED)
# -- Shader file checks (D-059) -----------------------------------------------
func test_fog_gdshader_exists() -> void:
assert_bool(ResourceLoader.exists("res://shaders/fog.gdshader")).override_failure_message(
"fog.gdshader must exist — fog rendering requires this shader file (#569)"
).is_true()
func test_fog_shader_defines_fog_alpha() -> void:
# D-059: explored fog overlay must be ~25-30% opacity.
# fog_alpha constant controls this. Verify the shader defines it.
if not ResourceLoader.exists("res://shaders/fog.gdshader"):
push_warning("TestFogSprint22: fog.gdshader not found — shader check skipped")
return
var source := FileAccess.get_file_as_string("res://shaders/fog.gdshader")
if source.is_empty():
push_warning("TestFogSprint22: fog.gdshader is empty or unreadable")
return
assert_bool(source.contains("fog_alpha")).override_failure_message(
"fog.gdshader must define fog_alpha for the 25-30%% explored-tile overlay (D-059)"
).is_true()
func test_fog_shader_defines_smoothstep_clarity_ramp() -> void:
# D-059/D-066: smooth gradient requires a clarity ramp (smoothstep).
# The blurred visibility → clarity ramp must use smoothstep for smooth gradients.
if not ResourceLoader.exists("res://shaders/fog.gdshader"):
push_warning("TestFogSprint22: fog.gdshader not found — skipped")
return
var source := FileAccess.get_file_as_string("res://shaders/fog.gdshader")
if source.is_empty():
return
assert_bool(source.contains("smoothstep")).override_failure_message(
"fog.gdshader must use smoothstep for the clarity ramp — hard steps violate D-066 gradient spec"
).is_true()
func test_fog_shader_defines_unexplored_color() -> void:
# D-059: unexplored = solid near-black #12141a.
if not ResourceLoader.exists("res://shaders/fog.gdshader"):
push_warning("TestFogSprint22: fog.gdshader not found — skipped")
return
var source := FileAccess.get_file_as_string("res://shaders/fog.gdshader")
if source.is_empty():
return
assert_bool(source.contains("UNEXPLORED_COLOR")).override_failure_message(
"fog.gdshader must define UNEXPLORED_COLOR constant (D-059 #12141a spec)"
).is_true()
func test_fog_shader_uses_gaussian_blur_for_gradient() -> void:
# D-066: 6-8 tile soft gradient requires Gaussian blur on visibility texture.
# Current implementation: 7x7 kernel at 2-texel intervals (±6 tiles), sigma 2.0
# in kernel space = 4.0 tiles effective. At 2-sigma (8 tiles), weight drops to 0.14.
# This covers the D-066 "6-8 tile" gradient spec.
if not ResourceLoader.exists("res://shaders/fog.gdshader"):
push_warning("TestFogSprint22: fog.gdshader not found — skipped")
return
var source := FileAccess.get_file_as_string("res://shaders/fog.gdshader")
if source.is_empty():
return
# 7x7 Gaussian uses dy from -3 to 3
assert_bool(source.contains("sample_visibility")).override_failure_message(
"fog.gdshader must call sample_visibility() for Gaussian-blurred visibility (D-066 gradient)"
).is_true()
assert_bool(source.contains("-3.0")).override_failure_message(
"fog.gdshader sample_visibility must use 7x7 kernel (±3 tiles) for 6-tile gradient coverage (D-066)"
).is_true()
# -- Regression: GameState visible_positions (existing contract) ---------------
func test_visible_positions_derived_from_visible_tiles_in_server_mode() -> void:
# D-020: In real server mode, visible_positions derives from visible_tiles.
# Fog rendering depends on this derivation being correct.
GameState.apply_snapshot({
"tick": 10,
"visible_tiles": [
{"x": 7, "y": 7, "z": 0, "visibility": "Forward"},
{"x": 8, "y": 7, "z": 0, "visibility": "Forward"},
],
})
assert_bool(GameState.visible_positions.has(Vector2i(7, 7))).override_failure_message(
"visible_positions must be derived from visible_tiles when no explicit visible_positions key"
).is_true()
assert_bool(GameState.visible_positions.has(Vector2i(8, 7))).is_true()
func test_visibility_sectors_populated_forward_only() -> void:
# D-015: visibility_sectors must be populated from visible_tiles.
# In Forward-only mode, all sectors are "Forward".
GameState.apply_snapshot({
"tick": 11,
"visible_tiles": [
{"x": 4, "y": 4, "z": 0, "visibility": "Forward"},
],
})
assert_bool(GameState.visibility_sectors.has(Vector2i(4, 4))).is_true()
assert_str(GameState.visibility_sectors[Vector2i(4, 4)]).is_equal("Forward")
func test_visible_positions_cleared_on_new_snapshot() -> void:
# Old positions from tick N must not persist to tick N+1
GameState.apply_snapshot({
"tick": 1,
"visible_tiles": [{"x": 5, "y": 5, "z": 0, "visibility": "Forward"}],
})
assert_int(GameState.visible_positions.size()).is_equal(1)
GameState.apply_snapshot({
"tick": 2,
"visible_tiles": [{"x": 10, "y": 10, "z": 0, "visibility": "Forward"}],
})
assert_bool(GameState.visible_positions.has(Vector2i(5, 5))).override_failure_message(
"Old visible positions must be cleared when new visible_tiles arrive"
).is_false()
assert_bool(GameState.visible_positions.has(Vector2i(10, 10))).is_true()
# -- Performance (D-059) -------------------------------------------------------
func test_fog_state_update_under_2ms_for_400_tiles() -> void:
# D-059: <1ms/frame CPU budget for fog update. Allow 2x margin for test env.
var fog_state = _get_fog_state()
if fog_state == null:
return
if not fog_state.has_method("update_from_state"):
return
var positions: Dictionary = {}
var tiles: Array = []
for x in range(20):
for y in range(20):
positions[Vector2i(x, y)] = true
tiles.append({"x": x, "y": y, "z": 0, "visibility": "Forward"})
GameState.visible_positions = positions
GameState.visible_tiles = tiles
var start := Time.get_ticks_usec()
fog_state.update_from_state()
var elapsed_ms := (Time.get_ticks_usec() - start) / 1000.0
assert_float(elapsed_ms).override_failure_message(
"FogState.update_from_state() must complete in <2ms for 400 tiles (spec: <1ms D-059)"
).is_less(2.0)