From a79fd56051a759751bf8e07ca982072707ed412e Mon Sep 17 00:00:00 2001 From: Kevin Trogant Date: Sat, 3 Aug 2024 12:43:09 +0200 Subject: [PATCH] feat(cvar): Unsigned integer type for cvars --- src/runtime/config.c | 6 ++++++ src/runtime/config.h | 6 +++++- src/runtime/runtime.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/runtime/config.c b/src/runtime/config.c index 0914376..d4e92ce 100644 --- a/src/runtime/config.c +++ b/src/runtime/config.c @@ -102,6 +102,9 @@ RT_DLLEXPORT void rtNotifyCVARChange(const rt_cvar *cvar) { case RT_CVAR_TYPE_SIZE: rtLog("CVAR", "Changed %s to %zu.", cvar->name, cvar->sz); break; + case RT_CVAR_TYPE_UINT: + rtLog("CVAR", "Changed %s to %u.", cvar->name, cvar->ui); + break; default: rtLog("CVAR", "Changed %s, but the cvar has an invalid type.", cvar->name); break; @@ -299,6 +302,9 @@ RT_DLLEXPORT rt_result rtSetCVARFromString(rt_cvar *cvar, const char *value_str) case RT_CVAR_TYPE_SIZE: num_read = sscanf(value_str, "%zu", &cvar->sz); break; + case RT_CVAR_TYPE_UINT: + num_read = sscanf(value_str, "%u", &cvar->ui); + break; default: rtReportError("CVAR", "CVar %s has an invalid type.", cvar->name); return 0; diff --git a/src/runtime/config.h b/src/runtime/config.h index e5ce05f..a1c5952 100644 --- a/src/runtime/config.h +++ b/src/runtime/config.h @@ -13,6 +13,7 @@ typedef enum { RT_CVAR_TYPE_FLOAT, RT_CVAR_TYPE_STRING, RT_CVAR_TYPE_SIZE, + RT_CVAR_TYPE_UINT, } rt_cvar_type; typedef struct { @@ -23,6 +24,7 @@ typedef struct { float f; const char *s; size_t sz; + unsigned int ui; }; rt_cvar_type type; } rt_cvar; @@ -38,12 +40,14 @@ typedef void(rt_cvar_change_event_handler_fn)(rt_cvar *cvar, void *userdata); rt_cvar n = {.name = #n, .description = d, .s = (v), .type = RT_CVAR_TYPE_STRING} #define RT_CVAR_SZ(n, d, v) \ rt_cvar n = {.name = #n, .description = d, .sz = (v), .type = RT_CVAR_TYPE_SIZE} +#define RT_CVAR_UI(n, d, v) \ + rt_cvar n = {.name = #n, .description = d, .ui = (v), .type = RT_CVAR_TYPE_UINT} RT_DLLEXPORT void rtRegisterCVAR(rt_cvar *cvar); RT_DLLEXPORT rt_cvar *rtGetCVAR(const char *name); -/* Change event handlers are called when rtNotifyCVARChange is called. +/* Change event handlers are called when rtNotifyCVARChange is called. * The system gives no guarantees about the order in which these are called. * * NOTE: A internal mutex is held while the event handlers run, which means that */ diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index 6ccad0a..f1a1736 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -75,6 +75,7 @@ enum { RT_SUCCESS = 0, RT_OUT_OF_MEMORY = 1, RT_INVALID_VALUE = 2, + RT_NOT_SUPPORTED = 3, RT_CUSTOM_ERROR_START,