by certeoun · 5y ago · 0 comments
Is it very well known in the game industry? I have trouble finding anything about it.
I wrote about it in a thread here called: "Why bugs might feel “impossible”" about two months ago and someone commented that the game TerraNova (from 1996) had a fully deterministic engine.
BTW TFA say StarCraft 2 (2007) used the technique but Warcraft 3 (2003) was already using a deterministic engine. Save files for Warcraft 3 games (including multiplayer ones over the Internet) consisted in only recording the player inputs and the "tick" at which they happened. This make for tiny savefiles, even for very long games.
So basically: several of us independently discovered that technique in the nineties. There may have been games in the eighties already using such a technique but I don't know any.
But in any case: the technique ain't new.
Fabien calls it "fixed timeslice". I find Fabien's solution much simpler. It is quite different to Fiedler's one.
while (running)
{
static std::uint32_t simulation_time{0U};
std::uint32_t const real_time = SDL_GetTicks();
process_input();
while (simulation_time < real_time)
{
simulation_time += 16U;
update(16U);
}
render();
}
As I understand it, the inner while loop's is essentially playing "catch up" with the outer while.
For simplicity's sake, let's assume that simulation_time is incremented to 1 in the inner while (simulation_time += 1U).
Further, let us assume that simulation_time is 42 in the first iteration. Now, the inner while needs to execute 42 times until it fails the loop condition (42 < 42).On the second iteration, simulation_time is equal to 58 (42 + 16). The inner while executes (42 < 58) 16 times now.
On the third iteration, simulation_time is equal to 59 (58 + 1). The inner while executes (58 < 59) 1 time.
The real_time cannot stay the same, as it polls the number of ticks since SDL was initialized. So apparently, simulation_time is always smaller than real_time.
(If for some reason, real_time isn't incremented in an iteration, then the inner loop will not get executed. However, I don't see a case where it can happen.)
Now, inside the update function there is a position update akin to current_position += speed * 16U. Now with the above iterations:
- The first iteration, causes 42 update calls (so current_position is updated 42 times as well).
- The second iteration, causes 16 update calls.
- The third, calls update 1 time.
So we are advancing the position of something variable times. (We are also executing the inner while in variable amounts.)
Maybe I am missing something here, but why doesn't the non-constant number of updates cause jitter? I really don't understand why it works at all to be honest. I am trying to understand it fully.