Commit dd7594f8 authored by Richard Gobeille's avatar Richard Gobeille

Duke3d: split [get/set][wall/sector] into separate opcodes for direct access...

Duke3d: split [get/set][wall/sector] into separate opcodes for direct access through VM_GetStruct()/VM_SetStruct()

This makes them match [get/set]actor.
parent ec55c692
......@@ -837,13 +837,19 @@ const tokenmap_t iter_tokens [] =
// keywords_for_private_opcodes[] resolves those opcodes to the publicly facing keyword that can generate them
static const tokenmap_t keywords_for_private_opcodes[] =
{
{ "getactor", CON_GETSPRITEEXT },
{ "getactor", CON_GETACTORSTRUCT },
{ "getactor", CON_GETSPRITESTRUCT },
{ "getactor", CON_GETSPRITEEXT },
{ "getactor", CON_GETACTORSTRUCT },
{ "getactor", CON_GETSPRITESTRUCT },
{ "setactor", CON_SETSPRITEEXT },
{ "setactor", CON_SETACTORSTRUCT },
{ "setactor", CON_SETSPRITESTRUCT },
{ "setactor", CON_SETSPRITEEXT },
{ "setactor", CON_SETACTORSTRUCT },
{ "setactor", CON_SETSPRITESTRUCT },
{ "getwall", CON_GETWALLSTRUCT },
{ "setwall", CON_SETWALLSTRUCT },
{ "getsector", CON_GETSECTORSTRUCT },
{ "setsector", CON_SETSECTORSTRUCT },
};
char const *VM_GetKeywordForID(int32_t id)
......@@ -1565,10 +1571,28 @@ static void C_GetNextVarType(int32_t type)
break;
case STRUCT_SECTOR:
scriptWriteValue(SectorLabels[labelNum].lId);
{
auto const &label = SectorLabels[labelNum];
scriptWriteValue(label.lId);
Bassert((*varptr & (MAXGAMEVARS-1)) == g_structVarIDs + STRUCT_SECTOR);
if (label.offset != -1 && (label.flags & LABEL_READFUNC) == 0)
*varptr = (*varptr & ~(MAXGAMEVARS-1)) + g_structVarIDs + STRUCT_SECTOR_INTERNAL__;
}
break;
case STRUCT_WALL:
scriptWriteValue(WallLabels[labelNum].lId);
{
auto const &label = WallLabels[labelNum];
scriptWriteValue(label.lId);
Bassert((*varptr & (MAXGAMEVARS-1)) == g_structVarIDs + STRUCT_WALL);
if (label.offset != -1 && (label.flags & LABEL_READFUNC) == 0)
*varptr = (*varptr & ~(MAXGAMEVARS-1)) + g_structVarIDs + STRUCT_WALL_INTERNAL__;
}
break;
case STRUCT_PLAYER:
scriptWriteValue(PlayerLabels[labelNum].lId);
......@@ -3296,16 +3320,44 @@ DO_DEFSTATE:
}
case CON_SETSECTOR:
{
intptr_t * const ins = &g_scriptPtr[-1];
int const labelNum = C_GetStructureIndexes(1, &h_sector);
if (labelNum == -1)
continue;
Bassert((*ins & VM_INSTMASK) == CON_SETSECTOR);
auto const &label = SectorLabels[labelNum];
if (label.offset != -1 && (label.flags & LABEL_WRITEFUNC) == 0)
*ins = CON_SETSECTORSTRUCT | LINE_NUMBER;
scriptWriteValue(label.lId);
C_GetNextVar();
continue;
}
case CON_GETSECTOR:
{
intptr_t * const ins = &g_scriptPtr[-1];
int const labelNum = C_GetStructureIndexes(1, &h_sector);
if (labelNum == -1)
continue;
scriptWriteValue(SectorLabels[labelNum].lId);
Bassert((*ins & VM_INSTMASK) == CON_GETSECTOR);
auto const &label = SectorLabels[labelNum];
if (label.offset != -1 && (label.flags & LABEL_READFUNC) == 0)
*ins = CON_GETSECTORSTRUCT | LINE_NUMBER;
C_GetNextVarType((tw == CON_GETSECTOR) ? GAMEVAR_READONLY : 0);
scriptWriteValue(label.lId);
C_GetNextVarType(GAMEVAR_READONLY);
continue;
}
......@@ -3335,16 +3387,44 @@ DO_DEFSTATE:
}
case CON_SETWALL:
{
intptr_t * const ins = &g_scriptPtr[-1];
int const labelNum = C_GetStructureIndexes(1, &h_wall);
if (labelNum == -1)
continue;
Bassert((*ins & VM_INSTMASK) == CON_SETWALL);
auto const &label = WallLabels[labelNum];
if (label.offset != -1 && (label.flags & LABEL_WRITEFUNC) == 0)
*ins = CON_SETWALLSTRUCT | LINE_NUMBER;
scriptWriteValue(label.lId);
C_GetNextVar();
continue;
}
case CON_GETWALL:
{
intptr_t * const ins = &g_scriptPtr[-1];
int const labelNum = C_GetStructureIndexes(1, &h_wall);
if (labelNum == -1)
continue;
scriptWriteValue(WallLabels[labelNum].lId);
Bassert((*ins & VM_INSTMASK) == CON_GETWALL);
auto const &label = WallLabels[labelNum];
if (label.offset != -1 && (label.flags & LABEL_READFUNC) == 0)
*ins = CON_GETWALLSTRUCT | LINE_NUMBER;
C_GetNextVarType((tw == CON_GETWALL) ? GAMEVAR_READONLY : 0);
scriptWriteValue(label.lId);
C_GetNextVarType(GAMEVAR_READONLY);
continue;
}
......
......@@ -106,7 +106,9 @@ enum QuickStructureAccess_t
STRUCT_ACTOR_INTERNAL__,
STRUCT_SPRITEEXT_INTERNAL__,
STRUCT_SECTOR,
STRUCT_SECTOR_INTERNAL__,
STRUCT_WALL,
STRUCT_WALL_INTERNAL__,
STRUCT_PLAYER,
STRUCT_ACTORVAR,
STRUCT_PLAYERVAR,
......@@ -981,12 +983,14 @@ enum IterationTypes_t
TRANSFORM(CON_SETPLAYERVAR) DELIMITER \
TRANSFORM(CON_SETPROJECTILE) DELIMITER \
TRANSFORM(CON_SETSECTOR) DELIMITER \
TRANSFORM(CON_SETSECTORSTRUCT) DELIMITER \
TRANSFORM(CON_SETSPRITEEXT) DELIMITER \
TRANSFORM(CON_SETSPRITESTRUCT) DELIMITER \
TRANSFORM(CON_SETTHISPROJECTILE) DELIMITER \
TRANSFORM(CON_SETTSPR) DELIMITER \
TRANSFORM(CON_SETUSERDEF) DELIMITER \
TRANSFORM(CON_SETWALL) DELIMITER \
TRANSFORM(CON_SETWALLSTRUCT) DELIMITER \
\
TRANSFORM(CON_GETACTOR) DELIMITER \
TRANSFORM(CON_GETACTORSTRUCT) DELIMITER \
......@@ -996,11 +1000,13 @@ enum IterationTypes_t
TRANSFORM(CON_GETPLAYERVAR) DELIMITER \
TRANSFORM(CON_GETPROJECTILE) DELIMITER \
TRANSFORM(CON_GETSECTOR) DELIMITER \
TRANSFORM(CON_GETSECTORSTRUCT) DELIMITER \
TRANSFORM(CON_GETSPRITEEXT) DELIMITER \
TRANSFORM(CON_GETSPRITESTRUCT) DELIMITER \
TRANSFORM(CON_GETTSPR) DELIMITER \
TRANSFORM(CON_GETUSERDEF) DELIMITER \
TRANSFORM(CON_GETWALL) DELIMITER \
TRANSFORM(CON_GETWALLSTRUCT) DELIMITER \
\
TRANSFORM(CON_ACTION) DELIMITER \
TRANSFORM(CON_ACTIVATEBYSECTOR) DELIMITER \
......
......@@ -2334,37 +2334,55 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
int const wallNum = Gv_GetVar(tw);
int const labelNum = *insptr++;
int const newValue = Gv_GetVar(*insptr++);
auto const &wallLabel = WallLabels[labelNum];
VM_ASSERT((unsigned)wallNum < MAXWALLS, "invalid wall %d\n", wallNum);
if (wallLabel.offset == -1 || wallLabel.flags & LABEL_WRITEFUNC)
{
VM_SetWall(wallNum, labelNum, newValue);
dispatch();
}
VM_SetWall(wallNum, labelNum, newValue);
dispatch();
}
VM_SetStruct(wallLabel.flags, (intptr_t *)((char *)&wall[wallNum] + wallLabel.offset), newValue);
vInstruction(CON_GETWALL):
insptr++;
{
tw = *insptr++;
int const wallNum = Gv_GetVar(tw);
int const labelNum = *insptr++;
VM_ASSERT((unsigned)wallNum < MAXWALLS, "invalid wall %d\n", wallNum);
Gv_SetVar(*insptr++, VM_GetWall(wallNum, labelNum));
dispatch();
}
vInstruction(CON_GETWALL):
vInstruction(CON_SETWALLSTRUCT):
insptr++;
{
tw = *insptr++;
int const wallNum = Gv_GetVar(tw);
int const labelNum = *insptr++;
int const newValue = Gv_GetVar(*insptr++);
auto const &wallLabel = WallLabels[labelNum];
VM_ASSERT((unsigned)wallNum < MAXWALLS, "invalid wall %d\n", wallNum);
Gv_SetVar(*insptr++,
(wallLabel.offset != -1 && (wallLabel.flags & LABEL_READFUNC) != LABEL_READFUNC)
? VM_GetStruct(wallLabel.flags, (intptr_t *)((char *)&wall[wallNum] + wallLabel.offset))
: VM_GetWall(wallNum, labelNum));
VM_SetStruct(wallLabel.flags, (intptr_t *)((char *)&wall[wallNum] + wallLabel.offset), newValue);
dispatch();
}
vInstruction(CON_GETWALLSTRUCT):
insptr++;
{
tw = *insptr++;
int const wallNum = Gv_GetVar(tw);
int const labelNum = *insptr++;
auto const &wallLabel = WallLabels[labelNum];
VM_ASSERT((unsigned)wallNum < MAXWALLS, "invalid wall %d\n", wallNum);
Gv_SetVar(*insptr++, VM_GetStruct(wallLabel.flags, (intptr_t *)((char *)&wall[wallNum] + wallLabel.offset)));
dispatch();
}
......@@ -2542,22 +2560,41 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
{
int const sectNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVar(insptr[-1]) : vm.pSprite->sectnum;
int const labelNum = *insptr++;
auto const &sectLabel = SectorLabels[labelNum];
int const newValue = Gv_GetVar(*insptr++);
VM_ASSERT((unsigned)sectNum < MAXSECTORS, "invalid sector %d\n", sectNum);
if (sectLabel.offset == -1 || sectLabel.flags & LABEL_WRITEFUNC)
{
VM_SetSector(sectNum, labelNum, newValue);
dispatch();
}
VM_SetSector(sectNum, labelNum, newValue);
dispatch();
}
vInstruction(CON_GETSECTOR):
insptr++;
{
int const sectNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVar(insptr[-1]) : vm.pSprite->sectnum;
int const labelNum = *insptr++;
VM_ASSERT((unsigned)sectNum < MAXSECTORS, "invalid sector %d\n", sectNum);
Gv_SetVar(*insptr++, VM_GetSector(sectNum, labelNum));
dispatch();
}
vInstruction(CON_SETSECTORSTRUCT):
insptr++;
{
int const sectNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVar(insptr[-1]) : vm.pSprite->sectnum;
int const labelNum = *insptr++;
auto const &sectLabel = SectorLabels[labelNum];
int const newValue = Gv_GetVar(*insptr++);
VM_ASSERT((unsigned)sectNum < MAXSECTORS, "invalid sector %d\n", sectNum);
VM_SetStruct(sectLabel.flags, (intptr_t *)((char *)&sector[sectNum] + sectLabel.offset), newValue);
dispatch();
}
vInstruction(CON_GETSECTOR):
vInstruction(CON_GETSECTORSTRUCT):
insptr++;
{
int const sectNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVar(insptr[-1]) : vm.pSprite->sectnum;
......@@ -2566,10 +2603,7 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
VM_ASSERT((unsigned)sectNum < MAXSECTORS, "invalid sector %d\n", sectNum);
Gv_SetVar(*insptr++,
(sectLabel.offset != -1 && (sectLabel.flags & LABEL_READFUNC) != LABEL_READFUNC)
? VM_GetStruct(sectLabel.flags, (intptr_t *)((char *)&sector[sectNum] + sectLabel.offset))
: VM_GetSector(sectNum, labelNum));
Gv_SetVar(*insptr++, VM_GetStruct(sectLabel.flags, (intptr_t *)((char *)&sector[sectNum] + sectLabel.offset)));
dispatch();
}
......
......@@ -83,12 +83,6 @@ memberlabel_t const SectorLabels[] = {
int32_t __fastcall VM_GetSector(int const sectNum, int32_t labelNum)
{
if (EDUKE32_PREDICT_FALSE((unsigned)sectNum >= (unsigned)numsectors))
{
CON_ERRPRINTF("invalid sector %d\n", sectNum);
return -1;
}
auto const &s = *(usectorptr_t)&sector[sectNum];
switch (labelNum)
......@@ -121,11 +115,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)
{
if (EDUKE32_PREDICT_FALSE((unsigned)sectNum >= (unsigned)numsectors))
{
CON_ERRPRINTF("invalid sector %d\n", sectNum);
return;
}
auto &s = sector[sectNum];
......@@ -188,12 +177,6 @@ memberlabel_t const WallLabels[]=
int32_t __fastcall VM_GetWall(int const wallNum, int32_t labelNum)
{
if (EDUKE32_PREDICT_FALSE((unsigned)wallNum >= (unsigned)numwalls))
{
CON_ERRPRINTF("invalid wall %d\n", wallNum);
return -1;
}
switch (labelNum)
{
case WALL_BLEND:
......@@ -212,11 +195,6 @@ int32_t __fastcall VM_GetWall(int const wallNum, int32_t labelNum)
void __fastcall VM_SetWall(int const wallNum, int const labelNum, int32_t const newValue)
{
if (EDUKE32_PREDICT_FALSE((unsigned)wallNum >= (unsigned)numwalls))
{
CON_ERRPRINTF("invalid wall %d\n", wallNum);
return;
}
switch (labelNum)
{
......
......@@ -631,19 +631,25 @@ static int __fastcall Gv_GetArrayOrStruct(int const gameVar, int const spriteNum
case STRUCT_SECTOR:
if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.pSprite->sectnum;
CHECK_INDEX(MAXSECTORS);
returnValue = VM_GetSector(arrayIndex, labelNum);
break;
returnValue = (SectorLabels[labelNum].offset != -1 && (SectorLabels[labelNum].flags & LABEL_READFUNC) == 0)
? VM_GetStruct(SectorLabels[labelNum].flags, (intptr_t *)((intptr_t)&sector[arrayIndex] + SectorLabels[labelNum].offset))
: VM_GetSector(arrayIndex, labelNum);
case STRUCT_SECTOR_INTERNAL__:
if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.pSprite->sectnum;
CHECK_INDEX(MAXSECTORS);
returnValue = VM_GetStruct(SectorLabels[labelNum].flags, (intptr_t *)((intptr_t)&sector[arrayIndex] + SectorLabels[labelNum].offset));
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 *)((intptr_t)&wall[arrayIndex] + WallLabels[labelNum].offset))
: VM_GetWall(arrayIndex, labelNum);
returnValue = VM_GetWall(arrayIndex, labelNum);
break;
case STRUCT_WALL_INTERNAL__:
CHECK_INDEX(MAXWALLS);
returnValue = VM_GetStruct(WallLabels[labelNum].flags, (intptr_t *)((intptr_t)&wall[arrayIndex] + WallLabels[labelNum].offset));
break;
case STRUCT_SPRITE:
......@@ -1098,7 +1104,9 @@ static void Gv_AddSystemVars(void)
Gv_NewVar("__actor__", -1, GAMEVAR_READONLY | GAMEVAR_SYSTEM | GAMEVAR_SPECIAL);
Gv_NewVar("__spriteext__", -1, GAMEVAR_READONLY | GAMEVAR_SYSTEM | GAMEVAR_SPECIAL);
Gv_NewVar("sector", -1, GAMEVAR_READONLY | GAMEVAR_SYSTEM | GAMEVAR_SPECIAL);
Gv_NewVar("__sector__", -1, GAMEVAR_READONLY | GAMEVAR_SYSTEM | GAMEVAR_SPECIAL);
Gv_NewVar("wall", -1, GAMEVAR_READONLY | GAMEVAR_SYSTEM | GAMEVAR_SPECIAL);
Gv_NewVar("__wall__", -1, GAMEVAR_READONLY | GAMEVAR_SYSTEM | GAMEVAR_SPECIAL);
Gv_NewVar("player", -1, GAMEVAR_READONLY | GAMEVAR_SYSTEM | GAMEVAR_SPECIAL);
Gv_NewVar("actorvar", -1, GAMEVAR_READONLY | GAMEVAR_SYSTEM | GAMEVAR_SPECIAL);
Gv_NewVar("playervar", -1, GAMEVAR_READONLY | GAMEVAR_SYSTEM | GAMEVAR_SPECIAL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment