Chunk deletion FPS lag? [ Solved ]

Place to get help with not working mods / modding interface.
Post Reply
Oarc
Fast Inserter
Fast Inserter
Posts: 101
Joined: Sun Sep 18, 2016 2:04 pm
Contact:

Chunk deletion FPS lag? [ Solved ]

Post 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
Last edited by Oarc on Sat Aug 05, 2017 4:02 pm, edited 1 time in total.

Bilka
Factorio Staff
Factorio Staff
Posts: 3156
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Chunk deletion FPS lag?

Post by Bilka »

Removing all chunks at once will produce less lag than removing one every (few) ticks. Image
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Oarc
Fast Inserter
Fast Inserter
Posts: 101
Joined: Sun Sep 18, 2016 2:04 pm
Contact:

Re: Chunk deletion FPS lag?

Post by Oarc »

Damn it why is that conversation familiar lol...

Well crap. There goes my idea!

Thanks I guess :)

Post Reply

Return to “Modding help”