diff --git a/packages/ludic.clock/queries.ludic b/packages/ludic.clock/queries.ludic index de4c0b68..8112e8e1 100644 --- a/packages/ludic.clock/queries.ludic +++ b/packages/ludic.clock/queries.ludic @@ -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 } diff --git a/packages/ludic.clock/state.ludic b/packages/ludic.clock/state.ludic index 654f1897..60feed1b 100644 --- a/packages/ludic.clock/state.ludic +++ b/packages/ludic.clock/state.ludic @@ -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 diff --git a/packages/ludic.minimap/grid.ludic b/packages/ludic.minimap/grid.ludic index 0299249b..21feb013 100644 --- a/packages/ludic.minimap/grid.ludic +++ b/packages/ludic.minimap/grid.ludic @@ -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 diff --git a/packages/ludic.minimap/pins.ludic b/packages/ludic.minimap/pins.ludic index 7df34b15..0bd1b13f 100644 --- a/packages/ludic.minimap/pins.ludic +++ b/packages/ludic.minimap/pins.ludic @@ -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] } diff --git a/packages/ludic.ui/eval_text.ludic b/packages/ludic.ui/eval_text.ludic index ef342b64..591bb221 100644 --- a/packages/ludic.ui/eval_text.ludic +++ b/packages/ludic.ui/eval_text.ludic @@ -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)