ensure correct props when baseline is updated post create

This commit is contained in:
Robin Appelman 2022-04-23 13:33:52 +02:00
commit d4c4fd1b4f
3 changed files with 18 additions and 13 deletions

View file

@ -1,6 +1,6 @@
use std::collections::{BTreeMap, BTreeSet, HashMap}; use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::iter::once; use std::iter::once;
use std::mem::replace; use std::mem::{replace, take};
use std::num::NonZeroU32; use std::num::NonZeroU32;
use tf_demo_parser::demo::message::packetentities::{ use tf_demo_parser::demo::message::packetentities::{
EntityId, PacketEntitiesMessage, PacketEntity, UpdateType, EntityId, PacketEntitiesMessage, PacketEntity, UpdateType,
@ -52,9 +52,8 @@ impl ActiveEntities {
if existing.serial_number != entity.serial_number if existing.serial_number != entity.serial_number
&& existing.server_class != entity.server_class && existing.server_class != entity.server_class
{ {
// todo: do baselines need to be cleanup up or updated here?
*existing = entity.clone(); *existing = entity.clone();
existing.update_type = UpdateType::Enter; existing.apply_update(&entity.props);
} else { } else {
debug_assert_eq!( debug_assert_eq!(
state.server_classes[usize::from(existing.server_class)], state.server_classes[usize::from(existing.server_class)],
@ -112,14 +111,20 @@ impl ActiveEntities {
), ),
]; ];
for entity in self.entities.values_mut() { for entity in self.entities.values_mut() {
if state.instance_baselines[1] match state.instance_baselines[1].get(entity.entity_index) {
.get(entity.entity_index) Some(baseline_entity) if baseline_entity.server_class == entity.server_class => {
.filter(|baseline| baseline.server_class == entity.server_class) entity.update_type = UpdateType::Preserve;
.is_some() }
{ Some(_baseline_entity) => {
entity.update_type = UpdateType::Preserve; // encode the baseline if the baseline server class differs
} else { let props = take(&mut entity.props);
entity.update_type = UpdateType::Enter; entity.props = take(&mut entity.baseline_props);
entity.apply_update(&props);
entity.update_type = UpdateType::Enter;
}
None => {
entity.update_type = UpdateType::Enter;
}
} }
} }

View file

@ -1 +1 @@
d4a8b06910ceb9e506618e68532cd0a2 4377cdb6395a8fecc6a6ab757a541d87

View file

@ -1 +1 @@
80daeb9392ef4c26d3c884d9e641668b 6346c2553bc2c8189eebccf743248bbe