perf(arena): cache the active camera lookup in ArenaBoundary

_process() called get_viewport().get_camera_3d() every frame to drive
the containment field's camera-side fade. Cache it the same way
ship_camera.gd caches the ball, revalidating with is_instance_valid
since exactly one camera rig is spawned per game-mode run today.
This commit is contained in:
Josh Creek
2026-08-04 17:36:37 +01:00
parent bb56f69edc
commit b01d5a68d9
2 changed files with 18 additions and 2 deletions
+18 -1
View File
@@ -98,6 +98,9 @@ const DECK_SHADER_PATH := "res://shaders/arena_deck.gdshader"
# _process() drives. Both stay null in headless runs, which never render.
var _shell: MeshInstance3D
var _field_material: ShaderMaterial
# Cached active camera for _process(), mirroring ship_camera.gd's _get_ball()
# pattern so the viewport lookup isn't repeated every frame.
var _camera: Camera3D
func _ready() -> void:
@@ -153,12 +156,26 @@ func _process(_delta: float) -> void:
# individually. Collision is untouched.
if _field_material == null:
return
var camera := get_viewport().get_camera_3d()
var camera := _get_camera()
if camera == null:
return # headless (RL/CI) has no camera
_field_material.set_shader_parameter("camera_local_pos", to_local(camera.global_position))
# Caches the viewport's active camera; a plain is_instance_valid revalidation
# is enough because exactly one ship_camera_rig (Camera3D) is spawned per
# game-mode run (GameMode.spawn_camera_rig, called once each from
# free_play.gd/match_mode.gd/spectate_mode.gd) and never re-spawned mid-match
# — there's no active-camera-switch scenario today. ArenaBoundary itself is
# destroyed/recreated per scene change, so the cache naturally resets with it;
# there's no stale-cache-across-scenes concern. Revisit this if split-screen
# or multiplayer camera-switching lands (see TODO.md's multiplayer section).
func _get_camera() -> Camera3D:
if not is_instance_valid(_camera):
_camera = get_viewport().get_camera_3d()
return _camera
# --- shared layout -----------------------------------------------------------
# Consumed by both the collider rings and the visual shell, so the two can
# never end up describing different geometry.