Direct struct access for tsprite, and break special gamevar access out of Gv_GetVar() and into a separate function like it already was with Gv_GetVarX()

git-svn-id: https://svn.eduke32.com/eduke32@7201 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-11-18 18:11:21 +00:00
parent 18916ddaf6
commit 32057d2e19
5 changed files with 188 additions and 281 deletions

View file

@ -930,39 +930,33 @@ const memberlabel_t ActorLabels[]=
{ "detail", ACTOR_DETAIL, 0, 0, -1 }, // deprecated name for 'blend'
};
const memberlabel_t TsprLabels[]=
const memberlabel_t TsprLabels[] =
{
// tsprite access
{ "tsprx", ACTOR_X, 0, 0, -1 },
{ "tspry", ACTOR_Y, 0, 0, -1 },
{ "tsprz", ACTOR_Z, 0, 0, -1 },
{ "tsprcstat", ACTOR_CSTAT, 0, 0, -1 },
{ "tsprpicnum", ACTOR_PICNUM, 0, 0, -1 },
{ "tsprshade", ACTOR_SHADE, 0, 0, -1 },
{ "tsprpal", ACTOR_PAL, 0, 0, -1 },
{ "tsprclipdist", ACTOR_CLIPDIST, 0, 0, -1 },
// { "tsprfiller", ACTOR_DETAIL, 0, 0, -1 },
{ "tsprblend", ACTOR_DETAIL, 0, 0, -1 },
{ "tsprxrepeat", ACTOR_XREPEAT, 0, 0, -1 },
{ "tspryrepeat", ACTOR_YREPEAT, 0, 0, -1 },
{ "tsprxoffset", ACTOR_XOFFSET, 0, 0, -1 },
{ "tspryoffset", ACTOR_YOFFSET, 0, 0, -1 },
{ "tsprsectnum", ACTOR_SECTNUM, 0, 0, -1 },
{ "tsprstatnum", ACTOR_STATNUM, 0, 0, -1 },
{ "tsprang", ACTOR_ANG, 0, 0, -1 },
{ "tsprowner", ACTOR_OWNER, 0, 0, -1 },
#if 1
{ "tsprxvel", ACTOR_XVEL, 0, 0, -1 },
{ "tspryvel", ACTOR_YVEL, 0, 0, -1 },
{ "tsprzvel", ACTOR_ZVEL, 0, 0, -1 },
{ "tsprlotag", ACTOR_LOTAG, 0, 0, -1 },
{ "tsprhitag", ACTOR_HITAG, 0, 0, -1 },
{ "tsprextra", ACTOR_EXTRA, 0, 0, -1 },
#endif
// aliases:
{ "tsprdetail", ACTOR_DETAIL, 0, 0, -1 }, // deprecated name for 'tsprblend'
LABEL_SETUP_UNMATCHED(sprite, x, "tsprx", ACTOR_X),
LABEL_SETUP_UNMATCHED(sprite, y, "tspry", ACTOR_Y),
LABEL_SETUP_UNMATCHED(sprite, z, "tsprz", ACTOR_Z),
LABEL_SETUP_UNMATCHED(sprite, cstat, "tsprcstat", ACTOR_CSTAT),
LABEL_SETUP_UNMATCHED(sprite, picnum, "tsprpicnum", ACTOR_PICNUM),
LABEL_SETUP_UNMATCHED(sprite, shade, "tsprshade", ACTOR_SHADE),
LABEL_SETUP_UNMATCHED(sprite, pal, "tsprpal", ACTOR_PAL),
LABEL_SETUP_UNMATCHED(sprite, clipdist, "tsprclipdist", ACTOR_CLIPDIST),
LABEL_SETUP_UNMATCHED(sprite, blend, "tsprblend", ACTOR_DETAIL),
LABEL_SETUP_UNMATCHED(sprite, xrepeat, "tsprxrepeat", ACTOR_XREPEAT),
LABEL_SETUP_UNMATCHED(sprite, yrepeat, "tspryrepeat", ACTOR_YREPEAT),
LABEL_SETUP_UNMATCHED(sprite, xoffset, "tsprxoffset", ACTOR_XOFFSET),
LABEL_SETUP_UNMATCHED(sprite, yoffset, "tspryoffset", ACTOR_YOFFSET),
LABEL_SETUP_UNMATCHED(sprite, sectnum, "tsprsectnum", ACTOR_SECTNUM),
LABEL_SETUP_UNMATCHED(sprite, statnum, "tsprstatnum", ACTOR_STATNUM),
LABEL_SETUP_UNMATCHED(sprite, ang, "tsprang", ACTOR_ANG),
LABEL_SETUP_UNMATCHED(sprite, owner, "tsprowner", ACTOR_OWNER),
LABEL_SETUP_UNMATCHED(sprite, xvel, "tsprxvel", ACTOR_XVEL),
LABEL_SETUP_UNMATCHED(sprite, yvel, "tspryvel", ACTOR_YVEL),
LABEL_SETUP_UNMATCHED(sprite, zvel, "tsprzvel", ACTOR_ZVEL),
LABEL_SETUP_UNMATCHED(sprite, lotag, "tsprlotag", ACTOR_LOTAG),
LABEL_SETUP_UNMATCHED(sprite, hitag, "tsprhitag", ACTOR_HITAG),
LABEL_SETUP_UNMATCHED(sprite, extra, "tsprextra", ACTOR_EXTRA),
};
const memberlabel_t PlayerLabels[]=

