Gamevar cleanup

git-svn-id: https://svn.eduke32.com/eduke32@6234 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2017-06-23 03:59:06 +00:00
parent 49edb0e9f6
commit f698b1e733
2 changed files with 71 additions and 111 deletions

View file

@ -111,7 +111,7 @@ void VM_ScriptInfo(intptr_t const *ptr, int range)
if (ptr == insptr) if (ptr == insptr)
{ {
if (vm.spriteNum) if (vm.spriteNum)
initprintf("current actor: %d (%d)\n", vm.spriteNum, TrackerCast(vm.pSprite->picnum)); initprintf("current actor: %d (%d)\n", vm.spriteNum, vm.pUSprite->picnum);
initprintf("g_errorLineNum: %d, g_tw: %d\n", g_errorLineNum, g_tw); initprintf("g_errorLineNum: %d, g_tw: %d\n", g_errorLineNum, g_tw);
} }
@ -515,7 +515,7 @@ GAMEEXEC_STATIC void VM_AlterAng(int32_t const moveFlags)
{ {
AC_MOVE_ID(vm.pData) = 0; AC_MOVE_ID(vm.pData) = 0;
OSD_Printf(OSD_ERROR "bad moveptr for actor %d (%d)!\n", vm.spriteNum, TrackerCast(vm.pSprite->picnum)); OSD_Printf(OSD_ERROR "bad moveptr for actor %d (%d)!\n", vm.spriteNum, vm.pUSprite->picnum);
return; return;
} }
@ -535,7 +535,6 @@ GAMEEXEC_STATIC void VM_AlterAng(int32_t const moveFlags)
if (moveFlags&seekplayer) if (moveFlags&seekplayer)
{ {
int angDiff;
int const spriteAngle = vm.pSprite->ang; int const spriteAngle = vm.pSprite->ang;
int const holoDukeSprite = vm.pPlayer->holoduke_on; int const holoDukeSprite = vm.pPlayer->holoduke_on;
@ -693,7 +692,7 @@ dead:
if (EDUKE32_PREDICT_FALSE((unsigned)AC_MOVE_ID(vm.pData) >= (unsigned)g_scriptSize-1)) if (EDUKE32_PREDICT_FALSE((unsigned)AC_MOVE_ID(vm.pData) >= (unsigned)g_scriptSize-1))
{ {
AC_MOVE_ID(vm.pData) = 0; AC_MOVE_ID(vm.pData) = 0;
OSD_Printf(OSD_ERROR "clearing bad moveptr for actor %d (%d)\n", vm.spriteNum, TrackerCast(vm.pSprite->picnum)); OSD_Printf(OSD_ERROR "clearing bad moveptr for actor %d (%d)\n", vm.spriteNum, vm.pUSprite->picnum);
return; return;
} }
@ -1490,7 +1489,7 @@ skip_check:
insptr++; insptr++;
if (EDUKE32_PREDICT_FALSE(((unsigned)vm.pSprite->yvel >= MAXSOUNDS))) if (EDUKE32_PREDICT_FALSE(((unsigned)vm.pSprite->yvel >= MAXSOUNDS)))
{ {
CON_ERRPRINTF("Invalid sound %d\n", TrackerCast(vm.pSprite->yvel)); CON_ERRPRINTF("Invalid sound %d\n", vm.pUSprite->yvel);
continue; continue;
} }
if (!S_CheckSoundPlaying(vm.spriteNum,vm.pSprite->yvel)) if (!S_CheckSoundPlaying(vm.spriteNum,vm.pSprite->yvel))
@ -2627,7 +2626,7 @@ nullquote:
if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors)) if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors))
{ {
CON_ERRPRINTF("Invalid sector %d\n", TrackerCast(vm.pSprite->sectnum)); CON_ERRPRINTF("Invalid sector %d\n", vm.pUSprite->sectnum);
continue; continue;
} }
@ -2657,7 +2656,7 @@ nullquote:
{ {
if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors)) if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors))
{ {
CON_ERRPRINTF("Invalid sector %d\n", TrackerCast(vm.pSprite->sectnum)); CON_ERRPRINTF("invalid sector %d\n", vm.pUSprite->sectnum);
insptr++; insptr++;
continue; continue;
} }
@ -2692,7 +2691,7 @@ nullquote:
if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors)) if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors))
{ {
CON_ERRPRINTF("Invalid sector %d\n", TrackerCast(vm.pSprite->sectnum)); CON_ERRPRINTF("Invalid sector %d\n", vm.pUSprite->sectnum);
insptr++; insptr++;
continue; continue;
} }
@ -2712,7 +2711,7 @@ nullquote:
if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors)) if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors))
{ {
CON_ERRPRINTF("Invalid sector %d\n", TrackerCast(vm.pSprite->sectnum)); CON_ERRPRINTF("Invalid sector %d\n", vm.pUSprite->sectnum);
continue; continue;
} }
@ -2733,7 +2732,7 @@ nullquote:
if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors)) if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors))
{ {
CON_ERRPRINTF("Invalid sector %d\n", TrackerCast(vm.pSprite->sectnum)); CON_ERRPRINTF("Invalid sector %d\n", vm.pUSprite->sectnum);
continue; continue;
} }
@ -3407,7 +3406,7 @@ nullquote:
insptr++; insptr++;
if ((unsigned)vm.pSprite->sectnum >= MAXSECTORS) if ((unsigned)vm.pSprite->sectnum >= MAXSECTORS)
{ {
CON_ERRPRINTF("Invalid sector %d\n", TrackerCast(vm.pSprite->sectnum)); CON_ERRPRINTF("Invalid sector %d\n", vm.pUSprite->sectnum);
insptr++; insptr++;
continue; continue;
} }

