mirror of
https://codeberg.org/demostf/parser.git
synced 2026-10-01 08:44:05 +02:00
clippy fixes
This commit is contained in:
parent
1a5960f7c4
commit
6cfd4990a6
13 changed files with 55 additions and 61 deletions
|
|
@ -616,8 +616,8 @@ impl GameState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn projectile_destroy(&mut self, id: EntityId) {
|
pub fn projectile_destroy(&mut self, id: EntityId) {
|
||||||
if let Some(projectile) = self.projectiles.remove(&id) {
|
if let Some(projectile) = self.projectiles.remove(&id)
|
||||||
if let Some(target) = self.check_collision(&projectile) {
|
&& let Some(target) = self.check_collision(&projectile) {
|
||||||
self.collisions.push(Collision {
|
self.collisions.push(Collision {
|
||||||
tick: self.tick,
|
tick: self.tick,
|
||||||
target: target.entity,
|
target: target.entity,
|
||||||
|
|
@ -625,7 +625,6 @@ impl GameState {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn remove_building(&mut self, entity_id: EntityId) {
|
pub fn remove_building(&mut self, entity_id: EntityId) {
|
||||||
self.buildings.remove(&entity_id);
|
self.buildings.remove(&entity_id);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ impl Eq for GameEventDefinition {}
|
||||||
|
|
||||||
impl PartialOrd for GameEventDefinition {
|
impl PartialOrd for GameEventDefinition {
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
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::demo::sendprop::{SendProp, SendPropIdentifier, SendPropValue};
|
||||||
use crate::{Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
use crate::{Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
||||||
use parse_display::{Display, FromStr};
|
use parse_display::{Display, FromStr};
|
||||||
use std::cmp::{Ordering, min};
|
use std::cmp::{min, Ordering};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use crate::demo::data::ServerTick;
|
use crate::demo::data::ServerTick;
|
||||||
|
|
@ -594,7 +594,7 @@ impl PacketEntitiesMessage {
|
||||||
let mut last_index: i32 = -1;
|
let mut last_index: i32 = -1;
|
||||||
|
|
||||||
let mut props: Vec<&SendProp> = props.into_iter().collect();
|
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 {
|
for prop in props {
|
||||||
true.write(stream)?;
|
true.write(stream)?;
|
||||||
|
|
|
||||||
|
|
@ -161,11 +161,7 @@ impl<'a> ParseBitSkip<'a> for CreateStringTableMessage<'a> {
|
||||||
|
|
||||||
#[cfg(feature = "write")]
|
#[cfg(feature = "write")]
|
||||||
impl Encode for CreateStringTableMessage<'_> {
|
impl Encode for CreateStringTableMessage<'_> {
|
||||||
fn encode(
|
fn encode(&self, stream: &mut BitWriteStream<LittleEndian>, state: &ParserState) -> Result<()> {
|
||||||
&self,
|
|
||||||
stream: &mut BitWriteStream<LittleEndian>,
|
|
||||||
state: &ParserState,
|
|
||||||
) -> Result<()> {
|
|
||||||
let table = &self.table;
|
let table = &self.table;
|
||||||
table.name.write(stream)?;
|
table.name.write(stream)?;
|
||||||
table.max_entries.write(stream)?;
|
table.max_entries.write(stream)?;
|
||||||
|
|
@ -173,8 +169,7 @@ impl Encode for CreateStringTableMessage<'_> {
|
||||||
(table.entries.len() as u16).write_sized(stream, encode_bits + 1)?;
|
(table.entries.len() as u16).write_sized(stream, encode_bits + 1)?;
|
||||||
|
|
||||||
// threshold and both widths are the ones used by the read side above
|
// threshold and both widths are the ones used by the read side above
|
||||||
let (length_bits, encode_length): (usize, fn(u32) -> u64) =
|
let (length_bits, encode_length): (usize, fn(u32) -> u64) = if state.protocol_version > 23 {
|
||||||
if state.protocol_version > 23 {
|
|
||||||
(40, encode_var_int_fixed)
|
(40, encode_var_int_fixed)
|
||||||
} else {
|
} else {
|
||||||
(20, |length| length as u64)
|
(20, |length| length as u64)
|
||||||
|
|
|
||||||
|
|
@ -110,8 +110,7 @@ impl Encode for TempEntitiesMessage {
|
||||||
count.write(stream)?;
|
count.write(stream)?;
|
||||||
|
|
||||||
// threshold and both widths are the ones used by the read side above
|
// threshold and both widths are the ones used by the read side above
|
||||||
let (length_bits, encode_length): (usize, fn(u32) -> u64) =
|
let (length_bits, encode_length): (usize, fn(u32) -> u64) = if state.protocol_version > 23 {
|
||||||
if state.protocol_version > 23 {
|
|
||||||
(40, encode_var_int_fixed)
|
(40, encode_var_int_fixed)
|
||||||
} else {
|
} else {
|
||||||
(17, |length| length as u64)
|
(17, |length| length as u64)
|
||||||
|
|
|
||||||
|
|
@ -358,13 +358,12 @@ impl ParseSendTable {
|
||||||
exclude_table.as_str(),
|
exclude_table.as_str(),
|
||||||
prop.name.as_str(),
|
prop.name.as_str(),
|
||||||
))
|
))
|
||||||
} else if let Some(table) = prop.get_data_table(tables) {
|
} else if let Some(table) = prop.get_data_table(tables)
|
||||||
if !processed_tables.contains(&&table.name) {
|
&& !processed_tables.contains(&&table.name) {
|
||||||
table.build_excludes(tables, processed_tables, excludes);
|
table.build_excludes(tables, processed_tables, excludes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: below is a direct port from the js which is a direct port from C++ and not very optimal
|
// TODO: below is a direct port from the js which is a direct port from C++ and not very optimal
|
||||||
fn push_props_end<'a>(
|
fn push_props_end<'a>(
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ use bitbuffer::{BitWrite, BitWriteStream, Endianness};
|
||||||
use num_enum::TryFromPrimitive;
|
use num_enum::TryFromPrimitive;
|
||||||
use parse_display::{Display, FromStr};
|
use parse_display::{Display, FromStr};
|
||||||
use serde::de::Error;
|
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::collections::{BTreeMap, HashMap};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
|
|
@ -475,13 +475,13 @@ impl Analyser {
|
||||||
.push(ChatMessage::from_message(text_message, tick));
|
.push(ChatMessage::from_message(text_message, tick));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UserMessage::Text(text_message) => {
|
UserMessage::Text(text_message)
|
||||||
if text_message.location == HudTextLocation::PrintTalk {
|
if text_message.location == HudTextLocation::PrintTalk =>
|
||||||
|
{
|
||||||
self.state
|
self.state
|
||||||
.chat
|
.chat
|
||||||
.push(ChatMessage::from_text(text_message, tick));
|
.push(ChatMessage::from_text(text_message, tick));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -504,11 +504,9 @@ impl Analyser {
|
||||||
user_state.team = spawn.team;
|
user_state.team = spawn.team;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GameEvent::TeamPlayRoundWin(event) => {
|
GameEvent::TeamPlayRoundWin(event) if event.win_reason != WIN_REASON_TIME_LIMIT => {
|
||||||
if event.win_reason != WIN_REASON_TIME_LIMIT {
|
|
||||||
self.state.rounds.push(Round::from_event(event, tick))
|
self.state.rounds.push(Round::from_event(event, tick))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -158,17 +158,14 @@ impl GameStateAnalyser {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if entity.update_type == UpdateType::Enter {
|
if entity.update_type == UpdateType::Enter
|
||||||
if let Some(prop) = entity
|
&& let Some(prop) = entity
|
||||||
.get_prop_by_identifier(&OUTER, parser_state)
|
.get_prop_by_identifier(&OUTER, parser_state)
|
||||||
.or_else(|| entity.get_prop_by_identifier(&OUTER2, parser_state))
|
.or_else(|| entity.get_prop_by_identifier(&OUTER2, parser_state))
|
||||||
{
|
&& let Ok(outer) = Handle::try_from(&prop.value) {
|
||||||
if let Ok(outer) = Handle::try_from(&prop.value) {
|
|
||||||
self.outer_map.insert(outer, entity.entity_index);
|
self.outer_map.insert(outer, entity.entity_index);
|
||||||
self.outer_map_rev.insert(entity.entity_index, outer);
|
self.outer_map_rev.insert(entity.entity_index, outer);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match class_name.as_str() {
|
match class_name.as_str() {
|
||||||
"CTFPlayer" => handle_player_entity(&mut self.state, entity, parser_state),
|
"CTFPlayer" => handle_player_entity(&mut self.state, entity, parser_state),
|
||||||
|
|
|
||||||
|
|
@ -165,8 +165,8 @@ pub fn handle_player_resource(
|
||||||
parser_state: &ParserState,
|
parser_state: &ParserState,
|
||||||
) {
|
) {
|
||||||
for prop in entity.props(parser_state) {
|
for prop in entity.props(parser_state) {
|
||||||
if let Some((table_name, prop_name)) = prop.identifier.names() {
|
if let Some((table_name, prop_name)) = prop.identifier.names()
|
||||||
if let Ok(player_id) = u32::from_str(prop_name.as_str()) {
|
&& let Ok(player_id) = u32::from_str(prop_name.as_str()) {
|
||||||
let entity_id = EntityId::from(player_id);
|
let entity_id = EntityId::from(player_id);
|
||||||
if let Some(player) = state
|
if let Some(player) = state
|
||||||
.players
|
.players
|
||||||
|
|
@ -201,5 +201,4 @@ pub fn handle_player_resource(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,12 @@ pub fn handle_medigun_entity(
|
||||||
ty = MedigunType::Vaccinator;
|
ty = MedigunType::Vaccinator;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(handle) = entity.get_own_prop_value_by_identifier::<Handle>(OUTER) {
|
if let Some(handle) = entity.get_own_prop_value_by_identifier::<Handle>(OUTER)
|
||||||
if let Some(player) = state.get_player_by_weapon_handle(handle) {
|
&& let Some(player) = state.get_player_by_weapon_handle(handle)
|
||||||
if let PlayerClassData::Medic { medigun, .. } = &mut player.class_data {
|
&& let PlayerClassData::Medic { medigun, .. } = &mut player.class_data {
|
||||||
*medigun = ty;
|
*medigun = ty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(target_handle) = entity.get_own_prop_value_by_identifier::<Handle>(TARGET) {
|
if let Some(target_handle) = entity.get_own_prop_value_by_identifier::<Handle>(TARGET) {
|
||||||
let target_id = state
|
let target_id = state
|
||||||
|
|
@ -43,8 +41,8 @@ pub fn handle_medigun_entity(
|
||||||
.copied()
|
.copied()
|
||||||
.and_then(|self_handle| state.get_player_by_weapon_handle(self_handle));
|
.and_then(|self_handle| state.get_player_by_weapon_handle(self_handle));
|
||||||
|
|
||||||
if let Some(medic) = medic {
|
if let Some(medic) = medic
|
||||||
if let PlayerClassData::Medic {
|
&& let PlayerClassData::Medic {
|
||||||
target,
|
target,
|
||||||
last_target,
|
last_target,
|
||||||
..
|
..
|
||||||
|
|
@ -56,5 +54,4 @@ pub fn handle_medigun_entity(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -302,14 +302,13 @@ impl ParserState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_string_entry(&mut self, table: &str, _index: usize, entry: &StringTableEntry) {
|
pub fn handle_string_entry(&mut self, table: &str, _index: usize, entry: &StringTableEntry) {
|
||||||
if table == "instancebaseline" {
|
if table == "instancebaseline"
|
||||||
if let (Some(extra), Ok(class_id)) = (&entry.extra_data, entry.text().parse()) {
|
&& let (Some(extra), Ok(class_id)) = (&entry.extra_data, entry.text().parse()) {
|
||||||
let baseline = StaticBaseline::new(class_id, extra.data.to_owned());
|
let baseline = StaticBaseline::new(class_id, extra.data.to_owned());
|
||||||
self.static_baselines.insert(class_id, baseline);
|
self.static_baselines.insert(class_id, baseline);
|
||||||
self.parsed_static_baselines.borrow_mut().remove(&class_id);
|
self.parsed_static_baselines.borrow_mut().remove(&class_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn index_for_prop(&self, class: ClassId, prop: SendPropIdentifier) -> Option<u32> {
|
pub fn index_for_prop(&self, class: ClassId, prop: SendPropIdentifier) -> Option<u32> {
|
||||||
let send_table = self.send_tables.get(usize::from(class))?;
|
let send_table = self.send_tables.get(usize::from(class))?;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use crate::{ParseError, ReadResult, Result, Stream};
|
||||||
use bitbuffer::{BitRead, BitReadStream, Endianness, LittleEndian};
|
use bitbuffer::{BitRead, BitReadStream, Endianness, LittleEndian};
|
||||||
#[cfg(feature = "write")]
|
#[cfg(feature = "write")]
|
||||||
use bitbuffer::{BitWrite, BitWriteSized, BitWriteStream};
|
use bitbuffer::{BitWrite, BitWriteSized, BitWriteStream};
|
||||||
use enumflags2::{BitFlags, bitflags};
|
use enumflags2::{bitflags, BitFlags};
|
||||||
#[cfg(feature = "write")]
|
#[cfg(feature = "write")]
|
||||||
use num_traits::Signed;
|
use num_traits::Signed;
|
||||||
use parse_display::Display;
|
use parse_display::Display;
|
||||||
|
|
@ -697,7 +697,11 @@ impl SendPropValue {
|
||||||
0.0f32
|
0.0f32
|
||||||
};
|
};
|
||||||
|
|
||||||
if is_negative { -z } else { z }
|
if is_negative {
|
||||||
|
-z
|
||||||
|
} else {
|
||||||
|
z
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => Self::read_float(stream, float_definition)?,
|
_ => 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 is_negative = stream.read()?;
|
||||||
let frac_val: u16 = stream.read_sized(11)?;
|
let frac_val: u16 = stream.read_sized(11)?;
|
||||||
let value = (frac_val as f32) * get_frac_factor(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")]
|
#[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
|
// 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
|
// 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
|
/// 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