diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-02-15 18:06:48 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-02-15 18:44:55 +0100 |
commit | 0f5455230c8955be0c6533574bd3d5b6f50792b6 (patch) | |
tree | 2167f70782174feda2541c163d264c62402b50be /scene/multiplayer | |
parent | 171021145d49ffdda9110869d35ee63a946af9f8 (diff) |
Use `switch` consistently in `_notification` (`scene` folder)
Diffstat (limited to 'scene/multiplayer')
-rw-r--r-- | scene/multiplayer/multiplayer_spawner.cpp | 34 | ||||
-rw-r--r-- | scene/multiplayer/multiplayer_synchronizer.cpp | 13 |
2 files changed, 28 insertions, 19 deletions
diff --git a/scene/multiplayer/multiplayer_spawner.cpp b/scene/multiplayer/multiplayer_spawner.cpp index 4f2a9d9e83..25ab27f3e7 100644 --- a/scene/multiplayer/multiplayer_spawner.cpp +++ b/scene/multiplayer/multiplayer_spawner.cpp @@ -84,22 +84,26 @@ void MultiplayerSpawner::_update_spawn_node() { } void MultiplayerSpawner::_notification(int p_what) { - if (p_what == NOTIFICATION_POST_ENTER_TREE) { - _update_spawn_node(); - } else if (p_what == NOTIFICATION_EXIT_TREE) { - _update_spawn_node(); - const ObjectID *oid = nullptr; - while ((oid = tracked_nodes.next(oid))) { - Node *node = Object::cast_to<Node>(ObjectDB::get_instance(*oid)); - ERR_CONTINUE(!node); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &MultiplayerSpawner::_node_exit)); - // This is unlikely, but might still crash the engine. - if (node->is_connected(SceneStringNames::get_singleton()->ready, callable_mp(this, &MultiplayerSpawner::_node_ready))) { - node->disconnect(SceneStringNames::get_singleton()->ready, callable_mp(this, &MultiplayerSpawner::_node_ready)); + switch (p_what) { + case NOTIFICATION_POST_ENTER_TREE: { + _update_spawn_node(); + } break; + + case NOTIFICATION_EXIT_TREE: { + _update_spawn_node(); + const ObjectID *oid = nullptr; + while ((oid = tracked_nodes.next(oid))) { + Node *node = Object::cast_to<Node>(ObjectDB::get_instance(*oid)); + ERR_CONTINUE(!node); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &MultiplayerSpawner::_node_exit)); + // This is unlikely, but might still crash the engine. + if (node->is_connected(SceneStringNames::get_singleton()->ready, callable_mp(this, &MultiplayerSpawner::_node_ready))) { + node->disconnect(SceneStringNames::get_singleton()->ready, callable_mp(this, &MultiplayerSpawner::_node_ready)); + } + get_multiplayer()->despawn(node, this); } - get_multiplayer()->despawn(node, this); - } - tracked_nodes.clear(); + tracked_nodes.clear(); + } break; } } diff --git a/scene/multiplayer/multiplayer_synchronizer.cpp b/scene/multiplayer/multiplayer_synchronizer.cpp index fbe1b99cc9..33e845a7a3 100644 --- a/scene/multiplayer/multiplayer_synchronizer.cpp +++ b/scene/multiplayer/multiplayer_synchronizer.cpp @@ -108,10 +108,15 @@ void MultiplayerSynchronizer::_notification(int p_what) { if (root_path.is_empty()) { return; } - if (p_what == NOTIFICATION_ENTER_TREE) { - _start(); - } else if (p_what == NOTIFICATION_EXIT_TREE) { - _stop(); + + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + _start(); + } break; + + case NOTIFICATION_EXIT_TREE: { + _stop(); + } break; } } |