Commit d25fc0b5 authored by Richard Gobeille's avatar Richard Gobeille

Duke3d: rework PlayerLabels[] to use the LABEL_SETUP macro

parent c398a6dd
......@@ -1004,13 +1004,21 @@ LIBS += -lm
VC_REV :=
VC_HASH :=
VC_BRANCH :=
-include EDUKE32_REVISION.mak
ifeq (,$(VC_REV))
VC_REV := $(shell git rev-list --count origin 2>&1)
VC_REV := $(shell git rev-list --count HEAD 2>&1)
endif
ifeq (,$(VC_HASH))
VC_HASH := $(shell git rev-parse --short=9 HEAD 2>&1)
endif
ifeq (,$(VC_BRANCH))
VC_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>&1)
ifneq (master,$(VC_BRANCH))
VC_REV := $(VC_REV)[$(VC_BRANCH)]
endif
endif
ifneq (,$(VC_REV)$(VC_HASH)$(VC_REV_CUSTOM))
REVFLAG := -DREV="r$(VC_REV)-$(VC_HASH)$(VC_REV_CUSTOM)"
endif
......
......@@ -849,6 +849,9 @@ static const tokenmap_t keywords_for_private_opcodes[] =
{ "getsector", CON_GETSECTORSTRUCT },
{ "setsector", CON_SETSECTORSTRUCT },
{ "getplayer", CON_GETPLAYERSTRUCT },
{ "setplayer", CON_SETPLAYERSTRUCT },
};
char const *VM_GetKeywordForID(int32_t id)
......@@ -1594,10 +1597,18 @@ static void C_GetNextVarType(int32_t type)
}
break;
case STRUCT_PLAYER:
scriptWriteValue(PlayerLabels[labelNum].lId);
{
auto const &label = PlayerLabels[labelNum];
if (PlayerLabels[labelNum].flags & LABEL_HASPARM2)
C_GetNextVarType(0);
scriptWriteValue(label.lId);
Bassert((*varptr & (MAXGAMEVARS-1)) == g_structVarIDs + STRUCT_PLAYER);
if (label.flags & LABEL_HASPARM2)
C_GetNextVarType(0);
else if (label.offset != -1 && (label.flags & LABEL_READFUNC) == 0)
*varptr = (*varptr & ~(MAXGAMEVARS-1)) + g_structVarIDs + STRUCT_PLAYER_INTERNAL__;
}
break;
case STRUCT_ACTORVAR:
case STRUCT_PLAYERVAR:
......@@ -3359,6 +3370,7 @@ DO_DEFSTATE:
continue;
}
case CON_FINDNEARACTOR3D:
case CON_FINDNEARACTOR:
case CON_FINDNEARACTORZ:
......@@ -3427,19 +3439,50 @@ DO_DEFSTATE:
}
case CON_SETPLAYER:
{
intptr_t * const ins = &g_scriptPtr[-1];
int const labelNum = C_GetStructureIndexes(1, &h_player);
if (labelNum == -1)
continue;
Bassert((*ins & VM_INSTMASK) == CON_SETPLAYER);
auto const &label = PlayerLabels[labelNum];
if (label.offset != -1 && (label.flags & (LABEL_WRITEFUNC|LABEL_HASPARM2)) == 0)
*ins = CON_SETPLAYERSTRUCT | LINE_NUMBER;
scriptWriteValue(label.lId);
if (label.flags & LABEL_HASPARM2)
C_GetNextVar();
C_GetNextVar();
continue;
}
case CON_GETPLAYER:
{
intptr_t * const ins = &g_scriptPtr[-1];
int const labelNum = C_GetStructureIndexes(1, &h_player);
if (labelNum == -1)
continue;
scriptWriteValue(PlayerLabels[labelNum].lId);
Bassert((*ins & VM_INSTMASK) == CON_GETPLAYER);
auto const &label = PlayerLabels[labelNum];
if (label.offset != -1 && (label.flags & (LABEL_READFUNC|LABEL_HASPARM2)) == 0)
*ins = CON_GETPLAYERSTRUCT | LINE_NUMBER;
if (PlayerLabels[labelNum].flags & LABEL_HASPARM2)
scriptWriteValue(label.lId);
if (label.flags & LABEL_HASPARM2)
C_GetNextVar();
C_GetNextVarType((tw == CON_GETPLAYER) ? GAMEVAR_READONLY : 0);
C_GetNextVarType(GAMEVAR_READONLY);
continue;
}
......
......@@ -110,6 +110,7 @@ enum QuickStructureAccess_t
STRUCT_WALL,
STRUCT_WALL_INTERNAL__,
STRUCT_PLAYER,
STRUCT_PLAYER_INTERNAL__,
STRUCT_ACTORVAR,
STRUCT_PLAYERVAR,
STRUCT_TSPR,
......@@ -980,6 +981,7 @@ enum IterationTypes_t
TRANSFORM(CON_SETARRAY) DELIMITER \
TRANSFORM(CON_SETARRAYSEQUENCE) DELIMITER \
TRANSFORM(CON_SETPLAYER) DELIMITER \
TRANSFORM(CON_SETPLAYERSTRUCT) DELIMITER \
TRANSFORM(CON_SETPLAYERVAR) DELIMITER \
TRANSFORM(CON_SETPROJECTILE) DELIMITER \
TRANSFORM(CON_SETSECTOR) DELIMITER \
......@@ -997,6 +999,7 @@ enum IterationTypes_t
TRANSFORM(CON_GETACTORVAR) DELIMITER \
TRANSFORM(CON_GETANGLE) DELIMITER \
TRANSFORM(CON_GETPLAYER) DELIMITER \
TRANSFORM(CON_GETPLAYERSTRUCT) DELIMITER \
TRANSFORM(CON_GETPLAYERVAR) DELIMITER \
TRANSFORM(CON_GETPROJECTILE) DELIMITER \
TRANSFORM(CON_GETSECTOR) DELIMITER \
......
......@@ -2312,30 +2312,64 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
dispatch();
vInstruction(CON_SETPLAYER):
insptr++;
{
int const playerNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVar(insptr[-1]) : vm.playerNum;
int const labelNum = *insptr++;
auto const &playerLabel = PlayerLabels[labelNum];
int const lParm2 = (PlayerLabels[labelNum].flags & LABEL_HASPARM2) ? Gv_GetVar(*insptr++) : 0;
VM_ASSERT((unsigned)playerNum < MAXSPRITES && ((playerLabel.flags & LABEL_HASPARM2) == 0 || (unsigned)lParm2 < (unsigned)playerLabel.maxParm2),
"%s[%d] invalid for sprite %d\n", playerLabel.name, lParm2, playerNum);
VM_SetPlayer(playerNum, labelNum, lParm2, Gv_GetVar(*insptr++));
dispatch();
}
vInstruction(CON_GETPLAYER):
insptr++;
{
int const playerNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVar(insptr[-1]) : vm.playerNum;
int const labelNum = *insptr++;
auto const &playerLabel = PlayerLabels[labelNum];
int const lParm2 = (playerLabel.flags & LABEL_HASPARM2) ? Gv_GetVar(*insptr++) : 0;
VM_ASSERT((unsigned)playerNum < MAXSPRITES && ((playerLabel.flags & LABEL_HASPARM2) == 0 || (unsigned)lParm2 < (unsigned)playerLabel.maxParm2),
"%s[%d] invalid for sprite %d\n", playerLabel.name, lParm2, playerNum);
Gv_SetVar(*insptr++, VM_GetPlayer(playerNum, labelNum, lParm2));
dispatch();
}
vInstruction(CON_SETPLAYERSTRUCT):
insptr++;
{
int const playerNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVar(insptr[-1]) : vm.playerNum;
int const labelNum = *insptr++;
int const lParm2 = (PlayerLabels[labelNum].flags & LABEL_HASPARM2) ? Gv_GetVar(*insptr++) : 0;
VM_ASSERT((unsigned)playerNum < MAXPLAYERS, "invalid player %d\n", playerNum);
VM_SetPlayer(playerNum, labelNum, lParm2, Gv_GetVar(*insptr++));
auto const &playerLabel = PlayerLabels[labelNum];
int const newValue = Gv_GetVar(*insptr++);
VM_SetStruct(playerLabel.flags, (intptr_t *)((char *)&g_player[playerNum].ps[0] + playerLabel.offset), newValue);
dispatch();
}
vInstruction(CON_GETPLAYER):
vInstruction(CON_GETPLAYERSTRUCT):
insptr++;
{
int const playerNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVar(insptr[-1]) : vm.playerNum;
int const labelNum = *insptr++;
int const lParm2 = (PlayerLabels[labelNum].flags & LABEL_HASPARM2) ? Gv_GetVar(*insptr++) : 0;
VM_ASSERT((unsigned)playerNum < MAXPLAYERS, "invalid player %d\n", playerNum);
Gv_SetVar(*insptr++, VM_GetPlayer(playerNum, labelNum, lParm2));
auto const &playerLabel = PlayerLabels[labelNum];
Gv_SetVar(*insptr++, VM_GetStruct(playerLabel.flags, (intptr_t *)((char *)&g_player[playerNum].ps[0] + playerLabel.offset)));
dispatch();
}
vInstruction(CON_SETWALL):
insptr++;
{
......
This diff is collapsed.
......@@ -934,6 +934,13 @@ static int __fastcall Gv_GetArrayOrStruct(int const gameVar, int const spriteNum
returnValue = VM_GetPlayer(arrayIndex, labelNum, arrayIndexVar);
break;
case STRUCT_PLAYER_INTERNAL__:
if (arrayIndexVar == g_thisActorVarID)
arrayIndex = vm.playerNum;
CHECK_INDEX(MAXPLAYERS);
returnValue = VM_GetStruct(PlayerLabels[labelNum].flags, (intptr_t *)((intptr_t)&g_player[arrayIndex].ps[0] + PlayerLabels[labelNum].offset));
break;
case STRUCT_THISPROJECTILE:
CHECK_INDEX(MAXSPRITES);
returnValue = VM_GetActiveProjectile(arrayIndex, labelNum);
......@@ -1366,6 +1373,7 @@ static void Gv_AddSystemVars(void)
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("__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);
Gv_NewVar("tspr", -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