#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum FrameAction {
Skip,
CommitFull,
CommitDamaged,
}
impl FrameAction {
#[must_use]
pub const fn commits(self) -> bool {
!matches!(self, Self::Skip)
}
}
#[derive(Debug)]
pub struct FrameEconomy {
first: bool,
force_full: bool,
committed: u64,
skipped: u64,
}
impl Default for FrameEconomy {
fn default() -> Self {
Self::new()
}
}
impl FrameEconomy {
#[must_use]
pub const fn new() -> Self {
Self {
first: true,
force_full: false,
committed: 0,
skipped: 0,
}
}
pub const fn decide(&mut self, content_changed: bool, damage_available: bool) -> FrameAction {
if self.first || self.force_full {
self.first = false;
self.force_full = false;
self.committed += 1;
return FrameAction::CommitFull;
}
if !content_changed {
self.skipped += 1;
return FrameAction::Skip;
}
self.committed += 1;
if damage_available {
FrameAction::CommitDamaged
} else {
FrameAction::CommitFull
}
}
pub const fn force_full(&mut self) {
self.force_full = true;
}
#[must_use]
pub const fn committed(&self) -> u64 {
self.committed
}
#[must_use]
pub const fn skipped(&self) -> u64 {
self.skipped
}
}