summaryrefslogtreecommitdiff
path: root/core/variant.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/variant.cpp')
-rw-r--r--core/variant.cpp2496
1 files changed, 1356 insertions, 1140 deletions
diff --git a/core/variant.cpp b/core/variant.cpp
index f4e4cd5341..181ced0f32 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -31,6 +31,7 @@
#include "variant.h"
#include "core/core_string_names.h"
+#include "core/debugger/engine_debugger.h"
#include "core/io/marshalls.h"
#include "core/math/math_funcs.h"
#include "core/print_string.h"
@@ -40,143 +41,137 @@
#include "scene/main/node.h"
String Variant::get_type_name(Variant::Type p_type) {
-
switch (p_type) {
case NIL: {
-
return "Nil";
} break;
// atomic types
case BOOL: {
-
return "bool";
} break;
case INT: {
-
return "int";
} break;
- case REAL: {
-
+ case FLOAT: {
return "float";
} break;
case STRING: {
-
return "String";
} break;
// math types
case VECTOR2: {
-
return "Vector2";
} break;
+ case VECTOR2I: {
+ return "Vector2i";
+ } break;
case RECT2: {
-
return "Rect2";
} break;
+ case RECT2I: {
+ return "Rect2i";
+ } break;
case TRANSFORM2D: {
-
return "Transform2D";
} break;
case VECTOR3: {
-
return "Vector3";
} break;
+ case VECTOR3I: {
+ return "Vector3i";
+ } break;
case PLANE: {
-
return "Plane";
} break;
- /*
- case QUAT: {
-
-
- } break;*/
case AABB: {
-
return "AABB";
} break;
case QUAT: {
-
return "Quat";
} break;
case BASIS: {
-
return "Basis";
} break;
case TRANSFORM: {
-
return "Transform";
} break;
// misc types
case COLOR: {
-
return "Color";
} break;
case _RID: {
-
return "RID";
} break;
case OBJECT: {
-
return "Object";
} break;
- case NODE_PATH: {
+ case CALLABLE: {
+ return "Callable";
+ } break;
+ case SIGNAL: {
+ return "Signal";
+ } break;
+ case STRING_NAME: {
+ return "StringName";
+ } break;
+ case NODE_PATH: {
return "NodePath";
} break;
case DICTIONARY: {
-
return "Dictionary";
} break;
case ARRAY: {
-
return "Array";
} break;
// arrays
- case POOL_BYTE_ARRAY: {
-
- return "PoolByteArray";
+ case PACKED_BYTE_ARRAY: {
+ return "PackedByteArray";
} break;
- case POOL_INT_ARRAY: {
-
- return "PoolIntArray";
+ case PACKED_INT32_ARRAY: {
+ return "PackedInt32Array";
} break;
- case POOL_REAL_ARRAY: {
-
- return "PoolRealArray";
+ case PACKED_INT64_ARRAY: {
+ return "PackedInt64Array";
} break;
- case POOL_STRING_ARRAY: {
+ case PACKED_FLOAT32_ARRAY: {
+ return "PackedFloat32Array";
- return "PoolStringArray";
} break;
- case POOL_VECTOR2_ARRAY: {
-
- return "PoolVector2Array";
+ case PACKED_FLOAT64_ARRAY: {
+ return "PackedFloat64Array";
} break;
- case POOL_VECTOR3_ARRAY: {
-
- return "PoolVector3Array";
+ case PACKED_STRING_ARRAY: {
+ return "PackedStringArray";
+ } break;
+ case PACKED_VECTOR2_ARRAY: {
+ return "PackedVector2Array";
} break;
- case POOL_COLOR_ARRAY: {
+ case PACKED_VECTOR3_ARRAY: {
+ return "PackedVector3Array";
- return "PoolColorArray";
+ } break;
+ case PACKED_COLOR_ARRAY: {
+ return "PackedColorArray";
} break;
default: {
@@ -187,25 +182,25 @@ String Variant::get_type_name(Variant::Type p_type) {
}
bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
-
- if (p_type_from == p_type_to)
+ if (p_type_from == p_type_to) {
return true;
- if (p_type_to == NIL && p_type_from != NIL) //nil can convert to anything
+ }
+ if (p_type_to == NIL && p_type_from != NIL) { //nil can convert to anything
return true;
+ }
if (p_type_from == NIL) {
return (p_type_to == OBJECT);
- };
+ }
- const Type *valid_types = NULL;
- const Type *invalid_types = NULL;
+ const Type *valid_types = nullptr;
+ const Type *invalid_types = nullptr;
switch (p_type_to) {
case BOOL: {
-
static const Type valid[] = {
INT,
- REAL,
+ FLOAT,
STRING,
NIL,
};
@@ -213,10 +208,9 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case INT: {
-
static const Type valid[] = {
BOOL,
- REAL,
+ FLOAT,
STRING,
NIL,
};
@@ -224,8 +218,7 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
- case REAL: {
-
+ case FLOAT: {
static const Type valid[] = {
BOOL,
INT,
@@ -237,7 +230,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case STRING: {
-
static const Type invalid[] = {
OBJECT,
NIL
@@ -245,8 +237,43 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
invalid_types = invalid;
} break;
- case TRANSFORM2D: {
+ case VECTOR2: {
+ static const Type valid[] = {
+ VECTOR2I,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
+ case VECTOR2I: {
+ static const Type valid[] = {
+ VECTOR2,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
+ case RECT2: {
+ static const Type valid[] = {
+ RECT2I,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
+ case RECT2I: {
+ static const Type valid[] = {
+ RECT2,
+ NIL,
+ };
+
+ valid_types = valid;
+ } break;
+ case TRANSFORM2D: {
static const Type valid[] = {
TRANSFORM,
NIL
@@ -254,8 +281,26 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
- case QUAT: {
+ case VECTOR3: {
+ static const Type valid[] = {
+ VECTOR3I,
+ NIL,
+ };
+
+ valid_types = valid;
+ } break;
+ case VECTOR3I: {
+ static const Type valid[] = {
+ VECTOR3,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
+
+ case QUAT: {
static const Type valid[] = {
BASIS,
NIL
@@ -265,7 +310,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case BASIS: {
-
static const Type valid[] = {
QUAT,
VECTOR3,
@@ -276,7 +320,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case TRANSFORM: {
-
static const Type valid[] = {
TRANSFORM2D,
QUAT,
@@ -289,7 +332,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case COLOR: {
-
static const Type valid[] = {
STRING,
INT,
@@ -301,7 +343,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case _RID: {
-
static const Type valid[] = {
OBJECT,
NIL
@@ -310,15 +351,21 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case OBJECT: {
+ static const Type valid[] = {
+ NIL
+ };
+ valid_types = valid;
+ } break;
+ case STRING_NAME: {
static const Type valid[] = {
+ STRING,
NIL
};
valid_types = valid;
} break;
case NODE_PATH: {
-
static const Type valid[] = {
STRING,
NIL
@@ -327,23 +374,23 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case ARRAY: {
-
static const Type valid[] = {
- POOL_BYTE_ARRAY,
- POOL_INT_ARRAY,
- POOL_STRING_ARRAY,
- POOL_REAL_ARRAY,
- POOL_COLOR_ARRAY,
- POOL_VECTOR2_ARRAY,
- POOL_VECTOR3_ARRAY,
+ PACKED_BYTE_ARRAY,
+ PACKED_INT32_ARRAY,
+ PACKED_INT64_ARRAY,
+ PACKED_FLOAT32_ARRAY,
+ PACKED_FLOAT64_ARRAY,
+ PACKED_STRING_ARRAY,
+ PACKED_COLOR_ARRAY,
+ PACKED_VECTOR2_ARRAY,
+ PACKED_VECTOR3_ARRAY,
NIL
};
valid_types = valid;
} break;
// arrays
- case POOL_BYTE_ARRAY: {
-
+ case PACKED_BYTE_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
@@ -351,16 +398,21 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
- case POOL_INT_ARRAY: {
-
+ case PACKED_INT32_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
};
valid_types = valid;
} break;
- case POOL_REAL_ARRAY: {
-
+ case PACKED_INT64_ARRAY: {
+ static const Type valid[] = {
+ ARRAY,
+ NIL
+ };
+ valid_types = valid;
+ } break;
+ case PACKED_FLOAT32_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
@@ -368,16 +420,22 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
- case POOL_STRING_ARRAY: {
+ case PACKED_FLOAT64_ARRAY: {
+ static const Type valid[] = {
+ ARRAY,
+ NIL
+ };
+ valid_types = valid;
+ } break;
+ case PACKED_STRING_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
};
valid_types = valid;
} break;
- case POOL_VECTOR2_ARRAY: {
-
+ case PACKED_VECTOR2_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
@@ -385,8 +443,7 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
- case POOL_VECTOR3_ARRAY: {
-
+ case PACKED_VECTOR3_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
@@ -394,8 +451,7 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
- case POOL_COLOR_ARRAY: {
-
+ case PACKED_COLOR_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
@@ -409,22 +465,20 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
}
if (valid_types) {
-
int i = 0;
while (valid_types[i] != NIL) {
-
- if (p_type_from == valid_types[i])
+ if (p_type_from == valid_types[i]) {
return true;
+ }
i++;
}
} else if (invalid_types) {
-
int i = 0;
while (invalid_types[i] != NIL) {
-
- if (p_type_from == invalid_types[i])
+ if (p_type_from == invalid_types[i]) {
return false;
+ }
i++;
}
@@ -435,24 +489,24 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
}
bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type_to) {
-
- if (p_type_from == p_type_to)
+ if (p_type_from == p_type_to) {
return true;
- if (p_type_to == NIL && p_type_from != NIL) //nil can convert to anything
+ }
+ if (p_type_to == NIL && p_type_from != NIL) { //nil can convert to anything
return true;
+ }
if (p_type_from == NIL) {
return (p_type_to == OBJECT);
- };
+ }
- const Type *valid_types = NULL;
+ const Type *valid_types = nullptr;
switch (p_type_to) {
case BOOL: {
-
static const Type valid[] = {
INT,
- REAL,
+ FLOAT,
//STRING,
NIL,
};
@@ -460,10 +514,9 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case INT: {
-
static const Type valid[] = {
BOOL,
- REAL,
+ FLOAT,
//STRING,
NIL,
};
@@ -471,8 +524,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
- case REAL: {
-
+ case FLOAT: {
static const Type valid[] = {
BOOL,
INT,
@@ -484,16 +536,51 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case STRING: {
-
static const Type valid[] = {
NODE_PATH,
+ STRING_NAME,
NIL
};
valid_types = valid;
} break;
- case TRANSFORM2D: {
+ case VECTOR2: {
+ static const Type valid[] = {
+ VECTOR2I,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
+ case VECTOR2I: {
+ static const Type valid[] = {
+ VECTOR2,
+ NIL,
+ };
+ valid_types = valid;
+
+ } break;
+ case RECT2: {
+ static const Type valid[] = {
+ RECT2I,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
+ case RECT2I: {
+ static const Type valid[] = {
+ RECT2,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
+ case TRANSFORM2D: {
static const Type valid[] = {
TRANSFORM,
NIL
@@ -501,8 +588,26 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
- case QUAT: {
+ case VECTOR3: {
+ static const Type valid[] = {
+ VECTOR3I,
+ NIL,
+ };
+ valid_types = valid;
+
+ } break;
+ case VECTOR3I: {
+ static const Type valid[] = {
+ VECTOR3,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
+
+ case QUAT: {
static const Type valid[] = {
BASIS,
NIL
@@ -512,7 +617,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case BASIS: {
-
static const Type valid[] = {
QUAT,
VECTOR3,
@@ -523,7 +627,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case TRANSFORM: {
-
static const Type valid[] = {
TRANSFORM2D,
QUAT,
@@ -536,7 +639,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case COLOR: {
-
static const Type valid[] = {
STRING,
INT,
@@ -548,7 +650,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case _RID: {
-
static const Type valid[] = {
OBJECT,
NIL
@@ -557,15 +658,21 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case OBJECT: {
+ static const Type valid[] = {
+ NIL
+ };
+ valid_types = valid;
+ } break;
+ case STRING_NAME: {
static const Type valid[] = {
+ STRING,
NIL
};
valid_types = valid;
} break;
case NODE_PATH: {
-
static const Type valid[] = {
STRING,
NIL
@@ -574,23 +681,23 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case ARRAY: {
-
static const Type valid[] = {
- POOL_BYTE_ARRAY,
- POOL_INT_ARRAY,
- POOL_STRING_ARRAY,
- POOL_REAL_ARRAY,
- POOL_COLOR_ARRAY,
- POOL_VECTOR2_ARRAY,
- POOL_VECTOR3_ARRAY,
+ PACKED_BYTE_ARRAY,
+ PACKED_INT32_ARRAY,
+ PACKED_INT64_ARRAY,
+ PACKED_FLOAT32_ARRAY,
+ PACKED_FLOAT64_ARRAY,
+ PACKED_STRING_ARRAY,
+ PACKED_COLOR_ARRAY,
+ PACKED_VECTOR2_ARRAY,
+ PACKED_VECTOR3_ARRAY,
NIL
};
valid_types = valid;
} break;
// arrays
- case POOL_BYTE_ARRAY: {
-
+ case PACKED_BYTE_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
@@ -598,16 +705,21 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
- case POOL_INT_ARRAY: {
-
+ case PACKED_INT32_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
};
valid_types = valid;
} break;
- case POOL_REAL_ARRAY: {
-
+ case PACKED_INT64_ARRAY: {
+ static const Type valid[] = {
+ ARRAY,
+ NIL
+ };
+ valid_types = valid;
+ } break;
+ case PACKED_FLOAT32_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
@@ -615,16 +727,22 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
- case POOL_STRING_ARRAY: {
+ case PACKED_FLOAT64_ARRAY: {
+ static const Type valid[] = {
+ ARRAY,
+ NIL
+ };
+ valid_types = valid;
+ } break;
+ case PACKED_STRING_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
};
valid_types = valid;
} break;
- case POOL_VECTOR2_ARRAY: {
-
+ case PACKED_VECTOR2_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
@@ -632,8 +750,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
- case POOL_VECTOR3_ARRAY: {
-
+ case PACKED_VECTOR3_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
@@ -641,8 +758,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
- case POOL_COLOR_ARRAY: {
-
+ case PACKED_COLOR_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
@@ -656,12 +772,11 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
}
if (valid_types) {
-
int i = 0;
while (valid_types[i] != NIL) {
-
- if (p_type_from == valid_types[i])
+ if (p_type_from == valid_types[i]) {
return true;
+ }
i++;
}
}
@@ -670,9 +785,9 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
}
bool Variant::operator==(const Variant &p_variant) const {
-
- if (type != p_variant.type) //evaluation of operator== needs to be more strict
+ if (type != p_variant.type) { //evaluation of operator== needs to be more strict
return false;
+ }
bool v;
Variant r;
evaluate(OP_EQUAL, *this, p_variant, r, v);
@@ -680,9 +795,9 @@ bool Variant::operator==(const Variant &p_variant) const {
}
bool Variant::operator!=(const Variant &p_variant) const {
-
- if (type != p_variant.type) //evaluation of operator== needs to be more strict
+ 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);
@@ -690,8 +805,9 @@ bool Variant::operator!=(const Variant &p_variant) const {
}
bool Variant::operator<(const Variant &p_variant) const {
- if (type != p_variant.type) //if types differ, then order by type first
+ if (type != p_variant.type) { //if types differ, then order by type first
return type < p_variant.type;
+ }
bool v;
Variant r;
evaluate(OP_LESS, *this, p_variant, r, v);
@@ -699,149 +815,146 @@ bool Variant::operator<(const Variant &p_variant) const {
}
bool Variant::is_zero() const {
-
switch (type) {
case NIL: {
-
return true;
} break;
// atomic types
case BOOL: {
-
return !(_data._bool);
} break;
case INT: {
-
return _data._int == 0;
} break;
- case REAL: {
-
- return _data._real == 0;
+ case FLOAT: {
+ return _data._float == 0;
} break;
case STRING: {
-
return *reinterpret_cast<const String *>(_data._mem) == String();
} break;
// math types
case VECTOR2: {
-
return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2();
} break;
- case RECT2: {
+ case VECTOR2I: {
+ return *reinterpret_cast<const Vector2i *>(_data._mem) == Vector2i();
+ } break;
+ case RECT2: {
return *reinterpret_cast<const Rect2 *>(_data._mem) == Rect2();
} break;
- case TRANSFORM2D: {
+ case RECT2I: {
+ return *reinterpret_cast<const Rect2i *>(_data._mem) == Rect2i();
+ } break;
+ case TRANSFORM2D: {
return *_data._transform2d == Transform2D();
} break;
case VECTOR3: {
-
return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3();
} break;
- case PLANE: {
+ case VECTOR3I: {
+ return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i();
+ } break;
+ case PLANE: {
return *reinterpret_cast<const Plane *>(_data._mem) == Plane();
} break;
- /*
- case QUAT: {
-
-
- } break;*/
case AABB: {
-
return *_data._aabb == ::AABB();
} break;
case QUAT: {
-
return *reinterpret_cast<const Quat *>(_data._mem) == Quat();
} break;
case BASIS: {
-
return *_data._basis == Basis();
} break;
case TRANSFORM: {
-
return *_data._transform == Transform();
} break;
// misc types
case COLOR: {
-
return *reinterpret_cast<const Color *>(_data._mem) == Color();
} break;
case _RID: {
-
return *reinterpret_cast<const RID *>(_data._mem) == RID();
} break;
case OBJECT: {
+ return _get_obj().obj == nullptr;
+ } break;
+ case CALLABLE: {
+ return reinterpret_cast<const Callable *>(_data._mem)->is_null();
+ } break;
+ case SIGNAL: {
+ return reinterpret_cast<const Signal *>(_data._mem)->is_null();
+ } break;
+ case STRING_NAME: {
+ return *reinterpret_cast<const StringName *>(_data._mem) != StringName();
- return _get_obj().obj == NULL;
} break;
case NODE_PATH: {
-
return reinterpret_cast<const NodePath *>(_data._mem)->is_empty();
} break;
case DICTIONARY: {
-
return reinterpret_cast<const Dictionary *>(_data._mem)->empty();
} break;
case ARRAY: {
-
return reinterpret_cast<const Array *>(_data._mem)->empty();
} break;
// arrays
- case POOL_BYTE_ARRAY: {
-
- return reinterpret_cast<const PoolVector<uint8_t> *>(_data._mem)->size() == 0;
+ case PACKED_BYTE_ARRAY: {
+ return PackedArrayRef<uint8_t>::get_array(_data.packed_array).size() == 0;
} break;
- case POOL_INT_ARRAY: {
-
- return reinterpret_cast<const PoolVector<int> *>(_data._mem)->size() == 0;
+ case PACKED_INT32_ARRAY: {
+ return PackedArrayRef<int32_t>::get_array(_data.packed_array).size() == 0;
} break;
- case POOL_REAL_ARRAY: {
-
- return reinterpret_cast<const PoolVector<real_t> *>(_data._mem)->size() == 0;
+ case PACKED_INT64_ARRAY: {
+ return PackedArrayRef<int64_t>::get_array(_data.packed_array).size() == 0;
} break;
- case POOL_STRING_ARRAY: {
-
- return reinterpret_cast<const PoolVector<String> *>(_data._mem)->size() == 0;
+ case PACKED_FLOAT32_ARRAY: {
+ return PackedArrayRef<float>::get_array(_data.packed_array).size() == 0;
} break;
- case POOL_VECTOR2_ARRAY: {
-
- return reinterpret_cast<const PoolVector<Vector2> *>(_data._mem)->size() == 0;
+ case PACKED_FLOAT64_ARRAY: {
+ return PackedArrayRef<double>::get_array(_data.packed_array).size() == 0;
} break;
- case POOL_VECTOR3_ARRAY: {
+ case PACKED_STRING_ARRAY: {
+ return PackedArrayRef<String>::get_array(_data.packed_array).size() == 0;
- return reinterpret_cast<const PoolVector<Vector3> *>(_data._mem)->size() == 0;
+ } break;
+ case PACKED_VECTOR2_ARRAY: {
+ return PackedArrayRef<Vector2>::get_array(_data.packed_array).size() == 0;
} break;
- case POOL_COLOR_ARRAY: {
+ case PACKED_VECTOR3_ARRAY: {
+ return PackedArrayRef<Vector3>::get_array(_data.packed_array).size() == 0;
- return reinterpret_cast<const PoolVector<Color> *>(_data._mem)->size() == 0;
+ } break;
+ case PACKED_COLOR_ARRAY: {
+ return PackedArrayRef<Color>::get_array(_data.packed_array).size() == 0;
} break;
default: {
@@ -852,50 +965,52 @@ bool Variant::is_zero() const {
}
bool Variant::is_one() const {
-
switch (type) {
case NIL: {
-
return true;
} break;
// atomic types
case BOOL: {
-
return _data._bool;
} break;
case INT: {
-
return _data._int == 1;
} break;
- case REAL: {
-
- return _data._real == 1;
+ case FLOAT: {
+ return _data._float == 1;
} break;
case VECTOR2: {
-
return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2(1, 1);
} break;
- case RECT2: {
+ case VECTOR2I: {
+ return *reinterpret_cast<const Vector2i *>(_data._mem) == Vector2i(1, 1);
+ } break;
+ case RECT2: {
return *reinterpret_cast<const Rect2 *>(_data._mem) == Rect2(1, 1, 1, 1);
} break;
- case VECTOR3: {
+ case RECT2I: {
+ return *reinterpret_cast<const Rect2i *>(_data._mem) == Rect2i(1, 1, 1, 1);
+ } break;
+ case VECTOR3: {
return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3(1, 1, 1);
} break;
- case PLANE: {
+ case VECTOR3I: {
+ return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i(1, 1, 1);
+ } break;
+ case PLANE: {
return *reinterpret_cast<const Plane *>(_data._mem) == Plane(1, 1, 1, 1);
} break;
case COLOR: {
-
return *reinterpret_cast<const Color *>(_data._mem) == Color(1, 1, 1, 1);
} break;
@@ -908,13 +1023,20 @@ bool Variant::is_one() const {
return false;
}
-void Variant::reference(const Variant &p_variant) {
+bool Variant::is_null() const {
+ if (type == OBJECT && _get_obj().obj) {
+ return false;
+ } else {
+ return true;
+ }
+}
+void Variant::reference(const Variant &p_variant) {
switch (type) {
case NIL:
case BOOL:
case INT:
- case REAL:
+ case FLOAT:
break;
default:
clear();
@@ -924,133 +1046,173 @@ void Variant::reference(const Variant &p_variant) {
switch (p_variant.type) {
case NIL: {
-
// none
} break;
// atomic types
case BOOL: {
-
_data._bool = p_variant._data._bool;
} break;
case INT: {
-
_data._int = p_variant._data._int;
} break;
- case REAL: {
-
- _data._real = p_variant._data._real;
+ case FLOAT: {
+ _data._float = p_variant._data._float;
} break;
case STRING: {
-
memnew_placement(_data._mem, String(*reinterpret_cast<const String *>(p_variant._data._mem)));
} break;
// math types
case VECTOR2: {
-
memnew_placement(_data._mem, Vector2(*reinterpret_cast<const Vector2 *>(p_variant._data._mem)));
} break;
+ case VECTOR2I: {
+ memnew_placement(_data._mem, Vector2i(*reinterpret_cast<const Vector2i *>(p_variant._data._mem)));
+ } break;
case RECT2: {
-
memnew_placement(_data._mem, Rect2(*reinterpret_cast<const Rect2 *>(p_variant._data._mem)));
} break;
+ case RECT2I: {
+ memnew_placement(_data._mem, Rect2i(*reinterpret_cast<const Rect2i *>(p_variant._data._mem)));
+ } break;
case TRANSFORM2D: {
-
_data._transform2d = memnew(Transform2D(*p_variant._data._transform2d));
} break;
case VECTOR3: {
-
memnew_placement(_data._mem, Vector3(*reinterpret_cast<const Vector3 *>(p_variant._data._mem)));
} break;
+ case VECTOR3I: {
+ memnew_placement(_data._mem, Vector3i(*reinterpret_cast<const Vector3i *>(p_variant._data._mem)));
+ } break;
case PLANE: {
-
memnew_placement(_data._mem, Plane(*reinterpret_cast<const Plane *>(p_variant._data._mem)));
} break;
case AABB: {
-
_data._aabb = memnew(::AABB(*p_variant._data._aabb));
} break;
case QUAT: {
-
memnew_placement(_data._mem, Quat(*reinterpret_cast<const Quat *>(p_variant._data._mem)));
} break;
case BASIS: {
-
_data._basis = memnew(Basis(*p_variant._data._basis));
} break;
case TRANSFORM: {
-
_data._transform = memnew(Transform(*p_variant._data._transform));
} break;
// misc types
case COLOR: {
-
memnew_placement(_data._mem, Color(*reinterpret_cast<const Color *>(p_variant._data._mem)));
} break;
case _RID: {
-
memnew_placement(_data._mem, RID(*reinterpret_cast<const RID *>(p_variant._data._mem)));
} break;
case OBJECT: {
+ memnew_placement(_data._mem, ObjData);
+
+ if (p_variant._get_obj().obj && p_variant._get_obj().id.is_reference()) {
+ Reference *reference = static_cast<Reference *>(p_variant._get_obj().obj);
+ if (!reference->reference()) {
+ _get_obj().obj = nullptr;
+ _get_obj().id = ObjectID();
+ break;
+ }
+ }
+
+ _get_obj().obj = const_cast<Object *>(p_variant._get_obj().obj);
+ _get_obj().id = p_variant._get_obj().id;
- memnew_placement(_data._mem, ObjData(p_variant._get_obj()));
} break;
- case NODE_PATH: {
+ case CALLABLE: {
+ memnew_placement(_data._mem, Callable(*reinterpret_cast<const Callable *>(p_variant._data._mem)));
+ } break;
+ case SIGNAL: {
+ memnew_placement(_data._mem, Signal(*reinterpret_cast<const Signal *>(p_variant._data._mem)));
+ } break;
+ case STRING_NAME: {
+ memnew_placement(_data._mem, StringName(*reinterpret_cast<const StringName *>(p_variant._data._mem)));
+ } break;
+ case NODE_PATH: {
memnew_placement(_data._mem, NodePath(*reinterpret_cast<const NodePath *>(p_variant._data._mem)));
} break;
case DICTIONARY: {
-
memnew_placement(_data._mem, Dictionary(*reinterpret_cast<const Dictionary *>(p_variant._data._mem)));
} break;
case ARRAY: {
-
memnew_placement(_data._mem, Array(*reinterpret_cast<const Array *>(p_variant._data._mem)));
} break;
// arrays
- case POOL_BYTE_ARRAY: {
-
- memnew_placement(_data._mem, PoolVector<uint8_t>(*reinterpret_cast<const PoolVector<uint8_t> *>(p_variant._data._mem)));
+ case PACKED_BYTE_ARRAY: {
+ _data.packed_array = static_cast<PackedArrayRef<uint8_t> *>(p_variant._data.packed_array)->reference();
+ if (!_data.packed_array) {
+ _data.packed_array = PackedArrayRef<uint8_t>::create();
+ }
} break;
- case POOL_INT_ARRAY: {
-
- memnew_placement(_data._mem, PoolVector<int>(*reinterpret_cast<const PoolVector<int> *>(p_variant._data._mem)));
+ case PACKED_INT32_ARRAY: {
+ _data.packed_array = static_cast<PackedArrayRef<int32_t> *>(p_variant._data.packed_array)->reference();
+ if (!_data.packed_array) {
+ _data.packed_array = PackedArrayRef<int32_t>::create();
+ }
} break;
- case POOL_REAL_ARRAY: {
-
- memnew_placement(_data._mem, PoolVector<real_t>(*reinterpret_cast<const PoolVector<real_t> *>(p_variant._data._mem)));
+ case PACKED_INT64_ARRAY: {
+ _data.packed_array = static_cast<PackedArrayRef<int64_t> *>(p_variant._data.packed_array)->reference();
+ if (!_data.packed_array) {
+ _data.packed_array = PackedArrayRef<int64_t>::create();
+ }
} break;
- case POOL_STRING_ARRAY: {
-
- memnew_placement(_data._mem, PoolVector<String>(*reinterpret_cast<const PoolVector<String> *>(p_variant._data._mem)));
+ case PACKED_FLOAT32_ARRAY: {
+ _data.packed_array = static_cast<PackedArrayRef<float> *>(p_variant._data.packed_array)->reference();
+ if (!_data.packed_array) {
+ _data.packed_array = PackedArrayRef<float>::create();
+ }
} break;
- case POOL_VECTOR2_ARRAY: {
-
- memnew_placement(_data._mem, PoolVector<Vector2>(*reinterpret_cast<const PoolVector<Vector2> *>(p_variant._data._mem)));
+ case PACKED_FLOAT64_ARRAY: {
+ _data.packed_array = static_cast<PackedArrayRef<double> *>(p_variant._data.packed_array)->reference();
+ if (!_data.packed_array) {
+ _data.packed_array = PackedArrayRef<double>::create();
+ }
} break;
- case POOL_VECTOR3_ARRAY: {
+ case PACKED_STRING_ARRAY: {
+ _data.packed_array = static_cast<PackedArrayRef<String> *>(p_variant._data.packed_array)->reference();
+ if (!_data.packed_array) {
+ _data.packed_array = PackedArrayRef<String>::create();
+ }
- memnew_placement(_data._mem, PoolVector<Vector3>(*reinterpret_cast<const PoolVector<Vector3> *>(p_variant._data._mem)));
+ } break;
+ case PACKED_VECTOR2_ARRAY: {
+ _data.packed_array = static_cast<PackedArrayRef<Vector2> *>(p_variant._data.packed_array)->reference();
+ if (!_data.packed_array) {
+ _data.packed_array = PackedArrayRef<Vector2>::create();
+ }
} break;
- case POOL_COLOR_ARRAY: {
+ case PACKED_VECTOR3_ARRAY: {
+ _data.packed_array = static_cast<PackedArrayRef<Vector3> *>(p_variant._data.packed_array)->reference();
+ if (!_data.packed_array) {
+ _data.packed_array = PackedArrayRef<Vector3>::create();
+ }
- memnew_placement(_data._mem, PoolVector<Color>(*reinterpret_cast<const PoolVector<Color> *>(p_variant._data._mem)));
+ } break;
+ case PACKED_COLOR_ARRAY: {
+ _data.packed_array = static_cast<PackedArrayRef<Color> *>(p_variant._data.packed_array)->reference();
+ if (!_data.packed_array) {
+ _data.packed_array = PackedArrayRef<Color>::create();
+ }
} break;
default: {
@@ -1060,25 +1222,53 @@ void Variant::reference(const Variant &p_variant) {
void Variant::zero() {
switch (type) {
- case NIL: break;
- case BOOL: this->_data._bool = false; break;
- case INT: this->_data._int = 0; break;
- case REAL: this->_data._real = 0; break;
- case VECTOR2: *reinterpret_cast<Vector2 *>(this->_data._mem) = Vector2(); break;
- case RECT2: *reinterpret_cast<Rect2 *>(this->_data._mem) = Rect2(); break;
- case VECTOR3: *reinterpret_cast<Vector3 *>(this->_data._mem) = Vector3(); break;
- case PLANE: *reinterpret_cast<Plane *>(this->_data._mem) = Plane(); break;
- case QUAT: *reinterpret_cast<Quat *>(this->_data._mem) = Quat(); break;
- case COLOR: *reinterpret_cast<Color *>(this->_data._mem) = Color(); break;
- default: this->clear(); break;
+ case NIL:
+ break;
+ case BOOL:
+ this->_data._bool = false;
+ break;
+ case INT:
+ this->_data._int = 0;
+ break;
+ case FLOAT:
+ this->_data._float = 0;
+ break;
+ case VECTOR2:
+ *reinterpret_cast<Vector2 *>(this->_data._mem) = Vector2();
+ break;
+ case VECTOR2I:
+ *reinterpret_cast<Vector2i *>(this->_data._mem) = Vector2i();
+ break;
+ case RECT2:
+ *reinterpret_cast<Rect2 *>(this->_data._mem) = Rect2();
+ break;
+ case RECT2I:
+ *reinterpret_cast<Rect2i *>(this->_data._mem) = Rect2i();
+ break;
+ case VECTOR3:
+ *reinterpret_cast<Vector3 *>(this->_data._mem) = Vector3();
+ break;
+ case VECTOR3I:
+ *reinterpret_cast<Vector3i *>(this->_data._mem) = Vector3i();
+ break;
+ case PLANE:
+ *reinterpret_cast<Plane *>(this->_data._mem) = Plane();
+ break;
+ case QUAT:
+ *reinterpret_cast<Quat *>(this->_data._mem) = Quat();
+ break;
+ case COLOR:
+ *reinterpret_cast<Color *>(this->_data._mem) = Color();
+ break;
+ default:
+ this->clear();
+ break;
}
}
void Variant::clear() {
-
switch (type) {
case STRING: {
-
reinterpret_cast<String *>(_data._mem)->~String();
} break;
/*
@@ -1089,74 +1279,81 @@ void Variant::clear() {
COLOR,
VECTOR2,
RECT2
- */
+ */
case TRANSFORM2D: {
-
memdelete(_data._transform2d);
} break;
case AABB: {
-
memdelete(_data._aabb);
} break;
case BASIS: {
-
memdelete(_data._basis);
} break;
case TRANSFORM: {
-
memdelete(_data._transform);
} break;
- // misc types
+ // misc types
+ case STRING_NAME: {
+ reinterpret_cast<StringName *>(_data._mem)->~StringName();
+ } break;
case NODE_PATH: {
-
reinterpret_cast<NodePath *>(_data._mem)->~NodePath();
} break;
case OBJECT: {
-
- _get_obj().obj = NULL;
- _get_obj().ref.unref();
+ if (_get_obj().id.is_reference()) {
+ //we are safe that there is a reference here
+ Reference *reference = static_cast<Reference *>(_get_obj().obj);
+ if (reference->unreference()) {
+ memdelete(reference);
+ }
+ }
+ _get_obj().obj = nullptr;
+ _get_obj().id = ObjectID();
} break;
case _RID: {
// not much need probably
reinterpret_cast<RID *>(_data._mem)->~RID();
} break;
+ case CALLABLE: {
+ reinterpret_cast<Callable *>(_data._mem)->~Callable();
+ } break;
+ case SIGNAL: {
+ reinterpret_cast<Signal *>(_data._mem)->~Signal();
+ } break;
case DICTIONARY: {
-
reinterpret_cast<Dictionary *>(_data._mem)->~Dictionary();
} break;
case ARRAY: {
-
reinterpret_cast<Array *>(_data._mem)->~Array();
} break;
// arrays
- case POOL_BYTE_ARRAY: {
-
- reinterpret_cast<PoolVector<uint8_t> *>(_data._mem)->~PoolVector<uint8_t>();
+ case PACKED_BYTE_ARRAY: {
+ PackedArrayRefBase::destroy(_data.packed_array);
} break;
- case POOL_INT_ARRAY: {
-
- reinterpret_cast<PoolVector<int> *>(_data._mem)->~PoolVector<int>();
+ case PACKED_INT32_ARRAY: {
+ PackedArrayRefBase::destroy(_data.packed_array);
} break;
- case POOL_REAL_ARRAY: {
-
- reinterpret_cast<PoolVector<real_t> *>(_data._mem)->~PoolVector<real_t>();
+ case PACKED_INT64_ARRAY: {
+ PackedArrayRefBase::destroy(_data.packed_array);
} break;
- case POOL_STRING_ARRAY: {
-
- reinterpret_cast<PoolVector<String> *>(_data._mem)->~PoolVector<String>();
+ case PACKED_FLOAT32_ARRAY: {
+ PackedArrayRefBase::destroy(_data.packed_array);
} break;
- case POOL_VECTOR2_ARRAY: {
-
- reinterpret_cast<PoolVector<Vector2> *>(_data._mem)->~PoolVector<Vector2>();
+ case PACKED_FLOAT64_ARRAY: {
+ PackedArrayRefBase::destroy(_data.packed_array);
} break;
- case POOL_VECTOR3_ARRAY: {
-
- reinterpret_cast<PoolVector<Vector3> *>(_data._mem)->~PoolVector<Vector3>();
+ case PACKED_STRING_ARRAY: {
+ PackedArrayRefBase::destroy(_data.packed_array);
} break;
- case POOL_COLOR_ARRAY: {
-
- reinterpret_cast<PoolVector<Color> *>(_data._mem)->~PoolVector<Color>();
+ case PACKED_VECTOR2_ARRAY: {
+ PackedArrayRefBase::destroy(_data.packed_array);
+ } break;
+ case PACKED_VECTOR3_ARRAY: {
+ PackedArrayRefBase::destroy(_data.packed_array);
+ } break;
+ case PACKED_COLOR_ARRAY: {
+ PackedArrayRefBase::destroy(_data.packed_array);
} break;
default: {
} /* not needed */
@@ -1166,238 +1363,256 @@ void Variant::clear() {
}
Variant::operator signed int() const {
-
switch (type) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
-
return 0;
}
}
}
-Variant::operator unsigned int() const {
+Variant::operator unsigned int() const {
switch (type) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
-
return 0;
}
}
}
Variant::operator int64_t() const {
-
switch (type) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_int64();
- default: {
-
+ case NIL:
return 0;
- }
- }
-}
-
-/*
-Variant::operator long unsigned int() const {
-
- switch( type ) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_int();
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
-
return 0;
}
}
-
- return 0;
-};
-*/
+}
Variant::operator uint64_t() const {
-
switch (type) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
-
return 0;
}
}
}
+Variant::operator ObjectID() const {
+ if (type == INT) {
+ return ObjectID(_data._int);
+ } else if (type == OBJECT) {
+ return _get_obj().id;
+ } else {
+ return ObjectID();
+ }
+}
+
#ifdef NEED_LONG_INT
Variant::operator signed long() const {
-
switch (type) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
-
return 0;
}
}
return 0;
-};
+}
Variant::operator unsigned long() const {
-
switch (type) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
-
return 0;
}
}
return 0;
-};
+}
#endif
Variant::operator signed short() const {
-
switch (type) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
-
return 0;
}
}
}
-Variant::operator unsigned short() const {
+Variant::operator unsigned short() const {
switch (type) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
-
return 0;
}
}
}
-Variant::operator signed char() const {
+Variant::operator signed char() const {
switch (type) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
-
return 0;
}
}
}
-Variant::operator unsigned char() const {
+Variant::operator unsigned char() const {
switch (type) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
-
return 0;
}
}
}
-Variant::operator CharType() const {
-
+Variant::operator char32_t() const {
return operator unsigned int();
}
Variant::operator float() const {
-
switch (type) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1.0 : 0.0;
- case INT: return (float)_data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_double();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1.0 : 0.0;
+ case INT:
+ return (float)_data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_float();
default: {
-
return 0;
}
}
}
-Variant::operator double() const {
+Variant::operator double() const {
switch (type) {
-
- case NIL: return 0;
- case BOOL: return _data._bool ? 1.0 : 0.0;
- case INT: return (double)_data._int;
- case REAL: return _data._real;
- case STRING: return operator String().to_double();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1.0 : 0.0;
+ case INT:
+ return (double)_data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_float();
default: {
-
return 0;
}
}
}
Variant::operator StringName() const {
-
- if (type == NODE_PATH) {
- return reinterpret_cast<const NodePath *>(_data._mem)->get_sname();
+ if (type == STRING_NAME) {
+ return *reinterpret_cast<const StringName *>(_data._mem);
+ } else if (type == STRING) {
+ return *reinterpret_cast<const String *>(_data._mem);
}
- return StringName(operator String());
+
+ return StringName();
}
struct _VariantStrPair {
-
String key;
String value;
bool operator<(const _VariantStrPair &p) const {
-
return key < p.key;
}
};
@@ -1410,41 +1625,54 @@ Variant::operator String() const {
String Variant::stringify(List<const void *> &stack) const {
switch (type) {
-
- case NIL: return "Null";
- case BOOL: return _data._bool ? "True" : "False";
- case INT: return itos(_data._int);
- case REAL: return rtos(_data._real);
- case STRING: return *reinterpret_cast<const String *>(_data._mem);
- case VECTOR2: return "(" + operator Vector2() + ")";
- case RECT2: return "(" + operator Rect2() + ")";
+ case NIL:
+ return "Null";
+ case BOOL:
+ return _data._bool ? "True" : "False";
+ case INT:
+ return itos(_data._int);
+ case FLOAT:
+ return rtos(_data._float);
+ case STRING:
+ return *reinterpret_cast<const String *>(_data._mem);
+ case VECTOR2:
+ return "(" + operator Vector2() + ")";
+ case VECTOR2I:
+ return "(" + operator Vector2i() + ")";
+ case RECT2:
+ return "(" + operator Rect2() + ")";
+ case RECT2I:
+ return "(" + operator Rect2i() + ")";
case TRANSFORM2D: {
-
Transform2D mat32 = operator Transform2D();
return "(" + Variant(mat32.elements[0]).operator String() + ", " + Variant(mat32.elements[1]).operator String() + ", " + Variant(mat32.elements[2]).operator String() + ")";
} break;
- case VECTOR3: return "(" + operator Vector3() + ")";
+ case VECTOR3:
+ return "(" + operator Vector3() + ")";
+ case VECTOR3I:
+ return "(" + operator Vector3i() + ")";
case PLANE:
return operator Plane();
//case QUAT:
- case AABB: return operator ::AABB();
- case QUAT: return "(" + operator Quat() + ")";
+ case AABB:
+ return operator ::AABB();
+ case QUAT:
+ return "(" + operator Quat() + ")";
case BASIS: {
-
Basis mat3 = operator Basis();
String mtx("(");
for (int i = 0; i < 3; i++) {
-
- if (i != 0)
+ if (i != 0) {
mtx += ", ";
+ }
mtx += "(";
for (int j = 0; j < 3; j++) {
-
- if (j != 0)
+ if (j != 0) {
mtx += ", ";
+ }
mtx += Variant(mat3.elements[i][j]).operator String();
}
@@ -1454,11 +1682,15 @@ String Variant::stringify(List<const void *> &stack) const {
return mtx + ")";
} break;
- case TRANSFORM: return operator Transform();
- case NODE_PATH: return operator NodePath();
- case COLOR: return String::num(operator Color().r) + "," + String::num(operator Color().g) + "," + String::num(operator Color().b) + "," + String::num(operator Color().a);
+ case TRANSFORM:
+ return operator Transform();
+ case STRING_NAME:
+ return operator StringName();
+ case NODE_PATH:
+ return operator NodePath();
+ case COLOR:
+ return String::num(operator Color().r) + "," + String::num(operator Color().g) + "," + String::num(operator Color().b) + "," + String::num(operator Color().a);
case DICTIONARY: {
-
const Dictionary &d = *reinterpret_cast<const Dictionary *>(_data._mem);
if (stack.find(d.id())) {
return "{...}";
@@ -1466,7 +1698,7 @@ String Variant::stringify(List<const void *> &stack) const {
stack.push_back(d.id());
- //const String *K=NULL;
+ //const String *K=nullptr;
String str("{");
List<Variant> keys;
d.get_key_list(&keys);
@@ -1474,7 +1706,6 @@ String Variant::stringify(List<const void *> &stack) const {
Vector<_VariantStrPair> pairs;
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
_VariantStrPair sp;
sp.key = E->get().stringify(stack);
sp.value = d[E->get()].stringify(stack);
@@ -1485,81 +1716,100 @@ String Variant::stringify(List<const void *> &stack) const {
pairs.sort();
for (int i = 0; i < pairs.size(); i++) {
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str += pairs[i].key + ":" + pairs[i].value;
}
str += "}";
return str;
} break;
- case POOL_VECTOR2_ARRAY: {
-
- PoolVector<Vector2> vec = operator PoolVector<Vector2>();
+ case PACKED_VECTOR2_ARRAY: {
+ Vector<Vector2> vec = operator Vector<Vector2>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + Variant(vec[i]);
}
str += "]";
return str;
} break;
- case POOL_VECTOR3_ARRAY: {
-
- PoolVector<Vector3> vec = operator PoolVector<Vector3>();
+ case PACKED_VECTOR3_ARRAY: {
+ Vector<Vector3> vec = operator Vector<Vector3>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + Variant(vec[i]);
}
str += "]";
return str;
} break;
- case POOL_STRING_ARRAY: {
-
- PoolVector<String> vec = operator PoolVector<String>();
+ case PACKED_STRING_ARRAY: {
+ Vector<String> vec = operator Vector<String>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + vec[i];
}
str += "]";
return str;
} break;
- case POOL_INT_ARRAY: {
-
- PoolVector<int> vec = operator PoolVector<int>();
+ case PACKED_INT32_ARRAY: {
+ Vector<int32_t> vec = operator Vector<int32_t>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + itos(vec[i]);
}
str += "]";
return str;
} break;
- case POOL_REAL_ARRAY: {
-
- PoolVector<real_t> vec = operator PoolVector<real_t>();
+ case PACKED_INT64_ARRAY: {
+ Vector<int64_t> vec = operator Vector<int64_t>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
+ str += ", ";
+ }
+ str = str + itos(vec[i]);
+ }
+ str += "]";
+ return str;
+ } break;
+ case PACKED_FLOAT32_ARRAY: {
+ Vector<float> vec = operator Vector<float>();
+ String str("[");
+ for (int i = 0; i < vec.size(); i++) {
+ if (i > 0) {
+ str += ", ";
+ }
+ str = str + rtos(vec[i]);
+ }
+ str += "]";
+ return str;
+ } break;
+ case PACKED_FLOAT64_ARRAY: {
+ Vector<double> vec = operator Vector<double>();
+ String str("[");
+ for (int i = 0; i < vec.size(); i++) {
+ if (i > 0) {
str += ", ";
+ }
str = str + rtos(vec[i]);
}
str += "]";
return str;
} break;
case ARRAY: {
-
Array arr = operator Array();
if (stack.find(arr.id())) {
return "[...]";
@@ -1568,8 +1818,9 @@ String Variant::stringify(List<const void *> &stack) const {
String str("[");
for (int i = 0; i < arr.size(); i++) {
- if (i)
+ if (i) {
str += ", ";
+ }
str += arr[i].stringify(stack);
}
@@ -1579,21 +1830,29 @@ String Variant::stringify(List<const void *> &stack) const {
} break;
case OBJECT: {
-
if (_get_obj().obj) {
-#ifdef DEBUG_ENABLED
- if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null()) {
- //only if debugging!
- if (!ObjectDB::instance_validate(_get_obj().obj)) {
- return "[Deleted Object]";
- };
- };
-#endif
+ if (!_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
+ return "[Freed Object]";
+ }
+
return _get_obj().obj->to_string();
- } else
+ } else {
return "[Object:null]";
+ }
} break;
+ case CALLABLE: {
+ const Callable &c = *reinterpret_cast<const Callable *>(_data._mem);
+ return c;
+ } break;
+ case SIGNAL: {
+ const Signal &s = *reinterpret_cast<const Signal *>(_data._mem);
+ return s;
+ } break;
+ case _RID: {
+ const RID &s = *reinterpret_cast<const RID *>(_data._mem);
+ return "RID(" + itos(s.get_id()) + ")";
+ } break;
default: {
return "[" + get_type_name(type) + "]";
}
@@ -1603,81 +1862,131 @@ String Variant::stringify(List<const void *> &stack) const {
}
Variant::operator Vector2() const {
-
- if (type == VECTOR2)
+ if (type == VECTOR2) {
return *reinterpret_cast<const Vector2 *>(_data._mem);
- else if (type == VECTOR3)
+ } else if (type == VECTOR2I) {
+ return *reinterpret_cast<const Vector2i *>(_data._mem);
+ } else if (type == VECTOR3) {
return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y);
- else
+ } else if (type == VECTOR3I) {
+ return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y);
+ } else {
return Vector2();
+ }
}
-Variant::operator Rect2() const {
- if (type == RECT2)
+Variant::operator Vector2i() const {
+ if (type == VECTOR2I) {
+ return *reinterpret_cast<const Vector2i *>(_data._mem);
+ } else if (type == VECTOR2) {
+ return *reinterpret_cast<const Vector2 *>(_data._mem);
+ } else if (type == VECTOR3) {
+ return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y);
+ } else if (type == VECTOR3I) {
+ return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y);
+ } else {
+ return Vector2i();
+ }
+}
+
+Variant::operator Rect2() const {
+ if (type == RECT2) {
return *reinterpret_cast<const Rect2 *>(_data._mem);
- else
+ } else if (type == RECT2I) {
+ return *reinterpret_cast<const Rect2i *>(_data._mem);
+ } else {
return Rect2();
+ }
}
-Variant::operator Vector3() const {
+Variant::operator Rect2i() const {
+ if (type == RECT2I) {
+ return *reinterpret_cast<const Rect2i *>(_data._mem);
+ } else if (type == RECT2) {
+ return *reinterpret_cast<const Rect2 *>(_data._mem);
+ } else {
+ return Rect2i();
+ }
+}
- if (type == VECTOR3)
+Variant::operator Vector3() const {
+ if (type == VECTOR3) {
return *reinterpret_cast<const Vector3 *>(_data._mem);
- else if (type == VECTOR2)
+ } else if (type == VECTOR3I) {
+ return *reinterpret_cast<const Vector3i *>(_data._mem);
+ } else if (type == VECTOR2) {
return Vector3(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0);
- else
+ } else if (type == VECTOR2I) {
+ return Vector3(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0);
+ } else {
return Vector3();
+ }
}
-Variant::operator Plane() const {
- if (type == PLANE)
+Variant::operator Vector3i() const {
+ if (type == VECTOR3I) {
+ return *reinterpret_cast<const Vector3i *>(_data._mem);
+ } else if (type == VECTOR3) {
+ return *reinterpret_cast<const Vector3 *>(_data._mem);
+ } else if (type == VECTOR2) {
+ return Vector3i(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0);
+ } else if (type == VECTOR2I) {
+ return Vector3i(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0);
+ } else {
+ return Vector3i();
+ }
+}
+
+Variant::operator Plane() const {
+ if (type == PLANE) {
return *reinterpret_cast<const Plane *>(_data._mem);
- else
+ } else {
return Plane();
+ }
}
-Variant::operator ::AABB() const {
- if (type == AABB)
+Variant::operator ::AABB() const {
+ if (type == AABB) {
return *_data._aabb;
- else
+ } else {
return ::AABB();
+ }
}
Variant::operator Basis() const {
-
- if (type == BASIS)
+ if (type == BASIS) {
return *_data._basis;
- else if (type == QUAT)
+ } else if (type == QUAT) {
return *reinterpret_cast<const Quat *>(_data._mem);
- else if (type == VECTOR3) {
+ } else if (type == VECTOR3) {
return Basis(*reinterpret_cast<const Vector3 *>(_data._mem));
- } else if (type == TRANSFORM) // unexposed in Variant::can_convert?
+ } else if (type == TRANSFORM) { // unexposed in Variant::can_convert?
return _data._transform->basis;
- else
+ } else {
return Basis();
+ }
}
Variant::operator Quat() const {
-
- if (type == QUAT)
+ if (type == QUAT) {
return *reinterpret_cast<const Quat *>(_data._mem);
- else if (type == BASIS)
+ } else if (type == BASIS) {
return *_data._basis;
- else if (type == TRANSFORM)
+ } else if (type == TRANSFORM) {
return _data._transform->basis;
- else
+ } else {
return Quat();
+ }
}
Variant::operator Transform() const {
-
- if (type == TRANSFORM)
+ if (type == TRANSFORM) {
return *_data._transform;
- else if (type == BASIS)
+ } else if (type == BASIS) {
return Transform(*_data._basis, Vector3());
- else if (type == QUAT)
+ } else if (type == QUAT) {
return Transform(Basis(*reinterpret_cast<const Quat *>(_data._mem)), Vector3());
- else if (type == TRANSFORM2D) {
+ } else if (type == TRANSFORM2D) {
const Transform2D &t = *_data._transform2d;
Transform m;
m.basis.elements[0][0] = t.elements[0][0];
@@ -1687,12 +1996,12 @@ Variant::operator Transform() const {
m.origin[0] = t.elements[2][0];
m.origin[1] = t.elements[2][1];
return m;
- } else
+ } else {
return Transform();
+ }
}
Variant::operator Transform2D() const {
-
if (type == TRANSFORM2D) {
return *_data._transform2d;
} else if (type == TRANSFORM) {
@@ -1705,55 +2014,47 @@ Variant::operator Transform2D() const {
m.elements[2][0] = t.origin[0];
m.elements[2][1] = t.origin[1];
return m;
- } else
+ } else {
return Transform2D();
+ }
}
Variant::operator Color() const {
-
- if (type == COLOR)
+ if (type == COLOR) {
return *reinterpret_cast<const Color *>(_data._mem);
- else if (type == STRING)
+ } else if (type == STRING) {
return Color::html(operator String());
- else if (type == INT)
+ } else if (type == INT) {
return Color::hex(operator int());
- else
+ } else {
return Color();
+ }
}
Variant::operator NodePath() const {
-
- if (type == NODE_PATH)
+ if (type == NODE_PATH) {
return *reinterpret_cast<const NodePath *>(_data._mem);
- else if (type == STRING)
+ } else if (type == STRING) {
return NodePath(operator String());
- else
+ } else {
return NodePath();
-}
-
-Variant::operator RefPtr() const {
-
- if (type == OBJECT)
- return _get_obj().ref;
- else
- return RefPtr();
+ }
}
Variant::operator RID() const {
-
- if (type == _RID)
+ if (type == _RID) {
return *reinterpret_cast<const RID *>(_data._mem);
- else if (type == OBJECT && !_get_obj().ref.is_null()) {
- return _get_obj().ref.get_rid();
+ } else if (type == OBJECT && _get_obj().obj == nullptr) {
+ return RID();
} else if (type == OBJECT && _get_obj().obj) {
#ifdef DEBUG_ENABLED
- if (ScriptDebugger::get_singleton()) {
- ERR_FAIL_COND_V_MSG(!ObjectDB::instance_validate(_get_obj().obj), RID(), "Invalid pointer (object was deleted).");
- };
+ if (EngineDebugger::is_active()) {
+ ERR_FAIL_COND_V_MSG(ObjectDB::get_instance(_get_obj().id) == nullptr, RID(), "Invalid pointer (object was freed).");
+ }
#endif
- Variant::CallError ce;
- Variant ret = _get_obj().obj->call(CoreStringNames::get_singleton()->get_rid, NULL, 0, ce);
- if (ce.error == Variant::CallError::CALL_OK && ret.get_type() == Variant::_RID) {
+ Callable::CallError ce;
+ Variant ret = _get_obj().obj->call(CoreStringNames::get_singleton()->get_rid, nullptr, 0, ce);
+ if (ce.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::_RID) {
return ret;
}
return RID();
@@ -1763,43 +2064,78 @@ Variant::operator RID() const {
}
Variant::operator Object *() const {
-
- if (type == OBJECT)
+ if (type == OBJECT) {
return _get_obj().obj;
- else
- return NULL;
+ } else {
+ return nullptr;
+ }
+}
+
+Object *Variant::get_validated_object_with_check(bool &r_previously_freed) const {
+ if (type == OBJECT) {
+ Object *instance = ObjectDB::get_instance(_get_obj().id);
+ r_previously_freed = !instance && _get_obj().id != ObjectID();
+ return instance;
+ } else {
+ r_previously_freed = false;
+ return nullptr;
+ }
}
-Variant::operator Node *() const {
- if (type == OBJECT)
+Object *Variant::get_validated_object() const {
+ if (type == OBJECT) {
+ return ObjectDB::get_instance(_get_obj().id);
+ } else {
+ return nullptr;
+ }
+}
+
+Variant::operator Node *() const {
+ if (type == OBJECT) {
return Object::cast_to<Node>(_get_obj().obj);
- else
- return NULL;
+ } else {
+ return nullptr;
+ }
}
-Variant::operator Control *() const {
- if (type == OBJECT)
+Variant::operator Control *() const {
+ if (type == OBJECT) {
return Object::cast_to<Control>(_get_obj().obj);
- else
- return NULL;
+ } else {
+ return nullptr;
+ }
}
Variant::operator Dictionary() const {
-
- if (type == DICTIONARY)
+ if (type == DICTIONARY) {
return *reinterpret_cast<const Dictionary *>(_data._mem);
- else
+ } else {
return Dictionary();
+ }
+}
+
+Variant::operator Callable() const {
+ if (type == CALLABLE) {
+ return *reinterpret_cast<const Callable *>(_data._mem);
+ } else {
+ return Callable();
+ }
+}
+
+Variant::operator Signal() const {
+ if (type == SIGNAL) {
+ return *reinterpret_cast<const Signal *>(_data._mem);
+ } else {
+ return Signal();
+ }
}
template <class DA, class SA>
inline DA _convert_array(const SA &p_array) {
-
DA da;
da.resize(p_array.size());
for (int i = 0; i < p_array.size(); i++) {
-
da.set(i, Variant(p_array.get(i)));
}
@@ -1808,32 +2144,36 @@ inline DA _convert_array(const SA &p_array) {
template <class DA>
inline DA _convert_array_from_variant(const Variant &p_variant) {
-
switch (p_variant.get_type()) {
-
case Variant::ARRAY: {
return _convert_array<DA, Array>(p_variant.operator Array());
}
- case Variant::POOL_BYTE_ARRAY: {
- return _convert_array<DA, PoolVector<uint8_t> >(p_variant.operator PoolVector<uint8_t>());
+ case Variant::PACKED_BYTE_ARRAY: {
+ return _convert_array<DA, Vector<uint8_t>>(p_variant.operator Vector<uint8_t>());
+ }
+ case Variant::PACKED_INT32_ARRAY: {
+ return _convert_array<DA, Vector<int32_t>>(p_variant.operator Vector<int32_t>());
+ }
+ case Variant::PACKED_INT64_ARRAY: {
+ return _convert_array<DA, Vector<int64_t>>(p_variant.operator Vector<int64_t>());
}
- case Variant::POOL_INT_ARRAY: {
- return _convert_array<DA, PoolVector<int> >(p_variant.operator PoolVector<int>());
+ case Variant::PACKED_FLOAT32_ARRAY: {
+ return _convert_array<DA, Vector<float>>(p_variant.operator Vector<float>());
}
- case Variant::POOL_REAL_ARRAY: {
- return _convert_array<DA, PoolVector<real_t> >(p_variant.operator PoolVector<real_t>());
+ case Variant::PACKED_FLOAT64_ARRAY: {
+ return _convert_array<DA, Vector<double>>(p_variant.operator Vector<double>());
}
- case Variant::POOL_STRING_ARRAY: {
- return _convert_array<DA, PoolVector<String> >(p_variant.operator PoolVector<String>());
+ case Variant::PACKED_STRING_ARRAY: {
+ return _convert_array<DA, Vector<String>>(p_variant.operator Vector<String>());
}
- case Variant::POOL_VECTOR2_ARRAY: {
- return _convert_array<DA, PoolVector<Vector2> >(p_variant.operator PoolVector<Vector2>());
+ case Variant::PACKED_VECTOR2_ARRAY: {
+ return _convert_array<DA, Vector<Vector2>>(p_variant.operator Vector<Vector2>());
}
- case Variant::POOL_VECTOR3_ARRAY: {
- return _convert_array<DA, PoolVector<Vector3> >(p_variant.operator PoolVector<Vector3>());
+ case Variant::PACKED_VECTOR3_ARRAY: {
+ return _convert_array<DA, Vector<Vector3>>(p_variant.operator Vector<Vector3>());
}
- case Variant::POOL_COLOR_ARRAY: {
- return _convert_array<DA, PoolVector<Color> >(p_variant.operator PoolVector<Color>());
+ case Variant::PACKED_COLOR_ARRAY: {
+ return _convert_array<DA, Vector<Color>>(p_variant.operator Vector<Color>());
}
default: {
return DA();
@@ -1842,267 +2182,173 @@ inline DA _convert_array_from_variant(const Variant &p_variant) {
}
Variant::operator Array() const {
-
- if (type == ARRAY)
+ if (type == ARRAY) {
return *reinterpret_cast<const Array *>(_data._mem);
- else
+ } else {
return _convert_array_from_variant<Array>(*this);
+ }
}
-Variant::operator PoolVector<uint8_t>() const {
-
- if (type == POOL_BYTE_ARRAY)
- return *reinterpret_cast<const PoolVector<uint8_t> *>(_data._mem);
- else
- return _convert_array_from_variant<PoolVector<uint8_t> >(*this);
+Variant::operator Vector<uint8_t>() const {
+ if (type == PACKED_BYTE_ARRAY) {
+ return static_cast<PackedArrayRef<uint8_t> *>(_data.packed_array)->array;
+ } else {
+ return _convert_array_from_variant<Vector<uint8_t>>(*this);
+ }
}
-Variant::operator PoolVector<int>() const {
- if (type == POOL_INT_ARRAY)
- return *reinterpret_cast<const PoolVector<int> *>(_data._mem);
- else
- return _convert_array_from_variant<PoolVector<int> >(*this);
+Variant::operator Vector<int32_t>() const {
+ if (type == PACKED_INT32_ARRAY) {
+ return static_cast<PackedArrayRef<int32_t> *>(_data.packed_array)->array;
+ } else {
+ return _convert_array_from_variant<Vector<int>>(*this);
+ }
}
-Variant::operator PoolVector<real_t>() const {
- if (type == POOL_REAL_ARRAY)
- return *reinterpret_cast<const PoolVector<real_t> *>(_data._mem);
- else
- return _convert_array_from_variant<PoolVector<real_t> >(*this);
+Variant::operator Vector<int64_t>() const {
+ if (type == PACKED_INT64_ARRAY) {
+ return static_cast<PackedArrayRef<int64_t> *>(_data.packed_array)->array;
+ } else {
+ return _convert_array_from_variant<Vector<int64_t>>(*this);
+ }
}
-Variant::operator PoolVector<String>() const {
+Variant::operator Vector<float>() const {
+ if (type == PACKED_FLOAT32_ARRAY) {
+ return static_cast<PackedArrayRef<float> *>(_data.packed_array)->array;
+ } else {
+ return _convert_array_from_variant<Vector<float>>(*this);
+ }
+}
- if (type == POOL_STRING_ARRAY)
- return *reinterpret_cast<const PoolVector<String> *>(_data._mem);
- else
- return _convert_array_from_variant<PoolVector<String> >(*this);
+Variant::operator Vector<double>() const {
+ if (type == PACKED_FLOAT64_ARRAY) {
+ return static_cast<PackedArrayRef<double> *>(_data.packed_array)->array;
+ } else {
+ return _convert_array_from_variant<Vector<double>>(*this);
+ }
}
-Variant::operator PoolVector<Vector3>() const {
- if (type == POOL_VECTOR3_ARRAY)
- return *reinterpret_cast<const PoolVector<Vector3> *>(_data._mem);
- else
- return _convert_array_from_variant<PoolVector<Vector3> >(*this);
+Variant::operator Vector<String>() const {
+ if (type == PACKED_STRING_ARRAY) {
+ return static_cast<PackedArrayRef<String> *>(_data.packed_array)->array;
+ } else {
+ return _convert_array_from_variant<Vector<String>>(*this);
+ }
}
-Variant::operator PoolVector<Vector2>() const {
- if (type == POOL_VECTOR2_ARRAY)
- return *reinterpret_cast<const PoolVector<Vector2> *>(_data._mem);
- else
- return _convert_array_from_variant<PoolVector<Vector2> >(*this);
+Variant::operator Vector<Vector3>() const {
+ if (type == PACKED_VECTOR3_ARRAY) {
+ return static_cast<PackedArrayRef<Vector3> *>(_data.packed_array)->array;
+ } else {
+ return _convert_array_from_variant<Vector<Vector3>>(*this);
+ }
}
-Variant::operator PoolVector<Color>() const {
+Variant::operator Vector<Vector2>() const {
+ if (type == PACKED_VECTOR2_ARRAY) {
+ return static_cast<PackedArrayRef<Vector2> *>(_data.packed_array)->array;
+ } else {
+ return _convert_array_from_variant<Vector<Vector2>>(*this);
+ }
+}
- if (type == POOL_COLOR_ARRAY)
- return *reinterpret_cast<const PoolVector<Color> *>(_data._mem);
- else
- return _convert_array_from_variant<PoolVector<Color> >(*this);
+Variant::operator Vector<Color>() const {
+ if (type == PACKED_COLOR_ARRAY) {
+ return static_cast<PackedArrayRef<Color> *>(_data.packed_array)->array;
+ } else {
+ return _convert_array_from_variant<Vector<Color>>(*this);
+ }
}
/* helpers */
Variant::operator Vector<RID>() const {
-
Array va = operator Array();
Vector<RID> rids;
rids.resize(va.size());
- for (int i = 0; i < rids.size(); i++)
+ for (int i = 0; i < rids.size(); i++) {
rids.write[i] = va[i];
- return rids;
-}
-
-Variant::operator Vector<Vector2>() const {
-
- PoolVector<Vector2> from = operator PoolVector<Vector2>();
- Vector<Vector2> to;
- int len = from.size();
- if (len == 0)
- return Vector<Vector2>();
- to.resize(len);
- PoolVector<Vector2>::Read r = from.read();
- Vector2 *w = to.ptrw();
- for (int i = 0; i < len; i++) {
-
- w[i] = r[i];
}
- return to;
+ return rids;
}
-Variant::operator PoolVector<Plane>() const {
-
+Variant::operator Vector<Plane>() const {
Array va = operator Array();
- PoolVector<Plane> planes;
+ Vector<Plane> planes;
int va_size = va.size();
- if (va_size == 0)
+ if (va_size == 0) {
return planes;
+ }
planes.resize(va_size);
- PoolVector<Plane>::Write w = planes.write();
+ Plane *w = planes.ptrw();
- for (int i = 0; i < va_size; i++)
+ for (int i = 0; i < va_size; i++) {
w[i] = va[i];
+ }
return planes;
}
-Variant::operator PoolVector<Face3>() const {
-
- PoolVector<Vector3> va = operator PoolVector<Vector3>();
- PoolVector<Face3> faces;
+Variant::operator Vector<Face3>() const {
+ Vector<Vector3> va = operator Vector<Vector3>();
+ Vector<Face3> faces;
int va_size = va.size();
- if (va_size == 0)
+ if (va_size == 0) {
return faces;
+ }
faces.resize(va_size / 3);
- PoolVector<Face3>::Write w = faces.write();
- PoolVector<Vector3>::Read r = va.read();
+ Face3 *w = faces.ptrw();
+ const Vector3 *r = va.ptr();
- for (int i = 0; i < va_size; i++)
+ for (int i = 0; i < va_size; i++) {
w[i / 3].vertex[i % 3] = r[i];
+ }
return faces;
}
-Variant::operator Vector<Plane>() const {
-
+Variant::operator Vector<Variant>() const {
Array va = operator Array();
- Vector<Plane> planes;
+ Vector<Variant> variants;
int va_size = va.size();
- if (va_size == 0)
- return planes;
-
- planes.resize(va_size);
-
- for (int i = 0; i < va_size; i++)
- planes.write[i] = va[i];
-
- return planes;
-}
-
-Variant::operator Vector<Variant>() const {
-
- Array from = operator Array();
- Vector<Variant> to;
- int len = from.size();
- to.resize(len);
- for (int i = 0; i < len; i++) {
-
- to.write[i] = from[i];
- }
- return to;
-}
-
-Variant::operator Vector<uint8_t>() const {
-
- PoolVector<uint8_t> from = operator PoolVector<uint8_t>();
- Vector<uint8_t> to;
- int len = from.size();
- to.resize(len);
- for (int i = 0; i < len; i++) {
-
- to.write[i] = from[i];
+ if (va_size == 0) {
+ return variants;
}
- return to;
-}
-Variant::operator Vector<int>() const {
- PoolVector<int> from = operator PoolVector<int>();
- Vector<int> to;
- int len = from.size();
- to.resize(len);
- for (int i = 0; i < len; i++) {
-
- to.write[i] = from[i];
+ variants.resize(va_size);
+ Variant *w = variants.ptrw();
+ for (int i = 0; i < va_size; i++) {
+ w[i] = va[i];
}
- return to;
-}
-Variant::operator Vector<real_t>() const {
- PoolVector<real_t> from = operator PoolVector<real_t>();
- Vector<real_t> to;
- int len = from.size();
- to.resize(len);
- for (int i = 0; i < len; i++) {
-
- to.write[i] = from[i];
- }
- return to;
+ return variants;
}
-Variant::operator Vector<String>() const {
-
- PoolVector<String> from = operator PoolVector<String>();
- Vector<String> to;
- int len = from.size();
- to.resize(len);
- for (int i = 0; i < len; i++) {
-
- to.write[i] = from[i];
- }
- return to;
-}
Variant::operator Vector<StringName>() const {
-
- PoolVector<String> from = operator PoolVector<String>();
+ Vector<String> from = operator Vector<String>();
Vector<StringName> to;
int len = from.size();
to.resize(len);
for (int i = 0; i < len; i++) {
-
to.write[i] = from[i];
}
return to;
}
-Variant::operator Vector<Vector3>() const {
-
- PoolVector<Vector3> from = operator PoolVector<Vector3>();
- Vector<Vector3> to;
- int len = from.size();
- if (len == 0)
- return Vector<Vector3>();
- to.resize(len);
- PoolVector<Vector3>::Read r = from.read();
- Vector3 *w = to.ptrw();
- for (int i = 0; i < len; i++) {
-
- w[i] = r[i];
- }
- return to;
-}
-Variant::operator Vector<Color>() const {
-
- PoolVector<Color> from = operator PoolVector<Color>();
- Vector<Color> to;
- int len = from.size();
- if (len == 0)
- return Vector<Color>();
- to.resize(len);
- PoolVector<Color>::Read r = from.read();
- Color *w = to.ptrw();
- for (int i = 0; i < len; i++) {
-
- w[i] = r[i];
- }
- return to;
-}
-
Variant::operator Margin() const {
-
return (Margin) operator int();
}
-Variant::operator Orientation() const {
+Variant::operator Orientation() const {
return (Orientation) operator int();
}
Variant::operator IP_Address() const {
-
- if (type == POOL_REAL_ARRAY || type == POOL_INT_ARRAY || type == POOL_BYTE_ARRAY) {
-
- PoolVector<int> addr = operator PoolVector<int>();
+ if (type == PACKED_FLOAT32_ARRAY || type == PACKED_INT32_ARRAY || type == PACKED_FLOAT64_ARRAY || type == PACKED_INT64_ARRAY || type == PACKED_BYTE_ARRAY) {
+ Vector<int> addr = operator Vector<int>();
if (addr.size() == 4) {
return IP_Address(addr.get(0), addr.get(1), addr.get(2), addr.get(3));
}
@@ -2112,26 +2358,16 @@ Variant::operator IP_Address() const {
}
Variant::Variant(bool p_bool) {
-
type = BOOL;
_data._bool = p_bool;
}
-/*
-Variant::Variant(long unsigned int p_long) {
-
- type=INT;
- _data._int=p_long;
-};
-*/
-
Variant::Variant(signed int p_int) {
-
type = INT;
_data._int = p_int;
}
-Variant::Variant(unsigned int p_int) {
+Variant::Variant(unsigned int p_int) {
type = INT;
_data._int = p_int;
}
@@ -2139,194 +2375,200 @@ Variant::Variant(unsigned int p_int) {
#ifdef NEED_LONG_INT
Variant::Variant(signed long p_int) {
-
type = INT;
_data._int = p_int;
}
-Variant::Variant(unsigned long p_int) {
+Variant::Variant(unsigned long p_int) {
type = INT;
_data._int = p_int;
}
#endif
Variant::Variant(int64_t p_int) {
-
type = INT;
_data._int = p_int;
}
Variant::Variant(uint64_t p_int) {
-
type = INT;
_data._int = p_int;
}
Variant::Variant(signed short p_short) {
-
type = INT;
_data._int = p_short;
}
-Variant::Variant(unsigned short p_short) {
+Variant::Variant(unsigned short p_short) {
type = INT;
_data._int = p_short;
}
-Variant::Variant(signed char p_char) {
+Variant::Variant(signed char p_char) {
type = INT;
_data._int = p_char;
}
-Variant::Variant(unsigned char p_char) {
+Variant::Variant(unsigned char p_char) {
type = INT;
_data._int = p_char;
}
-Variant::Variant(float p_float) {
- type = REAL;
- _data._real = p_float;
+Variant::Variant(float p_float) {
+ type = FLOAT;
+ _data._float = p_float;
}
+
Variant::Variant(double p_double) {
+ type = FLOAT;
+ _data._float = p_double;
+}
- type = REAL;
- _data._real = p_double;
+Variant::Variant(const ObjectID &p_id) {
+ type = INT;
+ _data._int = p_id;
}
Variant::Variant(const StringName &p_string) {
-
- type = STRING;
- memnew_placement(_data._mem, String(p_string.operator String()));
+ type = STRING_NAME;
+ memnew_placement(_data._mem, StringName(p_string));
}
-Variant::Variant(const String &p_string) {
+Variant::Variant(const String &p_string) {
type = STRING;
memnew_placement(_data._mem, String(p_string));
}
Variant::Variant(const char *const p_cstring) {
-
type = STRING;
memnew_placement(_data._mem, String((const char *)p_cstring));
}
-Variant::Variant(const CharType *p_wstring) {
-
+Variant::Variant(const char32_t *p_wstring) {
type = STRING;
memnew_placement(_data._mem, String(p_wstring));
}
-Variant::Variant(const Vector3 &p_vector3) {
+Variant::Variant(const Vector3 &p_vector3) {
type = VECTOR3;
memnew_placement(_data._mem, Vector3(p_vector3));
}
-Variant::Variant(const Vector2 &p_vector2) {
+Variant::Variant(const Vector3i &p_vector3i) {
+ type = VECTOR3I;
+ memnew_placement(_data._mem, Vector3i(p_vector3i));
+}
+
+Variant::Variant(const Vector2 &p_vector2) {
type = VECTOR2;
memnew_placement(_data._mem, Vector2(p_vector2));
}
-Variant::Variant(const Rect2 &p_rect2) {
+Variant::Variant(const Vector2i &p_vector2i) {
+ type = VECTOR2I;
+ memnew_placement(_data._mem, Vector2i(p_vector2i));
+}
+
+Variant::Variant(const Rect2 &p_rect2) {
type = RECT2;
memnew_placement(_data._mem, Rect2(p_rect2));
}
-Variant::Variant(const Plane &p_plane) {
+Variant::Variant(const Rect2i &p_rect2i) {
+ type = RECT2I;
+ memnew_placement(_data._mem, Rect2i(p_rect2i));
+}
+Variant::Variant(const Plane &p_plane) {
type = PLANE;
memnew_placement(_data._mem, Plane(p_plane));
}
-Variant::Variant(const ::AABB &p_aabb) {
+Variant::Variant(const ::AABB &p_aabb) {
type = AABB;
_data._aabb = memnew(::AABB(p_aabb));
}
Variant::Variant(const Basis &p_matrix) {
-
type = BASIS;
_data._basis = memnew(Basis(p_matrix));
}
Variant::Variant(const Quat &p_quat) {
-
type = QUAT;
memnew_placement(_data._mem, Quat(p_quat));
}
-Variant::Variant(const Transform &p_transform) {
+Variant::Variant(const Transform &p_transform) {
type = TRANSFORM;
_data._transform = memnew(Transform(p_transform));
}
Variant::Variant(const Transform2D &p_transform) {
-
type = TRANSFORM2D;
_data._transform2d = memnew(Transform2D(p_transform));
}
-Variant::Variant(const Color &p_color) {
+Variant::Variant(const Color &p_color) {
type = COLOR;
memnew_placement(_data._mem, Color(p_color));
}
Variant::Variant(const NodePath &p_node_path) {
-
type = NODE_PATH;
memnew_placement(_data._mem, NodePath(p_node_path));
}
-Variant::Variant(const RefPtr &p_resource) {
-
- type = OBJECT;
- memnew_placement(_data._mem, ObjData);
- REF *ref = reinterpret_cast<REF *>(p_resource.get_data());
- _get_obj().obj = ref->ptr();
- _get_obj().ref = p_resource;
-}
-
Variant::Variant(const RID &p_rid) {
-
type = _RID;
memnew_placement(_data._mem, RID(p_rid));
}
Variant::Variant(const Object *p_object) {
-
type = OBJECT;
memnew_placement(_data._mem, ObjData);
- _get_obj().obj = const_cast<Object *>(p_object);
+
+ if (p_object) {
+ if (p_object->is_reference()) {
+ Reference *reference = const_cast<Reference *>(static_cast<const Reference *>(p_object));
+ if (!reference->init_ref()) {
+ _get_obj().obj = nullptr;
+ _get_obj().id = ObjectID();
+ return;
+ }
+ }
+
+ _get_obj().obj = const_cast<Object *>(p_object);
+ _get_obj().id = p_object->get_instance_id();
+ } else {
+ _get_obj().obj = nullptr;
+ _get_obj().id = ObjectID();
+ }
}
-Variant::Variant(const Dictionary &p_dictionary) {
+Variant::Variant(const Callable &p_callable) {
+ type = CALLABLE;
+ memnew_placement(_data._mem, Callable(p_callable));
+}
+Variant::Variant(const Signal &p_callable) {
+ type = SIGNAL;
+ memnew_placement(_data._mem, Signal(p_callable));
+}
+
+Variant::Variant(const Dictionary &p_dictionary) {
type = DICTIONARY;
memnew_placement(_data._mem, Dictionary(p_dictionary));
}
Variant::Variant(const Array &p_array) {
-
type = ARRAY;
memnew_placement(_data._mem, Array(p_array));
}
-Variant::Variant(const PoolVector<Plane> &p_array) {
-
- type = ARRAY;
-
- Array *plane_array = memnew_placement(_data._mem, Array);
-
- plane_array->resize(p_array.size());
-
- for (int i = 0; i < p_array.size(); i++) {
-
- plane_array->operator[](i) = Variant(p_array[i]);
- }
-}
-
Variant::Variant(const Vector<Plane> &p_array) {
-
type = ARRAY;
Array *plane_array = memnew_placement(_data._mem, Array);
@@ -2334,13 +2576,11 @@ Variant::Variant(const Vector<Plane> &p_array) {
plane_array->resize(p_array.size());
for (int i = 0; i < p_array.size(); i++) {
-
plane_array->operator[](i) = Variant(p_array[i]);
}
}
Variant::Variant(const Vector<RID> &p_array) {
-
type = ARRAY;
Array *rid_array = memnew_placement(_data._mem, Array);
@@ -2348,78 +2588,69 @@ Variant::Variant(const Vector<RID> &p_array) {
rid_array->resize(p_array.size());
for (int i = 0; i < p_array.size(); i++) {
-
rid_array->set(i, Variant(p_array[i]));
}
}
-Variant::Variant(const Vector<Vector2> &p_array) {
+Variant::Variant(const Vector<uint8_t> &p_byte_array) {
+ type = PACKED_BYTE_ARRAY;
- type = NIL;
- PoolVector<Vector2> v;
- int len = p_array.size();
- if (len > 0) {
- v.resize(len);
- PoolVector<Vector2>::Write w = v.write();
- const Vector2 *r = p_array.ptr();
-
- for (int i = 0; i < len; i++)
- w[i] = r[i];
- }
- *this = v;
+ _data.packed_array = PackedArrayRef<uint8_t>::create(p_byte_array);
}
-Variant::Variant(const PoolVector<uint8_t> &p_raw_array) {
-
- type = POOL_BYTE_ARRAY;
- memnew_placement(_data._mem, PoolVector<uint8_t>(p_raw_array));
+Variant::Variant(const Vector<int32_t> &p_int32_array) {
+ type = PACKED_INT32_ARRAY;
+ _data.packed_array = PackedArrayRef<int32_t>::create(p_int32_array);
}
-Variant::Variant(const PoolVector<int> &p_int_array) {
- type = POOL_INT_ARRAY;
- memnew_placement(_data._mem, PoolVector<int>(p_int_array));
+Variant::Variant(const Vector<int64_t> &p_int64_array) {
+ type = PACKED_INT64_ARRAY;
+ _data.packed_array = PackedArrayRef<int64_t>::create(p_int64_array);
}
-Variant::Variant(const PoolVector<real_t> &p_real_array) {
- type = POOL_REAL_ARRAY;
- memnew_placement(_data._mem, PoolVector<real_t>(p_real_array));
+Variant::Variant(const Vector<float> &p_float32_array) {
+ type = PACKED_FLOAT32_ARRAY;
+ _data.packed_array = PackedArrayRef<float>::create(p_float32_array);
}
-Variant::Variant(const PoolVector<String> &p_string_array) {
- type = POOL_STRING_ARRAY;
- memnew_placement(_data._mem, PoolVector<String>(p_string_array));
+Variant::Variant(const Vector<double> &p_float64_array) {
+ type = PACKED_FLOAT64_ARRAY;
+ _data.packed_array = PackedArrayRef<double>::create(p_float64_array);
}
-Variant::Variant(const PoolVector<Vector3> &p_vector3_array) {
- type = POOL_VECTOR3_ARRAY;
- memnew_placement(_data._mem, PoolVector<Vector3>(p_vector3_array));
+Variant::Variant(const Vector<String> &p_string_array) {
+ type = PACKED_STRING_ARRAY;
+ _data.packed_array = PackedArrayRef<String>::create(p_string_array);
}
-Variant::Variant(const PoolVector<Vector2> &p_vector2_array) {
-
- type = POOL_VECTOR2_ARRAY;
- memnew_placement(_data._mem, PoolVector<Vector2>(p_vector2_array));
+Variant::Variant(const Vector<Vector3> &p_vector3_array) {
+ type = PACKED_VECTOR3_ARRAY;
+ _data.packed_array = PackedArrayRef<Vector3>::create(p_vector3_array);
}
-Variant::Variant(const PoolVector<Color> &p_color_array) {
- type = POOL_COLOR_ARRAY;
- memnew_placement(_data._mem, PoolVector<Color>(p_color_array));
+Variant::Variant(const Vector<Vector2> &p_vector2_array) {
+ type = PACKED_VECTOR2_ARRAY;
+ _data.packed_array = PackedArrayRef<Vector2>::create(p_vector2_array);
}
-Variant::Variant(const PoolVector<Face3> &p_face_array) {
+Variant::Variant(const Vector<Color> &p_color_array) {
+ type = PACKED_COLOR_ARRAY;
+ _data.packed_array = PackedArrayRef<Color>::create(p_color_array);
+}
- PoolVector<Vector3> vertices;
+Variant::Variant(const Vector<Face3> &p_face_array) {
+ Vector<Vector3> vertices;
int face_count = p_face_array.size();
vertices.resize(face_count * 3);
if (face_count) {
- PoolVector<Face3>::Read r = p_face_array.read();
- PoolVector<Vector3>::Write w = vertices.write();
+ const Face3 *r = p_face_array.ptr();
+ Vector3 *w = vertices.ptrw();
for (int i = 0; i < face_count; i++) {
-
- for (int j = 0; j < 3; j++)
+ for (int j = 0; j < 3; j++) {
w[i * 3 + j] = r[i].vertex[j];
+ }
}
}
@@ -2429,104 +2660,31 @@ Variant::Variant(const PoolVector<Face3> &p_face_array) {
}
/* helpers */
-
Variant::Variant(const Vector<Variant> &p_array) {
-
type = NIL;
- Array v;
- int len = p_array.size();
- v.resize(len);
- for (int i = 0; i < len; i++)
- v.set(i, p_array[i]);
- *this = v;
-}
-
-Variant::Variant(const Vector<uint8_t> &p_array) {
-
- type = NIL;
- PoolVector<uint8_t> v;
- int len = p_array.size();
- v.resize(len);
- for (int i = 0; i < len; i++)
- v.set(i, p_array[i]);
- *this = v;
-}
-
-Variant::Variant(const Vector<int> &p_array) {
-
- type = NIL;
- PoolVector<int> v;
- int len = p_array.size();
- v.resize(len);
- for (int i = 0; i < len; i++)
- v.set(i, p_array[i]);
- *this = v;
-}
-
-Variant::Variant(const Vector<real_t> &p_array) {
-
- type = NIL;
- PoolVector<real_t> v;
- int len = p_array.size();
- v.resize(len);
- for (int i = 0; i < len; i++)
- v.set(i, p_array[i]);
- *this = v;
-}
-
-Variant::Variant(const Vector<String> &p_array) {
-
- type = NIL;
- PoolVector<String> v;
- int len = p_array.size();
- v.resize(len);
- for (int i = 0; i < len; i++)
- v.set(i, p_array[i]);
- *this = v;
+ Array arr;
+ arr.resize(p_array.size());
+ for (int i = 0; i < p_array.size(); i++) {
+ arr[i] = p_array[i];
+ }
+ *this = arr;
}
Variant::Variant(const Vector<StringName> &p_array) {
-
type = NIL;
- PoolVector<String> v;
+ Vector<String> v;
int len = p_array.size();
v.resize(len);
- for (int i = 0; i < len; i++)
+ for (int i = 0; i < len; i++) {
v.set(i, p_array[i]);
- *this = v;
-}
-
-Variant::Variant(const Vector<Vector3> &p_array) {
-
- type = NIL;
- PoolVector<Vector3> v;
- int len = p_array.size();
- if (len > 0) {
- v.resize(len);
- PoolVector<Vector3>::Write w = v.write();
- const Vector3 *r = p_array.ptr();
-
- for (int i = 0; i < len; i++)
- w[i] = r[i];
}
*this = v;
}
-Variant::Variant(const Vector<Color> &p_array) {
-
- type = NIL;
- PoolVector<Color> v;
- int len = p_array.size();
- v.resize(len);
- for (int i = 0; i < len; i++)
- v.set(i, p_array[i]);
- *this = v;
-}
-
void Variant::operator=(const Variant &p_variant) {
-
- if (unlikely(this == &p_variant))
+ if (unlikely(this == &p_variant)) {
return;
+ }
if (unlikely(type != p_variant.type)) {
reference(p_variant);
@@ -2535,121 +2693,138 @@ void Variant::operator=(const Variant &p_variant) {
switch (p_variant.type) {
case NIL: {
-
// none
} break;
// atomic types
case BOOL: {
-
_data._bool = p_variant._data._bool;
} break;
case INT: {
-
_data._int = p_variant._data._int;
} break;
- case REAL: {
-
- _data._real = p_variant._data._real;
+ case FLOAT: {
+ _data._float = p_variant._data._float;
} break;
case STRING: {
-
*reinterpret_cast<String *>(_data._mem) = *reinterpret_cast<const String *>(p_variant._data._mem);
} break;
// math types
case VECTOR2: {
-
*reinterpret_cast<Vector2 *>(_data._mem) = *reinterpret_cast<const Vector2 *>(p_variant._data._mem);
} break;
+ case VECTOR2I: {
+ *reinterpret_cast<Vector2i *>(_data._mem) = *reinterpret_cast<const Vector2i *>(p_variant._data._mem);
+ } break;
case RECT2: {
-
*reinterpret_cast<Rect2 *>(_data._mem) = *reinterpret_cast<const Rect2 *>(p_variant._data._mem);
} break;
+ case RECT2I: {
+ *reinterpret_cast<Rect2i *>(_data._mem) = *reinterpret_cast<const Rect2i *>(p_variant._data._mem);
+ } break;
case TRANSFORM2D: {
-
*_data._transform2d = *(p_variant._data._transform2d);
} break;
case VECTOR3: {
-
*reinterpret_cast<Vector3 *>(_data._mem) = *reinterpret_cast<const Vector3 *>(p_variant._data._mem);
} break;
+ case VECTOR3I: {
+ *reinterpret_cast<Vector3i *>(_data._mem) = *reinterpret_cast<const Vector3i *>(p_variant._data._mem);
+ } break;
case PLANE: {
-
*reinterpret_cast<Plane *>(_data._mem) = *reinterpret_cast<const Plane *>(p_variant._data._mem);
} break;
case AABB: {
-
*_data._aabb = *(p_variant._data._aabb);
} break;
case QUAT: {
-
*reinterpret_cast<Quat *>(_data._mem) = *reinterpret_cast<const Quat *>(p_variant._data._mem);
} break;
case BASIS: {
-
*_data._basis = *(p_variant._data._basis);
} break;
case TRANSFORM: {
-
*_data._transform = *(p_variant._data._transform);
} break;
// misc types
case COLOR: {
-
*reinterpret_cast<Color *>(_data._mem) = *reinterpret_cast<const Color *>(p_variant._data._mem);
} break;
case _RID: {
-
*reinterpret_cast<RID *>(_data._mem) = *reinterpret_cast<const RID *>(p_variant._data._mem);
} break;
case OBJECT: {
+ if (_get_obj().id.is_reference()) {
+ //we are safe that there is a reference here
+ Reference *reference = static_cast<Reference *>(_get_obj().obj);
+ if (reference->unreference()) {
+ memdelete(reference);
+ }
+ }
+
+ if (p_variant._get_obj().obj && p_variant._get_obj().id.is_reference()) {
+ Reference *reference = static_cast<Reference *>(p_variant._get_obj().obj);
+ if (!reference->reference()) {
+ _get_obj().obj = nullptr;
+ _get_obj().id = ObjectID();
+ break;
+ }
+ }
+
+ _get_obj().obj = const_cast<Object *>(p_variant._get_obj().obj);
+ _get_obj().id = p_variant._get_obj().id;
- *reinterpret_cast<ObjData *>(_data._mem) = p_variant._get_obj();
} break;
- case NODE_PATH: {
+ case CALLABLE: {
+ *reinterpret_cast<Callable *>(_data._mem) = *reinterpret_cast<const Callable *>(p_variant._data._mem);
+ } break;
+ case SIGNAL: {
+ *reinterpret_cast<Signal *>(_data._mem) = *reinterpret_cast<const Signal *>(p_variant._data._mem);
+ } break;
+ case STRING_NAME: {
+ *reinterpret_cast<StringName *>(_data._mem) = *reinterpret_cast<const StringName *>(p_variant._data._mem);
+ } break;
+ case NODE_PATH: {
*reinterpret_cast<NodePath *>(_data._mem) = *reinterpret_cast<const NodePath *>(p_variant._data._mem);
} break;
case DICTIONARY: {
-
*reinterpret_cast<Dictionary *>(_data._mem) = *reinterpret_cast<const Dictionary *>(p_variant._data._mem);
} break;
case ARRAY: {
-
*reinterpret_cast<Array *>(_data._mem) = *reinterpret_cast<const Array *>(p_variant._data._mem);
} break;
// arrays
- case POOL_BYTE_ARRAY: {
-
- *reinterpret_cast<PoolVector<uint8_t> *>(_data._mem) = *reinterpret_cast<const PoolVector<uint8_t> *>(p_variant._data._mem);
+ case PACKED_BYTE_ARRAY: {
+ _data.packed_array = PackedArrayRef<uint8_t>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
- case POOL_INT_ARRAY: {
-
- *reinterpret_cast<PoolVector<int> *>(_data._mem) = *reinterpret_cast<const PoolVector<int> *>(p_variant._data._mem);
+ case PACKED_INT32_ARRAY: {
+ _data.packed_array = PackedArrayRef<int32_t>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
- case POOL_REAL_ARRAY: {
-
- *reinterpret_cast<PoolVector<real_t> *>(_data._mem) = *reinterpret_cast<const PoolVector<real_t> *>(p_variant._data._mem);
+ case PACKED_INT64_ARRAY: {
+ _data.packed_array = PackedArrayRef<int64_t>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
- case POOL_STRING_ARRAY: {
-
- *reinterpret_cast<PoolVector<String> *>(_data._mem) = *reinterpret_cast<const PoolVector<String> *>(p_variant._data._mem);
+ case PACKED_FLOAT32_ARRAY: {
+ _data.packed_array = PackedArrayRef<float>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
- case POOL_VECTOR2_ARRAY: {
-
- *reinterpret_cast<PoolVector<Vector2> *>(_data._mem) = *reinterpret_cast<const PoolVector<Vector2> *>(p_variant._data._mem);
+ case PACKED_FLOAT64_ARRAY: {
+ _data.packed_array = PackedArrayRef<double>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
- case POOL_VECTOR3_ARRAY: {
-
- *reinterpret_cast<PoolVector<Vector3> *>(_data._mem) = *reinterpret_cast<const PoolVector<Vector3> *>(p_variant._data._mem);
+ case PACKED_STRING_ARRAY: {
+ _data.packed_array = PackedArrayRef<String>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
- case POOL_COLOR_ARRAY: {
-
- *reinterpret_cast<PoolVector<Color> *>(_data._mem) = *reinterpret_cast<const PoolVector<Color> *>(p_variant._data._mem);
+ case PACKED_VECTOR2_ARRAY: {
+ _data.packed_array = PackedArrayRef<Vector2>::reference_from(_data.packed_array, p_variant._data.packed_array);
+ } break;
+ case PACKED_VECTOR3_ARRAY: {
+ _data.packed_array = PackedArrayRef<Vector3>::reference_from(_data.packed_array, p_variant._data.packed_array);
+ } break;
+ case PACKED_COLOR_ARRAY: {
+ _data.packed_array = PackedArrayRef<Color>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
default: {
}
@@ -2657,65 +2832,56 @@ void Variant::operator=(const Variant &p_variant) {
}
Variant::Variant(const IP_Address &p_address) {
-
type = STRING;
memnew_placement(_data._mem, String(p_address));
}
Variant::Variant(const Variant &p_variant) {
-
- type = NIL;
reference(p_variant);
}
-/*
-Variant::~Variant() {
-
- clear();
-}*/
-
uint32_t Variant::hash() const {
-
switch (type) {
case NIL: {
-
return 0;
} break;
case BOOL: {
-
return _data._bool ? 1 : 0;
} break;
case INT: {
-
return _data._int;
} break;
- case REAL: {
-
- return hash_djb2_one_float(_data._real);
+ case FLOAT: {
+ return hash_djb2_one_float(_data._float);
} break;
case STRING: {
-
return reinterpret_cast<const String *>(_data._mem)->hash();
} break;
// math types
case VECTOR2: {
-
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->x);
return hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->y, hash);
} break;
+ case VECTOR2I: {
+ uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Vector2i *>(_data._mem)->x);
+ return hash_djb2_one_32(reinterpret_cast<const Vector2i *>(_data._mem)->y, hash);
+ } break;
case RECT2: {
-
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.x);
hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.y, hash);
hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.x, hash);
return hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.y, hash);
} break;
+ case RECT2I: {
+ uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->position.x);
+ hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->position.y, hash);
+ hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->size.x, hash);
+ return hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->size.y, hash);
+ } break;
case TRANSFORM2D: {
-
uint32_t hash = 5831;
for (int i = 0; i < 3; i++) {
-
for (int j = 0; j < 2; j++) {
hash = hash_djb2_one_float(_data._transform2d->elements[i][j], hash);
}
@@ -2724,29 +2890,25 @@ uint32_t Variant::hash() const {
return hash;
} break;
case VECTOR3: {
-
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->x);
hash = hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->y, hash);
return hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->z, hash);
} break;
+ case VECTOR3I: {
+ uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->x);
+ hash = hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->y, hash);
+ return hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->z, hash);
+ } break;
case PLANE: {
-
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.x);
hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.y, hash);
hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.z, hash);
return hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->d, hash);
} break;
- /*
- case QUAT: {
-
-
- } break;*/
case AABB: {
-
uint32_t hash = 5831;
for (int i = 0; i < 3; i++) {
-
hash = hash_djb2_one_float(_data._aabb->position[i], hash);
hash = hash_djb2_one_float(_data._aabb->size[i], hash);
}
@@ -2755,7 +2917,6 @@ uint32_t Variant::hash() const {
} break;
case QUAT: {
-
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Quat *>(_data._mem)->x);
hash = hash_djb2_one_float(reinterpret_cast<const Quat *>(_data._mem)->y, hash);
hash = hash_djb2_one_float(reinterpret_cast<const Quat *>(_data._mem)->z, hash);
@@ -2763,10 +2924,8 @@ uint32_t Variant::hash() const {
} break;
case BASIS: {
-
uint32_t hash = 5831;
for (int i = 0; i < 3; i++) {
-
for (int j = 0; j < 3; j++) {
hash = hash_djb2_one_float(_data._basis->elements[i][j], hash);
}
@@ -2776,10 +2935,8 @@ uint32_t Variant::hash() const {
} break;
case TRANSFORM: {
-
uint32_t hash = 5831;
for (int i = 0; i < 3; i++) {
-
for (int j = 0; j < 3; j++) {
hash = hash_djb2_one_float(_data._transform->basis.elements[i][j], hash);
}
@@ -2792,7 +2949,6 @@ uint32_t Variant::hash() const {
// misc types
case COLOR: {
-
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Color *>(_data._mem)->r);
hash = hash_djb2_one_float(reinterpret_cast<const Color *>(_data._mem)->g, hash);
hash = hash_djb2_one_float(reinterpret_cast<const Color *>(_data._mem)->b, hash);
@@ -2800,73 +2956,99 @@ uint32_t Variant::hash() const {
} break;
case _RID: {
-
return hash_djb2_one_64(reinterpret_cast<const RID *>(_data._mem)->get_id());
} break;
case OBJECT: {
-
return hash_djb2_one_64(make_uint64_t(_get_obj().obj));
} break;
+ case STRING_NAME: {
+ return reinterpret_cast<const StringName *>(_data._mem)->hash();
+ } break;
case NODE_PATH: {
-
return reinterpret_cast<const NodePath *>(_data._mem)->hash();
} break;
case DICTIONARY: {
-
return reinterpret_cast<const Dictionary *>(_data._mem)->hash();
} break;
- case ARRAY: {
+ case CALLABLE: {
+ return reinterpret_cast<const Callable *>(_data._mem)->hash();
+ } break;
+ case SIGNAL: {
+ const Signal &s = *reinterpret_cast<const Signal *>(_data._mem);
+ uint32_t hash = s.get_name().hash();
+ return hash_djb2_one_64(s.get_object_id(), hash);
+ } break;
+ case ARRAY: {
const Array &arr = *reinterpret_cast<const Array *>(_data._mem);
return arr.hash();
} break;
- case POOL_BYTE_ARRAY: {
-
- const PoolVector<uint8_t> &arr = *reinterpret_cast<const PoolVector<uint8_t> *>(_data._mem);
+ case PACKED_BYTE_ARRAY: {
+ const Vector<uint8_t> &arr = PackedArrayRef<uint8_t>::get_array(_data.packed_array);
int len = arr.size();
if (likely(len)) {
- PoolVector<uint8_t>::Read r = arr.read();
+ const uint8_t *r = arr.ptr();
return hash_djb2_buffer((uint8_t *)&r[0], len);
} else {
return hash_djb2_one_64(0);
}
} break;
- case POOL_INT_ARRAY: {
-
- const PoolVector<int> &arr = *reinterpret_cast<const PoolVector<int> *>(_data._mem);
+ case PACKED_INT32_ARRAY: {
+ const Vector<int32_t> &arr = PackedArrayRef<int32_t>::get_array(_data.packed_array);
int len = arr.size();
if (likely(len)) {
- PoolVector<int>::Read r = arr.read();
- return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(int));
+ const int32_t *r = arr.ptr();
+ return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(int32_t));
} else {
return hash_djb2_one_64(0);
}
} break;
- case POOL_REAL_ARRAY: {
+ case PACKED_INT64_ARRAY: {
+ const Vector<int64_t> &arr = PackedArrayRef<int64_t>::get_array(_data.packed_array);
+ int len = arr.size();
+ if (likely(len)) {
+ const int64_t *r = arr.ptr();
+ return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(int64_t));
+ } else {
+ return hash_djb2_one_64(0);
+ }
- const PoolVector<real_t> &arr = *reinterpret_cast<const PoolVector<real_t> *>(_data._mem);
+ } break;
+ case PACKED_FLOAT32_ARRAY: {
+ const Vector<float> &arr = PackedArrayRef<float>::get_array(_data.packed_array);
int len = arr.size();
if (likely(len)) {
- PoolVector<real_t>::Read r = arr.read();
- return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(real_t));
+ const float *r = arr.ptr();
+ return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(float));
} else {
return hash_djb2_one_float(0.0);
}
} break;
- case POOL_STRING_ARRAY: {
+ case PACKED_FLOAT64_ARRAY: {
+ const Vector<double> &arr = PackedArrayRef<double>::get_array(_data.packed_array);
+ int len = arr.size();
+ if (likely(len)) {
+ const double *r = arr.ptr();
+ return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(double));
+ } else {
+ return hash_djb2_one_float(0.0);
+ }
+
+ } break;
+ case PACKED_STRING_ARRAY: {
uint32_t hash = 5831;
- const PoolVector<String> &arr = *reinterpret_cast<const PoolVector<String> *>(_data._mem);
+ const Vector<String> &arr = PackedArrayRef<String>::get_array(_data.packed_array);
int len = arr.size();
if (likely(len)) {
- PoolVector<String>::Read r = arr.read();
+ const String *r = arr.ptr();
for (int i = 0; i < len; i++) {
hash = hash_djb2_one_32(r[i].hash(), hash);
@@ -2875,14 +3057,13 @@ uint32_t Variant::hash() const {
return hash;
} break;
- case POOL_VECTOR2_ARRAY: {
-
+ case PACKED_VECTOR2_ARRAY: {
uint32_t hash = 5831;
- const PoolVector<Vector2> &arr = *reinterpret_cast<const PoolVector<Vector2> *>(_data._mem);
+ const Vector<Vector2> &arr = PackedArrayRef<Vector2>::get_array(_data.packed_array);
int len = arr.size();
if (likely(len)) {
- PoolVector<Vector2>::Read r = arr.read();
+ const Vector2 *r = arr.ptr();
for (int i = 0; i < len; i++) {
hash = hash_djb2_one_float(r[i].x, hash);
@@ -2892,14 +3073,13 @@ uint32_t Variant::hash() const {
return hash;
} break;
- case POOL_VECTOR3_ARRAY: {
-
+ case PACKED_VECTOR3_ARRAY: {
uint32_t hash = 5831;
- const PoolVector<Vector3> &arr = *reinterpret_cast<const PoolVector<Vector3> *>(_data._mem);
+ const Vector<Vector3> &arr = PackedArrayRef<Vector3>::get_array(_data.packed_array);
int len = arr.size();
if (likely(len)) {
- PoolVector<Vector3>::Read r = arr.read();
+ const Vector3 *r = arr.ptr();
for (int i = 0; i < len; i++) {
hash = hash_djb2_one_float(r[i].x, hash);
@@ -2910,14 +3090,13 @@ uint32_t Variant::hash() const {
return hash;
} break;
- case POOL_COLOR_ARRAY: {
-
+ case PACKED_COLOR_ARRAY: {
uint32_t hash = 5831;
- const PoolVector<Color> &arr = *reinterpret_cast<const PoolVector<Color> *>(_data._mem);
+ const Vector<Color> &arr = PackedArrayRef<Color>::get_array(_data.packed_array);
int len = arr.size();
if (likely(len)) {
- PoolVector<Color>::Read r = arr.read();
+ const Color *r = arr.ptr();
for (int i = 0; i < len; i++) {
hash = hash_djb2_one_float(r[i].r, hash);
@@ -2960,30 +3139,31 @@ uint32_t Variant::hash() const {
(hash_compare_scalar((p_lhs).b, (p_rhs).b)) && \
(hash_compare_scalar((p_lhs).a, (p_rhs).a))
-#define hash_compare_pool_array(p_lhs, p_rhs, p_type, p_compare_func) \
- const PoolVector<p_type> &l = *reinterpret_cast<const PoolVector<p_type> *>(p_lhs); \
- const PoolVector<p_type> &r = *reinterpret_cast<const PoolVector<p_type> *>(p_rhs); \
- \
- if (l.size() != r.size()) \
- return false; \
- \
- PoolVector<p_type>::Read lr = l.read(); \
- PoolVector<p_type>::Read rr = r.read(); \
- \
- for (int i = 0; i < l.size(); ++i) { \
- if (!p_compare_func((lr[i]), (rr[i]))) \
- return false; \
- } \
- \
+#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; \
+ } \
+ \
return true
bool Variant::hash_compare(const Variant &p_variant) const {
- if (type != p_variant.type)
+ if (type != p_variant.type) {
return false;
+ }
switch (type) {
- case REAL: {
- return hash_compare_scalar(_data._real, p_variant._data._real);
+ case FLOAT: {
+ return hash_compare_scalar(_data._float, p_variant._data._float);
} break;
case VECTOR2: {
@@ -2992,6 +3172,11 @@ bool Variant::hash_compare(const Variant &p_variant) const {
return hash_compare_vector2(*l, *r);
} break;
+ case VECTOR2I: {
+ const Vector2i *l = reinterpret_cast<const Vector2i *>(_data._mem);
+ const Vector2i *r = reinterpret_cast<const Vector2i *>(p_variant._data._mem);
+ return *l == *r;
+ } break;
case RECT2: {
const Rect2 *l = reinterpret_cast<const Rect2 *>(_data._mem);
@@ -3000,14 +3185,21 @@ bool Variant::hash_compare(const Variant &p_variant) const {
return (hash_compare_vector2(l->position, r->position)) &&
(hash_compare_vector2(l->size, r->size));
} break;
+ case RECT2I: {
+ const Rect2i *l = reinterpret_cast<const Rect2i *>(_data._mem);
+ const Rect2i *r = reinterpret_cast<const Rect2i *>(p_variant._data._mem);
+
+ return *l == *r;
+ } break;
case TRANSFORM2D: {
Transform2D *l = _data._transform2d;
Transform2D *r = p_variant._data._transform2d;
for (int i = 0; i < 3; i++) {
- if (!(hash_compare_vector2(l->elements[i], r->elements[i])))
+ if (!(hash_compare_vector2(l->elements[i], r->elements[i]))) {
return false;
+ }
}
return true;
@@ -3019,6 +3211,12 @@ bool Variant::hash_compare(const Variant &p_variant) const {
return hash_compare_vector3(*l, *r);
} break;
+ case VECTOR3I: {
+ const Vector3i *l = reinterpret_cast<const Vector3i *>(_data._mem);
+ const Vector3i *r = reinterpret_cast<const Vector3i *>(p_variant._data._mem);
+
+ return *l == *r;
+ } break;
case PLANE: {
const Plane *l = reinterpret_cast<const Plane *>(_data._mem);
@@ -3049,8 +3247,9 @@ bool Variant::hash_compare(const Variant &p_variant) const {
const Basis *r = p_variant._data._basis;
for (int i = 0; i < 3; i++) {
- if (!(hash_compare_vector3(l->elements[i], r->elements[i])))
+ if (!(hash_compare_vector3(l->elements[i], r->elements[i]))) {
return false;
+ }
}
return true;
@@ -3061,8 +3260,9 @@ bool Variant::hash_compare(const Variant &p_variant) const {
const Transform *r = p_variant._data._transform;
for (int i = 0; i < 3; i++) {
- if (!(hash_compare_vector3(l->basis.elements[i], r->basis.elements[i])))
+ if (!(hash_compare_vector3(l->basis.elements[i], r->basis.elements[i]))) {
return false;
+ }
}
return hash_compare_vector3(l->origin, r->origin);
@@ -3079,31 +3279,38 @@ bool Variant::hash_compare(const Variant &p_variant) const {
const Array &l = *(reinterpret_cast<const Array *>(_data._mem));
const Array &r = *(reinterpret_cast<const Array *>(p_variant._data._mem));
- if (l.size() != r.size())
+ if (l.size() != r.size()) {
return false;
+ }
for (int i = 0; i < l.size(); ++i) {
- if (!l[i].hash_compare(r[i]))
+ if (!l[i].hash_compare(r[i])) {
return false;
+ }
}
return true;
} break;
- case POOL_REAL_ARRAY: {
- hash_compare_pool_array(_data._mem, p_variant._data._mem, real_t, hash_compare_scalar);
+ // This is for floating point comparisons only.
+ case PACKED_FLOAT32_ARRAY: {
+ hash_compare_packed_array(_data.packed_array, p_variant._data.packed_array, float, hash_compare_scalar);
} break;
- case POOL_VECTOR2_ARRAY: {
- hash_compare_pool_array(_data._mem, p_variant._data._mem, Vector2, hash_compare_vector2);
+ case PACKED_FLOAT64_ARRAY: {
+ hash_compare_packed_array(_data.packed_array, p_variant._data.packed_array, double, hash_compare_scalar);
} break;
- case POOL_VECTOR3_ARRAY: {
- hash_compare_pool_array(_data._mem, p_variant._data._mem, Vector3, hash_compare_vector3);
+ case PACKED_VECTOR2_ARRAY: {
+ hash_compare_packed_array(_data.packed_array, p_variant._data.packed_array, Vector2, hash_compare_vector2);
} break;
- case POOL_COLOR_ARRAY: {
- hash_compare_pool_array(_data._mem, p_variant._data._mem, Color, hash_compare_color);
+ case PACKED_VECTOR3_ARRAY: {
+ hash_compare_packed_array(_data.packed_array, p_variant._data.packed_array, Vector3, hash_compare_vector3);
+ } break;
+
+ case PACKED_COLOR_ARRAY: {
+ hash_compare_packed_array(_data.packed_array, p_variant._data.packed_array, Color, hash_compare_color);
} break;
default:
@@ -3117,38 +3324,35 @@ bool Variant::hash_compare(const Variant &p_variant) const {
}
bool Variant::is_ref() const {
-
- return type == OBJECT && !_get_obj().ref.is_null();
+ return type == OBJECT && _get_obj().id.is_reference();
}
Vector<Variant> varray() {
-
return Vector<Variant>();
}
Vector<Variant> varray(const Variant &p_arg1) {
-
Vector<Variant> v;
v.push_back(p_arg1);
return v;
}
-Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2) {
+Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2) {
Vector<Variant> v;
v.push_back(p_arg1);
v.push_back(p_arg2);
return v;
}
-Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3) {
+Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3) {
Vector<Variant> v;
v.push_back(p_arg1);
v.push_back(p_arg2);
v.push_back(p_arg3);
return v;
}
-Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4) {
+Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4) {
Vector<Variant> v;
v.push_back(p_arg1);
v.push_back(p_arg2);
@@ -3158,7 +3362,6 @@ Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Varia
}
Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5) {
-
Vector<Variant> v;
v.push_back(p_arg1);
v.push_back(p_arg2);
@@ -3172,12 +3375,13 @@ void Variant::static_assign(const Variant &p_variant) {
}
bool Variant::is_shared() const {
-
switch (type) {
-
- case OBJECT: return true;
- case ARRAY: return true;
- case DICTIONARY: return true;
+ case OBJECT:
+ return true;
+ case ARRAY:
+ return true;
+ case DICTIONARY:
+ return true;
default: {
}
}
@@ -3189,30 +3393,27 @@ Variant Variant::call(const StringName &p_method, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
- CallError error;
+ Callable::CallError error;
Variant ret = call(p_method, argptr, argc, error);
switch (error.error) {
-
- case CallError::CALL_ERROR_INVALID_ARGUMENT: {
-
- String err = "Invalid type for argument #" + itos(error.argument) + ", expected '" + Variant::get_type_name(error.expected) + "'.";
+ case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: {
+ String err = "Invalid type for argument #" + itos(error.argument) + ", expected '" + Variant::get_type_name(Variant::Type(error.expected)) + "'.";
ERR_PRINT(err.utf8().get_data());
} break;
- case CallError::CALL_ERROR_INVALID_METHOD: {
-
+ case Callable::CallError::CALL_ERROR_INVALID_METHOD: {
String err = "Invalid method '" + p_method + "' for type '" + Variant::get_type_name(type) + "'.";
ERR_PRINT(err.utf8().get_data());
} break;
- case CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: {
-
+ case Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: {
String err = "Too many arguments for method '" + p_method + "'";
ERR_PRINT(err.utf8().get_data());
} break;
@@ -3224,71 +3425,86 @@ Variant Variant::call(const StringName &p_method, VARIANT_ARG_DECLARE) {
}
void Variant::construct_from_string(const String &p_string, Variant &r_value, ObjectConstruct p_obj_construct, void *p_construct_ud) {
-
r_value = Variant();
}
String Variant::get_construct_string() const {
-
String vars;
VariantWriter::write_to_string(*this, vars);
return vars;
}
-String Variant::get_call_error_text(Object *p_base, const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Variant::CallError &ce) {
-
+String Variant::get_call_error_text(Object *p_base, const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) {
String err_text;
- if (ce.error == Variant::CallError::CALL_ERROR_INVALID_ARGUMENT) {
+ if (ce.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) {
int errorarg = ce.argument;
if (p_argptrs) {
- err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(ce.expected) + ".";
+ err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(Variant::Type(ce.expected)) + ".";
} else {
- err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(ce.expected) + ".";
+ err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(Variant::Type(ce.expected)) + ".";
}
- } else if (ce.error == Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) {
+ } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) {
err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + ".";
- } else if (ce.error == Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {
+ } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {
err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + ".";
- } else if (ce.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) {
+ } else if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) {
err_text = "Method not found.";
- } else if (ce.error == Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL) {
+ } else if (ce.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) {
err_text = "Instance is null";
- } else if (ce.error == Variant::CallError::CALL_OK) {
+ } else if (ce.error == Callable::CallError::CALL_OK) {
return "Call OK";
}
String class_name = p_base->get_class();
Ref<Script> script = p_base->get_script();
if (script.is_valid() && script->get_path().is_resource_file()) {
-
class_name += "(" + script->get_path().get_file() + ")";
}
return "'" + class_name + "::" + String(p_method) + "': " + err_text;
}
-String vformat(const String &p_text, const Variant &p1, const Variant &p2, const Variant &p3, const Variant &p4, const Variant &p5) {
+String Variant::get_callable_error_text(const Callable &p_callable, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) {
+ String err_text;
+
+ if (ce.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) {
+ int errorarg = ce.argument;
+ if (p_argptrs) {
+ err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(Variant::Type(ce.expected)) + ".";
+ } else {
+ err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(Variant::Type(ce.expected)) + ".";
+ }
+ } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) {
+ err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + ".";
+ } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {
+ err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + ".";
+ } else if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) {
+ err_text = "Method not found.";
+ } else if (ce.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) {
+ err_text = "Instance is null";
+ } else if (ce.error == Callable::CallError::CALL_OK) {
+ return "Call OK";
+ }
+ return String(p_callable) + " : " + err_text;
+}
+
+String vformat(const String &p_text, const Variant &p1, const Variant &p2, const Variant &p3, const Variant &p4, const Variant &p5) {
Array args;
if (p1.get_type() != Variant::NIL) {
-
args.push_back(p1);
if (p2.get_type() != Variant::NIL) {
-
args.push_back(p2);
if (p3.get_type() != Variant::NIL) {
-
args.push_back(p3);
if (p4.get_type() != Variant::NIL) {
-
args.push_back(p4);
if (p5.get_type() != Variant::NIL) {
-
args.push_back(p5);
}
}