summaryrefslogtreecommitdiffstats
path: root/core/variant/variant.h
diff options
context:
space:
mode:
authorrune-scape <allie.smith.epic@gmail.com>2024-06-18 03:31:23 -0700
committerrune-scape <spartacrafter@gmail.com>2024-09-21 11:36:58 -0700
commitcee0e6667a2583a128ab3de33ab43f06222c4ca9 (patch)
treeaa187a8e2ea149ad8a00a844710d5c8c3cc18f8d /core/variant/variant.h
parente4e024ab88efe74677769395886bc1b09eccbac7 (diff)
downloadredot-engine-cee0e6667a2583a128ab3de33ab43f06222c4ca9.tar.gz
Refactor ref-counting code and fix ref counted releasing before aquiring
Diffstat (limited to 'core/variant/variant.h')
-rw-r--r--core/variant/variant.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/core/variant/variant.h b/core/variant/variant.h
index d4e4b330cd..c76b849abd 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -62,6 +62,10 @@
#include "core/variant/dictionary.h"
class Object;
+class RefCounted;
+
+template <typename T>
+class Ref;
struct PropertyInfo;
struct MethodInfo;
@@ -175,6 +179,20 @@ private:
struct ObjData {
ObjectID id;
Object *obj = nullptr;
+
+ void ref(const ObjData &p_from);
+ void ref_pointer(Object *p_object);
+ void ref_pointer(RefCounted *p_object);
+ void unref();
+
+ template <typename T>
+ _ALWAYS_INLINE_ void ref(const Ref<T> &p_from) {
+ if (p_from.is_valid()) {
+ ref(ObjData{ p_from->get_instance_id(), p_from.ptr() });
+ } else {
+ unref();
+ }
+ }
};
/* array helpers */