wip: timelines

This commit is contained in:
Quaternions 2023-09-08 12:33:49 -07:00
parent c565120ea7
commit 53d2b5b3f5
2 changed files with 48 additions and 0 deletions

View File

@ -1,3 +1,4 @@
pub mod framework; pub mod framework;
pub mod body; pub mod body;
pub mod instruction; pub mod instruction;
pub mod timelines;

47
src/timelines.rs Normal file
View File

@ -0,0 +1,47 @@
type ORDER = u32;
pub struct Tracker {
order: ORDER,
}
pub struct TimelineInstruction<I>{
pub order: ORDER,//absolute ordering of instructions which can be used for sorting even when there are multiple simultaneous timestamps
pub instruction: crate::instruction::TimedInstruction<I>,
}
pub struct Timeline<I>{
instructions: std::collections::VecDeque<TimelineInstruction<I>>,
trackers: Vec<Tracker>,//wrong
}
impl<I> Timeline<I>{
pub fn new() -> Self {
Self{
instructions:std::collections::VecDeque::<TimelineInstruction<I>>::new(),
trackers:Vec::<Tracker>::new(),
}
}
pub fn len(&self) -> usize {
return self.instructions.len()
}
pub fn first(&self) -> Option<&TimelineInstruction<I>> {
return self.instructions.get(0)
}
pub fn last(&self) -> Option<&TimelineInstruction<I>> {
return self.instructions.get(self.instructions.len()-1)
}
pub fn append(&mut self,instruction:TimelineInstruction<I>){
let i=self.instructions.len();
self.instructions.push_back(instruction);
for tracker in self.trackers.iter() {
tracker.set_active(true);
}
}
pub fn get_index_after_time(&mut self,time:crate::body::TIME) -> usize{
self.instructions.partition_point(|ins|ins.instruction.time<time)
}
pub fn get_index_after_order(&mut self,order:ORDER) -> usize{
self.instructions.partition_point(|ins|ins.order<order)
}
}