session: use replay directory
This commit is contained in:
parent
d5a6f8e1bc
commit
2eaddd493d
@ -12,6 +12,7 @@ use strafesnet_common::physics::{
|
|||||||
};
|
};
|
||||||
use strafesnet_common::timer::{Scaled,Timer};
|
use strafesnet_common::timer::{Scaled,Timer};
|
||||||
use strafesnet_common::session::{TimeInner as SessionTimeInner,Time as SessionTime};
|
use strafesnet_common::session::{TimeInner as SessionTimeInner,Time as SessionTime};
|
||||||
|
use strafesnet_settings::directories::Directories;
|
||||||
|
|
||||||
use crate::mouse_interpolator::{MouseInterpolator,StepInstruction,Instruction as MouseInterpolatorInstruction};
|
use crate::mouse_interpolator::{MouseInterpolator,StepInstruction,Instruction as MouseInterpolatorInstruction};
|
||||||
use strafesnet_physics::physics::{self,PhysicsContext,PhysicsData};
|
use strafesnet_physics::physics::{self,PhysicsContext,PhysicsData};
|
||||||
@ -149,6 +150,7 @@ enum ViewState{
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Session{
|
pub struct Session{
|
||||||
|
directories:Directories,
|
||||||
user_settings:UserSettings,
|
user_settings:UserSettings,
|
||||||
mouse_interpolator:crate::mouse_interpolator::MouseInterpolator,
|
mouse_interpolator:crate::mouse_interpolator::MouseInterpolator,
|
||||||
view_state:ViewState,
|
view_state:ViewState,
|
||||||
@ -163,10 +165,12 @@ pub struct Session{
|
|||||||
impl Session{
|
impl Session{
|
||||||
pub fn new(
|
pub fn new(
|
||||||
user_settings:UserSettings,
|
user_settings:UserSettings,
|
||||||
|
directories:Directories,
|
||||||
simulation:Simulation,
|
simulation:Simulation,
|
||||||
)->Self{
|
)->Self{
|
||||||
Self{
|
Self{
|
||||||
user_settings,
|
user_settings,
|
||||||
|
directories,
|
||||||
mouse_interpolator:MouseInterpolator::new(),
|
mouse_interpolator:MouseInterpolator::new(),
|
||||||
geometry_shared:Default::default(),
|
geometry_shared:Default::default(),
|
||||||
simulation,
|
simulation,
|
||||||
@ -295,11 +299,17 @@ impl InstructionConsumer<Instruction<'_>> for Session{
|
|||||||
match view_state{
|
match view_state{
|
||||||
ViewState::Play=>(),
|
ViewState::Play=>(),
|
||||||
ViewState::Replay(bot_id)=>if let Some(replay)=self.replays.remove(&bot_id){
|
ViewState::Replay(bot_id)=>if let Some(replay)=self.replays.remove(&bot_id){
|
||||||
let file_name=format!("replays/{}.snfb",ins.time);
|
let mut replays_path=self.directories.replays.clone();
|
||||||
|
let file_name=format!("{}.snfb",ins.time);
|
||||||
std::thread::spawn(move ||{
|
std::thread::spawn(move ||{
|
||||||
std::fs::create_dir_all("replays").unwrap();
|
std::fs::create_dir_all(replays_path.as_path()).unwrap();
|
||||||
let file=std::fs::File::create(file_name).unwrap();
|
replays_path.push(file_name);
|
||||||
strafesnet_snf::bot::write_bot(std::io::BufWriter::new(file),strafesnet_physics::VERSION.get(),replay.recording.instructions).unwrap();
|
let file=std::fs::File::create(replays_path).unwrap();
|
||||||
|
strafesnet_snf::bot::write_bot(
|
||||||
|
std::io::BufWriter::new(file),
|
||||||
|
strafesnet_physics::VERSION.get(),
|
||||||
|
replay.recording.instructions
|
||||||
|
).unwrap();
|
||||||
println!("Finished writing bot file!");
|
println!("Finished writing bot file!");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::graphics_worker::Instruction as GraphicsInstruction;
|
use crate::graphics_worker::Instruction as GraphicsInstruction;
|
||||||
use strafesnet_settings::settings;
|
use strafesnet_settings::{directories::Directories,settings};
|
||||||
use strafesnet_session::session::{
|
use strafesnet_session::session::{
|
||||||
Session,Simulation,SessionInputInstruction,SessionControlInstruction,SessionPlaybackInstruction,ImplicitModeInstruction,
|
Session,Simulation,SessionInputInstruction,SessionControlInstruction,SessionPlaybackInstruction,ImplicitModeInstruction,
|
||||||
Instruction as SessionInstruction,
|
Instruction as SessionInstruction,
|
||||||
@ -21,6 +21,7 @@ pub enum Instruction{
|
|||||||
|
|
||||||
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>,
|
||||||
|
directories:Directories,
|
||||||
user_settings:settings::UserSettings,
|
user_settings:settings::UserSettings,
|
||||||
)->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTimeInner>>{
|
)->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTimeInner>>{
|
||||||
let physics=strafesnet_physics::physics::PhysicsState::default();
|
let physics=strafesnet_physics::physics::PhysicsState::default();
|
||||||
@ -28,6 +29,7 @@ pub fn new<'a>(
|
|||||||
let simulation=Simulation::new(timer,physics);
|
let simulation=Simulation::new(timer,physics);
|
||||||
let mut session=Session::new(
|
let mut session=Session::new(
|
||||||
user_settings,
|
user_settings,
|
||||||
|
directories,
|
||||||
simulation,
|
simulation,
|
||||||
);
|
);
|
||||||
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction,SessionTimeInner>|{
|
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction,SessionTimeInner>|{
|
||||||
|
@ -232,6 +232,7 @@ pub fn worker<'a>(
|
|||||||
window,
|
window,
|
||||||
physics_thread:crate::physics_worker::new(
|
physics_thread:crate::physics_worker::new(
|
||||||
graphics_thread,
|
graphics_thread,
|
||||||
|
directories,
|
||||||
user_settings,
|
user_settings,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user