feat(render): #85 engine sprite-render system + deprecate bare draw_sprite
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 23s
ci / build-and-test (push) Successful in 2m20s
commit-lint / conventional-commits (push) Successful in 5s
docs / build-and-deploy (push) Successful in 28s

The engine already auto-ticks SpriteAnim/Motion; it now auto-DRAWS too.
Declare a Sprite component (id/offx/offy/scale/flip/tint/hidden, shipped from
ludic.core) on an entity with a Position and esys_sprite draws it each Render
frame — no hand-written Render handler, no hand animation (adds the SpriteAnim
frame when present). Registered on the engine-system registry (Render) and
spliced only when the game declares Sprite, so a game that never declares it
compiles byte-identically; opt out by omitting Sprite or `disable system
esys_sprite`.

Deprecates the bare draw_sprite/draw_sprite_scaled globals in favour of
Screen.sprite/Screen.sprite_scaled: a direct bare call emits a one-time
compile-time deprecation note (the bare form still lowers, since Screen.sprite
uses it); migrates the chronorift demo to the namespaced calls (golden render
byte-identical).

Example sprite_render (pixel-readback: engine draws the sprite, respects
hidden). Full suite 109/0, goldens byte-identical, fixpoint holds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-02 07:20:13 +03:00
parent d9287d6b1d
commit 57b8747c31
11 changed files with 18366 additions and 18002 deletions

View file

@ -367,6 +367,32 @@ function rt_draw_sprite_scaled(id: int, px: int, py: int, sc: int) -> void {
}
}
# The full sprite blit the engine sprite-render system (#85) uses: an integer
# scale (>= 1), a horizontal flip, and an optional solid tint (0 = keep the
# sprite's own colours; non-zero = draw every opaque pixel in the tint colour, for
# a hit-flash / team-colour silhouette). It funnels through the same put_px /
# fill_rect chokepoints, so camera / zoom / clip / blend all apply.
function rt_draw_sprite_ex(id: int, px: int, py: int, sc: int, flip: int, tint: int) -> void {
if id < 0 { return }
if id >= spr_n { return }
var s = sc
if s < 1 { s = 1 }
let base = id * SPR_SZ * SPR_SZ
for y in 0 .. SPR_SZ {
for x in 0 .. SPR_SZ {
var rx = x
if flip != 0 { rx = SPR_SZ - 1 - x } # sample mirrored, draw upright
let p = spr_px[base + y * SPR_SZ + rx]
if ((p >> 24) & 255) != 0 {
var col = (p & 16777215)
if tint != 0 { col = (tint & 16777215) }
if s == 1 { rt_put_px(px + x, py + y, col) }
else { rt_fill_rect(px + x * s, py + y * s, s, s, col) }
}
}
}
}
# ---- .lspr sprite sheets (palette + ASCII rows) ---------------------------
function rt_hexval(c: int) -> int {
if c >= 48 { if c <= 57 { return c - 48 } }