mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
add log performance button in proxy ui
This commit is contained in:
parent
0bac664c0f
commit
3beed97f2d
10 changed files with 110 additions and 47 deletions
|
@ -434,6 +434,15 @@ pub(crate) fn print_error(error: eyre::Report) -> eyre::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn print(string: &str) -> eyre::Result<()> {
|
||||
let lua = LuaState::current()?;
|
||||
lua.get_global(c"EwextPrint");
|
||||
lua.push_string(string);
|
||||
lua.call(1, 0i32)
|
||||
.wrap_err("Failed to call EwextPrintError")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// Only gets called by lua when loading a module.
|
||||
|
@ -720,6 +729,19 @@ pub unsafe extern "C" fn luaopen_ewext1(lua: *mut lua_State) -> c_int {
|
|||
})?
|
||||
}
|
||||
add_lua_fn!(des_broken_wand);
|
||||
|
||||
fn set_log(lua: LuaState) -> eyre::Result<()> {
|
||||
ExtState::with_global(|state| {
|
||||
state
|
||||
.modules
|
||||
.entity_sync
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.set_perf(lua.to_bool(1));
|
||||
Ok(())
|
||||
})?
|
||||
}
|
||||
add_lua_fn!(set_log);
|
||||
}
|
||||
println!("Initializing ewext - Ok");
|
||||
1
|
||||
|
|
|
@ -56,8 +56,12 @@ pub(crate) struct EntitySync {
|
|||
local_index: usize,
|
||||
remote_index: FxHashMap<PeerId, usize>,
|
||||
peer_order: Vec<PeerId>,
|
||||
log_performance: bool,
|
||||
}
|
||||
impl EntitySync {
|
||||
pub(crate) fn set_perf(&mut self, perf: bool) {
|
||||
self.log_performance = perf;
|
||||
}
|
||||
/*pub(crate) fn has_gid(&self, gid: Gid) -> bool {
|
||||
self.local_diff_model.has_gid(gid) || self.remote_models.values().any(|r| r.has_gid(gid))
|
||||
}*/
|
||||
|
@ -101,6 +105,7 @@ impl Default for EntitySync {
|
|||
local_index: 0,
|
||||
remote_index: Default::default(),
|
||||
peer_order: Vec::new(),
|
||||
log_performance: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -547,6 +552,8 @@ impl Module for EntitySync {
|
|||
self.local_diff_model.enable_later()?;
|
||||
self.local_diff_model.phys_later()?;
|
||||
let t = self.local_diff_model.update_pending_authority()?;
|
||||
let mut times = vec![0; 3];
|
||||
times[0] = t;
|
||||
for ent in self.look_current_entity.0.get() + 1..=EntityID::max_in_use()?.0.get() {
|
||||
if let Ok(ent) = EntityID::try_from(ent) {
|
||||
self.on_new_entity(ent, false)?;
|
||||
|
@ -560,12 +567,14 @@ impl Module for EntitySync {
|
|||
}
|
||||
}
|
||||
let mut t = start.elapsed().as_micros() + t;
|
||||
times[1] = t;
|
||||
{
|
||||
let (diff, dead);
|
||||
(diff, dead, t, self.local_index) = self
|
||||
.local_diff_model
|
||||
.update_tracked_entities(ctx, self.local_index, t)
|
||||
.wrap_err("Failed to update locally tracked entities")?;
|
||||
times[2] = t;
|
||||
let new_intersects = self.interest_tracker.got_any_new_interested();
|
||||
if !new_intersects.is_empty() {
|
||||
let init = self.local_diff_model.make_init();
|
||||
|
@ -648,6 +657,7 @@ impl Module for EntitySync {
|
|||
.apply_entities(ctx, *vi, t)
|
||||
.wrap_err("Failed to apply entity infos")?;
|
||||
self.remote_index.insert(*owner, v);
|
||||
times.push(t);
|
||||
for lid in remote_model.drain_grab_request() {
|
||||
send_remotedes(
|
||||
ctx,
|
||||
|
@ -717,6 +727,9 @@ impl Module for EntitySync {
|
|||
ctx.net
|
||||
.send(&NoitaOutbound::DesToProxy(UpdatePositions(pos_data)))?;
|
||||
}
|
||||
if self.log_performance {
|
||||
crate::print(&format!("{:?}", times))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -2319,6 +2319,12 @@ impl App {
|
|||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
let mut temp = netman.log_performance.load(Ordering::Relaxed);
|
||||
if ui.checkbox(&mut temp, "log performance metrics, requires noita to be restarted").changed() {
|
||||
netman.log_performance.store(temp, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
}
|
||||
ConnectedMenu::Mods => {
|
||||
let mods_list = netman.active_mods.lock().unwrap();
|
||||
|
|
|
@ -213,6 +213,7 @@ pub struct NetManager {
|
|||
pub players_sprite: Mutex<FxHashMap<OmniPeerId, (Option<WorldPos>, bool, bool, RgbaImage)>>,
|
||||
pub reset_map: AtomicBool,
|
||||
colors: Mutex<FxHashMap<u16, u32>>,
|
||||
pub log_performance: AtomicBool,
|
||||
}
|
||||
|
||||
impl NetManager {
|
||||
|
@ -255,6 +256,7 @@ impl NetManager {
|
|||
no_chunkmap_to_players: AtomicBool::new(true),
|
||||
no_chunkmap: AtomicBool::new(true),
|
||||
colors: Default::default(),
|
||||
log_performance: AtomicBool::new(false),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
@ -1064,6 +1066,10 @@ impl NetManager {
|
|||
"perk_ban_list",
|
||||
lst.perk_ban_list.unwrap_or(def.perk_ban_list).as_str(),
|
||||
);
|
||||
state.try_ws_write_option(
|
||||
"log_performance",
|
||||
self.log_performance.load(Ordering::Relaxed),
|
||||
);
|
||||
state.try_ws_write_option(
|
||||
"spell_ban_list",
|
||||
lst.spell_ban_list.unwrap_or(def.spell_ban_list).as_str(),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
dofile_once("data/scripts/lib/utilities.lua")
|
||||
|
||||
local entity_id = GetUpdatedEntityID()
|
||||
local pos_x, pos_y = EntityGetTransform( entity_id )
|
||||
local pos_x, pos_y = EntityGetTransform(entity_id)
|
||||
pos_x = pos_x - 5
|
||||
|
||||
local stones = {
|
||||
|
@ -26,7 +26,7 @@ if not GameHasFlagRun("ew_flag_this_is_host") then
|
|||
return
|
||||
end
|
||||
|
||||
for i=1,count do
|
||||
for i = 1, count do
|
||||
local obj
|
||||
local r = ProceduralRandomf(i + pos_x, pos_y + 4)
|
||||
if r > 0.9 then
|
||||
|
|
|
@ -28,11 +28,19 @@ ctx.init = function()
|
|||
ctx.host_frame_num = 0
|
||||
ctx.is_texting = false
|
||||
ctx.stop_cam = false
|
||||
ctx.timings = ""
|
||||
end
|
||||
|
||||
local function is_measure_perf_enabled()
|
||||
-- return ctx.proxy_opt.debug
|
||||
return false
|
||||
return ctx.proxy_opt.log_performance
|
||||
end
|
||||
|
||||
function ctx.finish()
|
||||
if is_measure_perf_enabled() and string.len(ctx.timings) > 1 then
|
||||
print(string.sub(ctx.timings, 1, -2) .. "}")
|
||||
ctx.timings = "{"
|
||||
end
|
||||
end
|
||||
|
||||
function ctx.add_hook(hook_name, system_name, fn)
|
||||
|
@ -45,10 +53,8 @@ function ctx.add_hook(hook_name, system_name, fn)
|
|||
local start_time = GameGetRealWorldTimeSinceStarted()
|
||||
util.tpcall(entry.fn, ...)
|
||||
local end_time = GameGetRealWorldTimeSinceStarted()
|
||||
local delta = (end_time - start_time) * 1000
|
||||
if delta > 0.02 then
|
||||
print("Hook " .. hook_name .. " took " .. delta .. " ms to run for " .. entry.system_name)
|
||||
end
|
||||
local delta = (end_time - start_time) * 1000000
|
||||
ctx.timings = ctx.timings .. entry.system_name .. ":" .. delta .. ","
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
|
@ -11,6 +11,9 @@ local module = {}
|
|||
EwextSerialize = util.serialize_entity
|
||||
EwextDeserialize = util.deserialize_entity
|
||||
EwextPrintError = util.print_error
|
||||
function EwextPrint(s)
|
||||
print(s)
|
||||
end
|
||||
function EwextAddInitLuaComponent(entity, file)
|
||||
return EntityAddComponent2(entity, "LuaComponent", {
|
||||
script_source_file = file,
|
||||
|
@ -29,6 +32,7 @@ function module.on_world_initialized()
|
|||
local material_list = tonumber(ffi.cast("intptr_t", world_ffi.get_material_ptr(0)))
|
||||
ewext.init_particle_world_state(grid_world, chunk_map, material_list)
|
||||
ewext.module_on_world_init()
|
||||
ewext.set_log(ctx.proxy_opt.log_performance)
|
||||
end
|
||||
|
||||
local function oh_another_world_state(entity)
|
||||
|
|
|
@ -64,7 +64,12 @@ local first = true
|
|||
|
||||
local function hole(item)
|
||||
local ce = EntityGetFirstComponent(item, "CellEaterComponent")
|
||||
if ce == nil or ComponentGetValue2(ce, "only_stain") or ComponentGetValue2(ce, "limited_materials") or EntityGetFirstComponent(item, "PhysicsBodyComponent") ~= nil then
|
||||
if
|
||||
ce == nil
|
||||
or ComponentGetValue2(ce, "only_stain")
|
||||
or ComponentGetValue2(ce, "limited_materials")
|
||||
or EntityGetFirstComponent(item, "PhysicsBodyComponent") ~= nil
|
||||
then
|
||||
return
|
||||
end
|
||||
local r = 0
|
||||
|
|
|
@ -634,6 +634,7 @@ function OnWorldPostUpdate() -- This is called every time the game has finished
|
|||
util.tpcall(on_world_post_update_inner)
|
||||
ctx.events = {}
|
||||
net.proxy_send("flush", "")
|
||||
ctx.finish()
|
||||
end
|
||||
|
||||
function register_localizations(translation_file, clear_count)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue