rnd(M03): add rendered ground query facade
This commit is contained in:
@@ -5,6 +5,7 @@ extends SceneTree
|
||||
const WORLD_RENDER_FACADE_SCRIPT := preload("res://src/render/world_render_facade.gd")
|
||||
const GODOT_WORLD_POSITION_SCRIPT := preload("res://src/domain/coordinates/godot_world_position.gd")
|
||||
const STREAMING_FOCUS_SCRIPT := preload("res://src/domain/streaming/streaming_focus.gd")
|
||||
const RENDERED_GROUND_SAMPLE_SCRIPT := preload("res://src/render/terrain/rendered_ground_sample.gd")
|
||||
|
||||
const RUNTIME_SCENE_PATHS: Array[String] = [
|
||||
"res://src/scenes/streaming/eastern_kingdoms_streaming.tscn",
|
||||
@@ -15,12 +16,19 @@ const TOOL_PATHS: Array[String] = [
|
||||
"res://src/tools/probe_render_camera_occluders.gd",
|
||||
"res://src/tools/probe_render_terrain_height.gd",
|
||||
]
|
||||
const STREAMING_WORLD_LOADER_PATH := "res://src/scenes/streaming/streaming_world_loader.gd"
|
||||
|
||||
|
||||
class StreamingWorldLoaderDouble extends Node:
|
||||
var current_focus: StreamingFocus
|
||||
var refresh_count := 0
|
||||
var metrics := {"tiles": 2, "queues": {"tile": 1}}
|
||||
var ground_sample: RefCounted = RENDERED_GROUND_SAMPLE_SCRIPT.available(42.25)
|
||||
var ground_snapshot := {
|
||||
"status": "sampled",
|
||||
"terrain_height": 42.25,
|
||||
"diagnostic": {"state_present": true},
|
||||
}
|
||||
|
||||
func set_streaming_focus(streaming_focus: StreamingFocus) -> void:
|
||||
current_focus = streaming_focus
|
||||
@@ -32,9 +40,16 @@ class StreamingWorldLoaderDouble extends Node:
|
||||
func render_baseline_snapshot() -> Dictionary:
|
||||
return metrics
|
||||
|
||||
func sample_rendered_ground_height(_godot_world_position: GodotWorldPosition) -> RefCounted:
|
||||
return ground_sample
|
||||
|
||||
func render_ground_query_snapshot(_godot_world_position: GodotWorldPosition) -> Dictionary:
|
||||
return ground_snapshot
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
var failures: Array[String] = []
|
||||
_verify_rendered_ground_sample_contract(failures)
|
||||
await _verify_delegation_and_snapshot_isolation(failures)
|
||||
_verify_repository_wiring(failures)
|
||||
|
||||
@@ -44,10 +59,26 @@ func _initialize() -> void:
|
||||
quit(1)
|
||||
return
|
||||
|
||||
print("WORLD_RENDER_FACADE PASS delegation=3 runtime_scenes=2 tools=3")
|
||||
print("WORLD_RENDER_FACADE PASS delegation=5 ground_contract=2 runtime_scenes=2 tools=3")
|
||||
quit(0)
|
||||
|
||||
|
||||
func _verify_rendered_ground_sample_contract(failures: Array[String]) -> void:
|
||||
var non_finite_sample = RENDERED_GROUND_SAMPLE_SCRIPT.available(INF)
|
||||
_expect_true(not non_finite_sample.is_available, "non-finite rendered ground is unavailable", failures)
|
||||
_expect_true(
|
||||
non_finite_sample.failure_code == &"render_terrain_height_not_finite",
|
||||
"non-finite rendered ground failure code",
|
||||
failures
|
||||
)
|
||||
var default_unavailable_sample = RENDERED_GROUND_SAMPLE_SCRIPT.unavailable(&"")
|
||||
_expect_true(
|
||||
default_unavailable_sample.failure_code == &"render_terrain_unavailable",
|
||||
"empty rendered ground failure code normalizes",
|
||||
failures
|
||||
)
|
||||
|
||||
|
||||
func _verify_delegation_and_snapshot_isolation(failures: Array[String]) -> void:
|
||||
var test_root := Node.new()
|
||||
var loader := StreamingWorldLoaderDouble.new()
|
||||
@@ -82,6 +113,24 @@ func _verify_delegation_and_snapshot_isolation(failures: Array[String]) -> void:
|
||||
(snapshot["queues"] as Dictionary)["tile"] = 999
|
||||
_expect_true(int(loader.metrics.tiles) == 2, "top-level metrics are detached", failures)
|
||||
_expect_true(int(loader.metrics.queues.tile) == 1, "nested metrics are detached", failures)
|
||||
|
||||
var query_position = GODOT_WORLD_POSITION_SCRIPT.new(100.0, 200.0, 300.0)
|
||||
var ground_sample: RefCounted = facade.sample_ground_height(query_position)
|
||||
_expect_true(ground_sample.is_available, "rendered ground sample delegates", failures)
|
||||
_expect_near(ground_sample.height_units, 42.25, "rendered ground height", failures)
|
||||
loader.ground_sample = RENDERED_GROUND_SAMPLE_SCRIPT.unavailable(&"render_terrain_mesh_not_ready")
|
||||
var unavailable_ground_sample: RefCounted = facade.sample_ground_height(query_position)
|
||||
_expect_true(not unavailable_ground_sample.is_available, "unavailable ground sample delegates", failures)
|
||||
_expect_true(
|
||||
unavailable_ground_sample.failure_code == &"render_terrain_mesh_not_ready",
|
||||
"ground failure code delegates",
|
||||
failures
|
||||
)
|
||||
var ground_snapshot: Dictionary = facade.renderer_ground_query_snapshot(query_position)
|
||||
ground_snapshot["terrain_height"] = 999.0
|
||||
(ground_snapshot["diagnostic"] as Dictionary)["state_present"] = false
|
||||
_expect_near(float(loader.ground_snapshot.terrain_height), 42.25, "ground snapshot top-level detached", failures)
|
||||
_expect_true(bool(loader.ground_snapshot.diagnostic.state_present), "ground snapshot nested detached", failures)
|
||||
test_root.queue_free()
|
||||
|
||||
|
||||
@@ -98,6 +147,44 @@ func _verify_repository_wiring(failures: Array[String]) -> void:
|
||||
_expect_true(not tool_source.contains('world.call("refresh_streaming_focus"'), "%s avoids direct streamer refresh" % tool_path, failures)
|
||||
_expect_true(not tool_source.contains('world.set("streaming_focus_source_path"'), "%s avoids direct streamer focus config" % tool_path, failures)
|
||||
|
||||
var terrain_probe_source := _read_text("res://src/tools/probe_render_terrain_height.gd", failures)
|
||||
_expect_true(
|
||||
terrain_probe_source.contains('"renderer_ground_query_snapshot"'),
|
||||
"terrain probe delegates ground diagnostics",
|
||||
failures
|
||||
)
|
||||
_expect_true(
|
||||
not terrain_probe_source.contains('world.get("_'),
|
||||
"terrain probe avoids private streamer state",
|
||||
failures
|
||||
)
|
||||
for forbidden_probe_text in [
|
||||
"_tile_states",
|
||||
"_tile_load_queue",
|
||||
"_tile_loading_tasks",
|
||||
"_available_tiles",
|
||||
"generate_triangle_mesh",
|
||||
]:
|
||||
_expect_true(
|
||||
not terrain_probe_source.contains(forbidden_probe_text),
|
||||
"terrain probe omits %s" % forbidden_probe_text,
|
||||
failures
|
||||
)
|
||||
|
||||
var loader_source := _read_text(STREAMING_WORLD_LOADER_PATH, failures)
|
||||
for required_loader_text in [
|
||||
"func sample_rendered_ground_height(godot_world_position: GodotWorldPosition)",
|
||||
"func render_ground_query_snapshot(godot_world_position: GodotWorldPosition)",
|
||||
"RENDER_GROUND_QUERY_RAY_HEIGHT_UNITS := 5000.0",
|
||||
"for radius_units in [2.0, 5.0, 10.0, 20.0, 40.0]",
|
||||
"generate_triangle_mesh()",
|
||||
]:
|
||||
_expect_true(
|
||||
loader_source.contains(required_loader_text),
|
||||
"streamer ground query retains %s" % required_loader_text,
|
||||
failures
|
||||
)
|
||||
|
||||
|
||||
func _read_text(path: String, failures: Array[String]) -> String:
|
||||
var file := FileAccess.open(path, FileAccess.READ)
|
||||
|
||||
Reference in New Issue
Block a user