0
\$\begingroup\$

I'm developing an multiplayer game "from scratch" (not using a big Engine-Suite like Unity but the lower-level libgdx).

Currently I've got a NetworkManager which handles the sending of messages on server side and receiving those with subsequently calling methods on client site.

At the moment the sync between figures works already once they are correct configured and spawned on both ends. Now I'm currently think about the spawning of those objects.


Approach No.1: My first approach was that every time the Server spawned a new (e.g.) player, it will subsequently send a "SpawnObjectMessage"-Object (holding all necessary type and configuration values) to all clients. Clients will than spawn a new player-figure. Now the synchronization works.

Concerns:

  • I have concerns with this solution that individual messages could be lost (due to network problems, for example),
  • or what happens if a client closes the program in the middle of the game and then starts again and all figures have to be reloaded (as already said : The server only sends the message once as soon as it spawns a player itself).

Approach No.2: The server hold a "model" of all figures (he does this anyway due to some other functionality) and sync this with all clients. The "model" here is a list of objects each one describing values of a figure: The

  • prefab/class/type the object is
  • if it is spawned of or just created on server side
  • is it controlled by a player and possibly the PlayerID
  • ... The server will send the complete List (or only the changed entries) to all clients every time some changes occur. The clients will override their local list and subsequently iterate over it and spawn objects if they could not find a corresponding counterpart. If a new Player enters the game or a client restarts the game, the server will resend the complete list to the new client.

Concerns:

  • This solution seems a little bit "reactive"
  • It maybe not very intuitive
  • Maybe I'm overseeing something what will bring problems

Which approach is more common or what concerns are you aware of in such projects?


edit/additional informations:

Since @milk asked how Updates works here is an additional explanation how this will work: The server will send continously update messages (e.g. "UpdatePositionMessage") for every Player-Objects exiting/spawned on server side. Server will keep doing so no matter if clients has successfully spawnend the corresponding counterpart object or not. Clients will simply ignore updating objects which can't be found. This update-mechanism is used in both approaches described above.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ For approach 1, how do you plan to do updates? Do you have a separate UpdateObjectMessage that clients would simply ignore if they missed the corresponding SpawnObjectMessage? \$\endgroup\$
    – milk
    Commented Feb 27, 2020 at 21:48
  • \$\begingroup\$ Yes it's exactly like this but this is not only for approach 1 since the update-strategy is working always the same after players are spawned on both ends no matter how the spawning was realized. Even approach 2 is just for SPAWNING and maybe for REMOVING objects - not for updating. I've edited the question with additional informations. \$\endgroup\$ Commented Feb 27, 2020 at 23:52
  • 1
    \$\begingroup\$ Are you using TCP? Messages can't be lost by TCP, only delayed (in the same order). Which is convenient, if your game is slow-paced (e.g. used by Minecraft, noting that when it was designed, nobody thought there would be much fast PVP) \$\endgroup\$
    – user20574
    Commented Feb 28, 2020 at 17:58
  • 1
    \$\begingroup\$ @user253751 Note that TCP won't handle disconnects longer than a certain timeout, so it's not a magic bullet. If a player's PC crashes, you'll need a way to get missed messages \$\endgroup\$
    – Mars
    Commented Mar 2, 2020 at 7:02

1 Answer 1

1
\$\begingroup\$

You can do something in-between.

For example, players request the full state when they reconnect, or if it's determined that something is wrong. During normal gameplay, you just send the relevant data. Of course, this requires that you also make sure that everyone has received the messages properly as well. Message Acknowledgement is one way to do this.

In Unity Photon for example, every networked object had it's own ID. As such, if the server sends a message and the client doesn't have an object with that ID, you know something is wrong. At that point, the client can request the full model from the master or owner.

Photon has a lot more options--I'd suggest playing around with it a little bit and implementing the functionality you feel you need.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .