Compare commits
3 Commits
bot-playba
...
bot-resimu
| Author | SHA1 | Date | |
|---|---|---|---|
| d4b6dfc71c | |||
| 16575eb777 | |||
| cc33eeb2ad |
@@ -1811,4 +1811,46 @@ mod test{
|
||||
Time::ZERO
|
||||
),None);
|
||||
}
|
||||
fn simulate(map:&str,bot:&str){
|
||||
//create physics
|
||||
let mut physics=PhysicsContext::default();
|
||||
|
||||
//load map
|
||||
let map_file=std::fs::File::open(format!("/run/media/quat/Files/Documents/map-files/verify-scripts/maps/{map}.snfm")).unwrap();
|
||||
let map=strafesnet_snf::read_map(map_file).unwrap().into_complete_map().unwrap();
|
||||
physics.generate_models(&map);
|
||||
|
||||
//load bot
|
||||
let bot_file=std::fs::File::open(format!("/run/media/quat/Files/Documents/Strafe Client/debug_bots_v1/{bot}")).unwrap();
|
||||
let instructions=strafesnet_snf::bot::read_bot_debug(bot_file).unwrap();
|
||||
|
||||
//run bot on physics
|
||||
for ins in instructions{
|
||||
physics.run_input_instruction(ins);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn simulate_bot_1(){
|
||||
//arcane
|
||||
simulate("bhop_snfm/5692113331","ff4940efb50f724e48eb54ce3593d88f")
|
||||
}
|
||||
#[test]
|
||||
fn simulate_bot_2(){
|
||||
simulate("bhop_snfm/5692113331","17cf70412eba16d172a67385cab5727e")
|
||||
}
|
||||
#[test]
|
||||
fn simulate_bot_4(){
|
||||
//brick
|
||||
simulate("bhop_snfm/5692176057","c0631c6f524eebddbf75237cac48e78e")
|
||||
}
|
||||
#[test]
|
||||
fn simulate_bot_5(){
|
||||
//toc
|
||||
simulate("bhop_snfm/5692152916","1722976199076914659")
|
||||
}
|
||||
#[test]
|
||||
fn simulate_bot_6(){
|
||||
//utopia
|
||||
simulate("surf_snfm/5692145408","1722980796007573431")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,83 +208,15 @@ impl MouseInterpolator{
|
||||
}
|
||||
}
|
||||
|
||||
struct PlayBacker{
|
||||
//Instructions
|
||||
timeline:std::collections::VecDeque<TimedInstruction<PhysicsInputInstruction>>,
|
||||
//"Simulation"
|
||||
timer:Timer<Scaled>,
|
||||
physics:crate::physics::PhysicsContext,
|
||||
}
|
||||
impl PlayBacker{
|
||||
pub fn new(
|
||||
physics:crate::physics::PhysicsContext,
|
||||
timeline:std::collections::VecDeque<TimedInstruction<PhysicsInputInstruction>>,
|
||||
)->Self{
|
||||
Self{
|
||||
timeline,
|
||||
timer:Timer::from_state(Scaled::identity(),false),
|
||||
physics,
|
||||
}
|
||||
}
|
||||
fn run(&mut self,time:Time){
|
||||
//all this does is advance the simulation to the instruction's timestamp
|
||||
let simulation_time=self.timer.time(time);
|
||||
while let Some(ins)=self.timeline.get(0){
|
||||
if ins.time<simulation_time{
|
||||
//run that sucker
|
||||
let ins=self.timeline.pop_front().unwrap();
|
||||
self.physics.run_input_instruction(ins);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn handle_instruction(&mut self,TimedInstruction{time,instruction}:&TimedInstruction<Instruction>){
|
||||
//match the instruction so the playback is pausable :D
|
||||
match instruction{
|
||||
&Instruction::SetPaused(paused)=>{
|
||||
let _=self.timer.set_paused(*time,paused);
|
||||
},
|
||||
_=>(),
|
||||
}
|
||||
self.run(*time);
|
||||
//idle the physics to allow any internal events to run (collisions mostly)
|
||||
self.physics.run_input_instruction(TimedInstruction{
|
||||
time:self.timer.time(*time),
|
||||
instruction:PhysicsInputInstruction::Idle,
|
||||
});
|
||||
}
|
||||
pub fn get_render_stuff(&self,time:Time)->(crate::physics::PhysicsOutputState,Time,glam::IVec2){
|
||||
(self.physics.output(),self.timer.time(time),self.physics.get_next_mouse().pos)
|
||||
}
|
||||
pub fn user_settings(&self)->crate::settings::UserSettings{
|
||||
//oof, settings ignored
|
||||
crate::settings::UserSettings::default()
|
||||
}
|
||||
pub fn change_map(&mut self,time:Time,map:&strafesnet_common::map::CompleteMap){
|
||||
self.run(time);
|
||||
self.physics.generate_models(&map);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new<'a>(
|
||||
mut graphics_worker:crate::compat_worker::INWorker<'a,crate::graphics_worker::Instruction>,
|
||||
user_settings:crate::settings::UserSettings,
|
||||
)->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction>>{
|
||||
let physics=crate::physics::PhysicsContext::default();
|
||||
/*
|
||||
let mut interpolator=MouseInterpolator::new(
|
||||
physics,
|
||||
user_settings
|
||||
);
|
||||
*/
|
||||
//load bot
|
||||
let bot_file=std::fs::File::open(format!("/run/media/quat/Files/Documents/Strafe Client/debug_bots_v2/1723150291506606436")).unwrap();
|
||||
let instructions=strafesnet_snf::bot::read_bot_debug(bot_file).unwrap();
|
||||
let mut interpolator=PlayBacker::new(
|
||||
physics,
|
||||
instructions.into(),
|
||||
);
|
||||
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{
|
||||
interpolator.handle_instruction(&ins);
|
||||
match ins.instruction{
|
||||
|
||||
Reference in New Issue
Block a user