refactor(M03): extract M2 mesh resource cache state

Work-Package: M03-RND-M2-MESH-RESOURCE-CACHE-001
Agent: sindo-main-codex
Tests: 35 headless renderer/coordinate contracts pass; checkpoint dry-run 7/7; documentation and coordination gates pass
Fidelity: preserves exact Mesh references, replacement semantics and final-shutdown lifetime; no visual parity claim
This commit is contained in:
2026-07-17 12:10:37 +04:00
parent e2bb501695
commit e990a6503d
13 changed files with 478 additions and 19 deletions
@@ -0,0 +1,50 @@
class_name M2MeshResourceCacheState
extends RefCounted
## Owns normalized-path references to prepared static M2 Mesh resources.
## The caller owns loading, preparation, missing-state and materialization.
var _mesh_by_normalized_path: Dictionary = {}
## Stores one prepared Mesh for a non-empty normalized M2 path. A later store
## for the same path replaces the retained reference.
func store_mesh(normalized_relative_path: String, mesh: Mesh) -> bool:
if normalized_relative_path.is_empty() or mesh == null:
return false
_mesh_by_normalized_path[normalized_relative_path] = mesh
return true
## Returns whether one normalized path currently has a retained Mesh.
func has_mesh(normalized_relative_path: String) -> bool:
return (
not normalized_relative_path.is_empty()
and _mesh_by_normalized_path.has(normalized_relative_path)
)
## Returns the exact retained Mesh reference, or null for empty/unknown paths.
func find_mesh(normalized_relative_path: String) -> Mesh:
if not has_mesh(normalized_relative_path):
return null
return _mesh_by_normalized_path[normalized_relative_path] as Mesh
## Returns the number of retained static M2 Mesh resources.
func mesh_count() -> int:
return _mesh_by_normalized_path.size()
## Returns a detached insertion-order list of cached normalized paths.
func normalized_paths_snapshot() -> Array[String]:
var normalized_paths: Array[String] = []
for normalized_path_variant in _mesh_by_normalized_path.keys():
normalized_paths.append(String(normalized_path_variant))
return normalized_paths
## Releases all retained Mesh references. The loader calls this only after
## asynchronous work has completed during final scene shutdown.
func clear() -> void:
_mesh_by_normalized_path.clear()
@@ -0,0 +1 @@
uid://dhkyjcrdblgkd