Skip to content

Commit

Permalink
fix some explosion logic, add an option for amount of explosion radii…
Browse files Browse the repository at this point in the history
… per frame
  • Loading branch information
bgkillas committed Dec 14, 2024
1 parent a370913 commit a6a6528
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 70 deletions.
21 changes: 9 additions & 12 deletions noita-proxy/src/net/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32> = (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) {
Expand All @@ -1294,16 +1294,10 @@ impl WorldManager {
rays: i32,
list: Vec<i32>,
) {
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),
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion quant.ew/files/system/enemy_sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
88 changes: 39 additions & 49 deletions quant.ew/files/system/explosion_cuts/explosion_cuts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion quant.ew/files/system/item_sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions quant.ew/files/system/orb_sync/orb_sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion quant.ew/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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",
Expand Down

0 comments on commit a6a6528

Please sign in to comment.