Gamevar cleanup: drop "register" qualifiers, shuffle a few things around.

git-svn-id: https://svn.eduke32.com/eduke32@4631 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2014-09-30 04:16:21 +00:00
parent c2517d0d99
commit 71bb5e5c8e
2 changed files with 187 additions and 172 deletions

View file

@ -538,9 +538,9 @@ int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags)
return 1; return 1;
} }
void __fastcall A_ResetVars(register int32_t iActor) void __fastcall A_ResetVars(int32_t iActor)
{ {
register int32_t i=(MAXGAMEVARS-1); int32_t i=(MAXGAMEVARS-1);
do do
{ {
if ((aGameVars[i].dwFlags & (GAMEVAR_PERACTOR|GAMEVAR_NODEFAULT)) == GAMEVAR_PERACTOR) if ((aGameVars[i].dwFlags & (GAMEVAR_PERACTOR|GAMEVAR_NODEFAULT)) == GAMEVAR_PERACTOR)
@ -560,7 +560,7 @@ static int32_t Gv_GetVarIndex(const char *szGameLabel)
return i; return i;
} }
int32_t __fastcall Gv_GetVar(register int32_t id, register int32_t iActor, register int32_t iPlayer) int32_t __fastcall Gv_GetVar(int32_t id, int32_t iActor, int32_t iPlayer)
{ {
if (id == g_iThisActorID) if (id == g_iThisActorID)
return iActor; return iActor;
@ -569,13 +569,13 @@ int32_t __fastcall Gv_GetVar(register int32_t id, register int32_t iActor, regis
return(*insptr++); return(*insptr++);
{ {
register intptr_t negateResult = id&(MAXGAMEVARS<<1); intptr_t negateResult = id&(MAXGAMEVARS<<1);
if (id >= g_gameVarCount) if (id >= g_gameVarCount)
{ {
if (id&(MAXGAMEVARS<<2)) // array if (id&(MAXGAMEVARS<<2)) // array
{ {
register int32_t index=Gv_GetVar(*insptr++,iActor,iPlayer); int32_t index=Gv_GetVar(*insptr++,iActor,iPlayer);
id &= (MAXGAMEVARS-1);// ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1)); id &= (MAXGAMEVARS-1);// ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1));
@ -590,7 +590,7 @@ int32_t __fastcall Gv_GetVar(register int32_t id, register int32_t iActor, regis
if (id&(MAXGAMEVARS<<3)) // struct shortcut vars if (id&(MAXGAMEVARS<<3)) // struct shortcut vars
{ {
register int32_t index=Gv_GetVar(*insptr++, iActor, iPlayer); int32_t index=Gv_GetVar(*insptr++, iActor, iPlayer);
switch ((id&(MAXGAMEVARS-1)) - g_iSpriteVarID) switch ((id&(MAXGAMEVARS-1)) - g_iSpriteVarID)
{ {
@ -710,7 +710,7 @@ wtf:
return -1; return -1;
} }
void __fastcall Gv_SetVar(register int32_t id, register int32_t lValue, register int32_t iActor, register int32_t iPlayer) void __fastcall Gv_SetVar(int32_t id, int32_t lValue, int32_t iActor, int32_t iPlayer)
{ {
if ((unsigned)id >= (unsigned)g_gameVarCount) goto badvarid; if ((unsigned)id >= (unsigned)g_gameVarCount) goto badvarid;
@ -754,22 +754,68 @@ badindex:
return; return;
} }
int32_t __fastcall Gv_GetVarX(register int32_t id) enum {
GVX_BADVARID = 0,
GVX_BADPLAYER,
GVX_BADSPRITE,
GVX_BADSECTOR,
GVX_BADWALL,
GVX_BADINDEX,
GVX_WTF,
GVX_ARRAYWTF
} gvxerror_t;
static const char *gvxerrs [] ={ "Gv_GetVarX(): invalid gamevar ID (%d)\n",
"Gv_GetVarX(): invalid player ID %d\n",
"Gv_GetVarX(): invalid sprite ID %d\n",
"Gv_GetVarX(): invalid sector ID %d\n",
"Gv_GetVarX(): invalid wall ID %d\n",
"Gv_GetVarX(): invalid array index (%s[%d])\n",
"Gv_GetVarX(): WTF?\n",
"Gv_GetVarX() (array): WTF?\n"
};
int32_t __fastcall Gv_GetVarX(int32_t id)
{ {
intptr_t negateResult = id&(MAXGAMEVARS<<1);
if (id == g_iThisActorID) if (id == g_iThisActorID)
return vm.g_i; return vm.g_i;
if (id == MAXGAMEVARS) if (id == MAXGAMEVARS)
return(*insptr++); return(*insptr++);
{ if (id >= g_gameVarCount && negateResult == 0)
register intptr_t negateResult = id&(MAXGAMEVARS<<1); goto nastyhacks;
if (id >= g_gameVarCount) id &= MAXGAMEVARS-1;
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{ {
default:
return ((aGameVars[id].val.lValue ^ -negateResult) + negateResult);
case GAMEVAR_PERPLAYER:
if ((unsigned) vm.g_p >= MAXPLAYERS)
{
id = vm.g_p;
CON_ERRPRINTF("%s", gvxerrs[GVX_BADPLAYER], id);
return -1;
}
return ((aGameVars[id].val.plValues[vm.g_p] ^ -negateResult) + negateResult);
case GAMEVAR_PERACTOR:
return ((aGameVars[id].val.plValues[vm.g_i] ^ -negateResult) + negateResult);
case GAMEVAR_INTPTR:
return (((*((int32_t *) aGameVars[id].val.lValue)) ^ -negateResult) + negateResult);
case GAMEVAR_SHORTPTR:
return (((*((int16_t *) aGameVars[id].val.lValue)) ^ -negateResult) + negateResult);
case GAMEVAR_CHARPTR:
return (((*((uint8_t *) aGameVars[id].val.lValue)) ^ -negateResult) + negateResult);
}
nastyhacks:
if (id&(MAXGAMEVARS<<2)) // array if (id&(MAXGAMEVARS<<2)) // array
{ {
register int32_t index=Gv_GetVarX(*insptr++); int32_t index=Gv_GetVarX(*insptr++);
int32_t siz; int32_t siz;
id &= (MAXGAMEVARS-1);// ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1)); id &= (MAXGAMEVARS-1);// ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1));
@ -782,7 +828,8 @@ int32_t __fastcall Gv_GetVarX(register int32_t id)
if (index < 0 || index >= siz) if (index < 0 || index >= siz)
{ {
negateResult = index; negateResult = index;
goto badindex; CON_ERRPRINTF("%s", gvxerrs[GVX_BADINDEX], aGameArrays[id].szLabel, (int32_t) negateResult);
return -1;
} }
switch (aGameArrays[id].dwFlags & GAMEARRAY_TYPE_MASK) switch (aGameArrays[id].dwFlags & GAMEARRAY_TYPE_MASK)
@ -796,7 +843,8 @@ int32_t __fastcall Gv_GetVarX(register int32_t id)
case GAMEARRAY_OFCHAR: case GAMEARRAY_OFCHAR:
return (((uint8_t *) aGameArrays[id].plValues)[index] ^ -negateResult) + negateResult; return (((uint8_t *) aGameArrays[id].plValues)[index] ^ -negateResult) + negateResult;
default: default:
goto arraywtf; CON_ERRPRINTF("%s", gvxerrs[GVX_ARRAYWTF]);
return -1;
} }
} }
@ -808,7 +856,7 @@ int32_t __fastcall Gv_GetVarX(register int32_t id)
{ {
case 0: //if (id == g_iSpriteVarID) case 0: //if (id == g_iSpriteVarID)
{ {
register int32_t parm2 = 0, label = *insptr++; int32_t parm2 = 0, label = *insptr++;
/*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/ /*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/
if (ActorLabels[label].flags & LABEL_HASPARM2) if (ActorLabels[label].flags & LABEL_HASPARM2)
@ -817,14 +865,15 @@ int32_t __fastcall Gv_GetVarX(register int32_t id)
if ((unsigned) index >= MAXSPRITES) if ((unsigned) index >= MAXSPRITES)
{ {
id = index; id = index;
goto badsprite; CON_ERRPRINTF("%s", gvxerrs[GVX_BADSPRITE], id);
return -1;
} }
return ((VM_AccessSpriteX(index, label, parm2) ^ -negateResult) + negateResult); return ((VM_AccessSpriteX(index, label, parm2) ^ -negateResult) + negateResult);
} }
case 3: //else if (id == g_iPlayerVarID) case 3: //else if (id == g_iPlayerVarID)
{ {
register int32_t parm2 = 0, label = *insptr++; int32_t parm2 = 0, label = *insptr++;
if (PlayerLabels[label].flags & LABEL_HASPARM2) if (PlayerLabels[label].flags & LABEL_HASPARM2)
parm2 = Gv_GetVarX(*insptr++); parm2 = Gv_GetVarX(*insptr++);
@ -834,7 +883,8 @@ int32_t __fastcall Gv_GetVarX(register int32_t id)
if ((unsigned) index >= MAXPLAYERS) if ((unsigned) index >= MAXPLAYERS)
{ {
id = index; id = index;
goto badplayer; CON_ERRPRINTF("%s", gvxerrs[GVX_BADPLAYER], id);
return -1;
} }
return ((VM_AccessPlayerX(index, label, parm2) ^ -negateResult) + negateResult); return ((VM_AccessPlayerX(index, label, parm2) ^ -negateResult) + negateResult);
} }
@ -846,7 +896,8 @@ int32_t __fastcall Gv_GetVarX(register int32_t id)
{ {
id = index; id = index;
insptr++; insptr++;
goto badsector; CON_ERRPRINTF("%s", gvxerrs[GVX_BADSECTOR], id);
return -1;
} }
return ((VM_AccessSectorX(index, *insptr++) ^ -negateResult) + negateResult); return ((VM_AccessSectorX(index, *insptr++) ^ -negateResult) + negateResult);
case 2: //else if (id == g_iWallVarID) case 2: //else if (id == g_iWallVarID)
@ -854,76 +905,21 @@ int32_t __fastcall Gv_GetVarX(register int32_t id)
{ {
id = index; id = index;
insptr++; insptr++;
goto badwall; CON_ERRPRINTF("%s", gvxerrs[GVX_BADWALL], id);
return -1;
} }
return ((VM_AccessWallX(index, *insptr++) ^ -negateResult) + negateResult); return ((VM_AccessWallX(index, *insptr++) ^ -negateResult) + negateResult);
default: default:
goto wtf;
}
}
id &= (MAXGAMEVARS-1);
if (!negateResult)
goto badvarid;
}
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{
default:
return ((aGameVars[id].val.lValue ^ -negateResult) + negateResult);
case GAMEVAR_PERPLAYER:
if ((unsigned)vm.g_p >= MAXPLAYERS)
{
id = vm.g_p;
goto badplayer;
}
return ((aGameVars[id].val.plValues[vm.g_p] ^ -negateResult) + negateResult);
case GAMEVAR_PERACTOR:
return ((aGameVars[id].val.plValues[vm.g_i] ^ -negateResult) + negateResult);
case GAMEVAR_INTPTR:
return (((*((int32_t *)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult);
case GAMEVAR_SHORTPTR:
return (((*((int16_t *)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult);
case GAMEVAR_CHARPTR:
return (((*((uint8_t *)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult);
}
badindex:
CON_ERRPRINTF("Gv_GetVarX(): invalid array index (%s[%d])\n", aGameArrays[id].szLabel, (int32_t)negateResult);
return -1;
badvarid:
CON_ERRPRINTF("Gv_GetVarX(): invalid gamevar ID (%d)\n", id);
return -1;
badplayer:
CON_ERRPRINTF("Gv_GetVarX(): invalid player ID %d\n", id);
return -1;
badsprite:
CON_ERRPRINTF("Gv_GetVarX(): invalid sprite ID %d\n", id);
return -1;
badsector:
CON_ERRPRINTF("Gv_GetVarX(): invalid sector ID %d\n", id);
return -1;
badwall:
CON_ERRPRINTF("Gv_GetVarX(): invalid wall ID %d\n", id);
return -1;
arraywtf:
CON_ERRPRINTF("Gv_GetVarX() (array): WTF?\n");
return -1;
wtf:
CON_ERRPRINTF("Gv_GetVarX(): WTF?\n"); CON_ERRPRINTF("Gv_GetVarX(): WTF?\n");
return -1; return -1;
} }
} }
void __fastcall Gv_SetVarX(register int32_t id, register int32_t lValue) CON_ERRPRINTF("%s", gvxerrs[GVX_WTF]);
return -1;
}
void __fastcall Gv_SetVarX(int32_t id, int32_t lValue)
{ {
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{ {
@ -1067,6 +1063,25 @@ void Gv_ResetSystemDefaults(void)
#endif #endif
G_InitProjectileData(); G_InitProjectileData();
// hackhackhackhackhack
i = hash_find(&h_arrays, "tilesizx");
if (i >= 0)
{
int32_t j = 0;
for (; j<MAXTILES; j++)
aGameArrays[i].plValues[j] = tilesiz[j].x;
}
i = hash_find(&h_arrays, "tilesizy");
if (i >= 0)
{
int32_t j = 0;
for (; j<MAXTILES; j++)
aGameArrays[i].plValues[j] = tilesiz[j].y;
}
//AddLog("EOF:ResetWeaponDefaults"); //AddLog("EOF:ResetWeaponDefaults");
} }
@ -1451,8 +1466,8 @@ static void Gv_AddSystemVars(void)
# endif # endif
// SYSTEM_GAMEARRAY // SYSTEM_GAMEARRAY
Gv_NewArray("tilesizx", NULL/*(void *)tilesizx*/, MAXTILES, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT); Gv_NewArray("tilesizx", NULL, MAXTILES, GAMEARRAY_READONLY);
Gv_NewArray("tilesizy", NULL/*(void *)tilesizy*/, MAXTILES, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT); Gv_NewArray("tilesizy", NULL, MAXTILES, GAMEARRAY_READONLY);
#endif #endif
} }

View file

@ -96,15 +96,15 @@ extern gamearray_t aGameArrays[MAXGAMEARRAYS];
extern int32_t g_gameVarCount; extern int32_t g_gameVarCount;
extern int32_t g_gameArrayCount; extern int32_t g_gameArrayCount;
int32_t __fastcall Gv_GetVar(register int32_t id,register int32_t iActor,register int32_t iPlayer); int32_t __fastcall Gv_GetVar(int32_t id, int32_t iActor, int32_t iPlayer);
void __fastcall Gv_SetVar(register int32_t id,register int32_t lValue,register int32_t iActor,register int32_t iPlayer); void __fastcall Gv_SetVar(int32_t id, int32_t lValue, int32_t iActor, int32_t iPlayer);
int32_t __fastcall Gv_GetVarX(register int32_t id); int32_t __fastcall Gv_GetVarX(int32_t id);
void __fastcall Gv_SetVarX(register int32_t id,register int32_t lValue); void __fastcall Gv_SetVarX(int32_t id, int32_t lValue);
int32_t Gv_GetVarByLabel(const char *szGameLabel,int32_t lDefault,int32_t iActor,int32_t iPlayer); int32_t Gv_GetVarByLabel(const char *szGameLabel,int32_t lDefault,int32_t iActor,int32_t iPlayer);
int32_t Gv_NewArray(const char *pszLabel,void *arrayptr,intptr_t asize,uint32_t dwFlags); int32_t Gv_NewArray(const char *pszLabel,void *arrayptr,intptr_t asize,uint32_t dwFlags);
int32_t Gv_NewVar(const char *pszLabel,intptr_t lValue,uint32_t dwFlags); int32_t Gv_NewVar(const char *pszLabel,intptr_t lValue,uint32_t dwFlags);
void __fastcall A_ResetVars(register int32_t iActor); void __fastcall A_ResetVars(int32_t iActor);
void Gv_DumpValues(void); void Gv_DumpValues(void);
void Gv_InitWeaponPointers(void); void Gv_InitWeaponPointers(void);
void Gv_RefreshPointers(void); void Gv_RefreshPointers(void);
@ -121,7 +121,7 @@ void Gv_Init(void);
void Gv_FinalizeWeaponDefaults(void); void Gv_FinalizeWeaponDefaults(void);
#if !defined LUNATIC #if !defined LUNATIC
#define GV_VAROP(func, operator) static inline void __fastcall func(register int32_t id, register int32_t lValue) \ #define GV_VAROP(func, operator) static inline void __fastcall func(int32_t id, int32_t lValue) \
{ \ { \
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) \ switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) \
{ \ { \