feat(assets): #81 namespaced spritesheet/atlas API (Sprite.* / Assets.*)
Sprite loading was a bare png_load — one file per 16x16 sprite, no way to load one sheet and address a cell by grid coords or name. Adds a Sprite.*/Assets.* runtime (atlas.ludic) over the variable-size image loader, so a cell is a sub-rect of the kept image and is NOT restricted to the 16x16 sprite table: Sprite.sheet(path,cw,ch), Sprite.cell(sheet,col,row), Sprite.cell_span(sheet,col,row,cols,rows) (a sprite may span >1 cell), Sprite.define/named (name + lookup), Sprite.draw/draw_scaled (through camera/zoom/clip like Screen.sprite), Sprite.width/height, and Assets.image/load/get. Spliced on demand (Sprite.sheet/… or Assets.*), so a program using neither is byte-identical. Example examples/library/atlas.ludic (verified against a real 12x11 Kenney sheet, incl. a 2x3 multi-cell span and named lookup). 14 docs pages. Full suite 114/0, goldens byte-identical, fixpoint holds. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
ab4546e365
commit
f3f1336882
21 changed files with 34542 additions and 32915 deletions
|
|
@ -176,6 +176,27 @@ function emit_ns_call(ns: pointer, meth: pointer, e: Node) -> Val {
|
|||
if (meth == "measure_text") { bare = "measure_text"; push(labels, "text") }
|
||||
if (meth == "pixel") { bare = "get_px"; push(labels, "x"); push(labels, "y") }
|
||||
}
|
||||
# Sprite.* / Assets.* — the namespaced spritesheet / atlas API (#81), a runtime
|
||||
# in atlas.ludic over the variable-size image loader. A cell (or multi-cell span)
|
||||
# is a sub-rect of a loaded sheet; draws go through rt_put_px so camera/zoom/clip
|
||||
# apply. Distinct from the `Sprite` engine component (#85) — same name, different
|
||||
# namespace (a namespaced builtin, never an entity).
|
||||
if (ns == "Sprite") {
|
||||
if (meth == "sheet") { bare = "atlas_sheet"; push(labels, "path"); push(labels, "cellw"); push(labels, "cellh") }
|
||||
if (meth == "cell") { bare = "atlas_cell"; push(labels, "sheet"); push(labels, "col"); push(labels, "row") }
|
||||
if (meth == "cell_span") { bare = "atlas_cell_span"; push(labels, "sheet"); push(labels, "col"); push(labels, "row"); push(labels, "cols"); push(labels, "rows") }
|
||||
if (meth == "define") { bare = "atlas_define"; push(labels, "name"); push(labels, "sheet"); push(labels, "col"); push(labels, "row") }
|
||||
if (meth == "named") { bare = "atlas_named"; push(labels, "name") }
|
||||
if (meth == "draw") { bare = "atlas_draw"; push(labels, "id"); push(labels, "x"); push(labels, "y") }
|
||||
if (meth == "draw_scaled") { bare = "atlas_draw_scaled"; push(labels, "id"); push(labels, "x"); push(labels, "y"); push(labels, "scale") }
|
||||
if (meth == "width") { bare = "atlas_width"; push(labels, "id") }
|
||||
if (meth == "height") { bare = "atlas_height"; push(labels, "id") }
|
||||
}
|
||||
if (ns == "Assets") {
|
||||
if (meth == "image") { bare = "atlas_image"; push(labels, "path") }
|
||||
if (meth == "load") { bare = "atlas_image"; push(labels, "path") } # alias
|
||||
if (meth == "get") { bare = "atlas_named"; push(labels, "name") } # alias of Sprite.named
|
||||
}
|
||||
# Camera.* — the world-space camera: a draw offset threaded through the render
|
||||
# path (runtime/native/core.ludic). set/follow move it; shake jitters it from
|
||||
# the seeded RNG, so a replay shakes identically.
|
||||
|
|
|
|||
|
|
@ -186,6 +186,10 @@ function p_postfix() -> Node {
|
|||
if e.a.kind == E_ID and e.a.s == "Xml" { g_uses_xml = true } # splice the XML reader on demand (Tiled #67)
|
||||
if e.a.kind == E_ID and e.a.s == "Base64" { g_uses_base64 = true } # splice base64 codec + inflate on demand (Tiled #67)
|
||||
if e.a.kind == E_ID and e.a.s == "Tiled" { g_uses_tiled = true } # splice the Tiled map runtime on demand (#69)
|
||||
# #81 — Sprite.sheet/cell/… or Assets.* splice the spritesheet/atlas runtime
|
||||
# (it reads the framebuffer + the image loader, so it links against core).
|
||||
if e.a.kind == E_ID and e.a.s == "Sprite" and (e.s == "sheet" or e.s == "cell" or e.s == "cell_span" or e.s == "define" or e.s == "named" or e.s == "draw" or e.s == "draw_scaled" or e.s == "width" or e.s == "height") { g_uses_atlas = true }
|
||||
if e.a.kind == E_ID and e.a.s == "Assets" { g_uses_atlas = true }
|
||||
if e.a.kind == E_ID and e.a.s == "Reflect" and (e.s == "serialize" or e.s == "apply") { g_uses_value = true; g_uses_reflect_io = true } # Reflect.serialize/apply -> value tree + world table
|
||||
# Input.* action-map / record-replay methods (#7) -> splice input.ludic.
|
||||
# Input.key stays bare (no runtime), so gate on the new methods only.
|
||||
|
|
@ -442,6 +446,7 @@ var g_uses_value: bool = false # Value.*/Json.*/Reflect.serialize -> splice t
|
|||
var g_uses_xml: bool = false # Xml.* -> splice the XML reader (Tiled #67)
|
||||
var g_uses_base64: bool = false # Base64.* -> splice the base64 codec + inflate (Tiled #67)
|
||||
var g_uses_tiled: bool = false # Tiled.* -> splice the Tiled map runtime (#69)
|
||||
var g_uses_atlas: bool = false # Sprite.sheet/cell/… or Assets.* -> splice the spritesheet/atlas runtime (#81)
|
||||
var g_uses_reflect_io: bool = false # Reflect.serialize/apply -> splice the reflection serializer
|
||||
var g_uses_esys: bool = false # an engine-owned system component (SpriteAnim/Motion/Light2D) is declared -> splice systems.ludic + force the reflection ABI
|
||||
var g_uses_input: bool = false # a program used Input.bind/down/poll/… (action maps + record/replay) -> splice input.ludic
|
||||
|
|
@ -784,6 +789,15 @@ function maybe_splice_runtime() -> void {
|
|||
do_import("runtime/native/xml.ludic")
|
||||
cur_dir = saved
|
||||
}
|
||||
# Sprite.sheet/cell/… or Assets.* (#81) — the spritesheet / atlas runtime. It
|
||||
# reads the framebuffer and the image loader (rt_image_load / img_px in
|
||||
# image.ludic), so it links against core.ludic (do_import dedupes).
|
||||
if g_uses_atlas {
|
||||
cur_dir = ""
|
||||
do_import("runtime/native/core.ludic")
|
||||
do_import("runtime/native/atlas.ludic")
|
||||
cur_dir = saved
|
||||
}
|
||||
# Base64.* (#67) — base64 codec; pull in the DEFLATE inflater alongside it, so
|
||||
# a plain tool can run the full base64 -> zlib/gzip decode chain (inflate.ludic
|
||||
# is self-contained; do_import dedupes when a game already linked it via core).
|
||||
|
|
@ -942,6 +956,7 @@ function parse_program() -> void {
|
|||
g_uses_xml = false
|
||||
g_uses_base64 = false
|
||||
g_uses_tiled = false
|
||||
g_uses_atlas = false
|
||||
g_uses_reflect_io = false
|
||||
g_tests = new []Node
|
||||
g_mod_sys_fn = new []pointer
|
||||
|
|
|
|||
66983
selfhost/ludicc.seed.ll
66983
selfhost/ludicc.seed.ll
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue