Add docs/ARCHITECTURE.md covering the tick rate, simulation and presentation split, command stream, entity IDs, snapshot format, seeded RNG rules, module map and performance budgets. A test scans src/sim for presentation dependencies and unseeded randomness, so the separation is enforced. Closes #3 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.5 KiB
GDScript
43 lines
1.5 KiB
GDScript
extends TestCase
|
|
|
|
## Identifiers from the engine's rendering, audio, UI and scene-tree areas.
|
|
const FORBIDDEN: Array[String] = [
|
|
"RenderingServer", "PhysicsServer3D", "AudioServer", "AudioStream", "DisplayServer",
|
|
"Node2D", "Node3D", "MeshInstance3D", "Camera3D", "Control", "CanvasItem", "Viewport",
|
|
"SceneTree", "get_tree", "Input.",
|
|
]
|
|
const NONDETERMINISTIC: Array[String] = [
|
|
"randf(", "randi(", "randf_range(", "randi_range(", "randomize(", "Time.", "OS.get_ticks",
|
|
]
|
|
|
|
|
|
func test_simulation_has_no_presentation_dependency() -> void:
|
|
_scan(FORBIDDEN)
|
|
|
|
|
|
func test_simulation_has_no_unseeded_randomness() -> void:
|
|
_scan(NONDETERMINISTIC)
|
|
|
|
|
|
func _scan(needles: Array[String]) -> void:
|
|
var paths: Array[String] = _scripts_under("res://src/sim")
|
|
assert_true(not paths.is_empty(), "expected scripts in src/sim")
|
|
for path: String in paths:
|
|
var source: String = FileAccess.get_file_as_string(path)
|
|
for needle: String in needles:
|
|
# Comments may mention these; only code counts.
|
|
for line: String in source.split("\n"):
|
|
var code: String = line.get_slice("#", 0)
|
|
if code.contains(needle):
|
|
fail("%s uses %s: %s" % [path, needle, line.strip_edges()])
|
|
|
|
|
|
func _scripts_under(dir_path: String) -> Array[String]:
|
|
var found: Array[String] = []
|
|
for name: String in DirAccess.get_files_at(dir_path):
|
|
if name.ends_with(".gd"):
|
|
found.append(dir_path.path_join(name))
|
|
for name: String in DirAccess.get_directories_at(dir_path):
|
|
found.append_array(_scripts_under(dir_path.path_join(name)))
|
|
return found
|