Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
db4ba34a42 | |||
56ccc4b58b |
@ -1,5 +1,6 @@
|
||||
pub mod bvh;
|
||||
pub mod map;
|
||||
pub mod run;
|
||||
pub mod aabb;
|
||||
pub mod model;
|
||||
pub mod zeroes;
|
||||
|
70
src/run.rs
Normal file
70
src/run.rs
Normal file
@ -0,0 +1,70 @@
|
||||
use crate::timer::{Timer,Scaled,Error as TimerError};
|
||||
use crate::integer::Time;
|
||||
|
||||
pub enum InvalidationReason{
|
||||
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error{
|
||||
AlreadyStarted,
|
||||
NotStarted,
|
||||
AlreadyFinished,
|
||||
}
|
||||
impl std::fmt::Display for Error{
|
||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
write!(f,"{self:?}")
|
||||
}
|
||||
}
|
||||
impl std::error::Error for Error{}
|
||||
|
||||
enum RunState{
|
||||
Created{timer:Timer<Paused>},
|
||||
Started{timer:Timer<Unpaused>},
|
||||
Finished{timer:Timer<Paused>},
|
||||
}
|
||||
|
||||
pub struct Run{
|
||||
invalidated:Option<InvalidationReason>,
|
||||
created:Time,
|
||||
state:RunState,
|
||||
}
|
||||
|
||||
impl Run{
|
||||
pub fn new(created:Time)->Self{
|
||||
Self{
|
||||
timer:Timer::scaled_paused(
|
||||
created,
|
||||
Time::ZERO,
|
||||
crate::integer::Ratio64::ONE,
|
||||
),
|
||||
invalidated:None,
|
||||
created,
|
||||
started:None,
|
||||
finished:None,
|
||||
}
|
||||
}
|
||||
pub fn start(&mut self,time:Time)->Result<(),Error>{
|
||||
match self.started{
|
||||
Some(_)=>Err(Error::AlreadyStarted),
|
||||
None=>{
|
||||
self.started=Some(time);
|
||||
self.timer.unpause(time).map_err(Error::Timer)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn finish(&mut self,time:Time)->Result<(),Error>{
|
||||
if self.started.is_none(){
|
||||
return Err(Error::NotStarted);
|
||||
}
|
||||
match self.finished{
|
||||
Some(_)=>Err(Error::AlreadyFinished),
|
||||
None=>{
|
||||
self.finished=Some(time);
|
||||
self.timer.pause(time).map_err(Error::Timer)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user