Skip to content

Commit

Permalink
Add helper method to get Object from ObjectID
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Dec 19, 2024
1 parent fafc073 commit 712540b
Show file tree
Hide file tree
Showing 50 changed files with 110 additions and 93 deletions.
2 changes: 1 addition & 1 deletion core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ void Thread::_start_func(void *ud) {
target_callable.callp(nullptr, 0, ret, ce);
// If script properly kept a reference to the thread, we should be able to re-reference it now
// (well, or if the call failed, since we had to break chains anyway because the outcome isn't known upfront).
t = Ref<Thread>(ObjectDB::get_instance(th_instance_id));
t = th_instance_id.get_ref<Thread>();
if (t.is_valid()) {
t->ret = ret;
t->running.clear();
Expand Down
2 changes: 1 addition & 1 deletion core/error/error_macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
} else {
String node_name;
if (p_id.is_valid()) {
Node *node = Object::cast_to<Node>(ObjectDB::get_instance(p_id));
Node *node = p_id.get_object<Node>();
if (node && node->is_inside_tree()) {
node_name = "\"" + String(node->get_path()) + "\"";
} else {
Expand Down
5 changes: 5 additions & 0 deletions core/object/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -1055,4 +1055,9 @@ class ObjectDB {
static int get_object_count();
};

template <typename T>
T *ObjectID::get_object() const {
return Object::cast_to<T>(ObjectDB::get_instance(*this));
}

#endif // OBJECT_H
7 changes: 7 additions & 0 deletions core/object/object_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

#include "core/typedefs.h"

template <typename T>
class Ref;

// Class to store an object ID (int64)
// needs to be compatile with int64 because this is what Variant uses
// Also, need to be explicitly only castable to 64 bits integer types
Expand All @@ -47,6 +50,10 @@ class ObjectID {
_ALWAYS_INLINE_ bool is_null() const { return id == 0; }
_ALWAYS_INLINE_ operator uint64_t() const { return id; }
_ALWAYS_INLINE_ operator int64_t() const { return (int64_t)id; }
template <typename T>
T *get_object() const;
template <typename T>
Ref<T> get_ref() const;

_ALWAYS_INLINE_ bool operator==(const ObjectID &p_id) const { return id == p_id.id; }
_ALWAYS_INLINE_ bool operator!=(const ObjectID &p_id) const { return id != p_id.id; }
Expand Down
5 changes: 5 additions & 0 deletions core/object/ref_counted.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,9 @@ struct VariantInternalAccessor<const Ref<T> &> {
static _FORCE_INLINE_ void set(Variant *v, const Ref<T> &p_ref) { VariantInternal::object_assign(v, p_ref); }
};

template <typename T>
Ref<T> ObjectID::get_ref() const {
return Ref<T>(ObjectDB::get_instance(*this));
}

#endif // REF_COUNTED_H
2 changes: 1 addition & 1 deletion editor/debugger/editor_debugger_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void EditorDebuggerNode::register_undo_redo(UndoRedo *p_undo_redo) {
}

EditorDebuggerRemoteObject *EditorDebuggerNode::get_inspected_remote_object() {
return Object::cast_to<EditorDebuggerRemoteObject>(ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_selection_history()->get_current()));
return EditorNode::get_singleton()->get_editor_selection_history()->get_current().get_object<EditorDebuggerRemoteObject>();
}

ScriptEditorDebugger *EditorDebuggerNode::get_debugger(int p_id) const {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3013,7 +3013,7 @@ void EditorFileSystem::_queue_refresh_filesystem() {

void EditorFileSystem::_refresh_filesystem() {
for (const ObjectID &id : folders_to_sort) {
EditorFileSystemDirectory *dir = Object::cast_to<EditorFileSystemDirectory>(ObjectDB::get_instance(id));
EditorFileSystemDirectory *dir = id.get_object<EditorFileSystemDirectory>();
if (dir) {
dir->subdirs.sort_custom<DirectoryComparator>();
}
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2339,7 +2339,7 @@ void EditorNode::edit_item(Object *p_object, Object *p_editing_owner) {
// If plugin is already associated with another owner, remove it from there first.
for (KeyValue<ObjectID, HashSet<EditorPlugin *>> &kv : active_plugins) {
if (kv.key != owner_id) {
EditorPropertyResource *epres = Object::cast_to<EditorPropertyResource>(ObjectDB::get_instance(kv.key));
EditorPropertyResource *epres = kv.key.get_object<EditorPropertyResource>();
if (epres && kv.value.has(plugin)) {
// If it's resource property editing the same resource type, fold it.
epres->fold_resource();
Expand Down Expand Up @@ -2458,7 +2458,7 @@ void EditorNode::_add_to_history(const Object *p_object, const String &p_propert
ObjectID history_id = editor_history.get_current();
if (id != history_id) {
const MultiNodeEdit *multi_node_edit = Object::cast_to<const MultiNodeEdit>(p_object);
const MultiNodeEdit *history_multi_node_edit = Object::cast_to<const MultiNodeEdit>(ObjectDB::get_instance(history_id));
const MultiNodeEdit *history_multi_node_edit = history_id.get_object<const MultiNodeEdit>();
if (multi_node_edit && history_multi_node_edit && multi_node_edit->is_same_selection(history_multi_node_edit)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion editor/gui/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_

void SceneTreeEditor::_tree_scroll_to_item(ObjectID p_item_id) {
ERR_FAIL_NULL(tree);
TreeItem *item = Object::cast_to<TreeItem>(ObjectDB::get_instance(p_item_id));
TreeItem *item = p_item_id.get_object<TreeItem>();
if (item) {
tree->scroll_to_item(item, true);
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/animation_player_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ AnimationMixer *AnimationPlayerEditor::fetch_mixer_for_library() const {
}

Node *AnimationPlayerEditor::get_cached_root_node() const {
return Object::cast_to<Node>(ObjectDB::get_instance(cached_root_node_id));
return cached_root_node_id.get_object<Node>();
}

bool AnimationPlayerEditor::_validate_tracks(const Ref<Animation> p_anim) {
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4729,7 +4729,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {

undo_redo->create_action(TTR("Paste Pose"));
for (const PoseClipboard &E : pose_clipboard) {
Node2D *n2d = Object::cast_to<Node2D>(ObjectDB::get_instance(E.id));
Node2D *n2d = E.id.get_object<Node2D>();
if (!n2d) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/editor_resource_tooltip_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

void EditorResourceTooltipPlugin::_thumbnail_ready(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata) {
ObjectID trid = p_udata;
TextureRect *tr = Object::cast_to<TextureRect>(ObjectDB::get_instance(trid));
TextureRect *tr = trid.get_object<TextureRect>();

if (!tr) {
return;
Expand Down
10 changes: 5 additions & 5 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ void Node3DEditorViewport::_clear_selected() {
}

void Node3DEditorViewport::_select_clicked(bool p_allow_locked) {
Node *node = Object::cast_to<Node3D>(ObjectDB::get_instance(clicked));
Node *node = clicked.get_object<Node>();
Node3D *selected = Object::cast_to<Node3D>(node);
clicked = ObjectID();

Expand Down Expand Up @@ -2099,7 +2099,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
const bool movement_threshold_passed = _edit.original_mouse_pos.distance_to(_edit.mouse_pos) > 8 * EDSCALE;

if (selection_in_progress && movement_threshold_passed && clicked.is_valid()) {
if (clicked_wants_append || !editor_selection->is_selected(Object::cast_to<Node>(ObjectDB::get_instance(clicked)))) {
if (clicked_wants_append || !editor_selection->is_selected(clicked.get_object<Node>)) {

Check failure on line 2102 in editor/plugins/node_3d_editor_plugin.cpp

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Editor (target=editor, tests=yes)

reference to non-static member function must be called; did you mean to call it with no arguments?

Check failure on line 2102 in editor/plugins/node_3d_editor_plugin.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

cannot convert '<unresolved overloaded function type>' to 'Node*'

Check failure on line 2102 in editor/plugins/node_3d_editor_plugin.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

cannot convert '<unresolved overloaded function type>' to 'Node*'

Check failure on line 2102 in editor/plugins/node_3d_editor_plugin.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

reference to non-static member function must be called; did you mean to call it with no arguments?

Check failure on line 2102 in editor/plugins/node_3d_editor_plugin.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

reference to non-static member function must be called; did you mean to call it with no arguments?

Check failure on line 2102 in editor/plugins/node_3d_editor_plugin.cpp

View workflow job for this annotation

GitHub Actions / 🤖 Android / Editor (target=editor)

reference to non-static member function must be called; did you mean to call it with no arguments?

Check failure on line 2102 in editor/plugins/node_3d_editor_plugin.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

'ObjectID::get_object': non-standard syntax; use '&' to create a pointer to member

Check failure on line 2102 in editor/plugins/node_3d_editor_plugin.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor w/ clang-cl (target=editor, tests=yes, use_llvm=yes)

reference to non-static member function must be called; did you mean to call it with no arguments?
cursor.region_select = true;
cursor.region_begin = _edit.original_mouse_pos;
clicked = ObjectID();
Expand Down Expand Up @@ -4815,8 +4815,8 @@ bool Node3DEditorViewport::_create_audio_node(Node *p_parent, const String &p_pa
void Node3DEditorViewport::_perform_drop_data() {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
if (spatial_editor->get_preview_material_target().is_valid()) {
GeometryInstance3D *geometry_instance = Object::cast_to<GeometryInstance3D>(ObjectDB::get_instance(spatial_editor->get_preview_material_target()));
MeshInstance3D *mesh_instance = Object::cast_to<MeshInstance3D>(ObjectDB::get_instance(spatial_editor->get_preview_material_target()));
GeometryInstance3D *geometry_instance = spatial_editor->get_preview_material_target().get_object<GeometryInstance3D>();
MeshInstance3D *mesh_instance = spatial_editor->get_preview_material_target().get_object<MeshInstance3D>();
if (mesh_instance && spatial_editor->get_preview_material_surface() != -1) {
undo_redo->create_action(vformat(TTR("Set Surface %d Override Material"), spatial_editor->get_preview_material_surface()));
undo_redo->add_do_method(geometry_instance, "set_surface_override_material", spatial_editor->get_preview_material_surface(), spatial_editor->get_preview_material());
Expand Down Expand Up @@ -8402,7 +8402,7 @@ void Node3DEditor::_request_gizmo(Object *p_obj) {
}

void Node3DEditor::_request_gizmo_for_id(ObjectID p_id) {
Node3D *node = Object::cast_to<Node3D>(ObjectDB::get_instance(p_id));
Node3D *node = p_id.get_object<Node3D>();
if (node) {
_request_gizmo(node);
}
Expand Down
6 changes: 3 additions & 3 deletions editor/plugins/tiles/tile_map_layer_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "core/os/keyboard.h"

TileMapLayer *TileMapLayerSubEditorPlugin::_get_edited_layer() const {
return Object::cast_to<TileMapLayer>(ObjectDB::get_instance(edited_tile_map_layer_id));
return edited_tile_map_layer_id.get_object<TileMapLayer>();
}

void TileMapLayerEditorTilesPlugin::tile_set_changed() {
Expand Down Expand Up @@ -2171,7 +2171,7 @@ void TileMapLayerEditorTilesPlugin::edit(ObjectID p_tile_map_layer_id) {
}
}

TileMapLayer *new_tile_map_layer = Object::cast_to<TileMapLayer>(ObjectDB::get_instance(edited_tile_map_layer_id));
TileMapLayer *new_tile_map_layer = edited_tile_map_layer_id.get_object<TileMapLayer>();
Ref<TileSet> new_tile_set;
if (new_tile_map_layer) {
new_tile_set = new_tile_map_layer->get_tile_set();
Expand Down Expand Up @@ -3632,7 +3632,7 @@ TileMapLayerEditorTerrainsPlugin::~TileMapLayerEditorTerrainsPlugin() {
}

TileMapLayer *TileMapLayerEditor::_get_edited_layer() const {
return Object::cast_to<TileMapLayer>(ObjectDB::get_instance(edited_tile_map_layer_id));
return edited_tile_map_layer_id.get_object<TileMapLayer>();
}

void TileMapLayerEditor::_find_tile_map_layers_in_scene(Node *p_current, const Node *p_owner, Vector<TileMapLayer *> &r_list) const {
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/tiles/tile_set_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ void TileSetEditor::remove_expanded_editor() {
return;
}

Node *original_parent = Object::cast_to<Node>(ObjectDB::get_instance(expanded_editor_parent));
Node *original_parent = expanded_editor_parent.get_object<Node>();
if (original_parent) {
expanded_editor->remove_meta("reparented");
expanded_editor->reparent(original_parent);
Expand Down
8 changes: 4 additions & 4 deletions editor/plugins/tiles/tiles_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,14 @@ void TileMapEditorPlugin::_tile_map_layer_changed() {

void TileMapEditorPlugin::_tile_map_layer_removed() {
// Workaround for TileMap, making sure the editor stays open when you delete the currently edited layer.
TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_group_id));
TileMap *tile_map = tile_map_group_id.get_object<TileMap>();
if (tile_map) {
edit(tile_map);
}
}

void TileMapEditorPlugin::_update_tile_map() {
TileMapLayer *edited_layer = Object::cast_to<TileMapLayer>(ObjectDB::get_instance(tile_map_layer_id));
TileMapLayer *edited_layer = tile_map_layer_id.get_object<TileMapLayer>();
if (edited_layer) {
Ref<TileSet> tile_set = edited_layer->get_tile_set();
if (tile_set.is_valid() && tile_set_id != tile_set->get_instance_id()) {
Expand All @@ -365,7 +365,7 @@ void TileMapEditorPlugin::_update_tile_map() {
}

void TileMapEditorPlugin::_select_layer(const StringName &p_name) {
TileMapLayer *edited_layer = Object::cast_to<TileMapLayer>(ObjectDB::get_instance(tile_map_layer_id));
TileMapLayer *edited_layer = tile_map_layer_id.get_object<TileMapLayer>();
ERR_FAIL_NULL(edited_layer);

Node *parent = edited_layer->get_parent();
Expand Down Expand Up @@ -417,7 +417,7 @@ void TileMapEditorPlugin::_notification(int p_notification) {
}

void TileMapEditorPlugin::edit(Object *p_object) {
TileMapLayer *edited_layer = Object::cast_to<TileMapLayer>(ObjectDB::get_instance(tile_map_layer_id));
TileMapLayer *edited_layer = tile_map_layer_id.get_object<TileMapLayer>();
if (edited_layer) {
edited_layer->disconnect(CoreStringName(changed), callable_mp(this, &TileMapEditorPlugin::_tile_map_layer_changed));
edited_layer->disconnect(SceneStringName(tree_exited), callable_mp(this, &TileMapEditorPlugin::_tile_map_layer_removed));
Expand Down
2 changes: 1 addition & 1 deletion editor/property_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void PropertySelector::_update_search() {
Variant::construct(type, v, nullptr, 0, ce);
v.get_method_list(&methods);
} else {
Ref<Script> script_ref = Object::cast_to<Script>(ObjectDB::get_instance(script));
Ref<Script> script_ref = script.get_ref<Script>();
if (script_ref.is_valid()) {
if (script_ref->is_built_in()) {
script_ref->reload(true);
Expand Down
4 changes: 2 additions & 2 deletions modules/multiplayer/multiplayer_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,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 = p_node.get_object<Node>()->get_path();
}

void MultiplayerDebugger::RPCProfiler::toggle(bool p_enable, const Array &p_opts) {
Expand Down Expand Up @@ -304,7 +304,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 = id.get_object<MultiplayerSynchronizer>();
ERR_FAIL_NULL(sync);
if (!sync_data.has(id)) {
sync_data[id] = SyncInfo(sync);
Expand Down
6 changes: 3 additions & 3 deletions modules/multiplayer/multiplayer_spawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,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 = spawn_node.get_object<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));
}
Expand All @@ -213,7 +213,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 = E.key.get_object<Node>();
ERR_CONTINUE(!node);
node->disconnect(SceneStringName(tree_exiting), callable_mp(this, &MultiplayerSpawner::_node_exit));
get_multiplayer()->object_configuration_remove(node, this);
Expand Down Expand Up @@ -267,7 +267,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 = p_id.get_object<Node>();
ERR_FAIL_NULL(node);
if (tracked_nodes.has(p_id)) {
tracked_nodes.erase(p_id);
Expand Down
2 changes: 1 addition & 1 deletion modules/multiplayer/multiplayer_spawner.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MultiplayerSpawner : public Node {
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() ? spawn_node.get_object<Node>() : nullptr;
}

void add_spawnable_scene(const String &p_path);
Expand Down
2 changes: 1 addition & 1 deletion modules/multiplayer/multiplayer_synchronizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ? root_node_cache.get_object<Node>() : nullptr;
}

void MultiplayerSynchronizer::reset() {
Expand Down
4 changes: 2 additions & 2 deletions modules/multiplayer/scene_cache_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,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 = (*oid).get_object<Node>();
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());
}
Expand Down Expand Up @@ -280,7 +280,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 = recv_node->oid.get_object<Node>();
if (!node) {
// Fallback to path lookup.
Node *root_node = SceneTree::get_singleton()->get_root()->get_node(multiplayer->get_root_path());
Expand Down
2 changes: 1 addition & 1 deletion modules/multiplayer/scene_replication_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class SceneReplicationInterface : public RefCounted {

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() ? p_id.get_object<T>() : nullptr;
}

#ifdef DEBUG_ENABLED
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/physics/character_body_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ void CharacterBody2D::_set_collision_direction(const PhysicsServer2D::MotionResu
on_wall = true;
wall_normal = p_result.collision_normal;
// Don't apply wall velocity when the collider is a CharacterBody2D.
if (Object::cast_to<CharacterBody2D>(ObjectDB::get_instance(p_result.collider_id)) == nullptr) {
if (p_result.collider_id.get_object<CharacterBody2D>() == nullptr) {
_set_platform_data(p_result);
}
}
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/physics/kinematic_collision_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ real_t KinematicCollision2D::get_depth() const {
}

Object *KinematicCollision2D::get_local_shape() const {
PhysicsBody2D *owner = Object::cast_to<PhysicsBody2D>(ObjectDB::get_instance(owner_id));
PhysicsBody2D *owner = owner_id.get_object<PhysicsBody2D>();
if (!owner) {
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions scene/2d/remote_transform_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void RemoteTransform2D::_update_remote() {
return;
}

Node2D *n = Object::cast_to<Node2D>(ObjectDB::get_instance(cache));
Node2D *n = cache.get_object<Node2D>();
if (!n) {
return;
}
Expand Down Expand Up @@ -117,7 +117,7 @@ void RemoteTransform2D::_notification(int p_what) {
case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
if (cache.is_valid()) {
_update_remote();
Node2D *n = Object::cast_to<Node2D>(ObjectDB::get_instance(cache));
Node2D *n = cache.get_object<Node2D>();
if (n) {
n->reset_physics_interpolation();
}
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/visible_on_screen_notifier_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ NodePath VisibleOnScreenEnabler2D::get_enable_node_path() {
}

void VisibleOnScreenEnabler2D::_update_enable_mode(bool p_enable) {
Node *node = static_cast<Node *>(ObjectDB::get_instance(node_id));
Node *node = node_id.get_object<Node>();
if (node) {
if (p_enable) {
switch (enable_mode) {
Expand Down
Loading

0 comments on commit 712540b

Please sign in to comment.