Compare commits

...

4 Commits

Author SHA1 Message Date
c558819835 set save location 2024-08-08 14:04:14 -07:00
772c9eb0b7 use nanoseconds lol 2024-08-08 13:23:45 -07:00
2366ca0f5f prototype bot worker 2024-08-08 13:23:45 -07:00
a4077ed0e3 use snf bot prerelease 2024-08-08 13:23:24 -07:00
7 changed files with 64 additions and 7 deletions

4
Cargo.lock generated
View File

@ -1952,9 +1952,9 @@ dependencies = [
[[package]] [[package]]
name = "strafesnet_snf" name = "strafesnet_snf"
version = "0.1.2" version = "0.1.3-bot"
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/" source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
checksum = "d12fc351b2af5fd7a8183175d55ac43e21eb8fd1f76cc70cd4713c0d1a556c96" checksum = "69448a3ed6ab5e9886cf83a3b2358c1f05d652cde4839963cd867978b924b52b"
dependencies = [ dependencies = [
"binrw 0.14.0", "binrw 0.14.0",
"id", "id",

View File

@ -26,7 +26,7 @@ strafesnet_bsp_loader = { version = "0.1.3", registry = "strafesnet", optional =
strafesnet_common = { version = "0.3.0", registry = "strafesnet" } strafesnet_common = { version = "0.3.0", registry = "strafesnet" }
strafesnet_deferred_loader = { version = "0.3.1", features = ["legacy"], registry = "strafesnet", optional = true } strafesnet_deferred_loader = { version = "0.3.1", features = ["legacy"], registry = "strafesnet", optional = true }
strafesnet_rbx_loader = { version = "0.3.2", registry = "strafesnet", optional = true } strafesnet_rbx_loader = { version = "0.3.2", registry = "strafesnet", optional = true }
strafesnet_snf = { version = "0.1.2", registry = "strafesnet", optional = true } strafesnet_snf = { version = "0.1.3-bot", registry = "strafesnet", optional = true }
wgpu = "22.0.0" wgpu = "22.0.0"
winit = "0.30.4" winit = "0.30.4"

35
src/bot_worker.rs Normal file
View File

@ -0,0 +1,35 @@
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(),
}
})
}

View File

@ -5,6 +5,7 @@ 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;

View File

@ -32,29 +32,33 @@ 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{ pub struct MouseInterpolator<'a>{
//"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( pub fn new<'a>(
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{ )->MouseInterpolator<'a>{
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,
} }
} }
@ -171,6 +175,13 @@ 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);
} }
} }
@ -211,10 +222,12 @@ impl MouseInterpolator{
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
); );
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{ crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{

View File

@ -213,10 +213,13 @@ 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){
@ -230,6 +233,7 @@ 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(

View File

@ -168,6 +168,7 @@ 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();
@ -178,6 +179,8 @@ 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(),
@ -187,6 +190,7 @@ 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,
), ),
}; };