1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 10:14:06 +02:00

Merge pull request 'Fix SendPropValue::Vector encoding when the float definition is NormalFloatVar' (#9) from glyphpoch/parser:fix/send-prop-vector-encoding into master

Reviewed-on: https://codeberg.org/demostf/parser/pulls/9
Reviewed-by: Robin Appelman <icewind@noreply.codeberg.org>
This commit is contained in:
Robin Appelman 2026-04-06 20:20:59 +02:00
commit d29508a25b

View file

@ -775,7 +775,10 @@ impl SendPropValue {
let val: Vector = self.try_into()?;
Self::write_float(val.x, stream, float_definition)?;
Self::write_float(val.y, stream, float_definition)?;
Self::write_float(val.z, stream, float_definition)?;
match float_definition {
FloatDefinition::NormalVarFloat => stream.write_bool(val.z.is_negative())?,
_ => Self::write_float(val.z, stream, float_definition)?,
}
Ok(())
}
SendPropParseDefinition::VectorXY {
@ -929,6 +932,17 @@ fn test_send_prop_value_roundtrip() {
definition: FloatDefinition::Coord,
},
);
send_prop_value_roundtrip(
SendPropValue::Vector(Vector {
x: 0.0,
y: 0.0,
z: -1.0,
}),
SendPropParseDefinition::Vector {
changes_often: false,
definition: FloatDefinition::NormalVarFloat,
},
);
send_prop_value_roundtrip(
SendPropValue::VectorXY(VectorXY { x: 1.0, y: 0.0 }),
SendPropParseDefinition::VectorXY {
@ -1015,6 +1029,32 @@ fn test_send_prop_value_roundtrip() {
);
}
#[test]
#[cfg(feature = "write")]
fn test_encode_vector_normal_var_float() {
use bitbuffer::BitWriteStream;
let vector = SendPropValue::Vector(Vector {
x: 0.0f32,
y: 0.0f32,
z: -1.0f32,
});
let def = SendPropParseDefinition::Vector {
changes_often: false,
definition: FloatDefinition::NormalVarFloat,
};
let mut data = Vec::new();
let pos = {
let mut write = BitWriteStream::new(&mut data, LittleEndian);
vector.encode(&mut write, &def).unwrap();
write.bit_len()
};
assert_eq!(pos, 25);
assert_eq!(data, vec![0, 0, 0, 1]);
}
impl From<i32> for SendPropValue {
fn from(value: i32) -> Self {
SendPropValue::Integer(value as i64)