#pragma once #include "core/templates/vector.h" #include "core/object/ref_counted.h" #include "core/variant/variant.h" #include "core/variant/typed_array.h" template TypedArray VectorToTypedArray(const Vector>& vector) { TypedArray arr; arr.resize(vector.size()); for (int i{}; i < vector.size(); ++i) { arr[i] = Variant(vector[i]); } return arr; } template Vector> TypedArrayToVector(const TypedArray& arr) { Vector> vector; vector.resize(arr.size()); for (int i{}; i < vector.size(); ++i) { vector.set(i, Ref(arr[i])); } return vector; } template TypedArray VectorToTypedArrayVariant(const Vector& vector) { TypedArray arr; arr.resize(vector.size()); for (int i{}; i < vector.size(); ++i) { arr[i] = Variant(vector[i]); } return arr; } template Vector TypedArrayToVectorVariant(const TypedArray& arr) { Vector vector; vector.resize(arr.size()); for (int i{}; i < vector.size(); ++i) { vector.set(i, arr[i]); } return vector; } template TypedArray VectorToTypedArrayCast(const Vector& vector) { TypedArray arr; arr.resize(vector.size()); for (int i{}; i < vector.size(); ++i) { arr[i] = Variant(static_cast(vector[i])); } return arr; } // template // static Type get_type_t(); // template <> static Type get_type_t() { return Type::BOOL; } // template <> static Type get_type_t() { return Type::INT; } // template <> static Type get_type_t() { return Type::FLOAT; } // template <> static Type get_type_t() { return Type::STRING; } // template <> static Type get_type_t() { return Type::VECTOR2; } // template <> static Type get_type_t() { return Type::VECTOR2I; } // template <> static Type get_type_t() { return Type::RECT2; } // template <> static Type get_type_t() { return Type::RECT2I; } // template <> static Type get_type_t() { return Type::VECTOR3; } // template <> static Type get_type_t() { return Type::VECTOR3I; } // template <> static Type get_type_t() { return Type::TRANSFORM2D; } // template <> static Type get_type_t() { return Type::VECTOR4; } // template <> static Type get_type_t() { return Type::VECTOR4I; } // template <> static Type get_type_t() { return Type::PLANE; } // template <> static Type get_type_t() { return Type::QUATERNION; } // template <> static Type get_type_t<::AABB>() { return Type::AABB; } // template <> static Type get_type_t() { return Type::BASIS; } // template <> static Type get_type_t() { return Type::TRANSFORM3D; } // template <> static Type get_type_t() { return Type::PROJECTION; } // template <> static Type get_type_t() { return Type::COLOR; } // template <> static Type get_type_t() { return Type::STRING_NAME; } // template <> static Type get_type_t() { return Type::NODE_PATH; } // template <> static Type get_type_t<::RID>() { return Type::RID; } // template <> static Type get_type_t() { return Type::OBJECT; } // template <> static Type get_type_t() { return Type::CALLABLE; } // template <> static Type get_type_t() { return Type::SIGNAL; } // template <> static Type get_type_t() { return Type::DICTIONARY; } // template <> static Type get_type_t() { return Type::ARRAY; } // template <> static Type get_type_t() { return Type::PACKED_BYTE_ARRAY; } // template <> static Type get_type_t() { return Type::PACKED_INT32_ARRAY; } // template <> static Type get_type_t() { return Type::PACKED_INT64_ARRAY; } // template <> static Type get_type_t() { return Type::PACKED_FLOAT32_ARRAY; } // template <> static Type get_type_t() { return Type::PACKED_FLOAT64_ARRAY; } // template <> static Type get_type_t() { return Type::PACKED_STRING_ARRAY; } // template <> static Type get_type_t() { return Type::PACKED_VECTOR2_ARRAY; } // template <> static Type get_type_t() { return Type::PACKED_VECTOR3_ARRAY; } // template <> static Type get_type_t() { return Type::PACKED_COLOR_ARRAY; } // template <> static Type get_type_t() { return Type::PACKED_VECTOR4_ARRAY; } // //template static Type get_type_t() { return Type::NIL; } // bool get_unsafe_bool() const { DEV_ASSERT(type == Type::BOOL); return _data._bool; } // int get_unsafe_int() const { DEV_ASSERT(type == Type::INT); return _data._int; } // float get_unsafe_float() const { DEV_ASSERT(type == Type::FLOAT); return _data._float; } // String get_unsafe_string() const { DEV_ASSERT(type == Type::STRING); return *reinterpret_cast(_data._mem); } // Vector2 get_unsafe_vector2() const { DEV_ASSERT(type == Type::VECTOR2); return *reinterpret_cast(_data._mem); } // Vector2i get_unsafe_vector2i() const { DEV_ASSERT(type == Type::VECTOR2I); return *reinterpret_cast(_data._mem); } // Vector3 get_unsafe_vector3() const { DEV_ASSERT(type == Type::VECTOR3); return *reinterpret_cast(_data._mem); } // Vector3i get_unsafe_vector3i() const { DEV_ASSERT(type == Type::VECTOR3I); return *reinterpret_cast(_data._mem); } // Transform2D get_unsafe_transform2d() const { DEV_ASSERT(type == Type::TRANSFORM2D); return *reinterpret_cast(_data._mem); } // Vector4 get_unsafe_vector4() const { DEV_ASSERT(type == Type::VECTOR4); return *reinterpret_cast(_data._mem); } // Vector4i get_unsafe_vector4i() const { DEV_ASSERT(type == Type::VECTOR4I); return *reinterpret_cast(_data._mem); } // Plane get_unsafe_plane() const { DEV_ASSERT(type == Type::PLANE); return *reinterpret_cast(_data._mem); } // Quaternion get_unsafe_quaternion() const { DEV_ASSERT(type == Type::QUATERNION); return *reinterpret_cast(_data._mem); } // ::AABB get_unsafe_aabb() const { DEV_ASSERT(type == Type::AABB); return *reinterpret_cast(_data._mem); } // Basis get_unsafe_basis() const { DEV_ASSERT(type == Type::BASIS); return *reinterpret_cast(_data._mem); } // Transform3D get_unsafe_transform3d() const { DEV_ASSERT(type == Type::TRANSFORM3D); return *reinterpret_cast(_data._mem); } // Projection get_unsafe_projection() const { DEV_ASSERT(type == Type::PROJECTION); return *reinterpret_cast(_data._mem); } // Color get_unsafe_color() const { DEV_ASSERT(type == Type::COLOR); return *reinterpret_cast(_data._mem); } // StringName get_unsafe_string_name() const { DEV_ASSERT(type == Type::STRING_NAME); return *reinterpret_cast(_data._mem); } // NodePath get_unsafe_node_path() const { DEV_ASSERT(type == Type::NODE_PATH); return *reinterpret_cast(_data._mem); } // ::RID get_unsafe_rid() const { DEV_ASSERT(type == Type::RID); return *reinterpret_cast(_data._mem); } // Object* get_unsafe_object() const { DEV_ASSERT(type == Type::OBJECT); return reinterpret_cast(&_data._mem[0])->obj; } // Callable get_unsafe_callable() const { DEV_ASSERT(type == Type::CALLABLE); return *reinterpret_cast(_data._mem); } // Signal get_unsafe_signal() const { DEV_ASSERT(type == Type::SIGNAL); return *reinterpret_cast(_data._mem); } // Dictionary get_unsafe_dictionary() const { DEV_ASSERT(type == Type::DICTIONARY); return *reinterpret_cast(_data._mem); } // Array get_unsafe_array() const { DEV_ASSERT(type == Type::ARRAY); return *reinterpret_cast(_data._mem); } // PackedByteArray get_unsafe_packed_byte_array() const { DEV_ASSERT(type == Type::PACKED_BYTE_ARRAY); return static_cast *>(_data.packed_array)->array; } // PackedInt32Array get_unsafe_packed_int32_array() const { DEV_ASSERT(type == Type::PACKED_INT32_ARRAY); return static_cast *>(_data.packed_array)->array; } // PackedInt64Array get_unsafe_packed_int64_array() const { DEV_ASSERT(type == Type::PACKED_INT64_ARRAY); return static_cast *>(_data.packed_array)->array; } // PackedFloat32Array get_unsafe_packed_float32_array() const { DEV_ASSERT(type == Type::PACKED_FLOAT32_ARRAY); return static_cast *>(_data.packed_array)->array; } // PackedFloat64Array get_unsafe_packed_float64_array() const { DEV_ASSERT(type == Type::PACKED_FLOAT64_ARRAY); return static_cast *>(_data.packed_array)->array; } // PackedStringArray get_unsafe_packed_string_array() const { DEV_ASSERT(type == Type::PACKED_STRING_ARRAY); return static_cast *>(_data.packed_array)->array; } // PackedVector2Array get_unsafe_packed_vector2_array() const { DEV_ASSERT(type == Type::PACKED_VECTOR2_ARRAY); return static_cast *>(_data.packed_array)->array; } // PackedVector3Array get_unsafe_packed_vector3_array() const { DEV_ASSERT(type == Type::PACKED_VECTOR3_ARRAY); return static_cast *>(_data.packed_array)->array; } // PackedColorArray get_unsafe_packed_color_array() const { DEV_ASSERT(type == Type::PACKED_COLOR_ARRAY); return static_cast *>(_data.packed_array)->array; } // PackedVector4Array get_unsafe_packed_vector4_array() const { DEV_ASSERT(type == Type::PACKED_VECTOR4_ARRAY); return static_cast *>(_data.packed_array)->array; } // template // T get_unsafe_t() const; // template <> bool get_unsafe_t() const { return get_unsafe_bool(); } // template <> int get_unsafe_t() const { return get_unsafe_int(); } // template <> float get_unsafe_t() const { return get_unsafe_float(); } // template <> String get_unsafe_t() const { return get_unsafe_string(); } // template <> Vector2 get_unsafe_t() const { return get_unsafe_vector2(); } // template <> Vector2i get_unsafe_t() const { return get_unsafe_vector2i(); } // template <> Vector3 get_unsafe_t() const { return get_unsafe_vector3(); } // template <> Vector3i get_unsafe_t() const { return get_unsafe_vector3i(); } // template <> Transform2D get_unsafe_t() const { return get_unsafe_transform2d(); } // template <> Vector4 get_unsafe_t() const { return get_unsafe_vector4(); } // template <> Vector4i get_unsafe_t() const { return get_unsafe_vector4i(); } // template <> Plane get_unsafe_t() const { return get_unsafe_plane(); } // template <> Quaternion get_unsafe_t() const { return get_unsafe_quaternion(); } // template <> ::AABB get_unsafe_t<::AABB>() const { return get_unsafe_aabb(); } // template <> Basis get_unsafe_t() const { return get_unsafe_basis(); } // template <> Transform3D get_unsafe_t() const { return get_unsafe_transform3d(); } // template <> Projection get_unsafe_t() const { return get_unsafe_projection(); } // template <> Color get_unsafe_t() const { return get_unsafe_color(); } // template <> StringName get_unsafe_t() const { return get_unsafe_string_name(); } // template <> NodePath get_unsafe_t() const { return get_unsafe_node_path(); } // template <> ::RID get_unsafe_t<::RID>() const { return get_unsafe_rid(); } // template <> Object* get_unsafe_t() const { return get_unsafe_object(); } // template <> Callable get_unsafe_t() const { return get_unsafe_callable(); } // template <> Signal get_unsafe_t() const { return get_unsafe_signal(); } // template <> Dictionary get_unsafe_t() const { return get_unsafe_dictionary(); } // template <> Array get_unsafe_t() const { return get_unsafe_array(); } // template <> PackedByteArray get_unsafe_t() const { return get_unsafe_packed_byte_array(); } // template <> PackedInt32Array get_unsafe_t() const { return get_unsafe_packed_int32_array(); } // template <> PackedInt64Array get_unsafe_t() const { return get_unsafe_packed_int64_array(); } // template <> PackedFloat32Array get_unsafe_t() const { return get_unsafe_packed_float32_array(); } // template <> PackedFloat64Array get_unsafe_t() const { return get_unsafe_packed_float64_array(); } // template <> PackedStringArray get_unsafe_t() const { return get_unsafe_packed_string_array(); } // template <> PackedVector2Array get_unsafe_t() const { return get_unsafe_packed_vector2_array(); } // template <> PackedVector3Array get_unsafe_t() const { return get_unsafe_packed_vector3_array(); } // template <> PackedColorArray get_unsafe_t() const { return get_unsafe_packed_color_array(); } // template <> PackedVector4Array get_unsafe_t() const { return get_unsafe_packed_vector4_array(); }