gloss_renderer/plugin_manager/
runner.rs

1use std::time::Duration;
2
3use crate::{viewer::Runner, viewer_headless::RunnerHeadless};
4
5use gloss_utils::abi_stable_aliases::std_types::RDuration;
6#[cfg(not(target_arch = "wasm32"))]
7use gloss_utils::abi_stable_aliases::StableAbi;
8
9//The runner in the viewer contains event loop and other things that cannot
10// cross the ffi barrier. So we make a new one that is slimmer
11#[repr(C)]
12#[cfg_attr(not(target_arch = "wasm32"), derive(StableAbi))]
13pub struct RunnerState {
14    pub is_running: bool,
15    pub do_render: bool,
16    pub request_redraw: bool,
17    first_time: bool,
18    dt: RDuration, /* delta time since we finished last frame, we store it directly here instead of constantly querying it because different
19                    * systems might then get different dt depending on how long they take to run. This dt is set once when doing
20                    * viewer.start_frame() */
21}
22//TODO use a tryinto and tryfrom functions
23impl RunnerState {
24    pub fn from(runner: &Runner) -> Self {
25        Self {
26            is_running: runner.is_running,
27            do_render: runner.do_render,
28            request_redraw: false,
29            first_time: runner.first_time,
30            dt: RDuration::from(runner.dt()),
31        }
32    }
33    pub fn from_headless(runner: &RunnerHeadless) -> Self {
34        Self {
35            is_running: runner.is_running,
36            do_render: runner.do_render,
37            request_redraw: false,
38            first_time: runner.first_time,
39            dt: RDuration::from(runner.dt()),
40        }
41    }
42    //onyl some of the fields are actually going to be modified and are worth
43    // storing back into the runner, at least the pub ones shound be set back into
44    // runner
45    pub fn to(&self, runner: &mut Runner) {
46        runner.is_running = self.is_running;
47        runner.do_render = self.do_render;
48    }
49    pub fn to_headless(&self, runner: &mut RunnerHeadless) {
50        runner.is_running = self.is_running;
51        runner.do_render = self.do_render;
52    }
53    pub fn request_redraw(&mut self) {
54        self.request_redraw = true;
55    }
56    pub fn dt(&self) -> Duration {
57        Duration::from(self.dt)
58    }
59    pub fn is_first_time(&self) -> bool {
60        self.first_time
61    }
62}