A prebuilt tool, bin/ludic-ui-preview (built by ludic-dev build, shipped beside ludic-lsp, run as `ludic ui-preview [--font DIR]`): ludic.ui with a backend that records every draw call as a line, and mock component classes the studio describes (load / model / calls). frame t runs ui_show at interface time t; text is measured on the CPU with the game's font.json metrics; locale goes through ludic.i18n; tree / box / rules inspect the frame. No game code, no GPU, no network. The wire protocol is frozen as tools/ui-preview/protocol-v1.md; smoke.txt is a transcript to run. ludic.ui gains, all additive: UiClass.make_of, UiBackend.said / emitted, UiRule.text / at (with comment line breaks kept so rule lines count true, and a class's styles read under its .lss path), and ui_root, ui_find, ui_rules_of, ui_rule_value, ui_building, ui_class, ui_class_load, ui_file_forget, ui_errors_clear; ui_nine_cuts_into exported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.2 KiB
Text
59 lines
2.2 KiB
Text
# instance.ludic - a mounted component's record (its props and state), found by where it sits in the
|
|
# tree; one that a build of its screen did not reach is gone, and its state with it
|
|
property UiInst {
|
|
key: string = ""
|
|
cls: UiClass = null
|
|
ptr: pointer = null
|
|
seen: int = 0
|
|
props: Val = null # its props, filled again each frame into the same object
|
|
model: Val = null # and its model, filled in place by the class's model()
|
|
fresh: bool = false # made, not reused: its first build makes its props and model
|
|
}
|
|
# builds before an unmounted instance is mounted again: the tree that last named it is good for two
|
|
const IN_SPARE_AFTER: int = 2
|
|
function in_get(ui_st: mut UiState, key: string, k: UiClass) -> UiInst {
|
|
for i in 0 .. len(ui_st.in_list) {
|
|
let it = ui_st.in_list[i]
|
|
if it.key == key and it.cls.name == k.name {
|
|
it.seen = ui_st.in_build
|
|
return it
|
|
}
|
|
}
|
|
let it = in_reuse(ui_st, k)
|
|
it.key = key
|
|
it.seen = ui_st.in_build
|
|
ui_kept(ui_st.in_list, it)
|
|
return it
|
|
}
|
|
# an unmounted instance of this class, put back as new, else a new one: a prompt that comes and goes
|
|
# as the player walks is mounted again without making another record, props and model each time
|
|
@alloc_ok("a component instance: made once per instance key, then kept or reused")
|
|
function in_reuse(ui_st: mut UiState, k: UiClass) -> UiInst {
|
|
let l = ui_st.in_free
|
|
for i in 0 .. len(l) {
|
|
let it = l[i]
|
|
if it.cls == k and it.cls.renew != null and ui_st.in_build - it.seen >= IN_SPARE_AFTER {
|
|
l[i] = l[len(l) - 1]
|
|
List.pop(l)
|
|
k.renew(it.ptr)
|
|
return it
|
|
}
|
|
}
|
|
let it = new UiInst
|
|
it.cls = k
|
|
if k.make_of != null { it.ptr = k.make_of(k) } else { it.ptr = k.make() }
|
|
it.fresh = true
|
|
return it
|
|
}
|
|
# after a build of `screen`: its instances the build did not reach are unmounted
|
|
function in_sweep(ui_st: mut UiState, screen: string) -> void {
|
|
var kept = 0
|
|
for i in 0 .. len(ui_st.in_list) {
|
|
let it = ui_st.in_list[i]
|
|
if it.seen == ui_st.in_build or not lc_mine(it.key, screen) {
|
|
ui_st.in_list[kept] = it
|
|
kept += 1
|
|
} else { ui_kept(ui_st.in_free, it) }
|
|
}
|
|
while len(ui_st.in_list) > kept { List.pop(ui_st.in_list) }
|
|
}
|