mln-rs-engine 0.0.22

Part of mln-rs, a MapLibre map renderer written in Rust. Depend on mln-rs instead.
Documentation
//! What a frame's update hands its encode.

use std::sync::Arc;

use mln_style::color::Color;
use mln_style::time::Instant;

use crate::camera::View;
use crate::placement::TestedShape;
use crate::render::light::EvaluatedLight;
use crate::render::paint_parameters::TransformParameters;
use crate::render::sky::EvaluatedSky;

/// A frame, as its update leaves it for its encode: the camera, the values
/// that the whole frame draws with, and the layers it draws.
pub(crate) struct Frame {
    pub(crate) transform: TransformParameters,
    /// Whether a gesture or an animation moves the camera.
    pub(crate) camera_moving: bool,
    /// The frame's time, from the host's clock; `None` in still modes.
    pub(crate) time_point: Option<Instant>,
    pub(crate) light: EvaluatedLight,
    pub(crate) sky: Option<EvaluatedSky>,
    /// Whether the frame draws terrain, which the layers that drape over it
    /// don't draw onto, and under which the other 2D layers draw without
    /// depth.
    pub(crate) terrain: bool,
    /// What the frame clears to: transparent black unless the style's
    /// bottom layer is a solid background.
    pub(crate) background_color: Color,
    pub(crate) symbol_fade_change: f32,
    /// Whether a transition or a fade still runs, which the next frame
    /// continues.
    pub(crate) needs_repaint: bool,
    /// When, without `needs_repaint`, the map changes next on its own: a
    /// symbol placement that isn't due yet.
    pub(crate) repaint_at: Option<Instant>,
    /// Whether every source, image and tile the frame needs had loaded.
    pub(crate) loaded: bool,
    pub(crate) placement_changed: bool,
    /// The indexes of the layers the frame draws, in the drawing order.
    pub(crate) layers: Vec<u32>,
    /// When the frame's update started.
    pub(crate) started: Instant,
    /// When the frame's update started placing symbols.
    pub(crate) symbols_started: Instant,
    /// The shapes the frame's placement tested, while a layer the frame
    /// draws reads them.
    pub(crate) collision_shapes: Option<Arc<Vec<TestedShape>>>,
}

impl Frame {
    /// A frame of `state` at `time_point` that draws no layers, started now.
    pub(crate) fn new(state: &View, camera_moving: bool, time_point: Option<Instant>) -> Self {
        let started = Instant::now();
        Frame {
            transform: TransformParameters::new(state),
            camera_moving,
            time_point,
            light: EvaluatedLight::default(),
            sky: None,
            terrain: false,
            background_color: Color::default(),
            symbol_fade_change: 0.0,
            needs_repaint: false,
            repaint_at: None,
            loaded: false,
            placement_changed: false,
            layers: Vec::new(),
            started,
            symbols_started: started,
            collision_shapes: None,
        }
    }
}