ludic.clock: clock_hhmm reads a table of the day's times made with the state; ludic.minimap: minimap_pin past the end is one kept empty mark; ludic.ui: ev_text's memo miss is its own declared function

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 17:57:30 +03:00
parent bad7c4a255
commit ac8c7b0c0b
5 changed files with 25 additions and 7 deletions

View file

@ -12,13 +12,24 @@ export function clock_hours_in(clock_st: ClockState, dt: float) -> float { retur
export function clock_is_night(clock_st: ClockState) -> bool { return clock_st.ck_hours > clock_st.ck_night_from or clock_st.ck_hours < clock_st.ck_night_to }
# "07:05"
# "07:05", from the table the state was made with
export function clock_hhmm(clock_st: ClockState) -> string {
let h = int(Math.floor(clock_st.ck_hours))
let m = int(Math.floor((clock_st.ck_hours - float(h)) * 60.0))
var hs = `{h}`
var ms = `{m}`
if h < 10 { hs = `0{h}` }
if m < 10 { ms = `0{m}` }
return hs + ":" + ms
return clock_st.ck_hhmm_tab[Math.clamp(h, 0, 23) * 60 + Math.clamp(m, 0, 59)]
}
@alloc_ok("once: the day's 1440 times, made with the state")
function ck_hhmm_table() -> []string {
let out = new []string
for t in 0 .. 1440 {
let h = t / 60
let m = t % 60
var hs = `{h}`
var ms = `{m}`
if h < 10 { hs = `0{h}` }
if m < 10 { ms = `0{m}` }
push(out, hs + ":" + ms)
}
return out
}

View file

@ -21,6 +21,7 @@ export property DayTurned {
}
export state ClockState {
ck_hhmm_tab: []string = ck_hhmm_table() # "00:00" .. "23:59", made with the state: asked every frame
cal_month_days: int = 30
cal_year_months: int = 12
cal_season: []int = null

View file

@ -1,6 +1,7 @@
# grid.ludic - the explored grid: square cells round the origin, and the part of it "explored" is
# measured over (a core, so a bigger grid does not change what a share of it means)
export state MinimapState {
mm_none: MinimapPin = new MinimapPin # minimap_pin past the end: an empty mark, the same one each time
mm_near: []int = new []int # minimap_pins_near's answer, cleared and refilled: a compass asks every frame
mm_land_n: int = 0 # land cells in the core, counted once per origin
mm_land_ox: float = 0.0

View file

@ -66,7 +66,7 @@ export function minimap_pin_put(minimap_st: mut MinimapState, x: float, z: float
# the i-th mark, or an empty one past the end
export function minimap_pin(minimap_st: MinimapState, i: int) -> MinimapPin {
if i < 0 or i >= minimap_pin_count(minimap_st) { return new MinimapPin }
if i < 0 or i >= minimap_pin_count(minimap_st) { return minimap_st.mm_none }
return minimap_st.mm_pins[i]
}

View file

@ -22,6 +22,11 @@ function ev_text(ui_st: mut UiState, x: UiExpr, e: UiEnv) -> Val {
if m.tags[i] == MM_TEXT and tx_same(ps, m.keys[i]) { return m.vals[i] }
at = (at + 1) & (MM_CAP - 1)
}
return ev_text_new(ui_st, m, ps)
}
# a text read this way for the first time: joined, and kept in the memo with its Value
@alloc_ok("a memo miss: once per distinct text, bounded by MM_CAP")
function ev_text_new(ui_st: mut UiState, m: UiMemo, ps: []string) -> Val {
var out = ""
for p in 0 .. len(ps) { out = out + ps[p] }
let j = mm_add(m, MM_TEXT, out)