feat(cvar): Unsigned integer type for cvars
Some checks failed
Ubuntu Cross to Win64 / Cross Compile with ming64 (1.4.0, ubuntu-latest) (push) Failing after 1m51s

This commit is contained in:
Kevin Trogant 2024-08-03 12:43:09 +02:00
parent beba96b915
commit a79fd56051
3 changed files with 12 additions and 1 deletions

View File

@ -102,6 +102,9 @@ RT_DLLEXPORT void rtNotifyCVARChange(const rt_cvar *cvar) {
case RT_CVAR_TYPE_SIZE: case RT_CVAR_TYPE_SIZE:
rtLog("CVAR", "Changed %s to %zu.", cvar->name, cvar->sz); rtLog("CVAR", "Changed %s to %zu.", cvar->name, cvar->sz);
break; break;
case RT_CVAR_TYPE_UINT:
rtLog("CVAR", "Changed %s to %u.", cvar->name, cvar->ui);
break;
default: default:
rtLog("CVAR", "Changed %s, but the cvar has an invalid type.", cvar->name); rtLog("CVAR", "Changed %s, but the cvar has an invalid type.", cvar->name);
break; break;
@ -299,6 +302,9 @@ RT_DLLEXPORT rt_result rtSetCVARFromString(rt_cvar *cvar, const char *value_str)
case RT_CVAR_TYPE_SIZE: case RT_CVAR_TYPE_SIZE:
num_read = sscanf(value_str, "%zu", &cvar->sz); num_read = sscanf(value_str, "%zu", &cvar->sz);
break; break;
case RT_CVAR_TYPE_UINT:
num_read = sscanf(value_str, "%u", &cvar->ui);
break;
default: default:
rtReportError("CVAR", "CVar %s has an invalid type.", cvar->name); rtReportError("CVAR", "CVar %s has an invalid type.", cvar->name);
return 0; return 0;

View File

@ -13,6 +13,7 @@ typedef enum {
RT_CVAR_TYPE_FLOAT, RT_CVAR_TYPE_FLOAT,
RT_CVAR_TYPE_STRING, RT_CVAR_TYPE_STRING,
RT_CVAR_TYPE_SIZE, RT_CVAR_TYPE_SIZE,
RT_CVAR_TYPE_UINT,
} rt_cvar_type; } rt_cvar_type;
typedef struct { typedef struct {
@ -23,6 +24,7 @@ typedef struct {
float f; float f;
const char *s; const char *s;
size_t sz; size_t sz;
unsigned int ui;
}; };
rt_cvar_type type; rt_cvar_type type;
} rt_cvar; } 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} rt_cvar n = {.name = #n, .description = d, .s = (v), .type = RT_CVAR_TYPE_STRING}
#define RT_CVAR_SZ(n, d, v) \ #define RT_CVAR_SZ(n, d, v) \
rt_cvar n = {.name = #n, .description = d, .sz = (v), .type = RT_CVAR_TYPE_SIZE} 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 void rtRegisterCVAR(rt_cvar *cvar);
RT_DLLEXPORT rt_cvar *rtGetCVAR(const char *name); 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. * 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 */ * NOTE: A internal mutex is held while the event handlers run, which means that */

View File

@ -75,6 +75,7 @@ enum {
RT_SUCCESS = 0, RT_SUCCESS = 0,
RT_OUT_OF_MEMORY = 1, RT_OUT_OF_MEMORY = 1,
RT_INVALID_VALUE = 2, RT_INVALID_VALUE = 2,
RT_NOT_SUPPORTED = 3,
RT_CUSTOM_ERROR_START, RT_CUSTOM_ERROR_START,