class_name PerformanceComponent extends VisibleOnScreenNotifier3D @export var animation: AnimationComponent var camera_distance_squared: float var on_screen: bool var delay_visible: float func _ready(): assert(animation) screen_entered.connect(on_screen_entered) screen_exited.connect(on_screen_exited) func on_screen_entered(): on_screen = true animation.delay = delay_visible func on_screen_exited(): on_screen = false animation.delay = AnimationPerformance.DELAY_INVISIBLE static func get_visible_players_sorted_by_distance() -> Array[Player]: var visible_players: Array[Player] = [] for player in Global.players.id_to_player.values(): player.performance.camera_distance_squared = player.global_position.distance_squared_to(Global.camera.global_position) if player.performance.on_screen: visible_players.append(player) else: player.performance.animation.delay = AnimationPerformance.DELAY_INVISIBLE if Global.player: Global.player.performance.camera_distance_squared = 0 visible_players.sort_custom(PerformanceComponent.distance_sort) return visible_players static func distance_sort(a: Player, b: Player) -> bool: return a.performance.camera_distance_squared < b.performance.camera_distance_squared