rm push/pop

This commit is contained in:
2026-02-26 08:13:27 -06:00
parent ef7e3e6449
commit ce6b0ddb3a
31 changed files with 251 additions and 255 deletions

View File

@@ -129,7 +129,7 @@ film2d.register = function(drawable) {
// Index by plane
var plane = drawable.plane || 'default'
if (!plane_index[plane]) plane_index[plane] = []
push(plane_index[plane], id)
plane_index[plane][] = id
// Index by groups (effect routing only)
var groups = drawable.groups || []
@@ -138,7 +138,7 @@ film2d.register = function(drawable) {
for (i = 0; i < length(groups); i++) {
g = groups[i]
if (!group_index[g]) group_index[g] = []
push(group_index[g], id)
group_index[g][] = id
}
return id
@@ -177,7 +177,7 @@ film2d.unregister = function(id) {
film2d.index_group = function(id, group) {
if (!group_index[group]) group_index[group] = []
if (search(group_index[group], text(id)) == null)
push(group_index[group], text(id))
group_index[group][] = text(id)
}
film2d.unindex_group = function(id, group) {
@@ -218,9 +218,9 @@ film2d.query = function(selector) {
// If also filtering by group, check membership
if (selector.group) {
groups = d.groups || []
if (search(groups, selector.group) != null) push(result, d)
if (search(groups, selector.group) != null) result[] = d
} else {
push(result, d)
result[] = d
}
}
}
@@ -232,7 +232,7 @@ film2d.query = function(selector) {
ids = group_index[selector.group] || []
for (i = 0; i < length(ids); i++) {
d = registry[ids[i]]
if (d && d.visible != false) push(result, d)
if (d && d.visible != false) result[] = d
}
return result
}
@@ -245,7 +245,7 @@ film2d.query = function(selector) {
if (!seen[ids[i]]) {
seen[ids[i]] = true
d = registry[ids[i]]
if (d && d.visible != false) push(result, d)
if (d && d.visible != false) result[] = d
}
}
}
@@ -268,7 +268,7 @@ film2d.get_groups = function(id) {
film2d.all_groups = function() {
var groups = []
arrfor(array(group_index), g => {
if (length(group_index[g]) > 0) push(groups, g)
if (length(group_index[g]) > 0) groups[] = g
})
return groups
}
@@ -312,7 +312,7 @@ film2d.render = function(params, render_backend) {
b = []
buckets[layer_key] = b
}
push(b, d)
b[] = d
}
// Sort layers numerically (keys are text)
@@ -339,14 +339,14 @@ film2d.render = function(params, render_backend) {
if (!y_down) b = reverse(b) // y_up => smaller y draws later => reverse
}
for (j = 0; j < length(b); j++) push(sorted_drawables, b[j])
for (j = 0; j < length(b); j++) sorted_drawables[] = b[j]
}
drawables = sorted_drawables
var commands = []
push(commands, { cmd: "begin_render", target: target, clear: clear_color, target_size: target_size })
push(commands, { cmd: "set_camera", camera: camera })
commands[] = { cmd: "begin_render", target: target, clear: clear_color, target_size: target_size }
commands[] = { cmd: "set_camera", camera: camera }
var batches = _batch_drawables(drawables)
var batch = null
@@ -354,18 +354,18 @@ film2d.render = function(params, render_backend) {
for (i = 0; i < length(batches); i++) {
batch = batches[i]
if (batch.type == "sprite_batch")
push(commands, { cmd: "draw_batch", batch_type: "sprites", geometry: { sprites: batch.sprites }, texture: batch.texture, material: batch.material })
commands[] = { cmd: "draw_batch", batch_type: "sprites", geometry: { sprites: batch.sprites }, texture: batch.texture, material: batch.material }
else if (batch.type == "mesh2d_batch")
push(commands, { cmd: "draw_mesh2d", meshes: batch.meshes, texture: batch.texture, material: batch.material })
commands[] = { cmd: "draw_mesh2d", meshes: batch.meshes, texture: batch.texture, material: batch.material }
else if (batch.type == "text")
push(commands, { cmd: "draw_text", drawable: batch.drawable })
commands[] = { cmd: "draw_text", drawable: batch.drawable }
else if (batch.type == "texture_ref")
push(commands, { cmd: "draw_texture_ref", drawable: batch.drawable })
commands[] = { cmd: "draw_texture_ref", drawable: batch.drawable }
else if (batch.type == "shape")
push(commands, { cmd: "draw_shape", drawable: batch.drawable })
commands[] = { cmd: "draw_shape", drawable: batch.drawable }
}
push(commands, { cmd: "end_render" })
commands[] = { cmd: "end_render" }
return { commands: commands }
}
@@ -408,9 +408,9 @@ function _batch_drawables(drawables) {
mat = d.material || {blend: 'alpha', sampler: d.filter || 'nearest'}
if (current && current.type == 'sprite_batch' && current.texture == tex && _mat_eq(current.material, mat)) {
push(current.sprites, d)
current.sprites[] = d
} else {
if (current) push(batches, current)
if (current) batches[] = current
current = {type: 'sprite_batch', texture: tex, material: mat, sprites: [d]}
}
} else if (d.type == 'particles') {
@@ -437,9 +437,9 @@ function _batch_drawables(drawables) {
}
if (current && current.type == 'sprite_batch' && current.texture == tex && _mat_eq(current.material, mat)) {
push(current.sprites, sprite)
current.sprites[] = sprite
} else {
if (current) push(batches, current)
if (current) batches[] = current
current = {type: 'sprite_batch', texture: tex, material: mat, sprites: [sprite]}
}
}
@@ -480,9 +480,9 @@ function _batch_drawables(drawables) {
tex = img
mat = default_mat
if (current && current.type == 'sprite_batch' && current.texture == tex && _mat_eq(current.material, mat)) {
push(current.sprites, sprite)
current.sprites[] = sprite
} else {
if (current) push(batches, current)
if (current) batches[] = current
current = {type: 'sprite_batch', texture: tex, material: mat, sprites: [sprite]}
}
}
@@ -493,28 +493,28 @@ function _batch_drawables(drawables) {
mat = d.material || {blend: d.blend || 'alpha', sampler: d.filter || 'linear'}
if (current && current.type == 'mesh2d_batch' && current.texture == tex && _mat_eq(current.material, mat)) {
push(current.meshes, d)
current.meshes[] = d
} else {
if (current) push(batches, current)
if (current) batches[] = current
current = {type: 'mesh2d_batch', texture: tex, material: mat, meshes: [d]}
}
} else if (d.type == 'shape') {
// Shapes are rendered individually (each has unique SDF params)
if (current) {
push(batches, current)
batches[] = current
current = null
}
push(batches, {type: 'shape', drawable: d})
batches[] = {type: 'shape', drawable: d}
} else {
if (current) {
push(batches, current)
batches[] = current
current = null
}
push(batches, {type: d.type, drawable: d})
batches[] = {type: d.type, drawable: d}
}
}
if (current) push(batches, current)
if (current) batches[] = current
return batches
}
@@ -531,7 +531,7 @@ film2d.snapshot = function() {
for (i = 0; i < length(ids); i++) {
d = registry[ids[i]]
if (!d) continue
push(result, {
result[] = {
id: ids[i],
type: d.type,
pos: d.pos ? {x: d.pos.x, y: d.pos.y} : null,
@@ -546,7 +546,7 @@ film2d.snapshot = function() {
opacity: d.opacity,
image: d.image ? (is_text(d.image) ? d.image : '(texture)') : null,
text: d.text
})
}
}
return result
}