Refactor upload_unpack_buffers

This commit is contained in:
Jarrod Doyle 2024-03-23 12:31:20 +00:00
parent 23ea18c3de
commit 66f44c5461
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 10 additions and 15 deletions

View File

@ -297,24 +297,24 @@ impl BrickmapManager {
self.brickgrid_staged.insert(index); self.brickgrid_staged.insert(index);
} }
// TODO: Tidy this up more
fn upload_unpack_buffers(&mut self, context: &gfx::Context) { fn upload_unpack_buffers(&mut self, context: &gfx::Context) {
// Brickgrid // Brickgrid
let mut data = Vec::new(); let mut data = Vec::new();
let mut iter = self.brickgrid_staged.iter(); let mut iter = self.brickgrid_staged.iter();
let mut to_remove = Vec::new(); let mut to_remove = Vec::new();
for _ in 0..self.unpack_max_count { for _ in 0..self.unpack_max_count {
let el = iter.next(); match iter.next() {
if el.is_none() { Some(val) => {
break; to_remove.push(*val);
data.push(*val as u32);
data.push(self.brickgrid[*val]);
}
None => break,
} }
let val = el.unwrap();
to_remove.push(*val as u32);
data.push(*val as u32);
data.push(self.brickgrid[*val]);
} }
for val in &to_remove { for val in &to_remove {
self.brickgrid_staged.remove(&(*val as usize)); self.brickgrid_staged.remove(val);
} }
if !data.is_empty() { if !data.is_empty() {
@ -328,12 +328,7 @@ impl BrickmapManager {
context.queue.write_buffer( context.queue.write_buffer(
&self.brickgrid_unpack_buffer, &self.brickgrid_unpack_buffer,
4, 4,
bytemuck::cast_slice(&[data.len()]), bytemuck::cast_slice(&[&[data.len() as u32, 0, 0], &data[..]].concat()),
);
context.queue.write_buffer(
&self.brickgrid_unpack_buffer,
16,
bytemuck::cast_slice(&data),
); );
// Brickmap // Brickmap