2024-08-02 19:14:26 +00:00
|
|
|
use strafesnet_snf::bot::BotDebug;
|
2024-08-01 21:06:40 +00:00
|
|
|
|
|
|
|
pub enum Instruction{
|
|
|
|
//TODO: pass map id
|
|
|
|
Create,
|
2024-08-02 19:14:26 +00:00
|
|
|
Delete,
|
2024-08-01 21:06:40 +00:00
|
|
|
Push{
|
|
|
|
ins:strafesnet_common::instruction::TimedInstruction<crate::physics::PhysicsInputInstruction>,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
//a new worker is spawned on a thread
|
|
|
|
//create opens a new file
|
|
|
|
//push pushes an instruction to the file
|
|
|
|
|
|
|
|
pub struct Worker{
|
2024-08-02 19:14:26 +00:00
|
|
|
file:Option<BotDebug>,
|
2024-08-01 21:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new<'a>(scope:&'a std::thread::Scope<'a,'_>)->crate::worker::QNWorker<'a,Instruction>{
|
|
|
|
let mut worker=Worker{
|
|
|
|
file:None,
|
|
|
|
};
|
|
|
|
crate::worker::QNWorker::new(scope,move|instruction|{
|
|
|
|
match instruction{
|
|
|
|
Instruction::Create=>{
|
2024-08-02 19:14:26 +00:00
|
|
|
worker.file=Some(BotDebug::new().unwrap())
|
2024-08-01 21:06:40 +00:00
|
|
|
},
|
2024-08-02 19:14:26 +00:00
|
|
|
Instruction::Delete=>{
|
|
|
|
match worker.file.take(){
|
|
|
|
Some(file)=>file.delete().unwrap(),
|
|
|
|
None=>println!("no file created!"),
|
|
|
|
}
|
|
|
|
}
|
2024-08-01 21:06:40 +00:00
|
|
|
Instruction::Push{ins}=>{
|
|
|
|
match &worker.file{
|
2024-08-02 19:14:26 +00:00
|
|
|
Some(file)=>file.push(ins).unwrap(),
|
|
|
|
None=>println!("no file created!"),
|
2024-08-01 21:06:40 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|