Skip to content

Commit

Permalink
partial set of clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
drey7925 committed Jun 27, 2024
1 parent 5164cd3 commit c94d32e
Show file tree
Hide file tree
Showing 42 changed files with 396 additions and 482 deletions.
10 changes: 5 additions & 5 deletions perovskite_client/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl CacheManager {
fn hash_texture_reference(
&self,
tex: Option<&TextureReference>,
hasher: &mut sha2::Sha256,
hasher: &mut Sha256,
) -> Option<()> {
if let Some(tex) = tex {
hasher.update(b"tex_ref:");
Expand All @@ -195,7 +195,7 @@ impl CacheManager {
fn hash_cube_render_info(
&self,
cube: &perovskite_core::protocol::blocks::CubeRenderInfo,
hasher: &mut sha2::Sha256,
hasher: &mut Sha256,
) -> Option<()> {
hasher.update(b"cube:");
hasher.update(cube.render_mode.to_le_bytes());
Expand All @@ -212,7 +212,7 @@ impl CacheManager {
fn hash_aabox_render_info(
&self,
aa_boxes: &perovskite_core::protocol::blocks::AxisAlignedBoxes,
hasher: &mut sha2::Sha256,
hasher: &mut Sha256,
) -> Option<()> {
hasher.update(b"aa_boxes:");
for aa_box in aa_boxes.boxes.iter() {
Expand All @@ -239,7 +239,7 @@ impl CacheManager {
fn hash_plant_render_info(
&self,
plant: &perovskite_core::protocol::blocks::PlantLikeRenderInfo,
hasher: &mut sha2::Sha256,
hasher: &mut Sha256,
) -> Option<()> {
hasher.update(b"plant_like:");
hasher.update(plant.wave_effect_scale.to_le_bytes());
Expand Down Expand Up @@ -277,7 +277,7 @@ impl CacheManager {

fn get_cache_path(expected_hash: &[u8; 32], cache_dir: &Path) -> PathBuf {
let hash_hex = hex::encode(expected_hash);
assert!(hash_hex.len() == 64);
assert_eq!(hash_hex.len(), 64);
// Security: The hash is untrusted... But we verified its length, and we generate the hex string ourselves.
let prefix = hash_hex[0..2].to_string();
let suffix = hash_hex[2..].to_string();
Expand Down
14 changes: 6 additions & 8 deletions perovskite_client/src/game_state/block_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use rustc_hash::FxHashMap;
use super::make_fallback_blockdef;

pub(crate) struct ClientBlockTypeManager {
block_defs: Vec<Option<blocks_proto::BlockTypeDef>>,
fallback_block_def: blocks_proto::BlockTypeDef,
block_defs: Vec<Option<BlockTypeDef>>,
fallback_block_def: BlockTypeDef,
air_block: BlockId,
light_propagators: bv::BitVec,
light_emitters: Vec<u8>,
Expand All @@ -23,9 +23,7 @@ pub(crate) struct ClientBlockTypeManager {
name_to_id: FxHashMap<String, BlockId>,
}
impl ClientBlockTypeManager {
pub(crate) fn new(
server_defs: Vec<blocks_proto::BlockTypeDef>,
) -> Result<ClientBlockTypeManager> {
pub(crate) fn new(server_defs: Vec<BlockTypeDef>) -> Result<ClientBlockTypeManager> {
let max_id = server_defs
.iter()
.map(|x| x.id)
Expand Down Expand Up @@ -126,14 +124,14 @@ impl ClientBlockTypeManager {
})
}

pub(crate) fn all_block_defs(&self) -> impl Iterator<Item = &blocks_proto::BlockTypeDef> {
pub(crate) fn all_block_defs(&self) -> impl Iterator<Item = &BlockTypeDef> {
self.block_defs.iter().flatten()
}

pub(crate) fn get_fallback_blockdef(&self) -> &blocks_proto::BlockTypeDef {
pub(crate) fn get_fallback_blockdef(&self) -> &BlockTypeDef {
&self.fallback_block_def
}
pub(crate) fn get_blockdef(&self, id: BlockId) -> Option<&blocks_proto::BlockTypeDef> {
pub(crate) fn get_blockdef(&self, id: BlockId) -> Option<&BlockTypeDef> {
match self.block_defs.get(id.index()) {
// none if get() failed due to bounds check
None => None,
Expand Down
12 changes: 4 additions & 8 deletions perovskite_client/src/game_state/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl GameEntity {
m.seq,
m.start_tick,
m.total_time_seconds,
(m.start_tick as f64 / 1_000_000_000.0 - tick as f64 / 1_000_000_000.0)
m.start_tick as f64 / 1_000_000_000.0 - tick as f64 / 1_000_000_000.0
)
})
.collect::<String>()
Expand Down Expand Up @@ -307,11 +307,7 @@ impl GameEntity {
Ok(())
}

pub(crate) fn as_transform(
&self,
base_position: Vector3<f64>,
time_tick: u64,
) -> cgmath::Matrix4<f32> {
pub(crate) fn as_transform(&self, base_position: Vector3<f64>, time_tick: u64) -> Matrix4<f32> {
let (pos, face_dir, pitch) = self.position(time_tick);

build_transform(base_position, pos, face_dir, pitch)
Expand Down Expand Up @@ -449,7 +445,7 @@ fn build_transform(
face_dir: Rad<f32>,
pitch: Rad<f32>,
) -> Matrix4<f32> {
let translation = cgmath::Matrix4::from_translation(
let translation = Matrix4::from_translation(
(pos - base_position).mul_element_wise(Vector3::new(1., -1., 1.)),
)
.cast()
Expand Down Expand Up @@ -487,7 +483,7 @@ impl EntityState {

Ok(Self {
entities: FxHashMap::default(),
fallback_entity: VkCgvBufferGpu::from_buffers(&vtx, &idx, &block_renderer.allocator())?
fallback_entity: VkCgvBufferGpu::from_buffers(&vtx, &idx, block_renderer.allocator())?
.unwrap(),
attached_to_entity: None,
})
Expand Down
30 changes: 15 additions & 15 deletions perovskite_client/src/game_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub(crate) enum GameAction {
Tap(DigTapAction),
Place(PlaceAction),
Inventory(InventoryAction),
PopupResponse(perovskite_core::protocol::ui::PopupResponse),
PopupResponse(protocol::ui::PopupResponse),
InteractKey(InteractKeyAction),
ChatMessage(String),
}
Expand All @@ -123,15 +123,15 @@ pub(crate) struct ChunkManager {
chunks: parking_lot::RwLock<ChunkMap>,
renderable_chunks: parking_lot::RwLock<ChunkMap>,
light_columns: parking_lot::RwLock<LightColumnMap>,
mesh_batches: parking_lot::Mutex<(FxHashMap<u64, MeshBatch>, MeshBatchBuilder)>,
mesh_batches: Mutex<(FxHashMap<u64, MeshBatch>, MeshBatchBuilder)>,
}
impl ChunkManager {
pub(crate) fn new() -> ChunkManager {
ChunkManager {
chunks: parking_lot::RwLock::new(FxHashMap::default()),
renderable_chunks: parking_lot::RwLock::new(FxHashMap::default()),
light_columns: parking_lot::RwLock::new(FxHashMap::default()),
mesh_batches: parking_lot::Mutex::new((FxHashMap::default(), MeshBatchBuilder::new())),
mesh_batches: Mutex::new((FxHashMap::default(), MeshBatchBuilder::new())),
}
}
/// Locks the chunk manager and returns a struct that can be used to access chunks in a read/write manner,
Expand Down Expand Up @@ -191,7 +191,7 @@ impl ChunkManager {
proto: protocol::game_rpc::MapChunk,
snappy_helper: &mut SnappyDecodeHelper,
block_types: &ClientBlockTypeManager,
) -> anyhow::Result<usize> {
) -> Result<usize> {
// Lock order: chunks -> [renderable_chunks] -> light_columns
let mut chunks_lock = {
let _span = span!("Acquire global chunk lock");
Expand Down Expand Up @@ -239,7 +239,7 @@ impl ChunkManager {
let block_coord: BlockCoordinate = match &update.block_coord {
Some(x) => x.into(),
None => {
log::warn!("Got delta with missing block_coord {:?}", update);
warn!("Got delta with missing block_coord {:?}", update);
missing_coord = true;
continue;
}
Expand All @@ -260,7 +260,7 @@ impl ChunkManager {
}
}
None => {
log::warn!("Got delta for unknown chunk {:?}", block_coord);
warn!("Got delta for unknown chunk {:?}", block_coord);
unknown_coords.push(block_coord);
None
}
Expand Down Expand Up @@ -608,11 +608,11 @@ pub(crate) struct ClientState {

pub(crate) block_types: Arc<ClientBlockTypeManager>,
pub(crate) items: Arc<ClientItemManager>,
pub(crate) last_update: parking_lot::Mutex<Instant>,
pub(crate) physics_state: parking_lot::Mutex<physics::PhysicsState>,
pub(crate) last_update: Mutex<Instant>,
pub(crate) physics_state: Mutex<physics::PhysicsState>,
pub(crate) chunks: ChunkManager,
pub(crate) inventories: parking_lot::Mutex<InventoryViewManager>,
pub(crate) tool_controller: parking_lot::Mutex<ToolController>,
pub(crate) inventories: Mutex<InventoryViewManager>,
pub(crate) tool_controller: Mutex<ToolController>,
pub(crate) shutdown: tokio_util::sync::CancellationToken,
pub(crate) actions: mpsc::Sender<GameAction>,
pub(crate) light_cycle: Arc<Mutex<LightCycle>>,
Expand Down Expand Up @@ -672,8 +672,8 @@ impl ClientState {
pending_error: Mutex::new(None),
wants_exit_from_game: Mutex::new(false),
last_position_weak: Mutex::new(PlayerPositionUpdate {
position: cgmath::Vector3::zero(),
velocity: cgmath::Vector3::zero(),
position: Vector3::zero(),
velocity: Vector3::zero(),
face_direction: (0.0, 0.0),
}),
timekeeper,
Expand All @@ -689,7 +689,7 @@ impl ClientState {
PlayerPositionUpdate {
// TODO tick, velocity
position: lock.pos(),
velocity: cgmath::Vector3::zero(),
velocity: Vector3::zero(),
face_direction: lock.angle(),
}
}
Expand Down Expand Up @@ -757,7 +757,7 @@ impl ClientState {

*self.last_position_weak.lock() = PlayerPositionUpdate {
position: player_position,
velocity: cgmath::Vector3::zero(),
velocity: Vector3::zero(),
face_direction: (az, el),
};

Expand Down Expand Up @@ -836,7 +836,7 @@ impl ClientState {

pub(crate) struct FrameState {
pub(crate) scene_state: SceneState,
pub(crate) player_position: cgmath::Vector3<f64>,
pub(crate) player_position: Vector3<f64>,
pub(crate) tool_state: ToolState,
}

Expand Down
22 changes: 11 additions & 11 deletions perovskite_client/src/game_state/physics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl PhysicsMode {
}

pub(crate) struct PhysicsState {
pos: cgmath::Vector3<f64>,
pos: Vector3<f64>,
az: Deg<f64>,
el: Deg<f64>,
target_az: Deg<f64>,
Expand All @@ -138,7 +138,7 @@ pub(crate) struct PhysicsState {
impl PhysicsState {
pub(crate) fn new(settings: Arc<ArcSwap<GameSettings>>) -> Self {
Self {
pos: cgmath::vec3(0., 0., -4.),
pos: vec3(0., 0., -4.),
az: Deg(0.),
el: Deg(0.),
target_az: Deg(0.),
Expand All @@ -161,7 +161,7 @@ impl PhysicsState {
client_state: &ClientState,
_aspect_ratio: f64,
delta: Duration,
) -> (cgmath::Vector3<f64>, (f64, f64)) {
) -> (Vector3<f64>, (f64, f64)) {
let mut input = client_state.input.lock();
if input.take_just_pressed(BoundAction::TogglePhysics) {
self.physics_mode = self.physics_mode.next(self.can_fly, self.can_noclip);
Expand Down Expand Up @@ -193,7 +193,7 @@ impl PhysicsState {
fn update_standard(
&mut self,
input: &mut InputState,
delta: std::time::Duration,
delta: Duration,
client_state: &ClientState,
) {
let _span = span!("physics_standard");
Expand Down Expand Up @@ -289,7 +289,7 @@ impl PhysicsState {
bump_height: f64,
target: Vector3<f64>,
chunks: ChunkManagerView<'_>,
block_types: &std::sync::Arc<ClientBlockTypeManager>,
block_types: &Arc<ClientBlockTypeManager>,
delta_secs: f64,
) -> Vector3<f64> {
let pre_bump_y = new_pos.y;
Expand Down Expand Up @@ -422,7 +422,7 @@ impl PhysicsState {
fn update_flying(
&mut self,
input: &mut InputState,
delta: std::time::Duration,
delta: Duration,
collisions: bool,
client_state: &ClientState,
) {
Expand Down Expand Up @@ -494,7 +494,7 @@ impl PhysicsState {
(self.az.0, self.el.0)
}

fn update_smooth_angles(&mut self, delta: std::time::Duration) {
fn update_smooth_angles(&mut self, delta: Duration) {
let factor =
ANGLE_SMOOTHING_FACTOR.powf(delta.as_secs_f64() / ANGLE_SMOOTHING_REFERENCE_DELTA);
self.el = (self.el * factor) + (self.target_el * (1.0 - factor));
Expand Down Expand Up @@ -755,10 +755,10 @@ fn push_collision_boxes(
output: &mut Vec<CollisionBox>,
) {
match &block.physics_info {
Some(block_type_def::PhysicsInfo::Solid(_)) => output.push(CollisionBox::full_cube(coord)),
Some(block_type_def::PhysicsInfo::Fluid(_)) => {}
Some(block_type_def::PhysicsInfo::Air(_)) => {}
Some(block_type_def::PhysicsInfo::SolidCustomCollisionboxes(boxes)) => {
Some(PhysicsInfo::Solid(_)) => output.push(CollisionBox::full_cube(coord)),
Some(PhysicsInfo::Fluid(_)) => {}
Some(PhysicsInfo::Air(_)) => {}
Some(PhysicsInfo::SolidCustomCollisionboxes(boxes)) => {
for box_ in &boxes.boxes {
if box_.variant_mask == 0 || (variant & box_.variant_mask as u16) != 0 {
output.push(CollisionBox::from_aabb(coord, box_, variant));
Expand Down
2 changes: 1 addition & 1 deletion perovskite_client/src/game_state/tool_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,4 @@ const POINTEE_DISTANCE: f64 = 6.;
// line_drawing seems to have problems when using Center rather than Corner
// Fudge it manually
// TODO file a bug for that crate
const RAYCAST_FUDGE_VEC: cgmath::Vector3<f64> = cgmath::vec3(0.5, 0.5, 0.5);
const RAYCAST_FUDGE_VEC: cgmath::Vector3<f64> = vec3(0.5, 0.5, 0.5);
Loading

0 comments on commit c94d32e

Please sign in to comment.