summaryrefslogtreecommitdiffstats
path: root/modules/multiplayer/scene_multiplayer.cpp
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2023-09-27 01:47:23 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2023-10-10 14:42:54 +0200
commit311a27281f8f04335f079eef506798903296192f (patch)
tree4a9b1aaa3bb369f1f6e2b1dc8806e2ea1267986b /modules/multiplayer/scene_multiplayer.cpp
parent9ce423914ec4a392e42dbf894dc7929befcc7e1d (diff)
downloadredot-engine-311a27281f8f04335f079eef506798903296192f.tar.gz
[MP] Avoid unnecessary internal ref/unrefs
Access the various internal components (cache/replicator) via pointer, to avoid unnecessary overhead.
Diffstat (limited to 'modules/multiplayer/scene_multiplayer.cpp')
-rw-r--r--modules/multiplayer/scene_multiplayer.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/modules/multiplayer/scene_multiplayer.cpp b/modules/multiplayer/scene_multiplayer.cpp
index 3e3118b1cd..04de3dfb7f 100644
--- a/modules/multiplayer/scene_multiplayer.cpp
+++ b/modules/multiplayer/scene_multiplayer.cpp
@@ -680,12 +680,16 @@ void SceneMultiplayer::_bind_methods() {
SceneMultiplayer::SceneMultiplayer() {
relay_buffer.instantiate();
- replicator = Ref<SceneReplicationInterface>(memnew(SceneReplicationInterface(this)));
- rpc = Ref<SceneRPCInterface>(memnew(SceneRPCInterface(this)));
cache = Ref<SceneCacheInterface>(memnew(SceneCacheInterface(this)));
+ replicator = Ref<SceneReplicationInterface>(memnew(SceneReplicationInterface(this, cache.ptr())));
+ rpc = Ref<SceneRPCInterface>(memnew(SceneRPCInterface(this, cache.ptr(), replicator.ptr())));
set_multiplayer_peer(Ref<OfflineMultiplayerPeer>(memnew(OfflineMultiplayerPeer)));
}
SceneMultiplayer::~SceneMultiplayer() {
clear();
+ // Ensure unref in reverse order for safety (we shouldn't use those pointers in the deconstructors anyway).
+ rpc.unref();
+ replicator.unref();
+ cache.unref();
}