euv-core 0.48.2

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Result returned by `FramePacingController::evaluate` for a single scheduling trigger.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct PacingDecision {
    /// Selected pacing action.
    #[get(type(copy))]
    pub(crate) action: PacingAction,
    /// Monotonic simulation delta time in seconds (`0.0` for deferred, capped, or lifecycle-only frames).
    #[get(type(copy))]
    pub(crate) sim_dt_secs: f32,
    /// Monotonic simulation delta time in integer nanoseconds (`0` for deferred, capped, or lifecycle-only frames).
    #[get(type(copy))]
    pub(crate) sim_dt_ns: u64,
    /// Monotonic VSync timestamp in nanoseconds associated with this decision.
    #[get(type(copy))]
    pub(crate) timestamp_ns: u64,
    /// Age of the oldest unpresented pending input event in milliseconds (`0.0` when none pending).
    #[get(type(copy))]
    pub(crate) input_age_ms: f32,
    /// Whether the caller should submit a rendered frame for this trigger.
    #[get(type(copy))]
    pub(crate) should_render: bool,
    /// Whether simulation clocks should advance on this trigger.
    #[get(type(copy))]
    pub(crate) should_step_sim: bool,
}

/// Telemetry counters summarizing VSync pacing health, double-gate avoidance, and spurious-step prevention.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct FramePacingStats {
    /// Total VSync opportunities processed.
    #[get(type(copy))]
    pub(crate) vsync_signals: u64,
    /// Total complete frames submitted.
    #[get(type(copy))]
    pub(crate) frames_submitted: u64,
    /// Total input/safe-area/fullscreen events cleanly deferred instead of spuriously advancing simulation.
    #[get(type(copy))]
    pub(crate) deferred_non_vsync_events: u64,
    /// Total VSyncs skipped solely due to an explicit user FPS cap below display refresh rate.
    #[get(type(copy))]
    pub(crate) user_cap_skips: u64,
    /// Total VSyncs deferred due to bounded in-flight frame backpressure.
    #[get(type(copy))]
    pub(crate) in_flight_waits: u64,
    /// Estimated missed VSync intervals where consecutive timestamps exceeded `1.5x` the nominal period.
    #[get(type(copy))]
    pub(crate) missed_vsync_intervals: u64,
    /// Number of clock time-base rebases (resume or display refresh mode switches).
    #[get(type(copy))]
    pub(crate) timebase_rebases: u64,
}

/// Unified single-source frame pacing controller eliminating double-gating and preventing non-VSync events from advancing game time.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct FramePacingController {
    /// Active hardware display refresh rate in Hertz (e.g. `60.0`, `120.0`, `144.0`, `240.0`).
    #[get(type(copy))]
    pub(crate) display_hz: f32,
    /// Whether the platform present/VSync loop already paces frames natively (disables redundant software sleep/skip gates).
    #[get(type(copy))]
    pub(crate) native_vsync_active: bool,
    /// Optional explicit user FPS cap (`None` = run at full display refresh rate).
    #[get(skip)]
    pub(crate) user_fps_cap: Option<u32>,
    /// Maximum allowed concurrent in-flight frames (`1..=4`).
    #[get(type(copy))]
    pub(crate) max_in_flight_frames: u32,
    /// Currently submitted frames awaiting present/fence completion.
    #[get(type(copy))]
    pub(crate) in_flight_frames: u32,
    /// Last VSync monotonic timestamp in nanoseconds (`0` before first VSync or after rebase).
    #[get(type(copy))]
    pub(crate) last_vsync_ns: u64,
    /// Last VSync timestamp at which a frame was actually submitted (`StepAndRender`), tracked separately from `last_vsync_ns`.
    #[get(type(copy))]
    pub(crate) last_submitted_vsync_ns: u64,
    /// Last presented frame monotonic timestamp in nanoseconds for explicit user cap pacing.
    #[get(type(copy))]
    pub(crate) last_present_ns: u64,
    /// Fixed simulation step duration in nanoseconds used to clamp `sim_dt_ns <= 2 * fixed_step_ns`.
    #[get(type(copy))]
    pub(crate) fixed_step_ns: u64,
    /// Monotonic timestamp of the earliest unpresented input event (`0` when no input is pending).
    #[get(type(copy))]
    pub(crate) oldest_pending_input_ns: u64,
    /// Whether a non-VSync input event marked the viewport dirty for the next VSync.
    #[get(type(copy))]
    pub(crate) pending_input_dirty: bool,
    /// Whether a safe-area or fullscreen transition marked layout dirty for the next VSync.
    #[get(type(copy))]
    pub(crate) pending_layout_dirty: bool,
    /// Cumulative pacing telemetry counters.
    #[get(type(copy))]
    pub(crate) stats: FramePacingStats,
}