scatter icon indicating copy to clipboard operation
scatter copied to clipboard

Add option for basic multiplayer sync

Open PieKing1215 opened this issue 1 year ago • 1 comments

(needed this for a project so figured I'd PR in case this is something you want :) )

Adds a new "Multiplayer Sync" option (false by default) on ProtonScatter node, which if enabled will sync the scatter output transforms from the multiplayer authority to clients

More specifically calls to these functions are synced via rpc:

  • _clear_collision_data
  • clear_output
  • _on_transforms_ready

Tested in Godot 4.1.1 (in an unreleased project) Might be worth making a dedicated test setup, idk how thorough you want to be

Demo (left is server with enabled field being toggled, right is client):

https://github.com/HungryProton/scatter/assets/13819558/b2b1e5af-ee76-4653-88f3-6f5c7cd5bc70

Some notes:

  • I'm not particularly familiar with this addon's code so not sure if there's other things that might cause issues with this
  • When using this you probably want to set enabled to false on clients, otherwise they will also try to scatter locally.
    • (it'd be possible to make it so clients ignore enabled/rebuild/etc if multiplayer sync is on, if that's desired)
  • The _multiplayer_call function looks kinda dumb, but I was trying to avoid using bind since iirc rpc only works with bind on 4.1.1+
  • Open to naming suggestions (ie. multiplayer_sync/"Multiplayer Sync", _multiplayer_call, _do_transforms_ready)

PieKing1215 avatar Oct 16 '23 06:10 PieKing1215

Hey, sorry for the delay. I don't know if scatter is really supposed to handle multiplayer at all. As long as you use the same seed on both sides, the results should be identical. (If they're not, that's an issue I need to fix)

I'm not familiar with multiplayer, but if you really need to drive it from the network, I would make it a separate node. (Added under a ScatterNode, like the ScatterItem nodes):

  • On the server side, the multiplayer node would listen to its parent build_complete signal, and send the transform list to the client
  • The client side receives the transforms from the server, and calls clear_output and _on_transform_ready on the scatter node. (similar to what ScatterCache does)

Basically, moving the multiplayer_call method to its own node, along with all the multiplayer features. Makes it easier to maintain (the scatter nodes don't know about multiplayer but still work as usual) and it doesn't cause conflicts with future updates.

HungryProton avatar Nov 24 '23 09:11 HungryProton