extends Node # Autoload: drops Engine.max_fps while the window is unfocused, so an idle # background window doesn't keep rendering at whatever uncapped rate the # hardware can hit. Independent of — and complementary to — the per-menu # refresh-rate cap in main_menu.gd/settings_menu.gd, which only covers menu # screens; this covers every scene, including gameplay. const BACKGROUND_FPS := 30 # 0 means "uncapped"; also what we restore to if focus is lost before any # menu/gameplay scene has had a chance to set its own cap. var _foreground_max_fps := 0 func _notification(what: int) -> void: match what: NOTIFICATION_APPLICATION_FOCUS_OUT: _foreground_max_fps = Engine.max_fps Engine.max_fps = BACKGROUND_FPS NOTIFICATION_APPLICATION_FOCUS_IN: Engine.max_fps = _foreground_max_fps