Page 1 of 1

Inexact simulation outside view

Posted: Tue Oct 24, 2017 10:45 am
by ymte
TL;DR To replace parts of the factory simulation outside the players' view with approximate, percentage-based simulation.

Static parts of the factory that are outside the players' view do not have to be exactly simulated but can be approximated.
For parts of the factory that are isolated (only few input/output belts/trains/logistic chests with few item types), simulation could be reduced to keeping only track of percentages of units that need very little updating:
  • - Continuous parts of belts keep track of how full they are
    - Splitters divide the available capacity evenly between outputs
    - Chests keep track of how full they are
    - Assembly machines calculate output percentage based on input percentages
For example, a simple system such as

Image

could be represented as

Image

When the chest is empty, the percentages have to be updated to look something like this:

Image

Once a player walks towards such system, the simulation has to know how much time passed since the last percentage update, then recalculate all percentages and convert it to real-world items with discrete positions.

This way of simulating is very CPU-friendly since each of these systems only need to be updated once something significant happens: train arriving, player walking close, chests empty, enemy attack. Many items can be simulated this way.
However this technique is not applicable for the entire factory, as circuit components or techniques relying on individual items cannot be abstracted into the percentage system. Belts containing many types of products also do not work well.

PS. Anyone experienced with the modding API: is it possible to skip over or replace parts of the factory simulation?

Re: Inexact simulation outside view

Posted: Tue Oct 24, 2017 1:50 pm
by sillyfly
AFAIK, this is pretty similar to what the UPS-Up mod does: https://mods.factorio.com/mods/AntiElite/UPS-up

It causes most entities to update less frequently, but each update does the equivalent of multiple ticks.


I'm pretty sure making the whole game work like that would be very complicated, and would eventually be more trouble than it's worth. One of the strengths of Factorio is that the simulation is deterministic and complete (in the scope it defines).

Re: Inexact simulation outside view

Posted: Tue Oct 24, 2017 2:32 pm
by JohnyDL
you add bug potential and you delete multiplayer compatibility and managing what does what when and how big those updates need to be can be complicated say your system fills a train so it's 'isolated' in terms of nothing directly connects to the user but you walk over there and because the update hasn't happened a train that would have been full hasn't moved, that'd be irritating.

Re: Inexact simulation outside view

Posted: Tue Oct 24, 2017 4:28 pm
by Jap2.0
Okay, now program something that can do that for something that isn't the least complex possible setup. Use logistics bots, trains, fluids, and mods. Also implement this into a complex, completely determenistic game while making significant preformance increases.

The point is, it's a lot harder than you make it sound for a lot less benefit than you think it would be.

Re: Inexact simulation outside view

Posted: Tue Oct 24, 2017 6:02 pm
by Rseding91
ymte wrote:Static parts of the factory that are outside the players' view do not have to be exactly simulated but can be approximated.
Yes they do have to be exactly simulated and no they can't be approximated. If things weren't exactly simulated it would break the circuit network, logistic network, and pretty much all game logic as you move around. It would also essentially double + the amount of code that would have to be written to make the game work with the end result it probably wouldn't be any faster but it would make the game so much worse.

Re: Inexact simulation outside view

Posted: Tue Oct 24, 2017 6:59 pm
by Koub
In that case ...
[Koub] Moved to "won't implement"