"Chunk updates pollution" event

Things that we aren't going to implement
Post Reply
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

"Chunk updates pollution" event

Post by Reika »

As per viewtopic.php?f=28&t=50178&p=292472#p292472 , which was never responded to.
Image

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: "Chunk updates pollution" event

Post by Rseding91 »

This is another one of the events we never made because of how frequently it would be called (100-200 times/tick or more).
If you want to get ahold of me I'm almost always on Discord.

User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: "Chunk updates pollution" event

Post by Reika »

Rseding91 wrote:This is another one of the events we never made because of how frequently it would be called (100-200 times/tick or more).
200 times a tick!? I thought chunks only updated their pollution once a second.

EDIT:
By "Update" I mean the spread/absorption behavior, not any time the data is accessed (like pollution emission).
Image

BenSeidel
Filter Inserter
Filter Inserter
Posts: 584
Joined: Tue Jun 28, 2016 1:44 am
Contact:

Re: "Chunk updates pollution" event

Post by BenSeidel »

What does access to the event give you that iterating over the chunks once a second does not?

User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: "Chunk updates pollution" event

Post by Reika »

BenSeidel wrote:What does access to the event give you that iterating over the chunks once a second does not?
I want to do something similar to Minecraft's block ticks. Iterating over the entire world is far too expensive to ever do all at once, even once per second, resulting in a noticeable lag spike every time it happens. Much better would be to 'piggyback' on the pollution calls that are going to happen anyways, and can even save a call to surface.getPollution if the event provides it.
Image

Patashu
Fast Inserter
Fast Inserter
Posts: 130
Joined: Mon May 08, 2017 11:57 pm
Contact:

Re: "Chunk updates pollution" event

Post by Patashu »

If you don't have to do something to EVERY chunk EVERY tick, you can scan over all chunks, but stop after you've scanned X, and next tick pick up starting at the next chunk over. That way performance penalty is spread evenly over all ticks, and does not increase in proportion to number of chunks generated.

User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: "Chunk updates pollution" event

Post by Reika »

Patashu wrote:If you don't have to do something to EVERY chunk EVERY tick, you can scan over all chunks, but stop after you've scanned X, and next tick pick up starting at the next chunk over. That way performance penalty is spread evenly over all ticks, and does not increase in proportion to number of chunks generated.
No, the iterator is an "all in one" kind of thing; there was a past discussion about exactly that.
Image

BenSeidel
Filter Inserter
Filter Inserter
Posts: 584
Joined: Tue Jun 28, 2016 1:44 am
Contact:

Re: "Chunk updates pollution" event

Post by BenSeidel »

Yes, the chunk iterator sucks for this kind of thing, you're much better off rolling your own by hooking into the "on_chunk_generation" code and putting each chunk into a table in a set of "iterator tables". This gives you control about how you divide them up. For example you could have 60 tables, one for each tick. On each tick, pick the appropriate table and iterate.

you could also divide the chucks up into non-polluted and polluted. This could help with large train-based maps where the pollution does not cover a significant portion of the map.

User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: "Chunk updates pollution" event

Post by Reika »

BenSeidel wrote:Yes, the chunk iterator sucks for this kind of thing, you're much better off rolling your own by hooking into the "on_chunk_generation" code and putting each chunk into a table in a set of "iterator tables". This gives you control about how you divide them up. For example you could have 60 tables, one for each tick. On each tick, pick the appropriate table and iterate.

you could also divide the chucks up into non-polluted and polluted. This could help with large train-based maps where the pollution does not cover a significant portion of the map.
This is an interesting idea.
Image

User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: "Chunk updates pollution" event

Post by Reika »

I made a couple realizations that complicate the above:

Getting the pre-existing chunks into that cache would still require iteration, though, if only once.

And splitting based on pollution - while useful - needs some way of being kept up-to-date, whose only means is again chunk iteration.
Image

Post Reply

Return to “Won't implement”