A mod does heavy calculations. It just doesn't need to do them every tick. Every minute would suffice entirely. Putting a modulo test at the beginning of the mod function as requirement for the calculations in the mod function to be done, would be the way to go then, to relief the game engine, right?
Like so:
Pseudocode A
I would like to hear your feedback, if this is THE efficient way to do it.Distributing Workload of Mod to Multiple Ticks
For the following I assume, the above solution is the way to go.But it is ugly, if the mod leaves the game to run smooth for the most time, and lags it for 5 seconds every full minute. So the mod has to distribute the work to every tick within a ... calculation cycle (CC) (lets call it that instead of a minute) evenly.
How would i approach this challenge, knowing, that the mod has to iterate through a long list of data, and do the same, short calculation for every item in the list. In other words, knowing, that the weight of the calculations stems from the amount of data to be processed, not from the complexity of the calculations.
Would I just divide the data into (ticks/CC) split parts and process one every tick? I guess, yes. But as I see it, there would be some problems.
Problem 1: Data can increase or decrease during the Calculation Cycle
Every tick the game engine itself can alter the data to be processed by the mod. Not only the values within the data items, but also add or remove items to or from the list.
Luckily, to process every item in the list precisely one time during one CC is not a strict necessity for the mod. If an item is not processed because it was added after a new CC begun or removed before the current CC ended, it is no deal. Is this called fuzzyness? The algorithm of the mod being somewhat fuzzy suffices entirely.
Problem 2: Knowing the Amount of Data and splitting it.
I understood, a lot of data in factorio is managed via linked lists because all of the data has to be processed every tick anyways. Is my understanding correct?
Then, for the list of all the entities on the map and/or for the list of all the entities on the map placed by the players:
1. what is a way for the mod to find out how many there are and
2. how could the mod split the list into more or less even parts?
The linked lists in factorio do not have an index, correct? No linked list has, correct?
Thanks for your feedback and your ideas.