Devlog #5: Syncing the world state


Finally, players can build together. In this update, I implemented player building and destruction into the game, all of course synced across the network. Lovely.

How does it work?

The system is built off of the deterministic nature of the world generation system: from the same starting conditions, any number of clients will always generate the same world. The beauty of this is that I don't actually need to have the server/host generate all the chunks, then send the data to all the clients, as is the case in a certain other block game. Instead, I just need to store the individual modifications made and send those instead.

As an example, when a player breaks a block, in the Bad System it goes like this:

  • Player breaks a block
  • Server fetches the entire chunk data (32768 blocks)
  • Server sends the entire chunk across the network.
  • Client decodes the entire chunk (again, 32768 blocks.)

However, in my system it goes like this:

  • All clients generate a chunk. Given the same seed, this will be the same chunk. During generation, if any previous block modifications are found these will be applied.
  • The player breaks a block.
  • The server tells everyone this one block has been modified.
  • Clients generate the chunk.

Like all things, this is a trade-off. As you might be able to tell, the second system uses less bandwidth however at the expense of CPU usage. It's more intensive on the processor to have to re-generate the chunk every-time - though to a modern CPU, it's still child's play. However, to me this system is worth it due to the huge amounts of data being saved. This makes it much better suited to the player-hosted architecture used in Build Fight, as I have no guarantee or realistic expectation that the host will be running anything other than a below-average spec PC on below-average WiFi. I think I've managed to strike the right balance here between system and network performance.

Play it now! Build dicks! Etc!

Up next: storing block data, with the primary purpose of being able to destroy blocks gradually rather than instantly.

Files

Build Fight: Windows 31 MB
Version 8 Oct 06, 2023

Get Build Fight Game

Leave a comment

Log in with itch.io to leave a comment.