From dedeec94921f2685c94bc5e523206ed216edc618 Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Thu, 19 Dec 2024 12:44:33 +0000 Subject: [PATCH] Simplified `ObjectDB::get_instance()` casting Reduces boiler plate by templating `get_instance()` for the cast type, while remaining backward compatible to the existing functionality. --- core/object/object.cpp | 1 + core/object/object.h | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/core/object/object.cpp b/core/object/object.cpp index bd4ff3d7b..77c0ad41a 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -2043,6 +2043,7 @@ void ObjectDB::remove_instance(Object *p_object) { rw_lock.write_unlock(); } + Object *ObjectDB::get_instance(ObjectID p_instance_id) { rw_lock.read_lock(); Object **obj = instances.getptr(p_instance_id); diff --git a/core/object/object.h b/core/object/object.h index 56213bc98..c7001aff9 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -856,6 +856,12 @@ public: typedef void (*DebugFunc)(Object *p_obj); static Object *get_instance(ObjectID p_instance_id); + + template + static T *get_instance(ObjectID p_instance_id) { + return Object::cast_to(get_instance(p_instance_id)); + } + static void debug_objects(DebugFunc p_func); static int get_object_count();