Selaa lähdekoodia

Merge pull request #100603 from lawnjelly/get_instance_cast

[3.x] Simplify `ObjectDB::get_instance()` casting
lawnjelly 5 kuukautta sitten
vanhempi
commit
157f8805c2
2 muutettua tiedostoa jossa 7 lisäystä ja 0 poistoa
  1. 1 0
      core/object.cpp
  2. 6 0
      core/object.h

+ 1 - 0
core/object.cpp

@@ -2036,6 +2036,7 @@ void ObjectDB::remove_instance(Object *p_object) {
 
 
 	rw_lock.write_unlock();
 	rw_lock.write_unlock();
 }
 }
+
 Object *ObjectDB::get_instance(ObjectID p_instance_id) {
 Object *ObjectDB::get_instance(ObjectID p_instance_id) {
 	rw_lock.read_lock();
 	rw_lock.read_lock();
 	Object **obj = instances.getptr(p_instance_id);
 	Object **obj = instances.getptr(p_instance_id);

+ 6 - 0
core/object.h

@@ -798,6 +798,12 @@ public:
 	typedef void (*DebugFunc)(Object *p_obj);
 	typedef void (*DebugFunc)(Object *p_obj);
 
 
 	static Object *get_instance(ObjectID p_instance_id);
 	static Object *get_instance(ObjectID p_instance_id);
+
+	template <class T>
+	static T *get_instance(ObjectID p_instance_id) {
+		return Object::cast_to<T>(get_instance(p_instance_id));
+	}
+
 	static void debug_objects(DebugFunc p_func);
 	static void debug_objects(DebugFunc p_func);
 	static int get_object_count();
 	static int get_object_count();