feat(M03): add entity presentation facade
This commit is contained in:
@@ -9,6 +9,8 @@ const GODOT_WORLD_POSITION_SCRIPT := preload("res://src/domain/coordinates/godot
|
||||
const STREAMING_FOCUS_SCRIPT := preload("res://src/domain/streaming/streaming_focus.gd")
|
||||
const RENDERED_GROUND_SAMPLE_SCRIPT := preload("res://src/render/terrain/rendered_ground_sample.gd")
|
||||
const WORLD_ENVIRONMENT_SNAPSHOT_SCRIPT := preload("res://src/render/environment/world_environment_snapshot.gd")
|
||||
const ENTITY_PRESENTATION_SNAPSHOT_SCRIPT := preload("res://src/render/entities/entity_presentation_snapshot.gd")
|
||||
const ENTITY_ID_SCRIPT := preload("res://src/domain/identity/entity_id.gd")
|
||||
|
||||
## Internal renderer implementation resolved relative to this node.
|
||||
## The referenced node remains owned by its scene parent.
|
||||
@@ -18,14 +20,19 @@ const WORLD_ENVIRONMENT_SNAPSHOT_SCRIPT := preload("res://src/render/environment
|
||||
## The facade delegates snapshots but owns neither the controller nor Environment.
|
||||
@export var world_environment_controller_path: NodePath = NodePath("../WowSkyController")
|
||||
|
||||
## Scene-owned service that creates and owns session-local world entity visuals.
|
||||
@export var world_entity_presenter_path: NodePath = NodePath("../WorldEntityPresenter")
|
||||
|
||||
## Optional explicit Node3D source sampled in Godot world coordinates.
|
||||
## Runtime scenes use the player; capture and probe tools replace it with their camera.
|
||||
@export var streaming_focus_source_path: NodePath
|
||||
|
||||
var _streaming_world_loader: Node
|
||||
var _world_environment_controller: Node
|
||||
var _world_entity_presenter: Node
|
||||
var _missing_loader_reported := false
|
||||
var _missing_environment_controller_reported := false
|
||||
var _missing_entity_presenter_reported := false
|
||||
var _missing_focus_source_reported := false
|
||||
|
||||
|
||||
@@ -116,6 +123,43 @@ func apply_environment_snapshot(world_environment_snapshot: RefCounted) -> bool:
|
||||
return bool(controller.call("apply_environment_snapshot", world_environment_snapshot))
|
||||
|
||||
|
||||
## Idempotently creates or updates one world entity visual through the renderer-
|
||||
## owned presenter. The immutable full snapshot remains caller-owned.
|
||||
func present_entity(entity_presentation_snapshot: RefCounted) -> bool:
|
||||
if (
|
||||
entity_presentation_snapshot == null
|
||||
or entity_presentation_snapshot.get_script() != ENTITY_PRESENTATION_SNAPSHOT_SCRIPT
|
||||
or not bool(entity_presentation_snapshot.get("is_valid"))
|
||||
):
|
||||
return false
|
||||
var presenter := _resolve_world_entity_presenter()
|
||||
if presenter == null:
|
||||
return false
|
||||
return bool(presenter.call("present_entity", entity_presentation_snapshot))
|
||||
|
||||
|
||||
## Removes one session-local entity visual without changing authoritative state.
|
||||
func remove_entity(entity_id: RefCounted) -> bool:
|
||||
if entity_id == null or entity_id.get_script() != ENTITY_ID_SCRIPT or not bool(entity_id.call("is_valid")):
|
||||
return false
|
||||
var presenter := _resolve_world_entity_presenter()
|
||||
if presenter == null:
|
||||
return false
|
||||
return bool(presenter.call("remove_entity", entity_id))
|
||||
|
||||
|
||||
## Returns detached entity-presentation diagnostics with no Node references.
|
||||
func entity_presentation_snapshot() -> Dictionary:
|
||||
var presenter := _resolve_world_entity_presenter()
|
||||
if presenter == null:
|
||||
return {}
|
||||
var snapshot_variant = presenter.call("entity_presentation_snapshot")
|
||||
if not (snapshot_variant is Dictionary):
|
||||
push_error("WorldRenderFacade received a non-Dictionary entity presentation snapshot.")
|
||||
return {}
|
||||
return (snapshot_variant as Dictionary).duplicate(true)
|
||||
|
||||
|
||||
func _capture_streaming_focus_from_source() -> void:
|
||||
if streaming_focus_source_path == NodePath():
|
||||
return
|
||||
@@ -177,3 +221,23 @@ func _resolve_world_environment_controller() -> Node:
|
||||
_world_environment_controller = candidate
|
||||
_missing_environment_controller_reported = false
|
||||
return _world_environment_controller
|
||||
|
||||
|
||||
func _resolve_world_entity_presenter() -> Node:
|
||||
if is_instance_valid(_world_entity_presenter):
|
||||
return _world_entity_presenter
|
||||
var candidate := get_node_or_null(world_entity_presenter_path)
|
||||
if candidate == null:
|
||||
if not _missing_entity_presenter_reported:
|
||||
push_error("WorldRenderFacade cannot resolve entity presenter at %s" % world_entity_presenter_path)
|
||||
_missing_entity_presenter_reported = true
|
||||
return null
|
||||
for required_method in [&"present_entity", &"remove_entity", &"entity_presentation_snapshot"]:
|
||||
if not candidate.has_method(required_method):
|
||||
if not _missing_entity_presenter_reported:
|
||||
push_error("WorldRenderFacade entity presenter lacks %s" % required_method)
|
||||
_missing_entity_presenter_reported = true
|
||||
return null
|
||||
_world_entity_presenter = candidate
|
||||
_missing_entity_presenter_reported = false
|
||||
return _world_entity_presenter
|
||||
|
||||
Reference in New Issue
Block a user