Compare commits

..

4 Commits

Author SHA1 Message Date
0b1a4a0ad4 hardcode new file 2024-08-08 14:05:33 -07:00
c37069c566 utopia bot 2024-08-08 13:24:21 -07:00
48dfe8bc40 toc bot 2024-08-08 13:24:21 -07:00
c0d543301e bot player 2024-08-08 13:24:21 -07:00
5 changed files with 72 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 physics;
mod graphics; mod graphics;
mod settings; mod settings;
mod bot_worker;
mod face_crawler; mod face_crawler;
mod compat_worker; mod compat_worker;
mod model_physics; mod model_physics;

@ -32,33 +32,29 @@ pub enum Instruction{
mod mouse_interpolator{ mod mouse_interpolator{
use super::*; use super::*;
//TODO: move this or tab //TODO: move this or tab
pub struct MouseInterpolator<'a>{ pub struct MouseInterpolator{
//"PlayerController" //"PlayerController"
user_settings:crate::settings::UserSettings, user_settings:crate::settings::UserSettings,
//"MouseInterpolator" //"MouseInterpolator"
timeline:std::collections::VecDeque<TimedInstruction<PhysicsInputInstruction>>, timeline:std::collections::VecDeque<TimedInstruction<PhysicsInputInstruction>>,
last_mouse_time:Time,//this value is pre-transformed to simulation time last_mouse_time:Time,//this value is pre-transformed to simulation time
mouse_blocking:bool, mouse_blocking:bool,
//????
bot_worker:crate::worker::QNWorker<'a,crate::bot_worker::Instruction>,
//"Simulation" //"Simulation"
timer:Timer<Scaled>, timer:Timer<Scaled>,
physics:crate::physics::PhysicsContext, physics:crate::physics::PhysicsContext,
} }
impl MouseInterpolator<'_>{ impl MouseInterpolator{
pub fn new<'a>( pub fn new(
physics:crate::physics::PhysicsContext, physics:crate::physics::PhysicsContext,
bot_worker:crate::worker::QNWorker<'a,crate::bot_worker::Instruction>,
user_settings:crate::settings::UserSettings, user_settings:crate::settings::UserSettings,
)->MouseInterpolator<'a>{ )->MouseInterpolator{
MouseInterpolator{ MouseInterpolator{
mouse_blocking:true, mouse_blocking:true,
last_mouse_time:physics.get_next_mouse().time, last_mouse_time:physics.get_next_mouse().time,
timeline:std::collections::VecDeque::new(), timeline:std::collections::VecDeque::new(),
timer:Timer::from_state(Scaled::identity(),false), timer:Timer::from_state(Scaled::identity(),false),
physics, physics,
bot_worker,
user_settings, user_settings,
} }
} }
@ -175,13 +171,6 @@ impl MouseInterpolator<'_>{
} }
fn empty_queue(&mut self){ fn empty_queue(&mut self){
while let Some(instruction)=self.timeline.pop_front(){ 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); self.physics.run_input_instruction(instruction);
} }
} }
@ -219,17 +208,83 @@ 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>( pub fn new<'a>(
mut graphics_worker:crate::compat_worker::INWorker<'a,crate::graphics_worker::Instruction>, mut graphics_worker:crate::compat_worker::INWorker<'a,crate::graphics_worker::Instruction>,
user_settings:crate::settings::UserSettings, user_settings:crate::settings::UserSettings,
bot_worker:crate::worker::QNWorker<'a,crate::bot_worker::Instruction>,
)->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction>>{ )->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction>>{
let physics=crate::physics::PhysicsContext::default(); let physics=crate::physics::PhysicsContext::default();
/*
let mut interpolator=MouseInterpolator::new( let mut interpolator=MouseInterpolator::new(
physics, physics,
bot_worker,
user_settings 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>|{ crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{
interpolator.handle_instruction(&ins); interpolator.handle_instruction(&ins);
match ins.instruction{ match ins.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 //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 //the thread that spawns the physics thread
let mut window_thread=crate::window::worker( let mut window_thread=crate::window::worker(
&window, &window,
setup_context, setup_context,
scope
); );
if let Some(arg)=std::env::args().nth(1){ if let Some(arg)=std::env::args().nth(1){
@ -233,7 +230,6 @@ pub fn setup_and_start(title:String){
println!("Entering event loop..."); println!("Entering event loop...");
let root_time=std::time::Instant::now(); let root_time=std::time::Instant::now();
run_event_loop(event_loop,window_thread,root_time).unwrap(); run_event_loop(event_loop,window_thread,root_time).unwrap();
});
} }
fn run_event_loop( fn run_event_loop(

@ -168,7 +168,6 @@ impl WindowContext<'_>{
pub fn worker<'a>( pub fn worker<'a>(
window:&'a winit::window::Window, window:&'a winit::window::Window,
setup_context:crate::setup::SetupContext<'a>, setup_context:crate::setup::SetupContext<'a>,
scope:&'a std::thread::Scope<'a,'_>,
)->crate::compat_worker::QNWorker<'a,TimedInstruction<WindowInstruction>>{ )->crate::compat_worker::QNWorker<'a,TimedInstruction<WindowInstruction>>{
// WindowContextSetup::new // WindowContextSetup::new
let user_settings=crate::settings::read_user_settings(); let user_settings=crate::settings::read_user_settings();
@ -179,8 +178,6 @@ pub fn worker<'a>(
//WindowContextSetup::into_context //WindowContextSetup::into_context
let screen_size=glam::uvec2(setup_context.config.width,setup_context.config.height); 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); 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{ let mut window_context=WindowContext{
manual_mouse_lock:false, manual_mouse_lock:false,
mouse:strafesnet_common::mouse::MouseState::default(), mouse:strafesnet_common::mouse::MouseState::default(),
@ -190,7 +187,6 @@ pub fn worker<'a>(
physics_thread:crate::physics_worker::new( physics_thread:crate::physics_worker::new(
graphics_thread, graphics_thread,
user_settings, user_settings,
bot_thread,
), ),
}; };