refactor(M03): extract M2 build batch planner
This commit is contained in:
@@ -33,6 +33,9 @@ const M2_PLACEMENT_TRANSFORM_RESOLVER_SCRIPT := preload(
|
||||
const M2_PLACEMENT_GROUPER_SCRIPT := preload(
|
||||
"res://src/render/m2/m2_placement_grouper.gd"
|
||||
)
|
||||
const M2_BUILD_BATCH_PLANNER_SCRIPT := preload(
|
||||
"res://src/render/m2/m2_build_batch_planner.gd"
|
||||
)
|
||||
const STREAMING_TARGET_PLANNER_SCRIPT := preload("res://src/render/streaming/streaming_target_planner.gd")
|
||||
const STREAMING_TARGET_POLICY_SCRIPT := preload("res://src/render/streaming/streaming_target_policy.gd")
|
||||
const RENDER_BUDGET_SCHEDULER_SCRIPT := preload("res://src/render/streaming/render_budget_scheduler.gd")
|
||||
@@ -219,6 +222,7 @@ var _m2_unique_placement_registry := (
|
||||
)
|
||||
var _m2_placement_transform_resolver := M2_PLACEMENT_TRANSFORM_RESOLVER_SCRIPT.new()
|
||||
var _m2_placement_grouper := M2_PLACEMENT_GROUPER_SCRIPT.new()
|
||||
var _m2_build_batch_planner := M2_BUILD_BATCH_PLANNER_SCRIPT.new()
|
||||
var _m2_mesh_cache: Dictionary = {}
|
||||
var _m2_mesh_load_requests: Dictionary = {}
|
||||
var _m2_mesh_finalize_queue: Array = []
|
||||
@@ -4315,14 +4319,15 @@ func _process_m2_build_jobs() -> void:
|
||||
_m2_build_queue.append(key)
|
||||
_render_budget_scheduler.try_consume_permit(RENDER_BUDGET_SCHEDULER_SCRIPT.M2_BUILD)
|
||||
continue
|
||||
var batch_size: int = (
|
||||
maxi(1, m2_animated_instances_per_tick)
|
||||
if animated_prototype != null
|
||||
else maxi(1, m2_multimesh_batch_size)
|
||||
var batch_plan: Dictionary = _m2_build_batch_planner.plan_batch(
|
||||
transforms.size(),
|
||||
offset,
|
||||
animated_prototype != null,
|
||||
m2_animated_instances_per_tick,
|
||||
m2_multimesh_batch_size
|
||||
)
|
||||
var batch_count: int = mini(batch_size, maxi(0, transforms.size() - offset))
|
||||
var batch_count: int = int(batch_plan["batch_count"])
|
||||
var serial: int = int(job.get("serial", 0))
|
||||
var consumed := batch_count
|
||||
if batch_count > 0:
|
||||
if animated_prototype != null:
|
||||
_materialize_m2_animated_batch(root as Node3D, rel_path, animated_prototype, transforms, offset, batch_count, serial)
|
||||
@@ -4337,11 +4342,11 @@ func _process_m2_build_jobs() -> void:
|
||||
else:
|
||||
_materialize_m2_group_batch(root as Node3D, rel_path, mesh, transforms, offset, batch_count, serial)
|
||||
job["serial"] = serial + 1
|
||||
if consumed <= 0 or offset + consumed >= transforms.size():
|
||||
if bool(batch_plan["group_complete"]):
|
||||
job["index"] = index + 1
|
||||
job["offset"] = 0
|
||||
else:
|
||||
job["offset"] = offset + consumed
|
||||
job["offset"] = int(batch_plan["next_offset"])
|
||||
_m2_build_jobs[key] = job
|
||||
_render_budget_scheduler.try_consume_permit(RENDER_BUDGET_SCHEDULER_SCRIPT.M2_BUILD)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user