The function below is called every 30 ticks, and looks for chunks in the "removal_list".
Everything works fine normally, but once this function starts to get called, FPS lag starts to happen for ALL connected players.
Also, it doesn't seem to happen while running in single-player mode, or at least it's much less noticeable. I'm having a hard time pinning down the reason for this FPS lag though, so maybe I'm wrong.
I did several things to optimize the rest of the code, and there is no FPS lag up until the point chunks start to get deleted.
I'm pretty confident the lag is related to this portion of the code, but all my code is up here: https://github.com/Oarcinae/FactorioSce ... growth_dev
(regrowth_map.lua contains this code)
What I normally would expect is UPS lag if I was running stupid code....
But something about chunk deletion seems to cause FPS lag... I don't understand why. Please help?
Code: Select all
-- Remove entries from the removal list
function OarcRegrowthRemoveChunk()
-- Next chunk to remove
if (#global.chunk_regrow.removal_list > 0) then
local c_pos = table.remove(global.chunk_regrow.removal_list)
local c_timer = global.chunk_regrow.map[c_pos.x][c_pos.y]
-- Confirm chunk is still expired
if (c_timer == nil) then
-- Check for pollution
if (game.surfaces[GAME_SURFACE_NAME].get_pollution(c_pos) > 0) then
global.chunk_regrow.map[c_pos.x][c_pos.y] = game.tick
-- Else delete the chunk
else
game.surfaces[GAME_SURFACE_NAME].delete_chunk({c_pos.x/32,c_pos.y/32})
global.chunk_regrow.map[c_pos.x][c_pos.y] = nil
-- DebugPrint("Deleting Chunk: X="..c_pos.x..",Y="..c_pos.y)
end
else
-- DebugPrint("Chunk no longer expired: X="..c_pos.x..",Y="..c_pos.y)
end
end
end