#ifndef RT_CONFIG_H #define RT_CONFIG_H #include "file_tab.h" #include "runtime.h" #ifdef __cplusplus extern "C" { #endif typedef enum { RT_CVAR_TYPE_INT, RT_CVAR_TYPE_FLOAT, RT_CVAR_TYPE_STRING, RT_CVAR_TYPE_SIZE, } rt_cvar_type; typedef struct { const char *name; const char *description; union { int i; float f; const char *s; size_t sz; }; rt_cvar_type type; } rt_cvar; typedef void(rt_cvar_change_event_handler_fn)(rt_cvar *cvar, void *userdata); /* n variable name, d description string, v default value*/ #define RT_CVAR_I(n, d, v) \ rt_cvar n = {.name = #n, .description = d, .i = (v), .type = RT_CVAR_TYPE_INT} #define RT_CVAR_F(n, d, v) \ rt_cvar n = {.name = #n, .description = d, .f = (v), .type = RT_CVAR_TYPE_FLOAT} #define RT_CVAR_S(n, d, v) \ 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} RT_DLLEXPORT void rtRegisterCVAR(rt_cvar *cvar); RT_DLLEXPORT rt_cvar *rtGetCVAR(const char *name); /* 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 */ RT_DLLEXPORT void rtRegisterCVARChangeEventHandler(rt_cvar *cvar, rt_cvar_change_event_handler_fn *event_handler, void *userdata); RT_DLLEXPORT void rtNotifyCVARChange(const rt_cvar *cvar); /* Load and parse configuration files. * They are processed in-order, meaning later files can overwrite earlier files. */ RT_DLLEXPORT rt_result rtProcessConfigFiles(unsigned int count, const rt_file_id *fids); RT_DLLEXPORT rt_result rtSetCVARFromString(rt_cvar *cvar, const char *value_str); #ifdef __cplusplus } #endif #endif