render3d: gltf_cached - a still model loaded once by dir, file and node

A game placing props while it plays (a sign an animal leaves, a fish, a bobber) loaded each through
gltf_load, which reads the file and parses its document every time. gltf_cached finds the same
(dir, file, node) by comparing the names in place and hands back the model the first load made;
a model whose document is read after the load (ludic.anim's clips) still goes through gltf_load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 11:39:41 +03:00
parent 0068411946
commit de85f201ad
3 changed files with 32 additions and 0 deletions

View file

@ -108,6 +108,10 @@ export state Render3dState {
gltf_mat_nrm: words = null
gltf_mat_arm: words = null
gltf_mat_n: int = 0
gltf_kept: []Model = null # gltf_cached's: a still model by dir, file and node, loaded once
gltf_kept_dir: []string = null
gltf_kept_file: []string = null
gltf_kept_node: []string = null
gltf_cutout: bool = false # the material being loaded is alpha-blended (a cut-out atlas)
gpu_kind: int = 0 # the backend running; 0 until gpu_select
gpu_wanted: int = 0 # what was asked for (setting or R3D_GFX)

View file

@ -0,0 +1,27 @@
# gltf_cached.ludic - a still model loaded once: the same (dir, file, node) asked again hands back the
# model the first load made, found by comparing the names in place, so asking allocates nothing. For
# props a game places while it plays (a fish, a sign an animal leaves); a model whose document is
# read after the load (ludic.anim's clips) still goes through gltf_load. A model loaded here is shared
# by every actor drawing it, and is never released.
export function gltf_cached(render3d_st: mut Render3dState, dir: string, file: string, node_name: string) -> Model {
if render3d_st.gltf_kept == null {
render3d_st.gltf_kept = new []Model
render3d_st.gltf_kept_dir = new []string
render3d_st.gltf_kept_file = new []string
render3d_st.gltf_kept_node = new []string
}
for i in 0 .. len(render3d_st.gltf_kept) {
if render3d_st.gltf_kept_node[i] == node_name and render3d_st.gltf_kept_file[i] == file and render3d_st.gltf_kept_dir[i] == dir { return render3d_st.gltf_kept[i] }
}
let m = gltf_load(render3d_st, dir, file, node_name)
push(render3d_st.gltf_kept, m)
push(render3d_st.gltf_kept_dir, dir)
push(render3d_st.gltf_kept_file, file)
push(render3d_st.gltf_kept_node, node_name)
return m
}
export function gltf_cached_count(render3d_st: Render3dState) -> int {
if render3d_st.gltf_kept == null { return 0 }
return len(render3d_st.gltf_kept)
}

View file

@ -29,6 +29,7 @@ import "post.ludic"
import "quat.ludic"
import "gltf.ludic"
import "gltf_release.ludic"
import "gltf_cached.ludic"
import "skin.ludic"
import "scatter.ludic"
import "actor.ludic"