feat: modules moved and engine moved to submodule
This commit is contained in:
parent
dfb5e645cd
commit
c33d2130cc
5136 changed files with 225275 additions and 64485 deletions
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef REF_COUNTED_H
|
||||
#define REF_COUNTED_H
|
||||
#pragma once
|
||||
|
||||
#include "core/object/class_db.h"
|
||||
#include "core/templates/safe_refcount.h"
|
||||
|
|
@ -86,6 +85,10 @@ class Ref {
|
|||
|
||||
//virtual RefCounted * get_reference() const { return reference; }
|
||||
public:
|
||||
static _FORCE_INLINE_ String get_class_static() {
|
||||
return T::get_class_static();
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool operator==(const T *p_ptr) const {
|
||||
return reference == p_ptr;
|
||||
}
|
||||
|
|
@ -128,6 +131,15 @@ public:
|
|||
ref(p_from);
|
||||
}
|
||||
|
||||
void operator=(Ref &&p_from) {
|
||||
if (reference == p_from.reference) {
|
||||
return;
|
||||
}
|
||||
unref();
|
||||
reference = p_from.reference;
|
||||
p_from.reference = nullptr;
|
||||
}
|
||||
|
||||
template <typename T_Other>
|
||||
void operator=(const Ref<T_Other> &p_from) {
|
||||
ref_pointer<false>(Object::cast_to<T>(p_from.ptr()));
|
||||
|
|
@ -160,6 +172,11 @@ public:
|
|||
this->operator=(p_from);
|
||||
}
|
||||
|
||||
Ref(Ref &&p_from) {
|
||||
reference = p_from.reference;
|
||||
p_from.reference = nullptr;
|
||||
}
|
||||
|
||||
template <typename T_Other>
|
||||
Ref(const Ref<T_Other> &p_from) {
|
||||
this->operator=(p_from);
|
||||
|
|
@ -181,10 +198,15 @@ public:
|
|||
// do a lot of referencing on references and stuff
|
||||
// mutexes will avoid more crashes?
|
||||
|
||||
if (reference && reference->unreference()) {
|
||||
memdelete(reference);
|
||||
if (reference) {
|
||||
// NOTE: `reinterpret_cast` is "safe" here because we know `T` has simple linear
|
||||
// inheritance to `RefCounted`. This guarantees that `T * == `RefCounted *`, which
|
||||
// allows us to declare `Ref<T>` with forward declared `T` types.
|
||||
if (reinterpret_cast<RefCounted *>(reference)->unreference()) {
|
||||
memdelete(reinterpret_cast<RefCounted *>(reference));
|
||||
}
|
||||
reference = nullptr;
|
||||
}
|
||||
reference = nullptr;
|
||||
}
|
||||
|
||||
template <typename... VarArgs>
|
||||
|
|
@ -233,19 +255,6 @@ struct PtrToArg<Ref<T>> {
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct PtrToArg<const Ref<T> &> {
|
||||
typedef Ref<T> EncodeT;
|
||||
|
||||
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
|
||||
if (p_ptr == nullptr) {
|
||||
return Ref<T>();
|
||||
}
|
||||
// p_ptr points to a RefCounted object
|
||||
return Ref<T>(*((T *const *)p_ptr));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct GetTypeInfo<Ref<T>> {
|
||||
static const Variant::Type VARIANT_TYPE = Variant::OBJECT;
|
||||
|
|
@ -256,26 +265,17 @@ struct GetTypeInfo<Ref<T>> {
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct GetTypeInfo<const Ref<T> &> {
|
||||
static const Variant::Type VARIANT_TYPE = Variant::OBJECT;
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE;
|
||||
|
||||
static inline PropertyInfo get_class_info() {
|
||||
return PropertyInfo(Variant::OBJECT, String(), PROPERTY_HINT_RESOURCE_TYPE, T::get_class_static());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct VariantInternalAccessor<Ref<T>> {
|
||||
static _FORCE_INLINE_ Ref<T> get(const Variant *v) { return Ref<T>(*VariantInternal::get_object(v)); }
|
||||
static _FORCE_INLINE_ void set(Variant *v, const Ref<T> &p_ref) { VariantInternal::object_assign(v, p_ref); }
|
||||
};
|
||||
|
||||
// Zero-constructing Ref initializes reference to nullptr (and thus empty).
|
||||
template <typename T>
|
||||
struct VariantInternalAccessor<const Ref<T> &> {
|
||||
static _FORCE_INLINE_ Ref<T> get(const Variant *v) { return Ref<T>(*VariantInternal::get_object(v)); }
|
||||
static _FORCE_INLINE_ void set(Variant *v, const Ref<T> &p_ref) { VariantInternal::object_assign(v, p_ref); }
|
||||
};
|
||||
struct is_zero_constructible<Ref<T>> : std::true_type {};
|
||||
|
||||
#endif // REF_COUNTED_H
|
||||
template <typename T>
|
||||
Ref<T> ObjectDB::get_ref(ObjectID p_instance_id) {
|
||||
return Ref<T>(get_instance(p_instance_id));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue