refactor(M03): extract terrain quality mesh cache
This commit is contained in:
@@ -18,6 +18,7 @@ const COORDINATE_MAPPER_SCRIPT := preload("res://src/domain/coordinates/coordina
|
||||
const ADT_TILE_COORDINATE_SCRIPT := preload("res://src/domain/coordinates/adt_tile_coordinate.gd")
|
||||
const ADT_TILE_LOCAL_POSITION_SCRIPT := preload("res://src/domain/coordinates/adt_tile_local_position.gd")
|
||||
const RENDERED_GROUND_SAMPLE_SCRIPT := preload("res://src/render/terrain/rendered_ground_sample.gd")
|
||||
const TERRAIN_QUALITY_MESH_CACHE_SCRIPT := preload("res://src/render/terrain/terrain_quality_mesh_cache.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")
|
||||
@@ -241,8 +242,7 @@ var _last_refresh_focus_pos := Vector3.ZERO
|
||||
var _has_refresh_focus := false
|
||||
var _tile_mesh_cache: Dictionary = {}
|
||||
var _tile_mesh_cache_order: Array = []
|
||||
var _terrain_quality_mesh_cache: Dictionary = {}
|
||||
var _terrain_quality_mesh_cache_order: Array = []
|
||||
var _terrain_quality_mesh_cache: RefCounted = TERRAIN_QUALITY_MESH_CACHE_SCRIPT.new()
|
||||
var _wmo_prototype_cache: Dictionary = {}
|
||||
var _wmo_render_cache: Dictionary = {}
|
||||
var _wmo_render_missing_cache: Dictionary = {}
|
||||
@@ -5500,53 +5500,28 @@ func _clear_tile_mesh_cache() -> void:
|
||||
|
||||
|
||||
func _restore_quality_terrain_mesh(tile_key: String, state: Dictionary) -> Dictionary:
|
||||
if not _terrain_quality_mesh_cache.has(tile_key):
|
||||
var cached: Dictionary = _terrain_quality_mesh_cache.call("restore", tile_key)
|
||||
if cached.is_empty():
|
||||
return state
|
||||
var cached: Dictionary = _terrain_quality_mesh_cache[tile_key]
|
||||
var source := String(cached.get("source", "baked_full"))
|
||||
if source == "control_splat_cache" or source == "splat_cache" or source == "splat":
|
||||
_terrain_quality_mesh_cache.erase(tile_key)
|
||||
_terrain_quality_mesh_cache_order.erase(tile_key)
|
||||
return state
|
||||
var mesh: Mesh = cached.get("mesh", null)
|
||||
if mesh == null:
|
||||
_terrain_quality_mesh_cache.erase(tile_key)
|
||||
_terrain_quality_mesh_cache_order.erase(tile_key)
|
||||
return state
|
||||
state["quality_terrain_mesh"] = mesh
|
||||
state["quality_terrain_source"] = source
|
||||
_touch_quality_terrain_mesh_cache(tile_key)
|
||||
return state
|
||||
|
||||
|
||||
func _store_quality_terrain_mesh(tile_key: String, mesh: Mesh, source: String) -> void:
|
||||
if tile_key.is_empty() or mesh == null:
|
||||
return
|
||||
if source == "control_splat_cache" or source == "splat_cache" or source == "splat":
|
||||
return
|
||||
_terrain_quality_mesh_cache[tile_key] = {
|
||||
"mesh": mesh,
|
||||
"source": source,
|
||||
}
|
||||
_touch_quality_terrain_mesh_cache(tile_key)
|
||||
_trim_quality_terrain_mesh_cache()
|
||||
|
||||
|
||||
func _touch_quality_terrain_mesh_cache(tile_key: String) -> void:
|
||||
_terrain_quality_mesh_cache_order.erase(tile_key)
|
||||
_terrain_quality_mesh_cache_order.append(tile_key)
|
||||
|
||||
|
||||
func _trim_quality_terrain_mesh_cache() -> void:
|
||||
var limit := maxi(0, terrain_quality_mesh_cache_limit)
|
||||
while _terrain_quality_mesh_cache_order.size() > limit:
|
||||
var oldest: String = _terrain_quality_mesh_cache_order.pop_front()
|
||||
_terrain_quality_mesh_cache.erase(oldest)
|
||||
_terrain_quality_mesh_cache.call(
|
||||
"store",
|
||||
tile_key,
|
||||
mesh,
|
||||
source,
|
||||
terrain_quality_mesh_cache_limit
|
||||
)
|
||||
|
||||
|
||||
func _clear_quality_terrain_mesh_cache() -> void:
|
||||
_terrain_quality_mesh_cache.clear()
|
||||
_terrain_quality_mesh_cache_order.clear()
|
||||
_terrain_quality_mesh_cache.call("clear")
|
||||
|
||||
|
||||
func _position_camera_over_world() -> void:
|
||||
|
||||
Reference in New Issue
Block a user