render3d: recycle texture and buffer ids, free a released model whole, actor_release

A freed texture or buffer id goes on a spare list the next one takes; tex_note_size keeps sizes by id.
model_release frees prims, meshes, material names, the skin and leaves gltf_cached. actor_release
takes an actor off the stage and actor_new reuses its record (ECS's Things come and go all day).
steady.ludic: an actor round at 0 bytes over 2000.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 12:00:53 +03:00
parent 2fe4018d28
commit 9b482d609a
14 changed files with 208 additions and 39 deletions

View file

@ -122,12 +122,10 @@ function actor_hide_part(a: Actor, name: string, hidden: bool) -> void {
}
function actor_new(render3d_st: mut Render3dState, model: Model) -> Actor {
let a = new Actor
let a = actor_fresh(render3d_st)
a.model = model
a.scale = 1.0
a.tint = v3_new(1.0, 1.0, 1.0)
a.rough = 1.0
a.mat = m4_new()
render3d_st.ac_next_id += 1; a.id = render3d_st.ac_next_id
if model != null { a.radius = Math.max(model.radius, model.height) + 1.0 }
a.cull = 450.0
@ -417,3 +415,36 @@ function actor_clear_all(render3d_st: mut Render3dState) -> void {
List.clear(render3d_st.ac_actors)
outline_clear(render3d_st)
}
# A record as `new Actor` makes it, with its matrix and tint: a released one when there is one.
function actor_fresh(render3d_st: mut Render3dState) -> Actor {
let sp = render3d_st.ac_spare
if sp == null or len(sp) == 0 {
let a = new Actor
a.tint = v3_new(1.0, 1.0, 1.0)
a.mat = m4_new()
return a
}
let a = List.pop(sp)
a.x = 0.0; a.y = 0.0; a.z = 0.0; a.yaw = 0.0; a.scale = 0.0; a.rough = 0.0
a.tint[0] = 1.0; a.tint[1] = 1.0; a.tint[2] = 1.0
m4_identity(a.mat)
a.visible = true; a.cast_hidden = false; a.casts = true; a.row = -1
a.cutout = false; a.emissive = 0.0; a.radius = 0.0; a.cull = 0.0; a.outline = 0.0
a.skin = null; a.ocol = null
return a
}
# Off the stage for good, and its record kept for the next actor_new: whoever released it never
# touches it again. What it was lent stays its lender's (a skin clone, a rim colour); what it made
# for itself (a part's tint, a part hidden) goes.
function actor_release(render3d_st: mut Render3dState, a: Actor) -> void {
if a == null or a.id == 0 { return } # released already
actor_remove(render3d_st, a)
if a.ptint != null { free(a.ptint); a.ptint = null }
if a.hide != null { free(a.hide); a.hide = null }
a.model = null; a.skin = null; a.ocol = null
a.id = 0
if render3d_st.ac_spare == null { render3d_st.ac_spare = new []Actor }
push(render3d_st.ac_spare, a)
}