#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PingPong {
active: usize,
drawn: bool,
single: bool,
}
impl PingPong {
#[must_use]
pub const fn new() -> Self {
Self {
active: 0,
drawn: false,
single: false,
}
}
#[must_use]
pub const fn single() -> Self {
Self {
active: 0,
drawn: false,
single: true,
}
}
#[must_use]
pub const fn active(self) -> usize {
self.active
}
#[must_use]
pub const fn draw_target(self) -> usize {
if self.single {
self.active
} else {
self.active ^ 1
}
}
#[must_use]
pub const fn commit_target(self) -> usize {
if self.drawn && !self.single {
self.active ^ 1
} else {
self.active
}
}
pub const fn mark_drawn(&mut self) {
if !self.single {
self.drawn = true;
}
}
#[must_use]
pub const fn has_undrawn(self) -> bool {
self.drawn
}
pub const fn published(&mut self) {
if self.drawn {
self.active ^= 1;
self.drawn = false;
}
}
}
impl Default for PingPong {
fn default() -> Self {
Self::new()
}
}