Compare commits

..

3 Commits

Author SHA1 Message Date
d4b6dfc71c edit sim tests 2024-08-08 13:48:44 -07:00
16575eb777 update bots location 2024-08-08 13:36:11 -07:00
cc33eeb2ad resimulation as tests 2024-08-08 13:24:55 -07:00
6 changed files with 46 additions and 61 deletions

@ -1,35 +0,0 @@
use strafesnet_snf::bot::BotDebug;
pub enum Instruction{
//TODO: pass map id
Create,
//Delete,
Push{
ins:strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>,
},
}
//a new worker is spawned on a thread
//create opens a new file
//push pushes an instruction to the file
pub struct Worker{
file:BotDebug,
}
fn date()->String{
format!("/run/media/quat/Files/Documents/Strafe Client/debug_bots_v2/{}",std::time::SystemTime::UNIX_EPOCH.elapsed().unwrap().as_nanos())
}
pub fn new<'a>(scope:&'a std::thread::Scope<'a,'_>)->crate::worker::QNWorker<'a,Instruction>{
let mut worker=Worker{
file:BotDebug::new(date()).unwrap(),
};
crate::worker::QNWorker::new(scope,move|instruction|{
match instruction{
Instruction::Create=>worker.file=BotDebug::new(date()).unwrap(),
//Instruction::Delete=>worker.file.delete().unwrap(),
Instruction::Push{ins}=>worker.file.push(ins).unwrap(),
}
})
}

@ -5,7 +5,6 @@ mod worker;
mod physics;
mod graphics;
mod settings;
mod bot_worker;
mod face_crawler;
mod compat_worker;
mod model_physics;

@ -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")
}
}

@ -32,33 +32,29 @@ pub enum Instruction{
mod mouse_interpolator{
use super::*;
//TODO: move this or tab
pub struct MouseInterpolator<'a>{
pub struct MouseInterpolator{
//"PlayerController"
user_settings:crate::settings::UserSettings,
//"MouseInterpolator"
timeline:std::collections::VecDeque<TimedInstruction<PhysicsInputInstruction>>,
last_mouse_time:Time,//this value is pre-transformed to simulation time
mouse_blocking:bool,
//????
bot_worker:crate::worker::QNWorker<'a,crate::bot_worker::Instruction>,
//"Simulation"
timer:Timer<Scaled>,
physics:crate::physics::PhysicsContext,
}
impl MouseInterpolator<'_>{
pub fn new<'a>(
impl MouseInterpolator{
pub fn new(
physics:crate::physics::PhysicsContext,
bot_worker:crate::worker::QNWorker<'a,crate::bot_worker::Instruction>,
user_settings:crate::settings::UserSettings,
)->MouseInterpolator<'a>{
)->MouseInterpolator{
MouseInterpolator{
mouse_blocking:true,
last_mouse_time:physics.get_next_mouse().time,
timeline:std::collections::VecDeque::new(),
timer:Timer::from_state(Scaled::identity(),false),
physics,
bot_worker,
user_settings,
}
}
@ -175,13 +171,6 @@ impl MouseInterpolator<'_>{
}
fn empty_queue(&mut self){
while let Some(instruction)=self.timeline.pop_front(){
//makeshift clone because requiring all TimedInstructions to be Clone is troublesome
self.bot_worker.send(crate::bot_worker::Instruction::Push{
ins:TimedInstruction{
time:instruction.time,
instruction:instruction.instruction.clone(),
}
}).unwrap();
self.physics.run_input_instruction(instruction);
}
}
@ -222,12 +211,10 @@ impl MouseInterpolator<'_>{
pub fn new<'a>(
mut graphics_worker:crate::compat_worker::INWorker<'a,crate::graphics_worker::Instruction>,
user_settings:crate::settings::UserSettings,
bot_worker:crate::worker::QNWorker<'a,crate::bot_worker::Instruction>,
)->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction>>{
let physics=crate::physics::PhysicsContext::default();
let mut interpolator=MouseInterpolator::new(
physics,
bot_worker,
user_settings
);
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{

@ -213,13 +213,10 @@ pub fn setup_and_start(title:String){
//dedicated thread to ping request redraw back and resize the window doesn't seem logical
std::thread::scope(|scope|{
//TODO: TAB
//the thread that spawns the physics thread
let mut window_thread=crate::window::worker(
&window,
setup_context,
scope
);
if let Some(arg)=std::env::args().nth(1){
@ -233,7 +230,6 @@ pub fn setup_and_start(title:String){
println!("Entering event loop...");
let root_time=std::time::Instant::now();
run_event_loop(event_loop,window_thread,root_time).unwrap();
});
}
fn run_event_loop(

@ -168,7 +168,6 @@ impl WindowContext<'_>{
pub fn worker<'a>(
window:&'a winit::window::Window,
setup_context:crate::setup::SetupContext<'a>,
scope:&'a std::thread::Scope<'a,'_>,
)->crate::compat_worker::QNWorker<'a,TimedInstruction<WindowInstruction>>{
// WindowContextSetup::new
let user_settings=crate::settings::read_user_settings();
@ -179,8 +178,6 @@ pub fn worker<'a>(
//WindowContextSetup::into_context
let screen_size=glam::uvec2(setup_context.config.width,setup_context.config.height);
let graphics_thread=crate::graphics_worker::new(graphics,setup_context.config,setup_context.surface,setup_context.device,setup_context.queue);
//this obviously doesn't belong here, do something about it pls
let bot_thread=crate::bot_worker::new(scope);
let mut window_context=WindowContext{
manual_mouse_lock:false,
mouse:strafesnet_common::mouse::MouseState::default(),
@ -190,7 +187,6 @@ pub fn worker<'a>(
physics_thread:crate::physics_worker::new(
graphics_thread,
user_settings,
bot_thread,
),
};