feat(ecs): engine-owned systems auto-tick user components (#43)
Adds the ECS hook issues #43 and #47 named as their real dependency: a system the *engine* owns, inserted into the frame loop over a component a game merely declares and carries — no `handler` wired. - runtime/native/systems.ludic: esys_spriteanim (SpriteAnim frame advance: loop/once/pingpong) and esys_motion (Motion value tween: linear/in/out/ in-out), both on the by-name reflection ABI, integer + deterministic. - backend: emit_engine_systems_for_phase inserts the calls after every user handler in a phase (auto-loop and the drivable tick helpers alike); uses_engine_systems() drives the systems.ludic splice, the world-table force-emit, and makes a component-only game count as a systems game. - A game that declares neither component is byte-for-byte unchanged. Worked example + regression: examples/library/anim_ecs.ludic. Full suite 73 passed, self-host C-free bootstrap fixpoint intact. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
9452557f3c
commit
b0143337d9
10 changed files with 15109 additions and 14658 deletions
|
|
@ -160,7 +160,7 @@ function emit_program() -> void {
|
|||
i = i + 1
|
||||
}
|
||||
if len(g_events) > 0 { emit_event_fns() } # EV0: @ev_<E> event-dispatch functions
|
||||
if has_ecs() and (len(g_events) > 0 or g_uses_query or g_uses_reflect) { emit_world_table() } # EV2/EV8: the mod reflection ABI (also powers Query.* / Reflect.*)
|
||||
if has_ecs() and (len(g_events) > 0 or g_uses_query or g_uses_reflect or g_uses_esys) { emit_world_table() } # EV2/EV8: the mod reflection ABI (also powers Query.* / Reflect.* / engine systems)
|
||||
if has_ecs() { emit_ecs_allocator(); emit_snapshot() }
|
||||
if has_ecs() { emit_net() } # N2/N3: @Sync serializers + @Owned storage (gated internally)
|
||||
if has_ui() { emit_ui_build() }
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ const MAX_ENT: int = 1024
|
|||
function has_systems() -> bool {
|
||||
var i = 0
|
||||
while i < len(prog) { if prog[i].kind == N_SYS { return true }; i = i + 1 }
|
||||
# a game with no hand-written handler but a well-known engine component still
|
||||
# runs a frame loop — the engine owns the system that ticks that component
|
||||
# (#43/#47). Treat it as a systems game so the loop / tick helpers are emitted.
|
||||
if uses_engine_systems() { return true }
|
||||
return false
|
||||
}
|
||||
function has_models() -> bool {
|
||||
|
|
@ -15,6 +19,19 @@ function has_models() -> bool {
|
|||
while i < len(prog) { if prog[i].kind == N_ARCH { return true }; i = i + 1 }
|
||||
return false
|
||||
}
|
||||
# does the program declare a well-known engine component? Each one is auto-ticked
|
||||
# by an engine-owned system (systems.ludic, wired in emit_engine_systems_for_
|
||||
# phase). Answering this drives the systems.ludic splice (parse.ludic) and the
|
||||
# reflection-ABI force-emit (emit_decl) — a game with none is byte-for-byte the
|
||||
# same as before the feature existed. Keep this list in sync with the phase table
|
||||
# in emit_engine_systems_for_phase.
|
||||
function uses_engine_systems() -> bool {
|
||||
if find_comp("SpriteAnim") != null { return true }
|
||||
if find_comp("Motion") != null { return true }
|
||||
if find_comp("Light2D") != null { return true }
|
||||
if find_comp("Occluder") != null { return true }
|
||||
return false
|
||||
}
|
||||
# N5: does the program have an `entry` block? A game with both handlers and an
|
||||
# `entry` drives its own loop (calling tick_fixed/tick_render), instead of the
|
||||
# compiler's auto frame loop. A game with handlers and no entry uses the auto-loop.
|
||||
|
|
|
|||
|
|
@ -46,10 +46,33 @@ function emit_call_one(d: Node) -> void {
|
|||
emit(" br label %"); emit(skip); emit("\n"); emit(skip); emit(":\n")
|
||||
}
|
||||
|
||||
# Engine-owned systems (#43/#47): systems the compiler injects into the frame
|
||||
# loop over a component the game merely declares and carries — the ECS hook the
|
||||
# animation and lighting follow-ups both stand on. Each entry is (component,
|
||||
# runtime fn, phase); the call is emitted only when the game declares that
|
||||
# component (so systems.ludic was spliced and the fn exists). They run *after*
|
||||
# the game's own handlers for the phase, so gameplay this frame is already
|
||||
# settled when the engine advances animation / accumulates light. Keep the
|
||||
# component list in sync with uses_engine_systems (emit_ecs.ludic).
|
||||
function emit_one_engine_system(comp: pointer, fn: pointer) -> void {
|
||||
if (find_comp(comp) != null) and (find_fn(fn) != null) {
|
||||
emit(" call void @fn_"); emit(fn); emit("()\n")
|
||||
}
|
||||
}
|
||||
function emit_engine_systems_for_phase(phase: pointer) -> void {
|
||||
if (phase == "Update") {
|
||||
emit_one_engine_system("SpriteAnim", "esys_spriteanim")
|
||||
emit_one_engine_system("Motion", "esys_motion")
|
||||
}
|
||||
if (phase == "Render") {
|
||||
emit_one_engine_system("Light2D", "esys_light2d")
|
||||
}
|
||||
}
|
||||
|
||||
# Global handlers run first, then the active scene's layer handlers in
|
||||
# declaration (draw) order. The active scene is snapshotted once per phase, so a
|
||||
# `become` mid-phase takes effect at the next phase boundary — exactly one scene
|
||||
# is active within any single phase.
|
||||
# is active within any single phase. Engine-owned systems for the phase run last.
|
||||
function emit_calls_for_phase(phase: pointer) -> void {
|
||||
var i = 0
|
||||
while i < len(prog) {
|
||||
|
|
@ -61,21 +84,23 @@ function emit_calls_for_phase(phase: pointer) -> void {
|
|||
var has_sc = false
|
||||
i = 0
|
||||
while i < len(prog) { let d = prog[i]; if d.kind == N_SYS and (d.ty == phase) and (d.c != null) { has_sc = true }; i = i + 1 }
|
||||
if not has_sc { return }
|
||||
let cs = emit_bind("load i32, ptr @L_scene")
|
||||
i = 0
|
||||
while i < len(prog) {
|
||||
let d = prog[i]
|
||||
if d.kind == N_SYS and (d.ty == phase) and (d.c != null) {
|
||||
let ce = emit_bind(`icmp eq i32 {cs}, {itoa(d.c.ival)}`)
|
||||
let run = lbl("scrun"); let skip = lbl("scskip")
|
||||
emit(" br i1 "); emit(ce); emit(", label %"); emit(run); emit(", label %"); emit(skip); emit("\n")
|
||||
emit(run); emit(":\n")
|
||||
emit_call_one(d)
|
||||
emit(" br label %"); emit(skip); emit("\n"); emit(skip); emit(":\n")
|
||||
if has_sc {
|
||||
let cs = emit_bind("load i32, ptr @L_scene")
|
||||
i = 0
|
||||
while i < len(prog) {
|
||||
let d = prog[i]
|
||||
if d.kind == N_SYS and (d.ty == phase) and (d.c != null) {
|
||||
let ce = emit_bind(`icmp eq i32 {cs}, {itoa(d.c.ival)}`)
|
||||
let run = lbl("scrun"); let skip = lbl("scskip")
|
||||
emit(" br i1 "); emit(ce); emit(", label %"); emit(run); emit(", label %"); emit(skip); emit("\n")
|
||||
emit(run); emit(":\n")
|
||||
emit_call_one(d)
|
||||
emit(" br label %"); emit(skip); emit("\n"); emit(skip); emit(":\n")
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
emit_engine_systems_for_phase(phase) # engine-owned systems run after every user handler
|
||||
}
|
||||
|
||||
# on enter / on exit compile to void functions @scene_enter_<Name> /
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue