Make clippy happy, fmt even though it is set to fmt on save in my

editor...."
This commit is contained in:
Imbris 2020-08-07 01:00:09 -04:00 committed by Monty Marz
parent 2faa1cd6c1
commit 2608217e83
6 changed files with 110 additions and 93 deletions

View File

@ -52,7 +52,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add detection of entities under the cursor - Add detection of entities under the cursor
- Functional group-system with exp-sharing and disabled damage to group members - Functional group-system with exp-sharing and disabled damage to group members
### Changed ### Changed
- Improved camera aiming - Improved camera aiming

View File

@ -21,9 +21,9 @@ use common::{
InventoryManip, InventoryUpdateEvent, InventoryManip, InventoryUpdateEvent,
}, },
msg::{ msg::{
validate_chat_msg, ChatMsgValidationError, ClientMsg, ClientState, Notification, validate_chat_msg, ChatMsgValidationError, ClientMsg, ClientState, InviteAnswer,
PlayerInfo, PlayerListUpdate, RegisterError, RequestStateError, ServerInfo, ServerMsg, Notification, PlayerInfo, PlayerListUpdate, RegisterError, RequestStateError, ServerInfo,
MAX_BYTES_CHAT_MSG, InviteAnswer, ServerMsg, MAX_BYTES_CHAT_MSG,
}, },
recipe::RecipeBook, recipe::RecipeBook,
state::State, state::State,
@ -135,48 +135,49 @@ impl Client {
let mut stream = block_on(participant.open(10, PROMISES_ORDERED | PROMISES_CONSISTENCY))?; let mut stream = block_on(participant.open(10, PROMISES_ORDERED | PROMISES_CONSISTENCY))?;
// Wait for initial sync // Wait for initial sync
let (state, entity, server_info, world_map, recipe_book, max_group_size) = block_on(async { let (state, entity, server_info, world_map, recipe_book, max_group_size) = block_on(
loop { async {
match stream.recv().await? { loop {
ServerMsg::InitialSync { match stream.recv().await? {
entity_package, ServerMsg::InitialSync {
server_info, entity_package,
time_of_day, server_info,
max_group_size, time_of_day,
world_map: (map_size, world_map), max_group_size,
recipe_book, world_map: (map_size, world_map),
} => { recipe_book,
// TODO: Display that versions don't match in Voxygen } => {
if &server_info.git_hash != *common::util::GIT_HASH { // TODO: Display that versions don't match in Voxygen
warn!( if &server_info.git_hash != *common::util::GIT_HASH {
"Server is running {}[{}], you are running {}[{}], versions might \ warn!(
be incompatible!", "Server is running {}[{}], you are running {}[{}], versions \
server_info.git_hash, might be incompatible!",
server_info.git_date, server_info.git_hash,
common::util::GIT_HASH.to_string(), server_info.git_date,
common::util::GIT_DATE.to_string(), common::util::GIT_HASH.to_string(),
); common::util::GIT_DATE.to_string(),
} );
}
debug!("Auth Server: {:?}", server_info.auth_provider); debug!("Auth Server: {:?}", server_info.auth_provider);
// Initialize `State` // Initialize `State`
let mut state = State::default(); let mut state = State::default();
// Client-only components // Client-only components
state state
.ecs_mut() .ecs_mut()
.register::<comp::Last<comp::CharacterState>>(); .register::<comp::Last<comp::CharacterState>>();
let entity = state.ecs_mut().apply_entity_package(entity_package); let entity = state.ecs_mut().apply_entity_package(entity_package);
*state.ecs_mut().write_resource() = time_of_day; *state.ecs_mut().write_resource() = time_of_day;
assert_eq!(world_map.len(), (map_size.x * map_size.y) as usize); assert_eq!(world_map.len(), (map_size.x * map_size.y) as usize);
let mut world_map_raw = let mut world_map_raw =
vec![0u8; 4 * world_map.len()/*map_size.x * map_size.y*/]; vec![0u8; 4 * world_map.len()/*map_size.x * map_size.y*/];
LittleEndian::write_u32_into(&world_map, &mut world_map_raw); LittleEndian::write_u32_into(&world_map, &mut world_map_raw);
debug!("Preparing image..."); debug!("Preparing image...");
let world_map = Arc::new( let world_map = Arc::new(
image::DynamicImage::ImageRgba8({ image::DynamicImage::ImageRgba8({
// Should not fail if the dimensions are correct. // Should not fail if the dimensions are correct.
let world_map = let world_map =
image::ImageBuffer::from_raw(map_size.x, map_size.y, world_map_raw); image::ImageBuffer::from_raw(map_size.x, map_size.y, world_map_raw);
@ -185,25 +186,26 @@ impl Client {
// Flip the image, since Voxygen uses an orientation where rotation from // Flip the image, since Voxygen uses an orientation where rotation from
// positive x axis to positive y axis is counterclockwise around the z axis. // positive x axis to positive y axis is counterclockwise around the z axis.
.flipv(), .flipv(),
); );
debug!("Done preparing image..."); debug!("Done preparing image...");
break Ok(( break Ok((
state, state,
entity, entity,
server_info, server_info,
(world_map, map_size), (world_map, map_size),
recipe_book, recipe_book,
max_group_size, max_group_size,
)); ));
}, },
ServerMsg::TooManyPlayers => break Err(Error::TooManyPlayers), ServerMsg::TooManyPlayers => break Err(Error::TooManyPlayers),
err => { err => {
warn!("whoops, server mad {:?}, ignoring", err); warn!("whoops, server mad {:?}, ignoring", err);
}, },
}
} }
} },
})?; )?;
stream.send(ClientMsg::Ping)?; stream.send(ClientMsg::Ping)?;
@ -443,7 +445,9 @@ impl Client {
pub fn max_group_size(&self) -> u32 { self.max_group_size } pub fn max_group_size(&self) -> u32 { self.max_group_size }
pub fn group_invite(&self) -> Option<(Uid, std::time::Instant, std::time::Duration)> { self.group_invite } pub fn group_invite(&self) -> Option<(Uid, std::time::Instant, std::time::Duration)> {
self.group_invite
}
pub fn group_info(&self) -> Option<(String, Uid)> { pub fn group_info(&self) -> Option<(String, Uid)> {
self.group_leader.map(|l| ("Group".into(), l)) // TODO self.group_leader.map(|l| ("Group".into(), l)) // TODO
@ -772,7 +776,10 @@ impl Client {
// 3) Update client local data // 3) Update client local data
// Check if the group invite has timed out and remove if so // Check if the group invite has timed out and remove if so
if self.group_invite.map_or(false, |(_, timeout, dur)| timeout.elapsed() > dur) { if self
.group_invite
.map_or(false, |(_, timeout, dur)| timeout.elapsed() > dur)
{
self.group_invite = None; self.group_invite = None;
} }
@ -1029,10 +1036,13 @@ impl Client {
// Check if this is a newly formed group by looking for absence of // Check if this is a newly formed group by looking for absence of
// other non pet group members // other non pet group members
if !matches!(role, group::Role::Pet) if !matches!(role, group::Role::Pet)
&& !self.group_members.values().any(|r| !matches!(r, group::Role::Pet)) && !self
.group_members
.values()
.any(|r| !matches!(r, group::Role::Pet))
{ {
frontend_events.push(Event::Chat(comp::ChatType::Meta.chat_msg( frontend_events.push(Event::Chat(comp::ChatType::Meta.chat_msg(
"Type /g or /group to chat with your group members" "Type /g or /group to chat with your group members",
))); )));
} }
if self.group_members.insert(uid, role) == Some(role) { if self.group_members.insert(uid, role) == Some(role) {
@ -1079,10 +1089,13 @@ impl Client {
if !self.pending_invites.insert(uid) { if !self.pending_invites.insert(uid) {
warn!("Received message about pending invite that was already pending"); warn!("Received message about pending invite that was already pending");
} }
} },
ServerMsg::InviteComplete { target, answer } => { ServerMsg::InviteComplete { target, answer } => {
if !self.pending_invites.remove(&target) { if !self.pending_invites.remove(&target) {
warn!("Received completed invite message for invite that was not in the list of pending invites") warn!(
"Received completed invite message for invite that was not in the \
list of pending invites"
)
} }
// TODO: expose this as a new event variant instead of going // TODO: expose this as a new event variant instead of going
// through the chat // through the chat
@ -1093,7 +1106,7 @@ impl Client {
InviteAnswer::TimedOut => "Invite timed out", InviteAnswer::TimedOut => "Invite timed out",
}; };
frontend_events.push(Event::Chat(comp::ChatType::Meta.chat_msg(msg))); frontend_events.push(Event::Chat(comp::ChatType::Meta.chat_msg(msg)));
} },
ServerMsg::Ping => { ServerMsg::Ping => {
self.singleton_stream.send(ClientMsg::Pong)?; self.singleton_stream.send(ClientMsg::Pong)?;
}, },

View File

@ -54,12 +54,13 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani
// Disallow inviting entity that is already in your group // Disallow inviting entity that is already in your group
let groups = state.ecs().read_storage::<Group>(); let groups = state.ecs().read_storage::<Group>();
let group_manager = state.ecs().read_resource::<GroupManager>(); let group_manager = state.ecs().read_resource::<GroupManager>();
if groups.get(entity).map_or(false, |group| { let already_in_same_group = groups.get(entity).map_or(false, |group| {
group_manager group_manager
.group_info(*group) .group_info(*group)
.map_or(false, |g| g.leader == entity) .map_or(false, |g| g.leader == entity)
&& groups.get(invitee) == Some(group) && groups.get(invitee) == Some(group)
}) { });
if already_in_same_group {
// Inform of failure // Inform of failure
if let Some(client) = clients.get_mut(entity) { if let Some(client) = clients.get_mut(entity) {
client.notify(ChatType::Meta.server_msg( client.notify(ChatType::Meta.server_msg(
@ -73,7 +74,7 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani
// Check if group max size is already reached // Check if group max size is already reached
// Adding the current number of pending invites // Adding the current number of pending invites
if state let group_size_limit_reached = state
.ecs() .ecs()
.read_storage() .read_storage()
.get(entity) .get(entity)
@ -88,8 +89,8 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani
}) })
.unwrap_or(1) as usize .unwrap_or(1) as usize
+ pending_invites.get(entity).map_or(0, |p| p.0.len()) + pending_invites.get(entity).map_or(0, |p| p.0.len())
>= max_group_size as usize >= max_group_size as usize;
{ if group_size_limit_reached {
// Inform inviter that they have reached the group size limit // Inform inviter that they have reached the group size limit
if let Some(client) = clients.get_mut(entity) { if let Some(client) = clients.get_mut(entity) {
client.notify( client.notify(
@ -161,12 +162,10 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani
} }
} else if agents.contains(invitee) { } else if agents.contains(invitee) {
send_invite(); send_invite();
} else { } else if let Some(client) = clients.get_mut(entity) {
if let Some(client) = clients.get_mut(entity) { client.notify(
client.notify( ChatType::Meta.server_msg("Can't invite, not a player or npc".to_owned()),
ChatType::Meta.server_msg("Can't invite, not a player or npc".to_owned()), );
);
}
} }
// Notify inviter that the invite is pending // Notify inviter that the invite is pending

View File

@ -509,13 +509,18 @@ impl Server {
.nanos as i64; .nanos as i64;
let terrain_nanos = self.state.ecs().read_resource::<sys::TerrainTimer>().nanos as i64; let terrain_nanos = self.state.ecs().read_resource::<sys::TerrainTimer>().nanos as i64;
let waypoint_nanos = self.state.ecs().read_resource::<sys::WaypointTimer>().nanos as i64; let waypoint_nanos = self.state.ecs().read_resource::<sys::WaypointTimer>().nanos as i64;
let invite_timeout_nanos = self.state.ecs().read_resource::<sys::InviteTimeoutTimer>().nanos as i64; let invite_timeout_nanos = self
.state
.ecs()
.read_resource::<sys::InviteTimeoutTimer>()
.nanos as i64;
let stats_persistence_nanos = self let stats_persistence_nanos = self
.state .state
.ecs() .ecs()
.read_resource::<sys::PersistenceTimer>() .read_resource::<sys::PersistenceTimer>()
.nanos as i64; .nanos as i64;
let total_sys_ran_in_dispatcher_nanos = terrain_nanos + waypoint_nanos + invite_timeout_nanos; let total_sys_ran_in_dispatcher_nanos =
terrain_nanos + waypoint_nanos + invite_timeout_nanos;
// Report timing info // Report timing info
self.tick_metrics self.tick_metrics

View File

@ -118,13 +118,13 @@ impl<'a> Widget for Group<'a> {
} }
} }
#[allow(clippy::blocks_in_if_conditions)] // TODO: Pending review in #587 fn style(&self) -> Self::Style {}
fn style(&self) -> Self::Style { () }
//TODO: Disband groups when there's only one member in them //TODO: Disband groups when there's only one member in them
//TODO: Always send health, energy, level and position of group members to the //TODO: Always send health, energy, level and position of group members to the
// client // client
#[allow(clippy::unused_unit)] // TODO: Pending review in #587 #[allow(clippy::unused_unit)] // TODO: Pending review in #587
#[allow(clippy::blocks_in_if_conditions)] // TODO: Pending review in #587
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event { fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs { state, ui, .. } = args; let widget::UpdateArgs { state, ui, .. } = args;
@ -326,11 +326,11 @@ impl<'a> Widget for Group<'a> {
21..=40 => LOW_HP_COLOR, 21..=40 => LOW_HP_COLOR,
_ => HP_COLOR, _ => HP_COLOR,
}; };
let lead = if uid == leader { true } else { false }; let is_leader = uid == leader;
// Don't show panel for the player! // Don't show panel for the player!
// Panel BG // Panel BG
back.w_h(152.0, 36.0) back.w_h(152.0, 36.0)
.color(if lead { .color(if is_leader {
Some(ERROR_COLOR) Some(ERROR_COLOR)
} else { } else {
Some(TEXT_COLOR) Some(TEXT_COLOR)
@ -396,7 +396,7 @@ impl<'a> Widget for Group<'a> {
.bottom_left_with_margins_on(state.ids.member_panels_txt_bg[i], 2.0, 2.0) .bottom_left_with_margins_on(state.ids.member_panels_txt_bg[i], 2.0, 2.0)
.font_size(20) .font_size(20)
.font_id(self.fonts.cyri.conrod_id) .font_id(self.fonts.cyri.conrod_id)
.color(if lead { ERROR_COLOR } else { GROUP_COLOR }) .color(if is_leader { ERROR_COLOR } else { GROUP_COLOR })
.w(300.0) // limit name length display .w(300.0) // limit name length display
.set(state.ids.member_panels_txt[i], ui); .set(state.ids.member_panels_txt[i], ui);
if let Some(energy) = energy { if let Some(energy) = energy {

View File

@ -1186,7 +1186,8 @@ impl<'a> Widget for Skillbar<'a> {
if let BarNumbers::Values = bar_values { if let BarNumbers::Values = bar_values {
let mut hp_text = format!( let mut hp_text = format!(
"{}/{}", "{}/{}",
(self.stats.health.current() / 10).max(1) as u32, // Don't show 0 health for living players (self.stats.health.current() / 10).max(1) as u32, /* Don't show 0 health for
* living players */
(self.stats.health.maximum() / 10) as u32 (self.stats.health.maximum() / 10) as u32
); );
let mut energy_text = format!( let mut energy_text = format!(