wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic 1804 vars into 126 states, 64 into lets; 23498 edits in 460 files Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5ffe50ed02
commit
19fcf60599
459 changed files with 17862 additions and 17603 deletions
|
|
@ -1,28 +1,28 @@
|
|||
# render3d_image.ludic - pictures for the render3d backend: a texture by path (its sRGB bytes as they
|
||||
# are, clamped at its edges, loaded again when the file changes) and a cell of a named atlas
|
||||
module ludic_ui
|
||||
function r3u_tex(path: string) -> int {
|
||||
for i in 0 .. len(r3u_tex_paths) {
|
||||
if r3u_tex_paths[i] == path { return r3u_tex_fresh(i) }
|
||||
function r3u_tex(ui_st: mut UiState, path: string) -> int {
|
||||
for i in 0 .. len(ui_st.r3u_tex_paths) {
|
||||
if ui_st.r3u_tex_paths[i] == path { return r3u_tex_fresh(ui_st, i) }
|
||||
}
|
||||
push(r3u_tex_paths, path)
|
||||
push(r3u_tex_ids, r3u_tex_load(path))
|
||||
push(r3u_tex_sizes, Fs.size(path))
|
||||
push(r3u_tex_seen, r3u_now())
|
||||
return r3u_tex_ids[len(r3u_tex_ids) - 1]
|
||||
push(ui_st.r3u_tex_paths, path)
|
||||
push(ui_st.r3u_tex_ids, r3u_tex_load(path))
|
||||
push(ui_st.r3u_tex_sizes, Fs.size(path))
|
||||
push(ui_st.r3u_tex_seen, r3u_now())
|
||||
return ui_st.r3u_tex_ids[len(ui_st.r3u_tex_ids) - 1]
|
||||
}
|
||||
# a picture is looked at again every half second: a file that has changed (or that was not there,
|
||||
# and is now) is loaded again, so an <img> of a photograph written over the old one shows the new one
|
||||
function r3u_tex_fresh(i: int) -> int {
|
||||
function r3u_tex_fresh(ui_st: mut UiState, i: int) -> int {
|
||||
let now = r3u_now()
|
||||
if now - r3u_tex_seen[i] < 0.5 and now >= r3u_tex_seen[i] { return r3u_tex_ids[i] }
|
||||
r3u_tex_seen[i] = now
|
||||
let size = Fs.size(r3u_tex_paths[i])
|
||||
if size == r3u_tex_sizes[i] and (r3u_tex_ids[i] != 0 or size < 0) { return r3u_tex_ids[i] }
|
||||
if r3u_tex_ids[i] != 0 { gpu_tex_free(r3u_tex_ids[i]) }
|
||||
r3u_tex_ids[i] = r3u_tex_load(r3u_tex_paths[i])
|
||||
r3u_tex_sizes[i] = size
|
||||
return r3u_tex_ids[i]
|
||||
if now - ui_st.r3u_tex_seen[i] < 0.5 and now >= ui_st.r3u_tex_seen[i] { return ui_st.r3u_tex_ids[i] }
|
||||
ui_st.r3u_tex_seen[i] = now
|
||||
let size = Fs.size(ui_st.r3u_tex_paths[i])
|
||||
if size == ui_st.r3u_tex_sizes[i] and (ui_st.r3u_tex_ids[i] != 0 or size < 0) { return ui_st.r3u_tex_ids[i] }
|
||||
if ui_st.r3u_tex_ids[i] != 0 { gpu_tex_free(ui_st.r3u_tex_ids[i]) }
|
||||
ui_st.r3u_tex_ids[i] = r3u_tex_load(ui_st.r3u_tex_paths[i])
|
||||
ui_st.r3u_tex_sizes[i] = size
|
||||
return ui_st.r3u_tex_ids[i]
|
||||
}
|
||||
# the interface is drawn in sRGB, and a picture's bytes are sRGB, so they are taken as they are
|
||||
# (not decoded to linear, which would darken it); clamped at its edges
|
||||
|
|
@ -36,64 +36,64 @@ function r3u_tex_load(path: string) -> int {
|
|||
return t
|
||||
}
|
||||
# a picture the program has written again, loaded again the next time it is drawn
|
||||
export function ui_image_reload(path: string) -> void {
|
||||
for i in 0 .. len(r3u_tex_paths) {
|
||||
if r3u_tex_paths[i] == path {
|
||||
r3u_tex_seen[i] = -1000000.0
|
||||
r3u_tex_sizes[i] = -2
|
||||
export function ui_image_reload(ui_st: mut UiState, path: string) -> void {
|
||||
for i in 0 .. len(ui_st.r3u_tex_paths) {
|
||||
if ui_st.r3u_tex_paths[i] == path {
|
||||
ui_st.r3u_tex_seen[i] = -1000000.0
|
||||
ui_st.r3u_tex_sizes[i] = -2
|
||||
}
|
||||
}
|
||||
}
|
||||
function r3u_image(src: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void {
|
||||
function r3u_image(ui_st: mut UiState, src: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void {
|
||||
var colon = -1
|
||||
for i in 0 .. len(src) {
|
||||
if colon < 0 and src[i] == 58 { colon = i }
|
||||
}
|
||||
if colon > 0 {
|
||||
let prefix: string = src[0..colon]
|
||||
for k in 0 .. len(r3u_atlas) {
|
||||
if r3u_atlas[k] == prefix {
|
||||
r3u_cell(k, src[colon + 1..len(src)], x, y, w, h, c, a)
|
||||
for k in 0 .. len(ui_st.r3u_atlas) {
|
||||
if ui_st.r3u_atlas[k] == prefix {
|
||||
r3u_cell(ui_st, k, src[colon + 1..len(src)], x, y, w, h, c, a)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
let t = r3u_tex(src)
|
||||
let t = r3u_tex(ui_st, src)
|
||||
if t != 0 { ov_sub(t, int(x), int(y), int(w), int(h), 0.0, 0.0, 1.0, 1.0, r3u_r(c), r3u_g(c), r3u_b(c), a) }
|
||||
}
|
||||
# a picture's own size, for object-fit; an atlas cell is drawn square
|
||||
function r3u_image_w(src: string) -> float {
|
||||
if r3u_is_cell(src) { return 1.0 }
|
||||
return float(tex_width(r3u_tex(src)))
|
||||
function r3u_image_w(ui_st: mut UiState, src: string) -> float {
|
||||
if r3u_is_cell(ui_st, src) { return 1.0 }
|
||||
return float(tex_width(r3u_tex(ui_st, src)))
|
||||
}
|
||||
function r3u_image_h(src: string) -> float {
|
||||
if r3u_is_cell(src) { return 1.0 }
|
||||
return float(tex_height(r3u_tex(src)))
|
||||
function r3u_image_h(ui_st: mut UiState, src: string) -> float {
|
||||
if r3u_is_cell(ui_st, src) { return 1.0 }
|
||||
return float(tex_height(r3u_tex(ui_st, src)))
|
||||
}
|
||||
function r3u_is_cell(src: string) -> bool {
|
||||
for k in 0 .. len(r3u_atlas) {
|
||||
let p = r3u_atlas[k]
|
||||
function r3u_is_cell(ui_st: UiState, src: string) -> bool {
|
||||
for k in 0 .. len(ui_st.r3u_atlas) {
|
||||
let p = ui_st.r3u_atlas[k]
|
||||
if len(src) > len(p) and src[0..len(p)] == p and src[len(p)] == 58 { return true }
|
||||
}
|
||||
return false
|
||||
}
|
||||
function r3u_cell(k: int, name: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void {
|
||||
let names = r3u_atlas_names[k]
|
||||
function r3u_cell(ui_st: mut UiState, k: int, name: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void {
|
||||
let names = ui_st.r3u_atlas_names[k]
|
||||
var idx = -1
|
||||
for i in 0 .. len(names) {
|
||||
if names[i] == name { idx = i }
|
||||
}
|
||||
if idx < 0 and len(name) > 0 and name[0] >= 48 and name[0] <= 57 { idx = int(el_num(name)) }
|
||||
if idx < 0 {
|
||||
ui_err(`{r3u_atlas[k]}:{name}: the atlas has no such picture`)
|
||||
ui_err(ui_st, `{ui_st.r3u_atlas[k]}:{name}: the atlas has no such picture`)
|
||||
return
|
||||
}
|
||||
let cols = r3u_atlas_cols[k]
|
||||
let rows = r3u_atlas_rows[k]
|
||||
let cols = ui_st.r3u_atlas_cols[k]
|
||||
let rows = ui_st.r3u_atlas_rows[k]
|
||||
let cx = idx % cols
|
||||
let cy = idx / cols
|
||||
let u0 = float(cx) / float(cols)
|
||||
let v0 = float(cy) / float(rows)
|
||||
let s = Math.min(w, h)
|
||||
ov_sub(r3u_atlas_tex[k], int(x + (w - s) / 2.0), int(y + (h - s) / 2.0), int(s), int(s), u0, v0, u0 + 1.0 / float(cols), v0 + 1.0 / float(rows), r3u_r(c), r3u_g(c), r3u_b(c), a)
|
||||
ov_sub(ui_st.r3u_atlas_tex[k], int(x + (w - s) / 2.0), int(y + (h - s) / 2.0), int(s), int(s), u0, v0, u0 + 1.0 / float(cols), v0 + 1.0 / float(rows), r3u_r(c), r3u_g(c), r3u_b(c), a)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue