ludic/packages/ludic.photo/order.ludic
Orkuncakilkaya 3b9b4a589b frame allocs: a click is not a frame, a reducer is its dispatch's, a capped push is bounded; ludic.photo at 0
The analysis made every component function a frame root, event handlers (cmp_x_on_delete) too, and
every reducer, whether its action is dispatched every frame or once a trip: a component's 'on'
handlers are no longer roots, and a dispatch is an edge to its action's reducers, so a reducer
counts only when frame code dispatches it. A push into a field declared @max(n) is bounded by the
fence's own check and no longer counted. Maroon Lake: frame_allocs 395 -> 337, frame_keeps 188 -> 169.

ludic.photo: the roll's order and a page of it are kept lists refilled in place (the pack's page
asked for both every frame), its kept lists say @max(256), and a shot's tags, a photograph's fact
and a new roll are declared (once per shot, sale or trip). 18 allocs and 9 keeps -> 0 and 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 20:02:47 +03:00

52 lines
2.5 KiB
Text

# order.ludic - the roll's order and its pages. Forty frames is a pile in taking order; once a frame
# has a grade the useful question is which are the best. The index is mapped, never the roll resorted.
export const PHOTO_NEWEST: int = 0
export const PHOTO_BEST: int = 1
export const PHOTO_BY_SUBJECT: int = 2
export const PHOTO_PAGE: int = 8
export function photo_sort(photo_st: PhotoState) -> int { return photo_st.pht_sort }
export function photo_sort_next(photo_st: mut PhotoState) -> void { photo_st.pht_sort = (photo_st.pht_sort + 1) % 3 }
export function photo_sort_set(photo_st: mut PhotoState, s: int) -> void { photo_st.pht_sort = Math.clamp(s, 0, 2) }
# the roll in the chosen order: newest first, best first, or by subject
export function photo_order(photo_st: mut PhotoState) -> []int {
List.clear(photo_st.pht_order)
for i in 0 .. photo_st.pht_n { push(photo_st.pht_order, i) }
if photo_st.pht_sort == PHOTO_NEWEST {
for i in 0 .. photo_st.pht_n { photo_st.pht_order[i] = photo_st.pht_n - 1 - i }
return photo_st.pht_order
}
for i in 0 .. photo_st.pht_n {
var best = i
for k in i + 1 .. photo_st.pht_n { if pht_before(photo_st, photo_st.pht_order[k], photo_st.pht_order[best]) { best = k } }
let t = photo_st.pht_order[i]
photo_st.pht_order[i] = photo_st.pht_order[best]
photo_st.pht_order[best] = t
}
return photo_st.pht_order
}
function pht_before(photo_st: PhotoState, a: int, b: int) -> bool {
if photo_st.pht_sort == PHOTO_BEST { return photo_st.pht_grade[a] > photo_st.pht_grade[b] }
return photo_st.pht_mask[a] < photo_st.pht_mask[b]
}
export function photo_pages(photo_st: PhotoState) -> int { return (photo_st.pht_n + PHOTO_PAGE - 1) / PHOTO_PAGE }
export function photo_page_now(photo_st: PhotoState) -> int { return photo_st.pht_page }
export function photo_page_step(photo_st: mut PhotoState, d: int) -> void { photo_st.pht_page = Math.clamp(photo_st.pht_page + d, 0, Math.max(photo_pages(photo_st) - 1, 0)) }
# a page of the roll, in its order; the page is held inside the roll
export function photo_page_list(photo_st: mut PhotoState) -> []int {
let out = photo_st.pht_page_out
List.clear(out)
if photo_st.pht_n == 0 { return out }
let order = photo_order(photo_st)
if photo_st.pht_page >= photo_pages(photo_st) { photo_st.pht_page = photo_pages(photo_st) - 1 }
for k in 0 .. PHOTO_PAGE {
let oi = photo_st.pht_page * PHOTO_PAGE + k
if oi < photo_st.pht_n { push(photo_st.pht_page_out, order[oi]) }
}
return out
}