perf(ship): gate telemetry emission on listeners and headless mode

Ship._emit_telemetry_data() ran get_euler()+trig every physics tick
for every ship regardless of whether a HUD was watching, wasting work
on AI ships and every headless training instance. Disable
_physics_process outright when headless, and skip emission the rest
of the time unless a signal actually has a listener.
This commit is contained in:
Josh Creek
2026-08-04 15:15:43 +01:00
parent 08a0f74391
commit fbb783b947
2 changed files with 19 additions and 11 deletions
+18 -1
View File
@@ -83,6 +83,12 @@ func _ready():
_boundary = get_tree().get_first_node_in_group("arena_boundary")
# Telemetry emission is HUD-only work; headless (RL/CI) instances never
# have one, so skip the per-tick cost entirely rather than relying on
# the listener check below to no-op every frame.
if DisplayServer.get_name() == "headless":
set_physics_process(false)
func _apply_team_color() -> void:
if not is_inside_tree():
@@ -112,7 +118,18 @@ func set_controller(new_controller: ShipController) -> void:
func _physics_process(_delta):
_emit_telemetry_data()
if _has_telemetry_listeners():
_emit_telemetry_data()
# Covers a second/AI ship with no HUD watching it - headless mode is already
# handled by disabling _physics_process entirely in _ready.
func _has_telemetry_listeners() -> bool:
return speed_changed.get_connections().size() > 0 \
or altitude_changed.get_connections().size() > 0 \
or attitude_changed.get_connections().size() > 0 \
or heading_changed.get_connections().size() > 0 \
or thrust_changed.get_connections().size() > 0
func _integrate_forces(state):