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

Merge pull request #100602 from KoBeWi/over_100_changes_in_50_random_files_aka_the_best_kind_of_PR

Add templated version of `ObjectDB::get_instance()`
This commit is contained in:
Thaddeus Crews
2025-03-31 12:03:47 -05:00
49 changed files with 121 additions and 104 deletions

View File

@@ -195,7 +195,7 @@ void MultiplayerDebugger::RPCProfiler::init_node(const ObjectID p_node) {
}
rpc_node_data.insert(p_node, RPCNodeInfo());
rpc_node_data[p_node].node = p_node;
rpc_node_data[p_node].node_path = Object::cast_to<Node>(ObjectDB::get_instance(p_node))->get_path();
rpc_node_data[p_node].node_path = ObjectDB::get_instance<Node>(p_node)->get_path();
}
void MultiplayerDebugger::RPCProfiler::toggle(bool p_enable, const Array &p_opts) {
@@ -300,7 +300,7 @@ void MultiplayerDebugger::ReplicationProfiler::add(const Array &p_data) {
const String what = p_data[0];
const ObjectID id = p_data[1];
const uint64_t size = p_data[2];
MultiplayerSynchronizer *sync = Object::cast_to<MultiplayerSynchronizer>(ObjectDB::get_instance(id));
MultiplayerSynchronizer *sync = ObjectDB::get_instance<MultiplayerSynchronizer>(id);
ERR_FAIL_NULL(sync);
if (!sync_data.has(id)) {
sync_data[id] = SyncInfo(sync);

View File

@@ -185,7 +185,7 @@ void MultiplayerSpawner::_update_spawn_node() {
}
#endif
if (spawn_node.is_valid()) {
Node *node = Object::cast_to<Node>(ObjectDB::get_instance(spawn_node));
Node *node = ObjectDB::get_instance<Node>(spawn_node);
if (node && node->is_connected("child_entered_tree", callable_mp(this, &MultiplayerSpawner::_node_added))) {
node->disconnect("child_entered_tree", callable_mp(this, &MultiplayerSpawner::_node_added));
}
@@ -211,7 +211,7 @@ void MultiplayerSpawner::_notification(int p_what) {
_update_spawn_node();
for (const KeyValue<ObjectID, SpawnInfo> &E : tracked_nodes) {
Node *node = Object::cast_to<Node>(ObjectDB::get_instance(E.key));
Node *node = ObjectDB::get_instance<Node>(E.key);
ERR_CONTINUE(!node);
node->disconnect(SceneStringName(tree_exiting), callable_mp(this, &MultiplayerSpawner::_node_exit));
get_multiplayer()->object_configuration_remove(node, this);
@@ -265,7 +265,7 @@ void MultiplayerSpawner::_spawn_notify(ObjectID p_id) {
}
void MultiplayerSpawner::_node_exit(ObjectID p_id) {
Node *node = Object::cast_to<Node>(ObjectDB::get_instance(p_id));
Node *node = ObjectDB::get_instance<Node>(p_id);
ERR_FAIL_NULL(node);
if (tracked_nodes.has(p_id)) {
tracked_nodes.erase(p_id);

View File

@@ -90,7 +90,7 @@ public:
PackedStringArray get_configuration_warnings() const override;
Node *get_spawn_node() const {
return spawn_node.is_valid() ? Object::cast_to<Node>(ObjectDB::get_instance(spawn_node)) : nullptr;
return spawn_node.is_valid() ? ObjectDB::get_instance<Node>(spawn_node) : nullptr;
}
void add_spawnable_scene(const String &p_path);

View File

@@ -100,7 +100,7 @@ void MultiplayerSynchronizer::_update_process() {
}
Node *MultiplayerSynchronizer::get_root_node() {
return root_node_cache.is_valid() ? Object::cast_to<Node>(ObjectDB::get_instance(root_node_cache)) : nullptr;
return root_node_cache.is_valid() ? ObjectDB::get_instance<Node>(root_node_cache) : nullptr;
}
void MultiplayerSynchronizer::reset() {

View File

@@ -152,7 +152,7 @@ void SceneCacheInterface::process_confirm_path(int p_from, const uint8_t *p_pack
}
if (valid_rpc_checksum == false) {
const Node *node = Object::cast_to<Node>(ObjectDB::get_instance(*oid));
const Node *node = ObjectDB::get_instance<Node>(*oid);
ERR_FAIL_NULL(node); // Bug.
ERR_PRINT("The rpc node checksum failed. Make sure to have the same methods on both nodes. Node path: " + node->get_path());
}
@@ -278,7 +278,7 @@ Object *SceneCacheInterface::get_cached_object(int p_from, uint32_t p_cache_id)
RecvNode *recv_node = pinfo->recv_nodes.getptr(p_cache_id);
ERR_FAIL_NULL_V_MSG(recv_node, nullptr, vformat("ID %d not found in cache of peer %d.", p_cache_id, p_from));
Node *node = Object::cast_to<Node>(ObjectDB::get_instance(recv_node->oid));
Node *node = ObjectDB::get_instance<Node>(recv_node->oid);
if (!node) {
// Fallback to path lookup.
Node *root_node = SceneTree::get_singleton()->get_root()->get_node(multiplayer->get_root_path());

View File

@@ -113,7 +113,7 @@ private:
template <typename T>
static T *get_id_as(const ObjectID &p_id) {
return p_id.is_valid() ? Object::cast_to<T>(ObjectDB::get_instance(p_id)) : nullptr;
return p_id.is_valid() ? ObjectDB::get_instance<T>(p_id) : nullptr;
}
#ifdef DEBUG_ENABLED