use Head for playback

This commit is contained in:
2026-02-19 08:02:20 -08:00
parent a9db4e38eb
commit 56a7912dbf

View File

@@ -2,6 +2,7 @@ use glam::Vec3Swizzles;
use strafesnet_common::timer::{Timer,Scaled};
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};
use strafesnet_common::physics::{Time as PhysicsTime,TimeInner as PhysicsTimeInner};
use strafesnet_roblox_bot_file::v0::{EventType,Head};
pub enum PlaybackInstructionInternal{
Sound
@@ -18,15 +19,21 @@ fn vector3_to_glam(v:&strafesnet_roblox_bot_file::v0::Vector3)->glam::Vec3{
/// A playback context. Advance time and then generate a camera position to pass to the renderer.
pub struct PlaybackHead{
//"Simulation"
event_id:usize,
head:Head,
offset:f64,
timer:Timer<Scaled<SessionTimeInner,PhysicsTimeInner>>,
}
const HEAD_NO_CRASH:Head={
let mut head=Head::new();
// push one output event so that output-1 doesn't underflow
head.push(EventType::Output);
head
};
impl PlaybackHead{
pub fn new(time:SessionTime)->Self{
let timer=Timer::unpaused(time,PhysicsTime::ZERO);
Self{
event_id:0,
head:HEAD_NO_CRASH,
offset:0.0,
timer,
}
@@ -35,17 +42,17 @@ impl PlaybackHead{
let simulation_time=self.timer.time(time);
let mut time_float=simulation_time.get() as f64/PhysicsTime::ONE_SECOND.get() as f64+self.offset+bot.offset();
loop{
match bot.timelines().output_events.get(self.event_id+1){
match self.head.next_event(bot.timelines()){
Some(next_event)=>{
if next_event.time<time_float{
self.event_id+=1;
self.head.push(next_event.event);
}else{
break;
}
},
None=>{
//reset playback
self.event_id=0;
self.head=HEAD_NO_CRASH;
self.offset-=bot.duration();
time_float-=bot.duration();
},
@@ -54,8 +61,8 @@ impl PlaybackHead{
}
pub fn get_position_angles(&self,bot:&crate::bot::CompleteBot,time:SessionTime)->(glam::Vec3,glam::Vec2){
let time=self.timer.time(time);
let event0=&bot.timelines().output_events[self.event_id];
let event1=&bot.timelines().output_events[self.event_id+1];
let event0=&bot.timelines().output_events[self.head.get_event_index(EventType::Output)-1];
let event1=&bot.timelines().output_events[self.head.get_event_index(EventType::Output)];
let p0=vector3_to_glam(&event0.event.position);
let p1=vector3_to_glam(&event1.event.position);
// let v0=vector3_to_glam(&event0.event.velocity);