From 223119654b4835c270ce4215f156e3c6236833b8 Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Thu, 19 Dec 2019 20:16:20 +0100 Subject: Initial commit --- src/doublebuffer.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/doublebuffer.rs (limited to 'src/doublebuffer.rs') diff --git a/src/doublebuffer.rs b/src/doublebuffer.rs new file mode 100644 index 0000000..563f157 --- /dev/null +++ b/src/doublebuffer.rs @@ -0,0 +1,31 @@ +pub struct DoubleBuffer { + a1: Vec, + a2: Vec, + switch: bool, +} + +impl DoubleBuffer { + pub fn new(a1: Vec, a2: Vec) -> Self { + Self { a1, a2, switch: false } + } + + pub fn switch(&mut self) { + self.switch = !self.switch; + } + + pub fn first(&self) -> &Vec { + if self.switch { &self.a2 } else { &self.a1 } + } + + pub fn first_mut(&mut self) -> &mut Vec { + if self.switch { &mut self.a2 } else { &mut self.a1 } + } + + pub fn second(&self) -> &Vec { + if self.switch { &self.a1 } else { &self.a2 } + } + + pub fn second_mut(&mut self) -> &mut Vec { + if self.switch { &mut self.a1 } else { &mut self.a2 } + } +} -- cgit v1.2.3-54-g00ecf