Closes the two open issues and lands the pending unreleased batch: - #90: `Sprite { atlas: 1 }` routes esys_sprite through atlas_draw_ex (scale/flip/tint), so cell / cell_span / strip ids of any size draw through the engine sprite-render system. examples/library/sprite_atlas is the pixel-readback regression. - #91: `become` from an @On(Event) listener / global handler / plain function no longer segfaults the compiler; it emits @L_scene_leave() (a dispatch on the live scene id) so the leaving scene's on-exit runs. UI_* handles are readable from any code (widget table built on first use). examples/library/scene_menus covers it. - fix: a windowed `ludicc -o` build that reaches the audio runtime only through the atlas/Assets preload import now links audio.ll + AVFoundation (the audio backend link was gated on a game-level Audio.* call, so any windowed game declaring Sprite failed to link). - the hand-written "Unreleased" CHANGELOG section is converted to changesets under changes/ so `x release` generates it. - plus the batch: engine-driven retained UI + UiClicked event, Overlay phase, TileSkin tilemap-render system, Key.* constants, Font/Ui/File namespaces, Sprite.strip, prefabs, managers, countdown fields, enum-typed machines, layer @Queries, ludic.prefs / ludic.dungeon packages, Ai.seek pathing, Solids.solid2, cursor confine (mode 3) fix, shooter centre-aim fix, reserved-word function diagnostic. Verified: x test (124/124), x test-tools, check-impl, check-vocabulary, check-docs, docs-gen + docs-check, bootstrap-cfree (seed is a fixpoint). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
e9c2c51bc3
commit
ad548840c7
139 changed files with 58981 additions and 43671 deletions
|
|
@ -74,7 +74,116 @@ function emit_engine_systems_for_phase(phase: pointer) -> void {
|
|||
# Tween.* fluent handles (#48): advanced each Update tick when the game uses
|
||||
# them (gated on g_uses_tween_rt rather than a declared component).
|
||||
if g_uses_tween_rt and (find_fn("esys_tween") != null) { emit(" call void @fn_esys_tween()\n") }
|
||||
if has_countdowns() { emit(" call void @L_countdowns()\n") } # `countdown` fields tick toward 0
|
||||
if g_uses_fx and (find_fn("fx_tick") != null) { emit(" call void @fn_fx_tick()\n") } # Fx.* age and move
|
||||
}
|
||||
if (phase == "Render") {
|
||||
if g_uses_fx and (find_fn("fx_draw") != null) { emit(" call void @fn_fx_draw()\n") } # Fx.* draw after the sprites
|
||||
}
|
||||
}
|
||||
|
||||
# @L_countdowns(): every `countdown` field of every live entity that carries the
|
||||
# component steps toward 0 once per Update (never below it). The timer idiom —
|
||||
# "frames left" fields counted down by hand in a handler — becomes a field type.
|
||||
function emit_countdown_system() -> void {
|
||||
let me = itoa(MAX_ENT)
|
||||
emit("define void @L_countdowns() {\nentry:\n")
|
||||
emit(" %n = load i32, ptr @L_entc\n br label %loop\nloop:\n")
|
||||
emit(" %i = phi i32 [ 0, %entry ], [ %i1, %next ]\n")
|
||||
emit(" %go = icmp slt i32 %i, %n\n br i1 %go, label %body, label %done\nbody:\n")
|
||||
emit(" %ap = getelementptr inbounds ["); emit(me); emit(" x i32], ptr @L_alive, i32 0, i32 %i\n")
|
||||
emit(" %al = load i32, ptr %ap\n %alive = icmp ne i32 %al, 0\n br i1 %alive, label %c0, label %next\n")
|
||||
var k = 0
|
||||
var i = 0
|
||||
while i < len(prog) {
|
||||
let d = prog[i]
|
||||
if d.kind == N_COMP {
|
||||
var any = false
|
||||
var f = 0
|
||||
while f < len(d.kids) { if (d.kids[f].ty == "countdown") { any = true }; f = f + 1 }
|
||||
if any {
|
||||
let sk = itoa(k); let nk = itoa(k + 1)
|
||||
emit("c"); emit(sk); emit(":\n")
|
||||
emit(" %h"); emit(sk); emit(" = getelementptr inbounds ["); emit(me); emit(" x i8], ptr @H_"); emit(d.s); emit(", i32 0, i32 %i\n")
|
||||
emit(" %hv"); emit(sk); emit(" = load i8, ptr %h"); emit(sk); emit("\n")
|
||||
emit(" %has"); emit(sk); emit(" = icmp ne i8 %hv"); emit(sk); emit(", 0\n")
|
||||
emit(" br i1 %has"); emit(sk); emit(", label %t"); emit(sk); emit(", label %c"); emit(nk); emit("\n")
|
||||
emit("t"); emit(sk); emit(":\n")
|
||||
emit(" %s"); emit(sk); emit(" = getelementptr inbounds ["); emit(me); emit(" x %Cmp_"); emit(d.s); emit("], ptr @S_"); emit(d.s); emit(", i32 0, i32 %i\n")
|
||||
f = 0
|
||||
while f < len(d.kids) {
|
||||
if (d.kids[f].ty == "countdown") {
|
||||
let fk = sk + ("_") + itoa(f)
|
||||
emit(" %fa"); emit(fk); emit(" = getelementptr inbounds %Cmp_"); emit(d.s); emit(", ptr %s"); emit(sk); emit(", i32 0, i32 "); emit(itoa(f)); emit("\n")
|
||||
emit(" %fv"); emit(fk); emit(" = load i32, ptr %fa"); emit(fk); emit("\n")
|
||||
emit(" %fp"); emit(fk); emit(" = icmp sgt i32 %fv"); emit(fk); emit(", 0\n")
|
||||
emit(" %fd"); emit(fk); emit(" = sub i32 %fv"); emit(fk); emit(", 1\n")
|
||||
emit(" %fn"); emit(fk); emit(" = select i1 %fp"); emit(fk); emit(", i32 %fd"); emit(fk); emit(", i32 %fv"); emit(fk); emit("\n")
|
||||
emit(" store i32 %fn"); emit(fk); emit(", ptr %fa"); emit(fk); emit("\n")
|
||||
}
|
||||
f = f + 1
|
||||
}
|
||||
emit(" br label %c"); emit(nk); emit("\n")
|
||||
k = k + 1
|
||||
}
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
emit("c"); emit(itoa(k)); emit(":\n br label %next\n")
|
||||
emit("next:\n %i1 = add i32 %i, 1\n br label %loop\ndone:\n ret void\n}\n\n")
|
||||
}
|
||||
|
||||
# @L_prefab_<Name>(): spawn one prefab with its presets; @L_spawn_prefab(name):
|
||||
# the runtime dispatch by name that Prefab.spawn(name:) calls (-1 for no such prefab).
|
||||
function emit_prefab_fn(pre: Node) -> void {
|
||||
ll_t = 0; ll_lbl = 0; g_term = false; loc_reset(); nloop = 0; nself = 0
|
||||
g_cur_scene = null
|
||||
ret_ty = "int"
|
||||
let fbody = buf_new()
|
||||
falloc = buf_new()
|
||||
let saved = code
|
||||
code = fbody
|
||||
let sp = node(S_SPAWN); sp.s = pre.s
|
||||
let e = emit_spawn(sp)
|
||||
emit(" ret i32 "); emit(e); emit("\n")
|
||||
code = saved
|
||||
emit("define i32 @L_prefab_"); emit(pre.s); emit("() {\nentry:\n")
|
||||
emit(buf_str(falloc))
|
||||
emit(buf_str(fbody))
|
||||
emit("}\n\n")
|
||||
}
|
||||
function emit_prefab_fns() -> void {
|
||||
var i = 0
|
||||
while i < len(prog) { if prog[i].kind == N_PREFAB { emit_prefab_fn(prog[i]) }; i = i + 1 }
|
||||
g_uses_str = true
|
||||
ll_t = 0; ll_lbl = 0; g_term = false; loc_reset(); nloop = 0; nself = 0
|
||||
let fbody = buf_new()
|
||||
falloc = buf_new()
|
||||
let saved = code
|
||||
code = fbody
|
||||
i = 0
|
||||
while i < len(prog) {
|
||||
let d = prog[i]
|
||||
if d.kind == N_PREFAB {
|
||||
let lit = node(E_STR); lit.s = d.s
|
||||
let sv = emit_expr(lit)
|
||||
let same = emit_bind(`call i32 @fn_str_eq(ptr %name, ptr {sv.code})`)
|
||||
let hit = emit_bind(`icmp ne i32 {same}, 0`)
|
||||
let yes = lbl("pf"); let no = lbl("pfn")
|
||||
emit(" br i1 "); emit(hit); emit(", label %"); emit(yes); emit(", label %"); emit(no); emit("\n")
|
||||
emit(yes); emit(":\n")
|
||||
let r = emit_bind(`call i32 @L_prefab_{d.s}()`)
|
||||
emit(" ret i32 "); emit(r); emit("\n")
|
||||
emit(no); emit(":\n")
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
emit(" ret i32 -1\n")
|
||||
code = saved
|
||||
emit("define i32 @L_spawn_prefab(ptr %name) {\nentry:\n")
|
||||
emit(buf_str(falloc))
|
||||
emit(buf_str(fbody))
|
||||
emit("}\n\n")
|
||||
}
|
||||
|
||||
# Global handlers run first, then the active scene's layer handlers in
|
||||
|
|
@ -101,6 +210,7 @@ function phase_id(phase: pointer) -> int {
|
|||
if phase == "Render" { return 4 }
|
||||
if phase == "Start" { return 5 }
|
||||
if phase == "OnQuit" { return 6 }
|
||||
if phase == "Overlay" { return 7 } # HUD/UI pass after the engine drew sprites
|
||||
return 7
|
||||
}
|
||||
|
||||
|
|
@ -223,18 +333,46 @@ function emit_calls_for_phase(phase: pointer) -> void {
|
|||
}
|
||||
emit_engine_systems_for_phase(phase) # engine-owned systems run after every user handler
|
||||
emit_dyn_systems_for_phase(phase) # #64: mod-registered systems run last
|
||||
if (phase == "Overlay") { emit_scene_menu_render() } # a scene's `shows` menu paints last
|
||||
}
|
||||
|
||||
# the menu of the live `scene X shows Menu`, drawn on top of everything else
|
||||
function emit_scene_menu_render() -> void {
|
||||
var any = false
|
||||
var i = 0
|
||||
while i < len(g_scenes) { if (g_scenes[i].ty != null) { any = true }; i = i + 1 }
|
||||
if not any { return }
|
||||
let cs = emit_bind("load i32, ptr @L_scene")
|
||||
i = 0
|
||||
while i < len(g_scenes) {
|
||||
let sc = g_scenes[i]
|
||||
if (sc.ty != null) {
|
||||
let ce = emit_bind(`icmp eq i32 {cs}, {itoa(sc.ival)}`)
|
||||
let run = lbl("mrun"); let skip = lbl("mskip")
|
||||
emit(" br i1 "); emit(ce); emit(", label %"); emit(run); emit(", label %"); emit(skip); emit("\n")
|
||||
emit(run); emit(":\n call void @fn_rt_ui_render()\n")
|
||||
emit(" br label %"); emit(skip); emit("\n"); emit(skip); emit(":\n")
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
}
|
||||
|
||||
# on enter / on exit compile to void functions @scene_enter_<Name> /
|
||||
# @scene_exit_<Name>, called at the transition point (and enter at boot for the
|
||||
# start scene). Emitted for every scene, empty body when the hook is absent.
|
||||
function emit_scene_fn(name: pointer, kind: pointer, body: Node) -> void {
|
||||
function emit_scene_fn(name: pointer, kind: pointer, body: Node, menu: pointer) -> void {
|
||||
ll_t = 0; ll_lbl = 0; g_term = false; loc_reset(); nloop = 0; nself = 0
|
||||
ret_ty = "void"
|
||||
let fbody = buf_new()
|
||||
falloc = buf_new()
|
||||
let saved = code
|
||||
code = fbody
|
||||
# `scene X shows Menu`: a free cursor and the menu open on enter, closed on exit
|
||||
if (menu != null) and (kind == "enter") {
|
||||
if (find_fn("input_cursor_mode") != null) { emit(" call void @fn_input_cursor_mode(i32 0)\n") }
|
||||
emit(" call void @fn_rt_ui_open(i32 "); emit(itoa(ui_index_of("UI_" + menu))); emit(")\n")
|
||||
}
|
||||
if (menu != null) and (kind == "exit") { emit(" call void @fn_rt_ui_close()\n") }
|
||||
if (body != null) { emit_block(body) }
|
||||
# EV1: a `public` scene fires scene_<S>_enter / scene_<S>_exit after its block
|
||||
let sev = `scene_{name}_{kind}`
|
||||
|
|
@ -253,10 +391,31 @@ function emit_scene_hooks() -> void {
|
|||
while i < len(g_scenes) {
|
||||
let sc = g_scenes[i]
|
||||
g_cur_scene = sc
|
||||
emit_scene_fn(sc.s, "enter", sc.a)
|
||||
emit_scene_fn(sc.s, "exit", sc.b)
|
||||
emit_scene_fn(sc.s, "enter", sc.a, sc.ty)
|
||||
emit_scene_fn(sc.s, "exit", sc.b, sc.ty)
|
||||
i = i + 1
|
||||
}
|
||||
g_cur_scene = null
|
||||
if len(g_scenes) > 0 { emit_scene_leave_fn() } # a program without scenes has no @L_scene
|
||||
}
|
||||
|
||||
# @L_scene_leave(): run the on-exit hook of whichever scene is live — what a
|
||||
# `become` outside any scene's own handlers (a global handler, an @On listener,
|
||||
# a plain function) calls, since it cannot know the leaving scene at compile time.
|
||||
function emit_scene_leave_fn() -> void {
|
||||
emit("define void @L_scene_leave() {\nentry:\n")
|
||||
emit(" %s = load i32, ptr @L_scene\n")
|
||||
var i = 0
|
||||
while i < len(g_scenes) {
|
||||
let sc = g_scenes[i]
|
||||
let k = itoa(i)
|
||||
emit(" %is"); emit(k); emit(" = icmp eq i32 %s, "); emit(itoa(sc.ival)); emit("\n")
|
||||
emit(" br i1 %is"); emit(k); emit(", label %leave"); emit(k); emit(", label %next"); emit(k); emit("\n")
|
||||
emit("leave"); emit(k); emit(":\n call void @scene_exit_"); emit(sc.s); emit("()\n ret void\n")
|
||||
emit("next"); emit(k); emit(":\n")
|
||||
i = i + 1
|
||||
}
|
||||
emit(" ret void\n}\n\n")
|
||||
}
|
||||
|
||||
# @OnDespawn(Model) hooks compile to `@on_despawn_<Model>(entity, reason)`
|
||||
|
|
@ -443,6 +602,7 @@ function emit_event_fns() -> void {
|
|||
|
||||
# --- @ev_<E>(payload): fire compile-time listeners, then foreign ones
|
||||
ll_t = 0; ll_lbl = 0; g_term = false; loc_reset(); nloop = 0; nself = 0
|
||||
g_cur_scene = null # a listener belongs to no scene: `become` leaves the live one
|
||||
ret_ty = "void"
|
||||
let fbody = buf_new()
|
||||
falloc = buf_new()
|
||||
|
|
|
|||
|
|
@ -12,6 +12,22 @@ function machine_var(a: Node) -> Node {
|
|||
return null
|
||||
}
|
||||
|
||||
# the value a state dispatches on: its explicit `= expr`; else, when the machine's
|
||||
# store is a `var` declared with an enum type, the variant named like the state
|
||||
# (`var mode: HeroState` + `state Rolling` -> HeroState.Rolling); else its ordinal.
|
||||
function machine_state_value(m: Node, state: Node) -> pointer {
|
||||
if (state.b != null) { return emit_expr(state.b).code }
|
||||
let gv = machine_var(m.a)
|
||||
if (gv != null) {
|
||||
if (gv.ty != null) {
|
||||
let ord = enum_ordinal(gv.ty, state.s)
|
||||
if ord >= 0 { return itoa(ord) }
|
||||
if (find_enum(gv.ty) != null) { perr(`machine state {state.s} is not a variant of enum {gv.ty}`) }
|
||||
}
|
||||
}
|
||||
return itoa(state.ival)
|
||||
}
|
||||
|
||||
function emit_machine(st: Node) -> void {
|
||||
let gv = machine_var(st.a)
|
||||
var s = ""
|
||||
|
|
@ -26,8 +42,8 @@ function emit_machine(st: Node) -> void {
|
|||
var i = 0
|
||||
while i < len(st.kids) {
|
||||
let state = st.kids[i]
|
||||
let v = emit_expr(state.b)
|
||||
let c = emit_bind(`icmp eq i32 {s}, {v.code}`)
|
||||
let v = machine_state_value(st, state)
|
||||
let c = emit_bind(`icmp eq i32 {s}, {v}`)
|
||||
let body = lbl("sbody"); let nxt = lbl("sarm")
|
||||
emit(" br i1 "); emit(c); emit(", label %"); emit(body); emit(", label %"); emit(nxt); emit("\n")
|
||||
emit(body); emit(":\n"); g_term = false
|
||||
|
|
@ -53,19 +69,22 @@ function emit_become(st: Node) -> void {
|
|||
while i < len(m.kids) { if (m.kids[i].s == st.s) { target = m.kids[i] }; i = i + 1 }
|
||||
if (target != null) {
|
||||
let gv = machine_var(m.a)
|
||||
let sv = emit_expr(target.b)
|
||||
let sv = machine_state_value(m, target)
|
||||
if (gv != null) {
|
||||
emit(" store i32 "); emit(sv.code); emit(", ptr @g_"); emit(m.a.s); emit("\n")
|
||||
emit(" store i32 "); emit(sv); emit(", ptr @g_"); emit(m.a.s); emit("\n")
|
||||
} else {
|
||||
let regv = emit_expr(m.a)
|
||||
emit(" call void @fn_rt_set_reg(i32 "); emit(regv.code); emit(", i32 "); emit(sv.code); emit(")\n")
|
||||
emit(" call void @fn_rt_set_reg(i32 "); emit(regv.code); emit(", i32 "); emit(sv); emit(")\n")
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
let sc = find_scene(st.s) # else a scene transition
|
||||
if (sc == null) { perr(`become: no state or scene {st.s}`) }
|
||||
# leave the scene we are in: statically known inside a scene's own handler, else
|
||||
# (a global handler, an event listener, a function) whichever scene is live now
|
||||
if (g_cur_scene != null) { emit(" call void @scene_exit_"); emit(g_cur_scene.s); emit("()\n") }
|
||||
else { emit(" call void @L_scene_leave()\n") }
|
||||
emit(" store i32 "); emit(itoa(sc.ival)); emit(", ptr @L_scene\n")
|
||||
emit(" call void @scene_enter_"); emit(sc.s); emit("()\n")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,16 @@
|
|||
# emit_spawn.ludic — spawn / despawn / self(), and seeding a component's fields
|
||||
# from its declared defaults plus any per-spawn overrides.
|
||||
|
||||
# run a hook body with `self()` bound to entity `e` (a constructor knows its entity)
|
||||
function emit_hook_with_self(e: pointer, body: Node) -> void {
|
||||
let sslot = emit_alloca("i32")
|
||||
emit(" store i32 "); emit(e); emit(", ptr "); emit(sslot); emit("\n")
|
||||
if nself < len(self_stk) { self_stk[nself] = sslot } else { push(self_stk, sslot) }
|
||||
nself = nself + 1
|
||||
emit_block(body)
|
||||
nself = nself - 1
|
||||
}
|
||||
|
||||
function emit_init_component(e: pointer, comp: pointer, rec: Node) -> void {
|
||||
let me = itoa(MAX_ENT)
|
||||
let c = find_comp(comp)
|
||||
|
|
@ -44,7 +54,7 @@ function emit_init_component(e: pointer, comp: pointer, rec: Node) -> void {
|
|||
let vslot = emit_alloca("ptr")
|
||||
emit(" store ptr "); emit(slot); emit(", ptr "); emit(vslot); emit("\n")
|
||||
loc_push(comp, vslot, comp)
|
||||
emit_block(ab)
|
||||
emit_hook_with_self(e, ab)
|
||||
nloc = save
|
||||
}
|
||||
# EV1: a @Public attach hook fires prop_<P>_attach with the entity
|
||||
|
|
@ -68,33 +78,72 @@ function emit_bind_props(model: Node, e: pointer) -> void {
|
|||
}
|
||||
}
|
||||
|
||||
# the record for component `cn` in a spawn or prefab node (null when absent)
|
||||
function spawn_record(n: Node, cn: pointer) -> Node {
|
||||
if (n == null) { return null }
|
||||
var i = 0
|
||||
while i < len(n.kids) { if (n.kids[i].s == cn) { return n.kids[i].a }; i = i + 1 }
|
||||
return null
|
||||
}
|
||||
# a prefab's preset fields with the spawn's own overrides after them (later wins)
|
||||
function merge_records(base: Node, over: Node) -> Node {
|
||||
if (base == null) { return over }
|
||||
if (over == null) { return base }
|
||||
let m = node(E_REC)
|
||||
var i = 0
|
||||
while i < len(base.kids) { push(m.kids, base.kids[i]); i = i + 1 }
|
||||
i = 0
|
||||
while i < len(over.kids) { push(m.kids, over.kids[i]); i = i + 1 }
|
||||
return m
|
||||
}
|
||||
|
||||
# the model behind a spawn name: a model itself, or the model at the end of a
|
||||
# prefab chain (`prefab Grunt: Foe`, `prefab Foe: Creature` -> Creature)
|
||||
function spawn_model(name: pointer) -> pointer {
|
||||
var n = name
|
||||
var depth = 0
|
||||
while true {
|
||||
let p = find_prefab(n)
|
||||
if (p == null) { return n }
|
||||
n = p.ty
|
||||
depth = depth + 1
|
||||
if depth > 16 { perr(`prefab {name}: the chain of prefabs never reaches a model`) }
|
||||
}
|
||||
return n
|
||||
}
|
||||
# the preset record for component `cn` along a prefab chain, base prefabs first
|
||||
function prefab_record(name: pointer, cn: pointer) -> Node {
|
||||
let p = find_prefab(name)
|
||||
if (p == null) { return null }
|
||||
return merge_records(prefab_record(p.ty, cn), spawn_record(p, cn))
|
||||
}
|
||||
|
||||
function emit_spawn(st: Node) -> pointer {
|
||||
let e = emit_bind("call i32 @L_alloc()")
|
||||
let ak = find_arch_id(st.s)
|
||||
let model = spawn_model(st.s)
|
||||
let ak = find_arch_id(model)
|
||||
if (find_prefab(st.s) != null) and (ak == 0) { perr(`prefab {st.s}: unknown model {model}`) }
|
||||
if ak > 0 {
|
||||
let me = itoa(MAX_ENT)
|
||||
let kp = nreg(); emit(" "); emit(kp); emit(" = getelementptr inbounds ["); emit(me); emit(" x i32], ptr @L_kind, i32 0, i32 "); emit(e); emit("\n")
|
||||
emit(" store i32 "); emit(itoa(ak)); emit(", ptr "); emit(kp); emit("\n")
|
||||
let arch = find_arch(st.s)
|
||||
let arch = find_arch(model)
|
||||
var c = 0
|
||||
while c < len(arch.kids) {
|
||||
let cn = arch.kids[c].s
|
||||
var rec = null
|
||||
var i = 0
|
||||
while i < len(st.kids) { if (st.kids[i].s == cn) { rec = st.kids[i].a }; i = i + 1 }
|
||||
emit_init_component(e, cn, rec)
|
||||
emit_init_component(e, cn, merge_records(prefab_record(st.s, cn), spawn_record(st, cn)))
|
||||
c = c + 1
|
||||
}
|
||||
let ob = onspawn_body(st.s) # @OnSpawn(Model) hook runs after init
|
||||
let ob = onspawn_body(model) # @OnSpawn(Model) hook runs after init
|
||||
if (ob != null) {
|
||||
let save = nloc
|
||||
emit_bind_props(arch, e)
|
||||
emit_block(ob)
|
||||
emit_hook_with_self(e, ob)
|
||||
nloc = save
|
||||
}
|
||||
# EV1: a @Public spawn hook also fires the public event model_<M>_spawn, so
|
||||
# mods (native or foreign, over the ABI) see the entity born.
|
||||
let sev = `model_{st.s}_spawn`
|
||||
let sev = `model_{model}_spawn`
|
||||
if (find_event(sev) != null) { emit(" call void @ev_"); emit(sev); emit("(i32 "); emit(e); emit(")\n") }
|
||||
} else {
|
||||
var i = 0
|
||||
|
|
@ -178,6 +227,11 @@ function emit_detach(st: Node) -> void {
|
|||
# enable/disable. `<P> on <e>` toggles a property's has-flag on an entity (its
|
||||
# data persists, so re-enabling restores it, and queries already skip a cleared
|
||||
# flag). A bare `<Model>` / `<Handler>` flips a global enabled flag.
|
||||
function find_sys(name: pointer) -> Node {
|
||||
var i = 0
|
||||
while i < len(prog) { let d = prog[i]; if d.kind == N_SYS and (d.s == name) { return d }; i = i + 1 }
|
||||
return null
|
||||
}
|
||||
function emit_toggle(st: Node) -> void {
|
||||
var val = "0"; if st.ival == 1 { val = "1" }
|
||||
if (st.ty != null) and (st.ty == "system") { return } # `disable system <fn>` is compile-time (handled in emit_one_engine_system); no runtime code
|
||||
|
|
@ -208,6 +262,11 @@ function emit_toggle(st: Node) -> void {
|
|||
if (find_event(tev) != null) { emit(" call void @ev_"); emit(tev); emit("(i32 "); emit(ev.code); emit(")\n") }
|
||||
} else {
|
||||
var g = "@HE_"; if is_model(st.s) { g = "@ME_" } # model vs handler
|
||||
emit(" store i32 "); emit(val); emit(", ptr "); emit(g); emit(st.s); emit("\n")
|
||||
var hname = st.s
|
||||
if (g == "@HE_") and (find_sys(hname) == null) and (g_cur_scene != null) { # a scene's own handler, by its bare name
|
||||
let qualified = `{g_cur_scene.s}_{hname}`
|
||||
if (find_sys(qualified) != null) { hname = qualified }
|
||||
}
|
||||
emit(" store i32 "); emit(val); emit(", ptr "); emit(g); emit(hname); emit("\n")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,29 @@ function ui_prop(w: Node, key: pointer) -> Node {
|
|||
while i < len(w.b.kids) { if (w.b.kids[i].s == key) { return w.b.kids[i].a }; i = i + 1 }
|
||||
return null
|
||||
}
|
||||
# a widget's props plus the text props (font, size, fg, align) it inherits from the
|
||||
# nearest ancestor that sets them — so a panel states the menu's look once.
|
||||
function ui_props_with_inherited(i: int) -> []Node {
|
||||
let w = uiw[i]
|
||||
let out = new []Node
|
||||
var p = 0
|
||||
while p < len(w.b.kids) { push(out, w.b.kids[p]); p = p + 1 }
|
||||
let keys = new []pointer
|
||||
push(keys, "font"); push(keys, "size"); push(keys, "fg"); push(keys, "align")
|
||||
var k = 0
|
||||
while k < len(keys) {
|
||||
if ui_prop(w, keys[k]) == null {
|
||||
var a = uiw_parent[i]
|
||||
while a >= 0 {
|
||||
let v = ui_prop(uiw[a], keys[k])
|
||||
if (v != null) { let fi = node(E_FINIT); fi.s = keys[k]; fi.a = v; push(out, fi); a = 0 - 1 }
|
||||
else { a = uiw_parent[a] }
|
||||
}
|
||||
}
|
||||
k = k + 1
|
||||
}
|
||||
return out
|
||||
}
|
||||
function ui_flatten(w: Node, parent: int) -> void {
|
||||
let idx = len(uiw)
|
||||
push(uiw, w); push(uiw_parent, parent)
|
||||
|
|
@ -41,6 +64,7 @@ function has_ui() -> bool {
|
|||
|
||||
# index of a UI_<name>: a ui block's root, or a widget's id=
|
||||
function ui_index_of(nm: pointer) -> int {
|
||||
if uiw == null { ui_flatten_all() } # a UI_ id may be read before @ui_build is emitted (a function, a listener)
|
||||
let s = nm[3..len(nm)] # strip "UI_"
|
||||
let u = 0; var bi = 0
|
||||
var i = 0
|
||||
|
|
@ -86,12 +110,13 @@ function emit_ui_build() -> void {
|
|||
ll_ui_set(i, 0, itoa(t))
|
||||
ll_ui_set(i, 1, itoa(uiw_parent[i]))
|
||||
if t == 4 { ll_ui_set(i, 17, "1") }
|
||||
let props = ui_props_with_inherited(i)
|
||||
var p = 0
|
||||
while p < len(w.b.kids) {
|
||||
let pr = w.b.kids[p]
|
||||
while p < len(props) {
|
||||
let pr = props[p]
|
||||
let k = pr.s
|
||||
let v = pr.a
|
||||
if (k == "id") { p = p + 1; continue }
|
||||
if (k == "id") or (k == "goto") { p = p + 1; continue }
|
||||
if (k == "text") {
|
||||
let sv = emit_expr(v)
|
||||
emit(" call void @fn_rt_ui_static_text(i32 "); emit(itoa(i)); emit(", ptr "); emit(sv.code); emit(")\n")
|
||||
|
|
|
|||
|
|
@ -422,6 +422,7 @@ function emit_tick_helpers() -> void {
|
|||
emit("define void @L_tick_render() {\nentry:\n")
|
||||
ll_t = 0; ll_lbl = 0
|
||||
emit_calls_for_phase("Render")
|
||||
emit_calls_for_phase("Overlay")
|
||||
emit(" ret void\n}\n\n")
|
||||
}
|
||||
|
||||
|
|
@ -433,6 +434,8 @@ function emit_game_defs() -> void {
|
|||
while i < len(prog) { if prog[i].kind == N_SYS { emit_system_fn(prog[i]) }; i = i + 1 }
|
||||
emit_despawn_hooks()
|
||||
emit_scene_hooks()
|
||||
if has_countdowns() { emit_countdown_system() } # `countdown` fields (see emit_game.ludic)
|
||||
if has_prefabs() { emit_prefab_fns() } # @L_prefab_<Name> + @L_spawn_prefab(name)
|
||||
emit_tick_helpers()
|
||||
}
|
||||
|
||||
|
|
@ -443,6 +446,7 @@ function emit_game_main() -> void {
|
|||
emit(" store i32 %argc, ptr @L_argc\n")
|
||||
emit(" store ptr %argv, ptr @L_argv\n")
|
||||
if (find_fn("rt_init") != null) { emit(" call void @fn_rt_init()\n") }
|
||||
emit(" call void @L_init_globals()\n")
|
||||
emit_calls_for_phase("Start")
|
||||
# enter the start scene once, after boot: store its id and run its on-enter.
|
||||
if len(g_scenes) > 0 {
|
||||
|
|
@ -482,6 +486,12 @@ function emit_game_main() -> void {
|
|||
emit(" store i32 "); emit(k); emit(", ptr @L_key\n")
|
||||
}
|
||||
}
|
||||
# a program with `ui` blocks: navigate the open UI from this frame's key and emit
|
||||
# UiClicked on activation — so a scene never polls ui_tick by hand.
|
||||
if has_ui() and (find_fn("rt_ui_tick") != null) {
|
||||
let uk = emit_bind("load i32, ptr @L_key")
|
||||
emit(" call void @fn_rt_ui_tick(i32 "); emit(uk); emit(")\n")
|
||||
}
|
||||
emit_calls_for_phase("Input")
|
||||
emit_calls_for_phase("FixedUpdate")
|
||||
emit_calls_for_phase("Update")
|
||||
|
|
@ -495,6 +505,9 @@ function emit_game_main() -> void {
|
|||
emit(" call void @fn_rt_clear(i32 "); emit(itoa(g_clear_color)); emit(")\n")
|
||||
}
|
||||
emit_calls_for_phase("Render")
|
||||
# Overlay: HUD / menus drawn after every engine Render system (sprites, lights), so
|
||||
# game UI is never painted under an actor. Presented together with the frame.
|
||||
emit_calls_for_phase("Overlay")
|
||||
if g_has_clear_color and (find_fn("rt_present") != null) {
|
||||
emit(" call void @fn_rt_present()\n")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue