add functions to Head

This commit is contained in:
2026-02-27 06:39:19 -08:00
parent e88d62c3ea
commit 508a0db66f

View File

@@ -782,6 +782,18 @@ impl Head{
pub const fn new()->Self{ pub const fn new()->Self{
Self([0;NUM_EVENT_TYPES]) Self([0;NUM_EVENT_TYPES])
} }
pub fn after_time(block:&Block,time:f64)->Self{
Self([
block.input_events.partition_point(|event|time<=event.time),
block.output_events.partition_point(|event|time<=event.time),
block.sound_events.partition_point(|event|time<=event.time),
block.world_events.partition_point(|event|time<=event.time),
block.gravity_events.partition_point(|event|time<=event.time),
block.run_events.partition_point(|event|time<=event.time),
block.camera_events.partition_point(|event|time<=event.time),
block.setting_events.partition_point(|event|time<=event.time),
])
}
// compare an event at the head of the plan to the best event collected so far. // compare an event at the head of the plan to the best event collected so far.
fn collect_event<E>( fn collect_event<E>(
&self, &self,
@@ -822,6 +834,9 @@ impl Head{
pub const fn get_event_index(&self,event_type:EventType)->usize{ pub const fn get_event_index(&self,event_type:EventType)->usize{
self.0[event_type as usize] self.0[event_type as usize]
} }
pub const fn set_event_index(&mut self,event_type:EventType,index:usize){
self.0[event_type as usize]=index;
}
/// Add the new event. /// Add the new event.
pub const fn push(&mut self,event_type:EventType){ pub const fn push(&mut self,event_type:EventType){
self.0[event_type as usize]+=1; self.0[event_type as usize]+=1;