feat(engine): Tiled P1 — rt_tmap model + GID resolver + render + projection (#69)
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 20s
ci / build-and-test (push) Successful in 1m48s
commit-lint / conventional-commits (push) Successful in 3s
docs / build-and-deploy (push) Successful in 27s

The heart of Tiled support: load a map and draw it.

- rt_tmap model (Tmap/TmLayer/TmTileset in tiled.ludic): map header + ordered
  layers (dense int32 GID arrays, heap-allocated to w*h, lifting the 96x64 cap)
  + tilesets. Built from the intermediate Value tree, so the TMX and TMJ paths
  both feed it.
- GID resolver (Tiled.resolve): gid -> (tileset, localId, flipH/V/D); the three
  flip flags masked off before the local-id lookup, returned alongside. gid==0
  is empty.
- Image-backed render (Tiled.draw): every visible tile layer in file order,
  blitting each tile from its tileset image with flips applied at draw.
- Compatibility projection (Tiled.project / auto on load): a designated
  collision layer projects to the legacy byte tilemap ('#' solid, '=' one-way
  via the oneway property, ' ' empty) so Grid.*/Path.*/esys_move are unchanged.
- Tiled.load resolves external tilesets + images relative to the map file and
  auto-projects a collision/solids/walls layer.
- The grid and physics_tiles demos now run off a loaded map (grid_maze.tmx /
  physics_map.tmx) instead of hand-authored Map.row strings, byte-identically.

Two compiler fixes fell out of this (see the changeset):
- emit_index_addr set g_addr_ty before evaluating the index, so slice[obj.field]
  came back mis-typed; set it last, like the raw-pointer branches.
- @strcmp was declared by both the world table and the fs prelude; centralise
  it in the head prelude so a game that uses Fs/Path links.

Proven by library/tiled_p1.ludic (14 assertions: loads+renders Kenney map
identically from .tmx and .tmj, flip mirroring) + the converted grid/
physics_tiles demos. x test: 92 passed; self-host bootstrap fixpoint intact.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-01 14:43:29 +03:00
parent 071c268de7
commit bc301c8d17
29 changed files with 12932 additions and 9582 deletions

View file

@ -43,16 +43,16 @@ function emit_index_addr(e: Node) -> pointer {
return r
}
let el = slice_elem(base.ty)
g_addr_ty = el
# load the data pointer from the slice header (field 0)
let dp = nreg()
emit(" "); emit(dp); emit(" = getelementptr inbounds %LSlice, ptr ")
emit(base.code); emit(", i32 0, i32 0\n")
let data = nreg()
emit(" "); emit(data); emit(" = load ptr, ptr "); emit(dp); emit("\n")
let ix = emit_expr(e.b)
let r = nreg()
emit(" "); emit(r); emit(" = getelementptr inbounds "); emit(llty(el))
let ix = emit_expr(e.b) # (evaluate index BEFORE setting
let r = nreg() # g_addr_ty — a member-access index
emit(" "); emit(r); emit(" = getelementptr inbounds "); emit(llty(el)) # overwrites it)
emit(", ptr "); emit(data); emit(", i32 "); emit(ix.code); emit("\n")
g_addr_ty = el # set last so the caller sees the element type
return r
}

View file

@ -611,8 +611,19 @@ function emit_ns_call(ns: pointer, meth: pointer, e: Node) -> Val {
# read/read_tsx produce the intermediate Value tree (#68); load/gid/resolve/
# draw/prop operate on the loaded map model (#69+).
if (ns == "Tiled") {
if (meth == "read") { bare = "tiled_read"; push(labels, "path") }
if (meth == "read_tsx") { bare = "tiled_read_tsx"; push(labels, "path") }
if (meth == "read") { bare = "tiled_read"; push(labels, "path") }
if (meth == "read_tsx") { bare = "tiled_read_tsx"; push(labels, "path") }
if (meth == "load") { bare = "tiled_load"; push(labels, "path") }
if (meth == "gid") { bare = "tmap_gid"; push(labels, "map"); push(labels, "layer"); push(labels, "x"); push(labels, "y") }
if (meth == "resolve") { bare = "tmap_resolve"; push(labels, "map"); push(labels, "gid") }
if (meth == "width") { bare = "tmap_width"; push(labels, "map") }
if (meth == "height") { bare = "tmap_height"; push(labels, "map") }
if (meth == "layer_count") { bare = "tmap_layer_count"; push(labels, "map") }
if (meth == "layer_name") { bare = "tmap_layer_name"; push(labels, "map"); push(labels, "index") }
if (meth == "draw") { bare = "tmap_draw"; push(labels, "map"); push(labels, "camx"); push(labels, "camy") }
if (meth == "project") { bare = "tmap_project"; push(labels, "map"); push(labels, "layer") }
if (meth == "tree") { bare = "tmap_tree"; push(labels, "map") }
if (meth == "tile_prop") { bare = "tmap_tile_prop"; push(labels, "map"); push(labels, "gid"); push(labels, "name") }
}
# #62: a package-provided namespace (declared with @Namespace(Foo)) that none
# of the hardcoded core blocks matched — alias Foo.method to the bare function

View file

@ -52,6 +52,7 @@ function emit_header() -> void {
emith("declare ptr @memcpy(ptr, ptr, i64)\n")
emith("declare ptr @memset(ptr, i32, i64)\n")
emith("declare i64 @strlen(ptr)\n")
emith("declare i32 @strcmp(ptr, ptr)\n")
emith("declare i32 @strncmp(ptr, ptr, i64)\n")
emith("declare ptr @strstr(ptr, ptr)\n")
emith("declare i32 @atoi(ptr)\n")

View file

@ -15,7 +15,6 @@
# ids are assignment order in the source; field ids are declaration order.
function emit_world_table() -> void {
let me = itoa(MAX_ENT)
emith("declare i32 @strcmp(ptr, ptr)\n")
# EV7 — schema opening: a mod can register a brand-new component at runtime.
# Compile-time components take prop ids 0..NC-1; mod-defined ones take NC.. and

View file

@ -98,7 +98,6 @@ function emit_fs_prelude() -> void {
emith("declare ptr @opendir(ptr)\n")
emith("declare ptr @readdir(ptr)\n")
emith("declare i32 @closedir(ptr)\n")
emith("declare i32 @strcmp(ptr, ptr)\n")
emit_fs_common()
emit_fs_path()
emit_fs_io()

File diff suppressed because it is too large Load diff