Skip to content

Commit

Permalink
Merge branch 'variant-set' into radiant-fork
Browse files Browse the repository at this point in the history
  • Loading branch information
RadiantUwU committed Jul 21, 2024
2 parents d299ba5 + a6f4e86 commit 61b19b5
Show file tree
Hide file tree
Showing 65 changed files with 1,560 additions and 19 deletions.
1 change: 1 addition & 0 deletions core/core_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ void register_global_constants() {
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_VECTOR3_ARRAY", Variant::PACKED_VECTOR3_ARRAY);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_COLOR_ARRAY", Variant::PACKED_COLOR_ARRAY);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_VECTOR4_ARRAY", Variant::PACKED_VECTOR4_ARRAY);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_SET", Variant::SET);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_MAX", Variant::VARIANT_MAX);

//comparison
Expand Down
1 change: 1 addition & 0 deletions core/extension/extension_api_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api(bool p_include_docs) {
{ Variant::PACKED_VECTOR3_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
{ Variant::PACKED_COLOR_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
{ Variant::PACKED_VECTOR4_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
{ Variant::SET, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
{ Variant::VARIANT_MAX, sizeof(uint64_t) + sizeof(float) * 4, sizeof(uint64_t) + sizeof(float) * 4, sizeof(uint64_t) + sizeof(double) * 4, sizeof(uint64_t) + sizeof(double) * 4 },
};

Expand Down
4 changes: 4 additions & 0 deletions core/extension/gdextension_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@ static GDExtensionVariantFromTypeConstructorFunc gdextension_get_variant_from_ty
return VariantTypeConstructor<Dictionary>::variant_from_type;
case GDEXTENSION_VARIANT_TYPE_ARRAY:
return VariantTypeConstructor<Array>::variant_from_type;
case GDEXTENSION_VARIANT_TYPE_SET:
return VariantTypeConstructor<Set>::variant_from_type;
case GDEXTENSION_VARIANT_TYPE_PACKED_BYTE_ARRAY:
return VariantTypeConstructor<PackedByteArray>::variant_from_type;
case GDEXTENSION_VARIANT_TYPE_PACKED_INT32_ARRAY:
Expand Down Expand Up @@ -664,6 +666,8 @@ static GDExtensionTypeFromVariantConstructorFunc gdextension_get_variant_to_type
return VariantTypeConstructor<Dictionary>::type_from_variant;
case GDEXTENSION_VARIANT_TYPE_ARRAY:
return VariantTypeConstructor<Array>::type_from_variant;
case GDEXTENSION_VARIANT_TYPE_SET:
return VariantTypeConstructor<Set>::type_from_variant;
case GDEXTENSION_VARIANT_TYPE_PACKED_BYTE_ARRAY:
return VariantTypeConstructor<PackedByteArray>::type_from_variant;
case GDEXTENSION_VARIANT_TYPE_PACKED_INT32_ARRAY:
Expand Down
2 changes: 2 additions & 0 deletions core/extension/gdextension_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ typedef enum {
GDEXTENSION_VARIANT_TYPE_PACKED_COLOR_ARRAY,
GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR4_ARRAY,

GDEXTENSION_VARIANT_TYPE_SET,

GDEXTENSION_VARIANT_TYPE_VARIANT_MAX
} GDExtensionVariantType;

Expand Down
67 changes: 66 additions & 1 deletion core/io/marshalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = carray;

} break;

case Variant::PACKED_VECTOR4_ARRAY: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
Expand Down Expand Up @@ -1244,6 +1243,47 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
}
r_variant = varray;

} break;

case Variant::SET: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
len -= 4;

Set set;

ERR_FAIL_MUL_OF(count, sizeof(double) * 4, ERR_INVALID_DATA);
ERR_FAIL_COND_V(count < 0 || count * sizeof(double) * 4 > (size_t)len, ERR_INVALID_DATA);

if (r_len) {
(*r_len) += 4; // Size of count number.
}

if (count) {
for (int i = 0; i < count; i++) {
int used = 0;
Variant v;
Error err = decode_variant(v, buf, len, &used, p_allow_objects, p_depth + 1);
ERR_FAIL_COND_V_MSG(err != OK, err, "Error when trying to decode Variant.");
buf += used;
len -= used;
set.add(v);
if (r_len) {
(*r_len) += used;
}
}

int adv = sizeof(double) * 4 * count;

if (r_len) {
(*r_len) += adv;
}
len -= adv;
buf += adv;
}
r_variant = set;

} break;
default: {
ERR_FAIL_V(ERR_BUG);
Expand Down Expand Up @@ -2040,6 +2080,31 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += sizeof(real_t) * 4 * len;

} break;

