17 Commits

Author SHA1 Message Date
d37ea33b1e constructors and destructors for serialization 2024-08-01 08:41:50 -07:00
540e4a25fb tests 2024-07-31 20:59:34 -07:00
270663e529 Timer constructors & traits 2024-07-31 20:59:31 -07:00
e55be91d24 change api 2024-07-31 19:06:54 -07:00
a98b71f0da un/pause mutate self instead of taking ownership (uses Copy) 2024-07-31 18:39:15 -07:00
d58af1f2b2 change function name to reflect what it does 2024-07-31 18:28:55 -07:00
42b1ae98f7 silence all warnings 2024-07-31 17:50:44 -07:00
63cc55d20c implement debug 2024-07-31 16:10:15 -07:00
1751356e3c TimerFixed is Copy 2024-07-31 15:59:10 -07:00
7736a1f8a2 it's one type 2024-07-31 15:56:53 -07:00
ccadc934ac perfection 2024-07-31 14:35:43 -07:00
78db4168a5 constructors 2024-07-31 14:21:35 -07:00
ce0572485b tweak 2024-07-31 14:09:57 -07:00
b55ba418aa tweak 2024-07-31 14:05:52 -07:00
852bbe6dad timer revelations 2024-07-31 13:57:59 -07:00
6a12d213e8 not right 2024-07-31 13:15:29 -07:00
4e4adcb934 timers 2024-07-31 12:10:35 -07:00
2 changed files with 0 additions and 104 deletions

View File

@@ -1,6 +1,5 @@
pub mod bvh;
pub mod map;
pub mod run;
pub mod aabb;
pub mod model;
pub mod timer;

View File

@@ -1,103 +0,0 @@
use crate::timer::{TimerFixed,Realtime,Paused,Unpaused};
use crate::integer::Time;
#[derive(Clone,Debug)]
pub enum FlagReason{
Anticheat,
StyleChange,
Clock,
Pause,
Flying,
Gravity,
Timescale,
TimeTravel,
Teleport,
}
impl ToString for FlagReason{
fn to_string(&self)->String{
match self{
FlagReason::Anticheat=>"Passed through anticheat zone.",
FlagReason::StyleChange=>"Changed style.",
FlagReason::Clock=>"Incorrect clock. (This can be caused by internet hiccups)",
FlagReason::Pause=>"Pausing is not allowed in this style.",
FlagReason::Flying=>"Flying is not allowed in this style.",
FlagReason::Gravity=>"Gravity modification is not allowed in this style.",
FlagReason::Timescale=>"Timescale is not allowed in this style.",
FlagReason::TimeTravel=>"Time travel is not allowed in this style.",
FlagReason::Teleport=>"Illegal teleport.",
}.to_owned()
}
}
#[derive(Debug)]
pub enum Error{
NotStarted,
AlreadyStarted,
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{}
#[derive(Clone,Debug)]
enum RunState{
Created,
Started{timer:TimerFixed<Realtime,Unpaused>},
Finished{timer:TimerFixed<Realtime,Paused>},
}
#[derive(Clone,Debug)]
pub struct Run{
state:RunState,
flagged:Option<FlagReason>,
}
impl Run{
pub fn new()->Self{
Self{
state:RunState::Created,
flagged:None,
}
}
pub fn time(&self,time:Time)->Time{
match &self.state{
RunState::Created=>Time::ZERO,
RunState::Started{timer}=>timer.time(time),
RunState::Finished{timer}=>timer.time(time),
}
}
pub fn start(&mut self,time:Time)->Result<(),Error>{
match &self.state{
RunState::Created=>{
self.state=RunState::Started{
timer:TimerFixed::new(time,Time::ZERO),
};
Ok(())
},
RunState::Started{..}=>Err(Error::AlreadyStarted),
RunState::Finished{..}=>Err(Error::AlreadyFinished),
}
}
pub fn finish(&mut self,time:Time)->Result<(),Error>{
//this uses Copy
match &self.state{
RunState::Created=>Err(Error::NotStarted),
RunState::Started{timer}=>{
self.state=RunState::Finished{
timer:timer.into_paused(time),
};
Ok(())
},
RunState::Finished{..}=>Err(Error::AlreadyFinished),
}
}
pub fn flag(&mut self,flag_reason:FlagReason){
//don't replace the first reason the run was flagged
if self.flagged.is_none(){
self.flagged=Some(flag_reason);
}
}
}