netplayjs icon indicating copy to clipboard operation
netplayjs copied to clipboard

Support >2 Players

Open rameshvarun opened this issue 5 years ago • 5 comments

rameshvarun avatar Mar 05 '19 18:03 rameshvarun

@rameshvarun I'm curious, any idea how this would work?

mmazzarolo avatar Apr 10 '21 12:04 mmazzarolo

The first step is to support games with a fixed player count, and where players can't join or leave after the game starts. For example, a game will have something like SimpleGame.playerCount = 3.

The required changes can be split into three areas:

  1. Netcode: The core synchronization algorithms should already support >2 players, but might need extra debugging.
  2. Transport: Right now, one player is the host and the other player is a client. In >2 players there will be one host with multiple clients. Each client connects to the host, and messages between clients are relayed through the host (this simplifies a lot of things).
  3. Lobby: Right now the game starts as soon as a client joins. This needs to be updated so that the game waits for the playerCount to be satisfied. Also needs UI to show people connecting / leaving.

The next step after this will be to allow games with a variable count, so a game will have something like SimpleGame.playerCount = { min: 2, max: 4}. We maintain the assumption that players don't join or leave. The only additional work required here is at the Lobby layer. Look to existing games like Halo to figure out UI.

The next step after this will be joinable / leavable games, but this is more complicated and requires additional changes, so I will leave that for another day.

rameshvarun avatar Apr 10 '21 14:04 rameshvarun

Understood, thanks for sharing. Mad props for this library, by the way. Still playing around with it, but both the code and the way it has been architected are clear and well written.

mmazzarolo avatar Apr 10 '21 15:04 mmazzarolo

Bump:

WebRTC One To Many Broadcast (SFU): https://www.youtube.com/watch?v=GMbdEnK8h3U 4 Player Webrtc tank game: https://github.com/maxscharwath/toonks-game

edge-rps avatar Jul 04 '23 02:07 edge-rps

@edge-rps I don't think your links are specifically related to rollback netcode, right? 👀

mmazzarolo avatar Jul 04 '23 06:07 mmazzarolo