Skip to main content

euv_example/state/
impl.rs

1use super::*;
2
3/// Lazy constructor for `ReactiveSignals`.
4impl ReactiveSignals {
5    /// Materializes the `/reactive` counter and derived `computed!` memo on first access.
6    ///
7    /// # Returns
8    ///
9    /// - `Self` - Initialized `/reactive` signal group.
10    #[must_use]
11    pub(crate) fn create() -> Self {
12        let counter: Signal<i32> = Signal::new(1);
13        let doubled: Memo<i32> = computed!((counter) -> i32 => move |n: i32| n * 2);
14        Self { counter, doubled }
15    }
16}
17
18/// Lazy constructor for `RenderWindowSignals`.
19impl RenderWindowSignals {
20    /// Materializes the `/render` and `/window` OS capability signals on first access.
21    ///
22    /// # Arguments
23    ///
24    /// - `usize` - Default host platform selector index.
25    ///
26    /// # Returns
27    ///
28    /// - `Self` - Initialized `/render` and `/window` signal group.
29    #[must_use]
30    pub(crate) fn create(default_plat_idx: usize) -> Self {
31        Self {
32            render_mode_index: Signal::new(0),
33            demo_fps_cap_index: Signal::new(0),
34            fullscreen: Signal::new(false),
35            island_active: Signal::new(false),
36            island_progress: Signal::new(25),
37            camera_perm_status: Signal::new(DEFAULT_CAMERA_PERM.to_string()),
38            protocol_status: Signal::new(DEFAULT_PROTOCOL_STATUS.to_string()),
39            a11y_announcements: Signal::new(0),
40            haptic_pulses: Signal::new(0),
41            os_target_platform_idx: Signal::new(default_plat_idx),
42            island_mode_idx: Signal::new(0),
43            system_notifications: Signal::new(vec![(
44                DEFAULT_SYS_NOTIF_TITLE.to_string(),
45                DEFAULT_SYS_NOTIF_BODY.to_string(),
46            )]),
47            permission_statuses: Signal::new(vec![PermissionStatus::NotDetermined; 14]),
48        }
49    }
50}
51
52/// Lazy constructor for `FormsSignals`.
53impl FormsSignals {
54    /// Materializes the `/forms` interactive control signals on first access.
55    ///
56    /// # Returns
57    ///
58    /// - `Self` - Initialized `/forms` signal group.
59    #[must_use]
60    pub(crate) fn create() -> Self {
61        Self {
62            username: Signal::new(DEFAULT_USERNAME.to_string()),
63            bio: Signal::new(DEFAULT_BIO_TEXT.to_string()),
64            stepper_value: Signal::new(4),
65            radio_index: Signal::new(1),
66            slider_value: Signal::new(65.0),
67            select_index: Signal::new(0),
68            select_open: Signal::new(false),
69            rating_value: Signal::new(4),
70            pin_toggled: Signal::new(false),
71            hardware_accel: Signal::new(true),
72            agree_terms: Signal::new(true),
73            active_tab: Signal::new(0),
74            page_index: Signal::new(1),
75            step_index: Signal::new(1),
76            accordion_open: Signal::new(Some(0)),
77            picker_color: Signal::new(Color::hex(0x2563EB)),
78            picker_time: Signal::new((14, 30)),
79            tag_items: Signal::new(vec![
80                DEFAULT_TAG_RUST.to_string(),
81                DEFAULT_TAG_NATIVE.to_string(),
82                DEFAULT_TAG_WASM.to_string(),
83            ]),
84            tree_selected: Signal::new(None),
85            breadcrumb_active: Signal::new(2),
86        }
87    }
88}
89
90/// Lazy constructor for `OverlaysSignals`.
91impl OverlaysSignals {
92    /// Materializes the `/overlays` modal, drawer, sheet, and toast signals on first access.
93    ///
94    /// # Returns
95    ///
96    /// - `Self` - Initialized `/overlays` signal group.
97    #[must_use]
98    pub(crate) fn create() -> Self {
99        Self {
100            modal_open: Signal::new(false),
101            drawer_open: Signal::new(false),
102            sheet_open: Signal::new(false),
103            popover_open: Signal::new(false),
104            dropdown_open: Signal::new(false),
105            dropdown_selected: Signal::new(None),
106            toast_visible: Signal::new(false),
107            notif_visible: Signal::new(false),
108            loading_active: Signal::new(false),
109        }
110    }
111}
112
113/// Lazy constructor for `DataSignals`.
114impl DataSignals {
115    /// Materializes the `/data` virtualized list scroll signal on first access.
116    ///
117    /// # Returns
118    ///
119    /// - `Self` - Initialized `/data` signal group.
120    #[must_use]
121    pub(crate) fn create() -> Self {
122        Self {
123            list_scroll_y: Signal::new(640.0),
124        }
125    }
126}
127
128/// Lazy constructor and shared-cell accessor for `Engine3dSignals`.
129impl Engine3dSignals {
130    /// Materializes the `/game3d` quality, ray-tracing, lighting, and camera control signals on first access.
131    ///
132    /// # Returns
133    ///
134    /// - `Self` - Initialized `/game3d` signal group.
135    #[must_use]
136    pub(crate) fn create() -> Self {
137        Self {
138            engine3d_quality: Signal::new(RenderQualityConfig::from_preset(
139                QualityPreset::Cinematic,
140            )),
141            engine3d_preset_idx: Signal::new(4),
142            engine3d_rt_idx: Signal::new(3),
143            engine3d_res_scale: Signal::new(100.0),
144            engine3d_time_of_day: Signal::new(17.2),
145            engine3d_import_queue: Signal::new(0),
146            engine3d_import_status: Signal::new(DEFAULT_ENGINE3D_STATUS.to_string()),
147            engine3d_camera_mode: Signal::new(0),
148        }
149    }
150
151    /// Returns the cached `Engine3dSignals` inside `cell`, materializing it once inside `owner_scope` on first call.
152    ///
153    /// # Arguments
154    ///
155    /// - `&Cell<Option<Self>>` - Shared lazy signal cell.
156    /// - `Scope` - Root ownership scope keeping materialized signals alive across page unmounts.
157    ///
158    /// # Returns
159    ///
160    /// - `Self` - Active `/game3d` signal group.
161    #[must_use]
162    pub(crate) fn get_or_init(cell: &Cell<Option<Self>>, owner_scope: Scope) -> Self {
163        if let Some(existing) = cell.get() {
164            return existing;
165        }
166        let created: Self = owner_scope.enter(Self::create);
167        cell.set(Some(created));
168        created
169    }
170}
171
172/// Lazy constructor and shared-cell accessor for `DynamicSignals`.
173impl DynamicSignals {
174    /// Materializes the `/dynamic` OTA and WASM control signals on first access.
175    ///
176    /// # Returns
177    ///
178    /// - `Self` - Initialized `/dynamic` signal group.
179    #[must_use]
180    pub(crate) fn create() -> Self {
181        Self {
182            sibling_counter: Signal::new(0),
183            dynamic_action_log: Signal::new(DEFAULT_DYNAMIC_ACTION_LOG.to_string()),
184            wasm_offline: Signal::new(false),
185            wasm_fault_status: Signal::new(DEFAULT_WASM_STATUS.to_string()),
186            wasm_bg_task: Signal::new(None),
187        }
188    }
189
190    /// Returns the cached `DynamicSignals` inside `cell`, materializing it once inside `owner_scope` on first call.
191    ///
192    /// # Arguments
193    ///
194    /// - `&Cell<Option<Self>>` - Shared lazy signal cell.
195    /// - `Scope` - Root ownership scope keeping materialized signals alive across global WASM slot swaps.
196    ///
197    /// # Returns
198    ///
199    /// - `Self` - Active `/dynamic` signal group.
200    #[must_use]
201    pub(crate) fn get_or_init(cell: &Cell<Option<Self>>, owner_scope: Scope) -> Self {
202        if let Some(existing) = cell.get() {
203            return existing;
204        }
205        let created: Self = owner_scope.enter(Self::create);
206        cell.set(Some(created));
207        created
208    }
209}
210
211/// Lazy constructor for `LabSignals`.
212impl LabSignals {
213    /// Materializes the `/lab` shadcn/ui component gallery and edge-case signals on first access.
214    ///
215    /// # Returns
216    ///
217    /// - `Self` - Initialized `/lab` signal group.
218    #[must_use]
219    pub(crate) fn create() -> Self {
220        Self {
221            alert_dialog_open: Signal::new(false),
222            alert_dialog_confirmed: Signal::new(false),
223            collapsible_open: Signal::new(true),
224            toggle_group_index: Signal::new(0),
225            otp_code: Signal::new(DEFAULT_OTP_CODE.to_string()),
226            command_query: Signal::new(String::new()),
227            command_selected: Signal::new(Some(0)),
228            hover_card_open: Signal::new(false),
229            calendar_day: Signal::new(25),
230            menubar_active: Signal::new(None),
231            carousel_index: Signal::new(0),
232            lab_combobox_query: Signal::new(String::new()),
233            lab_combobox_selected: Signal::new(0),
234            lab_combobox_open: Signal::new(false),
235            lab_table_filter: Signal::new(String::new()),
236            lab_table_sort_asc: Signal::new(true),
237            lab_table_selected: Signal::new(Some(0)),
238            lab_date_day: Signal::new(26),
239            lab_date_open: Signal::new(false),
240            lab_input_group_val: Signal::new(DEFAULT_INPUT_GROUP_VAL.to_string()),
241            lab_native_select_idx: Signal::new(0),
242            lab_nav_menu_active: Signal::new(None),
243            lab_split_ratio: Signal::new(0.45),
244            lab_block_scroll_chain: Signal::new(false),
245            lab_stop_click_bubble: Signal::new(true),
246            lab_parent_clicks: Signal::new(0),
247            lab_child_clicks: Signal::new(0),
248            lab_resize_preserve_count: Signal::new(1),
249            lab_rtl_mode: Signal::new(false),
250        }
251    }
252}
253
254/// Lazy constructor for `MediaSignals`.
255impl MediaSignals {
256    /// Materializes the `/media` Media Studio playback signals on first access.
257    ///
258    /// # Returns
259    ///
260    /// - `Self` - Initialized `/media` signal group.
261    #[must_use]
262    pub(crate) fn create() -> Self {
263        Self {
264            media_gif: Signal::new(GifAnimation::default()),
265            media_live: Signal::new(LivePhotoAsset::default()),
266            media_video: Signal::new(VideoTrack::default()),
267            media_audio: Signal::new(AudioTrack::default()),
268            media_pdf: Signal::new(PdfDocument::default()),
269            media_html_link_log: Signal::new(DEFAULT_MEDIA_LINK_LOG.to_string()),
270            media_loading: Signal::new(false),
271            media_bg_task: Signal::new(None),
272        }
273    }
274}
275
276/// Lazy constructor for `MarkdownSignals`.
277impl MarkdownSignals {
278    /// Materializes the `/markdown` Markdown & Code Studio signals on first access.
279    ///
280    /// # Returns
281    ///
282    /// - `Self` - Initialized `/markdown` signal group.
283    #[must_use]
284    pub(crate) fn create() -> Self {
285        Self {
286            markdown_copy_log: Signal::new(DEFAULT_MD_COPY_LOG.to_string()),
287            markdown_link_log: Signal::new(DEFAULT_MD_LINK_LOG.to_string()),
288            markdown_tasks_toggled: Signal::new(0),
289            markdown_lang_tab: Signal::new(0),
290            markdown_selectable: Signal::new(true),
291        }
292    }
293}
294
295/// Lazy constructor for `StressSignals`.
296impl StressSignals {
297    /// Materializes the `/stress` interactive UI stress benchmark signals on first access.
298    ///
299    /// # Returns
300    ///
301    /// - `Self` - Initialized `/stress` signal group.
302    #[must_use]
303    pub(crate) fn create() -> Self {
304        Self {
305            stress_results: Signal::new(Vec::new()),
306            stress_summary: Signal::new(STRESS_SUMMARY_READY.to_string()),
307        }
308    }
309}
310
311/// Lazy constructor for `ChartsSignals`.
312impl ChartsSignals {
313    /// Materializes the `/charts` ECharts Studio filter and readout signals on first access.
314    ///
315    /// # Returns
316    ///
317    /// - `Self` - Initialized `/charts` signal group.
318    #[must_use]
319    pub(crate) fn create() -> Self {
320        Self {
321            charts_category_idx: Signal::new(0),
322            charts_event_log: Signal::new(CHARTS_EVENT_READY.to_string()),
323        }
324    }
325}
326
327/// Lazy constructor for `WaterSignals`.
328impl WaterSignals {
329    /// Materializes the `/water` liquid physics control and telemetry signals on first access.
330    ///
331    /// # Returns
332    ///
333    /// - `Self` - Initialized `/water` signal group.
334    #[must_use]
335    pub(crate) fn create() -> Self {
336        Self {
337            fill_pct: Signal::new(FLUID_DEFAULT_FILL_RATIO * 100.0),
338            viscosity_idx: Signal::new(0),
339            buoyant_enabled: Signal::new(true),
340            fullscreen_open: Signal::new(false),
341            sensor_perm_status: Signal::new(WATER_PERM_DESKTOP_STATUS.to_string()),
342            stats: Signal::new(GyroLiquidStats::default()),
343        }
344    }
345}
346
347/// Lazy scene creation and zero-boot-cost handle accessors for `LazyWaterScene`.
348impl LazyWaterScene {
349    /// Creates a zero-allocation lazy placeholder bound to shared `scene_cell` and `signals_cell`.
350    ///
351    /// # Arguments
352    ///
353    /// - `Rc<RefCell<Option<GyroLiquidGameScene>>>` - Shared cell lazily storing the active liquid scene.
354    /// - `Rc<Cell<Option<WaterSignals>>>` - Shared cell storing `/water` reactive signals.
355    ///
356    /// # Returns
357    ///
358    /// - `Self` - Uninitialized lazy liquid scene wrapper.
359    #[must_use]
360    pub(crate) fn create_deferred(
361        scene_cell: Rc<RefCell<Option<GyroLiquidGameScene>>>,
362        signals_cell: Rc<Cell<Option<WaterSignals>>>,
363    ) -> Self {
364        Self {
365            scene_cell,
366            signals_cell,
367        }
368    }
369
370    /// Returns the active `GyroLiquidGameScene`, initializing it lazily on first access.
371    ///
372    /// # Arguments
373    ///
374    /// - `&Self` - Lazy water scene reference.
375    ///
376    /// # Returns
377    ///
378    /// - `GyroLiquidGameScene` - Active shareable liquid physics scene handle.
379    #[must_use]
380    pub(crate) fn ensure_scene(&self) -> GyroLiquidGameScene {
381        if let Some(existing) = self.get_scene_cell().borrow().as_ref() {
382            return existing.clone();
383        }
384        let created: GyroLiquidGameScene = GyroLiquidGameScene::default();
385        *self.get_scene_cell().borrow_mut() = Some(created.clone());
386        created
387    }
388}
389
390/// `GameScene` delegation forwarding fixed physics steps and zero-copy optical rendering to the lazily initialized `GyroLiquidGameScene`.
391impl GameScene for LazyWaterScene {
392    /// Steps the SI PBF liquid simulation and mirrors live `GyroLiquidStats` into `/water` signals.
393    ///
394    /// # Arguments
395    ///
396    /// - `&Self` - Mutable lazy water scene wrapper.
397    /// - `f32` - Fixed simulation timestep in seconds.
398    /// - `&InputState` - Real-time polled pointer and keyboard input state.
399    fn fixed_update(&mut self, dt: f32, input: &InputState) {
400        let mut scene: GyroLiquidGameScene = self.ensure_scene();
401        scene.fixed_update(dt, input);
402        if let Some(sig) = self.get_signals_cell().get() {
403            let _: bool = sig.get_stats().set_if_changed(scene.stats());
404        }
405    }
406
407    /// Renders the optical liquid frame into `ctx` and mirrors updated frame timings into `/water` signals.
408    ///
409    /// # Arguments
410    ///
411    /// - `&Self` - Mutable lazy water scene wrapper.
412    /// - `f32` - Interpolation alpha in `[0.0, 1.0]`.
413    /// - `&mut GameRenderContext<'_>` - Active viewport draw surface.
414    fn render(&mut self, alpha: f32, ctx: &mut GameRenderContext<'_>) {
415        let mut scene: GyroLiquidGameScene = self.ensure_scene();
416        scene.render(alpha, ctx);
417        if let Some(sig) = self.get_signals_cell().get() {
418            let _: bool = sig.get_stats().set_if_changed(scene.stats());
419        }
420    }
421}
422
423/// Construction, lazy signal accessors, async preloaders, and lifecycle helpers for `ShowcaseState`.
424impl ShowcaseState {
425    /// Initializes a minimal-boot `ShowcaseState` using a fresh `DynamicUpdateHub` and synchronous lazy route hydration.
426    ///
427    /// # Returns
428    ///
429    /// - `Self` - Initialized reactive showcase state.
430    #[must_use]
431    pub fn new() -> Self {
432        Self::new_with_hub(DynamicUpdateHub::new(), false)
433    }
434
435    /// Initializes a minimal-boot `ShowcaseState` bound directly to `hub` without allocating discarded hubs or managers.
436    ///
437    /// # Arguments
438    ///
439    /// - `DynamicUpdateHub` - Active `App` dynamic update hub to attach directly.
440    /// - `bool` - When `true`, offloads heavy `/media`, `/dynamic`, and `/game3d` route payloads onto background worker threads on native targets.
441    ///
442    /// # Returns
443    ///
444    /// - `Self` - Initialized reactive showcase state with only core shell signals allocated at boot.
445    #[must_use]
446    pub fn new_with_hub(hub: DynamicUpdateHub, bg_workers: bool) -> Self {
447        let (state_scope, _): (Scope, ()) = Scope::run(|_: Scope| {});
448        let arena: DemoPhysicsScene = DemoPhysicsScene::create_lazy_arena();
449        let game_host: GameEngineHost = GameEngineHost::new(arena, 1.0 / 60.0);
450        game_host.set_paused(true);
451        let engine3d_signals: Rc<Cell<Option<Engine3dSignals>>> = Rc::new(Cell::new(None));
452        let bg_workers_enabled: Rc<Cell<bool>> = Rc::new(Cell::new(bg_workers));
453        let scene3d: DemoOpenWorld3DScene = DemoOpenWorld3DScene::create_lazy_city_deferred(
454            engine3d_signals.clone(),
455            state_scope,
456            bg_workers_enabled.clone(),
457        );
458        let game3d_host: GameEngineHost = GameEngineHost::new(scene3d, 1.0 / 60.0);
459        game3d_host.set_paused(true);
460        let water_scene_cell: Rc<RefCell<Option<GyroLiquidGameScene>>> =
461            Rc::new(RefCell::new(None));
462        let water_signals: Rc<Cell<Option<WaterSignals>>> = Rc::new(Cell::new(None));
463        let lazy_water: LazyWaterScene =
464            LazyWaterScene::create_deferred(water_scene_cell.clone(), water_signals.clone());
465        let water_host: GameEngineHost = GameEngineHost::new(lazy_water, 1.0 / 60.0);
466        water_host.set_paused(true);
467        let router: EuvRouter = EuvRouter::new(ROUTE_OVERVIEW)
468            .with_default_retention(PageRetention::Freeze)
469            .with_dynamic_hub(hub.clone());
470        let wasm_registry: RegistryWasmFetcher = RegistryWasmFetcher::default();
471        let wasm_manager: WasmDynamicManager = WasmDynamicManager::new(
472            hub.clone(),
473            Rc::new(wasm_registry.clone()),
474            WasmSandboxConfig::default(),
475        );
476        let (
477            default_active_backend,
478            default_rec_backend,
479            default_cpu_mirror,
480            default_timing,
481            default_upload,
482        ): (&str, &str, bool, &str, &str) =
483            Self::default_adaptive_render_profile(current_platform());
484        let state: Self = Self {
485            route: Signal::new(ROUTE_OVERVIEW.to_string()),
486            state_scope,
487            theme: UiThemeState::new(active_feature_scheme(), ThemeMode::Light),
488            game_host,
489            game3d_host,
490            water_host,
491            water_scene_cell,
492            dynamic_hub: hub,
493            wasm_registry,
494            wasm_manager,
495            cmd_palette_open: Signal::new(false),
496            cmd_palette_query: Signal::new(String::new()),
497            auto_hide_chrome: Signal::new(true),
498            show_fps_hud: Signal::new(true),
499            swipe_routing: Signal::new(true),
500            reduced_motion: Signal::new(false),
501            adaptive_auto_switch: Signal::new(false),
502            adaptive_active_backend: Signal::new(default_active_backend.to_string()),
503            adaptive_recommended_backend: Signal::new(default_rec_backend.to_string()),
504            adaptive_cpu_mirror_active: Signal::new(default_cpu_mirror),
505            adaptive_present_timing_source: Signal::new(default_timing.to_string()),
506            adaptive_upload_strategy: Signal::new(default_upload.to_string()),
507            adaptive_handoff_attempts: Signal::new(0),
508            adaptive_handoff_successes: Signal::new(0),
509            adaptive_handoff_aborts: Signal::new(0),
510            router,
511            router_ready: Rc::new(Cell::new(false)),
512            lifecycle_mounts: Signal::new(0),
513            lifecycle_freezes: Signal::new(0),
514            lifecycle_resumes: Signal::new(0),
515            lifecycle_destroys: Signal::new(0),
516            lifecycle_last_event: Signal::new(DEFAULT_LIFECYCLE_BOOT.to_string()),
517            system_event_log: Signal::new(vec![DEFAULT_SYS_EVENT_LOG.to_string()]),
518            system_event_count: Signal::new(0),
519            bg_frozen: Signal::new(false),
520            bg_freeze_count: Signal::new(0),
521            bg_restore_count: Signal::new(0),
522            bg_snap_game2d_running: Rc::new(Cell::new(false)),
523            bg_snap_game3d_running: Rc::new(Cell::new(false)),
524            bg_snap_water_running: Rc::new(Cell::new(false)),
525            bg_snap_gif_playing: Rc::new(Cell::new(false)),
526            bg_snap_live_playing: Rc::new(Cell::new(false)),
527            bg_snap_video_playing: Rc::new(Cell::new(false)),
528            bg_snap_audio_playing: Rc::new(Cell::new(false)),
529            media_loaded: Rc::new(Cell::new(false)),
530            wasm_registry_loaded: Rc::new(Cell::new(false)),
531            stress_loaded: Rc::new(Cell::new(false)),
532            charts_loaded: Rc::new(Cell::new(false)),
533            bg_workers_enabled,
534            default_host_plat_idx: Rc::new(Cell::new(0)),
535            reactive_signals: Rc::new(Cell::new(None)),
536            render_window_signals: Rc::new(Cell::new(None)),
537            forms_signals: Rc::new(Cell::new(None)),
538            overlays_signals: Rc::new(Cell::new(None)),
539            data_signals: Rc::new(Cell::new(None)),
540            engine3d_signals,
541            dynamic_signals: Rc::new(Cell::new(None)),
542            lab_signals: Rc::new(Cell::new(None)),
543            media_signals: Rc::new(Cell::new(None)),
544            markdown_signals: Rc::new(Cell::new(None)),
545            stress_signals: Rc::new(Cell::new(None)),
546            charts_signals: Rc::new(Cell::new(None)),
547            water_signals,
548        };
549        state.wire_dynamic_hub_actions();
550        state
551    }
552
553    /// Records the host platform index without eagerly materializing `/window` signals at boot.
554    ///
555    /// # Arguments
556    ///
557    /// - `&Self` - Reactive showcase state reference.
558    /// - `usize` - Host platform index (`0..7`).
559    pub fn set_default_host_platform_idx(&self, idx: usize) {
560        self.get_default_host_plat_idx().set(idx);
561        if let Some(rw) = self.get_render_window_signals().get() {
562            let _: bool = rw.get_os_target_platform_idx().set_if_changed(idx);
563        }
564    }
565
566    /// Enables or disables off-main-thread background worker loading for heavy showcase routes.
567    ///
568    /// # Arguments
569    ///
570    /// - `&Self` - Reactive showcase state reference.
571    /// - `bool` - `true` to enable background worker threads on native targets.
572    pub fn set_bg_workers_enabled(&self, enabled: bool) {
573        self.get_bg_workers_enabled().set(enabled);
574    }
575
576    /// Resolves honest baseline adaptive render diagnostics for `platform` without faking unverified GPU direct present or hardware compositor timing.
577    ///
578    /// # Arguments
579    ///
580    /// - `PlatformKind` - Active host platform classification.
581    ///
582    /// # Returns
583    ///
584    /// - `(&'static str, &'static str, bool, &'static str, &'static str)` - `(active_backend, recommended_backend, cpu_mirror_active, timing_source, upload_strategy)`.
585    #[must_use]
586    fn default_adaptive_render_profile(
587        platform: PlatformKind,
588    ) -> (&'static str, &'static str, bool, &'static str, &'static str) {
589        let cfg: RenderConfig = RenderConfig::default();
590        let direct_gpu: bool = cfg.get_direct_gpu_present();
591        match platform {
592            PlatformKind::MacOs | PlatformKind::Ios | PlatformKind::IpadOs => {
593                if direct_gpu {
594                    (
595                        ADAPTIVE_BACKEND_METAL_DIRECT,
596                        ADAPTIVE_BACKEND_METAL_DIRECT,
597                        false,
598                        ADAPTIVE_TIMING_COMPOSITOR,
599                        ADAPTIVE_UPLOAD_DIRECT_GPU,
600                    )
601                } else {
602                    (
603                        ADAPTIVE_BACKEND_SOFTWARE_CPU,
604                        ADAPTIVE_BACKEND_METAL_DIRECT,
605                        true,
606                        ADAPTIVE_TIMING_PROXY,
607                        ADAPTIVE_UPLOAD_MULTI_RECT,
608                    )
609                }
610            }
611            PlatformKind::Android | PlatformKind::HarmonyOs => {
612                if direct_gpu {
613                    (
614                        ADAPTIVE_BACKEND_GLES3_DIRECT,
615                        ADAPTIVE_BACKEND_GLES3_DIRECT,
616                        false,
617                        ADAPTIVE_TIMING_COMPOSITOR,
618                        ADAPTIVE_UPLOAD_DIRECT_GPU,
619                    )
620                } else {
621                    (
622                        ADAPTIVE_BACKEND_SOFTWARE_CPU,
623                        ADAPTIVE_BACKEND_GLES3_DIRECT,
624                        true,
625                        ADAPTIVE_TIMING_PROXY,
626                        ADAPTIVE_UPLOAD_MULTI_RECT,
627                    )
628                }
629            }
630            PlatformKind::Windows => {
631                if direct_gpu {
632                    (
633                        ADAPTIVE_BACKEND_D3D11_DIRECT,
634                        ADAPTIVE_BACKEND_D3D11_DIRECT,
635                        false,
636                        ADAPTIVE_TIMING_COMPOSITOR,
637                        ADAPTIVE_UPLOAD_DIRECT_GPU,
638                    )
639                } else {
640                    (
641                        ADAPTIVE_BACKEND_SOFTWARE_CPU,
642                        ADAPTIVE_BACKEND_D3D11_DIRECT,
643                        true,
644                        ADAPTIVE_TIMING_PROXY,
645                        ADAPTIVE_UPLOAD_MULTI_RECT,
646                    )
647                }
648            }
649            PlatformKind::Linux => {
650                if direct_gpu {
651                    (
652                        ADAPTIVE_BACKEND_VULKAN_DIRECT,
653                        ADAPTIVE_BACKEND_VULKAN_DIRECT,
654                        false,
655                        ADAPTIVE_TIMING_COMPOSITOR,
656                        ADAPTIVE_UPLOAD_DIRECT_GPU,
657                    )
658                } else {
659                    (
660                        ADAPTIVE_BACKEND_SOFTWARE_CPU,
661                        ADAPTIVE_BACKEND_VULKAN_DIRECT,
662                        true,
663                        ADAPTIVE_TIMING_PROXY,
664                        ADAPTIVE_UPLOAD_MULTI_RECT,
665                    )
666                }
667            }
668            PlatformKind::Web => (
669                ADAPTIVE_BACKEND_WEBGL2_UPLOAD,
670                ADAPTIVE_BACKEND_WEBGL2_UPLOAD,
671                true,
672                ADAPTIVE_TIMING_PROXY,
673                ADAPTIVE_UPLOAD_MULTI_RECT,
674            ),
675            PlatformKind::Terminal | PlatformKind::TerminalCli => (
676                ADAPTIVE_BACKEND_TERMINAL,
677                ADAPTIVE_BACKEND_TERMINAL,
678                false,
679                ADAPTIVE_TIMING_UNOBSERVABLE,
680                ADAPTIVE_UPLOAD_NONE,
681            ),
682            PlatformKind::Wearable
683            | PlatformKind::MiniApp
684            | PlatformKind::QuickApp
685            | PlatformKind::Headless => (
686                ADAPTIVE_BACKEND_SOFTWARE_CPU,
687                ADAPTIVE_BACKEND_SOFTWARE_CPU,
688                true,
689                ADAPTIVE_TIMING_PROXY,
690                ADAPTIVE_UPLOAD_MULTI_RECT,
691            ),
692        }
693    }
694
695    /// Synchronizes live adaptive render router telemetry into reactive `/settings` diagnostics signals.
696    ///
697    /// # Arguments
698    ///
699    /// - `&Self` - Reactive showcase state reference.
700    /// - `&str` - Active backend display label.
701    /// - `&str` - Recommended backend display label.
702    /// - `bool` - Whether a CPU software mirror is active.
703    /// - `&str` - Honest presentation timing source label.
704    /// - `&str` - Active upload/submission strategy label.
705    /// - `(u64, u64, u64)` - `(attempts, successes, aborts)` handoff counters.
706    pub fn sync_adaptive_render_diagnostics(
707        &self,
708        active_backend: &str,
709        recommended_backend: &str,
710        cpu_mirror_active: bool,
711        timing_source: &str,
712        upload_strategy: &str,
713        handoff_counts: (u64, u64, u64),
714    ) {
715        let _: bool = self
716            .get_adaptive_active_backend()
717            .set_if_changed(active_backend.to_string());
718        let _: bool = self
719            .get_adaptive_recommended_backend()
720            .set_if_changed(recommended_backend.to_string());
721        let _: bool = self
722            .get_adaptive_cpu_mirror_active()
723            .set_if_changed(cpu_mirror_active);
724        let _: bool = self
725            .get_adaptive_present_timing_source()
726            .set_if_changed(timing_source.to_string());
727        let _: bool = self
728            .get_adaptive_upload_strategy()
729            .set_if_changed(upload_strategy.to_string());
730        let _: bool = self
731            .get_adaptive_handoff_attempts()
732            .set_if_changed(handoff_counts.0);
733        let _: bool = self
734            .get_adaptive_handoff_successes()
735            .set_if_changed(handoff_counts.1);
736        let _: bool = self
737            .get_adaptive_handoff_aborts()
738            .set_if_changed(handoff_counts.2);
739    }
740
741    /// Formats a human-readable backend label from a `(GraphicsBackend, RenderBackendCandidate)` pair.
742    ///
743    /// # Arguments
744    ///
745    /// - `GraphicsBackend` - Active low-level graphics API backend.
746    /// - `RenderBackendCandidate` - Active or recommended adaptive render candidate.
747    ///
748    /// # Returns
749    ///
750    /// - `&'static str` - Canonical truthful backend label.
751    #[must_use]
752    fn adaptive_candidate_label(
753        backend: GraphicsBackend,
754        candidate: RenderBackendCandidate,
755    ) -> &'static str {
756        match candidate {
757            RenderBackendCandidate::GpuDirect => match backend {
758                GraphicsBackend::Metal => ADAPTIVE_BACKEND_METAL_DIRECT,
759                GraphicsBackend::Vulkan => ADAPTIVE_BACKEND_VULKAN_DIRECT,
760                GraphicsBackend::Direct3D11 | GraphicsBackend::Direct3D12 => {
761                    ADAPTIVE_BACKEND_D3D11_DIRECT
762                }
763                GraphicsBackend::OpenGlEs => ADAPTIVE_BACKEND_GLES3_DIRECT,
764                GraphicsBackend::WebGpu | GraphicsBackend::WebGl2 => ADAPTIVE_BACKEND_WEBGL2_DIRECT,
765                GraphicsBackend::Canvas2d => ADAPTIVE_BACKEND_CANVAS2D,
766                GraphicsBackend::SoftwareCpu | GraphicsBackend::Headless => {
767                    ADAPTIVE_BACKEND_SOFTWARE_CPU
768                }
769            },
770            RenderBackendCandidate::GpuUpload => match backend {
771                GraphicsBackend::Metal => ADAPTIVE_BACKEND_METAL_UPLOAD,
772                GraphicsBackend::WebGpu | GraphicsBackend::WebGl2 => ADAPTIVE_BACKEND_WEBGL2_UPLOAD,
773                GraphicsBackend::Vulkan => ADAPTIVE_BACKEND_VULKAN_DIRECT,
774                GraphicsBackend::Direct3D11 | GraphicsBackend::Direct3D12 => {
775                    ADAPTIVE_BACKEND_D3D11_DIRECT
776                }
777                GraphicsBackend::OpenGlEs => ADAPTIVE_BACKEND_GLES3_DIRECT,
778                GraphicsBackend::Canvas2d => ADAPTIVE_BACKEND_CANVAS2D,
779                GraphicsBackend::SoftwareCpu | GraphicsBackend::Headless => {
780                    ADAPTIVE_BACKEND_SOFTWARE_CPU
781                }
782            },
783            RenderBackendCandidate::Hybrid => ADAPTIVE_BACKEND_HYBRID_SPARSE,
784            RenderBackendCandidate::Software => {
785                if backend == GraphicsBackend::Canvas2d {
786                    ADAPTIVE_BACKEND_CANVAS2D
787                } else {
788                    ADAPTIVE_BACKEND_SOFTWARE_CPU
789                }
790            }
791            RenderBackendCandidate::Terminal => ADAPTIVE_BACKEND_TERMINAL,
792        }
793    }
794
795    /// Synchronizes `/settings` adaptive rollout toggle into `app`'s live `AdaptiveRenderRouter` and mirrors real `AdaptiveFrameMetrics` back into reactive signals.
796    ///
797    /// # Arguments
798    ///
799    /// - `&Self` - Reactive showcase state reference.
800    /// - `&mut App` - Active application owning the live `Renderer` and `AdaptiveRenderRouter`.
801    pub fn sync_adaptive_from_app(&self, app: &mut App) {
802        let desired_mode: AdaptiveSwitchMode = if self.get_adaptive_auto_switch().get_untracked() {
803            AdaptiveSwitchMode::AutoSwitch
804        } else {
805            AdaptiveSwitchMode::RecommendOnly
806        };
807        if app.adaptive_switch_mode() != desired_mode {
808            app.set_adaptive_switch_mode(desired_mode);
809        }
810        let metrics: AdaptiveFrameMetrics = app.adaptive_frame_metrics();
811        let snap: AdaptiveRouterSnapshot = metrics.get_adaptive_router();
812        let backend: GraphicsBackend = app.get_renderer().get_active_backend();
813        let active_label: &str =
814            Self::adaptive_candidate_label(backend, snap.get_active_candidate());
815        let rec_label: &str =
816            Self::adaptive_candidate_label(backend, snap.get_recommended_candidate());
817        let timing_label: &str = match metrics.get_present_timing_source() {
818            PresentTimingSource::CompositorMeasured => ADAPTIVE_TIMING_COMPOSITOR,
819            PresentTimingSource::SubmissionProxy => ADAPTIVE_TIMING_PROXY,
820            PresentTimingSource::Unobservable => ADAPTIVE_TIMING_UNOBSERVABLE,
821        };
822        let upload_label: &str = match metrics.get_upload_strategy() {
823            UploadStrategy::DirectGpu => ADAPTIVE_UPLOAD_DIRECT_GPU,
824            UploadStrategy::MultiRect => ADAPTIVE_UPLOAD_MULTI_RECT,
825            UploadStrategy::MergedBbox => ADAPTIVE_UPLOAD_MERGED_BBOX,
826            UploadStrategy::FullFrame => ADAPTIVE_UPLOAD_FULL_FRAME,
827            UploadStrategy::None => ADAPTIVE_UPLOAD_NONE,
828        };
829        let successes: u64 = snap.get_seamless_handoff_successes();
830        let aborts: u64 = snap.get_handoff_aborts();
831        let attempts: u64 = successes.saturating_add(aborts);
832        self.sync_adaptive_render_diagnostics(
833            active_label,
834            rec_label,
835            metrics.get_cpu_mirror_active(),
836            timing_label,
837            upload_label,
838            (attempts, successes, aborts),
839        );
840    }
841
842    /// Synchronizes `/settings` adaptive rollout toggle into `app`'s live `AdaptiveRenderRouter` and combines it with live Web dual-canvas handoff and `SubmissionProxy` telemetry.
843    ///
844    /// # Arguments
845    ///
846    /// - `&Self` - Reactive showcase state reference.
847    /// - `&mut App` - Active WebAssembly application owning the live `Renderer` and `AdaptiveRenderRouter`.
848    /// - `&ShowcaseWebDualCanvasCoordinator` - Live stacked dual-canvas coordinator snapshot.
849    pub fn sync_adaptive_from_web_coordinator(
850        &self,
851        app: &mut App,
852        coord: &ShowcaseWebDualCanvasCoordinator,
853    ) {
854        self.sync_adaptive_from_app(app);
855        let active_path: ShowcaseWebPresentationPath = coord.get_active().get_path();
856        let active_label: &str = match active_path {
857            ShowcaseWebPresentationPath::GpuDirect => ADAPTIVE_BACKEND_WEBGL2_DIRECT,
858            ShowcaseWebPresentationPath::GpuUpload => ADAPTIVE_BACKEND_WEBGL2_UPLOAD,
859            ShowcaseWebPresentationPath::Canvas2d => ADAPTIVE_BACKEND_CANVAS2D,
860        };
861        let upload_label: &str = match active_path {
862            ShowcaseWebPresentationPath::GpuDirect => ADAPTIVE_UPLOAD_DIRECT_GPU,
863            ShowcaseWebPresentationPath::GpuUpload => ADAPTIVE_UPLOAD_MULTI_RECT,
864            ShowcaseWebPresentationPath::Canvas2d => ADAPTIVE_UPLOAD_FULL_FRAME,
865        };
866        let timing_label: &str = match coord.get_timing_source() {
867            ShowcaseWebTimingSource::SubmissionProxy => ADAPTIVE_TIMING_PROXY,
868            ShowcaseWebTimingSource::Unobservable => ADAPTIVE_TIMING_UNOBSERVABLE,
869        };
870        let snap: AdaptiveRouterSnapshot = app.adaptive_router_snapshot();
871        let successes: u64 = snap
872            .get_seamless_handoff_successes()
873            .saturating_add(coord.get_completed_swaps());
874        let aborts: u64 = snap
875            .get_handoff_aborts()
876            .saturating_add(coord.get_aborted_swaps());
877        let attempts: u64 = successes.saturating_add(aborts);
878        self.sync_adaptive_render_diagnostics(
879            active_label,
880            active_label,
881            coord.get_cpu_mirror_active(),
882            timing_label,
883            upload_label,
884            (attempts, successes, aborts),
885        );
886    }
887
888    /// Resets all reactive shell and runtime preferences to canonical showcase defaults.
889    ///
890    /// # Arguments
891    ///
892    /// - `&Self` - Reactive showcase state reference.
893    pub fn reset_preferences_to_defaults(&self) {
894        let _: bool = self.get_auto_hide_chrome().set_if_changed(true);
895        let _: bool = self.get_show_fps_hud().set_if_changed(true);
896        let _: bool = self.get_swipe_routing().set_if_changed(true);
897        let _: bool = self.get_reduced_motion().set_if_changed(false);
898        let _: bool = self.get_adaptive_auto_switch().set_if_changed(false);
899        let _: bool = self
900            .get_theme()
901            .get_scheme()
902            .set_if_changed(active_feature_scheme());
903        let _: bool = self.get_theme().get_mode().set_if_changed(ThemeMode::Light);
904    }
905
906    /// Returns the lazily initialized `/reactive` signal group.
907    ///
908    /// # Arguments
909    ///
910    /// - `&Self` - Reactive showcase state reference.
911    ///
912    /// # Returns
913    ///
914    /// - `ReactiveSignals` - Active `/reactive` signal group.
915    fn reactive_group(&self) -> ReactiveSignals {
916        if let Some(existing) = self.get_reactive_signals().get() {
917            return existing;
918        }
919        let created: ReactiveSignals = self.get_state_scope().enter(ReactiveSignals::create);
920        self.get_reactive_signals().set(Some(created));
921        created
922    }
923
924    /// Returns the lazily initialized `/render` and `/window` signal group.
925    ///
926    /// # Arguments
927    ///
928    /// - `&Self` - Reactive showcase state reference.
929    ///
930    /// # Returns
931    ///
932    /// - `RenderWindowSignals` - Active `/render` and `/window` signal group.
933    fn render_window_group(&self) -> RenderWindowSignals {
934        if let Some(existing) = self.get_render_window_signals().get() {
935            return existing;
936        }
937        let default_plat: usize = self.get_default_host_plat_idx().get();
938        let created: RenderWindowSignals = self
939            .get_state_scope()
940            .enter(|| RenderWindowSignals::create(default_plat));
941        self.get_render_window_signals().set(Some(created));
942        created
943    }
944
945    /// Returns the lazily initialized `/forms` signal group.
946    ///
947    /// # Arguments
948    ///
949    /// - `&Self` - Reactive showcase state reference.
950    ///
951    /// # Returns
952    ///
953    /// - `FormsSignals` - Active `/forms` signal group.
954    fn forms_group(&self) -> FormsSignals {
955        if let Some(existing) = self.get_forms_signals().get() {
956            return existing;
957        }
958        let created: FormsSignals = self.get_state_scope().enter(FormsSignals::create);
959        self.get_forms_signals().set(Some(created));
960        created
961    }
962
963    /// Returns the lazily initialized `/overlays` signal group.
964    ///
965    /// # Arguments
966    ///
967    /// - `&Self` - Reactive showcase state reference.
968    ///
969    /// # Returns
970    ///
971    /// - `OverlaysSignals` - Active `/overlays` signal group.
972    fn overlays_group(&self) -> OverlaysSignals {
973        if let Some(existing) = self.get_overlays_signals().get() {
974            return existing;
975        }
976        let created: OverlaysSignals = self.get_state_scope().enter(OverlaysSignals::create);
977        self.get_overlays_signals().set(Some(created));
978        created
979    }
980
981    /// Returns the lazily initialized `/data` signal group.
982    ///
983    /// # Arguments
984    ///
985    /// - `&Self` - Reactive showcase state reference.
986    ///
987    /// # Returns
988    ///
989    /// - `DataSignals` - Active `/data` signal group.
990    fn data_group(&self) -> DataSignals {
991        if let Some(existing) = self.get_data_signals().get() {
992            return existing;
993        }
994        let created: DataSignals = self.get_state_scope().enter(DataSignals::create);
995        self.get_data_signals().set(Some(created));
996        created
997    }
998
999    /// Returns the lazily initialized `/game3d` signal group.
1000    ///
1001    /// # Arguments
1002    ///
1003    /// - `&Self` - Reactive showcase state reference.
1004    ///
1005    /// # Returns
1006    ///
1007    /// - `Engine3dSignals` - Active `/game3d` signal group.
1008    fn engine3d_group(&self) -> Engine3dSignals {
1009        Engine3dSignals::get_or_init(self.get_engine3d_signals().as_ref(), self.get_state_scope())
1010    }
1011
1012    /// Returns the lazily initialized `/dynamic` signal group.
1013    ///
1014    /// # Arguments
1015    ///
1016    /// - `&Self` - Reactive showcase state reference.
1017    ///
1018    /// # Returns
1019    ///
1020    /// - `DynamicSignals` - Active `/dynamic` signal group.
1021    fn dynamic_group(&self) -> DynamicSignals {
1022        DynamicSignals::get_or_init(self.get_dynamic_signals().as_ref(), self.get_state_scope())
1023    }
1024
1025    /// Returns the lazily initialized `/lab` signal group.
1026    ///
1027    /// # Arguments
1028    ///
1029    /// - `&Self` - Reactive showcase state reference.
1030    ///
1031    /// # Returns
1032    ///
1033    /// - `LabSignals` - Active `/lab` signal group.
1034    fn lab_group(&self) -> LabSignals {
1035        if let Some(existing) = self.get_lab_signals().get() {
1036            return existing;
1037        }
1038        let created: LabSignals = self.get_state_scope().enter(LabSignals::create);
1039        self.get_lab_signals().set(Some(created));
1040        created
1041    }
1042
1043    /// Returns the lazily initialized `/media` signal group.
1044    ///
1045    /// # Arguments
1046    ///
1047    /// - `&Self` - Reactive showcase state reference.
1048    ///
1049    /// # Returns
1050    ///
1051    /// - `MediaSignals` - Active `/media` signal group.
1052    fn media_group(&self) -> MediaSignals {
1053        if let Some(existing) = self.get_media_signals().get() {
1054            return existing;
1055        }
1056        let created: MediaSignals = self.get_state_scope().enter(MediaSignals::create);
1057        self.get_media_signals().set(Some(created));
1058        created
1059    }
1060
1061    /// Returns the lazily initialized `/markdown` signal group.
1062    ///
1063    /// # Arguments
1064    ///
1065    /// - `&Self` - Reactive showcase state reference.
1066    ///
1067    /// # Returns
1068    ///
1069    /// - `MarkdownSignals` - Active `/markdown` signal group.
1070    fn markdown_group(&self) -> MarkdownSignals {
1071        if let Some(existing) = self.get_markdown_signals().get() {
1072            return existing;
1073        }
1074        let created: MarkdownSignals = self.get_state_scope().enter(MarkdownSignals::create);
1075        self.get_markdown_signals().set(Some(created));
1076        created
1077    }
1078
1079    /// Returns the lazily initialized `/stress` signal group.
1080    ///
1081    /// # Arguments
1082    ///
1083    /// - `&Self` - Reactive showcase state reference.
1084    ///
1085    /// # Returns
1086    ///
1087    /// - `StressSignals` - Active `/stress` signal group.
1088    fn stress_group(&self) -> StressSignals {
1089        if let Some(existing) = self.get_stress_signals().get() {
1090            return existing;
1091        }
1092        let created: StressSignals = self.get_state_scope().enter(StressSignals::create);
1093        self.get_stress_signals().set(Some(created));
1094        created
1095    }
1096
1097    /// Returns the lazily initialized `/charts` signal group.
1098    ///
1099    /// # Arguments
1100    ///
1101    /// - `&Self` - Reactive showcase state reference.
1102    ///
1103    /// # Returns
1104    ///
1105    /// - `ChartsSignals` - Active `/charts` signal group.
1106    fn charts_group(&self) -> ChartsSignals {
1107        if let Some(existing) = self.get_charts_signals().get() {
1108            return existing;
1109        }
1110        let created: ChartsSignals = self.get_state_scope().enter(ChartsSignals::create);
1111        self.get_charts_signals().set(Some(created));
1112        created
1113    }
1114
1115    /// Returns the lazily initialized `/water` signal group.
1116    ///
1117    /// # Arguments
1118    ///
1119    /// - `&Self` - Reactive showcase state reference.
1120    ///
1121    /// # Returns
1122    ///
1123    /// - `WaterSignals` - Active `/water` signal group.
1124    fn water_group(&self) -> WaterSignals {
1125        if let Some(existing) = self.get_water_signals().get() {
1126            return existing;
1127        }
1128        let created: WaterSignals = self.get_state_scope().enter(WaterSignals::create);
1129        self.get_water_signals().set(Some(created));
1130        created
1131    }
1132
1133    /// Returns `true` when the `/water` `GyroLiquidGameScene` has been lazily initialized.
1134    ///
1135    /// # Arguments
1136    ///
1137    /// - `&Self` - Reactive showcase state reference.
1138    ///
1139    /// # Returns
1140    ///
1141    /// - `bool` - Whether the liquid simulation handle is materialized.
1142    #[must_use]
1143    pub fn has_water_scene_initialized(&self) -> bool {
1144        self.get_water_scene_cell().borrow().is_some()
1145    }
1146
1147    /// Returns the shared `GyroLiquidGameScene`, materializing it lazily on first `/water` visit.
1148    ///
1149    /// # Arguments
1150    ///
1151    /// - `&Self` - Reactive showcase state reference.
1152    ///
1153    /// # Returns
1154    ///
1155    /// - `GyroLiquidGameScene` - Active shareable liquid physics scene handle.
1156    #[must_use]
1157    pub fn get_or_init_water_scene(&self) -> GyroLiquidGameScene {
1158        if let Some(existing) = self.get_water_scene_cell().borrow().as_ref() {
1159            return existing.clone();
1160        }
1161        let created: GyroLiquidGameScene = GyroLiquidGameScene::default();
1162        *self.get_water_scene_cell().borrow_mut() = Some(created.clone());
1163        let _: bool = self
1164            .water_group()
1165            .get_stats()
1166            .set_if_changed(created.stats());
1167        created
1168    }
1169
1170    /// Returns the `/water` liquid fill percentage signal (`25.0..=80.0`).
1171    ///
1172    /// # Arguments
1173    ///
1174    /// - `&Self` - Reactive showcase state reference.
1175    ///
1176    /// # Returns
1177    ///
1178    /// - `Signal<f32>` - Fill level percentage signal handle.
1179    #[must_use]
1180    pub fn get_water_fill_pct(&self) -> Signal<f32> {
1181        self.water_group().get_fill_pct()
1182    }
1183
1184    /// Returns the `/water` viscosity preset index signal (`0=Water`, `1=Light Oil`, `2=Honey`).
1185    ///
1186    /// # Arguments
1187    ///
1188    /// - `&Self` - Reactive showcase state reference.
1189    ///
1190    /// # Returns
1191    ///
1192    /// - `Signal<usize>` - Viscosity preset index signal handle.
1193    #[must_use]
1194    pub fn get_water_viscosity_idx(&self) -> Signal<usize> {
1195        self.water_group().get_viscosity_idx()
1196    }
1197
1198    /// Returns the `/water` buoyant floating bodies toggle signal.
1199    ///
1200    /// # Arguments
1201    ///
1202    /// - `&Self` - Reactive showcase state reference.
1203    ///
1204    /// # Returns
1205    ///
1206    /// - `Signal<bool>` - Buoyant bodies toggle signal handle.
1207    #[must_use]
1208    pub fn get_water_buoyant_enabled(&self) -> Signal<bool> {
1209        self.water_group().get_buoyant_enabled()
1210    }
1211
1212    /// Returns the `/water` fullscreen portal open signal.
1213    ///
1214    /// # Arguments
1215    ///
1216    /// - `&Self` - Reactive showcase state reference.
1217    ///
1218    /// # Returns
1219    ///
1220    /// - `Signal<bool>` - Fullscreen portal open signal handle.
1221    #[must_use]
1222    pub fn get_water_fullscreen_open(&self) -> Signal<bool> {
1223        self.water_group().get_fullscreen_open()
1224    }
1225
1226    /// Returns the `/water` motion sensor permission status message signal.
1227    ///
1228    /// # Arguments
1229    ///
1230    /// - `&Self` - Reactive showcase state reference.
1231    ///
1232    /// # Returns
1233    ///
1234    /// - `Signal<String>` - Motion sensor status signal handle.
1235    #[must_use]
1236    pub fn get_water_sensor_perm_status(&self) -> Signal<String> {
1237        self.water_group().get_sensor_perm_status()
1238    }
1239
1240    /// Returns the `/water` live physics telemetry snapshot signal.
1241    ///
1242    /// # Arguments
1243    ///
1244    /// - `&Self` - Reactive showcase state reference.
1245    ///
1246    /// # Returns
1247    ///
1248    /// - `Signal<GyroLiquidStats>` - Live liquid physics telemetry signal handle.
1249    #[must_use]
1250    pub fn get_water_stats(&self) -> Signal<GyroLiquidStats> {
1251        self.water_group().get_stats()
1252    }
1253
1254    /// Returns the interactive counter signal for `/reactive`.
1255    ///
1256    /// # Arguments
1257    ///
1258    /// - `&Self` - Reactive showcase state reference.
1259    ///
1260    /// # Returns
1261    ///
1262    /// - `Signal<i32>` - Counter signal handle.
1263    #[must_use]
1264    pub fn get_counter(&self) -> Signal<i32> {
1265        self.reactive_group().get_counter()
1266    }
1267
1268    /// Returns the derived `counter * 2` memo for `/reactive`.
1269    ///
1270    /// # Arguments
1271    ///
1272    /// - `&Self` - Reactive showcase state reference.
1273    ///
1274    /// # Returns
1275    ///
1276    /// - `Memo<i32>` - Doubled counter memo handle.
1277    #[must_use]
1278    pub fn get_doubled(&self) -> Memo<i32> {
1279        self.reactive_group().get_doubled()
1280    }
1281
1282    /// Returns the component-scoped demo render pipeline preview index signal.
1283    ///
1284    /// # Arguments
1285    ///
1286    /// - `&Self` - Reactive showcase state reference.
1287    ///
1288    /// # Returns
1289    ///
1290    /// - `Signal<usize>` - Render mode index signal handle.
1291    #[must_use]
1292    pub fn get_render_mode_index(&self) -> Signal<usize> {
1293        self.render_window_group().get_render_mode_index()
1294    }
1295
1296    /// Returns the component-scoped demo FPS cap index signal on `/window`.
1297    ///
1298    /// # Arguments
1299    ///
1300    /// - `&Self` - Reactive showcase state reference.
1301    ///
1302    /// # Returns
1303    ///
1304    /// - `Signal<usize>` - FPS cap index signal handle.
1305    #[must_use]
1306    pub fn get_demo_fps_cap_index(&self) -> Signal<usize> {
1307        self.render_window_group().get_demo_fps_cap_index()
1308    }
1309
1310    /// Returns the controlled fullscreen toggle signal.
1311    ///
1312    /// # Arguments
1313    ///
1314    /// - `&Self` - Reactive showcase state reference.
1315    ///
1316    /// # Returns
1317    ///
1318    /// - `Signal<bool>` - Fullscreen signal handle.
1319    #[must_use]
1320    pub fn get_fullscreen(&self) -> Signal<bool> {
1321        self.render_window_group().get_fullscreen()
1322    }
1323
1324    /// Returns the Dynamic Island active state signal.
1325    ///
1326    /// # Arguments
1327    ///
1328    /// - `&Self` - Reactive showcase state reference.
1329    ///
1330    /// # Returns
1331    ///
1332    /// - `Signal<bool>` - Island active signal handle.
1333    #[must_use]
1334    pub fn get_island_active(&self) -> Signal<bool> {
1335        self.render_window_group().get_island_active()
1336    }
1337
1338    /// Returns the Dynamic Island progress signal (`0..=100`).
1339    ///
1340    /// # Arguments
1341    ///
1342    /// - `&Self` - Reactive showcase state reference.
1343    ///
1344    /// # Returns
1345    ///
1346    /// - `Signal<u8>` - Island progress signal handle.
1347    #[must_use]
1348    pub fn get_island_progress(&self) -> Signal<u8> {
1349        self.render_window_group().get_island_progress()
1350    }
1351
1352    /// Returns the camera permission status readout signal.
1353    ///
1354    /// # Arguments
1355    ///
1356    /// - `&Self` - Reactive showcase state reference.
1357    ///
1358    /// # Returns
1359    ///
1360    /// - `Signal<String>` - Camera permission status signal handle.
1361    #[must_use]
1362    pub fn get_camera_perm_status(&self) -> Signal<String> {
1363        self.render_window_group().get_camera_perm_status()
1364    }
1365
1366    /// Returns the protocol registration status readout signal.
1367    ///
1368    /// # Arguments
1369    ///
1370    /// - `&Self` - Reactive showcase state reference.
1371    ///
1372    /// # Returns
1373    ///
1374    /// - `Signal<String>` - Protocol status signal handle.
1375    #[must_use]
1376    pub fn get_protocol_status(&self) -> Signal<String> {
1377        self.render_window_group().get_protocol_status()
1378    }
1379
1380    /// Returns the accessibility live announcement counter signal.
1381    ///
1382    /// # Arguments
1383    ///
1384    /// - `&Self` - Reactive showcase state reference.
1385    ///
1386    /// # Returns
1387    ///
1388    /// - `Signal<u32>` - Accessibility counter signal handle.
1389    #[must_use]
1390    pub fn get_a11y_announcements(&self) -> Signal<u32> {
1391        self.render_window_group().get_a11y_announcements()
1392    }
1393
1394    /// Returns the haptic pulse counter signal.
1395    ///
1396    /// # Arguments
1397    ///
1398    /// - `&Self` - Reactive showcase state reference.
1399    ///
1400    /// # Returns
1401    ///
1402    /// - `Signal<u32>` - Haptic counter signal handle.
1403    #[must_use]
1404    pub fn get_haptic_pulses(&self) -> Signal<u32> {
1405        self.render_window_group().get_haptic_pulses()
1406    }
1407
1408    /// Returns the simulated target platform index signal on `/window`.
1409    ///
1410    /// # Arguments
1411    ///
1412    /// - `&Self` - Reactive showcase state reference.
1413    ///
1414    /// # Returns
1415    ///
1416    /// - `Signal<usize>` - Target platform index signal handle.
1417    #[must_use]
1418    pub fn get_os_target_platform_idx(&self) -> Signal<usize> {
1419        self.render_window_group().get_os_target_platform_idx()
1420    }
1421
1422    /// Returns the Dynamic Island presentation mode index signal.
1423    ///
1424    /// # Arguments
1425    ///
1426    /// - `&Self` - Reactive showcase state reference.
1427    ///
1428    /// # Returns
1429    ///
1430    /// - `Signal<usize>` - Island presentation mode index signal handle.
1431    #[must_use]
1432    pub fn get_island_mode_idx(&self) -> Signal<usize> {
1433        self.render_window_group().get_island_mode_idx()
1434    }
1435
1436    /// Returns the live system notifications stack signal.
1437    ///
1438    /// # Arguments
1439    ///
1440    /// - `&Self` - Reactive showcase state reference.
1441    ///
1442    /// # Returns
1443    ///
1444    /// - `Signal<Vec<(String, String)>>` - System notifications signal handle.
1445    #[must_use]
1446    pub fn get_system_notifications(&self) -> Signal<Vec<(String, String)>> {
1447        self.render_window_group().get_system_notifications()
1448    }
1449
1450    /// Returns the per-permission status vector signal on `/window`.
1451    ///
1452    /// # Arguments
1453    ///
1454    /// - `&Self` - Reactive showcase state reference.
1455    ///
1456    /// # Returns
1457    ///
1458    /// - `Signal<Vec<PermissionStatus>>` - Permission statuses signal handle.
1459    #[must_use]
1460    pub fn get_permission_statuses(&self) -> Signal<Vec<PermissionStatus>> {
1461        self.render_window_group().get_permission_statuses()
1462    }
1463
1464    /// Returns the controlled username input signal.
1465    ///
1466    /// # Arguments
1467    ///
1468    /// - `&Self` - Reactive showcase state reference.
1469    ///
1470    /// # Returns
1471    ///
1472    /// - `Signal<String>` - Username signal handle.
1473    #[must_use]
1474    pub fn get_username(&self) -> Signal<String> {
1475        self.forms_group().get_username()
1476    }
1477
1478    /// Returns the controlled multi-line bio textarea signal.
1479    ///
1480    /// # Arguments
1481    ///
1482    /// - `&Self` - Reactive showcase state reference.
1483    ///
1484    /// # Returns
1485    ///
1486    /// - `Signal<String>` - Bio signal handle.
1487    #[must_use]
1488    pub fn get_bio(&self) -> Signal<String> {
1489        self.forms_group().get_bio()
1490    }
1491
1492    /// Returns the controlled numeric stepper signal.
1493    ///
1494    /// # Arguments
1495    ///
1496    /// - `&Self` - Reactive showcase state reference.
1497    ///
1498    /// # Returns
1499    ///
1500    /// - `Signal<i64>` - Stepper value signal handle.
1501    #[must_use]
1502    pub fn get_stepper_value(&self) -> Signal<i64> {
1503        self.forms_group().get_stepper_value()
1504    }
1505
1506    /// Returns the controlled radio group selection index signal.
1507    ///
1508    /// # Arguments
1509    ///
1510    /// - `&Self` - Reactive showcase state reference.
1511    ///
1512    /// # Returns
1513    ///
1514    /// - `Signal<usize>` - Radio index signal handle.
1515    #[must_use]
1516    pub fn get_radio_index(&self) -> Signal<usize> {
1517        self.forms_group().get_radio_index()
1518    }
1519
1520    /// Returns the controlled continuous slider value signal.
1521    ///
1522    /// # Arguments
1523    ///
1524    /// - `&Self` - Reactive showcase state reference.
1525    ///
1526    /// # Returns
1527    ///
1528    /// - `Signal<f32>` - Slider value signal handle.
1529    #[must_use]
1530    pub fn get_slider_value(&self) -> Signal<f32> {
1531        self.forms_group().get_slider_value()
1532    }
1533
1534    /// Returns the controlled select dropdown index signal.
1535    ///
1536    /// # Arguments
1537    ///
1538    /// - `&Self` - Reactive showcase state reference.
1539    ///
1540    /// # Returns
1541    ///
1542    /// - `Signal<usize>` - Select index signal handle.
1543    #[must_use]
1544    pub fn get_select_index(&self) -> Signal<usize> {
1545        self.forms_group().get_select_index()
1546    }
1547
1548    /// Returns the controlled select dropdown open flag signal.
1549    ///
1550    /// # Arguments
1551    ///
1552    /// - `&Self` - Reactive showcase state reference.
1553    ///
1554    /// # Returns
1555    ///
1556    /// - `Signal<bool>` - Select open signal handle.
1557    #[must_use]
1558    pub fn get_select_open(&self) -> Signal<bool> {
1559        self.forms_group().get_select_open()
1560    }
1561
1562    /// Returns the controlled star rating value signal.
1563    ///
1564    /// # Arguments
1565    ///
1566    /// - `&Self` - Reactive showcase state reference.
1567    ///
1568    /// # Returns
1569    ///
1570    /// - `Signal<usize>` - Rating value signal handle.
1571    #[must_use]
1572    pub fn get_rating_value(&self) -> Signal<usize> {
1573        self.forms_group().get_rating_value()
1574    }
1575
1576    /// Returns the controlled toggle pill pressed state signal.
1577    ///
1578    /// # Arguments
1579    ///
1580    /// - `&Self` - Reactive showcase state reference.
1581    ///
1582    /// # Returns
1583    ///
1584    /// - `Signal<bool>` - Pin toggled signal handle.
1585    #[must_use]
1586    pub fn get_pin_toggled(&self) -> Signal<bool> {
1587        self.forms_group().get_pin_toggled()
1588    }
1589
1590    /// Returns the controlled hardware acceleration toggle switch signal.
1591    ///
1592    /// # Arguments
1593    ///
1594    /// - `&Self` - Reactive showcase state reference.
1595    ///
1596    /// # Returns
1597    ///
1598    /// - `Signal<bool>` - Hardware acceleration signal handle.
1599    #[must_use]
1600    pub fn get_hardware_accel(&self) -> Signal<bool> {
1601        self.forms_group().get_hardware_accel()
1602    }
1603
1604    /// Returns the controlled terms checkbox signal.
1605    ///
1606    /// # Arguments
1607    ///
1608    /// - `&Self` - Reactive showcase state reference.
1609    ///
1610    /// # Returns
1611    ///
1612    /// - `Signal<bool>` - Terms checkbox signal handle.
1613    #[must_use]
1614    pub fn get_agree_terms(&self) -> Signal<bool> {
1615        self.forms_group().get_agree_terms()
1616    }
1617
1618    /// Returns the controlled tab bar index signal.
1619    ///
1620    /// # Arguments
1621    ///
1622    /// - `&Self` - Reactive showcase state reference.
1623    ///
1624    /// # Returns
1625    ///
1626    /// - `Signal<usize>` - Active tab signal handle.
1627    #[must_use]
1628    pub fn get_active_tab(&self) -> Signal<usize> {
1629        self.forms_group().get_active_tab()
1630    }
1631
1632    /// Returns the controlled pagination page number signal.
1633    ///
1634    /// # Arguments
1635    ///
1636    /// - `&Self` - Reactive showcase state reference.
1637    ///
1638    /// # Returns
1639    ///
1640    /// - `Signal<usize>` - Page index signal handle.
1641    #[must_use]
1642    pub fn get_page_index(&self) -> Signal<usize> {
1643        self.forms_group().get_page_index()
1644    }
1645
1646    /// Returns the controlled steps indicator index signal.
1647    ///
1648    /// # Arguments
1649    ///
1650    /// - `&Self` - Reactive showcase state reference.
1651    ///
1652    /// # Returns
1653    ///
1654    /// - `Signal<usize>` - Step index signal handle.
1655    #[must_use]
1656    pub fn get_step_index(&self) -> Signal<usize> {
1657        self.forms_group().get_step_index()
1658    }
1659
1660    /// Returns the controlled accordion expanded index signal.
1661    ///
1662    /// # Arguments
1663    ///
1664    /// - `&Self` - Reactive showcase state reference.
1665    ///
1666    /// # Returns
1667    ///
1668    /// - `Signal<Option<usize>>` - Accordion open index signal handle.
1669    #[must_use]
1670    pub fn get_accordion_open(&self) -> Signal<Option<usize>> {
1671        self.forms_group().get_accordion_open()
1672    }
1673
1674    /// Returns the controlled accent color picker signal.
1675    ///
1676    /// # Arguments
1677    ///
1678    /// - `&Self` - Reactive showcase state reference.
1679    ///
1680    /// # Returns
1681    ///
1682    /// - `Signal<Color>` - Picker color signal handle.
1683    #[must_use]
1684    pub fn get_picker_color(&self) -> Signal<Color> {
1685        self.forms_group().get_picker_color()
1686    }
1687
1688    /// Returns the controlled 24-hour time picker signal.
1689    ///
1690    /// # Arguments
1691    ///
1692    /// - `&Self` - Reactive showcase state reference.
1693    ///
1694    /// # Returns
1695    ///
1696    /// - `Signal<(u8, u8)>` - Picker time signal handle.
1697    #[must_use]
1698    pub fn get_picker_time(&self) -> Signal<(u8, u8)> {
1699        self.forms_group().get_picker_time()
1700    }
1701
1702    /// Returns the controlled dynamic tag input list signal.
1703    ///
1704    /// # Arguments
1705    ///
1706    /// - `&Self` - Reactive showcase state reference.
1707    ///
1708    /// # Returns
1709    ///
1710    /// - `Signal<Vec<String>>` - Tag items signal handle.
1711    #[must_use]
1712    pub fn get_tag_items(&self) -> Signal<Vec<String>> {
1713        self.forms_group().get_tag_items()
1714    }
1715
1716    /// Returns the controlled interactive tree selected label signal.
1717    ///
1718    /// # Arguments
1719    ///
1720    /// - `&Self` - Reactive showcase state reference.
1721    ///
1722    /// # Returns
1723    ///
1724    /// - `Signal<Option<String>>` - Tree selection signal handle.
1725    #[must_use]
1726    pub fn get_tree_selected(&self) -> Signal<Option<String>> {
1727        self.forms_group().get_tree_selected()
1728    }
1729
1730    /// Returns the controlled breadcrumb active index signal.
1731    ///
1732    /// # Arguments
1733    ///
1734    /// - `&Self` - Reactive showcase state reference.
1735    ///
1736    /// # Returns
1737    ///
1738    /// - `Signal<usize>` - Breadcrumb index signal handle.
1739    #[must_use]
1740    pub fn get_breadcrumb_active(&self) -> Signal<usize> {
1741        self.forms_group().get_breadcrumb_active()
1742    }
1743
1744    /// Returns the controlled modal open signal on `/overlays`.
1745    ///
1746    /// # Arguments
1747    ///
1748    /// - `&Self` - Reactive showcase state reference.
1749    ///
1750    /// # Returns
1751    ///
1752    /// - `Signal<bool>` - Modal open signal handle.
1753    #[must_use]
1754    pub fn get_modal_open(&self) -> Signal<bool> {
1755        self.overlays_group().get_modal_open()
1756    }
1757
1758    /// Returns the controlled drawer open signal on `/overlays`.
1759    ///
1760    /// # Arguments
1761    ///
1762    /// - `&Self` - Reactive showcase state reference.
1763    ///
1764    /// # Returns
1765    ///
1766    /// - `Signal<bool>` - Drawer open signal handle.
1767    #[must_use]
1768    pub fn get_drawer_open(&self) -> Signal<bool> {
1769        self.overlays_group().get_drawer_open()
1770    }
1771
1772    /// Returns the controlled sheet open signal on `/overlays`.
1773    ///
1774    /// # Arguments
1775    ///
1776    /// - `&Self` - Reactive showcase state reference.
1777    ///
1778    /// # Returns
1779    ///
1780    /// - `Signal<bool>` - Sheet open signal handle.
1781    #[must_use]
1782    pub fn get_sheet_open(&self) -> Signal<bool> {
1783        self.overlays_group().get_sheet_open()
1784    }
1785
1786    /// Returns the controlled popover open signal on `/overlays`.
1787    ///
1788    /// # Arguments
1789    ///
1790    /// - `&Self` - Reactive showcase state reference.
1791    ///
1792    /// # Returns
1793    ///
1794    /// - `Signal<bool>` - Popover open signal handle.
1795    #[must_use]
1796    pub fn get_popover_open(&self) -> Signal<bool> {
1797        self.overlays_group().get_popover_open()
1798    }
1799
1800    /// Returns the controlled dropdown open signal on `/overlays`.
1801    ///
1802    /// # Arguments
1803    ///
1804    /// - `&Self` - Reactive showcase state reference.
1805    ///
1806    /// # Returns
1807    ///
1808    /// - `Signal<bool>` - Dropdown open signal handle.
1809    #[must_use]
1810    pub fn get_dropdown_open(&self) -> Signal<bool> {
1811        self.overlays_group().get_dropdown_open()
1812    }
1813
1814    /// Returns the controlled dropdown selected index signal on `/overlays`.
1815    ///
1816    /// # Arguments
1817    ///
1818    /// - `&Self` - Reactive showcase state reference.
1819    ///
1820    /// # Returns
1821    ///
1822    /// - `Signal<Option<usize>>` - Dropdown selected index signal handle.
1823    #[must_use]
1824    pub fn get_dropdown_selected(&self) -> Signal<Option<usize>> {
1825        self.overlays_group().get_dropdown_selected()
1826    }
1827
1828    /// Returns the controlled toast banner visibility signal on `/overlays`.
1829    ///
1830    /// # Arguments
1831    ///
1832    /// - `&Self` - Reactive showcase state reference.
1833    ///
1834    /// # Returns
1835    ///
1836    /// - `Signal<bool>` - Toast visibility signal handle.
1837    #[must_use]
1838    pub fn get_toast_visible(&self) -> Signal<bool> {
1839        self.overlays_group().get_toast_visible()
1840    }
1841
1842    /// Returns the controlled notification visibility signal on `/overlays`.
1843    ///
1844    /// # Arguments
1845    ///
1846    /// - `&Self` - Reactive showcase state reference.
1847    ///
1848    /// # Returns
1849    ///
1850    /// - `Signal<bool>` - Notification visibility signal handle.
1851    #[must_use]
1852    pub fn get_notif_visible(&self) -> Signal<bool> {
1853        self.overlays_group().get_notif_visible()
1854    }
1855
1856    /// Returns the controlled loading overlay active signal on `/overlays`.
1857    ///
1858    /// # Arguments
1859    ///
1860    /// - `&Self` - Reactive showcase state reference.
1861    ///
1862    /// # Returns
1863    ///
1864    /// - `Signal<bool>` - Loading active signal handle.
1865    #[must_use]
1866    pub fn get_loading_active(&self) -> Signal<bool> {
1867        self.overlays_group().get_loading_active()
1868    }
1869
1870    /// Returns the vertical scroll offset signal driving the 10,000-row virtualized list on `/data`.
1871    ///
1872    /// # Arguments
1873    ///
1874    /// - `&Self` - Reactive showcase state reference.
1875    ///
1876    /// # Returns
1877    ///
1878    /// - `Signal<f32>` - Virtual list scroll offset signal handle.
1879    #[must_use]
1880    pub fn get_list_scroll_y(&self) -> Signal<f32> {
1881        self.data_group().get_list_scroll_y()
1882    }
1883
1884    /// Returns the live 3D quality and ray-tracing configuration signal.
1885    ///
1886    /// # Arguments
1887    ///
1888    /// - `&Self` - Reactive showcase state reference.
1889    ///
1890    /// # Returns
1891    ///
1892    /// - `Signal<RenderQualityConfig>` - 3D quality configuration signal handle.
1893    #[must_use]
1894    pub fn get_engine3d_quality(&self) -> Signal<RenderQualityConfig> {
1895        self.engine3d_group().get_engine3d_quality()
1896    }
1897
1898    /// Returns the live 3D quality preset index signal.
1899    ///
1900    /// # Arguments
1901    ///
1902    /// - `&Self` - Reactive showcase state reference.
1903    ///
1904    /// # Returns
1905    ///
1906    /// - `Signal<usize>` - 3D quality preset index signal handle.
1907    #[must_use]
1908    pub fn get_engine3d_preset_idx(&self) -> Signal<usize> {
1909        self.engine3d_group().get_engine3d_preset_idx()
1910    }
1911
1912    /// Returns the live 3D ray-tracing mode index signal.
1913    ///
1914    /// # Arguments
1915    ///
1916    /// - `&Self` - Reactive showcase state reference.
1917    ///
1918    /// # Returns
1919    ///
1920    /// - `Signal<usize>` - 3D ray-tracing mode index signal handle.
1921    #[must_use]
1922    pub fn get_engine3d_rt_idx(&self) -> Signal<usize> {
1923        self.engine3d_group().get_engine3d_rt_idx()
1924    }
1925
1926    /// Returns the live 3D internal resolution scale percentage signal.
1927    ///
1928    /// # Arguments
1929    ///
1930    /// - `&Self` - Reactive showcase state reference.
1931    ///
1932    /// # Returns
1933    ///
1934    /// - `Signal<f32>` - 3D resolution scale signal handle.
1935    #[must_use]
1936    pub fn get_engine3d_res_scale(&self) -> Signal<f32> {
1937        self.engine3d_group().get_engine3d_res_scale()
1938    }
1939
1940    /// Returns the live 3D sun time-of-day signal.
1941    ///
1942    /// # Arguments
1943    ///
1944    /// - `&Self` - Reactive showcase state reference.
1945    ///
1946    /// # Returns
1947    ///
1948    /// - `Signal<f32>` - 3D time-of-day signal handle.
1949    #[must_use]
1950    pub fn get_engine3d_time_of_day(&self) -> Signal<f32> {
1951        self.engine3d_group().get_engine3d_time_of_day()
1952    }
1953
1954    /// Returns the monotonic 3D model import request signal.
1955    ///
1956    /// # Arguments
1957    ///
1958    /// - `&Self` - Reactive showcase state reference.
1959    ///
1960    /// # Returns
1961    ///
1962    /// - `Signal<u64>` - 3D import queue signal handle.
1963    #[must_use]
1964    pub fn get_engine3d_import_queue(&self) -> Signal<u64> {
1965        self.engine3d_group().get_engine3d_import_queue()
1966    }
1967
1968    /// Returns the live 3D model import status readout signal.
1969    ///
1970    /// # Arguments
1971    ///
1972    /// - `&Self` - Reactive showcase state reference.
1973    ///
1974    /// # Returns
1975    ///
1976    /// - `Signal<String>` - 3D import status signal handle.
1977    #[must_use]
1978    pub fn get_engine3d_import_status(&self) -> Signal<String> {
1979        self.engine3d_group().get_engine3d_import_status()
1980    }
1981
1982    /// Returns the active 3D camera mode signal.
1983    ///
1984    /// # Arguments
1985    ///
1986    /// - `&Self` - Reactive showcase state reference.
1987    ///
1988    /// # Returns
1989    ///
1990    /// - `Signal<u8>` - 3D camera mode signal handle.
1991    #[must_use]
1992    pub fn get_engine3d_camera_mode(&self) -> Signal<u8> {
1993        self.engine3d_group().get_engine3d_camera_mode()
1994    }
1995
1996    /// Returns the preserved sibling counter signal on `/dynamic`.
1997    ///
1998    /// # Arguments
1999    ///
2000    /// - `&Self` - Reactive showcase state reference.
2001    ///
2002    /// # Returns
2003    ///
2004    /// - `Signal<i32>` - Sibling counter signal handle.
2005    #[must_use]
2006    pub fn get_sibling_counter(&self) -> Signal<i32> {
2007        self.dynamic_group().get_sibling_counter()
2008    }
2009
2010    /// Returns the latest dynamic OTA action log readout signal.
2011    ///
2012    /// # Arguments
2013    ///
2014    /// - `&Self` - Reactive showcase state reference.
2015    ///
2016    /// # Returns
2017    ///
2018    /// - `Signal<String>` - Dynamic action log signal handle.
2019    #[must_use]
2020    pub fn get_dynamic_action_log(&self) -> Signal<String> {
2021        self.dynamic_group().get_dynamic_action_log()
2022    }
2023
2024    /// Returns the simulated offline mode toggle signal for dynamic WASM tests.
2025    ///
2026    /// # Arguments
2027    ///
2028    /// - `&Self` - Reactive showcase state reference.
2029    ///
2030    /// # Returns
2031    ///
2032    /// - `Signal<bool>` - WASM offline flag signal handle.
2033    #[must_use]
2034    pub fn get_wasm_offline(&self) -> Signal<bool> {
2035        self.dynamic_group().get_wasm_offline()
2036    }
2037
2038    /// Returns the live dynamic WASM download and fault readout signal.
2039    ///
2040    /// # Arguments
2041    ///
2042    /// - `&Self` - Reactive showcase state reference.
2043    ///
2044    /// # Returns
2045    ///
2046    /// - `Signal<String>` - WASM fault status signal handle.
2047    #[must_use]
2048    pub fn get_wasm_fault_status(&self) -> Signal<String> {
2049        self.dynamic_group().get_wasm_fault_status()
2050    }
2051
2052    /// Returns the `EuvAlertDialog` open state signal on `/lab`.
2053    ///
2054    /// # Arguments
2055    ///
2056    /// - `&Self` - Reactive showcase state reference.
2057    ///
2058    /// # Returns
2059    ///
2060    /// - `Signal<bool>` - Alert dialog open signal handle.
2061    #[must_use]
2062    pub fn get_alert_dialog_open(&self) -> Signal<bool> {
2063        self.lab_group().get_alert_dialog_open()
2064    }
2065
2066    /// Returns the `EuvAlertDialog` confirmed flag signal on `/lab`.
2067    ///
2068    /// # Arguments
2069    ///
2070    /// - `&Self` - Reactive showcase state reference.
2071    ///
2072    /// # Returns
2073    ///
2074    /// - `Signal<bool>` - Alert dialog confirmed signal handle.
2075    #[must_use]
2076    pub fn get_alert_dialog_confirmed(&self) -> Signal<bool> {
2077        self.lab_group().get_alert_dialog_confirmed()
2078    }
2079
2080    /// Returns the `EuvCollapsible` expanded flag signal on `/lab`.
2081    ///
2082    /// # Arguments
2083    ///
2084    /// - `&Self` - Reactive showcase state reference.
2085    ///
2086    /// # Returns
2087    ///
2088    /// - `Signal<bool>` - Collapsible open signal handle.
2089    #[must_use]
2090    pub fn get_collapsible_open(&self) -> Signal<bool> {
2091        self.lab_group().get_collapsible_open()
2092    }
2093
2094    /// Returns the `EuvToggleGroup` active option index signal on `/lab`.
2095    ///
2096    /// # Arguments
2097    ///
2098    /// - `&Self` - Reactive showcase state reference.
2099    ///
2100    /// # Returns
2101    ///
2102    /// - `Signal<usize>` - Toggle group index signal handle.
2103    #[must_use]
2104    pub fn get_toggle_group_index(&self) -> Signal<usize> {
2105        self.lab_group().get_toggle_group_index()
2106    }
2107
2108    /// Returns the `EuvInputOtp` passcode string signal on `/lab`.
2109    ///
2110    /// # Arguments
2111    ///
2112    /// - `&Self` - Reactive showcase state reference.
2113    ///
2114    /// # Returns
2115    ///
2116    /// - `Signal<String>` - OTP code signal handle.
2117    #[must_use]
2118    pub fn get_otp_code(&self) -> Signal<String> {
2119        self.lab_group().get_otp_code()
2120    }
2121
2122    /// Returns the `EuvCommand` query string signal on `/lab`.
2123    ///
2124    /// # Arguments
2125    ///
2126    /// - `&Self` - Reactive showcase state reference.
2127    ///
2128    /// # Returns
2129    ///
2130    /// - `Signal<String>` - Command query signal handle.
2131    #[must_use]
2132    pub fn get_command_query(&self) -> Signal<String> {
2133        self.lab_group().get_command_query()
2134    }
2135
2136    /// Returns the `EuvCommand` selected index signal on `/lab`.
2137    ///
2138    /// # Arguments
2139    ///
2140    /// - `&Self` - Reactive showcase state reference.
2141    ///
2142    /// # Returns
2143    ///
2144    /// - `Signal<Option<usize>>` - Command selected index signal handle.
2145    #[must_use]
2146    pub fn get_command_selected(&self) -> Signal<Option<usize>> {
2147        self.lab_group().get_command_selected()
2148    }
2149
2150    /// Returns the `EuvHoverCard` open flag signal on `/lab`.
2151    ///
2152    /// # Arguments
2153    ///
2154    /// - `&Self` - Reactive showcase state reference.
2155    ///
2156    /// # Returns
2157    ///
2158    /// - `Signal<bool>` - Hover card open signal handle.
2159    #[must_use]
2160    pub fn get_hover_card_open(&self) -> Signal<bool> {
2161        self.lab_group().get_hover_card_open()
2162    }
2163
2164    /// Returns the `EuvCalendar` selected day signal on `/lab`.
2165    ///
2166    /// # Arguments
2167    ///
2168    /// - `&Self` - Reactive showcase state reference.
2169    ///
2170    /// # Returns
2171    ///
2172    /// - `Signal<u32>` - Calendar day signal handle.
2173    #[must_use]
2174    pub fn get_calendar_day(&self) -> Signal<u32> {
2175        self.lab_group().get_calendar_day()
2176    }
2177
2178    /// Returns the `EuvMenubar` active menu index signal on `/lab`.
2179    ///
2180    /// # Arguments
2181    ///
2182    /// - `&Self` - Reactive showcase state reference.
2183    ///
2184    /// # Returns
2185    ///
2186    /// - `Signal<Option<usize>>` - Menubar active index signal handle.
2187    #[must_use]
2188    pub fn get_menubar_active(&self) -> Signal<Option<usize>> {
2189        self.lab_group().get_menubar_active()
2190    }
2191
2192    /// Returns the `EuvCarousel` active slide index signal on `/lab`.
2193    ///
2194    /// # Arguments
2195    ///
2196    /// - `&Self` - Reactive showcase state reference.
2197    ///
2198    /// # Returns
2199    ///
2200    /// - `Signal<usize>` - Carousel index signal handle.
2201    #[must_use]
2202    pub fn get_carousel_index(&self) -> Signal<usize> {
2203        self.lab_group().get_carousel_index()
2204    }
2205
2206    /// Returns the `EuvCombobox` search query signal on `/lab`.
2207    ///
2208    /// # Arguments
2209    ///
2210    /// - `&Self` - Reactive showcase state reference.
2211    ///
2212    /// # Returns
2213    ///
2214    /// - `Signal<String>` - Combobox query signal handle.
2215    #[must_use]
2216    pub fn get_lab_combobox_query(&self) -> Signal<String> {
2217        self.lab_group().get_lab_combobox_query()
2218    }
2219
2220    /// Returns the `EuvCombobox` selected index signal on `/lab`.
2221    ///
2222    /// # Arguments
2223    ///
2224    /// - `&Self` - Reactive showcase state reference.
2225    ///
2226    /// # Returns
2227    ///
2228    /// - `Signal<usize>` - Combobox selected index signal handle.
2229    #[must_use]
2230    pub fn get_lab_combobox_selected(&self) -> Signal<usize> {
2231        self.lab_group().get_lab_combobox_selected()
2232    }
2233
2234    /// Returns the `EuvCombobox` open flag signal on `/lab`.
2235    ///
2236    /// # Arguments
2237    ///
2238    /// - `&Self` - Reactive showcase state reference.
2239    ///
2240    /// # Returns
2241    ///
2242    /// - `Signal<bool>` - Combobox open signal handle.
2243    #[must_use]
2244    pub fn get_lab_combobox_open(&self) -> Signal<bool> {
2245        self.lab_group().get_lab_combobox_open()
2246    }
2247
2248    /// Returns the `EuvDataTable` filter string signal on `/lab`.
2249    ///
2250    /// # Arguments
2251    ///
2252    /// - `&Self` - Reactive showcase state reference.
2253    ///
2254    /// # Returns
2255    ///
2256    /// - `Signal<String>` - Data table filter signal handle.
2257    #[must_use]
2258    pub fn get_lab_table_filter(&self) -> Signal<String> {
2259        self.lab_group().get_lab_table_filter()
2260    }
2261
2262    /// Returns the `EuvDataTable` ascending sort flag signal on `/lab`.
2263    ///
2264    /// # Arguments
2265    ///
2266    /// - `&Self` - Reactive showcase state reference.
2267    ///
2268    /// # Returns
2269    ///
2270    /// - `Signal<bool>` - Data table sort flag signal handle.
2271    #[must_use]
2272    pub fn get_lab_table_sort_asc(&self) -> Signal<bool> {
2273        self.lab_group().get_lab_table_sort_asc()
2274    }
2275
2276    /// Returns the `EuvDataTable` selected row index signal on `/lab`.
2277    ///
2278    /// # Arguments
2279    ///
2280    /// - `&Self` - Reactive showcase state reference.
2281    ///
2282    /// # Returns
2283    ///
2284    /// - `Signal<Option<usize>>` - Data table selected row signal handle.
2285    #[must_use]
2286    pub fn get_lab_table_selected(&self) -> Signal<Option<usize>> {
2287        self.lab_group().get_lab_table_selected()
2288    }
2289
2290    /// Returns the `EuvDatePicker` selected day signal on `/lab`.
2291    ///
2292    /// # Arguments
2293    ///
2294    /// - `&Self` - Reactive showcase state reference.
2295    ///
2296    /// # Returns
2297    ///
2298    /// - `Signal<u32>` - Date picker day signal handle.
2299    #[must_use]
2300    pub fn get_lab_date_day(&self) -> Signal<u32> {
2301        self.lab_group().get_lab_date_day()
2302    }
2303
2304    /// Returns the `EuvDatePicker` open flag signal on `/lab`.
2305    ///
2306    /// # Arguments
2307    ///
2308    /// - `&Self` - Reactive showcase state reference.
2309    ///
2310    /// # Returns
2311    ///
2312    /// - `Signal<bool>` - Date picker open signal handle.
2313    #[must_use]
2314    pub fn get_lab_date_open(&self) -> Signal<bool> {
2315        self.lab_group().get_lab_date_open()
2316    }
2317
2318    /// Returns the `EuvInputGroup` domain input value signal on `/lab`.
2319    ///
2320    /// # Arguments
2321    ///
2322    /// - `&Self` - Reactive showcase state reference.
2323    ///
2324    /// # Returns
2325    ///
2326    /// - `Signal<String>` - Input group value signal handle.
2327    #[must_use]
2328    pub fn get_lab_input_group_val(&self) -> Signal<String> {
2329        self.lab_group().get_lab_input_group_val()
2330    }
2331
2332    /// Returns the `EuvNativeSelect` selected index signal on `/lab`.
2333    ///
2334    /// # Arguments
2335    ///
2336    /// - `&Self` - Reactive showcase state reference.
2337    ///
2338    /// # Returns
2339    ///
2340    /// - `Signal<usize>` - Native select index signal handle.
2341    #[must_use]
2342    pub fn get_lab_native_select_idx(&self) -> Signal<usize> {
2343        self.lab_group().get_lab_native_select_idx()
2344    }
2345
2346    /// Returns the `EuvNavigationMenu` active dropdown index signal on `/lab`.
2347    ///
2348    /// # Arguments
2349    ///
2350    /// - `&Self` - Reactive showcase state reference.
2351    ///
2352    /// # Returns
2353    ///
2354    /// - `Signal<Option<usize>>` - Navigation menu active index signal handle.
2355    #[must_use]
2356    pub fn get_lab_nav_menu_active(&self) -> Signal<Option<usize>> {
2357        self.lab_group().get_lab_nav_menu_active()
2358    }
2359
2360    /// Returns the `EuvResizable` split ratio signal on `/lab`.
2361    ///
2362    /// # Arguments
2363    ///
2364    /// - `&Self` - Reactive showcase state reference.
2365    ///
2366    /// # Returns
2367    ///
2368    /// - `Signal<f32>` - Split ratio signal handle.
2369    #[must_use]
2370    pub fn get_lab_split_ratio(&self) -> Signal<f32> {
2371        self.lab_group().get_lab_split_ratio()
2372    }
2373
2374    /// Returns the nested scroll-chaining block toggle signal on `/lab`.
2375    ///
2376    /// # Arguments
2377    ///
2378    /// - `&Self` - Reactive showcase state reference.
2379    ///
2380    /// # Returns
2381    ///
2382    /// - `Signal<bool>` - Scroll chain toggle signal handle.
2383    #[must_use]
2384    pub fn get_lab_block_scroll_chain(&self) -> Signal<bool> {
2385        self.lab_group().get_lab_block_scroll_chain()
2386    }
2387
2388    /// Returns the click event bubbling stop toggle signal on `/lab`.
2389    ///
2390    /// # Arguments
2391    ///
2392    /// - `&Self` - Reactive showcase state reference.
2393    ///
2394    /// # Returns
2395    ///
2396    /// - `Signal<bool>` - Click bubble toggle signal handle.
2397    #[must_use]
2398    pub fn get_lab_stop_click_bubble(&self) -> Signal<bool> {
2399        self.lab_group().get_lab_stop_click_bubble()
2400    }
2401
2402    /// Returns the outer parent card click counter signal on `/lab`.
2403    ///
2404    /// # Arguments
2405    ///
2406    /// - `&Self` - Reactive showcase state reference.
2407    ///
2408    /// # Returns
2409    ///
2410    /// - `Signal<u32>` - Parent click counter signal handle.
2411    #[must_use]
2412    pub fn get_lab_parent_clicks(&self) -> Signal<u32> {
2413        self.lab_group().get_lab_parent_clicks()
2414    }
2415
2416    /// Returns the inner child button click counter signal on `/lab`.
2417    ///
2418    /// # Arguments
2419    ///
2420    /// - `&Self` - Reactive showcase state reference.
2421    ///
2422    /// # Returns
2423    ///
2424    /// - `Signal<u32>` - Child click counter signal handle.
2425    #[must_use]
2426    pub fn get_lab_child_clicks(&self) -> Signal<u32> {
2427        self.lab_group().get_lab_child_clicks()
2428    }
2429
2430    /// Returns the resize state-preservation counter signal on `/lab`.
2431    ///
2432    /// # Arguments
2433    ///
2434    /// - `&Self` - Reactive showcase state reference.
2435    ///
2436    /// # Returns
2437    ///
2438    /// - `Signal<u32>` - Resize preserve counter signal handle.
2439    #[must_use]
2440    pub fn get_lab_resize_preserve_count(&self) -> Signal<u32> {
2441        self.lab_group().get_lab_resize_preserve_count()
2442    }
2443
2444    /// Returns the RTL direction mode toggle signal on `/lab`.
2445    ///
2446    /// # Arguments
2447    ///
2448    /// - `&Self` - Reactive showcase state reference.
2449    ///
2450    /// # Returns
2451    ///
2452    /// - `Signal<bool>` - RTL mode signal handle.
2453    #[must_use]
2454    pub fn get_lab_rtl_mode(&self) -> Signal<bool> {
2455        self.lab_group().get_lab_rtl_mode()
2456    }
2457
2458    /// Returns the animated GIF playback signal on `/media`.
2459    ///
2460    /// # Arguments
2461    ///
2462    /// - `&Self` - Reactive showcase state reference.
2463    ///
2464    /// # Returns
2465    ///
2466    /// - `Signal<GifAnimation>` - GIF animation signal handle.
2467    #[must_use]
2468    pub fn get_media_gif(&self) -> Signal<GifAnimation> {
2469        self.media_group().get_media_gif()
2470    }
2471
2472    /// Returns the LIVE Photo asset signal on `/media`.
2473    ///
2474    /// # Arguments
2475    ///
2476    /// - `&Self` - Reactive showcase state reference.
2477    ///
2478    /// # Returns
2479    ///
2480    /// - `Signal<LivePhotoAsset>` - LIVE Photo signal handle.
2481    #[must_use]
2482    pub fn get_media_live(&self) -> Signal<LivePhotoAsset> {
2483        self.media_group().get_media_live()
2484    }
2485
2486    /// Returns the cross-platform video track signal on `/media`.
2487    ///
2488    /// # Arguments
2489    ///
2490    /// - `&Self` - Reactive showcase state reference.
2491    ///
2492    /// # Returns
2493    ///
2494    /// - `Signal<VideoTrack>` - Video track signal handle.
2495    #[must_use]
2496    pub fn get_media_video(&self) -> Signal<VideoTrack> {
2497        self.media_group().get_media_video()
2498    }
2499
2500    /// Returns the WAV audio waveform track signal on `/media`.
2501    ///
2502    /// # Arguments
2503    ///
2504    /// - `&Self` - Reactive showcase state reference.
2505    ///
2506    /// # Returns
2507    ///
2508    /// - `Signal<AudioTrack>` - Audio track signal handle.
2509    #[must_use]
2510    pub fn get_media_audio(&self) -> Signal<AudioTrack> {
2511        self.media_group().get_media_audio()
2512    }
2513
2514    /// Returns the multi-page PDF document signal on `/media`.
2515    ///
2516    /// # Arguments
2517    ///
2518    /// - `&Self` - Reactive showcase state reference.
2519    ///
2520    /// # Returns
2521    ///
2522    /// - `Signal<PdfDocument>` - PDF document signal handle.
2523    #[must_use]
2524    pub fn get_media_pdf(&self) -> Signal<PdfDocument> {
2525        self.media_group().get_media_pdf()
2526    }
2527
2528    /// Returns the Media Studio HTML link click log signal.
2529    ///
2530    /// # Arguments
2531    ///
2532    /// - `&Self` - Reactive showcase state reference.
2533    ///
2534    /// # Returns
2535    ///
2536    /// - `Signal<String>` - Media HTML link log signal handle.
2537    #[must_use]
2538    pub fn get_media_html_link_log(&self) -> Signal<String> {
2539        self.media_group().get_media_html_link_log()
2540    }
2541
2542    /// Returns the Media Studio background-decode loading state signal.
2543    ///
2544    /// # Arguments
2545    ///
2546    /// - `&Self` - Reactive showcase state reference.
2547    ///
2548    /// # Returns
2549    ///
2550    /// - `Signal<bool>` - Media loading state signal handle.
2551    #[must_use]
2552    pub fn get_media_loading(&self) -> Signal<bool> {
2553        self.media_group().get_media_loading()
2554    }
2555
2556    /// Returns the Markdown code block copy telemetry signal.
2557    ///
2558    /// # Arguments
2559    ///
2560    /// - `&Self` - Reactive showcase state reference.
2561    ///
2562    /// # Returns
2563    ///
2564    /// - `Signal<String>` - Markdown copy log signal handle.
2565    #[must_use]
2566    pub fn get_markdown_copy_log(&self) -> Signal<String> {
2567        self.markdown_group().get_markdown_copy_log()
2568    }
2569
2570    /// Returns the Markdown hyperlink click telemetry signal.
2571    ///
2572    /// # Arguments
2573    ///
2574    /// - `&Self` - Reactive showcase state reference.
2575    ///
2576    /// # Returns
2577    ///
2578    /// - `Signal<String>` - Markdown link log signal handle.
2579    #[must_use]
2580    pub fn get_markdown_link_log(&self) -> Signal<String> {
2581        self.markdown_group().get_markdown_link_log()
2582    }
2583
2584    /// Returns the Markdown GFM task toggle counter signal.
2585    ///
2586    /// # Arguments
2587    ///
2588    /// - `&Self` - Reactive showcase state reference.
2589    ///
2590    /// # Returns
2591    ///
2592    /// - `Signal<u32>` - Markdown tasks toggled signal handle.
2593    #[must_use]
2594    pub fn get_markdown_tasks_toggled(&self) -> Signal<u32> {
2595        self.markdown_group().get_markdown_tasks_toggled()
2596    }
2597
2598    /// Returns the Markdown code example language tab index signal.
2599    ///
2600    /// # Arguments
2601    ///
2602    /// - `&Self` - Reactive showcase state reference.
2603    ///
2604    /// # Returns
2605    ///
2606    /// - `Signal<usize>` - Markdown language tab signal handle.
2607    #[must_use]
2608    pub fn get_markdown_lang_tab(&self) -> Signal<usize> {
2609        self.markdown_group().get_markdown_lang_tab()
2610    }
2611
2612    /// Returns the Markdown selectable text toggle signal.
2613    ///
2614    /// # Arguments
2615    ///
2616    /// - `&Self` - Reactive showcase state reference.
2617    ///
2618    /// # Returns
2619    ///
2620    /// - `Signal<bool>` - Markdown selectable signal handle.
2621    #[must_use]
2622    pub fn get_markdown_selectable(&self) -> Signal<bool> {
2623        self.markdown_group().get_markdown_selectable()
2624    }
2625
2626    /// Returns the Stress Lab benchmark results list signal.
2627    ///
2628    /// # Arguments
2629    ///
2630    /// - `&Self` - Reactive showcase state reference.
2631    ///
2632    /// # Returns
2633    ///
2634    /// - `Signal<Vec<StressCaseResult>>` - Stress results signal handle.
2635    #[must_use]
2636    pub fn get_stress_results(&self) -> Signal<Vec<StressCaseResult>> {
2637        self.stress_group().get_stress_results()
2638    }
2639
2640    /// Returns the Stress Lab summary readout signal.
2641    ///
2642    /// # Arguments
2643    ///
2644    /// - `&Self` - Reactive showcase state reference.
2645    ///
2646    /// # Returns
2647    ///
2648    /// - `Signal<String>` - Stress summary signal handle.
2649    #[must_use]
2650    pub fn get_stress_summary(&self) -> Signal<String> {
2651        self.stress_group().get_stress_summary()
2652    }
2653
2654    /// Returns the ECharts Studio category filter index signal.
2655    ///
2656    /// # Arguments
2657    ///
2658    /// - `&Self` - Reactive showcase state reference.
2659    ///
2660    /// # Returns
2661    ///
2662    /// - `Signal<usize>` - Charts category index signal handle.
2663    #[must_use]
2664    pub fn get_charts_category_idx(&self) -> Signal<usize> {
2665        self.charts_group().get_charts_category_idx()
2666    }
2667
2668    /// Returns the ECharts Studio live interaction readout signal.
2669    ///
2670    /// # Arguments
2671    ///
2672    /// - `&Self` - Reactive showcase state reference.
2673    ///
2674    /// # Returns
2675    ///
2676    /// - `Signal<String>` - Charts event log signal handle.
2677    #[must_use]
2678    pub fn get_charts_event_log(&self) -> Signal<String> {
2679        self.charts_group().get_charts_event_log()
2680    }
2681
2682    /// Lazily hydrates Media Studio sample assets on first `/media` visit, using a background worker thread on interactive native apps.
2683    ///
2684    /// # Arguments
2685    ///
2686    /// - `&Self` - Reactive showcase state reference.
2687    pub fn ensure_media_loaded(&self) {
2688        if self.get_media_loaded().replace(true) {
2689            return;
2690        }
2691        if self.get_bg_workers_enabled().get() {
2692            let group: MediaSignals = self.media_group();
2693            let _: bool = group.get_media_loading().set_if_changed(true);
2694            let task: BackgroundTask<MediaSampleBundle> =
2695                BackgroundTask::spawn(Self::build_media_sample_bundle);
2696            let _: bool = group.get_media_bg_task().set(Some(task));
2697            return;
2698        }
2699        let bundle: MediaSampleBundle = Self::build_media_sample_bundle();
2700        self.commit_media_sample_bundle(bundle);
2701    }
2702
2703    /// Builds the complete Media Studio sample codec bundle (GIF89a, LIVE Photo, MP4, WAV, PDF).
2704    ///
2705    /// # Returns
2706    ///
2707    /// - `MediaSampleBundle` - Decoded sample media assets ready for signal commit.
2708    fn build_media_sample_bundle() -> MediaSampleBundle {
2709        MediaSampleBundle {
2710            gif: Self::build_decoded_sample_gif(),
2711            live: LivePhotoAsset::sample_live_photo(),
2712            video: Self::build_decoded_sample_mp4(),
2713            audio: AudioTrack::sample_synth_wav(),
2714            pdf: PdfDocument::sample_pdf(),
2715        }
2716    }
2717
2718    /// Commits a decoded `MediaSampleBundle` into the reactive Media Studio signals on the UI thread.
2719    ///
2720    /// # Arguments
2721    ///
2722    /// - `&Self` - Reactive showcase state reference.
2723    /// - `MediaSampleBundle` - Decoded sample media assets.
2724    fn commit_media_sample_bundle(&self, bundle: MediaSampleBundle) {
2725        let group: MediaSignals = self.media_group();
2726        let MediaSampleBundle {
2727            gif,
2728            live,
2729            video,
2730            audio,
2731            pdf,
2732        } = bundle;
2733        let _: bool = group.get_media_gif().set(gif);
2734        let _: bool = group.get_media_live().set(live);
2735        let _: bool = group.get_media_video().set(video);
2736        let _: bool = group.get_media_audio().set(audio);
2737        let _: bool = group.get_media_pdf().set(pdf);
2738        let _: bool = group.get_media_loading().set_if_changed(false);
2739    }
2740
2741    /// Encodes and decodes a real LZW-compressed GIF89a sample stream through `GifEncoder` and `MediaCodecRegistry::decode_gif`.
2742    ///
2743    /// # Returns
2744    ///
2745    /// - `GifAnimation` - Decoded animated GIF ready for Media Studio playback.
2746    fn build_decoded_sample_gif() -> GifAnimation {
2747        let width: u16 = 220;
2748        let height: u16 = 124;
2749        let palette: [[u8; 3]; 8] = [
2750            [17, 24, 39],
2751            [30, 41, 59],
2752            [56, 189, 248],
2753            [168, 85, 247],
2754            [244, 63, 94],
2755            [52, 211, 153],
2756            [226, 232, 240],
2757            [15, 23, 42],
2758        ];
2759        let pixel_count: usize = (width as usize) * (height as usize);
2760        let mut inputs: Vec<GifEncodeFrameInput> = Vec::with_capacity(8);
2761        for frame_idx in 0..8usize {
2762            let accent_idx: u8 = (2 + (frame_idx % 4)) as u8;
2763            let bar_x: usize = (frame_idx * 24) % (width as usize);
2764            let mut indices: Vec<u8> = vec![0u8; pixel_count];
2765            for y in 0..(height as usize) {
2766                let row_off: usize = y * (width as usize);
2767                let is_band: bool = (42..82).contains(&y);
2768                for x in 0..(width as usize) {
2769                    let dist: usize = x.abs_diff(bar_x);
2770                    let color_idx: u8 = if is_band && dist < 18 {
2771                        accent_idx
2772                    } else if (x / 16 + y / 16 + frame_idx) % 2 == 0 {
2773                        1
2774                    } else {
2775                        7
2776                    };
2777                    indices[row_off + x] = color_idx;
2778                }
2779            }
2780            let mut frame: GifEncodeFrameInput = GifEncodeFrameInput::default();
2781            frame
2782                .set_width(width)
2783                .set_height(height)
2784                .set_disposal(GifDisposalMethod::Keep)
2785                .set_delay_cs(12)
2786                .set_indices(indices);
2787            inputs.push(frame);
2788        }
2789        let encoded: Vec<u8> = GifEncoder::encode(width, height, &palette, Some(0), &inputs);
2790        MediaCodecRegistry::decode_gif(&encoded, MEDIA_GIF_TITLE)
2791            .unwrap_or_else(|_: String| GifAnimation::sample_neon_gif())
2792    }
2793
2794    /// Builds and decodes a real ISOBMFF MP4 stream through `Mp4ContainerBuilder` and `VideoTrack::from_mp4_bytes`.
2795    ///
2796    /// # Returns
2797    ///
2798    /// - `VideoTrack` - Decoded HDR MP4 video track ready for Media Studio playback.
2799    fn build_decoded_sample_mp4() -> VideoTrack {
2800        let width: u32 = 280;
2801        let height: u32 = 158;
2802        let accents: [Color; 4] = [
2803            Color::hex(0x22D3EE),
2804            Color::hex(0x6366F1),
2805            Color::hex(0xEC4899),
2806            Color::hex(0x10B981),
2807        ];
2808        let mut samples: Vec<Mp4BuilderSample> = Vec::with_capacity(12);
2809        for idx in 0..12usize {
2810            let img: ImageBuffer = MediaCodecRegistry::synthesize_frame(
2811                width,
2812                height,
2813                Color::hex(0x090D16),
2814                accents[idx % accents.len()],
2815                idx + 1,
2816            );
2817            let payload: Vec<u8> =
2818                SoftwareVideoDecoder::encode_intra_rgba_packet(width, height, img.get_pixels());
2819            let mut sample: Mp4BuilderSample = Mp4BuilderSample::default();
2820            sample
2821                .set_duration_ticks(1_000)
2822                .set_composition_offset_ticks(0)
2823                .set_is_keyframe(idx % 4 == 0)
2824                .set_payload(payload);
2825            samples.push(sample);
2826        }
2827        let mp4_bytes: Vec<u8> = Mp4ContainerBuilder::build_video_mp4(
2828            width,
2829            height,
2830            1_000,
2831            VideoCodec::H264,
2832            VideoColorInfo::hdr10_bt2020_pq(1000, 400),
2833            &samples,
2834        );
2835        match VideoTrack::from_mp4_bytes(mp4_bytes, MEDIA_VIDEO_TITLE) {
2836            Ok(mut track) => {
2837                let captions: Vec<String> = MEDIA_VIDEO_CAPTIONS
2838                    .iter()
2839                    .map(|line: &&str| (*line).to_string())
2840                    .collect();
2841                track.set_captions(captions);
2842                track
2843            }
2844            Err(_) => VideoTrack::sample_hdr_video(),
2845        }
2846    }
2847
2848    /// Lazily populates the in-memory `.wasm` OTA registry on first `/dynamic` visit, offloading payload assembly to a background worker on interactive native apps.
2849    ///
2850    /// # Arguments
2851    ///
2852    /// - `&Self` - Reactive showcase state reference.
2853    pub fn ensure_wasm_registry_loaded(&self) {
2854        if self.get_wasm_registry_loaded().replace(true) {
2855            return;
2856        }
2857        if self.get_bg_workers_enabled().get() {
2858            let group: DynamicSignals = self.dynamic_group();
2859            let _: bool = group
2860                .get_wasm_fault_status()
2861                .set_if_changed(STATUS_WASM_LOADING.to_string());
2862            let task: BackgroundTask<WasmSampleBundle> =
2863                BackgroundTask::spawn(Self::build_wasm_sample_bundle);
2864            let _: bool = group.get_wasm_bg_task().set(Some(task));
2865            return;
2866        }
2867        Self::populate_wasm_registry(self.get_wasm_registry());
2868    }
2869
2870    /// Commits any pending in-flight background WASM registry build synchronously so interactive clicks never race the worker.
2871    ///
2872    /// # Arguments
2873    ///
2874    /// - `&Self` - Reactive showcase state reference.
2875    pub fn ensure_wasm_registry_ready_now(&self) {
2876        self.ensure_wasm_registry_loaded();
2877        if let Some(group) = self.get_dynamic_signals().get()
2878            && let Some(task) = group.get_wasm_bg_task().get_untracked()
2879            && let Some(bundle) = task.take_blocking()
2880        {
2881            Self::commit_wasm_sample_bundle(self.get_wasm_registry(), bundle);
2882            let _: bool = group.get_wasm_bg_task().set(None);
2883            let _: bool = group
2884                .get_wasm_fault_status()
2885                .set_if_changed(DEFAULT_WASM_STATUS.to_string());
2886        }
2887    }
2888
2889    /// Polls any active background worker tasks (`/media`, `/dynamic`) and commits finished payloads atomically onto the UI thread.
2890    ///
2891    /// # Arguments
2892    ///
2893    /// - `&Self` - Reactive showcase state reference.
2894    ///
2895    /// # Returns
2896    ///
2897    /// - `bool` - `true` if any background payload committed on this frame.
2898    pub fn poll_async_loads(&self) -> bool {
2899        let mut committed: bool = false;
2900        if let Some(media) = self.get_media_signals().get()
2901            && let Some(task) = media.get_media_bg_task().get_untracked()
2902            && let Some(bundle) = task.try_take()
2903        {
2904            let _: bool = media.get_media_bg_task().set(None);
2905            self.commit_media_sample_bundle(bundle);
2906            committed = true;
2907        }
2908        if let Some(dyn_group) = self.get_dynamic_signals().get()
2909            && let Some(task) = dyn_group.get_wasm_bg_task().get_untracked()
2910            && let Some(bundle) = task.try_take()
2911        {
2912            let _: bool = dyn_group.get_wasm_bg_task().set(None);
2913            Self::commit_wasm_sample_bundle(self.get_wasm_registry(), bundle);
2914            let _: bool = dyn_group
2915                .get_wasm_fault_status()
2916                .set_if_changed(DEFAULT_WASM_STATUS.to_string());
2917            committed = true;
2918        }
2919        committed
2920    }
2921
2922    /// Lazily initializes the Stress Lab workload descriptors on first `/stress` visit.
2923    ///
2924    /// # Arguments
2925    ///
2926    /// - `&Self` - Reactive showcase state reference.
2927    pub fn ensure_stress_loaded(&self) {
2928        if self.get_stress_loaded().replace(true) {
2929            return;
2930        }
2931        let _: bool = self.get_stress_results().set(default_stress_results());
2932    }
2933
2934    /// Lazily marks ECharts Studio hydrated on first `/charts` visit so Frame 1 incurs zero chart option allocations.
2935    ///
2936    /// # Arguments
2937    ///
2938    /// - `&Self` - Reactive showcase state reference.
2939    pub fn ensure_charts_loaded(&self) {
2940        let _: bool = self.get_charts_loaded().replace(true);
2941    }
2942
2943    /// Assembles all genuine executable partial, global, and fault-case `.wasm` binary entries into a `Send` bundle.
2944    ///
2945    /// # Returns
2946    ///
2947    /// - `WasmSampleBundle` - Pre-built `.wasm` registry entries.
2948    fn build_wasm_sample_bundle() -> WasmSampleBundle {
2949        let p_v1: Vec<u8> = build_partial_widget_wasm(TITLE_WASM_PARTIAL_V1, 1, 0x2563EB);
2950        let p_v2: Vec<u8> = build_partial_widget_wasm(WASM_TITLE_PARTIAL_V2, 2, 0x7C3AED);
2951        let g_v1: Vec<u8> = build_global_app_wasm(WASM_TITLE_GLOBAL_V1, 1);
2952        let g_v2: Vec<u8> = build_global_app_wasm(WASM_TITLE_GLOBAL_V2, 2);
2953        let entries: Vec<WasmRegistryEntry> = vec![
2954            WasmRegistryEntry {
2955                url: URL_WASM_PARTIAL_V1.to_string(),
2956                bytes: p_v1.clone(),
2957                etag: WASM_ETAG_P1.to_string(),
2958                fault: WasmFaultKind::None,
2959            },
2960            WasmRegistryEntry {
2961                url: URL_WASM_PARTIAL_V2.to_string(),
2962                bytes: p_v2,
2963                etag: WASM_ETAG_P2.to_string(),
2964                fault: WasmFaultKind::None,
2965            },
2966            WasmRegistryEntry {
2967                url: URL_WASM_GLOBAL_V1.to_string(),
2968                bytes: g_v1,
2969                etag: WASM_ETAG_G1.to_string(),
2970                fault: WasmFaultKind::None,
2971            },
2972            WasmRegistryEntry {
2973                url: URL_WASM_GLOBAL_V2.to_string(),
2974                bytes: g_v2,
2975                etag: WASM_ETAG_G2.to_string(),
2976                fault: WasmFaultKind::None,
2977            },
2978            WasmRegistryEntry {
2979                url: URL_WASM_TIMEOUT_RETRY.to_string(),
2980                bytes: p_v1.clone(),
2981                etag: WASM_ETAG_RETRY.to_string(),
2982                fault: WasmFaultKind::TimeoutOnceThenSucceed,
2983            },
2984            WasmRegistryEntry {
2985                url: URL_WASM_HTTP_500.to_string(),
2986                bytes: p_v1.clone(),
2987                etag: WASM_ETAG_500.to_string(),
2988                fault: WasmFaultKind::Http500,
2989            },
2990            WasmRegistryEntry {
2991                url: URL_WASM_CORRUPTED.to_string(),
2992                bytes: build_faulty_wasm(WasmFaultKind::CorruptedMagic),
2993                etag: WASM_ETAG_CORRUPT.to_string(),
2994                fault: WasmFaultKind::None,
2995            },
2996            WasmRegistryEntry {
2997                url: URL_WASM_TAMPERED.to_string(),
2998                bytes: p_v1,
2999                etag: WASM_ETAG_TAMPER.to_string(),
3000                fault: WasmFaultKind::TamperedChecksum,
3001            },
3002            WasmRegistryEntry {
3003                url: URL_WASM_BAD_ABI.to_string(),
3004                bytes: build_faulty_wasm(WasmFaultKind::AbiMismatch),
3005                etag: WASM_ETAG_ABI.to_string(),
3006                fault: WasmFaultKind::None,
3007            },
3008            WasmRegistryEntry {
3009                url: URL_WASM_MISSING_EXPORT.to_string(),
3010                bytes: build_faulty_wasm(WasmFaultKind::MissingExport),
3011                etag: WASM_ETAG_NOEXP.to_string(),
3012                fault: WasmFaultKind::None,
3013            },
3014            WasmRegistryEntry {
3015                url: URL_WASM_FUEL_BOMB.to_string(),
3016                bytes: build_faulty_wasm(WasmFaultKind::InfiniteLoopOutOfFuel),
3017                etag: WASM_ETAG_FUEL.to_string(),
3018                fault: WasmFaultKind::None,
3019            },
3020            WasmRegistryEntry {
3021                url: URL_WASM_TRAP.to_string(),
3022                bytes: build_faulty_wasm(WasmFaultKind::ExecutionTrap),
3023                etag: WASM_ETAG_TRAP.to_string(),
3024                fault: WasmFaultKind::None,
3025            },
3026            WasmRegistryEntry {
3027                url: URL_WASM_OVERSIZED.to_string(),
3028                bytes: build_faulty_wasm(WasmFaultKind::OversizedBinary),
3029                etag: WASM_ETAG_BIG.to_string(),
3030                fault: WasmFaultKind::None,
3031            },
3032        ];
3033        WasmSampleBundle { entries }
3034    }
3035
3036    /// Commits a pre-built `WasmSampleBundle` into `registry`.
3037    ///
3038    /// # Arguments
3039    ///
3040    /// - `&RegistryWasmFetcher` - Target CDN registry fetcher.
3041    /// - `WasmSampleBundle` - Pre-built registry entries.
3042    fn commit_wasm_sample_bundle(registry: &RegistryWasmFetcher, bundle: WasmSampleBundle) {
3043        let WasmSampleBundle { entries } = bundle;
3044        for entry in entries.into_iter() {
3045            let WasmRegistryEntry {
3046                url,
3047                bytes,
3048                etag,
3049                fault,
3050            } = entry;
3051            registry.register(url, bytes, etag, fault);
3052        }
3053    }
3054
3055    /// Registers genuine executable partial, global, and fault-case `.wasm` binaries into `registry`.
3056    ///
3057    /// # Arguments
3058    ///
3059    /// - `&RegistryWasmFetcher` - Target CDN registry fetcher.
3060    pub fn populate_wasm_registry(registry: &RegistryWasmFetcher) {
3061        let bundle: WasmSampleBundle = Self::build_wasm_sample_bundle();
3062        Self::commit_wasm_sample_bundle(registry, bundle);
3063    }
3064
3065    /// Formats a concise single-line top navbar title for `route`.
3066    ///
3067    /// # Arguments
3068    ///
3069    /// - `&str` - Active route path.
3070    ///
3071    /// # Returns
3072    ///
3073    /// - `String` - Concise 1-2 word page title for the top navigation bar.
3074    #[must_use]
3075    pub fn breadcrumb_for_route(route: &str) -> String {
3076        SHOWCASE_ROUTES
3077            .iter()
3078            .find(|spec: &&ShowcaseRouteSpec| spec.get_path() == route)
3079            .map(|spec: &ShowcaseRouteSpec| spec.get_title())
3080            .unwrap_or(route)
3081            .to_string()
3082    }
3083
3084    /// Registers dynamic OTA and WASM event handlers on `self.dynamic_hub` without eagerly allocating `/dynamic` signals.
3085    ///
3086    /// # Arguments
3087    ///
3088    /// - `&Self` - Reactive showcase state reference.
3089    fn wire_dynamic_hub_actions(&self) {
3090        let route_sig: Signal<String> = self.get_route();
3091        let dyn_cell: Rc<Cell<Option<DynamicSignals>>> = self.get_dynamic_signals().clone();
3092        let owner_scope: Scope = self.get_state_scope();
3093        let mgr_act: WasmDynamicManager = self.get_wasm_manager().clone();
3094        self.get_dynamic_hub()
3095            .on_action(move |ev: &DynamicActionEvent| {
3096                let dyn_group: DynamicSignals =
3097                    DynamicSignals::get_or_init(dyn_cell.as_ref(), owner_scope);
3098                let action_log: Signal<String> = dyn_group.get_dynamic_action_log();
3099                let wasm_status: Signal<String> = dyn_group.get_wasm_fault_status();
3100                let summary: String = format!(
3101                    "{} from {} ({})",
3102                    ev.get_action(),
3103                    ev.get_source_id(),
3104                    ev.get_payload()
3105                );
3106                let _: bool = action_log.set_if_changed(summary);
3107                if let Some(target_route) = ev.get_action().strip_prefix("navigate:") {
3108                    let _: bool = route_sig.set_if_changed(target_route.to_string());
3109                } else if ev.get_action().as_str() == "return_dynamic" {
3110                    let _: bool = route_sig.set_if_changed(ROUTE_DYNAMIC.to_string());
3111                } else if ev.get_action().as_str() == "wasm_interact" {
3112                    let scope: WasmDynamicScope = WasmDynamicScope::Partial {
3113                        slot_id: SLOT_WASM_WIDGET.to_string(),
3114                    };
3115                    match mgr_act.dispatch_wasm_event(&scope, 1) {
3116                        Ok(next_st) => {
3117                            let _: bool = wasm_status.set(format!(
3118                                "WASM euv_on_event executed inside sandbox -> next_state={next_st} (native UI re-rendered)"
3119                            ));
3120                        }
3121                        Err(err) => {
3122                            let _: bool = wasm_status.set(format!("WASM event error: {err}"));
3123                        }
3124                    }
3125                } else if ev.get_action().as_str() == "global_wasm_action" {
3126                    match mgr_act.dispatch_wasm_event(&WasmDynamicScope::Global, 1) {
3127                        Ok(next_st) => {
3128                            let _: bool = wasm_status.set(format!(
3129                                "Global WASM euv_on_event executed live -> state={next_st} (full shell re-rendered)"
3130                            ));
3131                        }
3132                        Err(err) => {
3133                            let _: bool =
3134                                wasm_status.set(format!("Global WASM event error: {err}"));
3135                        }
3136                    }
3137                } else if ev.get_action().as_str() == "global_wasm_rollback" {
3138                    match mgr_act.rollback_global("user rollback") {
3139                        Ok(ver) => {
3140                            let _: bool = wasm_status.set(format!(
3141                                "Rolled back Global WASM shell to v{ver} (0 = native shell)"
3142                            ));
3143                        }
3144                        Err(_) => {
3145                            mgr_act.restore_native_global();
3146                            let _: bool =
3147                                wasm_status.set(STATUS_RESTORED_NATIVE_SHELL.to_string());
3148                        }
3149                    }
3150                } else if ev.get_action().as_str() == "global_wasm_restore" {
3151                    mgr_act.restore_native_global();
3152                    let _: bool = wasm_status.set(STATUS_RESTORED_NATIVE_SHELL.to_string());
3153                }
3154            });
3155    }
3156
3157    /// Rebinds `hub` onto this state and updates `wasm_manager` and router integration.
3158    ///
3159    /// # Arguments
3160    ///
3161    /// - `&Self` - Mutable showcase state.
3162    /// - `DynamicUpdateHub` - Shared dynamic update hub owned by `App`.
3163    pub fn attach_dynamic_hub(&mut self, hub: DynamicUpdateHub) {
3164        let wasm_mgr: WasmDynamicManager = WasmDynamicManager::new(
3165            hub.clone(),
3166            Rc::new(self.get_wasm_registry().clone()),
3167            WasmSandboxConfig::default(),
3168        );
3169        let Self {
3170            dynamic_hub,
3171            wasm_manager,
3172            router,
3173            ..
3174        } = self;
3175        let _: EuvRouter = router.clone().with_dynamic_hub(hub.clone());
3176        *dynamic_hub = hub;
3177        *wasm_manager = wasm_mgr;
3178        self.wire_dynamic_hub_actions();
3179    }
3180
3181    /// Builds `AiAppHooks` bridging route, theme, and 3D/2D game engine telemetry and controls to AI Schema v1 without eagerly allocating `/game3d` signals.
3182    ///
3183    /// # Arguments
3184    ///
3185    /// - `&Self` - Reactive showcase state reference.
3186    ///
3187    /// # Returns
3188    ///
3189    /// - `AiAppHooks` - Configured AI automation hooks bound to this state.
3190    #[cfg(any(debug_assertions, test))]
3191    #[must_use]
3192    pub fn build_ai_hooks(&self) -> AiAppHooks {
3193        let route_get: Signal<String> = self.get_route();
3194        let route_set: Signal<String> = self.get_route();
3195        let theme_get: UiThemeState = self.get_theme().clone();
3196        let theme_set: UiThemeState = self.get_theme().clone();
3197        let e3d_stats_cell: Rc<Cell<Option<Engine3dSignals>>> = self.get_engine3d_signals().clone();
3198        let e3d_ctrl_cell: Rc<Cell<Option<Engine3dSignals>>> = self.get_engine3d_signals().clone();
3199        let owner_scope: Scope = self.get_state_scope();
3200        AiAppHooks::new()
3201            .on_route(move || route_get.get_untracked())
3202            .on_scheme(move || theme_get.get_scheme().get_untracked().as_str().to_string())
3203            .on_game_stats(move || {
3204                let g: Engine3dSignals =
3205                    Engine3dSignals::get_or_init(e3d_stats_cell.as_ref(), owner_scope);
3206                let raw: String = format!(
3207                    "{{\"preset_idx\":{},\"rt_idx\":{},\"resolution_scale_pct\":{:.1},\"time_of_day\":{:.2},\"camera_mode\":{},\"import_status\":{:?}}}",
3208                    g.get_engine3d_preset_idx().get_untracked(),
3209                    g.get_engine3d_rt_idx().get_untracked(),
3210                    g.get_engine3d_res_scale().get_untracked(),
3211                    g.get_engine3d_time_of_day().get_untracked(),
3212                    g.get_engine3d_camera_mode().get_untracked(),
3213                    g.get_engine3d_import_status().get_untracked()
3214                );
3215                AiSchemaProtocol::parse_json_value(&raw)
3216            })
3217            .on_navigate(move |target: &str| {
3218                let _: bool = route_set.set_if_changed(target.to_string());
3219                Ok(())
3220            })
3221            .on_set_theme(move |scheme_opt: Option<&str>, mode_opt: Option<&str>| {
3222                if let Some(s_name) = scheme_opt {
3223                    let matched: Option<DesignScheme> = DesignScheme::all()
3224                        .into_iter()
3225                        .find(|ds: &DesignScheme| ds.as_str().eq_ignore_ascii_case(s_name));
3226                    match matched {
3227                        Some(ds) => theme_set.select_scheme(ds),
3228                        None => return Err(format!("Unknown design scheme: {s_name}")),
3229                    }
3230                }
3231                if let Some(m_name) = mode_opt {
3232                    let next_mode: ThemeMode = if m_name.eq_ignore_ascii_case("Dark") {
3233                        ThemeMode::Dark
3234                    } else if m_name.eq_ignore_ascii_case("Light") {
3235                        ThemeMode::Light
3236                    } else {
3237                        return Err(format!("Unknown theme mode: {m_name}"));
3238                    };
3239                    let _: bool = theme_set.get_mode().set_if_changed(next_mode);
3240                }
3241                Ok(())
3242            })
3243            .on_game_control(move |cmd: &str, payload: &Value| {
3244                let g: Engine3dSignals =
3245                    Engine3dSignals::get_or_init(e3d_ctrl_cell.as_ref(), owner_scope);
3246                let num_val: f64 = payload
3247                    .as_f64()
3248                    .or_else(|| payload.get("value").and_then(|v: &Value| v.as_f64()))
3249                    .unwrap_or(0.0);
3250                match cmd {
3251                    "camera_mode" => {
3252                        let next_cam: u8 = (num_val.round() as u8).min(3);
3253                        let _: bool = g.get_engine3d_camera_mode().set_if_changed(next_cam);
3254                        Ok(AiSchemaProtocol::parse_json_value(&format!(
3255                            "{{\"camera_mode\":{next_cam}}}"
3256                        )))
3257                    }
3258                    "preset" => {
3259                        let next_p: usize = (num_val.round() as usize).min(4);
3260                        let _: bool = g.get_engine3d_preset_idx().set_if_changed(next_p);
3261                        Ok(AiSchemaProtocol::parse_json_value(&format!(
3262                            "{{\"preset_idx\":{next_p}}}"
3263                        )))
3264                    }
3265                    "ray_tracing" => {
3266                        let next_rt: usize = (num_val.round() as usize).min(3);
3267                        let _: bool = g.get_engine3d_rt_idx().set_if_changed(next_rt);
3268                        Ok(AiSchemaProtocol::parse_json_value(&format!(
3269                            "{{\"rt_idx\":{next_rt}}}"
3270                        )))
3271                    }
3272                    "resolution_scale" => {
3273                        let next_s: f32 = (num_val as f32).clamp(40.0, 125.0);
3274                        let _: bool = g.get_engine3d_res_scale().set_if_changed(next_s);
3275                        Ok(AiSchemaProtocol::parse_json_value(&format!(
3276                            "{{\"resolution_scale_pct\":{next_s:.1}}}"
3277                        )))
3278                    }
3279                    "time_of_day" => {
3280                        let next_t: f32 = (num_val as f32).clamp(6.0, 23.0);
3281                        let _: bool = g.get_engine3d_time_of_day().set_if_changed(next_t);
3282                        Ok(AiSchemaProtocol::parse_json_value(&format!(
3283                            "{{\"time_of_day\":{next_t:.2}}}"
3284                        )))
3285                    }
3286                    "import_model" => {
3287                        let next_q: u64 = g
3288                            .get_engine3d_import_queue()
3289                            .get_untracked()
3290                            .saturating_add(1);
3291                        let _: bool = g.get_engine3d_import_queue().set_if_changed(next_q);
3292                        Ok(AiSchemaProtocol::parse_json_value(&format!(
3293                            "{{\"import_queue\":{next_q}}}"
3294                        )))
3295                    }
3296                    other => Err(format!("Unknown game control command: {other}")),
3297                }
3298            })
3299    }
3300
3301    /// Returns the categorized sidebar navigation items grouped in Linear/Vercel/shadcn hierarchy.
3302    ///
3303    /// # Returns
3304    ///
3305    /// - `Vec<EuvNavItem>` - Categorized list of showcase routes.
3306    #[must_use]
3307    pub fn nav_items() -> Vec<EuvNavItem> {
3308        SHOWCASE_ROUTES
3309            .iter()
3310            .map(|spec: &ShowcaseRouteSpec| {
3311                EuvNavItem::new(spec.get_path().to_string(), spec.get_label().to_string())
3312                    .section(spec.get_section())
3313            })
3314            .collect()
3315    }
3316
3317    /// Resolves the currently selected component-scoped demo `RenderMode` from `render_mode_index`.
3318    ///
3319    /// # Arguments
3320    ///
3321    /// - `&Self` - State reference.
3322    ///
3323    /// # Returns
3324    ///
3325    /// - `RenderMode` - Component-scoped demo render pipeline mode.
3326    #[must_use]
3327    pub fn selected_render_mode(&self) -> RenderMode {
3328        match self.get_render_mode_index().get_untracked() {
3329            1 => RenderMode::Software,
3330            2 => RenderMode::Hardware,
3331            3 => RenderMode::Hybrid,
3332            _ => RenderMode::Auto,
3333        }
3334    }
3335
3336    /// Resolves the currently selected component-scoped demo FPS cap from `demo_fps_cap_index`.
3337    ///
3338    /// # Arguments
3339    ///
3340    /// - `&Self` - State reference.
3341    ///
3342    /// # Returns
3343    ///
3344    /// - `Option<u32>` - Demo card FPS target (`None` = Native Uncapped).
3345    #[must_use]
3346    pub fn selected_demo_fps_cap(&self) -> Option<u32> {
3347        match self.get_demo_fps_cap_index().get_untracked() {
3348            1 => Some(30),
3349            2 => Some(60),
3350            3 => Some(120),
3351            4 => Some(144),
3352            5 => Some(240),
3353            6 => Some(360),
3354            _ => None,
3355        }
3356    }
3357
3358    /// Cycles to the next `DesignScheme` in `DesignScheme::all()`.
3359    ///
3360    /// # Arguments
3361    ///
3362    /// - `&Self` - State reference.
3363    pub fn next_scheme(&self) {
3364        let all: [DesignScheme; 17] = DesignScheme::all();
3365        let current: DesignScheme = self.get_theme().get_scheme().get_untracked();
3366        let pos: usize = all
3367            .iter()
3368            .position(|s: &DesignScheme| *s == current)
3369            .unwrap_or(0);
3370        let next: DesignScheme = all[(pos + 1) % all.len()];
3371        let _: bool = self.get_theme().get_scheme().set_if_changed(next);
3372    }
3373
3374    /// Toggles between light and dark theme modes.
3375    ///
3376    /// # Arguments
3377    ///
3378    /// - `&Self` - State reference.
3379    pub fn toggle_theme_mode(&self) {
3380        let cur: ThemeMode = self.get_theme().get_mode().get_untracked();
3381        let next: ThemeMode = match cur {
3382            ThemeMode::Light => ThemeMode::Dark,
3383            ThemeMode::Dark => ThemeMode::Light,
3384        };
3385        let _: bool = self.get_theme().get_mode().set_if_changed(next);
3386    }
3387
3388    /// Snapshots active running/playing state across all 15 showcase pages and freezes 2D/3D engines and media players for background.
3389    ///
3390    /// # Arguments
3391    ///
3392    /// - `&Self` - State reference.
3393    pub fn freeze_for_background(&self) {
3394        if self.get_bg_frozen().get_untracked() {
3395            return;
3396        }
3397        let game2d_running: bool = !self.get_game_host().is_paused();
3398        self.get_bg_snap_game2d_running().set(game2d_running);
3399        self.get_game_host().set_paused(true);
3400        let game3d_running: bool = !self.get_game3d_host().is_paused();
3401        self.get_bg_snap_game3d_running().set(game3d_running);
3402        self.get_game3d_host().set_paused(true);
3403        let water_running: bool = !self.get_water_host().is_paused();
3404        self.get_bg_snap_water_running().set(water_running);
3405        self.get_water_host().set_paused(true);
3406        if self.get_media_loaded().get() {
3407            let gif_playing: bool = self.get_media_gif().get_untracked().get_playing();
3408            self.get_bg_snap_gif_playing().set(gif_playing);
3409            if gif_playing {
3410                let _: bool = self.get_media_gif().update(|gif: &mut GifAnimation| {
3411                    gif.set_playing(false);
3412                });
3413            }
3414            let live_playing: bool = self.get_media_live().get_untracked().get_active_motion();
3415            self.get_bg_snap_live_playing().set(live_playing);
3416            if live_playing {
3417                let _: bool = self.get_media_live().update(|live: &mut LivePhotoAsset| {
3418                    live.set_motion_playing(false);
3419                });
3420            }
3421            let video_playing: bool =
3422                self.get_media_video().get_untracked().get_state() == PlaybackState::Playing;
3423            self.get_bg_snap_video_playing().set(video_playing);
3424            if video_playing {
3425                let _: bool = self.get_media_video().update(|video: &mut VideoTrack| {
3426                    video.set_state(PlaybackState::Paused);
3427                });
3428            }
3429            let audio_playing: bool =
3430                self.get_media_audio().get_untracked().get_state() == PlaybackState::Playing;
3431            self.get_bg_snap_audio_playing().set(audio_playing);
3432            if audio_playing {
3433                let _: bool = self.get_media_audio().update(|audio: &mut AudioTrack| {
3434                    audio.set_state(PlaybackState::Paused);
3435                });
3436            }
3437        }
3438        let _: bool = self.get_bg_frozen().set_if_changed(true);
3439        let _: bool = self
3440            .get_bg_freeze_count()
3441            .update(|count: &mut u32| *count = count.saturating_add(1));
3442    }
3443
3444    /// Restores the exact pre-background running/playing flags across all showcase game hosts and media players on foreground return.
3445    ///
3446    /// # Arguments
3447    ///
3448    /// - `&Self` - State reference.
3449    pub fn restore_from_foreground(&self) {
3450        if !self.get_bg_frozen().get_untracked() {
3451            return;
3452        }
3453        let active_route: String = self.get_route().get_untracked();
3454        if self.get_bg_snap_game2d_running().replace(false) && active_route == ROUTE_GAME {
3455            self.get_game_host().set_paused(false);
3456        }
3457        if self.get_bg_snap_game3d_running().replace(false) && active_route == ROUTE_GAME_3D {
3458            self.get_game3d_host().set_paused(false);
3459        }
3460        if self.get_bg_snap_water_running().replace(false) && active_route == ROUTE_WATER {
3461            self.get_water_host().set_paused(false);
3462        }
3463        if self.get_bg_snap_gif_playing().replace(false) {
3464            let _: bool = self.get_media_gif().update(|gif: &mut GifAnimation| {
3465                gif.set_playing(true);
3466            });
3467        }
3468        if self.get_bg_snap_live_playing().replace(false) {
3469            let _: bool = self.get_media_live().update(|live: &mut LivePhotoAsset| {
3470                live.set_motion_playing(true);
3471            });
3472        }
3473        if self.get_bg_snap_video_playing().replace(false) {
3474            let _: bool = self.get_media_video().update(|video: &mut VideoTrack| {
3475                video.set_state(PlaybackState::Playing);
3476            });
3477        }
3478        if self.get_bg_snap_audio_playing().replace(false) {
3479            let _: bool = self.get_media_audio().update(|audio: &mut AudioTrack| {
3480                audio.set_state(PlaybackState::Playing);
3481            });
3482        }
3483        let _: bool = self.get_bg_frozen().set_if_changed(false);
3484        let _: bool = self
3485            .get_bg_restore_count()
3486            .update(|count: &mut u32| *count = count.saturating_add(1));
3487    }
3488}
3489
3490/// Default `ShowcaseState` delegating to `ShowcaseState::new`.
3491impl Default for ShowcaseState {
3492    /// Creates a default `ShowcaseState`.
3493    ///
3494    /// # Returns
3495    ///
3496    /// - `Self` - Initialized state.
3497    fn default() -> Self {
3498        Self::new()
3499    }
3500}
3501
3502/// Arena setup and gameplay helper methods for `DemoPhysicsScene`.
3503impl DemoPhysicsScene {
3504    /// Creates an empty zero-allocation 2D arena placeholder that hydrates lazily on first active tick or render.
3505    ///
3506    /// # Returns
3507    ///
3508    /// - `Self` - Uninitialized lazy arena placeholder.
3509    #[must_use]
3510    pub fn create_lazy_arena() -> Self {
3511        Self {
3512            world: GameWorld::default(),
3513            physics: PhysicsWorld2D::default(),
3514            camera: Camera2D::default(),
3515            particles: ParticleSystem::default(),
3516            tilemap: TileMap::empty(0, 0, 48.0),
3517            actions: ActionMap::default(),
3518            audio: AudioBus::default(),
3519            player_id: EntityId::default(),
3520            fire_cooldown: 0.0,
3521            dash_cooldown: 0.0,
3522            score: 0,
3523            wave: 1,
3524            show_colliders: false,
3525            smoothed_fps: 0.0,
3526            ticks: 0,
3527            viewport_size: Size::new(820.0, 340.0),
3528            initialized: false,
3529            snapshots: DoubleBufferedSnapshot::new(World2DSnapshot::default()),
3530            to_despawn_scratch: Vec::new(),
3531            last_sampled_tick: u64::MAX,
3532            last_sampled_alpha_milli: i32::MIN,
3533            cached_interp: None,
3534        }
3535    }
3536
3537    /// Hydrates the full 2D arena tilemap, entities, and particle pool once on first active simulation or render.
3538    ///
3539    /// # Arguments
3540    ///
3541    /// - `&Self` - Mutable arena scene.
3542    fn ensure_initialized(&mut self) {
3543        if self.get_initialized() {
3544            return;
3545        }
3546        *self = Self::create_arena();
3547    }
3548
3549    /// Builds a playable 1280x720 tiled neon arena with player ship, obstacles, and initial enemy wave.
3550    ///
3551    /// # Returns
3552    ///
3553    /// - `Self` - Initialized playable arena scene.
3554    #[must_use]
3555    pub fn create_arena() -> Self {
3556        let mut tilemap: TileMap = TileMap::empty(24, 14, 48.0);
3557        let floor_a: u16 = tilemap.add_palette_entry(TilePaletteEntry::new(
3558            Color::hex(0x0B1120),
3559            Color::rgba(30, 41, 59, 90),
3560            false,
3561        ));
3562        let floor_b: u16 = tilemap.add_palette_entry(TilePaletteEntry::new(
3563            Color::hex(0x0F172A),
3564            Color::rgba(30, 41, 59, 90),
3565            false,
3566        ));
3567        let wall_tile: u16 = tilemap.add_palette_entry(TilePaletteEntry::new(
3568            Color::hex(0x1E293B),
3569            Color::hex(0x38BDF8),
3570            true,
3571        ));
3572        for row in 0..tilemap.get_rows() {
3573            for col in 0..tilemap.get_columns() {
3574                let is_border: bool = row == 0
3575                    || col == 0
3576                    || row + 1 == tilemap.get_rows()
3577                    || col + 1 == tilemap.get_columns();
3578                let tid: u16 = if is_border {
3579                    wall_tile
3580                } else if (row + col) % 2 == 0 {
3581                    floor_a
3582                } else {
3583                    floor_b
3584                };
3585                tilemap.set_tile(col, row, tid);
3586            }
3587        }
3588        let world_rect: Rect = tilemap.world_bounds();
3589        let inner_arena: Rect = Rect::new(
3590            56.0,
3591            56.0,
3592            (world_rect.get_width() - 112.0).max(200.0),
3593            (world_rect.get_height() - 112.0).max(200.0),
3594        );
3595        let mut world: GameWorld = GameWorld::with_capacity(256);
3596        let center: Point = Point::new(world_rect.get_width() * 0.5, world_rect.get_height() * 0.5);
3597        let player_id: EntityId = world.spawn(EntityTag::Player, center);
3598        if let Some(player) = world.get_entity_mut(player_id) {
3599            player.set_body(Some(RigidBody2D::dynamic(1.0, 0.4, 3.2)));
3600            player.set_collider(Some(Collider2D::circle(
3601                14.0,
3602                COLLISION_LAYER_PLAYER,
3603                COLLISION_MASK_PLAYER_DEFAULT,
3604                false,
3605            )));
3606            player.set_sprite(Some(Sprite2D::new(
3607                EntityVisualShape::Triangle,
3608                Size::new(30.0, 26.0),
3609                Color::hex(0x38BDF8),
3610                Color::hex(0xE0F2FE),
3611                10,
3612                0.0,
3613                true,
3614            )));
3615        }
3616        let pillars: [(f32, f32); 4] = [
3617            (280.0, 200.0),
3618            (860.0, 200.0),
3619            (280.0, 470.0),
3620            (860.0, 470.0),
3621        ];
3622        for (px, py) in pillars.into_iter() {
3623            let pid: EntityId = world.spawn(EntityTag::Obstacle, Point::new(px, py));
3624            if let Some(obs) = world.get_entity_mut(pid) {
3625                obs.set_body(Some(RigidBody2D::static_body(0.85)));
3626                obs.set_collider(Some(Collider2D::aabb(
3627                    52.0,
3628                    52.0,
3629                    COLLISION_LAYER_WORLD,
3630                    COLLISION_LAYER_ALL,
3631                    false,
3632                )));
3633                obs.set_sprite(Some(Sprite2D::new(
3634                    EntityVisualShape::Rect,
3635                    Size::new(52.0, 52.0),
3636                    Color::hex(0x1E293B),
3637                    Color::hex(0x6366F1),
3638                    2,
3639                    8.0,
3640                    true,
3641                )));
3642            }
3643        }
3644        let mut phys_cfg: PhysicsConfig = PhysicsConfig::default();
3645        phys_cfg.set_arena_bounds(Some(inner_arena));
3646        let mut camera: Camera2D = Camera2D::at(center, 1.0);
3647        camera.set_world_bounds(Some(world_rect));
3648        let mut scene: Self = Self {
3649            world,
3650            physics: PhysicsWorld2D::with_config(phys_cfg),
3651            camera,
3652            particles: ParticleSystem::with_capacity(1024),
3653            tilemap,
3654            actions: ActionMap::default(),
3655            audio: AudioBus::default(),
3656            player_id,
3657            fire_cooldown: 0.0,
3658            dash_cooldown: 0.0,
3659            score: 0,
3660            wave: 1,
3661            show_colliders: false,
3662            smoothed_fps: 0.0,
3663            ticks: 0,
3664            viewport_size: Size::new(820.0, 340.0),
3665            initialized: true,
3666            snapshots: DoubleBufferedSnapshot::new(World2DSnapshot::default()),
3667            to_despawn_scratch: Vec::with_capacity(32),
3668            last_sampled_tick: u64::MAX,
3669            last_sampled_alpha_milli: i32::MIN,
3670            cached_interp: None,
3671        };
3672        scene.spawn_enemy_wave(8);
3673        let initial_snap: World2DSnapshot =
3674            World2DSnapshot::capture(scene.get_world(), scene.get_camera(), true, Vec::new());
3675        scene.set_snapshots(DoubleBufferedSnapshot::new(initial_snap));
3676        scene
3677    }
3678
3679    /// Spawns `count` patrolling enemy drones around the arena perimeter.
3680    ///
3681    /// # Arguments
3682    ///
3683    /// - `&Self` - Mutable arena scene.
3684    /// - `usize` - Number of enemy drones to spawn.
3685    pub fn spawn_enemy_wave(&mut self, count: usize) {
3686        let bounds: Rect = self.get_tilemap().world_bounds();
3687        let cx: f32 = bounds.get_width() * 0.5;
3688        let cy: f32 = bounds.get_height() * 0.5;
3689        for idx in 0..count {
3690            let angle: f32 = ((idx as f32) / (count.max(1) as f32)) * 6.283_185_5
3691                + (self.get_wave() as f32) * 0.45;
3692            let radius: f32 = 220.0 + ((idx % 3) as f32) * 48.0;
3693            let sx: f32 = (cx + angle.cos() * radius).clamp(110.0, bounds.get_width() - 110.0);
3694            let sy: f32 = (cy + angle.sin() * radius).clamp(110.0, bounds.get_height() - 110.0);
3695            let speed: f32 = 95.0 + ((idx % 4) as f32) * 28.0;
3696            let eid: EntityId = self
3697                .get_mut_world()
3698                .spawn(EntityTag::Enemy, Point::new(sx, sy));
3699            if let Some(enemy) = self.get_mut_world().get_entity_mut(eid) {
3700                enemy.set_velocity(Velocity2D::new(
3701                    -angle.sin() * speed,
3702                    angle.cos() * speed,
3703                    1.5,
3704                ));
3705                enemy.set_body(Some(RigidBody2D::dynamic(1.2, 0.95, 0.05)));
3706                enemy.set_collider(Some(Collider2D::circle(
3707                    13.0,
3708                    COLLISION_LAYER_ENEMY,
3709                    COLLISION_LAYER_ALL,
3710                    false,
3711                )));
3712                enemy.set_sprite(Some(Sprite2D::new(
3713                    if idx % 2 == 0 {
3714                        EntityVisualShape::Diamond
3715                    } else {
3716                        EntityVisualShape::Circle
3717                    },
3718                    Size::new(26.0, 26.0),
3719                    if idx % 2 == 0 {
3720                        Color::hex(0xF43F5E)
3721                    } else {
3722                        Color::hex(0xF59E0B)
3723                    },
3724                    Color::hex(0xFEF08A),
3725                    6,
3726                    0.0,
3727                    true,
3728                )));
3729            }
3730        }
3731    }
3732
3733    /// Fires a fast plasma projectile from the player ship along `aim_angle`.
3734    ///
3735    /// # Arguments
3736    ///
3737    /// - `&Self` - Mutable arena scene.
3738    /// - `Point` - Launch origin in world coordinates.
3739    /// - `f32` - Launch angle in radians.
3740    fn fire_projectile(&mut self, origin: Point, aim_angle: f32) {
3741        let dir_x: f32 = aim_angle.cos();
3742        let dir_y: f32 = aim_angle.sin();
3743        let launch: Point =
3744            Point::new(origin.get_x() + dir_x * 20.0, origin.get_y() + dir_y * 20.0);
3745        let pid: EntityId = self.get_mut_world().spawn(EntityTag::Projectile, launch);
3746        if let Some(proj) = self.get_mut_world().get_entity_mut(pid) {
3747            proj.get_mut_transform().set_rotation_rad(aim_angle);
3748            proj.set_velocity(Velocity2D::new(dir_x * 520.0, dir_y * 520.0, 0.0));
3749            proj.set_body(Some(RigidBody2D::dynamic(0.2, 0.9, 0.0)));
3750            proj.set_collider(Some(Collider2D::circle(
3751                5.0,
3752                COLLISION_LAYER_PROJECTILE,
3753                COLLISION_LAYER_ENEMY | COLLISION_LAYER_WORLD,
3754                true,
3755            )));
3756            proj.set_sprite(Some(Sprite2D::new(
3757                EntityVisualShape::Circle,
3758                Size::new(10.0, 10.0),
3759                Color::hex(0x34D399),
3760                Color::hex(0xFFFFFF),
3761                8,
3762                0.0,
3763                true,
3764            )));
3765            proj.set_ttl_secs(Some(1.4));
3766        }
3767        let mut muzzle: ParticleEmitterConfig = ParticleEmitterConfig::default();
3768        muzzle
3769            .set_base_angle(aim_angle)
3770            .set_spread_rad(0.45)
3771            .set_min_speed(80.0)
3772            .set_max_speed(180.0)
3773            .set_min_life(0.12)
3774            .set_max_life(0.26)
3775            .set_start_size(3.5)
3776            .set_start_color(Color::hex(0x34D399))
3777            .set_end_color(Color::rgba(56, 189, 248, 0));
3778        self.get_mut_particles().emit_burst(launch, 6, muzzle);
3779        self.get_mut_audio().play(SoundCue::Laser, 0.65, 0.0, 1.05);
3780    }
3781}
3782
3783/// Deterministic fixed-timestep 2D game engine simulation and camera-driven HUD rendering for `DemoPhysicsScene`.
3784impl GameScene for DemoPhysicsScene {
3785    /// Steps player controls, ECS physics, collision combat, particles, and camera follow at 60Hz fixed cadence.
3786    ///
3787    /// # Arguments
3788    ///
3789    /// - `&Self` - Mutable arena scene.
3790    /// - `f32` - Fixed simulation delta time in seconds.
3791    /// - `&InputState` - Real-time polled keyboard and pointer state.
3792    fn fixed_update(&mut self, dt: f32, input: &InputState) {
3793        self.ensure_initialized();
3794        let move_vec: Point = self.get_actions().movement_vector(input);
3795        let fire_pressed: bool = self.get_actions().is_active(GameAction::Fire, input);
3796        let dash_pressed: bool = self.get_actions().is_just_pressed(GameAction::Dash, input);
3797        let wave_pressed: bool = self
3798            .get_actions()
3799            .is_just_pressed(GameAction::ActionAlt, input);
3800        if wave_pressed {
3801            let next_wave: u32 = self.get_wave().saturating_add(1);
3802            self.set_wave(next_wave);
3803            self.spawn_enemy_wave(6);
3804        }
3805        let fire_cd: f32 = (self.get_fire_cooldown() - dt).max(0.0);
3806        let dash_cd: f32 = (self.get_dash_cooldown() - dt).max(0.0);
3807        self.set_fire_cooldown(fire_cd);
3808        self.set_dash_cooldown(dash_cd);
3809        let player_id: EntityId = self.get_player_id();
3810        let mut player_pos: Point = Point::new(576.0, 336.0);
3811        let mut aim_angle: f32 = 0.0;
3812        let mut dashed: bool = false;
3813        if let Some(player) = self.get_mut_world().get_entity_mut(player_id) {
3814            player_pos = player.get_transform().get_position();
3815            let accel: f32 = 1650.0;
3816            let mut vel: Velocity2D = player.get_velocity();
3817            vel.set_vx(vel.get_vx() + move_vec.get_x() * accel * dt);
3818            vel.set_vy(vel.get_vy() + move_vec.get_y() * accel * dt);
3819            let mut rot: f32 = player.get_transform().get_rotation_rad();
3820            if move_vec.get_x().abs() > 0.05 || move_vec.get_y().abs() > 0.05 {
3821                rot = move_vec.get_y().atan2(move_vec.get_x());
3822            } else {
3823                rot += dt * 0.8;
3824            }
3825            if dash_pressed && dash_cd <= 0.0 {
3826                vel.set_vx(vel.get_vx() + rot.cos() * 440.0);
3827                vel.set_vy(vel.get_vy() + rot.sin() * 440.0);
3828                dashed = true;
3829            }
3830            player.set_velocity(vel);
3831            player.get_mut_transform().set_rotation_rad(rot);
3832            aim_angle = rot;
3833        }
3834        if dashed {
3835            self.set_dash_cooldown(0.45);
3836            self.get_mut_camera().add_trauma(0.25);
3837            let mut burst: ParticleEmitterConfig = ParticleEmitterConfig::default();
3838            burst
3839                .set_base_angle(aim_angle + PI)
3840                .set_spread_rad(0.9)
3841                .set_start_color(Color::hex(0x38BDF8))
3842                .set_end_color(Color::rgba(56, 189, 248, 0));
3843            self.get_mut_particles().emit_burst(player_pos, 18, burst);
3844            self.get_mut_audio().play(SoundCue::Dash, 0.8, 0.0, 1.0);
3845        }
3846        if (fire_pressed || self.get_ticks().is_multiple_of(22)) && fire_cd <= 0.0 {
3847            self.fire_projectile(player_pos, aim_angle);
3848            self.set_fire_cooldown(0.14);
3849        }
3850        let collisions: Vec<CollisionEvent> = {
3851            let Self { world, physics, .. } = self;
3852            physics.step(world, dt)
3853        };
3854        {
3855            let Self {
3856                world,
3857                to_despawn_scratch,
3858                camera,
3859                audio,
3860                ..
3861            } = self;
3862            to_despawn_scratch.clear();
3863            for ev in collisions.into_iter() {
3864                let tag_a: Option<EntityTag> = world
3865                    .get_entity(ev.get_entity_a())
3866                    .map(EntityRecord::get_tag);
3867                let tag_b: Option<EntityTag> = world
3868                    .get_entity(ev.get_entity_b())
3869                    .map(EntityRecord::get_tag);
3870                match (tag_a, tag_b) {
3871                    (Some(EntityTag::Projectile), Some(EntityTag::Enemy)) => {
3872                        if let Some(e) = world.get_entity(ev.get_entity_b()) {
3873                            to_despawn_scratch.push((
3874                                ev.get_entity_b(),
3875                                e.get_transform().get_position(),
3876                                true,
3877                            ));
3878                        }
3879                        to_despawn_scratch.push((ev.get_entity_a(), Point::default(), false));
3880                    }
3881                    (Some(EntityTag::Enemy), Some(EntityTag::Projectile)) => {
3882                        if let Some(e) = world.get_entity(ev.get_entity_a()) {
3883                            to_despawn_scratch.push((
3884                                ev.get_entity_a(),
3885                                e.get_transform().get_position(),
3886                                true,
3887                            ));
3888                        }
3889                        to_despawn_scratch.push((ev.get_entity_b(), Point::default(), false));
3890                    }
3891                    (Some(EntityTag::Projectile), Some(EntityTag::Obstacle)) => {
3892                        to_despawn_scratch.push((ev.get_entity_a(), Point::default(), false));
3893                    }
3894                    (Some(EntityTag::Obstacle), Some(EntityTag::Projectile)) => {
3895                        to_despawn_scratch.push((ev.get_entity_b(), Point::default(), false));
3896                    }
3897                    (Some(EntityTag::Player), Some(EntityTag::Enemy))
3898                    | (Some(EntityTag::Enemy), Some(EntityTag::Player)) => {
3899                        camera.add_trauma(0.35);
3900                        audio.play(SoundCue::Bounce, 0.7, 0.0, 0.85);
3901                    }
3902                    _ => {}
3903                }
3904            }
3905        }
3906        {
3907            let Self {
3908                world,
3909                to_despawn_scratch,
3910                score,
3911                camera,
3912                particles,
3913                audio,
3914                ..
3915            } = self;
3916            for &(eid, pos, is_enemy) in to_despawn_scratch.iter() {
3917                if world.despawn(eid) && is_enemy {
3918                    *score = score.saturating_add(100);
3919                    camera.add_trauma(0.32);
3920                    let mut exp: ParticleEmitterConfig = ParticleEmitterConfig::default();
3921                    exp.set_min_speed(70.0)
3922                        .set_max_speed(260.0)
3923                        .set_start_size(5.5)
3924                        .set_start_color(Color::hex(0xFB7185))
3925                        .set_end_color(Color::rgba(250, 204, 21, 0));
3926                    particles.emit_burst(pos, 22, exp);
3927                    audio.play(SoundCue::Explosion, 0.9, 0.0, 0.95);
3928                }
3929            }
3930            to_despawn_scratch.clear();
3931        }
3932        if self.get_world().count_by_tag(EntityTag::Enemy) < 3 {
3933            let next_wave: u32 = self.get_wave().saturating_add(1);
3934            self.set_wave(next_wave);
3935            self.spawn_enemy_wave(6);
3936        }
3937        let _: usize = self.get_mut_world().tick_lifetimes(dt);
3938        let _: usize = self.get_mut_particles().update(dt);
3939        let _: Vec<AudioCommand> = self.get_mut_audio().drain();
3940        if let Some(player) = self.get_world().get_entity(player_id) {
3941            let p: Point = player.get_transform().get_position();
3942            let vp: Size = self.get_viewport_size();
3943            self.get_mut_camera().follow(p, 7.5, dt, vp);
3944        }
3945        self.set_ticks(self.get_ticks().saturating_add(1));
3946        self.set_last_sampled_tick(u64::MAX);
3947        let next_snap: World2DSnapshot =
3948            World2DSnapshot::capture(self.get_world(), self.get_camera(), false, Vec::new());
3949        self.get_mut_snapshots().commit(next_snap);
3950    }
3951
3952    /// Updates smoothed frame-rate telemetry once per visual frame.
3953    ///
3954    /// # Arguments
3955    ///
3956    /// - `&Self` - Mutable arena scene.
3957    /// - `f32` - Real frame delta time in seconds.
3958    /// - `&InputState` - Current polled input snapshot.
3959    fn update(&mut self, dt: f32, _input: &InputState) {
3960        if dt > 0.0001 {
3961            let inst_fps: f32 = (1.0 / dt).clamp(1.0, 9999.0);
3962            let prev: f32 = self.get_smoothed_fps();
3963            let next: f32 = if prev <= 0.5 {
3964                inst_fps
3965            } else {
3966                prev * 0.85 + inst_fps * 0.15
3967            };
3968            self.set_smoothed_fps(next);
3969        }
3970    }
3971
3972    /// Renders the camera-projected tilemap, ECS entities, raycast targeting laser, particles, and engine HUD with single-pass snapshot interpolation.
3973    ///
3974    /// # Arguments
3975    ///
3976    /// - `&Self` - Mutable arena scene.
3977    /// - `f32` - Interpolation alpha in `[0.0, 1.0]`.
3978    /// - `&mut GameRenderContext<'_>` - Immediate-mode game draw surface.
3979    fn render(&mut self, alpha: f32, ctx: &mut GameRenderContext<'_>) {
3980        self.ensure_initialized();
3981        let size: Size = ctx.viewport_size();
3982        if size.get_width() > 32.0 && size.get_height() > 32.0 {
3983            let world_rect: Rect = self.get_tilemap().world_bounds();
3984            let fit_zoom: f32 = (size.get_width() / world_rect.get_width().max(1.0))
3985                .max(size.get_height() / world_rect.get_height().max(1.0))
3986                .clamp(1.0, 1.85);
3987            let vp_changed: bool = size != self.get_viewport_size();
3988            let zoom_changed: bool = (self.get_camera().get_zoom() - fit_zoom).abs() > 0.001;
3989            if vp_changed || zoom_changed {
3990                self.set_viewport_size(size);
3991                self.get_mut_camera().set_zoom(fit_zoom);
3992                self.get_mut_snapshots()
3993                    .get_mut_prev_state()
3994                    .get_mut_camera()
3995                    .set_zoom(fit_zoom);
3996                self.get_mut_snapshots()
3997                    .get_mut_curr_state()
3998                    .get_mut_camera()
3999                    .set_zoom(fit_zoom);
4000                self.set_last_sampled_tick(u64::MAX);
4001            }
4002        }
4003        ctx.clear(Color::hex(0x020617));
4004        let alpha_milli: i32 = (alpha.clamp(0.0, 1.0) * 1000.0).round() as i32;
4005        let cur_ticks: u64 = self.get_ticks();
4006        let needs_resample: bool = self.get_last_sampled_tick() != cur_ticks
4007            || self.get_last_sampled_alpha_milli() != alpha_milli
4008            || {
4009                let Self { cached_interp, .. } = self;
4010                cached_interp.is_none()
4011            };
4012        if needs_resample {
4013            let sampled: World2DSnapshot = self.get_snapshots().sample(alpha);
4014            let Self {
4015                cached_interp,
4016                last_sampled_tick,
4017                last_sampled_alpha_milli,
4018                ..
4019            } = self;
4020            *cached_interp = Some(sampled);
4021            *last_sampled_tick = cur_ticks;
4022            *last_sampled_alpha_milli = alpha_milli;
4023        }
4024        let player_id: EntityId = self.get_player_id();
4025        let (cam, interp_player_tr): (Camera2D, Option<EntityTransform>) = {
4026            let Self {
4027                cached_interp,
4028                world,
4029                camera,
4030                ..
4031            } = self;
4032            match cached_interp.as_ref() {
4033                Some(snap) => {
4034                    let tr: Option<EntityTransform> = snap
4035                        .get_entities()
4036                        .iter()
4037                        .find(|pose: &&EntityPose2D| pose.get_alive() && pose.get_id() == player_id)
4038                        .map(EntityPose2D::get_transform)
4039                        .or_else(|| world.get_entity(player_id).map(EntityRecord::get_transform));
4040                    (snap.get_camera(), tr)
4041                }
4042                None => (
4043                    *camera,
4044                    world.get_entity(player_id).map(EntityRecord::get_transform),
4045                ),
4046            }
4047        };
4048        ctx.render_tilemap(self.get_tilemap(), &cam);
4049        if let Some(player_tr) = interp_player_tr {
4050            let origin: Point = player_tr.get_position();
4051            let rot: f32 = player_tr.get_rotation_rad();
4052            let dir: Point = Point::new(rot.cos(), rot.sin());
4053            let end_world: Point = match PhysicsWorld2D::raycast(
4054                self.get_world(),
4055                origin,
4056                dir,
4057                340.0,
4058                COLLISION_LAYER_ENEMY | COLLISION_LAYER_WORLD,
4059            ) {
4060                Some(hit) => hit.get_point(),
4061                None => Point::new(
4062                    origin.get_x() + dir.get_x() * 340.0,
4063                    origin.get_y() + dir.get_y() * 340.0,
4064                ),
4065            };
4066            let s0: Point = cam.world_to_screen(origin, size);
4067            let s1: Point = cam.world_to_screen(end_world, size);
4068            ctx.draw_line(s0, s1, 1.5, Color::rgba(56, 189, 248, 120));
4069            ctx.fill_circle(s1, 3.5, Color::hex(0x38BDF8));
4070        }
4071        let drawn_entities: usize = {
4072            let Self {
4073                world,
4074                cached_interp,
4075                ..
4076            } = self;
4077            match cached_interp.as_ref() {
4078                Some(snap) => ctx.render_snapshot_world(world, snap),
4079                None => 0,
4080            }
4081        };
4082        let drawn_particles: usize = ctx.render_particles(self.get_particles(), &cam);
4083        if self.get_show_colliders() {
4084            ctx.draw_debug_colliders(self.get_world(), &cam);
4085        }
4086        ctx.fill_rounded_rect(
4087            Rect::new(
4088                10.0,
4089                10.0,
4090                (size.get_width() - 20.0).clamp(180.0, 560.0),
4091                28.0,
4092            ),
4093            Color::rgba(15, 23, 42, 210),
4094            6.0,
4095        );
4096        ctx.draw_text(
4097            Point::new(18.0, 16.0),
4098            format!(
4099                "FPS {:.0} | Wave {} | Score {} | Ent {} | Part {} | SFX {}",
4100                self.get_smoothed_fps(),
4101                self.get_wave(),
4102                self.get_score(),
4103                drawn_entities,
4104                drawn_particles,
4105                self.get_audio().get_total_played()
4106            ),
4107            12.0,
4108            Color::hex(0xE2E8F0),
4109        );
4110        let hint_y: f32 = (size.get_height() - 32.0).max(44.0);
4111        let hint_w: f32 = (size.get_width() - 24.0).clamp(180.0, 380.0);
4112        ctx.fill_rounded_rect(
4113            Rect::new(10.0, hint_y, hint_w, 22.0),
4114            Color::rgba(15, 23, 42, 200),
4115            6.0,
4116        );
4117        ctx.draw_text(
4118            Point::new(18.0, hint_y + 4.0),
4119            GAME_HUD_CONTROLS_HINT.to_string(),
4120            11.0,
4121            Color::rgba(226, 232, 240, 235),
4122        );
4123    }
4124}
4125
4126/// Construction, async city loading, and runtime-config helpers for `DemoOpenWorld3DScene`.
4127impl DemoOpenWorld3DScene {
4128    /// Creates an empty zero-allocation 3D city placeholder sharing lazy signal and background-worker cells.
4129    ///
4130    /// # Arguments
4131    ///
4132    /// - `Rc<Cell<Option<Engine3dSignals>>>` - Shared lazy `/game3d` control signal cell.
4133    /// - `Scope` - Root ownership scope retaining lazily materialized `/game3d` signals across route evictions.
4134    /// - `Rc<Cell<bool>>` - Shared toggle enabling background OS-thread city construction.
4135    ///
4136    /// # Returns
4137    ///
4138    /// - `Self` - Uninitialized lazy 3D scene placeholder.
4139    #[must_use]
4140    pub(crate) fn create_lazy_city_deferred(
4141        signals_cell: Rc<Cell<Option<Engine3dSignals>>>,
4142        state_scope: Scope,
4143        bg_workers_enabled: Rc<Cell<bool>>,
4144    ) -> Self {
4145        Self {
4146            world: World3D::default(),
4147            renderer: Renderer3D::default(),
4148            actions: ActionMap::default(),
4149            signals_cell,
4150            state_scope,
4151            bg_workers_enabled,
4152            bg_city_task: None,
4153            last_import_seq: 0,
4154            smoothed_fps: 0.0,
4155            initialized: false,
4156            snapshots: DoubleBufferedSnapshot::new(World3DSnapshot::default()),
4157            frame_pool: RenderBufferPool::with_capacity(3),
4158            gpu_target: GpuCompositeTarget::default(),
4159            frame_fence: 0,
4160            last_camera_mode: 0,
4161            ticks: 0,
4162            cached_world_frame: None,
4163            cached_world_rev: u64::MAX,
4164            cached_alpha_milli: i32::MIN,
4165            cached_dims: (0, 0),
4166            cached_quality: RenderQualityConfig::default(),
4167        }
4168    }
4169
4170    /// Resolves the shared lazy `/game3d` control signals on first active tick or render.
4171    ///
4172    /// # Arguments
4173    ///
4174    /// - `&Self` - 3D scene reference.
4175    ///
4176    /// # Returns
4177    ///
4178    /// - `Engine3dSignals` - Active `/game3d` control signals.
4179    fn active_signals(&self) -> Engine3dSignals {
4180        Engine3dSignals::get_or_init(self.get_signals_cell().as_ref(), self.get_state_scope())
4181    }
4182
4183    /// Commits a constructed `World3D` open-world city into this scene and marks the world render target dirty.
4184    ///
4185    /// # Arguments
4186    ///
4187    /// - `&Self` - Mutable 3D scene.
4188    /// - `World3D` - Built Vice Boulevard open-world city.
4189    fn install_world(&mut self, world: World3D) {
4190        let initial_snap: World3DSnapshot =
4191            World3DSnapshot::capture(&world, 0, true, Vec::new(), Vec::new());
4192        let init_mode: u8 = world.get_camera_mode();
4193        self.set_world(world);
4194        self.set_snapshots(DoubleBufferedSnapshot::new(initial_snap));
4195        self.set_last_camera_mode(init_mode);
4196        self.get_mut_gpu_target().mark_world_dirty();
4197        self.set_cached_world_frame(None);
4198        self.set_cached_world_rev(u64::MAX);
4199        self.set_initialized(true);
4200        let _: bool = self
4201            .active_signals()
4202            .get_engine3d_import_status()
4203            .set_if_changed(DEFAULT_ENGINE3D_STATUS.to_string());
4204    }
4205
4206    /// Lazily initializes the Vice Boulevard 3D open-world city, using a background worker thread on interactive native apps.
4207    ///
4208    /// # Arguments
4209    ///
4210    /// - `&Self` - Mutable 3D scene.
4211    ///
4212    /// # Returns
4213    ///
4214    /// - `bool` - `true` when the 3D city is ready for simulation and rendering.
4215    fn ensure_initialized(&mut self) -> bool {
4216        if self.get_initialized() {
4217            return true;
4218        }
4219        let ready_world: Option<World3D> = {
4220            let Self { bg_city_task, .. } = self;
4221            if let Some(task) = bg_city_task.as_ref() {
4222                if let Some(world) = task.try_take() {
4223                    *bg_city_task = None;
4224                    Some(world)
4225                } else {
4226                    return false;
4227                }
4228            } else {
4229                None
4230            }
4231        };
4232        if let Some(world) = ready_world {
4233            self.install_world(world);
4234            return true;
4235        }
4236        if self.get_bg_workers_enabled().get() {
4237            let task: BackgroundTask<World3D> =
4238                BackgroundTask::spawn(World3D::create_open_world_city);
4239            let _: bool = self
4240                .active_signals()
4241                .get_engine3d_import_status()
4242                .set_if_changed(STATUS_ENGINE3D_LOADING.to_string());
4243            self.set_bg_city_task(Some(task));
4244            return false;
4245        }
4246        let world: World3D = World3D::create_open_world_city();
4247        self.install_world(world);
4248        true
4249    }
4250
4251    /// Creates the live Vice Boulevard 3D open-world scene bound to explicit reactive runtime settings signals.
4252    ///
4253    /// # Arguments
4254    ///
4255    /// - `Signal<RenderQualityConfig>` - Live quality/RT/resolution configuration signal.
4256    /// - `Signal<f32>` - Live time-of-day sun hour signal.
4257    /// - `Signal<u64>` - Monotonic model import request signal.
4258    /// - `Signal<String>` - Live status feedback signal.
4259    /// - `Signal<u8>` - Active 3D camera mode signal (`0=Chase, 1=Hood, 2=Orbit, 3=Aerial`).
4260    ///
4261    /// # Returns
4262    ///
4263    /// - `Self` - Initialized 3D open-world scene.
4264    #[must_use]
4265    pub fn create_city(
4266        quality_signal: Signal<RenderQualityConfig>,
4267        time_signal: Signal<f32>,
4268        import_signal: Signal<u64>,
4269        status_signal: Signal<String>,
4270        camera_mode_signal: Signal<u8>,
4271    ) -> Self {
4272        let group: Engine3dSignals = Engine3dSignals {
4273            engine3d_quality: quality_signal,
4274            engine3d_preset_idx: Signal::new(4),
4275            engine3d_rt_idx: Signal::new(3),
4276            engine3d_res_scale: Signal::new(100.0),
4277            engine3d_time_of_day: time_signal,
4278            engine3d_import_queue: import_signal,
4279            engine3d_import_status: status_signal,
4280            engine3d_camera_mode: camera_mode_signal,
4281        };
4282        let (state_scope, _): (Scope, ()) = Scope::run(|_: Scope| {});
4283        let mut scene: Self = Self::create_lazy_city_deferred(
4284            Rc::new(Cell::new(Some(group))),
4285            state_scope,
4286            Rc::new(Cell::new(false)),
4287        );
4288        let _: bool = scene.ensure_initialized();
4289        scene
4290    }
4291}
4292
4293/// Deterministic 3D open-world simulation and HUD-decoupled PBR + BVH ray-traced rendering for `DemoOpenWorld3DScene`.
4294impl GameScene for DemoOpenWorld3DScene {
4295    /// Steps vehicle physics, camera follow, spinning imported models, time-of-day sun, and queued model imports.
4296    ///
4297    /// # Arguments
4298    ///
4299    /// - `&Self` - Mutable 3D scene.
4300    /// - `f32` - Fixed simulation timestep in seconds.
4301    /// - `&InputState` - Real-time polled keyboard/pointer state.
4302    fn fixed_update(&mut self, dt: f32, input: &InputState) {
4303        if !self.ensure_initialized() {
4304            return;
4305        }
4306        let signals: Engine3dSignals = self.active_signals();
4307        let req_seq: u64 = signals.get_engine3d_import_queue().get_untracked();
4308        if req_seq != self.get_last_import_seq() {
4309            self.set_last_import_seq(req_seq);
4310            let is_obj: bool = req_seq % 2 == 1;
4311            let z_pos: f32 = -4.0 - ((req_seq % 5) as f32) * 8.0;
4312            let x_pos: f32 = if is_obj { -5.5 } else { 5.5 };
4313            let import_res: Result<ImportedModel3D, String> = if is_obj {
4314                self.get_mut_world().import_model(
4315                    ModelFormat::Obj,
4316                    SAMPLE_OBJ_MONUMENT,
4317                    Transform3D::new(Vec3::new(x_pos, 0.0, z_pos), 0.0, Vec3::splat(1.0)),
4318                    PbrMaterial::pbr(Color::hex(0xF59E0B), 0.9, 0.14, 0.72),
4319                    0.85,
4320                )
4321            } else {
4322                self.get_mut_world().import_model(
4323                    ModelFormat::GltfJson,
4324                    SAMPLE_GLTF_TOWER,
4325                    Transform3D::new(Vec3::new(x_pos, 0.0, z_pos), 0.0, Vec3::splat(1.0)),
4326                    PbrMaterial::pbr(Color::hex(0x38BDF8), 0.85, 0.12, 0.80),
4327                    -0.70,
4328                )
4329            };
4330            if let Ok(info) = import_res {
4331                let msg: String = format!(
4332                    "Imported {} ({:?}): {} verts, {} tris (LOD0+LOD1 + BVH rebuilt)",
4333                    info.get_name(),
4334                    info.get_format(),
4335                    info.get_total_vertices(),
4336                    info.get_total_triangles()
4337                );
4338                let _: bool = signals.get_engine3d_import_status().set_if_changed(msg);
4339            }
4340        }
4341        let hour: f32 = signals.get_engine3d_time_of_day().get_untracked();
4342        if (hour - self.get_world().get_sun().get_time_of_day()).abs() > 0.05 {
4343            self.get_mut_world()
4344                .set_sun(DirectionalLight3D::from_time_of_day(hour));
4345        }
4346        let cam_mode: u8 = signals.get_engine3d_camera_mode().get_untracked();
4347        let cam_cut: bool = cam_mode != self.get_last_camera_mode();
4348        if cam_mode != self.get_world().get_camera_mode() {
4349            self.get_mut_world().set_camera_mode(cam_mode);
4350        }
4351        self.set_last_camera_mode(cam_mode);
4352        let Self { world, actions, .. } = self;
4353        world.step_simulation(dt, input, actions);
4354        let next_tick: u64 = self.get_ticks().saturating_add(1);
4355        self.set_ticks(next_tick);
4356        let next_snap: World3DSnapshot =
4357            World3DSnapshot::capture(self.get_world(), next_tick, cam_cut, Vec::new(), Vec::new());
4358        if cam_cut {
4359            self.get_mut_snapshots().commit_discontinuous(next_snap);
4360        } else {
4361            self.get_mut_snapshots().commit(next_snap);
4362        }
4363        self.get_mut_gpu_target().mark_world_dirty();
4364    }
4365
4366    /// Updates smoothed FPS telemetry for the 3D HUD overlay without dirtying the 3D world render target.
4367    ///
4368    /// # Arguments
4369    ///
4370    /// - `&Self` - Mutable 3D scene.
4371    /// - `f32` - Real frame delta time in seconds.
4372    /// - `&InputState` - Current polled input snapshot.
4373    fn update(&mut self, dt: f32, _input: &InputState) {
4374        if dt > 0.0001 {
4375            let inst_fps: f32 = (1.0 / dt).clamp(1.0, 9999.0);
4376            let prev: f32 = self.get_smoothed_fps();
4377            let next: f32 = if prev <= 0.5 {
4378                inst_fps
4379            } else {
4380                prev * 0.85 + inst_fps * 0.15
4381            };
4382            self.set_smoothed_fps(next);
4383            self.get_mut_gpu_target().mark_hud_dirty();
4384        }
4385    }
4386
4387    /// Renders the 3D open-world city with HUD-decoupled caching and overlays live telemetry HUD.
4388    ///
4389    /// # Arguments
4390    ///
4391    /// - `&Self` - Mutable 3D scene.
4392    /// - `f32` - Interpolation alpha.
4393    /// - `&mut GameRenderContext<'_>` - Immediate-mode viewport draw context.
4394    fn render(&mut self, alpha: f32, ctx: &mut GameRenderContext<'_>) {
4395        let size: Size = ctx.viewport_size();
4396        if !self.ensure_initialized() {
4397            ctx.clear(Color::hex(0x090D16));
4398            ctx.fill_rounded_rect(
4399                Rect::new(
4400                    10.0,
4401                    10.0,
4402                    (size.get_width() - 20.0).clamp(200.0, 560.0),
4403                    28.0,
4404                ),
4405                Color::rgba(15, 23, 42, 220),
4406                6.0,
4407            );
4408            ctx.draw_text(
4409                Point::new(18.0, 16.0),
4410                HUD_3D_LOADING_TITLE.to_string(),
4411                11.5,
4412                Color::hex(0x38BDF8),
4413            );
4414            return;
4415        }
4416        let signals: Engine3dSignals = self.active_signals();
4417        let quality: RenderQualityConfig = signals.get_engine3d_quality().get_untracked();
4418        let dpr: f32 = ctx.scale_factor().clamp(1.0, 2.5);
4419        let preset_boost: f32 = match quality.get_preset() {
4420            QualityPreset::Low => 1.05,
4421            QualityPreset::Medium => 1.25,
4422            QualityPreset::High => 1.38,
4423            QualityPreset::Ultra => 1.45,
4424            QualityPreset::Cinematic => 1.52,
4425        };
4426        let dpi_boost: f32 = preset_boost.max(dpr.min(2.0));
4427        let raw_w: f32 = (size.get_width().max(64.0) * dpi_boost).max(160.0);
4428        let raw_h: f32 = (size.get_height().max(64.0) * dpi_boost).max(160.0);
4429        let max_dim: f32 = 960.0;
4430        let max_pixels: f32 = 960.0 * 540.0;
4431        let dim_scale: f32 = (max_dim / raw_w.max(raw_h)).min(1.0);
4432        let area_scale: f32 = (max_pixels / (raw_w * raw_h).max(1.0)).sqrt().min(1.0);
4433        let fit_scale: f32 = dim_scale.min(area_scale);
4434        let vw: u32 = ((raw_w * fit_scale).round() as u32).clamp(160, 960);
4435        let vh: u32 = ((raw_h * fit_scale).round() as u32).clamp(160, 960);
4436        let next_fence: u64 = self.get_frame_fence().saturating_add(1);
4437        self.set_frame_fence(next_fence);
4438        let dst_rect: Rect = Rect::new(0.0, 0.0, size.get_width(), size.get_height());
4439        let alpha_milli: i32 = (alpha.clamp(0.0, 1.0) * 1000.0).round() as i32;
4440        let world_rev: u64 = self.get_gpu_target().get_world_revision();
4441        let can_reuse_world: bool = !self.get_gpu_target().needs_world_render()
4442            && self.get_cached_world_rev() == world_rev
4443            && self.get_cached_dims() == (vw, vh)
4444            && self.get_cached_quality() == quality
4445            && self.get_cached_alpha_milli() == alpha_milli;
4446        let mut blitted_pooled: bool = false;
4447        let gpu_handle: GpuTextureHandle = self.get_gpu_target().get_handle();
4448        if gpu_handle.is_valid() && ctx.composite_gpu_texture(dst_rect, gpu_handle) {
4449            let _: Option<GpuCompositeDescriptor> = self
4450                .get_mut_gpu_target()
4451                .record_composite_present(next_fence);
4452            blitted_pooled = true;
4453        } else if can_reuse_world {
4454            let reused_img: Option<ImageBuffer> = {
4455                let Self {
4456                    cached_world_frame, ..
4457                } = self;
4458                cached_world_frame.clone()
4459            };
4460            if let Some(cached_img) = reused_img {
4461                ctx.draw_image(dst_rect, cached_img);
4462                let hud_rev: u64 = self.get_gpu_target().get_hud_revision();
4463                let next_reuse: u64 = self
4464                    .get_gpu_target()
4465                    .get_hud_only_reuses()
4466                    .saturating_add(1);
4467                let target: &mut GpuCompositeTarget = self.get_mut_gpu_target();
4468                target.set_presented_hud_revision(hud_rev);
4469                target.set_hud_only_reuses(next_reuse);
4470                blitted_pooled = true;
4471            }
4472        }
4473        if !blitted_pooled {
4474            let pooled_lease: Option<PooledFrameLease> = {
4475                let Self {
4476                    world,
4477                    renderer,
4478                    snapshots,
4479                    frame_pool,
4480                    ..
4481                } = self;
4482                renderer.render_world_interpolated_into_pool(
4483                    world,
4484                    snapshots,
4485                    alpha,
4486                    (vw, vh),
4487                    &quality,
4488                    (frame_pool, next_fence),
4489                )
4490            };
4491            if let Some(lease) = pooled_lease {
4492                ctx.blit_pooled_frame(dst_rect, &lease);
4493                let cached_copy: ImageBuffer = lease.to_image_buffer_copy();
4494                lease.submit_in_flight();
4495                let _: usize = self.get_frame_pool().retire_fence(next_fence);
4496                self.set_cached_world_frame(Some(cached_copy));
4497                blitted_pooled = true;
4498            }
4499            if !blitted_pooled {
4500                let frame_img: ImageBuffer = {
4501                    let Self {
4502                        world, renderer, ..
4503                    } = self;
4504                    renderer.render_world(world, vw, vh, &quality)
4505                };
4506                self.set_cached_world_frame(Some(frame_img.clone()));
4507                ctx.draw_image(dst_rect, frame_img);
4508            }
4509            self.set_cached_world_rev(world_rev);
4510            self.set_cached_dims((vw, vh));
4511            self.set_cached_quality(quality);
4512            self.set_cached_alpha_milli(alpha_milli);
4513            let hud_rev: u64 = self.get_gpu_target().get_hud_revision();
4514            let target: &mut GpuCompositeTarget = self.get_mut_gpu_target();
4515            target.set_presented_world_revision(world_rev);
4516            target.set_presented_hud_revision(hud_rev);
4517        }
4518        let stats: RenderStats3D = self.get_renderer().get_last_stats();
4519        let fps: f32 = self.get_smoothed_fps();
4520        let compact_hud: bool = size.get_width() < 520.0;
4521        let hud_text: String = if compact_hud {
4522            format!(
4523                "{fps:.0} FPS | {:?} | {}x{} | {} rays",
4524                quality.get_preset(),
4525                stats.get_render_width(),
4526                stats.get_render_height(),
4527                stats.get_rays_traced()
4528            )
4529        } else {
4530            format!(
4531                "{fps:.0} FPS | 3D {:?} | RT {:?} | {}x{} | Tris {} | Rays {} | BVH {}",
4532                quality.get_preset(),
4533                quality.get_ray_tracing(),
4534                stats.get_render_width(),
4535                stats.get_render_height(),
4536                stats.get_triangles_drawn(),
4537                stats.get_rays_traced(),
4538                stats.get_bvh_nodes()
4539            )
4540        };
4541        ctx.fill_rounded_rect(
4542            Rect::new(
4543                10.0,
4544                10.0,
4545                (size.get_width() - 20.0).clamp(200.0, 620.0),
4546                28.0,
4547            ),
4548            Color::rgba(9, 13, 24, 210),
4549            6.0,
4550        );
4551        ctx.draw_text(Point::new(18.0, 16.0), hud_text, 11.0, Color::hex(0xE2E8F0));
4552    }
4553}