Commit graph

11 commits

Author SHA1 Message Date
Fabio Alessandrelli ca7d572908 [Net] Modularize multiplayer, expose MultiplayerAPI to extensions.
- RPC configurations are now dictionaries.
- Script.get_rpc_methods renamed to Script.get_rpc_config.
- Node.rpc[_id] and Callable.rpc now return an Error.
- Refactor MultiplayerAPI to allow extension.
- New MultiplayerAPI.rpc method with Array argument (for scripts).
- Move the default MultiplayerAPI implementation to a module.
2022-07-26 09:31:12 +02:00
Fabio Alessandrelli ddee5f6050 Add peer visibility to MultiplayerSynchronizer.
MultiplayerSynchronizers can now be configured to limit their visibility
to a subset of the connected peers, if the synchronized node was spawned
by a MultiplayerSpawner (either automatically or via custom spawn) the
given node will also be despawned remotely.

The replication system doesn't have the logic to handle subspawn
directly, but it is possible to handle them appropriately by manually
updating the visibility of the parent before changing the one of the
nested spawns via the "update_visibility" function.

The visibility of each MultiplayerSynchronizer can be controlled by
adding or remove filters via "[add|remove]_visibility_filter(callable)".

To further optimize the network code, visibility filters can be configured
to be automatically updated during idle or physics frame, or set to always
require manual update (via the "update_visibility" function).
2022-07-20 19:08:35 +02:00
reduz 12474fd87a Improve MultiplayerSynchronizer editor usability
* Add a button to add properties (which lets you select node and property)
* Add ability to drag properties and drop them to the editor.
* Made the editor transient (not always visible on the bottom) since its not needed most of the time.
* Added the ability to pin the editor, in case dragging properties from other nodes is desired.
2022-05-23 13:14:59 +02:00
reduz 45af29da80 Add a new HashSet template
* Intended to replace RBSet in most cases.
* Optimized for iteration speed
2022-05-20 22:40:38 +02:00
reduz 746dddc067 Replace most uses of Map by HashMap
* Map is unnecessary and inefficient in almost every case.
* Replaced by the new HashMap.
* Renamed Map to RBMap and Set to RBSet for cases that still make sense
  (order matters) but use is discouraged.

There were very few cases where replacing by HashMap was undesired because
keeping the key order was intended.
I tried to keep those (as RBMap) as much as possible, but might have missed
some. Review appreciated!
2022-05-16 10:37:48 +02:00
reduz 8b7c7f5a75 Add a new HashMap implementation
Adds a new, cleaned up, HashMap implementation.

* Uses Robin Hood Hashing (https://en.wikipedia.org/wiki/Hash_table#Robin_Hood_hashing).
* Keeps elements in a double linked list for simpler, ordered, iteration.
* Allows keeping iterators for later use in removal (Unlike Map<>, it does not do much
  for performance vs keeping the key, but helps replace old code).
* Uses a more modern C++ iterator API, deprecates the old one.
* Supports custom allocator (in case there is a wish to use a paged one).

This class aims to unify all the associative template usage and replace it by this one:
* Map<> (whereas key order does not matter, which is 99% of cases)
* HashMap<>
* OrderedHashMap<>
* OAHashMap<>
2022-05-12 11:21:29 +02:00
Nathan Franke 680a668e2f
remove child on despawn instead of just queue_delete 2022-05-05 08:50:21 -05:00
Fabio Alessandrelli 1e0d563467 [Net] Fix multi-peer path-only replication.
It used to check if a net_id was ever assigned to that node to detect
when to send the path confirm to the remote peer.
This is wrong, because the same net_id is shared for all the remote
peers, but sent one by one.
Instead we now check if it's either not assigned or if the assigned
net_id is a cache ID, and in that case ensure that the remote peer has
been notified.

This can be further improved by unifying the cache interface, but for
now it's a fast fix to get path-only sync to work.
2022-02-21 19:05:04 +01:00
Fabio Alessandrelli 87f4bbd668 [Debugger] Move most profilers to ServersDebugger.
Also splits bandwidth/rpc profiler (RPCProfiler is now in
SceneDebugger).
2022-02-06 17:36:48 +01:00
Fabio Alessandrelli 347d2dfc42 [Net] Move RPC, Node cache out of MultiplayerAPI.
Now uses two interfaces so it can be overridden in the future, and
core no longer depends on Node.

The interfaces are implements in scene/multiplayer.
Replaces root_node with root_path.
Remove all Node references from MultiplayerAPI.
2022-02-05 02:00:23 +01:00
Fabio Alessandrelli d219547c96 [Net] New replication interface, spawner and synchronizer nodes.
Initial implementation of the MultiplayerReplicationInterface and its
default implementation (SceneReplicationInterface).

New MultiplayerSpawner node helps dealing with instantiation of scenes
on remote peers (e.g. clients).
It supports both custom spawns via a `_spawn_custom` virtual function,
and optional auto-spawn of known scenes via a TypedArray<PackedScenes>
property.

New MultiplayerSynchornizer helps synchronizing states between the local
and remote peers, supports both sync and spawn properties and is
configured via a `SceneReplicationConfig` resource.
It can also sync via path (i.e. without being spawned by a
MultiplayerSpawner if both peers has it in tree, but will not send the
spawn state in that case, only the sync one.
2022-02-04 14:56:30 +01:00