forked from StrafesNET/strafe-project
39 lines
825 B
Rust
39 lines
825 B
Rust
|
use strafesnet_snf::bot::BotInstructions;
|
||
|
|
||
|
pub enum Instruction{
|
||
|
//TODO: pass map id
|
||
|
Create,
|
||
|
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{
|
||
|
file:Option<BotInstructions>,
|
||
|
}
|
||
|
|
||
|
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=>{
|
||
|
worker.file=Some(BotIntructions::new("hi.snfb"))
|
||
|
},
|
||
|
Instruction::Push{ins}=>{
|
||
|
match &worker.file{
|
||
|
Some(file)=>file.push(ins),
|
||
|
None=>{
|
||
|
println!("no file created!"),
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
}
|
||
|
})
|
||
|
}
|