ShotgunNinja / Kerbalism

Hundreds of Kerbals were killed in the making of this mod.
The Unlicense
43 stars 19 forks source link

Impossible to guarantee coherency in resource simulation of loaded vessels #96

Closed ShotgunNinja closed 7 years ago

ShotgunNinja commented 7 years ago

The resource cache (RC) used in this mod make the consumption/production agnostic to simulation step duration. That is, the resource simulation is consistent irregardless of the timewarp speed (and, indirectly, of the containers capacity).

The RC is used by everything that consume/produce resources in this mod. This include:

So, stock and third-party modules on loaded vessels are not using the RC. This mean that anything produced/consumed from these elements will not be agnostic to simulation step duration.

This issue is particularly evident on vessels with solar panels, due to the EC requirement of ECLSSs, and the dire consequences of incoherent simulation on the crew. It isn't particularly evident for other resources because these are usually covered by our own modules and processes, both of which are using the RC at all times, or because incoherency on the simulation of these other resources don't lead to evident consequences.

The proper solution would be to somehow force all stock and third-party modules in loaded vessels to use the RC. However, that doesn't seem to be possible unless these are reimplemented from scratch. That's hugely impractical.

An half-solution could be to reimplement only the stock solar panel module (that would also fix #95). This will avoid the most noticeable consequences of the issue.

ShotgunNinja commented 7 years ago

This was partially fixed, without replacing the stock solar panel module. Instead, a new module WarpFixer was created. This module set stock module output to zero, and then calculate the correct output itself, considering analytical sunlight visibility. Then the EC is produced using the resource cache, so that warpspeed and EC capacity can't influence the amount actually produced.

A full fix would require to obtain complete control on resource production/consumption in loaded vessels. The partial fix implemented should be good enough for 99% of the cases.

ShotgunNinja commented 7 years ago

The issue has been further minimized by detecting when some external module is producing a resource in a loaded vessel, without using the resource cache. In that case, the user is warned and timewarp above a threshold forbidden.

Incoherent consumers are not detected, because the consequences in that case are most likely non-negative for the player (eg: something consume less than it should).

This can be disabled by the player in settings. So he can opt for one of these 3 mutually exclusive solutions:

ShotgunNinja commented 7 years ago

To summarize, this was 'fixed' by: