Re:Preparing your game for deterministic netcode
by jayd16 on Sunday May 23, 2021 @12:01PM
(#27255990)
Depending on the game the error is often much larger. Especially when you have things like free player movement and obstructions. A little error can become a big error if one client sees a player move around a wall and the other see's them hit the wall and stop.
Re:Preparing your game for deterministic netcode
by YellowAfterlife on Monday May 24, 2021 @07:54AM
(#27263297)
I mention this briefly, but with re-syncing it is possible to end up in a situation where you end up re-sending the game state on each check interval - more so with a full-state CRC since floating-point errors can make values binary different long before the difference would result in a visible desync. Floating point issues are thus generally approached by using fixed-point math instead.
Doing a CRC of full game state also poses some additional requirements - e.g. any pointers must be relative offsets and any dynamic allocation should be deterministic and within the same block. It does, however, also make it easier to implement serialization/deserialization, as mentioned by Jyaif in another comment here.
Re:Preparing your game for deterministic netcode
by nightpool on Sunday May 23, 2021 @12:21PM
(#27256201)
Wait, so you're saying that a majority of players can override any other player's entire RAM? That sounds like an amazing paradise for hackers and griefers :D
Re:Preparing your game for deterministic netcode
by londons_explore on Sunday May 23, 2021 @02:06PM
(#27257125)
Well in the case of my game engine, all the game logic was untrusted anyway - in fact, in some games the actual game mechanic involved live-editing the code of the running game to try and give yourself an advantage - without ever causing a syntax error and while others are also live-editing the same code. Any keystroke causing a syntax error or infinite loop would be an insta-kick for the player who made that keystroke.
Re:Preparing your game for deterministic netcode
by vlovich123 on Sunday May 23, 2021 @01:25PM
(#27256767)
If you’re frightened by that, you may be shocked to realize your browser is running unprotected code from random people.
Re:Preparing your game for deterministic netcode
by jayd16 on Sunday May 23, 2021 @03:55PM
(#27258000)
It's actually very protected, no?
Re:Preparing your game for deterministic netcode
by vlovich123 on Sunday May 23, 2021 @04:32PM
(#27258336)
Still basically an infinitely larger attack surface than what OP describes which was fancy wording for some basic IPC primitives to synchronize some game state.
The 'desync' stuff was surprisingly easy to resolve. Instead of trying to make all game state deterministic (a near impossible task in some languages, where for example even basic math functions don't have fully defined rounding charactistics), I went for another approach...
Detect desyncs by periodically taking a ram snapshot of the whole game and calculating a CRC over it. It means your game state needs to be serializable, but you probably need that anyway so a new player can join the game mid game.
If the CRC doesn't match, do a majority vote to find out which player is wrong, then do the rsync algorithm to sync differences between the players. In nearly all cases there will only be a few bytes of differences.
There is no need for the game to halt or lag during any of this - the game can continue as normal. Players are likely seeing the exact same thing on the screen, because the differences between game states are probably an error of 0.00001 in some player position.
When the corrected state has arrived, replay frames to bring it up to the current timestamp and switch out states. Job done. User sees no glitchyness. Developers don't have to worry about tiny bits of nondeterministic behaviour in libraries out of their control. Everyone's happy.
Make sure it doesn't happen every frame though, or you'll waste a lot of CPU.