From 901619235b70d55d09f2f7b0a7108d965c69f3ba Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 29 Nov 2021 13:43:07 +0900 Subject: [PATCH] [vulkan] Split out cvar enum parsing code Need to reuse it :) --- .../video/renderer/vulkan/vulkan_vid_common.c | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/libs/video/renderer/vulkan/vulkan_vid_common.c b/libs/video/renderer/vulkan/vulkan_vid_common.c index 2209f89e0..b7a6530ac 100644 --- a/libs/video/renderer/vulkan/vulkan_vid_common.c +++ b/libs/video/renderer/vulkan/vulkan_vid_common.c @@ -86,6 +86,21 @@ cvar_t *vulkan_frame_count; cvar_t *vulkan_presentation_mode; cvar_t *msaaSamples; +static void +parse_cvar_enum (const char *enum_name, const char *err_str, int err_val, + cvar_t *var) +{ + exprctx_t context = {}; + context.memsuper = new_memsuper(); + + if (cexpr_parse_enum (QFV_GetEnum (enum_name), var->string, + &context, &var->int_val)) { + Sys_Printf ("%s\n", err_str); + var->int_val = err_val; + } + delete_memsuper (context.memsuper); +} + static void vulkan_presentation_mode_f (cvar_t *var) { @@ -115,15 +130,8 @@ vulkan_frame_count_f (cvar_t *var) static void msaaSamples_f (cvar_t *var) { - exprctx_t context = {}; - context.memsuper = new_memsuper(); - - if (cexpr_parse_enum (QFV_GetEnum ("VkSampleCountFlagBits"), var->string, - &context, &var->int_val)) { - Sys_Printf ("Invalid MSAA samples, using 1\n"); - var->int_val = VK_SAMPLE_COUNT_1_BIT; - } - delete_memsuper (context.memsuper); + parse_cvar_enum ("VkSampleCountFlagBits", "Invalid MSAA samples, using 1", + VK_SAMPLE_COUNT_1_BIT, var); } static void