Page 1 of 1
surface.total_pollution read
Posted: Wed Jan 02, 2019 8:59 pm
by Boodals
Currently, to get the total amount of pollution on a surface, you have to iterate over every chunk, and call get_pollution on them all. As surfaces can easily have hundreds if not thousands of chunks, it quickly gets slow.
Bilka said on discord that the game tracks polluted chunks, and thus will be able to do it more efficiently. Also less API calls is always better.
Re: surface.total_pollution read
Posted: Thu Jan 03, 2019 8:48 am
by Rseding91
What's the use-case? I could add it, but it's still an O(N) cost where N is all of the polluted chunks.
Re: surface.total_pollution read
Posted: Fri Jan 04, 2019 8:08 am
by darkfrei
Rseding91 wrote: Thu Jan 03, 2019 8:48 am
What's the use-case? I could add it, but it's still an O(N) cost where N is all of the polluted chunks.
How it was checked in evolution calculation?
Re: surface.total_pollution read
Posted: Fri Jan 04, 2019 8:19 am
by Godmave
How it was checked in evolution calculation?
I would guess that that one only sums up the pollution absorbed by the spawners
Re: surface.total_pollution read
Posted: Fri Jan 04, 2019 8:56 am
by DaveMcW
Evolution only adds up pollution, it doesn't subtract when it is absorbed by tiles.
Re: surface.total_pollution read
Posted: Fri Jan 04, 2019 2:43 pm
by Rseding91
darkfrei wrote: Fri Jan 04, 2019 8:08 am
Rseding91 wrote: Thu Jan 03, 2019 8:48 am
What's the use-case? I could add it, but it's still an O(N) cost where N is all of the polluted chunks.
How it was checked in evolution calculation?
Evolution is modified as pollution is created.
Re: surface.total_pollution read
Posted: Fri Jan 04, 2019 3:12 pm
by Mylon
It's pretty simple to do in lua:
Code: Select all
function getPollution()
-- Iterate over all chunks and sum pollution.
local pollution = 0
-- local surface = game.surfaces[1]
for chunk in game.surfaces[1].get_chunks() do
pollution = pollution + game.surfaces[1].get_pollution({chunk.x*32, chunk.y*32})
end
return pollution
end
Re: surface.total_pollution read
Posted: Fri Jan 04, 2019 4:49 pm
by Boodals
Rseding91 wrote: Thu Jan 03, 2019 8:48 am
What's the use-case? I could add it, but it's still an O(N) cost where N is all of the polluted chunks.
A simple use case would be just a GUI that monitors the total amount of pollution your factory is producing.
My use case is: a mod which makes pollution affect whether the surface is habitable, or if you need a special suit to breathe, and also causes global warming which can melt ice (alien biomes), and start forest fires.
As an alternative to the O(N), you could keep a running total for each surface that updates when pollution is created/absorbed. It would affect performance of the base game, but perhaps it could be used in a graph. It would be nice to be able to see how much less pollution you're producing by installing efficiency modules, for example.
Mylon wrote: Fri Jan 04, 2019 3:12 pm
It's pretty simple to do in lua:
Read the OP
Re: surface.total_pollution read
Posted: Mon Feb 04, 2019 9:37 pm
by Boodals
Ayy I implemented this myself for 0.17 (I got access to the game's source code).
LuaSurface.get_total_pollution()