redux-swarmlog
redux-swarmlog copied to clipboard
Suitable For Multiplayer Game State Sync?
Title says it :) Sorry if it is a stupid question.
Very Interesting Project!
What kind of game? WebRTC has a bit of latency but probably not enough to cause any issues with what you're doing.
I am more concerned about hyperlog + redux - I guess the server would send updates every 100ms or so. Mostly Entity Velocities and so on. In my tests mith webrtc-swarm I had latencies around 150ms so thats ok I guess.
I just will have to try I guess :>
I have not profiled the latency. It is certainly low enough to work for some games. I am really loving generals.io and it would work well for that kind of game. Please let me know if you profile the round trip time.
I have written another reducer called-back-to-the-present
it is based on requestAnimationFrame
it creates a log of keys pressed by players on each frame. It optimistically generates an immutable copy of the state for each frame on each client. This is regenerated if new info about a previous frame comes in. But when there is consensus i.e. all clients have sent a keystroke or keepalive past a given frame the state for old frames can be garbaged.
So there are two logs one for key presses that does not get garbaged and can be used for replays and one for game state positions, velocities etc we keep this as short as possible.
When new clients connect they receive a copy of the consensus state from a peer i.e. the latest frame that we know will never change. All other peers are informed of the new comer and send any actions after the consensus. Then the newcomer becomes a normal peer.
This should work for up to about 10 peer there is no swarm so traffic grows factorially with number of players. But the engine should be general purpose enough for any arcade game.
I will see if I can dig it out. I have not tested it properly but think I got it working.
I found it and pushed it here:
https://github.com/philholden/back-to-the-present
You are totally awesome man! I will look into it, Thanks!