C-CON: Enumify quick structure access.

git-svn-id: https://svn.eduke32.com/eduke32@5087 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2015-03-25 06:27:42 +00:00
parent 4682da7a22
commit 5c8a2e3ea6
4 changed files with 55 additions and 43 deletions

View file

@ -1628,7 +1628,7 @@ static void C_GetNextVarType(int32_t type)
if (i < 0) if (i < 0)
{ {
i=GetDefID(label+(g_numLabels<<6)); i=GetDefID(label+(g_numLabels<<6));
if (i < g_iSpriteVarID || i > g_iActorVarID) if ((unsigned) (i - g_iStructVarIDs) >= NUMQUICKSTRUCTS)
i = -1; i = -1;
if (EDUKE32_PREDICT_FALSE(i < 0)) if (EDUKE32_PREDICT_FALSE(i < 0))
@ -1686,16 +1686,24 @@ static void C_GetNextVarType(int32_t type)
C_GetNextLabelName(); C_GetNextLabelName();
/*initprintf("found xxx label of \"%s\"\n", label+(g_numLabels<<6));*/ /*initprintf("found xxx label of \"%s\"\n", label+(g_numLabels<<6));*/
if (i == g_iSpriteVarID) switch (i - g_iStructVarIDs)
{
case STRUCT_SPRITE:
lLabelID=C_GetLabelNameOffset(&actorH,Bstrtolower(label+(g_numLabels<<6))); lLabelID=C_GetLabelNameOffset(&actorH,Bstrtolower(label+(g_numLabels<<6)));
else if (i == g_iSectorVarID) break;
case STRUCT_SECTOR:
lLabelID=C_GetLabelNameOffset(&sectorH,Bstrtolower(label+(g_numLabels<<6))); lLabelID=C_GetLabelNameOffset(&sectorH,Bstrtolower(label+(g_numLabels<<6)));
else if (i == g_iWallVarID) break;
case STRUCT_WALL:
lLabelID=C_GetLabelNameOffset(&wallH,Bstrtolower(label+(g_numLabels<<6))); lLabelID=C_GetLabelNameOffset(&wallH,Bstrtolower(label+(g_numLabels<<6)));
else if (i == g_iPlayerVarID) break;
case STRUCT_PLAYER:
lLabelID=C_GetLabelNameOffset(&playerH,Bstrtolower(label+(g_numLabels<<6))); lLabelID=C_GetLabelNameOffset(&playerH,Bstrtolower(label+(g_numLabels<<6)));
else if (i == g_iActorVarID) break;
case STRUCT_ACTORVAR:
lLabelID=GetDefID(label+(g_numLabels<<6)); lLabelID=GetDefID(label+(g_numLabels<<6));
break;
}
//printf("LabelID is %d\n",lLabelID); //printf("LabelID is %d\n",lLabelID);
if (EDUKE32_PREDICT_FALSE(lLabelID == -1)) if (EDUKE32_PREDICT_FALSE(lLabelID == -1))
@ -1707,8 +1715,9 @@ static void C_GetNextVarType(int32_t type)
bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7)); bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
if (i == g_iSpriteVarID) switch (i - g_iStructVarIDs)
{ {
case STRUCT_SPRITE:
*g_scriptPtr++=ActorLabels[lLabelID].lId; *g_scriptPtr++=ActorLabels[lLabelID].lId;
//printf("member's flags are: %02Xh\n",ActorLabels[lLabelID].flags); //printf("member's flags are: %02Xh\n",ActorLabels[lLabelID].flags);
@ -1719,13 +1728,14 @@ static void C_GetNextVarType(int32_t type)
// get the ID of the DEF // get the ID of the DEF
C_GetNextVarType(0); C_GetNextVarType(0);
} }
} break;
else if (i == g_iSectorVarID) case STRUCT_SECTOR:
*g_scriptPtr++=SectorLabels[lLabelID].lId; *g_scriptPtr++=SectorLabels[lLabelID].lId;
else if (i == g_iWallVarID) break;
*g_scriptPtr++=SectorLabels[lLabelID].lId; case STRUCT_WALL:
else if (i == g_iPlayerVarID) *g_scriptPtr++=WallLabels[lLabelID].lId;
{ break;
case STRUCT_PLAYER:
*g_scriptPtr++=PlayerLabels[lLabelID].lId; *g_scriptPtr++=PlayerLabels[lLabelID].lId;
//printf("member's flags are: %02Xh\n",ActorLabels[lLabelID].flags); //printf("member's flags are: %02Xh\n",ActorLabels[lLabelID].flags);
@ -1736,9 +1746,11 @@ static void C_GetNextVarType(int32_t type)
// get the ID of the DEF // get the ID of the DEF
C_GetNextVarType(0); C_GetNextVarType(0);
} }
} break;
else if (i == g_iActorVarID) case STRUCT_ACTORVAR:
*g_scriptPtr++=lLabelID; *g_scriptPtr++=lLabelID;
break;
}
} }
return; return;
} }

