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

@ -33,8 +33,8 @@ function huge_make(m: fixed, e: int) -> Huge {
var mm = m
if mm < 0.0 { neg = true; mm = 0.0 - mm }
var ee = e
while mm >= HUGE_TEN { mm = mm / HUGE_TEN; ee = ee + 1 }
while mm < HUGE_ONE { mm = mm * HUGE_TEN; ee = ee - 1 }
while mm >= HUGE_TEN { mm /= HUGE_TEN; ee += 1 }
while mm < HUGE_ONE { mm *= HUGE_TEN; ee -= 1 }
if neg { mm = 0.0 - mm }
h.m = mm; h.e = ee
return h
@ -45,10 +45,10 @@ function huge_from(value: int) -> Huge {
if value == 0 { return huge_make(0.0, 0) }
var neg = false
var v: long = value
if v < 0 { neg = true; v = 0 - v }
if v < 0 { neg = true; v = -v }
var e = 0
var p: long = 1
while p * 10 <= v { p = p * 10; e = e + 1 }
while p * 10 <= v { p *= 10; e += 1 }
let raw: long = (v * 65536) / p # v / 10^e in Q16.16 (in [1,10))
let rawi: int = raw
var m: fixed = as_fixed(rawi)
@ -78,7 +78,7 @@ function huge_add(a: Huge, b: Huge) -> Huge {
if diff > 8 { return big } # negligible at display precision
var sm = small.m
var k = 0
while k < diff { sm = sm / HUGE_TEN; k = k + 1 }
while k < diff { sm /= HUGE_TEN; k += 1 }
return huge_make(big.m + sm, big.e)
}
@ -90,9 +90,9 @@ function huge_cmp(a: Huge, b: Huge) -> int {
if sa != sb { if sa > sb { return 1 }; return -1 }
if sa == 0 { return 0 }
var c = 0
if a.e != b.e { if a.e > b.e { c = 1 } else { c = 0 - 1 } }
else { if a.m > b.m { c = 1 } else { if a.m < b.m { c = 0 - 1 } else { c = 0 } } }
if sa < 0 { c = 0 - c }
if a.e != b.e { if a.e > b.e { c = 1 } else { c = -1 } }
else { if a.m > b.m { c = 1 } else { if a.m < b.m { c = -1 } else { c = 0 } } }
if sa < 0 { c = -c }
return c
}
@ -109,8 +109,8 @@ function huge_str(a: Huge) -> pointer {
let frac: fixed = m - fixed(ip)
var dd: int = floor(frac * 100.0 + 0.5) # round the two decimals to nearest
var ex = a.e
if dd >= 100 { dd = 0; ip = ip + 1 } # rounding carried into the ones place
if ip >= 10 { ip = 1; ex = ex + 1 } # ...and on into the exponent
if dd >= 100 { dd = 0; ip += 1 } # rounding carried into the ones place
if ip >= 10 { ip = 1; ex += 1 } # ...and on into the exponent
var ds = string(dd)
if dd < 10 { ds = "0" + ds }
return neg + string(ip) + "." + ds + "e" + string(ex)
@ -124,8 +124,8 @@ const ANGLE_TAU: fixed = 6.28318531
# wrap any radian value into the half-open range [-pi, pi)
function angle_wrap(a: fixed) -> fixed {
var x = a
while x >= ANGLE_PI { x = x - ANGLE_TAU }
while x < 0.0 - ANGLE_PI { x = x + ANGLE_TAU }
while x >= ANGLE_PI { x -= ANGLE_TAU }
while x < 0.0 - ANGLE_PI { x += ANGLE_TAU }
return x
}