refactor(M03): extract WMO render build queue

This commit is contained in:
2026-07-17 00:56:55 +04:00
parent 040b635ec6
commit e1bb105fff
12 changed files with 643 additions and 42 deletions
+59
View File
@@ -0,0 +1,59 @@
class_name WmoRenderBuildJob
extends RefCounted
## Holds one lightweight-WMO build cursor and strong engine-object references.
## Releasing this record never frees the referenced Node or Resource.
var _placement_key: String
var _root: Node3D
var _render_resource: Resource
var _mesh_index: int = 0
var _multimesh_index: int = 0
func _init(placement_key: String, root: Node3D, render_resource: Resource) -> void:
_placement_key = placement_key
_root = root
_render_resource = render_resource
## Returns the immutable placement identity used by the queue.
func placement_key() -> String:
return _placement_key
## Returns the strongly referenced scene root without transferring ownership.
func root() -> Node3D:
return _root
## Returns the strongly referenced render resource without transferring ownership.
func render_resource() -> Resource:
return _render_resource
## Returns the current mesh-group cursor.
func mesh_index() -> int:
return _mesh_index
## Returns the current doodad MultiMesh-group cursor.
func multimesh_index() -> int:
return _multimesh_index
## Atomically adopts both cursor values returned by the pure step planner.
func adopt_cursors(next_mesh_index: int, next_multimesh_index: int) -> void:
_mesh_index = next_mesh_index
_multimesh_index = next_multimesh_index
## Returns detached scalar state and never exposes engine-object references.
func diagnostic_snapshot() -> Dictionary:
return {
"placement_key": _placement_key,
"mesh_index": _mesh_index,
"multimesh_index": _multimesh_index,
"has_root": _root != null,
"has_render_resource": _render_resource != null,
}
@@ -0,0 +1 @@
uid://gyjq5dqueyi7
+88
View File
@@ -0,0 +1,88 @@
class_name WmoRenderBuildQueue
extends RefCounted
## Owns pending lightweight-WMO job records and FIFO placement keys.
const JOB_SCRIPT := preload("res://src/render/wmo/wmo_render_build_job.gd")
var _jobs_by_placement_key: Dictionary = {}
var _queued_placement_keys: Array[String] = []
## Enqueues a new typed job. Duplicate placement keys replace the keyed job but
## append another FIFO entry, preserving the loader's historical behavior.
func enqueue(placement_key: String, root: Node3D, render_resource: Resource) -> bool:
if placement_key.is_empty() or root == null or render_resource == null:
return false
_jobs_by_placement_key[placement_key] = JOB_SCRIPT.new(
placement_key,
root,
render_resource
)
_queued_placement_keys.append(placement_key)
return true
## Returns whether at least one FIFO key, including a stale key, is pending.
func has_pending() -> bool:
return not _queued_placement_keys.is_empty()
## Returns the front FIFO key, or an empty String when the queue is empty.
func front_key() -> String:
if _queued_placement_keys.is_empty():
return ""
return _queued_placement_keys.front()
## Returns the current typed job for a placement key, or null for a stale key.
func job_for(placement_key: String) -> WmoRenderBuildJob:
return _jobs_by_placement_key.get(placement_key, null) as WmoRenderBuildJob
## Pops and returns the front FIFO key, or an empty String when already empty.
func pop_front() -> String:
if _queued_placement_keys.is_empty():
return ""
return _queued_placement_keys.pop_front()
## Cancels the keyed job and erases only the first matching FIFO key. Returns
## whether an active job record existed. Engine objects are never freed here.
func cancel(placement_key: String) -> bool:
var had_job := _jobs_by_placement_key.has(placement_key)
_jobs_by_placement_key.erase(placement_key)
_queued_placement_keys.erase(placement_key)
return had_job
## Releases all job/key references without freeing referenced engine objects.
func clear() -> void:
_jobs_by_placement_key.clear()
_queued_placement_keys.clear()
## Returns FIFO entry count, including duplicate and stale keys.
func pending_count() -> int:
return _queued_placement_keys.size()
## Returns active keyed job count, excluding stale FIFO keys.
func active_job_count() -> int:
return _jobs_by_placement_key.size()
## Returns detached FIFO order and placement-key-sorted scalar job diagnostics.
func diagnostic_snapshot() -> Dictionary:
var placement_keys: Array = _jobs_by_placement_key.keys()
placement_keys.sort()
var jobs: Array[Dictionary] = []
for placement_key_variant in placement_keys:
var placement_key := String(placement_key_variant)
var job := job_for(placement_key)
if job != null:
jobs.append(job.diagnostic_snapshot())
return {
"queued_placement_keys": _queued_placement_keys.duplicate(),
"jobs": jobs,
}
@@ -0,0 +1 @@
uid://b165sgg76lrt8