diff --git a/noita-proxy/src/net/world.rs b/noita-proxy/src/net/world.rs index 178c7b82..9d211370 100644 --- a/noita-proxy/src/net/world.rs +++ b/noita-proxy/src/net/world.rs @@ -1264,12 +1264,12 @@ impl WorldManager { Some((x, y)) } pub(crate) fn cut_through_world_explosion(&mut self, x: i32, y: i32, r: i32, d: u8, ray: u32) { - let rays = (r * 2).clamp(16, 1024); + let rays = (r * 2).clamp(4, 1024); + let t = TAU / rays as f32; let results: Vec = (0..rays) .into_par_iter() .map(|n| { - let t = TAU / rays as f32; - let theta = t * n as f32; + let theta = t * (n as f32 + 0.5); let end_x = x + (r as f32 * theta.cos()) as i32; let end_y = y + (r as f32 * theta.sin()) as i32; if let Some((ex, ey)) = self.do_ray(x, y, end_x, end_y, ray, d) { @@ -1294,16 +1294,10 @@ impl WorldManager { rays: i32, list: Vec, ) { - let mut r = 0; - for n in &list { - if *n > r { - r = *n - } - } + let r = (*list.iter().max().unwrap_or(&0) as f64).sqrt().ceil() as i32; if r == 0 { return; } - let r = (r as f64).sqrt().ceil() as i32; let (min_cx, max_cx) = ( (x - r).div_euclid(CHUNK_SIZE as i32), (x + r).div_euclid(CHUNK_SIZE as i32), @@ -1335,8 +1329,11 @@ impl WorldManager { for icy in 0..CHUNK_SIZE as i32 { let cy = chunk_start_y + icy; let dy = cy - y; - let r = list[(rays as f32 * (dy as f32).atan2(dx as f32) / TAU) as usize]; - if dd + dy * dy <= r { + let mut i = rays as f32 * (dy as f32).atan2(dx as f32) / TAU; + if i.is_sign_negative() { + i += rays as f32 + } + if dd + dy * dy <= list[i as usize] { let px = icy as usize * CHUNK_SIZE + icx as usize; chunk.set_pixel(px, air_pixel); } diff --git a/quant.ew/files/system/enemy_sync.lua b/quant.ew/files/system/enemy_sync.lua index c13e4c79..5f497b5b 100644 --- a/quant.ew/files/system/enemy_sync.lua +++ b/quant.ew/files/system/enemy_sync.lua @@ -374,7 +374,7 @@ function enemy_sync.client_cleanup() end function enemy_sync.on_world_update_host() - local rt = math.floor(ModSettingGet("quant.ew.enemy_sync")) + local rt = tonumber(ModSettingGet("quant.ew.enemy_sync")) local n = 0 if rt == 3 then n = 2 diff --git a/quant.ew/files/system/explosion_cuts/explosion_cuts.lua b/quant.ew/files/system/explosion_cuts/explosion_cuts.lua index 5c041bc4..2243a2df 100644 --- a/quant.ew/files/system/explosion_cuts/explosion_cuts.lua +++ b/quant.ew/files/system/explosion_cuts/explosion_cuts.lua @@ -46,66 +46,56 @@ end local first = true +local function update(ent) + local proj = EntityGetFirstComponentIncludingDisabled(ent, "ProjectileComponent") + if proj ~= nil and ComponentGetValue2(proj, "on_death_explode") then + local x, y = EntityGetTransform(ent) + local r = ComponentObjectGetValue2(proj, "config_explosion", "explosion_radius") + alive[ent] = {x, y, r, + ComponentObjectGetValue2(proj, "config_explosion", "max_durability_to_destroy"), + ComponentObjectGetValue2(proj, "config_explosion", "ray_energy")} + else + local mat = EntityGetFirstComponent(ent, "MagicConvertMaterialComponent") + if mat ~= nil and ComponentGetValue2(mat, "from_material_tag") == "[solid]" then + local x, y = EntityGetTransform(ent) + alive[ent] = {x, y, ComponentGetValue2(mat, "radius"), ComponentGetValue2(mat, "to_material")} + end + end +end + function mod.on_world_update_host() if first then send_mats() first = false end - local n = EntitiesGetMaxID() - for ent = last + 1, n do - if EntityGetIsAlive(ent) then - local proj = EntityGetFirstComponentIncludingDisabled(ent, "ProjectileComponent") - if proj ~= nil and ComponentGetValue2(proj, "on_death_explode") then - local x, y = EntityGetTransform(ent) - local r = ComponentObjectGetValue2(proj, "config_explosion", "explosion_radius") - if r >= 16 then - alive[ent] = {x, y, r, - ComponentObjectGetValue2(proj, "config_explosion", "max_durability_to_destroy"), - ComponentObjectGetValue2(proj, "config_explosion", "ray_energy")} - end - else - local mat = EntityGetFirstComponent(ent, "MagicConvertMaterialComponent") - if mat ~= nil and ComponentGetValue2(mat, "from_material_tag") == "[solid]" then - local x, y = EntityGetTransform(ent) - alive[ent] = {x, y, ComponentGetValue2(mat, "radius"), ComponentGetValue2(mat, "to_material")} + local count = tonumber(ModSettingGet("quant.ew.explosions")) + for ent, data in pairs(alive) do + if not EntityGetIsAlive(ent) then + if count > 0 then + if #alive[ent] == 5 then + count = count - data[3] + local inp = math.floor(data[1]) .. " " .. math.floor(data[2]) + .. " " .. math.floor(data[3]) .. " " .. math.floor(data[4]) .. " " .. math.floor(data[5]) + net.proxy_send("cut_through_world_explosion", inp) + else + count = count - data[3] + local inp = math.floor(data[1]) .. " " .. math.floor(data[2]) + .. " " .. math.floor(data[3]) .. " " .. math.floor(data[4]) + net.proxy_send("cut_through_world_circle", inp) end + alive[ent] = nil end + else + update(ent) end end - last = n - local count = 128 - for ent, data in pairs(alive) do - if not EntityGetIsAlive(ent) and count > 0 then - if #alive[ent] == 5 then - count = count - data[3] - local inp = math.floor(data[1]) .. " " .. math.floor(data[2]) - .. " " .. math.floor(data[3]) .. " " .. math.floor(data[4]) .. " " .. math.floor(data[5]) - net.proxy_send("cut_through_world_explosion", inp) - else - local inp = math.floor(data[1]) .. " " .. math.floor(data[2]) - .. " " .. math.floor(data[3]) .. " " .. math.floor(data[4]) - net.proxy_send("cut_through_world_circle", inp) - end - alive[ent] = nil - else - local proj = EntityGetFirstComponentIncludingDisabled(ent, "ProjectileComponent") - if proj ~= nil and ComponentGetValue2(proj, "on_death_explode") then - local x, y = EntityGetTransform(ent) - local r = ComponentObjectGetValue2(proj, "config_explosion", "explosion_radius") - if r >= 16 then - alive[ent] = {x, y, r, - ComponentObjectGetValue2(proj, "config_explosion", "max_durability_to_destroy"), - ComponentObjectGetValue2(proj, "config_explosion", "ray_energy")} - end - else - local mat = EntityGetFirstComponent(ent, "MagicConvertMaterialComponent") - if mat ~= nil and ComponentGetValue2(mat, "from_material_tag") == "[solid]" then - local x, y = EntityGetTransform(ent) - alive[ent] = {x, y, ComponentGetValue2(mat, "radius"), ComponentGetValue2(mat, "to_material")} - end - end + local n = EntitiesGetMaxID() + for ent = last + 1, n do + if EntityGetIsAlive(ent) then + update(ent) end end + last = n end return mod \ No newline at end of file diff --git a/quant.ew/files/system/item_sync.lua b/quant.ew/files/system/item_sync.lua index d27ce0aa..938661b2 100644 --- a/quant.ew/files/system/item_sync.lua +++ b/quant.ew/files/system/item_sync.lua @@ -536,7 +536,7 @@ function item_sync.on_world_update() end end end - local rt = math.floor(ModSettingGet("quant.ew.item_sync")) + local rt = tonumber(ModSettingGet("quant.ew.item_sync")) local n = 0 if rt == 5 then n = 3 diff --git a/quant.ew/files/system/orb_sync/orb_sync.lua b/quant.ew/files/system/orb_sync/orb_sync.lua index bceb4695..17a3a96b 100644 --- a/quant.ew/files/system/orb_sync/orb_sync.lua +++ b/quant.ew/files/system/orb_sync/orb_sync.lua @@ -57,18 +57,24 @@ function rpc.update_orbs(found_orbs, to_host) end end +local last = 0 + function module.on_world_update() if GameGetFrameNum() % 15 == 0 then local found_local = orbs_found_this_run() - for _, orb_ent in ipairs(EntityGetWithTag("hittable") or {}) do - local comp = EntityGetFirstComponent(orb_ent, "OrbComponent") - if comp ~= nil then - local orb = ComponentGetValue2(comp, "orb_id") - if table.contains(found_local, orb) then - EntityKill(orb_ent) + local n = EntitiesGetMaxID() + for ent = last + 1, n do + if EntityGetIsAlive(ent) then + local comp = EntityGetFirstComponent(ent, "OrbComponent") + if comp ~= nil then + local orb = ComponentGetValue2(comp, "orb_id") + if table.contains(found_local, orb) then + EntityKill(ent) + end end end end + last = n end if wait_for_these ~= nil and not EntityHasTag(ctx.my_player.entity, "polymorphed") then actual_orbs_update(wait_for_these) diff --git a/quant.ew/settings.lua b/quant.ew/settings.lua index 39d2d418..254e741a 100755 --- a/quant.ew/settings.lua +++ b/quant.ew/settings.lua @@ -258,7 +258,7 @@ local function build_settings() { id = "enemy_sync", ui_name = "enemy sync interval", - ui_description = "every N frames enemys are synced, host only, try 3 if laggy", + ui_description = "host only, every N frames enemys are synced, try 3 if laggy", value_default = "2", scope = MOD_SETTING_SCOPE_RUNTIME, }, @@ -276,6 +276,13 @@ local function build_settings() value_default = "-1", scope = MOD_SETTING_SCOPE_RUNTIME, }, + { + id = "explosions", + ui_name = "amount of radii of explosions can be handled in 1 frame", + ui_description = "host only, decrease if weird network lag, increase if weird world sync, cpu bounded", + value_default = "128", + scope = MOD_SETTING_SCOPE_RUNTIME, + }, { id = "team", ui_name = "friendly fire team",