extends SceneTree const Controller := preload("res://world/jajce/GrassInteractionController.gd") var failures: Array[String] = [] class RestoreSource: extends Node signal state_restored func _initialize() -> void: call_deferred("_run") func _run() -> void: _check_trail_lifecycle() await _check_loaded_binding() if failures.is_empty(): print("Foliage interaction checks passed") quit(0) else: for failure in failures: push_error(failure) quit(1) func _check_trail_lifecycle() -> void: var field := FoliageTrailMap.new() var positions: Dictionary[int, Vector3] = {1: Vector3(0.25, 0, 0.25)} field.advance(0.08, Vector3.ZERO, positions) positions[1] = Vector3(2.25, 0, 0.25) field.advance(0.08, Vector3.ZERO, positions) _check(_sample(field, Vector2(1.25, 0.25)).b > 0.9, "Walking should leave a continuous trail") _check( _sample(field, Vector2(1.25, 0.75)).g > 0 and _sample(field, Vector2(1.25, -0.25)).g < 0, "The two sides of a trail should bend away from the travelled line" ) positions[1] = Vector3(18.25, 0, 0.25) field.advance(0.08, Vector3.ZERO, positions) _check(_sample(field, Vector2(10.25, 0.25)).b == 0, "Teleports must not paint connecting lines") _check( _sample(field, Vector2(18.25, 0.25)).b > 0.9, "Teleported actors still press their destination" ) field.advance(0.08, Vector3(1, 0, 1), {}) _check( _sample(field, Vector2(1.25, 0.25)).b > 0.8, "Camera movement must keep trails in world space" ) field.advance(4.0, Vector3.ZERO, {}) var recovering := _sample(field, Vector2(1.25, 0.25)).b _check(recovering > 0.1 and recovering < 0.6, "Abandoned trails should gradually recover") field.advance(4.1, Vector3.ZERO, {}) _check( (field.get("_cells") as Dictionary).is_empty(), "Recovered trails should release sparse history" ) positions[1] = Vector3(0.25, 6, 0.25) field.advance(0.08, Vector3.ZERO, positions) var elevated := _sample(field, Vector2(0.25, 0.25)) _check( is_equal_approx(elevated.a / elevated.b, 6.0), "Foot height must reach the shader for bridge rejection" ) field.advance(0.08, Vector3(300, 0, 300), {}) _check((field.get("_cells") as Dictionary).is_empty(), "Off-window trails must be discarded") positions[1] = Vector3(2.25, 0, 0.25) field.advance(0.08, Vector3.ZERO, positions) _check( _sample(field, Vector2(1.25, 0.25)).b == 0, "Re-entering actors must not connect to stale positions" ) field.clear() _check(_sample(field, Vector2(2.25, 0.25)).b == 0, "Reset must clear the uploaded field") _check( (field.get("_previous_positions") as Dictionary).is_empty(), "Reset must discard actor history" ) func _check_loaded_binding() -> void: var stage := Node3D.new() root.add_child(stage) var camera := Camera3D.new() stage.add_child(camera) camera.current = true var simulation := RestoreSource.new() simulation.name = "SimulationManager" stage.add_child(simulation) var world := Node3D.new() stage.add_child(world) var terrain := Node3D.new() world.add_child(terrain) var patch := ( load("res://world/jajce/StylizedBerryPatch.tscn").instantiate() as StylizedBerryPatch ) world.add_child(patch) patch.scale = Vector3(1.2, 0.8, 1.1) patch.rotation.y = 0.6 var controller := Controller.new() controller.grass_material = ( load("res://world/jajce/materials/cozy_grass_material.tres").duplicate(true) ) terrain.add_child(controller) var foreign := Node3D.new() root.add_child(foreign) foreign.add_to_group("grass_interactors") var actors: Array[Node3D] = [] for index in 12: var actor := Node3D.new() stage.add_child(actor) actor.position.x = 1.0 + index actor.add_to_group("grass_interactors") actors.append(actor) await process_frame controller.set_process(false) controller.call("_refresh_interactors", 0.08) var material := controller.grass_material var positions: PackedVector3Array = material.get_shader_parameter("interactor_positions") _check( int(material.get_shader_parameter("interactor_count")) == 8, "Contact work must respect the eight-actor cap" ) _check( positions[0] == actors[0].position, "A closer actor in another scene container must be rejected" ) _check( bool(material.get_shader_parameter("foliage_trails_enabled")), "Loaded grass must enable its trail field" ) var leaves := patch.get_node("Leaves") as MultiMeshInstance3D var berries := patch.get_node("Berries") as MultiMeshInstance3D var leaf_material := leaves.multimesh.mesh.surface_get_material(0) as ShaderMaterial var berry_material := berries.multimesh.mesh.surface_get_material(0) as ShaderMaterial _check( ( ( leaf_material.get_shader_parameter("foliage_trail_map") == material.get_shader_parameter("foliage_trail_map") ) and ( berry_material.get_shader_parameter("foliage_trail_map") == material.get_shader_parameter("foliage_trail_map") ) ), "Bush leaves, berries and meadow must use the same world-local footprint field" ) var visible_berries := patch.get_visible_berry_count() actors[0].hide() controller.primary_interactor_path = controller.get_path_to(actors.back()) controller.max_interactors = 4 controller.call("_refresh_interactors", 0.12) positions = material.get_shader_parameter("interactor_positions") _check( ( int(material.get_shader_parameter("interactor_count")) == 4 and positions[0].x == 12 and positions[1].x == 2 ), "Balanced must reserve the primary actor slot, cap actors and ignore hidden visuals" ) simulation.state_restored.emit() _check( not bool(material.get_shader_parameter("foliage_trails_enabled")), "Successful restores must clear visual trails immediately" ) controller.set_interaction_enabled(false) _check(not controller.is_processing(), "Low quality must stop interaction updates") _check( not bool(leaf_material.get_shader_parameter("foliage_trails_enabled")), "Low quality must release bushes as well as grass" ) _check( int(material.get_shader_parameter("interactor_count")) == 0, "Low quality must clear direct contacts" ) _check( patch.get_visible_berry_count() == visible_berries, "Contact bending must not change resource presentation amounts" ) controller.set_interaction_enabled(true) controller.call("_refresh_interactors", 0.08) _check( bool(berry_material.get_shader_parameter("foliage_trails_enabled")), "Bush interaction must resume after Low quality" ) var other_field := FoliageTrailMap.new() _check( other_field.texture != material.get_shader_parameter("foliage_trail_map"), "Each world must own a distinct trail texture" ) foreign.free() stage.free() await process_frame func _sample(field: FoliageTrailMap, position: Vector2) -> Color: var image := field.get("_image") as Image var pixel := Vector2i( (position - Vector2(field.world_rect.x, field.world_rect.y)) / field.CELL_SIZE ) return image.get_pixelv(pixel) func _check(condition: bool, message: String) -> void: if not condition: failures.append(message)