I have a game like minecraft, I can run, set and delete blocks. The world consists of a limited set of chunks. I want to write a server for it with the help of a library called boost asio. I need help with the following: how to properly transfer customers data chunks along with data from other characters. Example of a situation: a player enters a server, on which we assume there are already a couple of players. It needs to transfer information about chunks (just a three-dimensional array containing the type of the block) because he came in and did not know anything about the server world and of course the data of other players (their nickname, position, gaze direction). Do I need to integrate it all into one structure? Like this:

struct Data {
 std::string name;
 glm::vec3 position;
 glm::vec2 eye_dir;
 bool updateChunk;
 glm::vec3 chunkNumber;
 uint chunk[16*16*16];

That is, the client sends the numbers of the chunks that it needs to update and when the server sends it a packet, then it looks: if you send chunkUpdate = true, then it takes an array and puts the data into the client. Is this approach correct at all? And another question: communication between such packages between the client and the server is strictly a game of “throw the ball to each other in turn”?

P.S. I apologize in advance if there is not enough information or I have explained the essence incomprehensibly, I will be glad if you ask a clarifying question in this case.

  • \$\begingroup\$ Why does a chunk have a name and a eye direction? And whats the updateChunk for? Seems like you're mixing different parts of data in a single packet, don't do that. \$\endgroup\$ – tkausl Jan 22 '19 at 8:45
  • \$\begingroup\$ @tkausl, I apologize, probably made a stupid example. The server should send to the player continuously the data of other players (their position and sight for the minimum), but the problem is that I still need to somehow transfer the data of the chunk. If I can organize a continuous stream of data transfer to the player, how can I transfer the information of the chunks when it is necessary for some player? \$\endgroup\$ – De74ttempt Jan 22 '19 at 13:43
  • \$\begingroup\$ You should have different types of packages/data you send. One for chunk-data, one for player movements, one for block changes, and so on. \$\endgroup\$ – tkausl Jan 22 '19 at 13:52
  • \$\begingroup\$ @tkausl, thanks for the answer and apologize for the trivial question \$\endgroup\$ – De74ttempt Jan 22 '19 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.