I need to split up a table
Posted: Fri May 14, 2021 12:36 am
I have UDP sockets enabling co-op on my dungeon crawler and when a client connects to the host the first thing the host does is send the game world to the client. The host sends a range of layers that describe the game world:
- tile information (the maps)
- obstacle information (rocks, trees, etc that sit ON TOP of the tiles)
- tile weight information for each tile (for path-finding)
- object information (things on the tiles)
and I expect even more layers in the future like weather and environment effects. The UDP transfer is a simple bitser serialisation into a single string (datagram) for transmission to the client. Unfortunately, sending even one layer on a modest 100 x 100 map makes UDP go "MESSAGE TOO LARGE" (or something). My serialised string for one layer is about 11,000 characters and I'm guess that is exceeding the UDP limit for a single datagram (I assume to be just under 64k bytes).
So - what to do?
Most obvious thing is to send the world information in smaller chunks. I can send say, 20 rows at a time and do this 5 times to get the whole 100 rows to the client. I was hoping to have a much larger world or even an indefinite world so not sure this is a good idea.
I'm now leaning towards the client requesting just the 'chunk' that is visible on the screen (+ some reasonable margin). That would also be about 30 rows/columns of viewable tiles but it would need to be requested and sent repeatedly on demand as the players move around the world. Some of that can be cached but not much. Of all the layers I described above, nearly all of them can change or be impacted by player actions.
As a proof of concept, for demo purposes and to test the UDP/sockets, what is the correct way to break up a 100 x 100 table into 5 smaller tables? UDP can't send tables so each of those 5 messages MUST be serialised or textified in some way. I'm not too worried about unpacking and stitching the table back together. I assume that will be a simple thing.
And THEN - when I've sent those five messages for that ONE layer - I need to do the same for the other layers.
I guess I'm on a learning curve and I'll take good, bad and ugly suggestions. I'm an iterative guy (aren't most of us) where I'll take anything that works and then refactor it later.
I'm guessing my problem is not unique so thought I'd learn from past failures and successes.
- tile information (the maps)
- obstacle information (rocks, trees, etc that sit ON TOP of the tiles)
- tile weight information for each tile (for path-finding)
- object information (things on the tiles)
and I expect even more layers in the future like weather and environment effects. The UDP transfer is a simple bitser serialisation into a single string (datagram) for transmission to the client. Unfortunately, sending even one layer on a modest 100 x 100 map makes UDP go "MESSAGE TOO LARGE" (or something). My serialised string for one layer is about 11,000 characters and I'm guess that is exceeding the UDP limit for a single datagram (I assume to be just under 64k bytes).
So - what to do?
Most obvious thing is to send the world information in smaller chunks. I can send say, 20 rows at a time and do this 5 times to get the whole 100 rows to the client. I was hoping to have a much larger world or even an indefinite world so not sure this is a good idea.
I'm now leaning towards the client requesting just the 'chunk' that is visible on the screen (+ some reasonable margin). That would also be about 30 rows/columns of viewable tiles but it would need to be requested and sent repeatedly on demand as the players move around the world. Some of that can be cached but not much. Of all the layers I described above, nearly all of them can change or be impacted by player actions.
As a proof of concept, for demo purposes and to test the UDP/sockets, what is the correct way to break up a 100 x 100 table into 5 smaller tables? UDP can't send tables so each of those 5 messages MUST be serialised or textified in some way. I'm not too worried about unpacking and stitching the table back together. I assume that will be a simple thing.
And THEN - when I've sent those five messages for that ONE layer - I need to do the same for the other layers.
I guess I'm on a learning curve and I'll take good, bad and ugly suggestions. I'm an iterative guy (aren't most of us) where I'll take anything that works and then refactor it later.
I'm guessing my problem is not unique so thought I'd learn from past failures and successes.