strafe-project/src/bot_worker.rs

44 lines
961 B
Rust
Raw Normal View History

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{
2024-08-05 20:35:54 +00:00
ins:strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>,
2024-08-01 21:06:40 +00:00
},
}
//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}=>{
2024-08-05 20:35:27 +00:00
match &mut 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
}
},
}
})
}