honeycomb_render/
app.rs

1use bevy::prelude::App as BevyApp;
2use bevy::prelude::*;
3use honeycomb_core::cmap::CMap2;
4use honeycomb_core::geometry::CoordsFloat;
5
6use crate::capture::{Capture, CaptureList};
7use crate::plugins::{CapturePlugin, GuiPlugin, OptionsPlugin, ScenePlugin};
8
9/// Default render structure.
10///
11/// This structure is essentially a wrapper around a regular `bevy` application. It only provides
12/// an additional method ([`App::add_capture`]) to allow user to record map data that should be
13/// displayed when running.
14pub struct App {
15    /// Inner `bevy` app.
16    pub app: BevyApp,
17    capture_list: CaptureList,
18}
19
20impl App {
21    /// Add a capture to the collection of the app. The capture is created on-the-fly using the
22    /// specified reference to a combinatorial map.
23    pub fn add_capture<T: CoordsFloat>(&mut self, cmap: &CMap2<T>) -> usize {
24        let cap_id = self.capture_list.0.len();
25        let capture = Capture::new(cap_id, cmap);
26        self.capture_list.0.push(capture);
27        cap_id
28    }
29
30    /// Launch the inner `bevy` app.
31    pub fn run(mut self) {
32        self.app.insert_resource(self.capture_list);
33        self.app.run();
34    }
35}
36
37impl Default for App {
38    fn default() -> Self {
39        let mut app = BevyApp::new();
40        // resource
41        app.insert_resource(Msaa::Sample4)
42            .insert_resource(ClearColor(Color::srgb(0.9, 0.9, 0.9)));
43        // plugins
44        app.add_plugins(DefaultPlugins)
45            .add_plugins(OptionsPlugin)
46            .add_plugins(GuiPlugin)
47            .add_plugins(ScenePlugin)
48            .add_plugins(CapturePlugin);
49        Self {
50            app,
51            capture_list: CaptureList(Vec::new()),
52        }
53    }
54}