summaryrefslogtreecommitdiff
path: root/core/reference.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/reference.h')
-rw-r--r--core/reference.h123
1 files changed, 32 insertions, 91 deletions
diff --git a/core/reference.h b/core/reference.h
index d2314005b9..30a93d82a6 100644
--- a/core/reference.h
+++ b/core/reference.h
@@ -33,13 +33,11 @@
#include "core/class_db.h"
#include "core/object.h"
-#include "core/ref_ptr.h"
#include "core/safe_refcount.h"
class Reference : public Object {
GDCLASS(Reference, Object);
- friend class RefBase;
SafeRefCount refcount;
SafeRefCount refcount_init;
@@ -133,17 +131,9 @@ public:
return reference;
}
- RefPtr get_ref_ptr() const {
-
- RefPtr refptr;
- Ref<Reference> *irr = reinterpret_cast<Ref<Reference> *>(refptr.get_data());
- *irr = *this;
- return refptr;
- };
-
operator Variant() const {
- return Variant(get_ref_ptr());
+ return Variant(reference);
}
void operator=(const Ref &p_from) {
@@ -162,36 +152,27 @@ public:
Ref r;
r.reference = Object::cast_to<T>(refb);
ref(r);
- r.reference = NULL;
+ r.reference = nullptr;
}
- void operator=(const RefPtr &p_refptr) {
+ void operator=(const Variant &p_variant) {
+
+ Object *object = p_variant.get_validated_object();
- Ref<Reference> *irr = reinterpret_cast<Ref<Reference> *>(p_refptr.get_data());
- Reference *refb = irr->ptr();
- if (!refb) {
- unref();
+ if (object == reference) {
return;
}
- Ref r;
- r.reference = Object::cast_to<T>(refb);
- ref(r);
- r.reference = NULL;
- }
- void operator=(const Variant &p_variant) {
+ unref();
- RefPtr refptr = p_variant;
- Ref<Reference> *irr = reinterpret_cast<Ref<Reference> *>(refptr.get_data());
- Reference *refb = irr->ptr();
- if (!refb) {
- unref();
+ if (!object) {
return;
}
- Ref r;
- r.reference = Object::cast_to<T>(refb);
- ref(r);
- r.reference = NULL;
+
+ T *r = Object::cast_to<T>(object);
+ if (r && r->reference()) {
+ reference = r;
+ }
}
template <class T_Other>
@@ -209,14 +190,14 @@ public:
Ref(const Ref &p_from) {
- reference = NULL;
+ reference = nullptr;
ref(p_from);
}
template <class T_Other>
Ref(const Ref<T_Other> &p_from) {
- reference = NULL;
+ reference = nullptr;
Reference *refb = const_cast<Reference *>(static_cast<const Reference *>(p_from.ptr()));
if (!refb) {
unref();
@@ -225,49 +206,35 @@ public:
Ref r;
r.reference = Object::cast_to<T>(refb);
ref(r);
- r.reference = NULL;
+ r.reference = nullptr;
}
Ref(T *p_reference) {
- reference = NULL;
+ reference = nullptr;
if (p_reference)
ref_pointer(p_reference);
}
Ref(const Variant &p_variant) {
- RefPtr refptr = p_variant;
- Ref<Reference> *irr = reinterpret_cast<Ref<Reference> *>(refptr.get_data());
- reference = NULL;
- Reference *refb = irr->ptr();
- if (!refb) {
- unref();
+ Object *object = p_variant.get_validated_object();
+
+ if (!object) {
+ reference = nullptr;
return;
}
- Ref r;
- r.reference = Object::cast_to<T>(refb);
- ref(r);
- r.reference = NULL;
- }
-
- Ref(const RefPtr &p_refptr) {
- Ref<Reference> *irr = reinterpret_cast<Ref<Reference> *>(p_refptr.get_data());
- reference = NULL;
- Reference *refb = irr->ptr();
- if (!refb) {
- unref();
- return;
+ T *r = Object::cast_to<T>(object);
+ if (r && r->reference()) {
+ reference = r;
+ } else {
+ reference = nullptr;
}
- Ref r;
- r.reference = Object::cast_to<T>(refb);
- ref(r);
- r.reference = NULL;
}
- inline bool is_valid() const { return reference != NULL; }
- inline bool is_null() const { return reference == NULL; }
+ inline bool is_valid() const { return reference != nullptr; }
+ inline bool is_null() const { return reference == nullptr; }
void unref() {
//TODO this should be moved to mutexes, since this engine does not really
@@ -278,7 +245,7 @@ public:
memdelete(reference);
}
- reference = NULL;
+ reference = nullptr;
}
void instance() {
@@ -287,7 +254,7 @@ public:
Ref() {
- reference = NULL;
+ reference = nullptr;
}
~Ref() {
@@ -318,7 +285,7 @@ public:
#ifdef PTRCALL_ENABLED
template <class T>
-struct PtrToArg<Ref<T> > {
+struct PtrToArg<Ref<T>> {
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
@@ -340,38 +307,12 @@ struct PtrToArg<const Ref<T> &> {
}
};
-//this is for RefPtr
-
-template <>
-struct PtrToArg<RefPtr> {
-
- _FORCE_INLINE_ static RefPtr convert(const void *p_ptr) {
-
- return Ref<Reference>(const_cast<Reference *>(reinterpret_cast<const Reference *>(p_ptr))).get_ref_ptr();
- }
-
- _FORCE_INLINE_ static void encode(RefPtr p_val, const void *p_ptr) {
-
- Ref<Reference> r = p_val;
- *(Ref<Reference> *)p_ptr = r;
- }
-};
-
-template <>
-struct PtrToArg<const RefPtr &> {
-
- _FORCE_INLINE_ static RefPtr convert(const void *p_ptr) {
-
- return Ref<Reference>(const_cast<Reference *>(reinterpret_cast<const Reference *>(p_ptr))).get_ref_ptr();
- }
-};
-
#endif // PTRCALL_ENABLED
#ifdef DEBUG_METHODS_ENABLED
template <class T>
-struct GetTypeInfo<Ref<T> > {
+struct GetTypeInfo<Ref<T>> {
static const Variant::Type VARIANT_TYPE = Variant::OBJECT;
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE;