Page 1 of 1

Chunk deletion FPS lag? [ Solved ]

Posted: Sat Aug 05, 2017 3:45 pm
by Oarc
I'm trying to write a scenario that slowly deletes unused map chunks but I'm running into weird FPS lag.

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

Re: Chunk deletion FPS lag?

Posted: Sat Aug 05, 2017 3:57 pm
by Bilka
Removing all chunks at once will produce less lag than removing one every (few) ticks. Image

Re: Chunk deletion FPS lag?

Posted: Sat Aug 05, 2017 4:02 pm
by Oarc
Damn it why is that conversation familiar lol...

Well crap. There goes my idea!

Thanks I guess :)