Skip to content

Commit

Permalink
Support PackedColorArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Daylily-Zeleen committed Sep 7, 2024
1 parent ee629e5 commit 77634fa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
44 changes: 44 additions & 0 deletions src/dserializer.gdany.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum DType : uint8_t {
PACKED_VECTOR2_ARRAY,
PACKED_VECTOR3_ARRAY,
PACKED_COLOR_ARRAY,
PACKED_VECTOR4_ARRAY,

VARIANT_MAX,

Expand Down Expand Up @@ -792,6 +793,9 @@ _INLINE_ void cal_size_variant(const Variant &p_val, integral_t &r_len, const ui
case Variant::PACKED_VECTOR3_ARRAY: {
cal_size<little_endin>(p_val.operator godot::PackedVector3Array(), r_len);
} break;
case DType::PACKED_VECTOR4_ARRAY: {
cal_size<little_endin>(p_val.operator godot::PackedVector4Array(), r_len);
} break;
case DType::PACKED_COLOR_ARRAY: {
cal_size_color_arr<little_endin, 0>(p_val.operator godot::PackedColorArray(), r_len);
} break;
Expand Down Expand Up @@ -946,6 +950,9 @@ _INLINE_ void encode_variant(buffer_t *&p_buf, const Variant &p_val, const uint8
case Variant::PACKED_VECTOR3_ARRAY: {
encode<little_endin>(p_buf, p_val.operator godot::PackedVector3Array());
} break;
case Variant::PACKED_VECTOR4_ARRAY: {
encode<little_endin>(p_buf, p_val.operator godot::PackedVector4Array());
} break;
case Variant::PACKED_COLOR_ARRAY: {
encode_color_arr<little_endin, 0>(p_buf, p_val.operator godot::PackedColorArray());
} break;
Expand Down Expand Up @@ -1101,6 +1108,9 @@ _INLINE_ void encode_variant(buffer_t *&p_buf, const Variant &p_val, const uint8
case Variant::PACKED_VECTOR3_ARRAY: {
encode<little_endin>(p_buf, p_val.operator godot::PackedVector3Array(), r_len);
} break;
case Variant::PACKED_VECTOR4_ARRAY: {
encode<little_endin>(p_buf, p_val.operator godot::PackedVector4Array(), r_len);
} break;
case Variant::PACKED_COLOR_ARRAY: {
encode_color_arr<little_endin, 0>(p_buf, p_val.operator godot::PackedColorArray(), r_len);
} break;
Expand Down Expand Up @@ -1373,6 +1383,15 @@ _INLINE_ void decode_variant(buffer_t *&p_buf, Variant &p_val, const uint8_t &ty
p_val = v;
}
} break;
case DType::PACKED_VECTOR4_ARRAY: {
if (empty) {
p_val = godot::PackedVector4Array();
} else {
godot::PackedVector4Array v;
decode<little_endin>(p_buf, v);
p_val = v;
}
} break;
case DType::PACKED_COLOR_ARRAY: {
if (empty) {
p_val = godot::PackedColorArray();
Expand Down Expand Up @@ -1497,6 +1516,13 @@ _INLINE_ void cal_size(const Variant &p_val, integral_t &r_len) {
}
cal_size<little_endin>(arr, r_len);
} break;
case Variant::PACKED_VECTOR4_ARRAY: {
auto arr = p_val.operator godot::PackedVector4Array();
if (arr.is_empty()) {
return;
}
cal_size<little_endin>(arr, r_len);
} break;
case Variant::PACKED_STRING_ARRAY: {
auto arr = p_val.operator godot::PackedStringArray();
if (arr.is_empty()) {
Expand Down Expand Up @@ -1672,6 +1698,15 @@ _INLINE_ void encode(buffer_t *&p_buf, const Variant &p_val) {
encode_type<little_endin>(p_buf, DType::PACKED_VECTOR3_ARRAY);
encode<little_endin>(p_buf, arr);
} break;
case Variant::PACKED_VECTOR4_ARRAY: {
auto arr = p_val.operator godot::PackedVector4Array();
if (arr.is_empty()) {
encode_type<little_endin>(p_buf, DType::PACKED_VECTOR4_ARRAY | 0x80);
return;
}
encode_type<little_endin>(p_buf, DType::PACKED_VECTOR4_ARRAY);
encode<little_endin>(p_buf, arr);
} break;
case Variant::PACKED_STRING_ARRAY: {
auto arr = p_val.operator godot::PackedStringArray();
if (arr.is_empty()) {
Expand Down Expand Up @@ -1840,6 +1875,15 @@ _INLINE_ void encode(buffer_t *&p_buf, const Variant &p_val, integral_t &r_len)
encode_type<little_endin>(p_buf, DType::PACKED_VECTOR3_ARRAY, r_len);
encode<little_endin>(p_buf, arr, r_len);
} break;
case Variant::PACKED_VECTOR4_ARRAY: {
auto arr = p_val.operator godot::PackedVector4Array();
if (arr.is_empty()) {
encode_type<little_endin>(p_buf, DType::PACKED_VECTOR4_ARRAY | 0x80, r_len);
return;
}
encode_type<little_endin>(p_buf, DType::PACKED_VECTOR4_ARRAY, r_len);
encode<little_endin>(p_buf, arr, r_len);
} break;
case Variant::PACKED_STRING_ARRAY: {
auto arr = p_val.operator godot::PackedStringArray();
if (arr.is_empty()) {
Expand Down
6 changes: 4 additions & 2 deletions src/dserializer.gdbase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ concept GodotFixedElementLenthArray = !Number<T> &&
(GodotPackedIntArray<T> ||
std::same_as<T, PackedByteArray> || std::same_as<T, PackedFloat32Array> ||
std::same_as<T, PackedFloat64Array> || std::same_as<T, PackedVector2Array> ||
std::same_as<T, PackedVector3Array> || std::same_as<T, PackedColorArray>);
std::same_as<T, PackedVector3Array> || std::same_as<T, PackedVector4Array> ||
std::same_as<T, PackedColorArray>);
#define godot_fixed_element_length_array_t GodotFixedElementLenthArray auto

#else // HAS_CXX20
Expand Down Expand Up @@ -106,7 +107,8 @@ using GodotPackedIntArray = T;
std::is_same_v<T, PackedInt32Array> || std::is_same_v<T, PackedInt64Array> || \
std::is_same_v<T, PackedByteArray> || std::is_same_v<T, PackedFloat32Array> || \
std::is_same_v<T, PackedFloat64Array> || std::is_same_v<T, PackedVector2Array> || \
std::is_same_v<T, PackedVector3Array> || std::is_same_v<T, PackedColorArray>> *_##T = nullptr
std::is_same_v<T, PackedVector3Array> || std::is_same_v<T, PackedVector4Array> || \
std::is_same_v<T, PackedColorArray>> *_##T = nullptr
template <typename T, IS_GODOT_FIXED_ELEMENT_LENGTH_ARRAY_T(T)>
using GodotFixedElementLengthArray = T;
#define godot_fixed_element_length_array_t GodotFixedElementLengthArray<TGodotFixedElementLengthArray>
Expand Down

0 comments on commit 77634fa

Please sign in to comment.