Getting list of all generated chunks
-
- Smart Inserter
- Posts: 2767
- Joined: Tue Apr 25, 2017 2:01 pm
- Contact:
Getting list of all generated chunks
To help make some operations of a mod I'm working on more performant, I'm wanting to switch from surface.find_entities_filtered of the entire surface to checking a few chunks at a time. I'm looking for a way to get a list of all currently generated chunks, store them away in global, then parse through them a few at a time each tick. Would the LuaSurface::get_chunks do this for me? It's not clear from the description if it's all possible, generated, or charted chunks, though my assumption is generated. Also being an iterator, I'm unsure if I can actually just store its results somewhere and do them a few at a time vs needing to loop through them all in one shot (even if that loop is going through to store them away one by one).
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
Re: Getting list of all generated chunks
Yes, the iterator can be stored.
The stored iterator contains the current chunks, even if they were generated after it was created. It might not catch some newly created chunks, if they are inserted before the current position.
When the iterator reaches the end of the list it stops iterating, even if new chunks are generated later.
Example, run it on a new map for best effect:
The stored iterator contains the current chunks, even if they were generated after it was created. It might not catch some newly created chunks, if they are inserted before the current position.
When the iterator reaches the end of the list it stops iterating, even if new chunks are generated later.
Example, run it on a new map for best effect:
Code: Select all
/c
global.count = 0
script.on_nth_tick(1, function()
chunk = global.iterator and global.iterator()
if chunk then
global.count = global.count + 1
else
game.print("end at " .. global.count .. " chunks")
global.count = 0
local n = 0
for chunk in game.surfaces[1].get_chunks() do n = n + 1 end
game.print("start at " .. n .. " chunks")
global.iterator = game.surfaces[1].get_chunks()
end
end)
-
- Smart Inserter
- Posts: 2767
- Joined: Tue Apr 25, 2017 2:01 pm
- Contact:
Re: Getting list of all generated chunks
Ok, great, thank you. That's fine if it doesn't catch newly generated chunks after its creation. I'm already listening to on_chunk_generated. I just need this iterator for already existing maps that this mod is added to, or if one of its startup settings are changed.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics