From 872d506d953e845d0f44cbe3765a6088b00ff7fd Mon Sep 17 00:00:00 2001 From: terminx Date: Thu, 1 Dec 2016 04:06:40 +0000 Subject: [PATCH] Change OSD_CvarModified() to rely on a CVAR_MODIFIED flag set in osdcmd_cvar_set(), instead of merely comparing the current value to the default value. This leaves the storing of the default value (dval in osdcvar_t) in place for use in future features that haven't been programmed yet. git-svn-id: https://svn.eduke32.com/eduke32@5946 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/osd.h | 25 ++++++++++--------- polymer/eduke32/build/src/osd.c | 38 +++++++++++++---------------- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/polymer/eduke32/build/include/osd.h b/polymer/eduke32/build/include/osd.h index 85f3a5c21..6a05f54d7 100644 --- a/polymer/eduke32/build/include/osd.h +++ b/polymer/eduke32/build/include/osd.h @@ -32,19 +32,20 @@ const char *OSD_StripColors(char *out, const char *in); enum cvartype_t { - CVAR_FLOAT = 0x00000001, - CVAR_INT = 0x00000002, - CVAR_UINT = 0x00000004, - CVAR_BOOL = 0x00000008, - CVAR_STRING = 0x00000010, - CVAR_DOUBLE = 0x00000020, - CVAR_LOCKED = 0x00000040, - CVAR_MULTI = 0x00000080, - CVAR_NOSAVE = 0x00000100, - CVAR_FUNCPTR = 0x00000200, - CVAR_RESTARTVID = 0x00000400, - CVAR_INVALIDATEALL = 0x00000800, + CVAR_FLOAT = 0x00000001, + CVAR_INT = 0x00000002, + CVAR_UINT = 0x00000004, + CVAR_BOOL = 0x00000008, + CVAR_STRING = 0x00000010, + CVAR_DOUBLE = 0x00000020, + CVAR_LOCKED = 0x00000040, + CVAR_MULTI = 0x00000080, + CVAR_NOSAVE = 0x00000100, + CVAR_FUNCPTR = 0x00000200, + CVAR_RESTARTVID = 0x00000400, + CVAR_INVALIDATEALL = 0x00000800, CVAR_INVALIDATEART = 0x00001000, + CVAR_MODIFIED = 0x00002000, }; typedef struct _symbol diff --git a/polymer/eduke32/build/src/osd.c b/polymer/eduke32/build/src/osd.c index bd28efadb..1e52a6745 100644 --- a/polymer/eduke32/build/src/osd.c +++ b/polymer/eduke32/build/src/osd.c @@ -129,7 +129,7 @@ int32_t OSD_RegisterCvar(const cvar_t *cvar) return 0; } -static int32_t OSD_CvarModified(const osdcvar_t *cvar) +static int OSD_CvarModified(const osdcvar_t *cvar) { if (!osd) return 0; @@ -140,26 +140,7 @@ static int32_t OSD_CvarModified(const osdcvar_t *cvar) return 0; } - int rv = 0; - - switch (cvar->c.type & (CVAR_BOOL|CVAR_INT|CVAR_UINT|CVAR_FLOAT|CVAR_DOUBLE|CVAR_STRING)) - { - case CVAR_BOOL: - case CVAR_INT: - rv = (cvar->dval.i != *(int32_t *)cvar->c.vptr); break; - case CVAR_UINT: - rv = (cvar->dval.uint != *(uint32_t *)cvar->c.vptr); break; - case CVAR_FLOAT: - rv = (cvar->dval.f != *(float *)cvar->c.vptr); break; - case CVAR_DOUBLE: - rv = (cvar->dval.d != *(double *)cvar->c.vptr); break; - case CVAR_STRING: - rv = 1; break; - default: - EDUKE32_UNREACHABLE_SECTION(break); - } - - return rv; + return (cvar->c.type & CVAR_MODIFIED) == CVAR_MODIFIED; } // color code format is as follows: @@ -710,6 +691,8 @@ static int32_t _internal_osdfunc_toggle(const osdfuncparm_t *parm) } *(int32_t *)osd->cvars[i].c.vptr = 1 - *(int32_t *)osd->cvars[i].c.vptr; + osd->cvars[i].c.type |= CVAR_MODIFIED; + return OSDCMD_OK; } @@ -2070,7 +2053,10 @@ int32_t osdcmd_cvar_set(const osdfuncparm_t *parm) OSD_Printf("%s value out of range\n",osd->cvars[i].c.name); return OSDCMD_OK; } + *(float *)osd->cvars[i].c.vptr = val; + osd->cvars[i].c.type |= CVAR_MODIFIED; + if (!OSD_ParsingScript()) OSD_Printf("%s %f",osd->cvars[i].c.name,val); } @@ -2091,7 +2077,10 @@ int32_t osdcmd_cvar_set(const osdfuncparm_t *parm) OSD_Printf("%s value out of range\n",osd->cvars[i].c.name); return OSDCMD_OK; } + *(double *)osd->cvars[i].c.vptr = val; + osd->cvars[i].c.type |= CVAR_MODIFIED; + if (!OSD_ParsingScript()) OSD_Printf("%s %f",osd->cvars[i].c.name,val); } @@ -2113,7 +2102,10 @@ int32_t osdcmd_cvar_set(const osdfuncparm_t *parm) OSD_Printf("%s value out of range\n",osd->cvars[i].c.name); return OSDCMD_OK; } + *(int32_t *)osd->cvars[i].c.vptr = val; + osd->cvars[i].c.type |= CVAR_MODIFIED; + if (!OSD_ParsingScript()) OSD_Printf("%s %d",osd->cvars[i].c.name,val); } @@ -2135,6 +2127,7 @@ int32_t osdcmd_cvar_set(const osdfuncparm_t *parm) } *(uint32_t *) osd->cvars[i].c.vptr = val; + osd->cvars[i].c.type |= CVAR_MODIFIED; if (!OSD_ParsingScript()) OSD_Printf("%s %d", osd->cvars[i].c.name, val); @@ -2150,6 +2143,9 @@ int32_t osdcmd_cvar_set(const osdfuncparm_t *parm) Bstrncpy((char *)osd->cvars[i].c.vptr, parm->parms[0], osd->cvars[i].c.max-1); ((char *)osd->cvars[i].c.vptr)[osd->cvars[i].c.max-1] = 0; + + osd->cvars[i].c.type |= CVAR_MODIFIED; + if (!OSD_ParsingScript()) OSD_Printf("%s %s",osd->cvars[i].c.name,(char *)osd->cvars[i].c.vptr); }