View file

@ -57,20 +57,20 @@ enum
#define VM_INSTMASK 0xfff
#define C_CUSTOMERROR(Text, ...) \
do \
{ \
C_ReportError(-1); \
initprintf("%s:%d: error: " Text "\n", g_scriptFileName, g_lineNumber, ##__VA_ARGS__); \
g_errorCnt++; \
#define C_CUSTOMERROR(Text, ...) \
do \
{ \
C_ReportError(-1); \
initprintf("%s:%d: error: " Text "\n", g_scriptFileName, g_lineNumber, ##__VA_ARGS__); \
g_errorCnt++; \
} while (0)
#define C_CUSTOMWARNING(Text, ...) \
do \
{ \
C_ReportError(-1); \
initprintf("%s:%d: warning: " Text "\n", g_scriptFileName, g_lineNumber, ##__VA_ARGS__); \
g_warningCnt++; \
#define C_CUSTOMWARNING(Text, ...) \
do \
{ \
C_ReportError(-1); \
initprintf("%s:%d: warning: " Text "\n", g_scriptFileName, g_lineNumber, ##__VA_ARGS__); \
g_warningCnt++; \
} while (0)
#if !defined LUNATIC
@ -96,7 +96,7 @@ extern int32_t g_weaponVarID; // var ID of "WEAPON"
extern int32_t g_worksLikeVarID; // var ID of "WORKSLIKE"
extern int32_t g_zRangeVarID; // var ID of "ZRANGE"
// KEEPINSYNC gamevars.c: "special vars for struct access"
// KEEPINSYNC gamevars.cpp: "special vars for struct access"
enum QuickStructureAccess_t
{
STRUCT_SPRITE,

View file

@ -4872,8 +4872,9 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop)
{
int const spriteNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVarX(*(insptr - 1)) : vm.spriteNum;
int const labelNum = *insptr++;
auto const &tsprLabel = TsprLabels[labelNum];
VM_SetTsprite(spriteNum, labelNum, Gv_GetVarX(*insptr++));
VM_SetStruct(tsprLabel.flags, (intptr_t *)((char *)spriteext[spriteNum].tspr + tsprLabel.offset), Gv_GetVarX(*insptr++));
continue;
}
@ -4882,8 +4883,9 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop)
{
int const spriteNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVarX(*(insptr - 1)) : vm.spriteNum;
int const labelNum = *insptr++;
auto const &tsprLabel = TsprLabels[labelNum];
Gv_SetVarX(*insptr++, VM_GetTsprite(spriteNum, labelNum));
Gv_SetVarX(*insptr++, VM_GetStruct(tsprLabel.flags, (intptr_t *)((char *)spriteext[spriteNum].tspr + tsprLabel.offset)));
continue;
}

View file

@ -38,8 +38,6 @@ int32_t __fastcall VM_GetSector(int const sectNum, int32_t labelNum);
void __fastcall VM_SetSector(int const sectNum, int const labelNum, int32_t newValue);
int32_t __fastcall VM_GetSprite(int const spriteNum, int32_t labelNum, int const lParm2);
void __fastcall VM_SetSprite(int const spriteNum, int const labelNum, int const lParm2, int32_t const newValue);
int32_t __fastcall VM_GetTsprite(int const spriteNum, int32_t labelNum);
void __fastcall VM_SetTsprite(int const spriteNum, int const labelNum, int32_t const newValue);
int32_t __fastcall VM_GetProjectile(int const tileNum, int32_t labelNum);
void __fastcall VM_SetProjectile(int const tileNum, int const labelNum, int32_t const newValue);
int32_t __fastcall VM_GetTileData(int const tileNum, int32_t labelNum);
@ -1126,92 +1124,6 @@ int32_t __fastcall VM_GetSprite(int const spriteNum, int32_t labelNum, int const
return labelNum;
}
int32_t __fastcall VM_GetTsprite(int const spriteNum, int32_t labelNum)
{
if (EDUKE32_PREDICT_FALSE((unsigned)spriteNum >= MAXSPRITES || spriteext[spriteNum].tspr == NULL))
{
CON_ERRPRINTF("invalid sprite %d or no tsprite\n", spriteNum);
return -1;
}
auto const &t = *spriteext[spriteNum].tspr;
switch (labelNum)
{
case ACTOR_X: labelNum = t.x; break;
case ACTOR_Y: labelNum = t.y; break;
case ACTOR_Z: labelNum = t.z; break;
case ACTOR_CSTAT: labelNum = t.cstat; break;
case ACTOR_PICNUM: labelNum = t.picnum; break;
case ACTOR_SHADE: labelNum = t.shade; break;
case ACTOR_PAL: labelNum = t.pal; break;
case ACTOR_CLIPDIST: labelNum = t.clipdist; break;
case ACTOR_DETAIL: labelNum = t.blend; break;
case ACTOR_XREPEAT: labelNum = t.xrepeat; break;
case ACTOR_YREPEAT: labelNum = t.yrepeat; break;
case ACTOR_XOFFSET: labelNum = t.xoffset; break;
case ACTOR_YOFFSET: labelNum = t.yoffset; break;
case ACTOR_SECTNUM: labelNum = t.sectnum; break;
case ACTOR_STATNUM: labelNum = t.statnum; break;
case ACTOR_ANG: labelNum = t.ang; break;
case ACTOR_OWNER: labelNum = t.owner; break;
case ACTOR_XVEL: labelNum = t.xvel; break;
case ACTOR_YVEL: labelNum = t.yvel; break;
case ACTOR_ZVEL: labelNum = t.zvel; break;
case ACTOR_EXTRA: labelNum = t.extra; break;
case ACTOR_LOTAG: labelNum = (int16_t)t.lotag; break;
case ACTOR_HITAG: labelNum = (int16_t)t.hitag; break;
case ACTOR_ULOTAG: labelNum = (uint16_t)t.lotag; break;
case ACTOR_UHITAG: labelNum = (uint16_t)t.hitag; break;
default: EDUKE32_UNREACHABLE_SECTION(labelNum = -1; break);
}
return labelNum;
}
void __fastcall VM_SetTsprite(int const spriteNum, int const labelNum, int32_t const newValue)
{
if (EDUKE32_PREDICT_FALSE((unsigned) spriteNum >= MAXSPRITES || spriteext[spriteNum].tspr == NULL))
{
CON_ERRPRINTF("invalid sprite %d or no tsprite\n", spriteNum);
return;
}
auto &t = *spriteext[spriteNum].tspr;
switch (labelNum)
{
case ACTOR_X: t.x = newValue; break;
case ACTOR_Y: t.y = newValue; break;
case ACTOR_Z: t.z = newValue; break;
case ACTOR_CSTAT: t.cstat = newValue; break;
case ACTOR_PICNUM: t.picnum = newValue; break;
case ACTOR_SHADE: t.shade = newValue; break;
case ACTOR_PAL: t.pal = newValue; break;
case ACTOR_CLIPDIST: t.clipdist = newValue; break;
case ACTOR_DETAIL: t.blend = newValue; break;
case ACTOR_XREPEAT: t.xrepeat = newValue; break;
case ACTOR_YREPEAT: t.yrepeat = newValue; break;
case ACTOR_XOFFSET: t.xoffset = newValue; break;
case ACTOR_YOFFSET: t.yoffset = newValue; break;
case ACTOR_SECTNUM: t.sectnum = newValue; break;
case ACTOR_STATNUM: t.statnum = newValue; break;
case ACTOR_ANG: t.ang = newValue; break;
case ACTOR_OWNER: t.owner = newValue; break;
case ACTOR_XVEL: t.xvel = newValue; break;
case ACTOR_YVEL: t.yvel = newValue; break;
case ACTOR_ZVEL: t.zvel = newValue; break;
case ACTOR_EXTRA: t.extra = newValue; break;
case ACTOR_LOTAG: t.lotag = (int16_t)newValue; break;
case ACTOR_HITAG: t.hitag = (int16_t)newValue; break;
case ACTOR_ULOTAG: t.lotag = (uint16_t)newValue; break;
case ACTOR_UHITAG: t.hitag = (uint16_t)newValue; break;
}
}
int32_t __fastcall VM_GetProjectile(int const tileNum, int32_t labelNum)
{
if (EDUKE32_PREDICT_FALSE((unsigned)tileNum >= MAXTILES || g_tile[tileNum].proj == NULL))

View file

@ -617,6 +617,143 @@ int __fastcall Gv_GetArrayValue(int const id, int index)
goto badindex; \
}
int __fastcall Gv_GetSpecialVar(int gameVar, int spriteNum, int playerNum)
{
int returnValue = 0;
if (gameVar & GV_FLAG_ARRAY)
{
gameVar &= (MAXGAMEVARS-1); // ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1));
int const arrayIndex = Gv_GetVar(*insptr++, spriteNum, playerNum);
if (EDUKE32_PREDICT_FALSE((unsigned)arrayIndex >= (unsigned)aGameArrays[gameVar].size))
{
spriteNum = arrayIndex;
goto badarrayindex;
}
returnValue = Gv_GetArrayValue(gameVar, arrayIndex);
}
else if (gameVar & GV_FLAG_STRUCT) // struct shortcut vars
{
int arrayIndexVar = *insptr++;
int arrayIndex = Gv_GetVar(arrayIndexVar, spriteNum, playerNum);
int const labelNum = *insptr++;
gameVar &= (MAXGAMEVARS-1);
switch (gameVar - g_structVarIDs)
{
case STRUCT_SPRITE:
arrayIndexVar = (ActorLabels[labelNum].flags & LABEL_HASPARM2) ? Gv_GetVar(*insptr++, spriteNum, playerNum) : 0;
CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetSprite(arrayIndex, labelNum, arrayIndexVar);
break;
case STRUCT_SPRITE_INTERNAL__:
CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetStruct(ActorLabels[labelNum].flags, (intptr_t *)((char *)&sprite[arrayIndex] + ActorLabels[labelNum].offset));
break;
case STRUCT_ACTOR_INTERNAL__:
CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetStruct(ActorLabels[labelNum].flags, (intptr_t *)((char *)&actor[arrayIndex] + ActorLabels[labelNum].offset));
break;
case STRUCT_SPRITEEXT_INTERNAL__:
CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetStruct(ActorLabels[labelNum].flags, (intptr_t *)((char *)&spriteext[arrayIndex] + ActorLabels[labelNum].offset));
break;
case STRUCT_TSPR:
CHECK_INDEX(MAXSPRITES);
returnValue
= VM_GetStruct(TsprLabels[labelNum].flags, (intptr_t *)((char *)(spriteext[arrayIndex].tspr) + TsprLabels[labelNum].offset));
break;
case STRUCT_THISPROJECTILE:
CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetActiveProjectile(arrayIndex, labelNum);
break;
case STRUCT_PROJECTILE:
CHECK_INDEX(MAXTILES);
returnValue = VM_GetProjectile(arrayIndex, labelNum);
break;
case STRUCT_TILEDATA:
if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.pSprite->picnum;
CHECK_INDEX(MAXTILES);
returnValue = VM_GetTileData(arrayIndex, labelNum);
break;
case STRUCT_PALDATA:
if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.pSprite->pal;
CHECK_INDEX(MAXPALOOKUPS);
returnValue = VM_GetPalData(arrayIndex, labelNum);
break;
case STRUCT_PLAYER:
if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.playerNum;
arrayIndexVar
= (EDUKE32_PREDICT_FALSE(PlayerLabels[labelNum].flags & LABEL_HASPARM2)) ? Gv_GetVar(*insptr++, spriteNum, playerNum) : 0;
CHECK_INDEX(MAXPLAYERS);
returnValue = VM_GetPlayer(arrayIndex, labelNum, arrayIndexVar);
break;
case STRUCT_INPUT:
if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.playerNum;
CHECK_INDEX(MAXPLAYERS);
returnValue = VM_GetPlayerInput(arrayIndex, labelNum);
break;
// no THISACTOR check here because we convert those cases to setvarvar
case STRUCT_ACTORVAR: returnValue = Gv_GetVar(labelNum, arrayIndex, vm.playerNum); break;
case STRUCT_PLAYERVAR: returnValue = Gv_GetVar(labelNum, vm.spriteNum, arrayIndex); break;
case STRUCT_SECTOR:
if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.pSprite->sectnum;
CHECK_INDEX(MAXSECTORS);
returnValue = (SectorLabels[labelNum].offset != -1 && (SectorLabels[labelNum].flags & LABEL_READFUNC) == 0)
? VM_GetStruct(SectorLabels[labelNum].flags, (intptr_t *)((char *)&sector[arrayIndex] + SectorLabels[labelNum].offset))
: VM_GetSector(arrayIndex, labelNum);
break;
case STRUCT_WALL:
CHECK_INDEX(MAXWALLS);
returnValue = (WallLabels[labelNum].offset != -1 && (WallLabels[labelNum].flags & LABEL_READFUNC) == 0)
? VM_GetStruct(WallLabels[labelNum].flags, (intptr_t *)((char *)&wall[arrayIndex] + WallLabels[labelNum].offset))
: VM_GetWall(arrayIndex, labelNum);
break;
case STRUCT_USERDEF:
arrayIndexVar = (EDUKE32_PREDICT_FALSE(UserdefsLabels[labelNum].flags & LABEL_HASPARM2)) ? Gv_GetVarX(*insptr++) : 0;
returnValue = VM_GetUserdef(labelNum, arrayIndexVar);
break;
default: EDUKE32_UNREACHABLE_SECTION(return -1);
}
}
return returnValue;
badindex:
CON_ERRPRINTF("Gv_GetVar(): invalid index %d for \"%s\"\n", spriteNum, aGameVars[gameVar].szLabel);
return -1;
badarrayindex:
CON_ERRPRINTF("Gv_GetVar(): invalid array index (%s[%d])\n", aGameArrays[gameVar].szLabel,spriteNum);
return -1;
}
int __fastcall Gv_GetVar(int gameVar, int spriteNum, int playerNum)
{
if (gameVar == g_thisActorVarID)
@ -626,14 +763,13 @@ int __fastcall Gv_GetVar(int gameVar, int spriteNum, int playerNum)
return *insptr++;
int invertResult = !!(gameVar & GV_FLAG_NEGATIVE);
gamevar_t const & var = aGameVars[gameVar &= (MAXGAMEVARS-1)];
if ((gameVar & ~GV_FLAG_NEGATIVE) >= g_gameVarCount)
goto special;
return (Gv_GetSpecialVar(gameVar, spriteNum, playerNum) ^ -invertResult) + invertResult;
int returnValue, varFlags;
varFlags = var.flags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK);
gamevar_t const & var = aGameVars[gameVar &= (MAXGAMEVARS-1)];
int returnValue;
int const varFlags = var.flags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK);
if (varFlags == GAMEVAR_PERACTOR)
{
@ -661,143 +797,6 @@ int __fastcall Gv_GetVar(int gameVar, int spriteNum, int playerNum)
return (returnValue ^ -invertResult) + invertResult;
special:
if (gameVar & GV_FLAG_ARRAY)
{
gameVar &= (MAXGAMEVARS-1); // ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1));
int const arrayIndex = Gv_GetVar(*insptr++, spriteNum, playerNum);
if (EDUKE32_PREDICT_FALSE((unsigned)arrayIndex >= (unsigned)aGameArrays[gameVar].size))
{
spriteNum = arrayIndex;
goto badarrayindex;
}
returnValue = Gv_GetArrayValue(gameVar, arrayIndex);
}
else if (gameVar & GV_FLAG_STRUCT) // struct shortcut vars
{
int arrayIndexVar = *insptr++;
int arrayIndex = Gv_GetVar(arrayIndexVar, spriteNum, playerNum);
int const labelNum = *insptr++;
gameVar &= (MAXGAMEVARS-1);
switch (gameVar - g_structVarIDs)
{
case STRUCT_SPRITE:
arrayIndexVar = (ActorLabels[labelNum].flags & LABEL_HASPARM2) ? Gv_GetVar(*insptr++, spriteNum, playerNum) : 0;
CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetSprite(arrayIndex, labelNum, arrayIndexVar);
break;
case STRUCT_SPRITE_INTERNAL__:
CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetStruct(ActorLabels[labelNum].flags, (intptr_t *)((char *)&sprite[arrayIndex] + ActorLabels[labelNum].offset));
break;
case STRUCT_ACTOR_INTERNAL__:
CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetStruct(ActorLabels[labelNum].flags, (intptr_t *)((char *)&actor[arrayIndex] + ActorLabels[labelNum].offset));
break;
case STRUCT_SPRITEEXT_INTERNAL__:
CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetStruct(ActorLabels[labelNum].flags, (intptr_t *)((char *)&spriteext[arrayIndex] + ActorLabels[labelNum].offset));
break;
case STRUCT_TSPR:
CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetTsprite(arrayIndex, labelNum);
break;
case STRUCT_THISPROJECTILE:
CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetActiveProjectile(arrayIndex, labelNum);
break;
case STRUCT_PROJECTILE:
CHECK_INDEX(MAXTILES);
returnValue = VM_GetProjectile(arrayIndex, labelNum);
break;
case STRUCT_TILEDATA:
if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.pSprite->picnum;
CHECK_INDEX(MAXTILES);
returnValue = VM_GetTileData(arrayIndex, labelNum);
break;
case STRUCT_PALDATA:
if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.pSprite->pal;
CHECK_INDEX(MAXPALOOKUPS);
returnValue = VM_GetPalData(arrayIndex, labelNum);
break;
case STRUCT_PLAYER:
if (arrayIndexVar == g_thisActorVarID) arrayIndex = vm.playerNum;
arrayIndexVar = (EDUKE32_PREDICT_FALSE(PlayerLabels[labelNum].flags & LABEL_HASPARM2)) ?
Gv_GetVar(*insptr++, spriteNum, playerNum) : 0;
CHECK_INDEX(MAXPLAYERS);
returnValue = VM_GetPlayer(arrayIndex, labelNum, arrayIndexVar);
break;
case STRUCT_INPUT:
if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.playerNum;
CHECK_INDEX(MAXPLAYERS);
returnValue = VM_GetPlayerInput(arrayIndex, labelNum);
break;
// no THISACTOR check here because we convert those cases to setvarvar
case STRUCT_ACTORVAR:
returnValue = Gv_GetVar(labelNum, arrayIndex, vm.playerNum);
break;
case STRUCT_PLAYERVAR:
returnValue = Gv_GetVar(labelNum, vm.spriteNum, arrayIndex);
break;
case STRUCT_SECTOR:
if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.pSprite->sectnum;
CHECK_INDEX(MAXSECTORS);
returnValue = (SectorLabels[labelNum].offset != -1 && (SectorLabels[labelNum].flags & LABEL_READFUNC) == 0)
? VM_GetStruct(SectorLabels[labelNum].flags, (intptr_t *)((char *)&sector[arrayIndex] + SectorLabels[labelNum].offset))
: VM_GetSector(arrayIndex, labelNum);
break;
case STRUCT_WALL:
CHECK_INDEX(MAXWALLS);
returnValue = (WallLabels[labelNum].offset != -1 && (WallLabels[labelNum].flags & LABEL_READFUNC) == 0)
? VM_GetStruct(WallLabels[labelNum].flags, (intptr_t *)((char *)&wall[arrayIndex] + WallLabels[labelNum].offset))
: VM_GetWall(arrayIndex, labelNum);
break;
case STRUCT_USERDEF:
arrayIndexVar = (EDUKE32_PREDICT_FALSE(UserdefsLabels[labelNum].flags & LABEL_HASPARM2)) ? Gv_GetVarX(*insptr++) : 0;
returnValue = VM_GetUserdef(labelNum, arrayIndexVar);
break;
default:
EDUKE32_UNREACHABLE_SECTION(return -1);
}
}
else
{
CON_ERRPRINTF("Gv_GetVar(): invalid gamevar ID (%d)\n", gameVar);
return -1;
}
return (returnValue ^ -invertResult) + invertResult;
badarrayindex:
CON_ERRPRINTF("Gv_GetVar(): invalid array index (%s[%d])\n", aGameArrays[gameVar].szLabel,spriteNum);
return -1;
badindex:
CON_ERRPRINTF("Gv_GetVar(): invalid index %d for \"%s\"\n", spriteNum, var.szLabel);
return -1;
@ -903,7 +902,7 @@ int __fastcall Gv_GetSpecialVarX(int gameVar)
else if (gameVar & GV_FLAG_STRUCT) // struct shortcut vars
{
int arrayIndexVar = *insptr++;
auto const structIndex = (gameVar & (MAXGAMEVARS-1)) - g_structVarIDs;
int const structIndex = (gameVar & (MAXGAMEVARS-1)) - g_structVarIDs;
int arrayIndex = structIndex != STRUCT_USERDEF ? Gv_GetVarX(arrayIndexVar) : -1;
int const labelNum = *insptr++;
@ -932,7 +931,7 @@ int __fastcall Gv_GetSpecialVarX(int gameVar)
case STRUCT_TSPR:
CHECK_INDEX(MAXSPRITES, GVX_BADSPRITE);
returnValue = VM_GetTsprite(arrayIndex, labelNum);
returnValue = VM_GetStruct(TsprLabels[labelNum].flags, (intptr_t *)((char *)(spriteext[arrayIndex].tspr) + TsprLabels[labelNum].offset));
break;
case STRUCT_THISPROJECTILE:
@ -1085,7 +1084,7 @@ void __fastcall Gv_GetManyVars(int const numVars, int32_t * const outBuf)
continue;
}
gamevar_t &var = aGameVars[gameVar &= MAXGAMEVARS-1];
gamevar_t const &var = aGameVars[gameVar &= MAXGAMEVARS-1];
int const varFlags = var.flags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK);
int value = var.global;
@ -1119,7 +1118,7 @@ perr:
void __fastcall Gv_SetVarX(int const gameVar, int const newValue)
{
gamevar_t & var = aGameVars[gameVar];
gamevar_t &var = aGameVars[gameVar];
int const varFlags = var.flags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK);
if (!varFlags) var.global = newValue;
@ -1162,7 +1161,7 @@ static intptr_t *Gv_GetVarDataPtr(const char *szGameLabel)
if (EDUKE32_PREDICT_FALSE(gameVar < 0))
return NULL;
gamevar_t & var = aGameVars[gameVar];
gamevar_t &var = aGameVars[gameVar];
if (var.flags & (GAMEVAR_PERACTOR | GAMEVAR_PERPLAYER))
{
@ -1434,7 +1433,7 @@ static int32_t G_StaticToDynamicSound(int32_t const sound)
// We cannot do this before, because the dynamic maps are not yet set up then.
void Gv_FinalizeWeaponDefaults(void)
{
for (bssize_t i=0; i<MAX_WEAPONS; i++)
for (int i=0; i<MAX_WEAPONS; i++)
{
FINISH_WEAPON_DEFAULT_TILE(i, Shoots);
FINISH_WEAPON_DEFAULT_TILE(i, Spawn);