avaraline / Avara

Port of the original 1996 game from Ambrosia Software.
MIT License
122 stars 19 forks source link

Allow users on a server to spectate games already in progress #196

Open assertivist opened 3 years ago

assertivist commented 3 years ago

If a user connects to a server with a game is still active, we should allow for "Start Game" to bring the new user into the game as a spectator.

This feature is deceptively difficult, as Avara depends on the deterministic local state of each user's game. In order to pull this off, the game clients would need a way to sync not only the level and the active players, but also the inputs for every player for each frame that has been played until that point.

jmunkki commented 2 years ago

What you could do is keep a record of all the player actions and allow the player who joined to spectate to obtain a copy. Load the level and then replay those actions without rendering any graphics (just the game engine). This should bring you up to real time and then you can start replaying the game with graphics. Depending on how slow/fast this turns out to be, you might want to render the graphics here and there (the GPU is going to do the heavy lifting anyway).

You could also expand this by recording games this way and then allow replaying saved games (player POV or free flight camera).

Also, if you send the saved game to a (web) server and allow people to stream data to their client, they could spectate games live even when they are not connected to the game server.

assertivist commented 2 years ago

keep a record of all the player actions and allow the player who joined to spectate to obtain a copy

This is outlined in #43, and with a serialization format this should be trivial, even P2P

(player POV or free flight camera)

It actually has live POV spectator mode already, it will be simple to adapt this for use during film playback. Camera flight controls would be awesome too, also useful for BSPViewer. I'll open a separate issue for that I think.

send the saved game to a (web) server

This idea has been in gestation for a long time, the most recent sketch of such a thing is here: https://github.com/avaraline/depot but that's more specific to tracking and distributing level sets.

It would be awfully neat to also store game statistics and player data, which requires some kind of link between a player in the game and a user on a website. It would probably be good to enumerate a user story for such an ID/verification process that isn't too invasive.