forked from StrafesNET/roblox-bot-player
lib: initialize PlaybackState more thoroughly
This commit is contained in:
@@ -194,22 +194,43 @@ impl PlaybackState{
|
||||
}
|
||||
}
|
||||
pub(crate) fn process_head(&mut self,block:&v0::Block,head:&v0::Head){
|
||||
// The whole point of this is to avoid running the realtime events!
|
||||
/*
|
||||
for event in &block.input_events[0..head.get_event_index(v0::EventType::Input)]{
|
||||
// Avoid running the realtime events from the beginning.
|
||||
// Run the preceding input event to initialize the state.
|
||||
if let Some(index)=head.get_event_index(v0::EventType::Input).checked_sub(1)
|
||||
&&let Some(event)=block.input_events.get(index)
|
||||
{
|
||||
self.push_input(&event.event);
|
||||
}
|
||||
for event in &block.output_events[0..head.get_event_index(v0::EventType::Output)]{
|
||||
|
||||
// Helper function
|
||||
fn is_output_tick_end(&(_,event):&(usize,&v0::Timed<v0::OutputEvent>))->bool{
|
||||
event.event.tick_info.contains(v0::TickInfo::TickEnd)
|
||||
}
|
||||
// Run two preceding output events to flush out the default state.
|
||||
let output_end_index=head.get_event_index(v0::EventType::Output);
|
||||
let mut it=block.output_events[..output_end_index].iter().enumerate().rev();
|
||||
// Find two TickEnd events before output_end_index
|
||||
let _first=it.find(is_output_tick_end);
|
||||
let second=it.find(is_output_tick_end);
|
||||
// Get the index at the second event, if two TickEnd events don't exist then start at 0
|
||||
let output_start_index=second.map_or(0,|(i,_)|i);
|
||||
for event in &block.output_events[output_start_index..output_end_index]{
|
||||
self.push_output(&event.event);
|
||||
}
|
||||
for event in &bot.sound_events[0..head.get_event_index(v0::EventType::Sound)]{
|
||||
self.push_sound(&event.event);
|
||||
}
|
||||
*/
|
||||
|
||||
// for event in &bot.sound_events[0..head.get_event_index(v0::EventType::Sound)]{
|
||||
// self.push_sound(&event.event);
|
||||
// }
|
||||
|
||||
// Offline events have to be run from the beginning because they contain cumulative state.
|
||||
// for event in &bot.world_events[0..head.get_event_index(v0::EventType::World)]{
|
||||
// self.push_world(&event.event);
|
||||
// }
|
||||
for event in &block.gravity_events[0..head.get_event_index(v0::EventType::Gravity)]{
|
||||
|
||||
// Except for gravity, only the most recent event is relevant.
|
||||
if let Some(index)=head.get_event_index(v0::EventType::Gravity).checked_sub(1)
|
||||
&&let Some(event)=block.gravity_events.get(index)
|
||||
{
|
||||
self.push_gravity(&event.event);
|
||||
}
|
||||
for event in &block.run_events[0..head.get_event_index(v0::EventType::Run)]{
|
||||
|
||||
Reference in New Issue
Block a user