fixed bug where world offset was applied to camera position delayed 1 frame
This commit is contained in:
@@ -17,8 +17,8 @@ pub struct Nodes {
|
||||
buffer: Box<[u32]>,
|
||||
offset: Vector3<i32>,
|
||||
dirty: bool,
|
||||
busy: bool,
|
||||
queue: Vec<Vector3<i32>>,
|
||||
shift: Option<Vector3<i32>>,
|
||||
working: bool,
|
||||
channel: (Sender<NodeBuffer>, Receiver<NodeBuffer>)
|
||||
}
|
||||
|
||||
@@ -29,8 +29,9 @@ impl Nodes {
|
||||
buffer: vec![0_u32; NODE_TEX_SIZE_QB].into_boxed_slice(),
|
||||
offset: Vector3{x:0,y:0,z:0},
|
||||
dirty: false,
|
||||
busy: false,
|
||||
queue: Vec::new(),
|
||||
|
||||
shift: None,
|
||||
working: false,
|
||||
channel: mpsc::channel()
|
||||
}
|
||||
}
|
||||
@@ -44,7 +45,7 @@ impl Nodes {
|
||||
}
|
||||
|
||||
pub fn is_busy(&self) -> bool {
|
||||
self.busy
|
||||
self.shift != None
|
||||
}
|
||||
|
||||
pub fn set_node(&mut self, index: usize, value: u32) {
|
||||
@@ -53,31 +54,24 @@ impl Nodes {
|
||||
}
|
||||
|
||||
pub fn shift(&mut self, offset: &Vector3<i32>) {
|
||||
self.queue.push(*offset);
|
||||
if self.shift == None {
|
||||
self.shift = Some(*offset);
|
||||
} else {
|
||||
println!("Tried to shift while another shifin was in progress");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, queue: &wgpu::Queue, texture: &wgpu::Texture) {
|
||||
|
||||
// Receive work
|
||||
while let Ok(result) = self.channel.1.try_recv() {
|
||||
self.offset += result.0;
|
||||
self.buffer = result.1;
|
||||
self.busy = false;
|
||||
self.dirty = true;
|
||||
}
|
||||
|
||||
// Check if there is some more work
|
||||
if !self.busy {
|
||||
if let Some(offset) = self.queue.pop() {
|
||||
self.busy = true;
|
||||
self.dirty = false;
|
||||
if !self.working {
|
||||
if let Some(offset) = self.shift {
|
||||
let source = self.buffer.clone();
|
||||
let tx = self.channel.0.clone();
|
||||
|
||||
self.working = true;
|
||||
|
||||
// Spawn worker
|
||||
thread::spawn(move || {
|
||||
println!("shift worker start: {:?}", offset);
|
||||
|
||||
let size = NODE_TEX_SIZE as i32;
|
||||
let mut target = vec![0_u32; NODE_TEX_SIZE_QB].into_boxed_slice();
|
||||
let (ox, oy, oz) = (offset.x, offset.y, offset.z);
|
||||
@@ -92,14 +86,22 @@ impl Nodes {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Send result
|
||||
tx.send((offset, target)).unwrap();
|
||||
println!("shift worker done: {:?}", offset);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Receive work
|
||||
while let Ok(result) = self.channel.1.try_recv() {
|
||||
self.offset += result.0;
|
||||
self.buffer = result.1;
|
||||
self.shift = None;
|
||||
self.dirty = true;
|
||||
self.working = false;
|
||||
}
|
||||
|
||||
if self.dirty {
|
||||
self.dirty = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user