try to make world sync more work more consistently

This commit is contained in:
bgkillas 2025-03-15 00:02:35 -04:00
parent e8b575160a
commit b135e0deed
3 changed files with 10 additions and 20 deletions

View file

@ -1847,12 +1847,8 @@ impl RemoteDiffModel {
let mut end = None;
let start = if start >= l { 0 } else { start };
for (i, (lid, entity_info)) in self.entity_infos.iter().enumerate() {
match self
.tracked
.get_by_left(lid)
.and_then(|entity_id| entity_id.is_alive().then_some(*entity_id))
{
Some(entity) => {
match self.tracked.get_by_left(lid) {
Some(entity) if entity.is_alive() => {
if time + tmr.elapsed().as_micros() > 5000 || start > i {
if end.is_none() && start <= i {
end = Some(i);
@ -1888,7 +1884,7 @@ impl RemoteDiffModel {
}
}
} else {
match self.inner(ctx, entity_info, entity, lid) {
match self.inner(ctx, entity_info, *entity, lid) {
Ok(Some(lid)) => to_remove.push(lid),
Err(s) => print_error(s)?,
_ => {}

View file

@ -125,7 +125,6 @@ pub(crate) enum WorldNetMessage {
},
TransferOk {
chunk: ChunkCoord,
chunk_data: Option<ChunkData>,
listeners: FxHashSet<OmniPeerId>,
},
TransferFailed {
@ -1090,12 +1089,10 @@ impl WorldManager {
debug!("Got a request for authority transfer");
let state = self.chunk_state.get(&chunk);
if let Some(ChunkState::Authority { listeners, .. }) = state {
let chunk_data = self.outbound_model.get_chunk_data(chunk);
self.emit_msg(
Destination::Peer(source),
WorldNetMessage::TransferOk {
chunk,
chunk_data,
listeners: listeners.clone(),
},
);
@ -1117,16 +1114,8 @@ impl WorldManager {
);
}
}
WorldNetMessage::TransferOk {
chunk,
chunk_data,
listeners,
} => {
WorldNetMessage::TransferOk { chunk, listeners } => {
debug!("Transfer ok");
if let Some(chunk_data) = chunk_data {
self.inbound_model.apply_chunk_data(chunk, &chunk_data);
self.outbound_model.apply_chunk_data(chunk, &chunk_data);
}
for listener in listeners.iter() {
self.emit_msg(
Destination::Peer(*listener),

View file

@ -164,10 +164,13 @@ local function get_all_chunks(ocx, ocy, pos_data, priority, give_0)
end
end
local wait
function world_sync.on_world_update()
if ctx.run_ended then
if ctx.run_ended or (wait ~= nil and wait > GameGetFrameNum()) then
return
end
wait = nil
int = math.floor(tonumber(ModSettingGet("quant.ew.world_sync") or 4) or 4 + 0.5)
local cx, cy = GameGetCameraPos()
cx, cy = math.floor(cx / CHUNK_SIZE), math.floor(cy / CHUNK_SIZE)
@ -195,6 +198,8 @@ function world_sync.on_world_update()
else
get_all_chunks(ocx, ocy, pos_data, 16, true)
end
else
wait = GameGetFrameNum() + 30
end
else
local pri = 0