Skip to content

Commit

Permalink
Remove obsolete "modified" field from Chunk::Populated
Browse files Browse the repository at this point in the history
  • Loading branch information
patowen committed Apr 30, 2024
1 parent 8a09681 commit 7c2bd56
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 18 deletions.
3 changes: 1 addition & 2 deletions client/src/graphics/voxels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Voxels {
}
while let Some(chunk) = self.worldgen.poll() {
let chunk_id = ChunkId::new(chunk.node, chunk.chunk);
sim.graph.populate_chunk(chunk_id, chunk.voxels, false);
sim.graph.populate_chunk(chunk_id, chunk.voxels);

// Now that the block is populated, we can apply any pending block updates the server
// provided that the client couldn't apply.
Expand Down Expand Up @@ -175,7 +175,6 @@ impl Voxels {
ref mut surface,
ref mut old_surface,
ref voxels,
..
} => {
if let Some(slot) = surface.or(*old_surface) {
// Render an already-extracted surface
Expand Down
2 changes: 1 addition & 1 deletion client/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl Sim {
tracing::error!("Voxel data received from server is of incorrect dimension");
continue;
};
self.graph.populate_chunk(chunk_id, voxel_data, true);
self.graph.populate_chunk(chunk_id, voxel_data);
}
}

Expand Down
1 change: 0 additions & 1 deletion common/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fn build_graph(c: &mut Criterion) {
if let Some(params) = ChunkParams::new(12, &graph, chunk) {
graph[chunk] = Chunk::Populated {
voxels: params.generate_voxels(),
modified: false,
surface: None,
old_surface: None,
};
Expand Down
2 changes: 0 additions & 2 deletions common/src/graph_collision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ mod tests {
for vertex in dodeca::Vertex::iter() {
graph[ChunkId::new(node, vertex)] = Chunk::Populated {
voxels: VoxelData::Solid(Material::Void),
modified: false,
surface: None,
old_surface: None,
};
Expand Down Expand Up @@ -428,7 +427,6 @@ mod tests {
for vertex in dodeca::Vertex::iter() {
graph[ChunkId::new(node, vertex)] = Chunk::Populated {
voxels: VoxelData::Solid(Material::Void),
modified: false,
surface: None,
old_surface: None,
};
Expand Down
3 changes: 0 additions & 3 deletions common/src/margins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ pub fn reconcile_margin_voxels(
voxels: neighbor_voxels,
surface: neighbor_surface,
old_surface: neighbor_old_surface,
..
} = &mut graph[neighbor_chunk]
else {
unreachable!();
Expand All @@ -213,7 +212,6 @@ pub fn reconcile_margin_voxels(
voxels,
surface,
old_surface,
..
} = &mut graph[chunk]
else {
unreachable!();
Expand Down Expand Up @@ -383,7 +381,6 @@ mod tests {
for chunk in [current_chunk, node_neighbor_chunk, vertex_neighbor_chunk] {
*graph.get_chunk_mut(chunk).unwrap() = Chunk::Populated {
voxels: VoxelData::Solid(Material::Void),
modified: false,
surface: None,
old_surface: None,
};
Expand Down
7 changes: 1 addition & 6 deletions common/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,14 @@ impl Graph {
}

/// Populates a chunk with the given voxel data and ensures that margins are correctly fixed up.
pub fn populate_chunk(&mut self, chunk: ChunkId, mut voxels: VoxelData, modified: bool) {
pub fn populate_chunk(&mut self, chunk: ChunkId, mut voxels: VoxelData) {
let dimension = self.layout().dimension;
// Fix up margins for the chunk we're inserting along with any neighboring chunks
for chunk_direction in ChunkDirection::iter() {
let Some(Chunk::Populated {
voxels: neighbor_voxels,
surface: neighbor_surface,
old_surface: neighbor_old_surface,
..
}) = self
.get_chunk_neighbor(chunk, chunk_direction.axis, chunk_direction.sign)
.map(|chunk_id| &mut self[chunk_id])
Expand All @@ -121,7 +120,6 @@ impl Graph {
// After clearing any margins we needed to clear, we can now insert the data into the graph
*self.get_chunk_mut(chunk).unwrap() = Chunk::Populated {
voxels,
modified,
surface: None,
old_surface: None,
};
Expand All @@ -136,7 +134,6 @@ impl Graph {
// Update the block
let Some(Chunk::Populated {
voxels,
modified,
surface,
old_surface,
}) = self.get_chunk_mut(block_update.chunk_id)
Expand All @@ -149,7 +146,6 @@ impl Graph {
.expect("coords are in-bounds");

*voxel = block_update.new_material;
*modified = true;
*old_surface = surface.take().or(*old_surface);

for chunk_direction in ChunkDirection::iter() {
Expand Down Expand Up @@ -192,7 +188,6 @@ pub enum Chunk {
Generating,
Populated {
voxels: VoxelData,
modified: bool,
surface: Option<SlotId>,
old_surface: Option<SlotId>,
},
Expand Down
5 changes: 2 additions & 3 deletions server/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl Sim {
if let Some(voxel_data) = self.preloaded_voxel_data.remove(&chunk) {
fresh_voxel_data.push((chunk, voxel_data.serialize(self.cfg.chunk_size)));
self.modified_chunks.insert(chunk);
self.graph.populate_chunk(chunk, voxel_data, true)
self.graph.populate_chunk(chunk, voxel_data)
}
}
}
Expand Down Expand Up @@ -318,8 +318,7 @@ impl Sim {
if let Some(params) =
ChunkParams::new(self.cfg.chunk_size, &self.graph, chunk)
{
self.graph
.populate_chunk(chunk, params.generate_voxels(), false);
self.graph.populate_chunk(chunk, params.generate_voxels());
}
}
}
Expand Down

0 comments on commit 7c2bd56

Please sign in to comment.