case Variant::SET: {
Set data = p_variant;
int len = data.size();

if (buf) {
encode_uint32(len, buf);
buf += 4;
}

r_len += 4;

if (buf) {
for (const Variant &var : data) {
int buf_len;
Error err = encode_variant(var, buf, buf_len, p_full_objects, p_depth + 1);
ERR_FAIL_COND_V(err, err);
ERR_FAIL_COND_V(buf_len % 4, ERR_BUG);
if (buf) {
buf += buf_len;
}
r_len += buf_len;
}
}
} break;
default: {
ERR_FAIL_V(ERR_BUG);
}
Expand Down
1 change: 1 addition & 0 deletions core/io/packed_data_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
case Variant::PACKED_COLOR_ARRAY:
case Variant::PACKED_VECTOR4_ARRAY:
case Variant::STRING_NAME:
case Variant::SET:
case Variant::NODE_PATH: {
uint32_t pos = tmpdata.size();
int len;
Expand Down
3 changes: 2 additions & 1 deletion core/io/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
case Variant::Type::PACKED_STRING_ARRAY:
case Variant::Type::PACKED_VECTOR2_ARRAY:
case Variant::Type::PACKED_VECTOR3_ARRAY:
case Variant::Type::PACKED_VECTOR4_ARRAY: {
case Variant::Type::PACKED_VECTOR4_ARRAY:
case Variant::Type::SET: {
r->set(E.name, p.duplicate(p_subresources));
} break;

Expand Down
28 changes: 27 additions & 1 deletion core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ enum {
VARIANT_VECTOR4I = 51,
VARIANT_PROJECTION = 52,
VARIANT_PACKED_VECTOR4_ARRAY = 53,
VARIANT_SET = 54,
OBJECT_EMPTY = 0,
OBJECT_EXTERNAL_RESOURCE = 1,
OBJECT_INTERNAL_RESOURCE = 2,
Expand All @@ -95,7 +96,8 @@ enum {
// Version 4: New string ID for ext/subresources, breaks forward compat.
// Version 5: Ability to store script class in the header.
// Version 6: Added PackedVector4Array Variant type.
FORMAT_VERSION = 6,
// Version 7: Added Set Variant type.
FORMAT_VERSION = 7,
FORMAT_VERSION_CAN_RENAME_DEPS = 1,
FORMAT_VERSION_NO_NODEPATH_PROPERTY = 3,
};
Expand Down Expand Up @@ -667,6 +669,21 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {

r_v = array;

} break;
case VARIANT_SET: {
uint32_t len = f->get_32();

Set set;

for (uint32_t i = 0; i < len; i++) {
Variant v;
const Error err = parse_variant(v);
ERR_FAIL_COND_V(err != OK, err);
set.add(v);
}

r_v = set;

} break;
default: {
ERR_FAIL_V(ERR_FILE_CORRUPT);
Expand Down Expand Up @@ -2004,6 +2021,15 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref<FileAccess> f, const V
f->store_real(r[i].w);
}

} break;
case Variant::SET: {
f->store_32(VARIANT_SET);
Set set = p_property;
f->store_32(set.size());
for (const Variant &var : set) {
write_variant(f, var, resource_map, external_resources, string_map);
}

} break;
default: {
ERR_FAIL_MSG("Invalid variant.");
Expand Down
1 change: 1 addition & 0 deletions core/object/script_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ void ScriptLanguage::get_core_type_words(List<String> *p_core_type_words) const
p_core_type_words->push_back("PackedVector3Array");
p_core_type_words->push_back("PackedColorArray");
p_core_type_words->push_back("PackedVector4Array");
p_core_type_words->push_back("Set");
}

void ScriptLanguage::frame() {
Expand Down
1 change: 1 addition & 0 deletions core/variant/method_ptrcall.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ MAKE_PTRARG(PackedVector2Array);
MAKE_PTRARG(PackedVector3Array);
MAKE_PTRARG(PackedColorArray);
MAKE_PTRARG(PackedVector4Array);
MAKE_PTRARG(Set);
MAKE_PTRARG_BY_REFERENCE(Variant);

// This is for Object.
Expand Down
Loading

0 comments on commit 61b19b5

Please sign in to comment.