refactor(M03): extract M2 animation load pipeline state
This commit is contained in:
@@ -72,6 +72,9 @@ const M2_PROTOTYPE_CACHE_STATE_SCRIPT := preload(
|
||||
const M2_MESH_LOAD_PIPELINE_STATE_SCRIPT := preload(
|
||||
"res://src/render/m2/m2_mesh_load_pipeline_state.gd"
|
||||
)
|
||||
const M2_ANIMATION_LOAD_PIPELINE_STATE_SCRIPT := preload(
|
||||
"res://src/render/m2/m2_animation_load_pipeline_state.gd"
|
||||
)
|
||||
const M2_MESH_RESOURCE_CACHE_STATE_SCRIPT := preload(
|
||||
"res://src/render/m2/m2_mesh_resource_cache_state.gd"
|
||||
)
|
||||
@@ -270,8 +273,7 @@ var _m2_prototype_cache_state := M2_PROTOTYPE_CACHE_STATE_SCRIPT.new()
|
||||
var _m2_mesh_resource_cache_state := M2_MESH_RESOURCE_CACHE_STATE_SCRIPT.new()
|
||||
var _m2_mesh_resource_extractor := M2_MESH_RESOURCE_EXTRACTOR_SCRIPT.new()
|
||||
var _m2_mesh_load_pipeline_state := M2_MESH_LOAD_PIPELINE_STATE_SCRIPT.new()
|
||||
var _m2_animation_load_requests: Dictionary = {}
|
||||
var _m2_animation_finalize_queue: Array = []
|
||||
var _m2_animation_load_pipeline_state := M2_ANIMATION_LOAD_PIPELINE_STATE_SCRIPT.new()
|
||||
var _wmo_build_jobs: Dictionary = {}
|
||||
var _wmo_build_queue: Array = []
|
||||
var _tile_loading_tasks: Dictionary = {}
|
||||
@@ -1017,7 +1019,7 @@ func _log_hitch_profile(start_usec: int, timings: Array[String], did_refresh: bo
|
||||
_adt_water_load_pipeline_state.total_load_count(),
|
||||
_detail_asset_queue.size(),
|
||||
_m2_group_tasks.size(),
|
||||
_m2_animation_finalize_queue.size() + _m2_animation_load_requests.size(),
|
||||
_m2_animation_load_pipeline_state.total_work_count(),
|
||||
_m2_mesh_load_pipeline_state.total_work_count(),
|
||||
_m2_build_queue.size(),
|
||||
(
|
||||
@@ -1048,7 +1050,7 @@ func render_baseline_snapshot() -> Dictionary:
|
||||
"water": _adt_water_load_pipeline_state.total_load_count(),
|
||||
"detail": _detail_asset_queue.size(),
|
||||
"m2_task": _m2_group_tasks.size(),
|
||||
"m2_animation": _m2_animation_finalize_queue.size() + _m2_animation_load_requests.size(),
|
||||
"m2_animation": _m2_animation_load_pipeline_state.total_work_count(),
|
||||
"m2_mesh": _m2_mesh_load_pipeline_state.total_work_count(),
|
||||
"m2_build": _m2_build_queue.size(),
|
||||
"wmo_build": (
|
||||
@@ -1334,7 +1336,7 @@ func _tick_runtime_stats(delta: float) -> void:
|
||||
_tile_load_queue.size(),
|
||||
_detail_asset_queue.size(),
|
||||
_m2_group_tasks.size(),
|
||||
_m2_animation_finalize_queue.size() + _m2_animation_load_requests.size(),
|
||||
_m2_animation_load_pipeline_state.total_work_count(),
|
||||
_m2_mesh_load_pipeline_state.total_work_count(),
|
||||
_m2_build_queue.size(),
|
||||
(
|
||||
@@ -2355,15 +2357,14 @@ func _wait_for_tile_tasks() -> void:
|
||||
_m2_mesh_load_pipeline_state.clear()
|
||||
_m2_runtime_mesh_finalizer.clear()
|
||||
|
||||
for pending in _m2_animation_load_requests.values():
|
||||
for pending in _m2_animation_load_pipeline_state.request_records_snapshot():
|
||||
var path: String = String(pending.get("path", ""))
|
||||
if path.is_empty():
|
||||
continue
|
||||
var status := ResourceLoader.load_threaded_get_status(path)
|
||||
if status == ResourceLoader.THREAD_LOAD_IN_PROGRESS or status == ResourceLoader.THREAD_LOAD_LOADED:
|
||||
ResourceLoader.load_threaded_get(path)
|
||||
_m2_animation_load_requests.clear()
|
||||
_m2_animation_finalize_queue.clear()
|
||||
_m2_animation_load_pipeline_state.clear()
|
||||
|
||||
var wmo_scene_request_paths := _wmo_scene_resource_cache_state.request_paths_snapshot()
|
||||
for path_variant in wmo_scene_request_paths.values():
|
||||
@@ -3004,8 +3005,7 @@ func _clear_streamed_world() -> void:
|
||||
_m2_unique_placement_registry.clear()
|
||||
_m2_mesh_load_pipeline_state.clear()
|
||||
_m2_runtime_mesh_finalizer.clear()
|
||||
_m2_animation_load_requests.clear()
|
||||
_m2_animation_finalize_queue.clear()
|
||||
_m2_animation_load_pipeline_state.clear()
|
||||
_wmo_build_jobs.clear()
|
||||
_wmo_build_queue.clear()
|
||||
_wmo_scene_resource_cache_state.clear_transient_state()
|
||||
@@ -4210,24 +4210,21 @@ func _drain_m2_group_results() -> void:
|
||||
|
||||
|
||||
func _drain_m2_animation_loads() -> void:
|
||||
for normalized_rel_variant in _m2_animation_load_requests.keys():
|
||||
var normalized_rel := String(normalized_rel_variant)
|
||||
var pending: Dictionary = _m2_animation_load_requests[normalized_rel]
|
||||
for pending in _m2_animation_load_pipeline_state.request_records_snapshot():
|
||||
var normalized_rel := String(pending.get("normalized", ""))
|
||||
var path := String(pending.get("path", ""))
|
||||
if path.is_empty():
|
||||
_m2_animation_load_requests.erase(normalized_rel)
|
||||
_m2_animation_load_pipeline_state.discard_request(normalized_rel)
|
||||
_m2_prototype_cache_state.mark_animation_static(normalized_rel)
|
||||
continue
|
||||
var status := ResourceLoader.load_threaded_get_status(path)
|
||||
if status != ResourceLoader.THREAD_LOAD_LOADED and status != ResourceLoader.THREAD_LOAD_FAILED:
|
||||
continue
|
||||
pending["status"] = status
|
||||
_m2_animation_load_requests.erase(normalized_rel)
|
||||
_m2_animation_finalize_queue.append(pending)
|
||||
_m2_animation_load_pipeline_state.complete_request(normalized_rel, status)
|
||||
|
||||
while not _m2_animation_finalize_queue.is_empty() and _render_budget_scheduler.try_consume_permit(
|
||||
while _m2_animation_load_pipeline_state.has_finalize_record() and _render_budget_scheduler.try_consume_permit(
|
||||
RENDER_BUDGET_SCHEDULER_SCRIPT.M2_ANIMATION_FINALIZE):
|
||||
var pending: Dictionary = _m2_animation_finalize_queue.pop_front()
|
||||
var pending: Dictionary = _m2_animation_load_pipeline_state.pop_finalize_record()
|
||||
var normalized_rel := String(pending.get("normalized", ""))
|
||||
if (
|
||||
normalized_rel.is_empty()
|
||||
@@ -4341,7 +4338,7 @@ func _process_m2_build_jobs() -> void:
|
||||
animated_prototype = _get_or_load_m2_native_animated_prototype(rel_path)
|
||||
if animated_prototype == null:
|
||||
animated_prototype = _get_or_load_m2_animated_prototype(rel_path)
|
||||
if enable_m2_animated_instances and _m2_animation_load_requests.has(normalized_rel):
|
||||
if enable_m2_animated_instances and _m2_animation_load_pipeline_state.has_request(normalized_rel):
|
||||
_m2_build_queue.pop_front()
|
||||
_m2_build_queue.append(key)
|
||||
_render_budget_scheduler.try_consume_permit(RENDER_BUDGET_SCHEDULER_SCRIPT.M2_BUILD)
|
||||
@@ -4945,7 +4942,7 @@ func _get_or_load_m2_animated_prototype(rel_path: String) -> Node3D:
|
||||
return cached_animated
|
||||
if _m2_prototype_cache_state.is_animation_static(normalized_rel):
|
||||
return null
|
||||
if _m2_animation_load_requests.has(normalized_rel):
|
||||
if _m2_animation_load_pipeline_state.has_request(normalized_rel):
|
||||
return null
|
||||
|
||||
_request_m2_animation_load(normalized_rel)
|
||||
@@ -4953,7 +4950,7 @@ func _get_or_load_m2_animated_prototype(rel_path: String) -> Node3D:
|
||||
|
||||
|
||||
func _request_m2_animation_load(normalized_rel: String) -> void:
|
||||
if normalized_rel.is_empty() or _m2_animation_load_requests.has(normalized_rel):
|
||||
if normalized_rel.is_empty() or _m2_animation_load_pipeline_state.has_request(normalized_rel):
|
||||
return
|
||||
var cache_res_path := _find_m2_animated_glb_cache_path(normalized_rel)
|
||||
if cache_res_path.is_empty():
|
||||
@@ -4965,10 +4962,7 @@ func _request_m2_animation_load(normalized_rel: String) -> void:
|
||||
false,
|
||||
ResourceLoader.CACHE_MODE_REUSE)
|
||||
if err == OK or err == ERR_BUSY:
|
||||
_m2_animation_load_requests[normalized_rel] = {
|
||||
"normalized": normalized_rel,
|
||||
"path": cache_res_path,
|
||||
}
|
||||
_m2_animation_load_pipeline_state.remember_request(normalized_rel, cache_res_path)
|
||||
else:
|
||||
_m2_prototype_cache_state.mark_animation_static(normalized_rel)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user