refactor(runtime,packages,examples): named constants, package enums, idiom sweep

- runtime: HEADLESS_FRAME_PATH, STICK_DEADZONE / STICK_LEFT_X/Y, key and
  byte codes as char literals throughout (`k == 'w'`, `fill(rt_map, ' ', …)`)
- ludic.gameplay/stats: drop the duplicate `stat_field` (it answered "atk"
  for every build stat); Stats.base uses stats_field_name
- ludic.shooter: compare aim modes and fire patterns with AimMode.* and
  WeaponPattern.* instead of raw ints; STICK_RIGHT_X/Y
- ludic.npcai: DecisionMade / brain_set_state use AiState.*
- examples/games/menu.ludic uses Font.load / Ui.* with FONT_PATH and
  BACKDROP named; strings.ludic header says what it prints
- whole tree: `x = x + 1` → `x += 1` (single-term right-hand sides only),
  `0 - x` → `-x`, ASCII codes → char literals; every .ludic and every
  ```ludic fence reformatted with the fixed formatter (whitespace only)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-05 01:12:26 +03:00
parent e3e1bc7784
commit bf36bc8a8f
103 changed files with 1256 additions and 1252 deletions

View file

@ -77,40 +77,40 @@ function atlas_register_name(name: pointer, id: int) -> void {
if at_nname >= ATLAS_MAX_NAME { return }
at_name_str[at_nname] = name
at_name_id[at_nname] = id
at_nname = at_nname + 1
at_nname += 1
}
# load a spritesheet PNG whose cells are cw x ch px; returns a sheet handle (>= 0).
function atlas_sheet(path: pointer, cw: int, ch: int) -> int {
atlas_init()
if at_nsheet >= ATLAS_MAX_SHEET { return 0 - 1 }
if at_nsheet >= ATLAS_MAX_SHEET { return -1 }
let img = rt_image_load(path)
if img < 0 { return 0 - 1 }
if img < 0 { return -1 }
let h = at_nsheet
at_sheet_img[h] = img
at_sheet_cw[h] = cw
at_sheet_ch[h] = ch
at_nsheet = at_nsheet + 1
at_nsheet += 1
return h
}
# register an atlas sprite for a sub-rect (px) of a sheet's image.
function atlas_make(sheet: int, sx: int, sy: int, w: int, h: int) -> int {
atlas_init()
if at_nspr >= ATLAS_MAX_SPR { return 0 - 1 }
if at_nspr >= ATLAS_MAX_SPR { return -1 }
let id = at_nspr
at_spr_sheet[id] = sheet
at_spr_sx[id] = sx
at_spr_sy[id] = sy
at_spr_w[id] = w
at_spr_h[id] = h
at_nspr = at_nspr + 1
at_nspr += 1
return id
}
# one cell (col, row) of a sheet, addressed by grid coords.
function atlas_cell(sheet: int, col: int, row: int) -> int {
if (sheet < 0) or (sheet >= at_nsheet) { return 0 - 1 }
if (sheet < 0) or (sheet >= at_nsheet) { return -1 }
let cw = at_sheet_cw[sheet]
let ch = at_sheet_ch[sheet]
return atlas_make(sheet, col * cw, row * ch, cw, ch)
@ -119,7 +119,7 @@ function atlas_cell(sheet: int, col: int, row: int) -> int {
# a sprite spanning cols x rows cells from (col, row) — some sprites cover more
# than one cell (a tall character, a wide object).
function atlas_cell_span(sheet: int, col: int, row: int, cols: int, rows: int) -> int {
if (sheet < 0) or (sheet >= at_nsheet) { return 0 - 1 }
if (sheet < 0) or (sheet >= at_nsheet) { return -1 }
let cw = at_sheet_cw[sheet]
let ch = at_sheet_ch[sheet]
return atlas_make(sheet, col * cw, row * ch, cols * cw, rows * ch)
@ -129,11 +129,11 @@ function atlas_cell_span(sheet: int, col: int, row: int, cols: int, rows: int) -
function atlas_define(name: pointer, sheet: int, col: int, row: int) -> int {
atlas_init()
let id = atlas_cell(sheet, col, row)
if id < 0 { return 0 - 1 }
if id < 0 { return -1 }
if at_nname < ATLAS_MAX_NAME {
at_name_str[at_nname] = name
at_name_id[at_nname] = id
at_nname = at_nname + 1
at_nname += 1
}
return id
}
@ -144,24 +144,24 @@ function atlas_named(name: pointer) -> int {
var i = 0
while i < at_nname {
if at_name_str[i] == name { return at_name_id[i] }
i = i + 1
i += 1
}
return 0 - 1
return -1
}
# load a whole image file as one atlas sprite (a 1x1 sheet the size of the image).
function atlas_image(path: pointer) -> int {
atlas_init()
if at_nsheet >= ATLAS_MAX_SHEET { return 0 - 1 }
if at_nsheet >= ATLAS_MAX_SHEET { return -1 }
let img = rt_image_load(path)
if img < 0 { return 0 - 1 }
if img < 0 { return -1 }
let w = img_w[img]
let h = img_h[img]
let sh = at_nsheet
at_sheet_img[sh] = img
at_sheet_cw[sh] = w
at_sheet_ch[sh] = h
at_nsheet = at_nsheet + 1
at_nsheet += 1
return atlas_make(sh, 0, 0, w, h)
}
@ -191,10 +191,10 @@ function atlas_draw(id: int, dx: int, dy: int) -> void {
let px = s[srcy * iw + srcx]
if ((px >> 24) & 255) >= 128 { rt_put_px(dx + x, dy + y, px & 16777215) }
}
x = x + 1
x += 1
}
}
y = y + 1
y += 1
}
}
@ -223,10 +223,10 @@ function atlas_draw_scaled(id: int, dx: int, dy: int, sc: int) -> void {
let px = s[srcy * iw + srcx]
if ((px >> 24) & 255) >= 128 { rt_fill_rect(dx + x * sc, dy + y * sc, sc, sc, px & 16777215) }
}
x = x + 1
x += 1
}
}
y = y + 1
y += 1
}
}
@ -265,22 +265,22 @@ function atlas_draw_ex(id: int, dx: int, dy: int, sc0: int, flip: int, tint: int
else { rt_fill_rect(dx + x * sc, dy + y * sc, sc, sc, col) }
}
}
x = x + 1
x += 1
}
}
y = y + 1
y += 1
}
}
# a strip of `count` frames starting at (col,row), each `rows` cells tall, registered
# as consecutive ids so `first + SpriteAnim.frame` addresses the current frame.
function atlas_strip(sheet: int, col: int, row: int, count: int, rows: int) -> int {
var first = 0 - 1
var first = -1
var i = 0
while i < count {
let id = atlas_cell_span(sheet, col + i, row, 1, rows)
if first < 0 { first = id }
i = i + 1
i += 1
}
return first
}
@ -299,7 +299,7 @@ function atlas_draw_meter(x: int, y: int, value: int, max: int, per_icon: int, s
if value >= i * per_icon + per_icon / 2 { id = half }
if value >= (i + 1) * per_icon { id = full }
atlas_draw(id, x + i * spacing, y)
i = i + 1
i += 1
}
}
@ -312,9 +312,9 @@ function assets_enqueue_dir(dir: pointer) -> void {
while i < len(names) {
let file = names[i]
var dot = len(file) - 1
while (dot > 0) and (file[dot] != 46) { dot = dot - 1 }
while (dot > 0) and (file[dot] != '.') { dot -= 1 }
if dot > 0 { assets_enqueue(file[0..dot], dir + ("/") + file) }
i = i + 1
i += 1
}
}
@ -325,7 +325,7 @@ function assets_enqueue(name: pointer, path: pointer) -> void {
if at_q_n >= ATLAS_MAX_QUEUE { return }
at_q_name[at_q_n] = name
at_q_path[at_q_n] = path
at_q_n = at_q_n + 1
at_q_n += 1
}
# Load up to `max` queued assets this frame, registering each under its name, and
@ -338,8 +338,8 @@ function assets_pump(max: int) -> int {
var done = 0
while (done < max) and (at_q_pos < at_q_n) {
assets_load_one(at_q_name[at_q_pos], at_q_path[at_q_pos])
at_q_pos = at_q_pos + 1
done = done + 1
at_q_pos += 1
done += 1
}
if (at_q_pos >= at_q_n) and (not at_q_announced) { at_q_announced = true; emit AssetsReady() }
return done
@ -362,7 +362,7 @@ function path_has_suffix(path: pointer, suffix: pointer) -> bool {
var i = 0
while i < m {
if path[n - m + i] != suffix[i] { return false }
i = i + 1
i += 1
}
return true
}
@ -380,7 +380,7 @@ function assets_load_one(name: pointer, path: pointer) -> void {
if at_font_n < ATLAS_MAX_FONT {
at_font_name[at_font_n] = name
at_font_id[at_font_n] = rt_font_load(path)
at_font_n = at_font_n + 1
at_font_n += 1
}
return
}
@ -391,7 +391,7 @@ function assets_font(name: pointer) -> int {
var i = 0
while i < at_font_n {
if at_font_name[i] == name { return at_font_id[i] }
i = i + 1
i += 1
}
return 0
}