netplayjs
netplayjs copied to clipboard
Support >2 Players
@rameshvarun I'm curious, any idea how this would work?
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:
- Netcode: The core synchronization algorithms should already support >2 players, but might need extra debugging.
- 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).
- 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.
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.
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 I don't think your links are specifically related to rollback netcode, right? 👀