Skip to main content

euv_engine/engine/
struct.rs

1use super::*;
2
3/// A zero-sized namespace struct providing static engine entry points.
4///
5/// This struct follows the same pattern as `euv::App`, serving as the
6/// single root namespace for all top-level engine operations: creating
7/// engine handles, initializing rendering backends, and starting the
8/// fixed-timestep game loop.
9///
10/// All engine usage flows through `Engine::xxx` static calls, mirroring
11/// how `euv::App::use_signal` / `euv::App::mount` are the public entry
12/// points of the core framework.
13#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
14pub struct Engine;
15
16/// A handle to a running or initialized engine instance.
17///
18/// Holds the engine configuration, an optional Canvas 2D renderer, an
19/// optional WebGPU renderer, and the optional scheduler handle once the
20/// game loop has started. Use `Engine::new_handle` to construct one, then
21/// call `init_canvas` or `init_webgpu` (matching the backend chosen in
22/// `RenderConfig`) and finally `start` to begin the game loop.
23#[derive(Clone, Data, New)]
24pub struct EngineHandle {
25    /// The engine configuration containing render and scheduler settings.
26    #[get_mut(pub(crate))]
27    #[set(pub(crate))]
28    pub(crate) config: EngineConfig,
29    /// The initialized Canvas 2D renderer, or `None` if the WebGPU backend is used or initialization has not yet happened.
30    #[get(type(clone))]
31    #[get_mut(pub(crate))]
32    #[set(pub(crate))]
33    pub(crate) canvas_renderer: Option<CanvasRenderer>,
34    /// The initialized WebGPU renderer, or `None` if the Canvas 2D backend is used or initialization has not yet happened.
35    #[get(type(clone))]
36    #[get_mut(pub(crate))]
37    #[set(pub(crate))]
38    pub(crate) webgpu_renderer: Option<WebGpuRenderer>,
39    /// The initialized WebGL 2 renderer, or `None` if another backend is used or initialization has not yet happened.
40    #[get(type(clone))]
41    #[get_mut(pub(crate))]
42    #[set(pub(crate))]
43    pub(crate) webgl_renderer: Option<WebGl2Backend>,
44    /// The shared input state once `register_input` has attached the DOM
45    /// event listeners, or `None` before registration (or if the canvas
46    /// selector did not resolve at registration time).
47    #[new(skip)]
48    #[get_mut(pub(crate))]
49    #[set(pub(crate))]
50    pub(crate) input_cell: Option<InputStateCell>,
51    /// The shared task registry holding every [`Updatable`] object the
52    /// scheduler advances on each fixed step. Always present so callers can
53    /// register tasks before `start` is called.
54    #[new(skip)]
55    #[get(pub(crate))]
56    #[get_mut(pub(crate))]
57    #[set(pub(crate))]
58    pub(crate) tasks: TaskRegistryRc,
59    /// The shared asset loader, present once `register_assets` has created
60    /// it, or `None` when asset loading was never requested.
61    #[new(skip)]
62    #[get(pub(crate))]
63    #[get_mut(pub(crate))]
64    #[set(pub(crate))]
65    pub(crate) asset_loader: Option<AssetLoader>,
66    /// The running scheduler handle, or `None` before `start` is called.
67    #[get(pub(crate))]
68    #[get_mut(pub(crate))]
69    #[set(pub(crate))]
70    pub(crate) scheduler_handle: Option<SchedulerHandle>,
71}