From eb4d5668011bb26443add0ed8582291544c10c75 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 3 Apr 2022 11:11:28 +0900 Subject: [PATCH] [vkparse] Add support for inheriting objects It simply parses the referenced plist dictionary (via @inherit = plist.path;) into the current data block, then allows the data to be overwritten by the current plist dictionary. This may be a bit iffy for any allocated resources, so some care must be taken, but it seems to work nicely. --- libs/video/renderer/vulkan/vkgen/vkstruct.r | 3 +++ libs/video/renderer/vulkan/vkparse.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/libs/video/renderer/vulkan/vkgen/vkstruct.r b/libs/video/renderer/vulkan/vkgen/vkstruct.r index 500659bc0..cd580849b 100644 --- a/libs/video/renderer/vulkan/vkgen/vkstruct.r +++ b/libs/video/renderer/vulkan/vkgen/vkstruct.r @@ -130,6 +130,9 @@ [field_def writeParseData]; } fprintf (output_file, "static plfield_t %s_fields[] = {\n", [self outname]); + fprintf (output_file, + "\t{\"@inherit\", 0, QFString, parse_inherit, &%s_fields},\n", + [self outname]); for (int i = [field_defs count]; i-- > 0; ) { FieldDef *field_def = [field_defs objectAtIndex:i]; [field_def writeField]; diff --git a/libs/video/renderer/vulkan/vkparse.c b/libs/video/renderer/vulkan/vkparse.c index 97fdd813d..e6c084672 100644 --- a/libs/video/renderer/vulkan/vkparse.c +++ b/libs/video/renderer/vulkan/vkparse.c @@ -376,6 +376,24 @@ parse_custom (const plfield_t *field, const plitem_t *item, return custom->parse (item, offsets, messages, context); } +static int +parse_inherit (const plfield_t *field, const plitem_t *item, + void *data, plitem_t *messages, void *context) +{ + exprctx_t ectx = *((parsectx_t *)context)->ectx; + plitem_t *inheritItem = 0; + exprval_t result = { &cexpr_plitem, &inheritItem }; + ectx.result = &result; + const char *inheritstr = PL_String (item); + Sys_MaskPrintf (SYS_vulkan_parse, "parse_inherit: %s\n", inheritstr); + int ret = !cexpr_eval_string (inheritstr, &ectx); + if (ret) { + ret = PL_ParseStruct (field->data, inheritItem, data, messages, + context); + } + return ret; +} + static int parse_RGBA (const plitem_t *item, void **data, plitem_t *messages, parsectx_t *context)