Skip to content

Commit a6a6528

Browse files
committed
fix some explosion logic, add an option for amount of explosion radii per frame
1 parent a370913 commit a6a6528

File tree

6 files changed

+70
-70
lines changed

6 files changed

+70
-70
lines changed

noita-proxy/src/net/world.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,12 +1264,12 @@ impl WorldManager {
12641264
Some((x, y))
12651265
}
12661266
pub(crate) fn cut_through_world_explosion(&mut self, x: i32, y: i32, r: i32, d: u8, ray: u32) {
1267-
let rays = (r * 2).clamp(16, 1024);
1267+
let rays = (r * 2).clamp(4, 1024);
1268+
let t = TAU / rays as f32;
12681269
let results: Vec<i32> = (0..rays)
12691270
.into_par_iter()
12701271
.map(|n| {
1271-
let t = TAU / rays as f32;
1272-
let theta = t * n as f32;
1272+
let theta = t * (n as f32 + 0.5);
12731273
let end_x = x + (r as f32 * theta.cos()) as i32;
12741274
let end_y = y + (r as f32 * theta.sin()) as i32;
12751275
if let Some((ex, ey)) = self.do_ray(x, y, end_x, end_y, ray, d) {
@@ -1294,16 +1294,10 @@ impl WorldManager {
12941294
rays: i32,
12951295
list: Vec<i32>,
12961296
) {
1297-
let mut r = 0;
1298-
for n in &list {
1299-
if *n > r {
1300-
r = *n
1301-
}
1302-
}
1297+
let r = (*list.iter().max().unwrap_or(&0) as f64).sqrt().ceil() as i32;
13031298
if r == 0 {
13041299
return;
13051300
}
1306-
let r = (r as f64).sqrt().ceil() as i32;
13071301
let (min_cx, max_cx) = (
13081302
(x - r).div_euclid(CHUNK_SIZE as i32),
13091303
(x + r).div_euclid(CHUNK_SIZE as i32),
@@ -1335,8 +1329,11 @@ impl WorldManager {
13351329
for icy in 0..CHUNK_SIZE as i32 {
13361330
let cy = chunk_start_y + icy;
13371331
let dy = cy - y;
1338-
let r = list[(rays as f32 * (dy as f32).atan2(dx as f32) / TAU) as usize];
1339-
if dd + dy * dy <= r {
1332+
let mut i = rays as f32 * (dy as f32).atan2(dx as f32) / TAU;
1333+
if i.is_sign_negative() {
1334+
i += rays as f32
1335+
}
1336+
if dd + dy * dy <= list[i as usize] {
13401337
let px = icy as usize * CHUNK_SIZE + icx as usize;
13411338
chunk.set_pixel(px, air_pixel);
13421339
}

quant.ew/files/system/enemy_sync.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ function enemy_sync.client_cleanup()
374374
end
375375

376376
function enemy_sync.on_world_update_host()
377-
local rt = math.floor(ModSettingGet("quant.ew.enemy_sync"))
377+
local rt = tonumber(ModSettingGet("quant.ew.enemy_sync"))
378378
local n = 0
379379
if rt == 3 then
380380
n = 2

quant.ew/files/system/explosion_cuts/explosion_cuts.lua

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -46,66 +46,56 @@ end
4646

4747
local first = true
4848

49+
local function update(ent)
50+
local proj = EntityGetFirstComponentIncludingDisabled(ent, "ProjectileComponent")
51+
if proj ~= nil and ComponentGetValue2(proj, "on_death_explode") then
52+
local x, y = EntityGetTransform(ent)
53+
local r = ComponentObjectGetValue2(proj, "config_explosion", "explosion_radius")
54+
alive[ent] = {x, y, r,
55+
ComponentObjectGetValue2(proj, "config_explosion", "max_durability_to_destroy"),
56+
ComponentObjectGetValue2(proj, "config_explosion", "ray_energy")}
57+
else
58+
local mat = EntityGetFirstComponent(ent, "MagicConvertMaterialComponent")
59+
if mat ~= nil and ComponentGetValue2(mat, "from_material_tag") == "[solid]" then
60+
local x, y = EntityGetTransform(ent)
61+
alive[ent] = {x, y, ComponentGetValue2(mat, "radius"), ComponentGetValue2(mat, "to_material")}
62+
end
63+
end
64+
end
65+
4966
function mod.on_world_update_host()
5067
if first then
5168
send_mats()
5269
first = false
5370
end
54-
local n = EntitiesGetMaxID()
55-
for ent = last + 1, n do
56-
if EntityGetIsAlive(ent) then
57-
local proj = EntityGetFirstComponentIncludingDisabled(ent, "ProjectileComponent")
58-
if proj ~= nil and ComponentGetValue2(proj, "on_death_explode") then
59-
local x, y = EntityGetTransform(ent)
60-
local r = ComponentObjectGetValue2(proj, "config_explosion", "explosion_radius")
61-
if r >= 16 then
62-
alive[ent] = {x, y, r,
63-
ComponentObjectGetValue2(proj, "config_explosion", "max_durability_to_destroy"),
64-
ComponentObjectGetValue2(proj, "config_explosion", "ray_energy")}
65-
end
66-
else
67-
local mat = EntityGetFirstComponent(ent, "MagicConvertMaterialComponent")
68-
if mat ~= nil and ComponentGetValue2(mat, "from_material_tag") == "[solid]" then
69-
local x, y = EntityGetTransform(ent)
70-
alive[ent] = {x, y, ComponentGetValue2(mat, "radius"), ComponentGetValue2(mat, "to_material")}
71+
local count = tonumber(ModSettingGet("quant.ew.explosions"))
72+
for ent, data in pairs(alive) do
73+
if not EntityGetIsAlive(ent) then
74+
if count > 0 then
75+
if #alive[ent] == 5 then
76+
count = count - data[3]
77+
local inp = math.floor(data[1]) .. " " .. math.floor(data[2])
78+
.. " " .. math.floor(data[3]) .. " " .. math.floor(data[4]) .. " " .. math.floor(data[5])
79+
net.proxy_send("cut_through_world_explosion", inp)
80+
else
81+
count = count - data[3]
82+
local inp = math.floor(data[1]) .. " " .. math.floor(data[2])
83+
.. " " .. math.floor(data[3]) .. " " .. math.floor(data[4])
84+
net.proxy_send("cut_through_world_circle", inp)
7185
end
86+
alive[ent] = nil
7287
end
88+
else
89+
update(ent)
7390
end
7491
end
75-
last = n
76-
local count = 128
77-
for ent, data in pairs(alive) do
78-
if not EntityGetIsAlive(ent) and count > 0 then
79-
if #alive[ent] == 5 then
80-
count = count - data[3]
81-
local inp = math.floor(data[1]) .. " " .. math.floor(data[2])
82-
.. " " .. math.floor(data[3]) .. " " .. math.floor(data[4]) .. " " .. math.floor(data[5])
83-
net.proxy_send("cut_through_world_explosion", inp)
84-
else
85-
local inp = math.floor(data[1]) .. " " .. math.floor(data[2])
86-
.. " " .. math.floor(data[3]) .. " " .. math.floor(data[4])
87-
net.proxy_send("cut_through_world_circle", inp)
88-
end
89-
alive[ent] = nil
90-
else
91-
local proj = EntityGetFirstComponentIncludingDisabled(ent, "ProjectileComponent")
92-
if proj ~= nil and ComponentGetValue2(proj, "on_death_explode") then
93-
local x, y = EntityGetTransform(ent)
94-
local r = ComponentObjectGetValue2(proj, "config_explosion", "explosion_radius")
95-
if r >= 16 then
96-
alive[ent] = {x, y, r,
97-
ComponentObjectGetValue2(proj, "config_explosion", "max_durability_to_destroy"),
98-
ComponentObjectGetValue2(proj, "config_explosion", "ray_energy")}
99-
end
100-
else
101-
local mat = EntityGetFirstComponent(ent, "MagicConvertMaterialComponent")
102-
if mat ~= nil and ComponentGetValue2(mat, "from_material_tag") == "[solid]" then
103-
local x, y = EntityGetTransform(ent)
104-
alive[ent] = {x, y, ComponentGetValue2(mat, "radius"), ComponentGetValue2(mat, "to_material")}
105-
end
106-
end
92+
local n = EntitiesGetMaxID()
93+
for ent = last + 1, n do
94+
if EntityGetIsAlive(ent) then
95+
update(ent)
10796
end
10897
end
98+
last = n
10999
end
110100

111101
return mod

quant.ew/files/system/item_sync.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ function item_sync.on_world_update()
536536
end
537537
end
538538
end
539-
local rt = math.floor(ModSettingGet("quant.ew.item_sync"))
539+
local rt = tonumber(ModSettingGet("quant.ew.item_sync"))
540540
local n = 0
541541
if rt == 5 then
542542
n = 3

quant.ew/files/system/orb_sync/orb_sync.lua

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,24 @@ function rpc.update_orbs(found_orbs, to_host)
5757
end
5858
end
5959

60+
local last = 0
61+
6062
function module.on_world_update()
6163
if GameGetFrameNum() % 15 == 0 then
6264
local found_local = orbs_found_this_run()
63-
for _, orb_ent in ipairs(EntityGetWithTag("hittable") or {}) do
64-
local comp = EntityGetFirstComponent(orb_ent, "OrbComponent")
65-
if comp ~= nil then
66-
local orb = ComponentGetValue2(comp, "orb_id")
67-
if table.contains(found_local, orb) then
68-
EntityKill(orb_ent)
65+
local n = EntitiesGetMaxID()
66+
for ent = last + 1, n do
67+
if EntityGetIsAlive(ent) then
68+
local comp = EntityGetFirstComponent(ent, "OrbComponent")
69+
if comp ~= nil then
70+
local orb = ComponentGetValue2(comp, "orb_id")
71+
if table.contains(found_local, orb) then
72+
EntityKill(ent)
73+
end
6974
end
7075
end
7176
end
77+
last = n
7278
end
7379
if wait_for_these ~= nil and not EntityHasTag(ctx.my_player.entity, "polymorphed") then
7480
actual_orbs_update(wait_for_these)

quant.ew/settings.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ local function build_settings()
258258
{
259259
id = "enemy_sync",
260260
ui_name = "enemy sync interval",
261-
ui_description = "every N frames enemys are synced, host only, try 3 if laggy",
261+
ui_description = "host only, every N frames enemys are synced, try 3 if laggy",
262262
value_default = "2",
263263
scope = MOD_SETTING_SCOPE_RUNTIME,
264264
},
@@ -276,6 +276,13 @@ local function build_settings()
276276
value_default = "-1",
277277
scope = MOD_SETTING_SCOPE_RUNTIME,
278278
},
279+
{
280+
id = "explosions",
281+
ui_name = "amount of radii of explosions can be handled in 1 frame",
282+
ui_description = "host only, decrease if weird network lag, increase if weird world sync, cpu bounded",
283+
value_default = "128",
284+
scope = MOD_SETTING_SCOPE_RUNTIME,
285+
},
279286
{
280287
id = "team",
281288
ui_name = "friendly fire team",

0 commit comments

Comments
 (0)