diff --git a/src/lib.rs b/src/lib.rs index fd9d95a..5827b28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ pub mod framework; pub mod body; pub mod instruction; +pub mod timelines; diff --git a/src/timelines.rs b/src/timelines.rs new file mode 100644 index 0000000..6268f48 --- /dev/null +++ b/src/timelines.rs @@ -0,0 +1,47 @@ +type ORDER = u32; + +pub struct Tracker { + order: ORDER, +} + +pub struct TimelineInstruction{ + 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, +} + +pub struct Timeline{ + instructions: std::collections::VecDeque>, + trackers: Vec,//wrong +} + +impl Timeline{ + pub fn new() -> Self { + Self{ + instructions:std::collections::VecDeque::>::new(), + trackers:Vec::::new(), + } + } + + pub fn len(&self) -> usize { + return self.instructions.len() + } + pub fn first(&self) -> Option<&TimelineInstruction> { + return self.instructions.get(0) + } + pub fn last(&self) -> Option<&TimelineInstruction> { + return self.instructions.get(self.instructions.len()-1) + } + pub fn append(&mut self,instruction:TimelineInstruction){ + 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 usize{ + self.instructions.partition_point(|ins|ins.order