1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-25 15:37:42 +00:00

[MP] Avoid unnecessary internal ref/unrefs

Access the various internal components (cache/replicator) via pointer,
to avoid unnecessary overhead.
This commit is contained in:
Fabio Alessandrelli
2023-09-27 01:47:23 +02:00
parent 9ce423914e
commit 311a27281f
6 changed files with 32 additions and 20 deletions

View File

@@ -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();
}