forked from StrafesNET/strafe-client
Compare commits
5 Commits
master
...
bot-playba
Author | SHA1 | Date | |
---|---|---|---|
0b1a4a0ad4 | |||
c37069c566 | |||
48dfe8bc40 | |||
c0d543301e | |||
a4077ed0e3 |
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -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",
|
||||||
|
@ -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"
|
||||||
|
|
||||||
|
@ -208,15 +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,
|
||||||
)->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,
|
||||||
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{
|
||||||
|
Loading…
Reference in New Issue
Block a user