I thought this would only apply to rendering graphics, but after reading the "When To Use It" section, I realized I've done double buffering on entire game states before (~2 years ago project). At the beginning of my update loop, I'd (deep) copy the current game state into a new object and begin incrementally updating the copy. Then I'd reassign right before Thread.sleeping (or whatever language idiom) until the next game loop "tick".Wasn't too fond of my C# deep copy solution:
var serialized = JsonSerializer.Serialize(this);
return JsonSerializer.Deserialize<GameState>(serialized);
I took an interested in functional programming, pure functions, immutability, etc. soon after.
Sharlin|7 years ago
Jare|7 years ago
If execution of logic is always performed in the same order, then the partially updated world state is not a problem for determinism (though it may be for correctness). Double buffering may let you reorder the execution of logic in different ways and still keep it deterministic. This would likely be needed for logic that executes in parallel threads, which is increasingly important for high-performance game engines.
a1369209993|7 years ago