mirror of
https://codeberg.org/demostf/parser.git
synced 2026-10-01 00:34:06 +02:00
clippy fixes
This commit is contained in:
parent
1a5960f7c4
commit
6cfd4990a6
13 changed files with 55 additions and 61 deletions
|
|
@ -616,15 +616,14 @@ impl GameState {
|
|||
}
|
||||
|
||||
pub fn projectile_destroy(&mut self, id: EntityId) {
|
||||
if let Some(projectile) = self.projectiles.remove(&id) {
|
||||
if let Some(target) = self.check_collision(&projectile) {
|
||||
if let Some(projectile) = self.projectiles.remove(&id)
|
||||
&& let Some(target) = self.check_collision(&projectile) {
|
||||
self.collisions.push(Collision {
|
||||
tick: self.tick,
|
||||
target: target.entity,
|
||||
projectile,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_building(&mut self, entity_id: EntityId) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ impl Eq for GameEventDefinition {}
|
|||
|
||||
impl PartialOrd for GameEventDefinition {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.id.cmp(&other.id))
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::demo::parser::ParseBitSkip;
|
|||
use crate::demo::sendprop::{SendProp, SendPropIdentifier, SendPropValue};
|
||||
use crate::{Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
||||
use parse_display::{Display, FromStr};
|
||||
use std::cmp::{Ordering, min};
|
||||
use std::cmp::{min, Ordering};
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::demo::data::ServerTick;
|
||||
|
|
@ -594,7 +594,7 @@ impl PacketEntitiesMessage {
|
|||
let mut last_index: i32 = -1;
|
||||
|
||||
let mut props: Vec<&SendProp> = props.into_iter().collect();
|
||||
props.sort_by(|a, b| a.index.cmp(&b.index));
|
||||
props.sort_by_key(|a| a.index);
|
||||
|
||||
for prop in props {
|
||||
true.write(stream)?;
|
||||
|
|
|
|||
|
|
@ -161,11 +161,7 @@ impl<'a> ParseBitSkip<'a> for CreateStringTableMessage<'a> {
|
|||
|
||||
#[cfg(feature = "write")]
|
||||
impl Encode for CreateStringTableMessage<'_> {
|
||||
fn encode(
|
||||
&self,
|
||||
stream: &mut BitWriteStream<LittleEndian>,
|
||||
state: &ParserState,
|
||||
) -> Result<()> {
|
||||
fn encode(&self, stream: &mut BitWriteStream<LittleEndian>, state: &ParserState) -> Result<()> {
|
||||
let table = &self.table;
|
||||
table.name.write(stream)?;
|
||||
table.max_entries.write(stream)?;
|
||||
|
|
@ -173,12 +169,11 @@ impl Encode for CreateStringTableMessage<'_> {
|
|||
(table.entries.len() as u16).write_sized(stream, encode_bits + 1)?;
|
||||
|
||||
// threshold and both widths are the ones used by the read side above
|
||||
let (length_bits, encode_length): (usize, fn(u32) -> u64) =
|
||||
if state.protocol_version > 23 {
|
||||
(40, encode_var_int_fixed)
|
||||
} else {
|
||||
(20, |length| length as u64)
|
||||
};
|
||||
let (length_bits, encode_length): (usize, fn(u32) -> u64) = if state.protocol_version > 23 {
|
||||
(40, encode_var_int_fixed)
|
||||
} else {
|
||||
(20, |length| length as u64)
|
||||
};
|
||||
stream.reserve_int::<ParseError, _>(length_bits, |stream| {
|
||||
table.fixed_user_data_size.is_some().write(stream)?;
|
||||
if let Some(fixed_size) = table.fixed_user_data_size {
|
||||
|
|
|
|||
|
|
@ -110,12 +110,11 @@ impl Encode for TempEntitiesMessage {
|
|||
count.write(stream)?;
|
||||
|
||||
// threshold and both widths are the ones used by the read side above
|
||||
let (length_bits, encode_length): (usize, fn(u32) -> u64) =
|
||||
if state.protocol_version > 23 {
|
||||
(40, encode_var_int_fixed)
|
||||
} else {
|
||||
(17, |length| length as u64)
|
||||
};
|
||||
let (length_bits, encode_length): (usize, fn(u32) -> u64) = if state.protocol_version > 23 {
|
||||
(40, encode_var_int_fixed)
|
||||
} else {
|
||||
(17, |length| length as u64)
|
||||
};
|
||||
stream.reserve_int::<ParseError, _>(length_bits, |stream| {
|
||||
let start = stream.bit_len();
|
||||
let mut last_class_id = u16::MAX.into();
|
||||
|
|
|
|||
|
|
@ -358,11 +358,10 @@ impl ParseSendTable {
|
|||
exclude_table.as_str(),
|
||||
prop.name.as_str(),
|
||||
))
|
||||
} else if let Some(table) = prop.get_data_table(tables) {
|
||||
if !processed_tables.contains(&&table.name) {
|
||||
} else if let Some(table) = prop.get_data_table(tables)
|
||||
&& !processed_tables.contains(&&table.name) {
|
||||
table.build_excludes(tables, processed_tables, excludes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use bitbuffer::{BitWrite, BitWriteStream, Endianness};
|
|||
use num_enum::TryFromPrimitive;
|
||||
use parse_display::{Display, FromStr};
|
||||
use serde::de::Error;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer, ser::SerializeMap};
|
||||
use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
|
|
@ -475,12 +475,12 @@ impl Analyser {
|
|||
.push(ChatMessage::from_message(text_message, tick));
|
||||
}
|
||||
}
|
||||
UserMessage::Text(text_message) => {
|
||||
if text_message.location == HudTextLocation::PrintTalk {
|
||||
self.state
|
||||
.chat
|
||||
.push(ChatMessage::from_text(text_message, tick));
|
||||
}
|
||||
UserMessage::Text(text_message)
|
||||
if text_message.location == HudTextLocation::PrintTalk =>
|
||||
{
|
||||
self.state
|
||||
.chat
|
||||
.push(ChatMessage::from_text(text_message, tick));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -504,10 +504,8 @@ impl Analyser {
|
|||
user_state.team = spawn.team;
|
||||
}
|
||||
}
|
||||
GameEvent::TeamPlayRoundWin(event) => {
|
||||
if event.win_reason != WIN_REASON_TIME_LIMIT {
|
||||
self.state.rounds.push(Round::from_event(event, tick))
|
||||
}
|
||||
GameEvent::TeamPlayRoundWin(event) if event.win_reason != WIN_REASON_TIME_LIMIT => {
|
||||
self.state.rounds.push(Round::from_event(event, tick))
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,17 +158,14 @@ impl GameStateAnalyser {
|
|||
return;
|
||||
};
|
||||
|
||||
if entity.update_type == UpdateType::Enter {
|
||||
if let Some(prop) = entity
|
||||
if entity.update_type == UpdateType::Enter
|
||||
&& let Some(prop) = entity
|
||||
.get_prop_by_identifier(&OUTER, parser_state)
|
||||
.or_else(|| entity.get_prop_by_identifier(&OUTER2, parser_state))
|
||||
{
|
||||
if let Ok(outer) = Handle::try_from(&prop.value) {
|
||||
&& let Ok(outer) = Handle::try_from(&prop.value) {
|
||||
self.outer_map.insert(outer, entity.entity_index);
|
||||
self.outer_map_rev.insert(entity.entity_index, outer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match class_name.as_str() {
|
||||
"CTFPlayer" => handle_player_entity(&mut self.state, entity, parser_state),
|
||||
|
|
|
|||
|
|
@ -165,8 +165,8 @@ pub fn handle_player_resource(
|
|||
parser_state: &ParserState,
|
||||
) {
|
||||
for prop in entity.props(parser_state) {
|
||||
if let Some((table_name, prop_name)) = prop.identifier.names() {
|
||||
if let Ok(player_id) = u32::from_str(prop_name.as_str()) {
|
||||
if let Some((table_name, prop_name)) = prop.identifier.names()
|
||||
&& let Ok(player_id) = u32::from_str(prop_name.as_str()) {
|
||||
let entity_id = EntityId::from(player_id);
|
||||
if let Some(player) = state
|
||||
.players
|
||||
|
|
@ -200,6 +200,5 @@ pub fn handle_player_resource(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,13 +25,11 @@ pub fn handle_medigun_entity(
|
|||
ty = MedigunType::Vaccinator;
|
||||
}
|
||||
|
||||
if let Some(handle) = entity.get_own_prop_value_by_identifier::<Handle>(OUTER) {
|
||||
if let Some(player) = state.get_player_by_weapon_handle(handle) {
|
||||
if let PlayerClassData::Medic { medigun, .. } = &mut player.class_data {
|
||||
if let Some(handle) = entity.get_own_prop_value_by_identifier::<Handle>(OUTER)
|
||||
&& let Some(player) = state.get_player_by_weapon_handle(handle)
|
||||
&& let PlayerClassData::Medic { medigun, .. } = &mut player.class_data {
|
||||
*medigun = ty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(target_handle) = entity.get_own_prop_value_by_identifier::<Handle>(TARGET) {
|
||||
|
|
@ -43,8 +41,8 @@ pub fn handle_medigun_entity(
|
|||
.copied()
|
||||
.and_then(|self_handle| state.get_player_by_weapon_handle(self_handle));
|
||||
|
||||
if let Some(medic) = medic {
|
||||
if let PlayerClassData::Medic {
|
||||
if let Some(medic) = medic
|
||||
&& let PlayerClassData::Medic {
|
||||
target,
|
||||
last_target,
|
||||
..
|
||||
|
|
@ -55,6 +53,5 @@ pub fn handle_medigun_entity(
|
|||
*last_target = target_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -302,13 +302,12 @@ impl ParserState {
|
|||
}
|
||||
|
||||
pub fn handle_string_entry(&mut self, table: &str, _index: usize, entry: &StringTableEntry) {
|
||||
if table == "instancebaseline" {
|
||||
if let (Some(extra), Ok(class_id)) = (&entry.extra_data, entry.text().parse()) {
|
||||
if table == "instancebaseline"
|
||||
&& let (Some(extra), Ok(class_id)) = (&entry.extra_data, entry.text().parse()) {
|
||||
let baseline = StaticBaseline::new(class_id, extra.data.to_owned());
|
||||
self.static_baselines.insert(class_id, baseline);
|
||||
self.parsed_static_baselines.borrow_mut().remove(&class_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn index_for_prop(&self, class: ClassId, prop: SendPropIdentifier) -> Option<u32> {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::{ParseError, ReadResult, Result, Stream};
|
|||
use bitbuffer::{BitRead, BitReadStream, Endianness, LittleEndian};
|
||||
#[cfg(feature = "write")]
|
||||
use bitbuffer::{BitWrite, BitWriteSized, BitWriteStream};
|
||||
use enumflags2::{BitFlags, bitflags};
|
||||
use enumflags2::{bitflags, BitFlags};
|
||||
#[cfg(feature = "write")]
|
||||
use num_traits::Signed;
|
||||
use parse_display::Display;
|
||||
|
|
@ -697,7 +697,11 @@ impl SendPropValue {
|
|||
0.0f32
|
||||
};
|
||||
|
||||
if is_negative { -z } else { z }
|
||||
if is_negative {
|
||||
-z
|
||||
} else {
|
||||
z
|
||||
}
|
||||
}
|
||||
_ => Self::read_float(stream, float_definition)?,
|
||||
};
|
||||
|
|
@ -1554,7 +1558,11 @@ pub fn read_bit_normal(stream: &mut Stream) -> ReadResult<f32> {
|
|||
let is_negative = stream.read()?;
|
||||
let frac_val: u16 = stream.read_sized(11)?;
|
||||
let value = (frac_val as f32) * get_frac_factor(11);
|
||||
if is_negative { Ok(-value) } else { Ok(value) }
|
||||
if is_negative {
|
||||
Ok(-value)
|
||||
} else {
|
||||
Ok(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "write")]
|
||||
|
|
|
|||
|
|
@ -155,7 +155,11 @@ fn re_encode_test(input_file: &str) {
|
|||
|
||||
// a desync shows up as the packet loop quietly stopping early, so the
|
||||
// round trip above passes while most of the demo is never looked at
|
||||
assert!(!packets.incomplete, "{} was not read to the end", input_file);
|
||||
assert!(
|
||||
!packets.incomplete,
|
||||
"{} was not read to the end",
|
||||
input_file
|
||||
);
|
||||
}
|
||||
|
||||
/// A demo recorded on an older protocol must be parsed with that protocol, not
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue