Spread out world sync over several frames.

This commit is contained in:
IQuant 2024-08-06 16:47:29 +03:00
parent a39ca3a433
commit 54d3cbe8ca
5 changed files with 23 additions and 16 deletions

View file

@ -1997,7 +1997,7 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
[[package]]
name = "noita-proxy"
version = "0.17.0"
version = "0.17.1"
dependencies = [
"argh",
"bincode",

View file

@ -5,7 +5,7 @@ resolver = "2"
[package]
name = "noita-proxy"
description = "Noita Entangled Worlds companion app."
version = "0.17.0"
version = "0.17.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -53,7 +53,7 @@ impl Default for GameSettings {
use_constant_seed: false,
item_dedup: true,
enemy_hp_mult: 1.0,
world_sync_interval: 10,
world_sync_interval: 2,
}
}
}
@ -446,7 +446,7 @@ impl App {
ui.add_space(10.0);
ui.label(tr("World-will-be-synced-every-this-many-frames"));
ui.label(tr("Higher-values-result-in-less-performance-impact"));
ui.add(Slider::new(&mut game_settings.world_sync_interval, 1..=60));
ui.add(Slider::new(&mut game_settings.world_sync_interval, 1..=10));
}
ui.label(tr("world-sync-is-pixel-sync-note"));

View file

@ -196,7 +196,8 @@ impl WorldManager {
pub(crate) fn update(&mut self) {
let mut emit_queue = Vec::new();
let unload_limit = 1;
// How many updates till we relinquish authority/stop listening.
let unload_limit = 6;
for (&chunk, state) in self.chunk_state.iter_mut() {
let chunk_last_update = self

View file

@ -19,6 +19,8 @@ local KEY_WORLD_END = 1
local CHUNK_SIZE = 128
local iter = 0
function world_sync.on_world_update()
local grid_world = world_ffi.get_grid_world()
@ -31,23 +33,27 @@ function world_sync.on_world_update()
return
end
local px, py = EntityGetTransform(player_data.entity)
-- Original Chunk x/y
local ocx, ocy = math.floor(px / CHUNK_SIZE), math.floor(py / CHUNK_SIZE)
for cx = ocx-2,ocx+2 do
for cy = ocy-2,ocy+2 do
local crect = rect.Rectangle(cx * CHUNK_SIZE, cy * CHUNK_SIZE, (cx+1) * CHUNK_SIZE, (cy+1) * CHUNK_SIZE)
if DoesWorldExistAt(crect.left, crect.top, crect.right, crect.bottom) then
local area = world.encode_area(chunk_map, crect.left, crect.top, crect.right, crect.bottom, encoded_area)
if area ~= nil then
if ctx.proxy_opt.debug then
GameCreateSpriteForXFrames("mods/quant.ew/files/debug/box_128x128.png", crect.left+64, crect.top + 64, true, 0, 0, 11, true)
end
local str = ffi.string(area, world.encoded_size(area))
net.proxy_bin_send(KEY_WORLD_FRAME, str)
local cx = ocx - 2 + iter
for cy = ocy-2,ocy+2 do
local crect = rect.Rectangle(cx * CHUNK_SIZE, cy * CHUNK_SIZE, (cx+1) * CHUNK_SIZE, (cy+1) * CHUNK_SIZE)
if DoesWorldExistAt(crect.left, crect.top, crect.right, crect.bottom) then
local area = world.encode_area(chunk_map, crect.left, crect.top, crect.right, crect.bottom, encoded_area)
if area ~= nil then
if ctx.proxy_opt.debug then
GameCreateSpriteForXFrames("mods/quant.ew/files/debug/box_128x128.png", crect.left+64, crect.top + 64, true, 0, 0, 11, true)
end
local str = ffi.string(area, world.encoded_size(area))
net.proxy_bin_send(KEY_WORLD_FRAME, str)
end
end
end
iter = iter + 1
if iter > 5 then
iter = 0
end
net.proxy_bin_send(KEY_WORLD_END, "")
end