feat(render): #85 engine sprite-render system + deprecate bare draw_sprite
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:
parent
d9287d6b1d
commit
57b8747c31
11 changed files with 18366 additions and 18002 deletions
|
|
@ -24,19 +24,19 @@ handler Draw phase Render {
|
|||
',', 'S', 'B' => base = SPR_FLOOR
|
||||
'=' => base = SPR_WALL
|
||||
}
|
||||
draw_sprite(base, sx, sy)
|
||||
if c == 'T' { draw_sprite(SPR_TREE, sx, sy) }
|
||||
if c == '#' { draw_sprite(SPR_TREE, sx, sy) }
|
||||
if c == 'H' { draw_sprite(SPR_HOUSE, sx, sy) }
|
||||
if c == 'D' { draw_sprite(SPR_DOOR, sx, sy) }
|
||||
if c == 'S' { draw_sprite(SPR_DOOR, sx, sy) }
|
||||
Screen.sprite(base, sx, sy)
|
||||
if c == 'T' { Screen.sprite(SPR_TREE, sx, sy) }
|
||||
if c == '#' { Screen.sprite(SPR_TREE, sx, sy) }
|
||||
if c == 'H' { Screen.sprite(SPR_HOUSE, sx, sy) }
|
||||
if c == 'D' { Screen.sprite(SPR_DOOR, sx, sy) }
|
||||
if c == 'S' { Screen.sprite(SPR_DOOR, sx, sy) }
|
||||
if c == 'B' {
|
||||
if boss_down == 0 { draw_sprite(SPR_BOSS, sx, sy) }
|
||||
if boss_down == 0 { Screen.sprite(SPR_BOSS, sx, sy) }
|
||||
}
|
||||
}
|
||||
}
|
||||
for (p, a) in query [Pos, Actor] {
|
||||
draw_sprite(a.kind, p.x * 16 - cx, p.y * 16 - cy)
|
||||
Screen.sprite(a.kind, p.x * 16 - cx, p.y * 16 - cy)
|
||||
}
|
||||
for (h, pp) in query [Stats, Party] {
|
||||
if pp.slot == 0 {
|
||||
|
|
@ -59,7 +59,7 @@ handler Draw phase Render {
|
|||
for (e, a) in query [Stats, Actor, {Enemy}] {
|
||||
var bs = 5
|
||||
if enemy_type == 2 { bs = 7 }
|
||||
draw_sprite_scaled(a.kind, 160 - bs * 8, 44, bs)
|
||||
Screen.sprite_scaled(a.kind, 160 - bs * 8, 44, bs)
|
||||
Screen.draw_text(100, 20, enemy_name(enemy_type), 0xffffff, 1)
|
||||
Screen.fill_rectangle(100, 30, 120, 8, 0x401018)
|
||||
Screen.fill_rectangle(100, 30, e.hp * 120 / e.maxhp, 8, 0xe04040)
|
||||
|
|
@ -75,7 +75,7 @@ handler Draw phase Render {
|
|||
var spr = 5
|
||||
if pt.slot == 1 { spr = 9 }
|
||||
if pt.slot == act { Screen.draw_rectangle(hx - 2, 180, 88, 44, 0xffff00) }
|
||||
draw_sprite_scaled(spr, hx, 184, 2)
|
||||
Screen.sprite_scaled(spr, hx, 184, 2)
|
||||
if pt.slot == 0 { Screen.draw_text(hx + 36, 182, "KNIGHT", 0xffe08a, 1) }
|
||||
if pt.slot == 1 { Screen.draw_text(hx + 36, 182, "MAGE", 0xc9a0ff, 1) }
|
||||
Screen.draw_text(hx + 36, 195, "HP", 0x88ff88, 1)
|
||||
|
|
|
|||
32
examples/library/sprite_render.ludic
Normal file
32
examples/library/sprite_render.ludic
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# sprite_render.ludic — the engine-owned sprite-render system (#85). Declare a
|
||||
# Sprite component (from ludic.core) on an entity with a Position and the engine
|
||||
# draws it each Render frame — no hand-written Render handler querying positions
|
||||
# and calling draw_sprite per entity. A `hidden` sprite is skipped. Verified by
|
||||
# pixel readback after one frame.
|
||||
#
|
||||
# Driven headless by one stdin key ('q' quits after the frame renders).
|
||||
# printf 'q' | LUDIC_MODULES=packages bin/ludic examples/library/sprite_render.ludic -> 1 0
|
||||
program SpriteRender {
|
||||
import "ludic.core/components.ludic"
|
||||
|
||||
var HERO: int = 0
|
||||
|
||||
@OnStart handler Boot {
|
||||
HERO = png_load("assets/kenney/tiny-dungeon/Tiles/tile_0096.png")
|
||||
spawn Shown { Position { x: 40, y: 40 }, Sprite { id: HERO } }
|
||||
spawn Hidden { Position { x: 100, y: 40 }, Sprite { id: HERO, hidden: 1 } }
|
||||
}
|
||||
|
||||
# An empty Render handler: the engine sprite system draws the Sprite entities.
|
||||
handler Draw phase Render { }
|
||||
|
||||
@OnQuit handler Report {
|
||||
var drew = 0
|
||||
for yy in 40 .. 56 { for xx in 40 .. 56 { if Screen.pixel(xx, yy) != 0 { drew = 1 } } }
|
||||
print(drew) # 1 — the engine drew the shown sprite
|
||||
|
||||
var hid = 0
|
||||
for yy in 40 .. 56 { for xx in 100 .. 116 { if Screen.pixel(xx, yy) != 0 { hid = 1 } } }
|
||||
print(hid) # 0 — the hidden sprite was skipped
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue