extends SceneTree
## Write the SHIPPING map's compiled density GLSL to a file, verbatim.
##
## godot --headless --path . --script res://scenes/test/dump_map_glsl.gd
##
## Whatever we conclude about the terrain has to be a conclusion about THIS
## text: it is what the GPU compiles and what every chunk's density, normal and
## edge-crossing comes out of. Reading the C++ that assembles it is a
## reconstruction, and #45 lost a session to a reconstruction that omitted the
## wrapper.
##
## The map is instantiated and read ONE FRAME LATER, because add_child from
## _initialize does not run _ready until the first process frame -- reading the
## generator before that is the false failure this gate's neighbour documents.
var MAP := "res://scenes/maps/map_dc_diffusion.tscn"
var OUT := "/tmp/map_density.glsl"
var _map: Node = null
func _initialize() -> void:
# --map <res://...> --out <path>, so the SAME dumper serves both maps and a
# diff between them is a diff of one text rather than of two scripts.
var args := OS.get_cmdline_user_args()
for i in range(args.size() - 1):
if args[i] == "--map": MAP = args[i + 1]
elif args[i] == "--out": OUT = args[i + 1]
var packed := load(MAP) as PackedScene
if packed == null:
print("FAIL — %s did not load" % MAP)
quit(2)
return
_map = packed.instantiate()
root.add_child(_map)
func _process(_dt: float) -> bool:
var gen = _map.get("_gen") if _map != null else null
if gen == null:
print("FAIL — the map has no generator after _ready")
quit(3)
return true
var gs: String = gen.get_compiled_glsl()
var f := FileAccess.open(OUT, FileAccess.WRITE)
f.store_string(gs)
f.flush()
f.close()
print("wrote %s (%d bytes)" % [OUT, gs.length()])
quit(0)
return true