feat: updated engine
This commit is contained in:
parent
cbe99774ff
commit
f4cf6b3999
6607 changed files with 910135 additions and 430025 deletions
|
|
@ -34,11 +34,36 @@
|
|||
#include "core/io/json.h"
|
||||
#include "core/io/resource.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/object/gdtype.h"
|
||||
#include "core/variant/variant_parser.h"
|
||||
#include "core/variant/variant_pools.h"
|
||||
|
||||
PagedAllocator<Variant::Pools::BucketSmall, true> Variant::Pools::_bucket_small;
|
||||
PagedAllocator<Variant::Pools::BucketMedium, true> Variant::Pools::_bucket_medium;
|
||||
PagedAllocator<Variant::Pools::BucketLarge, true> Variant::Pools::_bucket_large;
|
||||
// Caution: These GDTypes are work-in-progress and may not be feature complete.
|
||||
// Do not use them without consulting the core team.
|
||||
static GDType *variant_gdtypes[Variant::VARIANT_MAX] = {};
|
||||
|
||||
GDType &Variant::_get_gdtype_for_type(Variant::Type p_type) {
|
||||
ERR_FAIL_INDEX_V_MSG(p_type, VARIANT_MAX, *variant_gdtypes[Variant::NIL], "Invalid Variant type");
|
||||
|
||||
return *variant_gdtypes[p_type];
|
||||
}
|
||||
|
||||
void Variant::_register_variant_gdtypes() {
|
||||
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
|
||||
Variant::Type type = static_cast<Variant::Type>(i);
|
||||
variant_gdtypes[i] = memnew(GDType(nullptr, Variant::get_type_name(type)));
|
||||
variant_gdtypes[i]->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
void Variant::_unregister_variant_gdtypes() {
|
||||
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
|
||||
if (variant_gdtypes[i]) {
|
||||
memdelete(variant_gdtypes[i]);
|
||||
variant_gdtypes[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String Variant::get_type_name(Variant::Type p_type) {
|
||||
switch (p_type) {
|
||||
|
|
@ -868,17 +893,6 @@ bool Variant::operator==(const Variant &p_variant) const {
|
|||
return hash_compare(p_variant);
|
||||
}
|
||||
|
||||
bool Variant::operator!=(const Variant &p_variant) const {
|
||||
// Don't use `!hash_compare(p_variant)` given it makes use of OP_EQUAL
|
||||
if (type != p_variant.type) { //evaluation of operator== needs to be more strict
|
||||
return true;
|
||||
}
|
||||
bool v;
|
||||
Variant r;
|
||||
evaluate(OP_NOT_EQUAL, *this, p_variant, r, v);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool Variant::operator<(const Variant &p_variant) const {
|
||||
if (type != p_variant.type) { //if types differ, then order by type first
|
||||
return type < p_variant.type;
|
||||
|
|
@ -1183,7 +1197,7 @@ void Variant::reference(const Variant &p_variant) {
|
|||
memnew_placement(_data._mem, Rect2i(*reinterpret_cast<const Rect2i *>(p_variant._data._mem)));
|
||||
} break;
|
||||
case TRANSFORM2D: {
|
||||
_data._transform2d = (Transform2D *)Pools::_bucket_small.alloc();
|
||||
_data._transform2d = VariantPools::alloc<Transform2D>();
|
||||
memnew_placement(_data._transform2d, Transform2D(*p_variant._data._transform2d));
|
||||
} break;
|
||||
case VECTOR3: {
|
||||
|
|
@ -1202,22 +1216,22 @@ void Variant::reference(const Variant &p_variant) {
|
|||
memnew_placement(_data._mem, Plane(*reinterpret_cast<const Plane *>(p_variant._data._mem)));
|
||||
} break;
|
||||
case AABB: {
|
||||
_data._aabb = (::AABB *)Pools::_bucket_small.alloc();
|
||||
_data._aabb = VariantPools::alloc<::AABB>();
|
||||
memnew_placement(_data._aabb, ::AABB(*p_variant._data._aabb));
|
||||
} break;
|
||||
case QUATERNION: {
|
||||
memnew_placement(_data._mem, Quaternion(*reinterpret_cast<const Quaternion *>(p_variant._data._mem)));
|
||||
} break;
|
||||
case BASIS: {
|
||||
_data._basis = (Basis *)Pools::_bucket_medium.alloc();
|
||||
_data._ptr = VariantPools::alloc<Basis>();
|
||||
memnew_placement(_data._basis, Basis(*p_variant._data._basis));
|
||||
} break;
|
||||
case TRANSFORM3D: {
|
||||
_data._transform3d = (Transform3D *)Pools::_bucket_medium.alloc();
|
||||
_data._ptr = VariantPools::alloc<Transform3D>();
|
||||
memnew_placement(_data._transform3d, Transform3D(*p_variant._data._transform3d));
|
||||
} break;
|
||||
case PROJECTION: {
|
||||
_data._projection = (Projection *)Pools::_bucket_large.alloc();
|
||||
_data._ptr = VariantPools::alloc<Projection>();
|
||||
memnew_placement(_data._projection, Projection(*p_variant._data._projection));
|
||||
} break;
|
||||
|
||||
|
|
@ -1388,35 +1402,35 @@ void Variant::_clear_internal() {
|
|||
case TRANSFORM2D: {
|
||||
if (_data._transform2d) {
|
||||
_data._transform2d->~Transform2D();
|
||||
Pools::_bucket_small.free((Pools::BucketSmall *)_data._transform2d);
|
||||
VariantPools::free(_data._transform2d);
|
||||
_data._transform2d = nullptr;
|
||||
}
|
||||
} break;
|
||||
case AABB: {
|
||||
if (_data._aabb) {
|
||||
_data._aabb->~AABB();
|
||||
Pools::_bucket_small.free((Pools::BucketSmall *)_data._aabb);
|
||||
VariantPools::free(_data._aabb);
|
||||
_data._aabb = nullptr;
|
||||
}
|
||||
} break;
|
||||
case BASIS: {
|
||||
if (_data._basis) {
|
||||
_data._basis->~Basis();
|
||||
Pools::_bucket_medium.free((Pools::BucketMedium *)_data._basis);
|
||||
VariantPools::free(_data._basis);
|
||||
_data._basis = nullptr;
|
||||
}
|
||||
} break;
|
||||
case TRANSFORM3D: {
|
||||
if (_data._transform3d) {
|
||||
_data._transform3d->~Transform3D();
|
||||
Pools::_bucket_medium.free((Pools::BucketMedium *)_data._transform3d);
|
||||
VariantPools::free(_data._transform3d);
|
||||
_data._transform3d = nullptr;
|
||||
}
|
||||
} break;
|
||||
case PROJECTION: {
|
||||
if (_data._projection) {
|
||||
_data._projection->~Projection();
|
||||
Pools::_bucket_large.free((Pools::BucketLarge *)_data._projection);
|
||||
VariantPools::free(_data._projection);
|
||||
_data._projection = nullptr;
|
||||
}
|
||||
} break;
|
||||
|
|
@ -1504,6 +1518,10 @@ Variant::operator int8_t() const {
|
|||
return _to_int<int8_t>();
|
||||
}
|
||||
|
||||
Variant::operator Math::int_alt_t() const {
|
||||
return _to_int<Math::int_alt_t>();
|
||||
}
|
||||
|
||||
Variant::operator uint64_t() const {
|
||||
return _to_int<uint64_t>();
|
||||
}
|
||||
|
|
@ -1520,6 +1538,10 @@ Variant::operator uint8_t() const {
|
|||
return _to_int<uint8_t>();
|
||||
}
|
||||
|
||||
Variant::operator Math::uint_alt_t() const {
|
||||
return _to_int<Math::uint_alt_t>();
|
||||
}
|
||||
|
||||
Variant::operator ObjectID() const {
|
||||
if (type == INT) {
|
||||
return ObjectID(_data._int);
|
||||
|
|
@ -2333,6 +2355,11 @@ Variant::Variant(int8_t p_int8) :
|
|||
_data._int = p_int8;
|
||||
}
|
||||
|
||||
Variant::Variant(Math::int_alt_t p_int_alt) :
|
||||
type(INT) {
|
||||
_data._int = p_int_alt;
|
||||
}
|
||||
|
||||
Variant::Variant(uint64_t p_uint64) :
|
||||
type(INT) {
|
||||
_data._int = int64_t(p_uint64);
|
||||
|
|
@ -2353,6 +2380,11 @@ Variant::Variant(uint8_t p_uint8) :
|
|||
_data._int = int64_t(p_uint8);
|
||||
}
|
||||
|
||||
Variant::Variant(Math::uint_alt_t p_uint_alt) :
|
||||
type(INT) {
|
||||
_data._int = p_uint_alt;
|
||||
}
|
||||
|
||||
Variant::Variant(float p_float) :
|
||||
type(FLOAT) {
|
||||
_data._float = p_float;
|
||||
|
|
@ -2448,13 +2480,13 @@ Variant::Variant(const Plane &p_plane) :
|
|||
|
||||
Variant::Variant(const ::AABB &p_aabb) :
|
||||
type(AABB) {
|
||||
_data._aabb = (::AABB *)Pools::_bucket_small.alloc();
|
||||
_data._aabb = VariantPools::alloc<::AABB>();
|
||||
memnew_placement(_data._aabb, ::AABB(p_aabb));
|
||||
}
|
||||
|
||||
Variant::Variant(const Basis &p_matrix) :
|
||||
type(BASIS) {
|
||||
_data._basis = (Basis *)Pools::_bucket_medium.alloc();
|
||||
_data._basis = VariantPools::alloc<Basis>();
|
||||
memnew_placement(_data._basis, Basis(p_matrix));
|
||||
}
|
||||
|
||||
|
|
@ -2466,19 +2498,19 @@ Variant::Variant(const Quaternion &p_quaternion) :
|
|||
|
||||
Variant::Variant(const Transform3D &p_transform) :
|
||||
type(TRANSFORM3D) {
|
||||
_data._transform3d = (Transform3D *)Pools::_bucket_medium.alloc();
|
||||
_data._transform3d = VariantPools::alloc<Transform3D>();
|
||||
memnew_placement(_data._transform3d, Transform3D(p_transform));
|
||||
}
|
||||
|
||||
Variant::Variant(const Projection &pp_projection) :
|
||||
type(PROJECTION) {
|
||||
_data._projection = (Projection *)Pools::_bucket_large.alloc();
|
||||
_data._projection = VariantPools::alloc<Projection>();
|
||||
memnew_placement(_data._projection, Projection(pp_projection));
|
||||
}
|
||||
|
||||
Variant::Variant(const Transform2D &p_transform) :
|
||||
type(TRANSFORM2D) {
|
||||
_data._transform2d = (Transform2D *)Pools::_bucket_small.alloc();
|
||||
_data._transform2d = VariantPools::alloc<Transform2D>();
|
||||
memnew_placement(_data._transform2d, Transform2D(p_transform));
|
||||
}
|
||||
|
||||
|
|
@ -3155,18 +3187,18 @@ uint32_t Variant::recursive_hash(int recursion_count) const {
|
|||
#define hash_compare_packed_array(p_lhs, p_rhs, p_type, p_compare_func) \
|
||||
const Vector<p_type> &l = PackedArrayRef<p_type>::get_array(p_lhs); \
|
||||
const Vector<p_type> &r = PackedArrayRef<p_type>::get_array(p_rhs); \
|
||||
\
|
||||
if (l.size() != r.size()) \
|
||||
return false; \
|
||||
\
|
||||
const p_type *lr = l.ptr(); \
|
||||
const p_type *rr = r.ptr(); \
|
||||
\
|
||||
for (int i = 0; i < l.size(); ++i) { \
|
||||
if (!p_compare_func((lr[i]), (rr[i]))) \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
\
|
||||
if (l.size() != r.size()) \
|
||||
return false; \
|
||||
\
|
||||
const p_type *lr = l.ptr(); \
|
||||
const p_type *rr = r.ptr(); \
|
||||
\
|
||||
for (int i = 0; i < l.size(); ++i) { \
|
||||
if (!p_compare_func((lr[i]), (rr[i]))) \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
return true
|
||||
|
||||
bool Variant::hash_compare(const Variant &p_variant, int recursion_count, bool semantic_comparison) const {
|
||||
|
|
@ -3433,14 +3465,24 @@ bool Variant::is_ref_counted() const {
|
|||
bool Variant::is_type_shared(Variant::Type p_type) {
|
||||
switch (p_type) {
|
||||
case OBJECT:
|
||||
case ARRAY:
|
||||
case DICTIONARY:
|
||||
case ARRAY:
|
||||
// NOTE: Packed array constructors **do** copies (unlike `Array()` and `Dictionary()`),
|
||||
// whereas they pass by reference when inside a `Variant`.
|
||||
case PACKED_BYTE_ARRAY:
|
||||
case PACKED_INT32_ARRAY:
|
||||
case PACKED_INT64_ARRAY:
|
||||
case PACKED_FLOAT32_ARRAY:
|
||||
case PACKED_FLOAT64_ARRAY:
|
||||
case PACKED_STRING_ARRAY:
|
||||
case PACKED_VECTOR2_ARRAY:
|
||||
case PACKED_VECTOR3_ARRAY:
|
||||
case PACKED_COLOR_ARRAY:
|
||||
case PACKED_VECTOR4_ARRAY:
|
||||
return true;
|
||||
default: {
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Variant::is_shared() const {
|
||||
|
|
@ -3551,6 +3593,7 @@ String Variant::get_callable_error_text(const Callable &p_callable, const Varian
|
|||
}
|
||||
|
||||
void Variant::register_types() {
|
||||
_register_variant_gdtypes();
|
||||
_register_variant_operators();
|
||||
_register_variant_methods();
|
||||
_register_variant_setters_getters();
|
||||
|
|
@ -3564,4 +3607,5 @@ void Variant::unregister_types() {
|
|||
_unregister_variant_setters_getters();
|
||||
_unregister_variant_destructors();
|
||||
_unregister_variant_utility_functions();
|
||||
_unregister_variant_gdtypes();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue