Skip to main content

mln_runtime/render/
frame.rs

1//! Frame demands and the results that they finish with.
2
3use mln_engine::RenderMode;
4use mln_engine::camera::{FrameProjection, MapView};
5
6/// When a demand draws a frame.
7#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
8pub enum DemandMode {
9    /// Draws a frame when the map changed since the last one, and otherwise
10    /// finishes with [`FrameDisposition::NoUpdate`].
11    #[default]
12    IfChanged,
13    /// Draws a frame even when nothing changed.
14    Force,
15    /// Draws a frame when the map changed since the last one, and otherwise
16    /// waits for the map's next update.
17    WaitForUpdate,
18}
19
20/// A demand for one frame.
21#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
22pub struct FrameDemand {
23    pub mode: DemandMode,
24    /// A value of the host's choice that the demand's result carries.
25    pub token: u64,
26}
27
28impl FrameDemand {
29    #[must_use]
30    pub fn new(mode: DemandMode, token: u64) -> Self {
31        FrameDemand { mode, token }
32    }
33}
34
35/// How a frame demand finished.
36#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
37pub enum FrameDisposition {
38    Rendered,
39    /// The map had nothing new to draw, or a barrier ended the demand.
40    NoUpdate,
41    /// The session couldn't take the frame, as after a detach or an abandon.
42    TargetNotReady,
43    /// A later demand with the same mode replaced this one.
44    Superseded,
45    /// The session failed. Its snapshot says why.
46    Failed,
47}
48
49/// How one frame demand finished.
50#[derive(Clone, Copy, Debug, PartialEq)]
51pub struct FrameResult {
52    pub disposition: FrameDisposition,
53    /// The token of the demand that the result finishes, or `None` for the
54    /// session's demand of a still image that
55    /// [`Map::request_still_image`](crate::Map::request_still_image) asked
56    /// for.
57    pub token: Option<u64>,
58    /// The map update that a rendered frame shows, or the latest one for a
59    /// demand that rendered nothing. The frame includes a command's change
60    /// when this is at least the command's
61    /// [`render_update_generation`](crate::Applied::render_update_generation).
62    pub map_update_generation: u64,
63    /// The session's generation when it rendered the frame: it grows when the
64    /// session resizes. Zero for a demand that rendered nothing.
65    pub generation: u64,
66    /// Counts the session's rendered frames, this one included. Zero for a
67    /// demand that rendered nothing.
68    pub frame_generation: u64,
69    /// Whether the map changes after this frame without new commands: a
70    /// transition runs, or the symbols wait for a placement, which an update
71    /// of the map's own draws.
72    pub needs_repaint: bool,
73    /// The camera and extent that a rendered frame shows.
74    pub view: Option<MapView>,
75    /// Whether everything that a rendered frame shows had loaded.
76    pub mode: RenderMode,
77    /// Where a rendered frame drew the map, and the depth that it wrote.
78    pub projection: Option<FrameProjection>,
79}
80
81impl FrameResult {
82    /// The result of a demand that rendered nothing.
83    pub(crate) fn unrendered(token: Option<u64>, disposition: FrameDisposition, map_update_generation: u64) -> Self {
84        FrameResult {
85            disposition,
86            token,
87            map_update_generation,
88            generation: 0,
89            frame_generation: 0,
90            needs_repaint: false,
91            view: None,
92            mode: RenderMode::Partial,
93            projection: None,
94        }
95    }
96}