Revolutionary-Games / Thrive

The main repository for the development of the evolution game Thrive.
https://revolutionarygamesstudio.com/
Other
2.84k stars 503 forks source link

ATP production and consumption get out of sync when the game lags #2276

Open 84634E1A607A opened 3 years ago

84634E1A607A commented 3 years ago

ATP falls sharply when I maximize the Thrive window. This problem can be reproduced in earlier releases as well. Also when I experience a game lag the ATP will suddenly fall lower than it should be.

hhyyrylainen commented 3 years ago

I was sure that there was already an issue for this, but I couldn't find this. I've known about this for a while.

If the game experiences a lag spike (or the framerate is too low): the ATP production slows down because the compound storage is not increased, meaning that when more ATP is produced during a longer frame simulation ATP can't be produced at the rate it should be. And then on top of that the ATP usage is correctly computed for a longer frame, so unless you have really large storage capacity you'll run out of ATP on that frame because ATP could not be produced the right amount.

I think maybe this will explain things better:

84634E1A607A commented 3 years ago

What if we handle the usage first? Then we will have more space to fit in.

hhyyrylainen commented 3 years ago

The effect would be the same: you take damage and / or can't move at normal speed as you don't have ATP to power movement.

A slightly better way would be to have the consumption be computed first, processes were ran then, and finally ATP damage would be given (if cell doesn't have any ATP), though this is hard to fit in the current design because the process system is ran on background threads (in order to speed up processing many cells on multicore CPUs). So it's not possible to fit the Microbe class doing some stuff, then processes run, and then doing stuff again.

hhyyrylainen commented 3 years ago

One way to limit the consumption per frame, would be to assume that the game runs at least at 15 FPS or so, and cap the maximum elapsed time for the process system and Microbe computations.

hhyyrylainen commented 5 months ago

With the ECS change I've now limited the game delta to 0.1 I think to make sure there cannot be massive update timesteps. So this may be fixed.