Item Network

by y_e_a_r

This mod adds a new logistics mechanic: The Item Network. It replaces trains and logistics bots by teleporting items and fluids directly between Network Chests and Tanks.

Tweaks
1 year, 1 month ago
1.1
2.19K
Logistics Fluids Logistic network Storage Cheats

i Automizing chest updating rate

1 year, 2 months ago

Hey you two, thx for the cool mod :)

I have a suggestion. If you want the item network to always take the same amount of time updating chests per tick, i made a formula for you so you could automatically set the chest updating rate using these steps:

  1. Write some code which averages the amount of time per tick over an entire session (I can do that for you)
  2. Choose any megabase you have. It should be one with a large enough amount of workload.
  3. You'll need two versions of the same megabase: One with 0 Network Chests and one with n network chests where n is a huge number like 1000 or so. But it really needs to be the same megabase, just the amount of network chests should change. And you should make sure that the network chests actually have something to do and not just be there.
  4. Measure the average time per tick for both bases over a large amount of time.
  5. Let's call the avereage amount of time per tick for the base without network chests t_0 and the one with network chests t_n
  6. Integrate some code into the Item Network mod which measures the amount of time per tick for each tick individually, not averaging it anymore.
  7. Let t be the measured time for this tick. Let k be the amount of network chests present during this tick. Let t_des be the fixed amount of time you want the mod to take per tick. Let r be the amount of chests being updated in the next tick. Then the formula goes as following:

r = t_des * ((((t_0 / t_n) * n) + k) / t)

  1. Round r to the nearest integer.
  2. Of course you can repeat the same process for Network Tanks.

I'm thinking about a pull request, but honestly you two seem like more than capable and i have gotten somewhat tired of modding and rather want to enjoy playing the game again :) But maybe in the future, what would you say? :)

1 year, 2 months ago
(updated 1 year, 2 months ago)

Actually i think if we
1. would let n be the amount of updated chests per tick in the megabase and
2. would let k be the amount of chests updated in the last tick
instead, it would yield better results.

Also if r is larger than the amounts of chests present, it needs to be made smaller, like r = math.min(r, present_chests).

1 year, 2 months ago

And if you want to minimize the work done by calculating the updating rate, it would probably be enough to recalculate it every n_th tick, like every 10th tick or so

1 year, 2 months ago

Actually there's a way to do it without requiring you to take any pre-measurements in a megabase.

Let r_i be the amount of chests updated at tick n and
Let t_i be the total duration of tick n
Let t_des be the amount of time you want the mod to take for just updating the chests each tick.

Let i, j, k be ticks.
then

r_i = t_des * ((r_j - r_k) / (t_j - t_k))

By choosing appropriate ticks j and k, you could pre-calculate the amounts of chests you can update at tick i.

You would just need to make sure that r_j ~= r_k and t_j ~= t_k. Just choose the last two ticks which satisfy this. The further the distance between i, j and k, the more inaccurate it gets.

Keep in mind that:
1. You can at minimum start to calculate it with tick 3 and not earlier
2. Tick 1 and tick 2 need to have different amounts of chests updated in order for this to work. This is impossible if there aren't any chests present.
3. 0 is an absolutely valid updating rate for this formula. So as soon as the player puts down the first chest, you can start calculating.

1 year, 1 month ago

This looks interesting, but before diving I just want to confirm:

Factorio mods (afaik) have a hard restriction that they can't make time measurements. This was done to ensure that mods are entirely deterministic to help fix multiplayer sync issues.

Is this dynamic updating approach still possible given we can't measure time durations?

1 year, 1 month ago

I didn't know that. If we really can't take any time measurements at all, then no. It is definitely required to get the ingame ups at the runtime stage for this to be dynamic.

But i think it's possible to do with the LuaProfiler class:
https://lua-api.factorio.com/latest/classes/LuaProfiler.html

Another idea would be to use console commands. In debug mode e.g. there are the 'show-fps' and 'show-clock' commands. If it was possible to execute console commands in a 'io.popen'-kinda way, then it would be possible. I don't know wether the LuaRemote or anything else in the API provides that kind of power.

Would be kinda sad if the idea of a dynamic mod which automatically fits to the needs of the users was ultimately blocked forever.

1 year, 1 month ago

From the LuaProfiler docs:

Since performance is non-deterministic, these [LuaProfiler] objects don't allow reading the raw time values from Lua.

So unfortunately I think we are blocked from doing any kind of time measurement.

While it's not possible for now, it's good to have these equations laying around in case they are needed in the future. Thanks for the suggestion!

1 year, 1 month ago

Np. You are awesome!

New response