Commit 8a11a529 authored by Jordon Moss's avatar Jordon Moss
Browse files

NetDuke32: Get quick access for the tiledata struct working.

parent 8c136ed1
......@@ -3910,10 +3910,10 @@ static int X_DoExecute(void)
case CON_GETPLAYER:
insptr++;
{
int const playerNum = (*insptr++ != sysVarIDs.THISACTOR) ? Gv_GetVarX(insptr[-1]) : g_p;
int const labelNum = *insptr++;
int const playerNum = (*insptr++ != sysVarIDs.THISACTOR) ? Gv_GetVarX(insptr[-1]) : g_p;
int const labelNum = *insptr++;
auto const& playerLabel = PlayerLabels[labelNum];
int const lParm2 = (playerLabel.flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0;
int const lParm2 = (playerLabel.flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0;
VM_ABORT_IF(((unsigned)playerNum >= MAXPLAYERS) | ((unsigned)lParm2 > (unsigned)playerLabel.maxParm2),
"%s[%d] invalid for player %d", playerLabel.name, lParm2, playerNum);
......@@ -3932,10 +3932,9 @@ static int X_DoExecute(void)
case CON_GETINPUT:
insptr++;
{
int const playerNum = (*insptr++ != sysVarIDs.THISACTOR) ? Gv_GetVarX(insptr[-1]) : g_p;
int const labelNum = *insptr++;
int const lVar2 = *insptr++;
int const playerNum = (*insptr++ != sysVarIDs.THISACTOR) ? Gv_GetVarX(insptr[-1]) : g_p;
int const labelNum = *insptr++;
int const lVar2 = *insptr++;
if(tw == CON_SETINPUT)
VM_SetPlayerInput(playerNum, labelNum, Gv_GetVarX(lVar2));
......@@ -3949,11 +3948,15 @@ static int X_DoExecute(void)
case CON_GETTILEDATA:
insptr++;
{
// syntax [gs]ettiledata[<var>].x <VAR>
// <varid> <xxxid> <varid>
int lVar1 = *insptr++, lLabelID = *insptr++, lVar2 = *insptr++;
int const tileNum = *insptr++;
int const labelNum = *insptr++;
int const lVar2 = *insptr++;
if(tw == CON_SETTILEDATA)
VM_SetTileData(tileNum, labelNum, Gv_GetVarX(lVar2));
else
Gv_SetVarX(lVar2, VM_GetTileData(tileNum, labelNum));
X_AccessTileData(tw == CON_SETTILEDATA, lVar1, lLabelID, lVar2);
break;
}
......@@ -3961,10 +3964,10 @@ static int X_DoExecute(void)
case CON_GETUSERDEF:
insptr++;
{
int const labelNum = *insptr++;
auto const& udLabel = UserdefsLabels[labelNum];
int const lParm2 = (udLabel.flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0;
int const lVar2 = *insptr++;
int const labelNum = *insptr++;
auto const& udLabel = UserdefsLabels[labelNum];
int const lParm2 = (udLabel.flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0;
int const lVar2 = *insptr++;
X_AccessUserdef(tw==CON_SETUSERDEF, labelNum, lVar2, lParm2);
break;
......@@ -3974,14 +3977,15 @@ static int X_DoExecute(void)
case CON_GETPROJECTILE:
insptr++;
{
int const tileNum = Gv_GetVarX(*insptr++);
int const labelNum = *insptr++;
int const lVar2 = *insptr++;
int const tileNum = Gv_GetVarX(*insptr++);
int const labelNum = *insptr++;
int const lVar2 = *insptr++;
if(tw == CON_SETPROJECTILE)
VM_SetProjectile(tileNum, labelNum, Gv_GetVarX(lVar2));
else
Gv_SetVarX(lVar2, VM_GetProjectile(tileNum, labelNum));
break;
}
......@@ -3992,8 +3996,8 @@ static int X_DoExecute(void)
int const wallNum = Gv_GetVarX(*insptr++);
VM_ABORT_IF((unsigned)wallNum >= MAXWALLS, "invalid wall %d", wallNum);
int const labelNum = *insptr++;
int const lVar2 = *insptr++;
int const labelNum = *insptr++;
int const lVar2 = *insptr++;
if(tw == CON_SETWALL)
VM_SetWall(wallNum, labelNum, Gv_GetVarX(lVar2));
......@@ -4014,11 +4018,10 @@ static int X_DoExecute(void)
int const lVar2 = *insptr++;
if (tw == CON_SETACTORVAR)
{
Gv_SetVar(lVar1, Gv_GetVarX(lVar2), lSprite, g_p);
break;
}
Gv_SetVarX(lVar2, Gv_GetVar(lVar1, lSprite, g_p));
else
Gv_SetVarX(lVar2, Gv_GetVar(lVar1, lSprite, g_p));
break;
}
......@@ -4033,11 +4036,10 @@ static int X_DoExecute(void)
int const lVar2 = *insptr++;
if (tw == CON_SETPLAYERVAR)
{
Gv_SetVar(lVar1, Gv_GetVarX(lVar2), g_i, playerNum);
break;
}
Gv_SetVarX(lVar2, Gv_GetVar(lVar1, g_i, playerNum));
else
Gv_SetVarX(lVar2, Gv_GetVar(lVar1, g_i, playerNum));
break;
}
......@@ -4045,15 +4047,14 @@ static int X_DoExecute(void)
case CON_GETACTOR:
insptr++;
{
int const spriteNum = (*insptr++ != sysVarIDs.THISACTOR) ? Gv_GetVarX(insptr[-1]) : g_i;
int const labelNum = *insptr++;
auto const& actorLabel = ActorLabels[labelNum];
int const lParm2 = (actorLabel.flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0;
int const spriteNum = (*insptr++ != sysVarIDs.THISACTOR) ? Gv_GetVarX(insptr[-1]) : g_i;
int const labelNum = *insptr++;
auto const& actorLabel = ActorLabels[labelNum];
int const lParm2 = (actorLabel.flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0;
int const lVar2 = *insptr++;
VM_ABORT_IF(((unsigned)spriteNum >= MAXSPRITES) | ((unsigned)lParm2 > (unsigned)actorLabel.maxParm2),
"%s[%d] invalid for sprite %d", actorLabel.name, lParm2, spriteNum);
int const lVar2 = *insptr++;
"%s[%d] invalid for sprite %d", actorLabel.name, lParm2, spriteNum);
if (tw == CON_SETACTOR)
VM_SetSprite(spriteNum, labelNum, lParm2, Gv_GetVarX(lVar2));
......@@ -4070,14 +4071,15 @@ static int X_DoExecute(void)
int const spriteNum = (*insptr++ != sysVarIDs.THISACTOR) ? Gv_GetVarX(insptr[-1]) : g_i;
VM_ABORT_IF((unsigned)spriteNum >= MAXSPRITES, "invalid sprite %d", spriteNum);
int const labelNum = *insptr++;
auto const& tsprLabel = TsprLabels[labelNum];
int const lVar2 = *insptr++;
int const labelNum = *insptr++;
auto const& tsprLabel = TsprLabels[labelNum];
int const lVar2 = *insptr++;
if(tw == CON_SETTSPR)
VM_SetStruct(tsprLabel.flags, (intptr_t*)((char*)spriteext[spriteNum].tspr + tsprLabel.offset), Gv_GetVarX(lVar2));
else
Gv_SetVarX(lVar2, VM_GetStruct(tsprLabel.flags, (intptr_t*)((char*)spriteext[spriteNum].tspr + tsprLabel.offset)));
break;
}
......
......@@ -555,92 +555,60 @@ void VM_InitHashTables(void)
// this is all the crap for accessing the game's structs through the CON VM
// I got a 3-4 fps gain by inlining these...
void __fastcall X_AccessTileData(int iSet, int lVar1, int lLabelID, int lVar2)
int32_t __fastcall VM_GetTileData(int const tileNum, int32_t labelNum)
{
int lValue = 0, tile = g_i;
if (EDUKE32_PREDICT_FALSE((unsigned)tileNum >= MAXTILES))
{
CON_ERRPRINTF("invalid tile %d\n", tileNum);
return -1;
}
if (lVar1 != sysVarIDs.THISACTOR)
tile = Gv_GetVar(lVar1, g_i, g_p);
auto const& tileDataLabel = TileDataLabels[labelNum];
auto const& p = picanm[tileNum];
if ((tile < 0 || tile >= MAXTILES) && g_scriptSanityChecks)
switch (tileDataLabel.lId)
{
OSD_Printf(CON_ERROR "tried to %s %s on invalid tile number (%d) from sprite id: %d, picnum: %d.\n", g_errorLineNum, VM_GetKeywordForID(g_tw),
iSet ? "set" : "get", TileDataLabels[lLabelID].name, tile, g_i, TrackerCast(g_sp->picnum));
insptr += (lVar2 == MAXGAMEVARS);
case TILEDATA_XSIZE: return tilesiz[tileNum].x;
case TILEDATA_YSIZE: return tilesiz[tileNum].y;
case TILEDATA_GAMEFLAGS: return g_tile[tileNum].flags;
case TILEDATA_ANIMFRAMES: return p.num;
case TILEDATA_XOFFSET: return p.xofs;
case TILEDATA_YOFFSET: return p.yofs;
case TILEDATA_ANIMSPEED: return (p.sf & PICANM_ANIMSPEED_MASK);
case TILEDATA_ANIMTYPE: return (p.sf & PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT;
default: EDUKE32_UNREACHABLE_SECTION(return -1);
}
}
void __fastcall VM_SetTileData(int const tileNum, int const labelNum, int32_t newValue)
{
if (EDUKE32_PREDICT_FALSE((unsigned)tileNum >= MAXTILES))
{
CON_ERRPRINTF("invalid tile %d\n", tileNum);
return;
}
if (iSet)
lValue = Gv_GetVar(lVar2, g_i, g_p);
auto const& tileDataLabel = TileDataLabels[labelNum];
auto& p = picanm[tileNum];
switch (lLabelID)
switch (tileDataLabel.lId)
{
case TILEDATA_XSIZE:
if (iSet)
{
tilesiz[tile].x = lValue;
return;
}
Gv_SetVar(lVar2, tilesiz[tile].x, g_i, g_p);
return;
case TILEDATA_YSIZE:
if (iSet)
{
tilesiz[tile].y = lValue;
return;
}
Gv_SetVar(lVar2, tilesiz[tile].y, g_i, g_p);
return;
case TILEDATA_GAMEFLAGS:
if (iSet)
{
g_tile[tile].flags = lValue;
return;
}
Gv_SetVar(lVar2, g_tile[tile].flags, g_i, g_p);
return;
case TILEDATA_ANIMFRAMES:
if (iSet)
{
picanm[tile].num = lValue;
return;
}
Gv_SetVar(lVar2, picanm[tile].num, g_i, g_p);
return;
case TILEDATA_XOFFSET:
if (iSet)
{
picanm[tile].xofs = lValue;
return;
}
Gv_SetVar(lVar2, picanm[tile].xofs, g_i, g_p);
return;
case TILEDATA_YOFFSET:
if (iSet)
{
picanm[tile].yofs = lValue;
return;
}
Gv_SetVar(lVar2, picanm[tile].yofs, g_i, g_p);
return;
case TILEDATA_ANIMSPEED:
if (iSet)
{
picanm[tile].sf = (picanm[tile].sf & ~PICANM_ANIMSPEED_MASK) | (lValue & PICANM_ANIMSPEED_MASK);
return;
}
Gv_SetVar(lVar2, (picanm[tile].sf & PICANM_ANIMSPEED_MASK), g_i, g_p);
return;
case TILEDATA_ANIMTYPE:
if (iSet)
{
picanm[tile].sf = (picanm[tile].sf & ~PICANM_ANIMTYPE_MASK) | ((lValue << PICANM_ANIMTYPE_SHIFT) & PICANM_ANIMTYPE_MASK);
return;
}
Gv_SetVar(lVar2, (picanm[tile].sf & PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT, g_i, g_p);
return;
default:
return;
//case TILEDATA_XSIZE: tilesiz[tileNum].x = newValue; break;
//case TILEDATA_YSIZE: tilesiz[tileNum].y = newValue; break;
case TILEDATA_GAMEFLAGS: g_tile[tileNum].flags = newValue; return;
case TILEDATA_ANIMFRAMES: p.num = newValue; return;
case TILEDATA_XOFFSET: p.xofs = newValue; return;
case TILEDATA_YOFFSET: p.yofs = newValue; return;
case TILEDATA_ANIMSPEED: p.sf = (p.sf & ~PICANM_ANIMSPEED_MASK) | (newValue & PICANM_ANIMSPEED_MASK); return;
case TILEDATA_ANIMTYPE: p.sf = (p.sf & ~PICANM_ANIMTYPE_MASK) | ((newValue << PICANM_ANIMTYPE_SHIFT) & PICANM_ANIMTYPE_MASK); return;
default: return;
}
}
......
......@@ -26,7 +26,9 @@ void __fastcall VM_SetProjectile(int const tileNum, int const labelNum, int32
int32_t __fastcall VM_GetActiveProjectile(int const spriteNum, int32_t labelNum);
void __fastcall VM_SetActiveProjectile(int const spriteNum, int const labelNum, int32_t const newValue);
void __fastcall X_AccessTileData(int iSet, int lVar1, int lLabelID, int lVar2);
int32_t __fastcall VM_GetTileData(int const tileNum, int32_t labelNum);
void __fastcall VM_SetTileData(int const tileNum, int const labelNum, int32_t newValue);
void __fastcall X_AccessUserdef(int iSet, int labelNum, int lVar2, int lParm2);
typedef struct
......
......@@ -642,14 +642,14 @@ static int __fastcall Gv_GetArrayOrStruct(int const gameVar, int const spriteNum
CHECK_INDEX(MAXTILES);
returnValue = VM_GetProjectile(arrayIndex, labelNum);
break;
#if 0
case STRUCT_TILEDATA:
if (arrayIndexVar == sysVarIDs.THISACTOR)
arrayIndex = vm.pSprite->picnum;
arrayIndex = g_sp->picnum;
CHECK_INDEX(MAXTILES);
returnValue = VM_GetTileData(arrayIndex, labelNum);
break;
#if 0
case STRUCT_PALDATA:
if (arrayIndexVar == sysVarIDs.THISACTOR)
arrayIndex = vm.pSprite->pal;
......@@ -698,6 +698,7 @@ int __fastcall Gv_GetVar(int id, int iActor, int iPlayer)
if (id == GV_FLAG_CONSTANT)
return *insptr++;
// Special IDs for backwards compatibility
if (id == sysVarIDs.RESPAWN_MONSTERS) return DMFLAGS_TEST(DMFLAG_RESPAWNMONSTERS);
if (id == sysVarIDs.RESPAWN_ITEMS) return DMFLAGS_TEST(DMFLAG_RESPAWNITEMS);
if (id == sysVarIDs.RESPAWN_INVENTORY) return DMFLAGS_TEST(DMFLAG_RESPAWNINVENTORY);
......
Supports Markdown
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