View file

@ -602,7 +602,7 @@ int __fastcall Gv_GetVar(int gameVar, int spriteNum, int playerNum)
int invertResult = !!(gameVar & (MAXGAMEVARS << 1)); int invertResult = !!(gameVar & (MAXGAMEVARS << 1));
if (EDUKE32_PREDICT_FALSE((gameVar & ~(MAXGAMEVARS << 1)) >= g_gameVarCount)) if ((gameVar & ~(MAXGAMEVARS << 1)) >= g_gameVarCount)
goto special; goto special;
gameVar &= (MAXGAMEVARS - 1); gameVar &= (MAXGAMEVARS - 1);
@ -652,98 +652,78 @@ special:
} }
else if (gameVar&(MAXGAMEVARS<<3)) // struct shortcut vars else if (gameVar&(MAXGAMEVARS<<3)) // struct shortcut vars
{ {
int arrayIndexVar = *insptr++; int arrayIndexVar = *insptr++;
int arrayIndex = Gv_GetVar(arrayIndexVar, spriteNum, playerNum); int arrayIndex = Gv_GetVar(arrayIndexVar, spriteNum, playerNum);
int const labelNum = *insptr++;
gameVar &= (MAXGAMEVARS - 1); gameVar &= (MAXGAMEVARS - 1);
switch (gameVar - g_structVarIDs) switch (gameVar - g_structVarIDs)
{ {
case STRUCT_SPRITE: case STRUCT_SPRITE:
{ arrayIndexVar = (EDUKE32_PREDICT_FALSE(ActorLabels[labelNum].flags & LABEL_HASPARM2)) ?
int const label = *insptr++;
arrayIndexVar = (EDUKE32_PREDICT_FALSE(ActorLabels[label].flags & LABEL_HASPARM2)) ?
Gv_GetVar(*insptr++, spriteNum, playerNum) : 0; Gv_GetVar(*insptr++, spriteNum, playerNum) : 0;
CHECK_INDEX(MAXSPRITES); CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetSprite(arrayIndex, label, arrayIndexVar); returnValue = VM_GetSprite(arrayIndex, labelNum, arrayIndexVar);
break; break;
}
case STRUCT_TSPR: case STRUCT_TSPR:
{
int const label = *insptr++;
CHECK_INDEX(MAXSPRITES); CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetTsprite(arrayIndex, label); returnValue = VM_GetTsprite(arrayIndex, labelNum);
break; break;
}
case STRUCT_THISPROJECTILE: case STRUCT_THISPROJECTILE:
{
int const label = *insptr++;
CHECK_INDEX(MAXSPRITES); CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetActiveProjectile(arrayIndex, label); returnValue = VM_GetActiveProjectile(arrayIndex, labelNum);
break; break;
}
case STRUCT_PROJECTILE: case STRUCT_PROJECTILE:
{
int const label = *insptr++;
CHECK_INDEX(MAXTILES); CHECK_INDEX(MAXTILES);
returnValue = VM_GetProjectile(arrayIndex, label); returnValue = VM_GetProjectile(arrayIndex, labelNum);
break; break;
}
case STRUCT_TILEDATA: case STRUCT_TILEDATA:
{
int const label = *insptr++;
CHECK_INDEX(MAXTILES); CHECK_INDEX(MAXTILES);
returnValue = VM_GetTileData(arrayIndex, label); returnValue = VM_GetTileData(arrayIndex, labelNum);
break; break;
}
case STRUCT_PALDATA: case STRUCT_PALDATA:
{
int const label = *insptr++;
CHECK_INDEX(MAXPALOOKUPS); CHECK_INDEX(MAXPALOOKUPS);
returnValue = VM_GetPalData(arrayIndex, label); returnValue = VM_GetPalData(arrayIndex, labelNum);
break; break;
}
case STRUCT_PLAYER: case STRUCT_PLAYER:
{
int const label = *insptr++;
if (arrayIndexVar == g_thisActorVarID) arrayIndex = vm.playerNum; if (arrayIndexVar == g_thisActorVarID) arrayIndex = vm.playerNum;
arrayIndexVar = (EDUKE32_PREDICT_FALSE(PlayerLabels[label].flags & LABEL_HASPARM2)) ? arrayIndexVar = (EDUKE32_PREDICT_FALSE(PlayerLabels[labelNum].flags & LABEL_HASPARM2)) ?
Gv_GetVar(*insptr++, spriteNum, playerNum) : 0; Gv_GetVar(*insptr++, spriteNum, playerNum) : 0;
CHECK_INDEX(MAXPLAYERS); CHECK_INDEX(MAXPLAYERS);
returnValue = VM_GetPlayer(arrayIndex, label, arrayIndexVar); returnValue = VM_GetPlayer(arrayIndex, labelNum, arrayIndexVar);
break; break;
}
case STRUCT_INPUT:
{
int const label = *insptr++;
case STRUCT_INPUT:
if (arrayIndexVar == g_thisActorVarID) arrayIndex = vm.playerNum; if (arrayIndexVar == g_thisActorVarID) arrayIndex = vm.playerNum;
CHECK_INDEX(MAXPLAYERS); CHECK_INDEX(MAXPLAYERS);
returnValue = VM_GetPlayerInput(arrayIndex, label); returnValue = VM_GetPlayerInput(arrayIndex, labelNum);
break; break;
}
case STRUCT_ACTORVAR: case STRUCT_ACTORVAR:
case STRUCT_PLAYERVAR: case STRUCT_PLAYERVAR:
returnValue = Gv_GetVar(*insptr++, arrayIndex, playerNum); returnValue = Gv_GetVar(labelNum, arrayIndex, playerNum);
break; break;
case STRUCT_SECTOR: case STRUCT_SECTOR:
if (arrayIndexVar == g_thisActorVarID) arrayIndex = sprite[vm.spriteNum].sectnum; if (arrayIndexVar == g_thisActorVarID) arrayIndex = sprite[vm.spriteNum].sectnum;
CHECK_INDEX(MAXSECTORS); CHECK_INDEX(MAXSECTORS);
returnValue = VM_GetSector(arrayIndex, *insptr++); returnValue = VM_GetSector(arrayIndex, labelNum);
break; break;
case STRUCT_WALL: case STRUCT_WALL:
CHECK_INDEX(MAXWALLS); CHECK_INDEX(MAXWALLS);
returnValue = VM_GetWall(arrayIndex, *insptr++); returnValue = VM_GetWall(arrayIndex, labelNum);
break; break;
case STRUCT_USERDEF: case STRUCT_USERDEF:
returnValue = VM_GetUserdef(*insptr++); returnValue = VM_GetUserdef(labelNum);
break; break;
default: default:
@ -822,17 +802,17 @@ enum
}; };
static const char *gvxerrs[] = { static const char *gvxerrs[] = {
"Gv_GetVarX(): invalid gamevar ID", "invalid gamevar ID",
"Gv_GetVarX(): invalid player ID", "invalid player ID",
"Gv_GetVarX(): invalid sprite ID", "invalid sprite ID",
"Gv_GetVarX(): invalid sector ID", "invalid sector ID",
"Gv_GetVarX(): invalid wall ID", "invalid wall ID",
"Gv_GetVarX(): invalid array index", "invalid array index",
"Gv_GetVarX(): invalid tile ID", "invalid tile ID",
"Gv_GetVarX(): invalid pal ID", "invalid pal ID",
}; };
#define CHECK_INDEX(arrayIndex, range, error) \ #define CHECK_INDEX(range, error) \
if (EDUKE32_PREDICT_FALSE((unsigned)arrayIndex >= range)) \ if (EDUKE32_PREDICT_FALSE((unsigned)arrayIndex >= range)) \
\ \
{ \ { \
@ -866,97 +846,78 @@ int __fastcall Gv_GetSpecialVarX(int gameVar)
} }
else if (gameVar & (MAXGAMEVARS << 3)) // struct shortcut vars else if (gameVar & (MAXGAMEVARS << 3)) // struct shortcut vars
{ {
int arrayIndexVar = *insptr++; int arrayIndexVar = *insptr++;
int arrayIndex = Gv_GetVarX(arrayIndexVar); int arrayIndex = Gv_GetVarX(arrayIndexVar);
int const labelNum = *insptr++;
switch ((gameVar & (MAXGAMEVARS - 1)) - g_structVarIDs) switch ((gameVar & (MAXGAMEVARS - 1)) - g_structVarIDs)
{ {
case STRUCT_SPRITE: case STRUCT_SPRITE:
{
int const labelNum = *insptr++;
arrayIndexVar = (EDUKE32_PREDICT_FALSE(ActorLabels[labelNum].flags & LABEL_HASPARM2)) ? Gv_GetVarX(*insptr++) : 0; arrayIndexVar = (EDUKE32_PREDICT_FALSE(ActorLabels[labelNum].flags & LABEL_HASPARM2)) ? Gv_GetVarX(*insptr++) : 0;
CHECK_INDEX(arrayIndex, MAXSPRITES, GVX_BADSPRITE); CHECK_INDEX(MAXSPRITES, GVX_BADSPRITE);
returnValue = VM_GetSprite(arrayIndex, labelNum, arrayIndexVar); returnValue = VM_GetSprite(arrayIndex, labelNum, arrayIndexVar);
break; break;
}
case STRUCT_TSPR: case STRUCT_TSPR:
{ CHECK_INDEX(MAXSPRITES, GVX_BADSPRITE);
int const labelNum = *insptr++;
CHECK_INDEX(arrayIndex, MAXSPRITES, GVX_BADSPRITE);
returnValue = VM_GetTsprite(arrayIndex, labelNum); returnValue = VM_GetTsprite(arrayIndex, labelNum);
break; break;
}
case STRUCT_THISPROJECTILE: case STRUCT_THISPROJECTILE:
{ CHECK_INDEX(MAXSPRITES, GVX_BADSPRITE);
int const labelNum = *insptr++;
CHECK_INDEX(arrayIndex, MAXSPRITES, GVX_BADSPRITE);
returnValue = VM_GetActiveProjectile(arrayIndex, labelNum); returnValue = VM_GetActiveProjectile(arrayIndex, labelNum);
break; break;
}
case STRUCT_PROJECTILE: case STRUCT_PROJECTILE:
{ CHECK_INDEX(MAXTILES, GVX_BADTILE);
int const labelNum = *insptr++;
CHECK_INDEX(arrayIndex, MAXTILES, GVX_BADTILE);
returnValue = VM_GetProjectile(arrayIndex, labelNum); returnValue = VM_GetProjectile(arrayIndex, labelNum);
break; break;
}
case STRUCT_TILEDATA: case STRUCT_TILEDATA:
{ CHECK_INDEX(MAXTILES, GVX_BADTILE);
int const labelNum = *insptr++;
CHECK_INDEX(arrayIndex, MAXTILES, GVX_BADTILE);
returnValue = VM_GetTileData(arrayIndex, labelNum); returnValue = VM_GetTileData(arrayIndex, labelNum);
break; break;
}
case STRUCT_PALDATA: case STRUCT_PALDATA:
{ CHECK_INDEX(MAXPALOOKUPS, GVX_BADPAL);
int const labelNum = *insptr++;
CHECK_INDEX(arrayIndex, MAXPALOOKUPS, GVX_BADPAL);
returnValue = VM_GetPalData(arrayIndex, labelNum); returnValue = VM_GetPalData(arrayIndex, labelNum);
break; break;
}
case STRUCT_PLAYER: case STRUCT_PLAYER:
{
int const labelNum = *insptr++;
if (arrayIndexVar == g_thisActorVarID) if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.playerNum; arrayIndex = vm.playerNum;
arrayIndexVar = (EDUKE32_PREDICT_FALSE(PlayerLabels[labelNum].flags & LABEL_HASPARM2)) ? arrayIndexVar = (EDUKE32_PREDICT_FALSE(PlayerLabels[labelNum].flags & LABEL_HASPARM2)) ?
Gv_GetVarX(*insptr++) : 0; Gv_GetVarX(*insptr++) : 0;
CHECK_INDEX(arrayIndex, MAXPLAYERS, GVX_BADPLAYER); CHECK_INDEX(MAXPLAYERS, GVX_BADPLAYER);
returnValue = VM_GetPlayer(arrayIndex, labelNum, arrayIndexVar); returnValue = VM_GetPlayer(arrayIndex, labelNum, arrayIndexVar);
break; break;
}
case STRUCT_INPUT: case STRUCT_INPUT:
{
int const labelNum = *insptr++;
if (arrayIndexVar == g_thisActorVarID) if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.playerNum; arrayIndex = vm.playerNum;
CHECK_INDEX(arrayIndex, MAXPLAYERS, GVX_BADPLAYER); CHECK_INDEX(MAXPLAYERS, GVX_BADPLAYER);
returnValue = VM_GetPlayerInput(arrayIndex, labelNum); returnValue = VM_GetPlayerInput(arrayIndex, labelNum);
break; break;
}
case STRUCT_ACTORVAR: case STRUCT_ACTORVAR:
case STRUCT_PLAYERVAR: case STRUCT_PLAYERVAR:
returnValue = Gv_GetVar(*insptr++, arrayIndex, vm.playerNum); returnValue = Gv_GetVar(labelNum, arrayIndex, vm.playerNum);
break; break;
case STRUCT_SECTOR: case STRUCT_SECTOR:
if (arrayIndexVar == g_thisActorVarID) if (arrayIndexVar == g_thisActorVarID)
arrayIndex = sprite[vm.spriteNum].sectnum; arrayIndex = sprite[vm.spriteNum].sectnum;
CHECK_INDEX(arrayIndex, MAXSECTORS, GVX_BADSECTOR); CHECK_INDEX(MAXSECTORS, GVX_BADSECTOR);
returnValue = VM_GetSector(arrayIndex, *insptr++); returnValue = VM_GetSector(arrayIndex, labelNum);
break; break;
case STRUCT_WALL: case STRUCT_WALL:
CHECK_INDEX(arrayIndex, MAXWALLS, GVX_BADWALL); CHECK_INDEX(MAXWALLS, GVX_BADWALL);
returnValue = VM_GetWall(arrayIndex, *insptr++); returnValue = VM_GetWall(arrayIndex, labelNum);
break; break;
case STRUCT_USERDEF: case STRUCT_USERDEF:
returnValue = VM_GetUserdef(*insptr++); returnValue = VM_GetUserdef(labelNum);
break; break;
default: EDUKE32_UNREACHABLE_SECTION(return -1); default: EDUKE32_UNREACHABLE_SECTION(return -1);
@ -966,7 +927,7 @@ int __fastcall Gv_GetSpecialVarX(int gameVar)
return returnValue; return returnValue;
badindex: badindex:
CON_ERRPRINTF("%s %d\n", gvxerrs[returnValue], gameVar); CON_ERRPRINTF("Gv_GetSpecialVarX(): %s %d\n", gvxerrs[returnValue], gameVar);
return -1; return -1;
} }
@ -983,7 +944,7 @@ int __fastcall Gv_GetVarX(int gameVar)
int const invertResult = !!(gameVar & (MAXGAMEVARS << 1)); int const invertResult = !!(gameVar & (MAXGAMEVARS << 1));
int returnValue = -1; int returnValue = -1;
if (EDUKE32_PREDICT_FALSE(gameVar >= g_gameVarCount && invertResult == 0)) if (gameVar >= g_gameVarCount && invertResult == 0)
returnValue = Gv_GetSpecialVarX(gameVar); returnValue = Gv_GetSpecialVarX(gameVar);
else else
{ {
@ -1011,25 +972,25 @@ int __fastcall Gv_GetVarX(int gameVar)
return (returnValue ^ -invertResult) + invertResult; return (returnValue ^ -invertResult) + invertResult;
perr: perr:
CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADPLAYER], vm.playerNum); CON_ERRPRINTF("Gv_GetVarX(): %s %d\n", gvxerrs[GVX_BADPLAYER], vm.playerNum);
return -1; return -1;
} }
void __fastcall Gv_GetManyVars(int const count, int32_t * const rv) void __fastcall Gv_GetManyVars(int const numVars, int32_t * const outBuf)
{ {
for (bssize_t j = 0; j < count; ++j) for (bssize_t j = 0; j < numVars; ++j)
{ {
int gameVar = *insptr++; int gameVar = *insptr++;
if (gameVar == g_thisActorVarID) if (gameVar == g_thisActorVarID)
{ {
rv[j] = vm.spriteNum; outBuf[j] = vm.spriteNum;
continue; continue;
} }
if (gameVar == MAXGAMEVARS) if (gameVar == MAXGAMEVARS)
{ {
rv[j] = *insptr++; outBuf[j] = *insptr++;
continue; continue;
} }
@ -1037,7 +998,7 @@ void __fastcall Gv_GetManyVars(int const count, int32_t * const rv)
if (EDUKE32_PREDICT_FALSE(gameVar >= g_gameVarCount && invertResult == 0)) if (EDUKE32_PREDICT_FALSE(gameVar >= g_gameVarCount && invertResult == 0))
{ {
rv[j] = Gv_GetSpecialVarX(gameVar); outBuf[j] = Gv_GetSpecialVarX(gameVar);
continue; continue;
} }
@ -1064,7 +1025,7 @@ void __fastcall Gv_GetManyVars(int const count, int32_t * const rv)
} }
} }
rv[j] = (value ^ -invertResult) + invertResult; outBuf[j] = (value ^ -invertResult) + invertResult;
continue; continue;
perr: perr: