transpose next buffer state calculation

This commit is contained in:
Quaternions 2025-01-14 23:38:45 -08:00
parent 7476d7cdc7
commit 292df72709

View File

@ -124,47 +124,37 @@ impl MouseInterpolator{
}
// replace_with allows the enum variant to safely be replaced from behind a mutable reference
let (ins_mouse,ins_other)=replace_with::replace_with_or_abort_and_return(&mut self.buffer_state,|buffer_state|{
let next_state=match buffer_state{
BufferState::Unbuffered=>{
if let Instruction::MoveMouse(pos)=ins.instruction.instruction{
return ((None,None),BufferState::Initializing(ins.time,MouseState{pos,time:ins.instruction.time}));
match ins.instruction.instruction{
Instruction::MoveMouse(pos)=>{
let next_mouse_state=MouseState{pos,time:ins.instruction.time};
match buffer_state{
BufferState::Unbuffered=>{
((None,None),BufferState::Initializing(ins.time,next_mouse_state))
},
BufferState::Initializing(_time,mouse_state)=>{
let ins_mouse=TimedInstruction{
time:mouse_state.time,
instruction:MouseInstruction::ReplaceMouse{
m0:mouse_state,
m1:next_mouse_state.clone(),
},
};
((Some(ins_mouse),None),BufferState::Buffered(ins.time,next_mouse_state))
},
BufferState::Buffered(_time,mouse_state)=>{
let ins_mouse=TimedInstruction{
time:mouse_state.time,
instruction:MouseInstruction::SetNextMouse(next_mouse_state.clone()),
};
((Some(ins_mouse),None),BufferState::Buffered(ins.time,next_mouse_state))
},
}
BufferState::Unbuffered
},
BufferState::Initializing(time,mouse_state)=>{
if let Instruction::MoveMouse(pos)=ins.instruction.instruction{
let next_mouse_state=MouseState{pos,time:ins.instruction.time};
let ins_mouse=TimedInstruction{
time:mouse_state.time,
instruction:MouseInstruction::ReplaceMouse{
m0:mouse_state,
m1:next_mouse_state.clone(),
},
};
return ((Some(ins_mouse),None),BufferState::Buffered(ins.time,next_mouse_state));
}
BufferState::Initializing(time,mouse_state)
},
BufferState::Buffered(time,mouse_state)=>{
if let Instruction::MoveMouse(pos)=ins.instruction.instruction{
let next_mouse_state=MouseState{pos,time:ins.instruction.time};
let ins_mouse=TimedInstruction{
time:mouse_state.time,
instruction:MouseInstruction::SetNextMouse(next_mouse_state.clone()),
};
return ((Some(ins_mouse),None),BufferState::Buffered(ins.time,next_mouse_state));
}
BufferState::Buffered(time,mouse_state)
},
};
let ins_other=match ins.instruction.instruction{
Instruction::MoveMouse(_)=>None,
Instruction::Other(other_instruction)=>Some(TimedInstruction{
Instruction::Other(other_instruction)=>((None,Some(TimedInstruction{
time:ins.instruction.time,
instruction:other_instruction,
}),
};
((None,ins_other),next_state)
})),buffer_state),
}
});
if let Some(ins)=ins_mouse{
self.push_mouse(ins);