View file

@ -55,11 +55,18 @@ extern int32_t g_iLoTagID; // var ID of "LOTAG"
extern int32_t g_iHiTagID; // var ID of "HITAG" extern int32_t g_iHiTagID; // var ID of "HITAG"
extern int32_t g_iTextureID; // var ID of "TEXTURE" extern int32_t g_iTextureID; // var ID of "TEXTURE"
extern int32_t g_iThisActorID; // var ID of "THISACTOR" extern int32_t g_iThisActorID; // var ID of "THISACTOR"
extern int32_t g_iSpriteVarID;
extern int32_t g_iSectorVarID; // KEEPINSYNC gamevars.c: "special vars for struct access"
extern int32_t g_iWallVarID; enum QuickStructureAccess_t {
extern int32_t g_iPlayerVarID; STRUCT_SPRITE,
extern int32_t g_iActorVarID; STRUCT_SECTOR,
STRUCT_WALL,
STRUCT_PLAYER,
STRUCT_ACTORVAR,
NUMQUICKSTRUCTS,
};
extern int32_t g_iStructVarIDs;
extern intptr_t *apScriptGameEvent[MAXGAMEEVENTS]; extern intptr_t *apScriptGameEvent[MAXGAMEEVENTS];
#endif #endif

View file

@ -76,11 +76,7 @@ int32_t g_iLoTagID = -1; // var ID of "LOTAG"
int32_t g_iHiTagID = -1; // var ID of "HITAG" int32_t g_iHiTagID = -1; // var ID of "HITAG"
int32_t g_iTextureID = -1; // var ID of "TEXTURE" int32_t g_iTextureID = -1; // var ID of "TEXTURE"
int32_t g_iThisActorID = -1; // var ID of "THISACTOR" int32_t g_iThisActorID = -1; // var ID of "THISACTOR"
int32_t g_iSpriteVarID = -1; int32_t g_iStructVarIDs = -1;
int32_t g_iSectorVarID = -1;
int32_t g_iWallVarID = -1;
int32_t g_iPlayerVarID = -1;
int32_t g_iActorVarID = -1;
GAMEEXEC_STATIC void VM_Execute(int32_t loop); GAMEEXEC_STATIC void VM_Execute(int32_t loop);
@ -3927,7 +3923,7 @@ finish_qsprintf:
else if (*insptr&(MAXGAMEVARS<<3)) else if (*insptr&(MAXGAMEVARS<<3))
{ {
// FIXME FIXME FIXME // FIXME FIXME FIXME
if ((lVarID & (MAXGAMEVARS-1)) == g_iActorVarID) if ((lVarID & (MAXGAMEVARS-1)) == g_iStructVarIDs + STRUCT_ACTORVAR)
{ {
intptr_t const *oinsptr = insptr++; intptr_t const *oinsptr = insptr++;
int32_t index = Gv_GetVarX(*insptr++); int32_t index = Gv_GetVarX(*insptr++);

View file

@ -653,9 +653,9 @@ nastyhacks:
int indexvar = *insptr; int indexvar = *insptr;
int32_t index=Gv_GetVar(*insptr++, iActor, iPlayer); int32_t index=Gv_GetVar(*insptr++, iActor, iPlayer);
switch ((id&(MAXGAMEVARS-1)) - g_iSpriteVarID) switch ((id&(MAXGAMEVARS-1)) - g_iStructVarIDs)
{ {
case 0: //if (id == g_iSpriteVarID) case STRUCT_SPRITE:
{ {
int const label = *insptr++; int const label = *insptr++;
@ -673,7 +673,7 @@ nastyhacks:
break; break;
} }
case 3: //else if (id == g_iPlayerVarID) case STRUCT_PLAYER:
{ {
int const label = *insptr++; int const label = *insptr++;
@ -692,11 +692,11 @@ nastyhacks:
break; break;
} }
case 4: //else if (id == g_iActorVarID) case STRUCT_ACTORVAR:
rv = Gv_GetVar(*insptr++, index, iPlayer); rv = Gv_GetVar(*insptr++, index, iPlayer);
break; break;
case 1: //else if (id == g_iSectorVarID) case STRUCT_SECTOR:
if (indexvar == g_iThisActorID) index = sprite[vm.g_i].sectnum; if (indexvar == g_iThisActorID) index = sprite[vm.g_i].sectnum;
if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSECTORS)) if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSECTORS))
{ {
@ -707,7 +707,7 @@ nastyhacks:
rv = VM_GetSector(index, *insptr++); rv = VM_GetSector(index, *insptr++);
break; break;
case 2: //else if (id == g_iWallVarID) case STRUCT_WALL:
if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXWALLS)) if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXWALLS))
{ {
iPlayer = index; iPlayer = index;
@ -840,9 +840,9 @@ int32_t __fastcall Gv_GetSpecialVarX(int32_t id)
int indexvar = *insptr; int indexvar = *insptr;
int index = Gv_GetVarX(*insptr++); int index = Gv_GetVarX(*insptr++);
switch ((id & (MAXGAMEVARS - 1)) - g_iSpriteVarID) switch ((id & (MAXGAMEVARS - 1)) - g_iStructVarIDs)
{ {
case 0: // if (id == g_iSpriteVarID) case STRUCT_SPRITE:
{ {
int const label = *insptr++; int const label = *insptr++;
@ -861,7 +861,7 @@ int32_t __fastcall Gv_GetSpecialVarX(int32_t id)
break; break;
} }
case 3: // else if (id == g_iPlayerVarID) case STRUCT_PLAYER:
{ {
int const label = *insptr++; int const label = *insptr++;
@ -882,11 +882,11 @@ int32_t __fastcall Gv_GetSpecialVarX(int32_t id)
break; break;
} }
case 4: // else if (id == g_iActorVarID) case STRUCT_ACTORVAR:
rv = Gv_GetVar(*insptr++, index, vm.g_p); rv = Gv_GetVar(*insptr++, index, vm.g_p);
break; break;
case 1: // else if (id == g_iSectorVarID) case STRUCT_SECTOR:
if (indexvar == g_iThisActorID) if (indexvar == g_iThisActorID)
index = sprite[vm.g_i].sectnum; index = sprite[vm.g_i].sectnum;
@ -900,7 +900,7 @@ int32_t __fastcall Gv_GetSpecialVarX(int32_t id)
rv = VM_GetSector(index, *insptr++); rv = VM_GetSector(index, *insptr++);
break; break;
case 2: // else if (id == g_iWallVarID) case STRUCT_WALL:
if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXWALLS)) if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXWALLS))
{ {
id = index; id = index;
@ -1140,11 +1140,7 @@ void Gv_ResetSystemDefaults(void)
g_iTextureID = Gv_GetVarIndex("TEXTURE"); g_iTextureID = Gv_GetVarIndex("TEXTURE");
g_iThisActorID = Gv_GetVarIndex("THISACTOR"); g_iThisActorID = Gv_GetVarIndex("THISACTOR");
g_iSpriteVarID = Gv_GetVarIndex("sprite"); g_iStructVarIDs = Gv_GetVarIndex("sprite");
g_iSectorVarID = Gv_GetVarIndex("sector");
g_iWallVarID = Gv_GetVarIndex("wall");
g_iPlayerVarID = Gv_GetVarIndex("player");
g_iActorVarID = Gv_GetVarIndex("actorvar");
#endif #endif
for (int i = 0; i <= MAXTILES - 1; i++) for (int i = 0; i <= MAXTILES - 1; i++)
@ -1467,6 +1463,7 @@ static void Gv_AddSystemVars(void)
Gv_NewVar("THISACTOR", 0, GAMEVAR_READONLY | GAMEVAR_SYSTEM); Gv_NewVar("THISACTOR", 0, GAMEVAR_READONLY | GAMEVAR_SYSTEM);
// special vars for struct access // special vars for struct access
// KEEPINSYNC gamedef.h: enum QuickStructureAccess_t
Gv_NewVar("sprite", -1, GAMEVAR_READONLY | GAMEVAR_SYSTEM | GAMEVAR_SPECIAL); Gv_NewVar("sprite", -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);