Replace the separate full Gv_AddVar/SubVar/etc functions with a macro that generates them since they were all the same anyway (other than the operator, obviously)

git-svn-id: https://svn.eduke32.com/eduke32@3267 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2012-12-12 02:53:05 +00:00
parent 9d2260c3c8
commit 5d031ec257

View file

@ -100,220 +100,40 @@ void Gv_ResetSystemDefaults(void);
void Gv_ResetVars(void); void Gv_ResetVars(void);
void Gv_WriteSave(FILE *fil,int32_t newbehav); void Gv_WriteSave(FILE *fil,int32_t newbehav);
static inline void __fastcall Gv_AddVar(register int32_t id, register int32_t lValue) #define GV_VAROP(func, operator) static inline void __fastcall func(register int32_t id, register int32_t lValue) \
{ { \
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) \
{ { \
default: default: \
aGameVars[id].val.lValue += lValue; aGameVars[id].val.lValue operator lValue; \
return; return; \
case GAMEVAR_PERPLAYER: case GAMEVAR_PERPLAYER: \
if ((unsigned)vm.g_p > MAXPLAYERS-1) return; if ((unsigned)vm.g_p > MAXPLAYERS-1) return; \
aGameVars[id].val.plValues[vm.g_p] += lValue; aGameVars[id].val.plValues[vm.g_p] operator lValue; \
return; return; \
case GAMEVAR_PERACTOR: case GAMEVAR_PERACTOR: \
if ((unsigned)vm.g_i > MAXSPRITES-1) return; if ((unsigned)vm.g_i > MAXSPRITES-1) return; \
aGameVars[id].val.plValues[vm.g_i] += lValue; aGameVars[id].val.plValues[vm.g_i] operator lValue; \
return; return; \
case GAMEVAR_INTPTR: case GAMEVAR_INTPTR: \
*((int32_t *)aGameVars[id].val.lValue) += (int32_t)lValue; *((int32_t *)aGameVars[id].val.lValue) operator (int32_t)lValue; \
return; return; \
case GAMEVAR_SHORTPTR: case GAMEVAR_SHORTPTR: \
*((int16_t *)aGameVars[id].val.lValue) += (int16_t)lValue; *((int16_t *)aGameVars[id].val.lValue) operator (int16_t)lValue; \
return; return; \
case GAMEVAR_CHARPTR: case GAMEVAR_CHARPTR: \
*((uint8_t *)aGameVars[id].val.lValue) +=(uint8_t)lValue; *((uint8_t *)aGameVars[id].val.lValue) operator (uint8_t)lValue; \
return; return; \
} } \
} }
static inline void __fastcall Gv_SubVar(register int32_t id, register int32_t lValue) GV_VAROP(Gv_AddVar, +=)
{ GV_VAROP(Gv_SubVar, -=)
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) GV_VAROP(Gv_MulVar, *=)
{ GV_VAROP(Gv_DivVar, /=)
default: GV_VAROP(Gv_ModVar, %=)
aGameVars[id].val.lValue -= lValue; GV_VAROP(Gv_AndVar, &=)
return; GV_VAROP(Gv_XorVar, ^=)
case GAMEVAR_PERPLAYER: GV_VAROP(Gv_OrVar, |=)
if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
aGameVars[id].val.plValues[vm.g_p] -= lValue;
return;
case GAMEVAR_PERACTOR:
if ((unsigned)vm.g_i > MAXSPRITES-1) return;
aGameVars[id].val.plValues[vm.g_i] -= lValue;
return;
case GAMEVAR_INTPTR:
*((int32_t *)aGameVars[id].val.lValue) -= (int32_t)lValue;
return;
case GAMEVAR_SHORTPTR:
*((int16_t *)aGameVars[id].val.lValue) -= (int16_t)lValue;
return;
case GAMEVAR_CHARPTR:
*((uint8_t *)aGameVars[id].val.lValue) -=(uint8_t)lValue;
return;
}
}
static inline void __fastcall Gv_MulVar(register int32_t id, register int32_t lValue)
{
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{
default:
aGameVars[id].val.lValue *= lValue;
return;
case GAMEVAR_PERPLAYER:
if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
aGameVars[id].val.plValues[vm.g_p] *= lValue;
return;
case GAMEVAR_PERACTOR:
if ((unsigned)vm.g_i > MAXSPRITES-1) return;
aGameVars[id].val.plValues[vm.g_i] *= lValue;
return;
case GAMEVAR_INTPTR:
*((int32_t *)aGameVars[id].val.lValue) *= (int32_t)lValue;
return;
case GAMEVAR_SHORTPTR:
*((int16_t *)aGameVars[id].val.lValue) *= (int16_t)lValue;
return;
case GAMEVAR_CHARPTR:
*((uint8_t *)aGameVars[id].val.lValue) *=(uint8_t)lValue;
return;
}
}
static inline void __fastcall Gv_DivVar(register int32_t id, register int32_t lValue)
{
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{
default:
aGameVars[id].val.lValue /= lValue;
return;
case GAMEVAR_PERPLAYER:
if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
aGameVars[id].val.plValues[vm.g_p] /= lValue;
return;
case GAMEVAR_PERACTOR:
if ((unsigned)vm.g_i > MAXSPRITES-1) return;
aGameVars[id].val.plValues[vm.g_i] /= lValue;
return;
case GAMEVAR_INTPTR:
*((int32_t *)aGameVars[id].val.lValue) /= (int32_t)lValue;
return;
case GAMEVAR_SHORTPTR:
*((int16_t *)aGameVars[id].val.lValue) /= (int16_t)lValue;
return;
case GAMEVAR_CHARPTR:
*((uint8_t *)aGameVars[id].val.lValue) /=(uint8_t)lValue;
return;
}
}
static inline void __fastcall Gv_ModVar(register int32_t id, register int32_t lValue)
{
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{
default:
aGameVars[id].val.lValue %= lValue;
return;
case GAMEVAR_PERPLAYER:
if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
aGameVars[id].val.plValues[vm.g_p] %= lValue;
return;
case GAMEVAR_PERACTOR:
if ((unsigned)vm.g_i > MAXSPRITES-1) return;
aGameVars[id].val.plValues[vm.g_i] %= lValue;
return;
case GAMEVAR_INTPTR:
*((int32_t *)aGameVars[id].val.lValue) %= (int32_t)lValue;
return;
case GAMEVAR_SHORTPTR:
*((int16_t *)aGameVars[id].val.lValue) %= (int16_t)lValue;
return;
case GAMEVAR_CHARPTR:
*((uint8_t *)aGameVars[id].val.lValue) %=(uint8_t)lValue;
return;
}
}
static inline void __fastcall Gv_AndVar(register int32_t id, register int32_t lValue)
{
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{
default:
aGameVars[id].val.lValue &= lValue;
return;
case GAMEVAR_PERPLAYER:
if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
aGameVars[id].val.plValues[vm.g_p] &= lValue;
return;
case GAMEVAR_PERACTOR:
if ((unsigned)vm.g_i > MAXSPRITES-1) return;
aGameVars[id].val.plValues[vm.g_i] &= lValue;
return;
case GAMEVAR_INTPTR:
*((int32_t *)aGameVars[id].val.lValue) &= (int32_t)lValue;
return;
case GAMEVAR_SHORTPTR:
*((int16_t *)aGameVars[id].val.lValue) &= (int16_t)lValue;
return;
case GAMEVAR_CHARPTR:
*((uint8_t *)aGameVars[id].val.lValue) &=(uint8_t)lValue;
return;
}
}
static inline void __fastcall Gv_XorVar(register int32_t id, register int32_t lValue)
{
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{
default:
aGameVars[id].val.lValue ^= lValue;
return;
case GAMEVAR_PERPLAYER:
if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
aGameVars[id].val.plValues[vm.g_p] ^= lValue;
return;
case GAMEVAR_PERACTOR:
if ((unsigned)vm.g_i > MAXSPRITES-1) return;
aGameVars[id].val.plValues[vm.g_i] ^= lValue;
return;
case GAMEVAR_INTPTR:
*((int32_t *)aGameVars[id].val.lValue) ^= (int32_t)lValue;
return;
case GAMEVAR_SHORTPTR:
*((int16_t *)aGameVars[id].val.lValue) ^= (int16_t)lValue;
return;
case GAMEVAR_CHARPTR:
*((uint8_t *)aGameVars[id].val.lValue) ^=(uint8_t)lValue;
return;
}
}
static inline void __fastcall Gv_OrVar(register int32_t id, register int32_t lValue)
{
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{
default:
aGameVars[id].val.lValue |= lValue;
return;
case GAMEVAR_PERPLAYER:
if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
aGameVars[id].val.plValues[vm.g_p] |= lValue;
return;
case GAMEVAR_PERACTOR:
if ((unsigned)vm.g_i > MAXSPRITES-1) return;
aGameVars[id].val.plValues[vm.g_i] |= lValue;
return;
case GAMEVAR_INTPTR:
*((int32_t *)aGameVars[id].val.lValue) |= (int32_t)lValue;
return;
case GAMEVAR_SHORTPTR:
*((int16_t *)aGameVars[id].val.lValue) |= (int16_t)lValue;
return;
case GAMEVAR_CHARPTR:
*((uint8_t *)aGameVars[id].val.lValue) |=(uint8_t)lValue;
return;
}
}
#endif #endif