Skip to main content

mln_runtime/render/
frame.rs

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