diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 55118e2..3dfa498 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -162,7 +162,9 @@ var _skybox_sky : Sky = null # the Sky object created in _setup_enviro var _skybox_frames : Array = [] # Array[ImageTexture] for animated skybox frames var _skybox_frame_idx : int = 0 var _skybox_timer : Timer = null -var _stars : Dictionary = {} # sessionId (String) → MeshInstance3D (live mode) +var _stars : Dictionary = {} # sessionId (String) → MeshInstance3D (live mode) +var _ambient_star_timer : Timer = null +var _ambient_star_ctr : int = 0 # counter for unique ambient IDs # ── Animation / facing state ─────────────────────────────────────────────────── var _local_is_p1 : bool = false # true when Auth.user_id == playerOneAccountId @@ -268,6 +270,9 @@ func _exit_tree() -> void: if Settings.settings_changed.is_connected(_on_skybox_setting_changed): Settings.settings_changed.disconnect(_on_skybox_setting_changed) # Unsubscribe from activity feed and free star nodes. + if _ambient_star_timer != null and is_instance_valid(_ambient_star_timer): + _ambient_star_timer.queue_free() + _ambient_star_timer = null if Settings.skybox_mode == "live": Network.request("game.unsubscribe_activity", {}, func(_t: String, _r: Variant) -> void: pass, @@ -371,11 +376,16 @@ func _setup_live_skybox(env: Environment) -> void: func(code: String, msg: String) -> void: push_warning("[GameScreen] subscribe_activity failed — %s: %s" % [code, msg])) + _start_ambient_star_cycle() + func _on_skybox_setting_changed() -> void: # Tear down current live subscriptions / stars before switching mode. if Game.game_activity.is_connected(_on_game_activity): Game.game_activity.disconnect(_on_game_activity) _clear_stars() + if _ambient_star_timer != null and is_instance_valid(_ambient_star_timer): + _ambient_star_timer.queue_free() + _ambient_star_timer = null if _skybox_timer != null: _skybox_timer.queue_free() _skybox_timer = null @@ -396,6 +406,27 @@ func _on_game_activity(event_type: String, session_id: String) -> void: "started": _add_star(session_id, false) "ended": _remove_star(session_id) +## Schedules the next ambient star spawn (1-2 per 5 s on average). +func _start_ambient_star_cycle() -> void: + if _ambient_star_timer != null and is_instance_valid(_ambient_star_timer): + _ambient_star_timer.queue_free() + _ambient_star_timer = Timer.new() + _ambient_star_timer.wait_time = randf_range(2.5, 5.0) + _ambient_star_timer.one_shot = true + add_child(_ambient_star_timer) + _ambient_star_timer.timeout.connect(_on_ambient_star_timer) + _ambient_star_timer.start() + +## Spawns one ambient star, schedules its removal, then re-arms the cycle. +func _on_ambient_star_timer() -> void: + var fake_id := "~ambient~%d" % _ambient_star_ctr + _ambient_star_ctr += 1 + _add_star(fake_id, false) + # Each ambient star lives for 15–30 s before it fades out. + get_tree().create_timer(randf_range(15.0, 30.0)).timeout.connect( + func() -> void: _remove_star(fake_id)) + _start_ambient_star_cycle() + # ── Live-star skybox helpers ─────────────────────────────────────────────────── ## Returns a deterministic spherical position from a session ID hash.