Merge commit 'f104995' into lang/ecs

This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 02:02:11 +03:00
commit e8a34255ac
10 changed files with 45701 additions and 45326 deletions

View file

@ -45,7 +45,7 @@ function bd_pass_down(ui_st: mut UiState, n: UiNode, k: UiTpl, e: UiEnv) -> void
}
let id = tpl_attr(k, "id")
if id != null { n.id = ui_eval_text(ui_st, id, e) }
let up = new UiPass
let up = up_take(ui_st)
up.sheet = k.sheet
up.style = k.style
up.env = e

View file

@ -10,7 +10,7 @@ export property UiClass {
make: fn() -> pointer = null
props: fn(pointer, Val) -> void = null
model: fn(pointer, Val) -> Val = null # fills the object it is given (the instance keeps one)
call: fn(pointer, string, Val) -> Val = null
call: fn(pointer, string, Val, Val) -> Val = null # the last: where to write the answer, or null
root: UiTpl = null # the template, once read
sheet: UiSheet = null
seen_xml: string = "" # the files as a developer's build last found them on disk

View file

@ -58,7 +58,7 @@ function env_set(ui_st: mut UiState, e: UiEnv, name: string, v: Val) -> void {
if at.inst != null {
let args = Value.list()
Value.add(args, v)
if Value.kind(at.inst.cls.call(at.inst.ptr, `set:{name}`, args)) != 99 { return }
if Value.kind(at.inst.cls.call(at.inst.ptr, `set:{name}`, args, null)) != 99 { return }
}
if at.state != null and Value.has(at.state, name) != 0 {
Value.put(at.state, name, v)

View file

@ -51,7 +51,7 @@ function ev_call_with(ui_st: mut UiState, x: UiExpr, e: UiEnv, args: Val) -> Val
var at = e
while at != null {
if at.inst != null {
let r = at.inst.cls.call(at.inst.ptr, x.s, args)
let r = at.inst.cls.call(at.inst.ptr, x.s, args, uv_hold(ui_st))
if Value.kind(r) != 99 { return r }
}
at = at.parent

View file

@ -12,6 +12,9 @@ export property UiPool {
envs1: []UiEnv = null
un: int = 0
ue: int = 0
ups0: []UiPass = null # a component root's passes (bd_pass_down)
ups1: []UiPass = null
uu: int = 0
vals0: []Val = null # what expressions work out while the screen is built (uv_new)
vals1: []Val = null
uv: int = 0
@ -31,12 +34,15 @@ function pl_begin(ui_st: mut UiState, screen: string) -> void {
p.envs1 = new []UiEnv
p.vals0 = new []Val
p.vals1 = new []Val
p.ups0 = new []UiPass
p.ups1 = new []UiPass
push(ui_st.pl_pools, p)
}
p.gen = 1 - p.gen
p.un = 0
p.ue = 0
p.uv = 0
p.uu = 0
ui_st.pl_cur = p
}
# a node, blank, with its own lists (empty) - from the pool when a build is under way
@ -122,3 +128,33 @@ function uv_bool(ui_st: mut UiState, b: bool) -> Val {
if b { return ui_st.uv_true }
return ui_st.uv_false
}
# a pooled record as it is, for a call to write its answer into (a list keeps its items); null outside
# a build, where what is answered may be kept
function uv_hold(ui_st: mut UiState) -> Val {
let p = ui_st.pl_cur
if not ui_st.uv_on or p == null { return null }
var list = p.vals0
if p.gen == 1 { list = p.vals1 }
if p.uv < len(list) {
p.uv += 1
return list[p.uv - 1]
}
let v = Value.null()
push(list, v)
p.uv += 1
return v
}
function up_take(ui_st: mut UiState) -> UiPass {
let p = ui_st.pl_cur
if p == null { return new UiPass }
var list = p.ups0
if p.gen == 1 { list = p.ups1 }
if p.uu < len(list) {
p.uu += 1
return list[p.uu - 1]
}
let u = new UiPass
push(list, u)
p.uu += 1
return u
}

View file

@ -45,17 +45,11 @@ export function ui_image_reload(ui_st: mut UiState, path: string) -> void {
}
}
function r3u_image(render3d_st: mut Render3dState, 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(ui_st.r3u_atlas) {
if ui_st.r3u_atlas[k] == prefix {
r3u_cell(render3d_st, ui_st, k, src[colon + 1..len(src)], x, y, w, h, c, a)
return
}
for k in 0 .. len(ui_st.r3u_atlas) { # icon:NAME, the atlas and the name read in place
let p = ui_st.r3u_atlas[k]
if len(src) > len(p) and src[len(p)] == 58 and sat(src, 0, p) {
r3u_cell(render3d_st, ui_st, k, src, len(p) + 1, x, y, w, h, c, a)
return
}
}
let t = r3u_tex(render3d_st, ui_st, src)
@ -77,15 +71,17 @@ function r3u_is_cell(ui_st: UiState, src: string) -> bool {
}
return false
}
function r3u_cell(render3d_st: mut Render3dState, ui_st: mut UiState, k: int, name: string, x: float, y: float, w: float, h: float, c: int, a: float) -> void {
# the cell whose name is src from `at` on (compared where it stands), or its number
function r3u_cell(render3d_st: mut Render3dState, ui_st: mut UiState, k: int, src: string, at: int, x: float, y: float, w: float, h: float, c: int, a: float) -> void {
let names = ui_st.r3u_atlas_names[k]
let n = len(src) - at
var idx = -1
for i in 0 .. len(names) {
if names[i] == name { idx = i }
if len(names[i]) == n and sat(src, at, names[i]) { 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 and n > 0 and src[at] >= 48 and src[at] <= 57 { idx = int(el_num_in(src, at, len(src))) }
if idx < 0 {
ui_err(ui_st, `{ui_st.r3u_atlas[k]}:{name}: the atlas has no such picture`)
ui_err(ui_st, `{src}: the atlas has no such picture`)
return
}
let cols = ui_st.r3u_atlas_cols[k]

View file

@ -178,6 +178,76 @@ function value_be_str(v: Val, s: pointer) -> Val {
v.txt = s
return v
}
# a result written into `into` when one is given (a record ludic.ui keeps and hands out again), made
# as ever when it is null - what a component's call() answers a template with
function value_into(into: Val, tag: int) -> Val {
if into == null { return value_new(tag) }
return value_become(into, tag)
}
function value_into_null(into: Val) -> Val { return value_into(into, 0) }
function value_into_int(into: Val, n: int) -> Val {
let v = value_into(into, 1)
v.num = n
return v
}
function value_into_float(into: Val, x: float) -> Val {
let v = value_into(into, 7)
v.num = float_bits(x)
return v
}
function value_into_str(into: Val, s: pointer) -> Val {
let v = value_into(into, 4)
v.txt = s
return v
}
function value_into_bool(into: Val, b: bool) -> Val {
let v = value_into(into, 3)
if b { v.num = 1 }
return v
}
# a list result: `into`'s items are kept and changed in place where they are already that kind
function value_into_list(into: Val, n: int) -> Val {
if into == null { return value_list() }
into.tag = 5
into.num = 0
into.txt = null
value_lists(into)
while len(into.kids) > n { List.pop(into.kids) }
return into
}
function value_into_ints(into: Val, xs: []int) -> Val {
let l = value_into_list(into, len(xs))
for i in 0 .. len(xs) {
let v = value_item(l, i, 1)
v.num = xs[i]
}
return l
}
function value_into_floats(into: Val, xs: []float) -> Val {
let l = value_into_list(into, len(xs))
for i in 0 .. len(xs) {
let v = value_item(l, i, 7)
v.num = float_bits(xs[i])
}
return l
}
function value_into_strs(into: Val, xs: []string) -> Val {
let l = value_into_list(into, len(xs))
for i in 0 .. len(xs) {
let v = value_item(l, i, 4)
v.txt = xs[i]
}
return l
}
function value_into_bools(into: Val, xs: []bool) -> Val {
let l = value_into_list(into, len(xs))
for i in 0 .. len(xs) {
let v = value_item(l, i, 3)
v.num = 0
if xs[i] { v.num = 1 }
}
return l
}
# a list or an object emptied in place, its room kept - for one filled again every frame
function value_clear(v: Val) -> void {
if v.kids == null { return }

View file

@ -41,6 +41,18 @@ function cm_model_src(c: int, px: pointer, rec: pointer, head: Node) -> pointer
}
return src + " return o\n}\n"
}
# what a call answers, written into `into` (ludic.ui's pooled record while it builds, null otherwise)
function cm_into(c: int, ty: pointer, x: pointer, head: Node) -> pointer {
if (ty == "int") { return `value_into_int(into, {x})` }
if (ty == "float") { return `value_into_float(into, {x})` }
if (ty == "string") { return `value_into_str(into, {x})` }
if (ty == "bool") { return `value_into_bool(into, {x})` }
if (ty == "[]int") { return `value_into_ints(into, {x})` }
if (ty == "[]float") { return `value_into_floats(into, {x})` }
if (ty == "[]string") { return `value_into_strs(into, {x})` }
if (ty == "[]bool") { return `value_into_bools(into, {x})` }
return cm_to(c, ty, x, head)
}
function cm_set(c: int, ty: pointer, k: pointer, x: pointer, head: Node) -> pointer {
if (ty == "int") { return ` value_set_int(o, "{k}", {x})\n` }
if (ty == "float") { return ` value_set_float(o, "{k}", {x})\n` }
@ -61,7 +73,7 @@ function cm_to(c: int, ty: pointer, x: pointer, head: Node) -> pointer {
# call(name, args): a function or an event by name, or "set:NAME" for a state the template sets.
# A name it does not know answers a Value of kind 99, which the runtime reports.
function cm_call_src(c: int, px: pointer, rec: pointer, head: Node) -> pointer {
var src = `function {px}call(p: pointer, name: string, args: Val) -> Val {{\n let s: {rec} = p\n`
var src = `function {px}call(p: pointer, name: string, args: Val, into: Val) -> Val {{\n let s: {rec} = p\n`
let calls = g_cm_calls[c]
var i = 0
while i < len(calls) {
@ -75,10 +87,7 @@ function cm_call_src(c: int, px: pointer, rec: pointer, head: Node) -> pointer {
}
src = src + ` if name == "{g_cm_cnames[c][i]}" {{\n`
let call = f.s + "(" + args + ")"
if f.ty == "void" { src = src + ` {call}\n return value_null()\n` } else {
let back = cm_to(c, f.ty, call, head)
src = src + ` return {back}\n`
}
if f.ty == "void" { src = src + ` {call}\n return value_into_null(into)\n` } else { src = src + ` return {cm_into(c, f.ty, call, head)}\n` }
src = src + " }\n"
i += 1
}
@ -87,11 +96,11 @@ function cm_call_src(c: int, px: pointer, rec: pointer, head: Node) -> pointer {
if not g_cm_prop[c][i] {
let k = g_cm_keep[c][i]
let got = cm_from(c, g_cm_keep_ty[c][i], "value_at(args, 0)")
src = src + ` if name == "set:{k}" {{\n s.{k} = {got}\n return value_null()\n }}\n`
src = src + ` if name == "set:{k}" {{\n s.{k} = {got}\n return value_into_null(into)\n }}\n`
}
i += 1
}
return src + " return value_new(99)\n}\n"
return src + " return value_into(into, 99)\n}\n"
}
# a parameter out of the template's argument list
function cm_arg(c: int, p: Node, i: int) -> pointer {

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff