diff --git a/common/src/state.rs b/common/src/state.rs index a42f370c02..1fab2d3076 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -5,7 +5,7 @@ use crate::{ comp, msg::{EcsCompPacket, EcsResPacket}, sys, - terrain::{TerrainChunk, TerrainMap, Block}, + terrain::{Block, TerrainChunk, TerrainMap}, vol::WriteVol, }; use rayon::{ThreadPool, ThreadPoolBuilder}; @@ -17,7 +17,7 @@ use specs::{ }; use sphynx; use std::{ - collections::{HashSet, HashMap}, + collections::{HashMap, HashSet}, sync::Arc, time::Duration, }; @@ -255,11 +255,13 @@ impl State { { self.ecs .write_resource::() - .modified_chunks.insert(key); + .modified_chunks + .insert(key); } else { self.ecs .write_resource::() - .new_chunks.insert(key); + .new_chunks + .insert(key); } } @@ -273,7 +275,8 @@ impl State { { self.ecs .write_resource::() - .removed_chunks.insert(key); + .removed_chunks + .insert(key); } } @@ -303,21 +306,19 @@ impl State { .write_resource::() .blocks .drain() - .for_each(|(pos, block)| if terrain.set(pos, block).is_ok() { - chunk_changes.modified_chunks.insert(terrain.pos_key(pos)); - } else { - warn!("Tried to modify block outside of terrain at {:?}", pos); + .for_each(|(pos, block)| { + if terrain.set(pos, block).is_ok() { + chunk_changes.modified_chunks.insert(terrain.pos_key(pos)); + } else { + warn!("Tried to modify block outside of terrain at {:?}", pos); + } }); } /// Clean up the state after a tick. pub fn cleanup(&mut self) { // Clean up data structures from the last tick. - self.ecs - .write_resource::() - .clear(); - self.ecs - .write_resource::() - .clear(); + self.ecs.write_resource::().clear(); + self.ecs.write_resource::().clear(); } } diff --git a/common/src/terrain/chonk.rs b/common/src/terrain/chonk.rs index 5343eedf3f..ed8c7a60b1 100644 --- a/common/src/terrain/chonk.rs +++ b/common/src/terrain/chonk.rs @@ -1,6 +1,6 @@ use super::{block::Block, TerrainChunkMeta, TerrainChunkSize}; use crate::{ - vol::{BaseVol, ReadVol, WriteVol, VolSize}, + vol::{BaseVol, ReadVol, VolSize, WriteVol}, volumes::chunk::{Chunk, ChunkErr}, }; use fxhash::FxHashMap; @@ -188,7 +188,7 @@ impl WriteVol for Chonk { SubChunk::Hash(cblock, map) if block == *cblock => { map.remove(&rpos.map(|e| e as u8)); Ok(()) - }, + } SubChunk::Hash(_cblock, map) if map.len() <= 4096 => { map.insert(rpos.map(|e| e as u8), block); Ok(()) diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 44881fdc83..aee364d8dc 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -7,7 +7,7 @@ use common::{ comp, msg::ServerMsg, npc::{get_npc_name, NpcKind}, - state::{TimeOfDay, TerrainChange}, + state::{TerrainChange, TimeOfDay}, terrain::Block, vol::Vox, }; @@ -254,10 +254,9 @@ fn handle_tp(server: &mut Server, entity: EcsEntity, args: String, action: &Chat } }, None => { - server.clients.notify( - entity, - ServerMsg::Chat(format!("You have no position!")), - ); + server + .clients + .notify(entity, ServerMsg::Chat(format!("You have no position!"))); } } } @@ -332,10 +331,7 @@ fn handle_players(server: &mut Server, entity: EcsEntity, _args: String, _action fn handle_solid(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) { match server.state.read_component_cloned::(entity) { Some(current_pos) => { - let mut terrain_change = server - .state - .ecs() - .write_resource::(); + let mut terrain_change = server.state.ecs().write_resource::(); for i in -1..2 { for j in -1..2 { @@ -358,10 +354,7 @@ fn handle_solid(server: &mut Server, entity: EcsEntity, args: String, action: &C fn handle_empty(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) { match server.state.read_component_cloned::(entity) { Some(current_pos) => { - let mut terrain_change = server - .state - .ecs() - .write_resource::(); + let mut terrain_change = server.state.ecs().write_resource::(); for i in -1..2 { for j in -1..2 { diff --git a/server/src/lib.rs b/server/src/lib.rs index 0becf22dee..105c5a5bd8 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -17,7 +17,7 @@ use common::{ msg::{ClientMsg, ClientState, RequestStateError, ServerInfo, ServerMsg}, net::PostOffice, state::{State, Uid}, - terrain::{TerrainChunk, TerrainMap, TerrainChunkSize}, + terrain::{TerrainChunk, TerrainChunkSize, TerrainMap}, vol::VolSize, }; use log::{debug, warn}; @@ -246,7 +246,12 @@ impl Server { self.pending_chunks.remove(&key); } - fn chunk_in_vd(player_pos: Vec3, chunk_pos: Vec2, terrain: &TerrainMap, vd: u32) -> bool { + fn chunk_in_vd( + player_pos: Vec3, + chunk_pos: Vec2, + terrain: &TerrainMap, + vd: u32, + ) -> bool { let player_chunk_pos = terrain.pos_key(player_pos.map(|e| e as i32)); let adjusted_dist_sqr = Vec2::from(player_chunk_pos - chunk_pos) diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 9adde0895c..ed6544eb8c 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -94,12 +94,14 @@ impl Terrain { .modified_chunks .iter() .map(|c| (true, c)) - .chain(client - .state() - .chunk_changes() - .new_chunks - .iter() - .map(|c| (false, c))) + .chain( + client + .state() + .chunk_changes() + .new_chunks + .iter() + .map(|c| (false, c)), + ) { // TODO: ANOTHER PROBLEM HERE! // What happens if the block on the edge of a chunk gets modified? We need to spawn @@ -122,11 +124,14 @@ impl Terrain { } if neighbours { - self.mesh_todo.insert(pos, ChunkMeshState { + self.mesh_todo.insert( pos, - started_tick: current_tick, - active_worker: false, - }); + ChunkMeshState { + pos, + started_tick: current_tick, + active_worker: false, + }, + ); } } }