-
- auto world_iter = state->GetWorld().Entities().begin();
- auto world_end = state->GetWorld().Entities().end();
-
- uint32_t count = 0;
- pack.ReadEntityCount(count);
-
- for (uint32_t i = 0; i < count; ++i) {
- uint32_t entity_id = 0;
- pack.ReadEntityID(entity_id, i);
-
- while (world_iter != world_end && world_iter->ID() < entity_id) {
- ++world_iter;
- }
- if (world_iter == world_end) {
- // nothing can be done from here
- return;
- }
- if (world_iter->ID() == entity_id) {
- if (UpdateEntity(entity_id, pack.Seq())) {
- pack.ReadEntityState(world_iter->GetState(), i);
- }
- }
- }
-}
-
-bool MasterState::UpdateEntity(uint32_t entity_id, uint16_t seq) {
- auto entry = update_status.find(entity_id);
- if (entry == update_status.end()) {
- update_status.emplace(entity_id, UpdateStatus{ seq, update_timer.Elapsed() });
- return true;
- }
-
- int pack_diff = int16_t(seq) - int16_t(entry->second.last_packet);
- int time_diff = update_timer.Elapsed() - entry->second.last_update;
- entry->second.last_update = update_timer.Elapsed();
-
- if (pack_diff > 0 || time_diff > 1500) {
- entry->second.last_packet = seq;
- return true;
- } else {
- return false;
- }
-}
-
-void MasterState::ClearEntity(uint32_t entity_id) {
- update_status.erase(entity_id);