Switch VM_EventCommon to use references

git-svn-id: https://svn.eduke32.com/eduke32@7205 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-11-18 18:11:44 +00:00
parent 3b7f41e2bb
commit 0d652ae063
6 changed files with 56 additions and 59 deletions

View file

@ -606,7 +606,7 @@ void A_DeleteSprite(int spriteNum)
int32_t playerDist; int32_t playerDist;
int playerNum = A_FindPlayer(&sprite[spriteNum], &playerDist); int playerNum = A_FindPlayer(&sprite[spriteNum], &playerDist);
if (VM_OnEventWithDist_(EVENT_KILLIT, spriteNum, playerNum, playerDist)) if (VM_OnEventWithDist__(EVENT_KILLIT, spriteNum, playerNum, playerDist))
return; return;
} }
@ -8392,7 +8392,7 @@ static void G_DoEventGame(int const nEventID)
int32_t playerDist; int32_t playerDist;
int const playerNum = A_FindPlayer(&sprite[spriteNum], &playerDist); int const playerNum = A_FindPlayer(&sprite[spriteNum], &playerDist);
VM_OnEventWithDist_(nEventID, spriteNum, playerNum, playerDist); VM_OnEventWithDist__(nEventID, spriteNum, playerNum, playerDist);
spriteNum = nextSprite; spriteNum = nextSprite;
} }

View file

@ -1323,7 +1323,7 @@ int32_t A_InsertSprite(int16_t whatsect,int32_t s_x,int32_t s_y,int32_t s_z,int1
int32_t p, pl = A_FindPlayer(s, &p); int32_t p, pl = A_FindPlayer(s, &p);
block_deletesprite++; block_deletesprite++;
VM_OnEventWithDist_(EVENT_EGS, i, pl, p); VM_OnEventWithDist__(EVENT_EGS, i, pl, p);
block_deletesprite--; block_deletesprite--;
} }
@ -3411,7 +3411,7 @@ SPAWN_END:
{ {
int32_t p; int32_t p;
int32_t pl=A_FindPlayer(&sprite[newSprite],&p); int32_t pl=A_FindPlayer(&sprite[newSprite],&p);
VM_OnEventWithDist_(EVENT_SPAWN,newSprite, pl, p); VM_OnEventWithDist__(EVENT_SPAWN,newSprite, pl, p);
} }
return newSprite; return newSprite;
@ -3537,7 +3537,7 @@ static inline void G_DoEventAnimSprites(int tspriteNum)
return; return;
spriteext[tsprOwner].tspr = &tsprite[tspriteNum]; spriteext[tsprOwner].tspr = &tsprite[tspriteNum];
VM_OnEvent_(EVENT_ANIMATESPRITES, tsprOwner, screenpeek); VM_OnEvent__(EVENT_ANIMATESPRITES, tsprOwner, screenpeek);
spriteext[tsprOwner].tspr = NULL; spriteext[tsprOwner].tspr = NULL;
} }

View file

@ -48,7 +48,7 @@ static int32_t g_checkingIfElse, g_processingState, g_lastKeyword = -1;
static intptr_t *g_caseScriptPtr; static intptr_t *g_caseScriptPtr;
static intptr_t previous_event; static intptr_t previous_event;
static int32_t g_numCases = 0, g_checkingCase = 0; static int32_t g_numCases = 0, g_checkingCase = 0;
static int32_t g_checkingSwitch = 0, g_currentEvent = -1; static int32_t g_checkingSwitch = 0;
static int32_t g_labelsOnly = 0, g_dynamicTileMapping = 0, g_dynamicSoundMapping = 0; static int32_t g_labelsOnly = 0, g_dynamicTileMapping = 0, g_dynamicSoundMapping = 0;
static int32_t g_numBraces = 0; static int32_t g_numBraces = 0;
@ -779,10 +779,10 @@ const char *EventNames[MAXEVENTS] =
}; };
#if !defined LUNATIC #if !defined LUNATIC
#define LABEL_SETUP_UNMATCHED(struct, memb, name, idx) \ #define LABEL_SETUP_UNMATCHED(struct, memb, name, idx) \
{ \ { \
name, idx, sizeof(struct[0].memb) | (is_unsigned <decltype(struct[0].memb)>::value ? LABEL_UNSIGNED : 0), 0, \ name, idx, sizeof(struct[0].memb) | (is_unsigned<decltype(struct[0].memb)>::value ? LABEL_UNSIGNED : 0), 0, \
offsetof(std::remove_pointer <decltype(&struct[0])>::type, memb) \ offsetof(std::remove_pointer<decltype(&struct[0])>::type, memb) \
} }
#define LABEL_SETUP(struct, memb, idx) LABEL_SETUP_UNMATCHED(struct, memb, #memb, idx) #define LABEL_SETUP(struct, memb, idx) LABEL_SETUP_UNMATCHED(struct, memb, #memb, idx)

View file

@ -48,7 +48,7 @@ vmstate_t vm;
#if !defined LUNATIC #if !defined LUNATIC
int32_t g_tw; int32_t g_tw;
int32_t g_errorLineNum; int32_t g_errorLineNum;
int32_t g_currentEventExec = -1; int32_t g_currentEvent = -1;
intptr_t const *insptr; intptr_t const *insptr;
@ -85,7 +85,7 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop);
#if !defined LUNATIC #if !defined LUNATIC
void VM_ScriptInfo(intptr_t const *ptr, int range) void VM_ScriptInfo(intptr_t const *ptr, int range)
{ {
if (!apScript || (!vm.pSprite && !vm.pPlayer && g_currentEventExec == -1)) if (!apScript || (!vm.pSprite && !vm.pPlayer && g_currentEvent == -1))
return; return;
if (ptr) if (ptr)
@ -134,7 +134,7 @@ intptr_t apScriptEvents[MAXEVENTS];
// May recurse, e.g. through EVENT_XXX -> ... -> EVENT_KILLIT // May recurse, e.g. through EVENT_XXX -> ... -> EVENT_KILLIT
#ifdef LUNATIC #ifdef LUNATIC
static FORCE_INLINE int32_t VM_EventCommon_(int eventNum, int spriteNum, int playerNum, int playerDist, int32_t returnValue) static FORCE_INLINE int32_t VM_EventCommon__(int const &eventNum, int const &spriteNum, int const &playerNum, int const &playerDist, int32_t returnValue)
{ {
const double t = timerGetHiTicks(); const double t = timerGetHiTicks();
int32_t ret = El_CallEvent(&g_ElState, eventNum, spriteNum, playerNum, playerDist, &returnValue); int32_t ret = El_CallEvent(&g_ElState, eventNum, spriteNum, playerNum, playerDist, &returnValue);
@ -161,20 +161,20 @@ static void VM_DummySprite(void)
vm.pData = &dummy.t_data[0]; vm.pData = &dummy.t_data[0];
} }
static FORCE_INLINE int32_t VM_EventCommon_(int const eventNum, int const spriteNum, int const playerNum, int const playerDist, int32_t returnValue) static FORCE_INLINE int32_t VM_EventCommon__(int const &eventNum, int const &spriteNum, int const &playerNum, int const &playerDist, int32_t returnValue)
{ {
const double t = timerGetHiTicks(); double const t = timerGetHiTicks();
vmstate_t const tempvm = { spriteNum, playerNum, playerDist, 0, NULL, NULL, g_player[playerNum].ps, NULL };
const vmstate_t tempvm = { spriteNum, playerNum, playerDist, 0, NULL, NULL, g_player[playerNum].ps, NULL }; auto & returnVar = aGameVars[g_returnVarID].global;
int const backupReturnVar = returnVar;
int const backupEvent = g_currentEvent;
int const backupReturnVar = aGameVars[g_returnVarID].global; returnVar = returnValue;
int const backupEventExec = g_currentEventExec; g_currentEvent = eventNum;
aGameVars[g_returnVarID].global = returnValue; intptr_t const *backupinsptr = insptr;
g_currentEventExec = eventNum; const vmstate_t vm_backup = vm;
intptr_t const *oinsptr = insptr;
const vmstate_t vm_backup = vm;
insptr = apScript + apScriptEvents[eventNum]; insptr = apScript + apScriptEvents[eventNum];
vm = tempvm; vm = tempvm;
@ -201,12 +201,11 @@ static FORCE_INLINE int32_t VM_EventCommon_(int const eventNum, int const sprite
// this needs to happen after VM_DeleteSprite() because VM_DeleteSprite() // this needs to happen after VM_DeleteSprite() because VM_DeleteSprite()
// can trigger additional events // can trigger additional events
vm = vm_backup; vm = vm_backup;
insptr = oinsptr; insptr = backupinsptr;
g_currentEventExec = backupEventExec; g_currentEvent = backupEvent;
returnValue = aGameVars[g_returnVarID].global; returnValue = returnVar;
returnVar = backupReturnVar;
aGameVars[g_returnVarID].global = backupReturnVar;
g_eventTotalMs[eventNum] += timerGetHiTicks()-t; g_eventTotalMs[eventNum] += timerGetHiTicks()-t;
g_eventCalls[eventNum]++; g_eventCalls[eventNum]++;
@ -219,34 +218,32 @@ static FORCE_INLINE int32_t VM_EventCommon_(int const eventNum, int const sprite
// which are not only optimized further based on lDist or iReturn (or both) having values known at compile time, // which are not only optimized further based on lDist or iReturn (or both) having values known at compile time,
// but are called faster due to having less parameters // but are called faster due to having less parameters
int32_t VM_OnEventWithBoth_(int const nEventID, int const spriteNum, int const playerNum, int const nDist, int32_t const nReturn) int32_t VM_OnEventWithBoth__(int const nEventID, int const spriteNum, int const playerNum, int const nDist, int32_t const nReturn)
{ {
return VM_EventCommon_(nEventID, spriteNum, playerNum, nDist, nReturn); return VM_EventCommon__(nEventID, spriteNum, playerNum, nDist, nReturn);
} }
int32_t VM_OnEventWithReturn_(int const nEventID, int const spriteNum, int const playerNum, int32_t const nReturn) int32_t VM_OnEventWithReturn__(int const nEventID, int const spriteNum, int const playerNum, int32_t const nReturn)
{ {
return VM_EventCommon_(nEventID, spriteNum, playerNum, -1, nReturn); return VM_EventCommon__(nEventID, spriteNum, playerNum, -1, nReturn);
} }
int32_t VM_OnEventWithDist_(int const nEventID, int const spriteNum, int const playerNum, int const nDist) int32_t VM_OnEventWithDist__(int const nEventID, int const spriteNum, int const playerNum, int const nDist)
{ {
return VM_EventCommon_(nEventID, spriteNum, playerNum, nDist, 0); return VM_EventCommon__(nEventID, spriteNum, playerNum, nDist, 0);
} }
int32_t VM_OnEvent_(int const nEventID, int const spriteNum, int const playerNum) int32_t VM_OnEvent__(int const nEventID, int const spriteNum, int const playerNum)
{ {
return VM_EventCommon_(nEventID, spriteNum, playerNum, -1, 0); return VM_EventCommon__(nEventID, spriteNum, playerNum, -1, 0);
} }
static int32_t VM_CheckSquished(void) static bool VM_CheckSquished(void)
{ {
usectortype const * const pSector = (usectortype *)&sector[vm.pSprite->sectnum]; auto const pSector = (usectortype *)&sector[vm.pSprite->sectnum];
if (pSector->lotag == ST_23_SWINGING_DOOR || if (pSector->lotag == ST_23_SWINGING_DOOR || (vm.pSprite->picnum == APLAYER && ud.noclip) ||
(pSector->lotag == ST_1_ABOVE_WATER && (pSector->lotag == ST_1_ABOVE_WATER && !A_CheckNoSE7Water((uspritetype const *)vm.pSprite, vm.pSprite->sectnum, pSector->lotag, NULL)))
!A_CheckNoSE7Water((uspritetype const *)vm.pSprite, vm.pSprite->sectnum, pSector->lotag, NULL)) ||
(vm.pSprite->picnum == APLAYER && ud.noclip))
return 0; return 0;
int32_t floorZ = pSector->floorz; int32_t floorZ = pSector->floorz;
@ -6173,7 +6170,7 @@ void G_SaveMapState(void)
// If we're in EVENT_ANIMATESPRITES, we'll be saving pointer values to disk :-/ // If we're in EVENT_ANIMATESPRITES, we'll be saving pointer values to disk :-/
#if !defined LUNATIC #if !defined LUNATIC
if (g_currentEventExec == EVENT_ANIMATESPRITES) if (g_currentEvent == EVENT_ANIMATESPRITES)
initprintf("Line %d: savemapstate called from EVENT_ANIMATESPRITES. WHY?\n", g_errorLineNum); initprintf("Line %d: savemapstate called from EVENT_ANIMATESPRITES. WHY?\n", g_errorLineNum);
#endif #endif
Bmemcpy(&save->spriteext[0],&spriteext[0],sizeof(spriteext_t)*MAXSPRITES); Bmemcpy(&save->spriteext[0],&spriteext[0],sizeof(spriteext_t)*MAXSPRITES);
@ -6312,7 +6309,7 @@ void G_RestoreMapState(void)
// If we're restoring from EVENT_ANIMATESPRITES, all spriteext[].tspr // If we're restoring from EVENT_ANIMATESPRITES, all spriteext[].tspr
// will be overwritten, so NULL them. // will be overwritten, so NULL them.
#if !defined LUNATIC #if !defined LUNATIC
if (g_currentEventExec == EVENT_ANIMATESPRITES) if (g_currentEvent == EVENT_ANIMATESPRITES)
{ {
initprintf("Line %d: loadmapstate called from EVENT_ANIMATESPRITES. WHY?\n",g_errorLineNum); initprintf("Line %d: loadmapstate called from EVENT_ANIMATESPRITES. WHY?\n",g_errorLineNum);
for (native_t i=0; i<MAXSPRITES; i++) for (native_t i=0; i<MAXSPRITES; i++)

View file

@ -49,7 +49,7 @@ extern vmstate_t vm;
#if !defined LUNATIC #if !defined LUNATIC
extern int32_t g_tw; extern int32_t g_tw;
extern int32_t g_errorLineNum; extern int32_t g_errorLineNum;
extern int32_t g_currentEventExec; extern int32_t g_currentEvent;
void A_LoadActor(int32_t spriteNum); void A_LoadActor(int32_t spriteNum);
#endif #endif
@ -75,12 +75,12 @@ void VM_DrawTileGeneric(int32_t x, int32_t y, int32_t zoom, int32_t tilenum,
int32_t shade, int32_t orientation, int32_t p); int32_t shade, int32_t orientation, int32_t p);
#endif #endif
int32_t VM_OnEventWithBoth_(int nEventID, int spriteNum, int playerNum, int nDist, int32_t nReturn); int32_t VM_OnEvent__(int nEventID, int spriteNum, int playerNum);
int32_t VM_OnEventWithReturn_(int nEventID, int spriteNum, int playerNum, int32_t nReturn); int32_t VM_OnEventWithBoth__(int nEventID, int spriteNum, int playerNum, int nDist, int32_t nReturn);
int32_t VM_OnEventWithDist_(int nEventID, int spriteNum, int playerNum, int nDist); int32_t VM_OnEventWithDist__(int nEventID, int spriteNum, int playerNum, int nDist);
int32_t VM_OnEvent_(int nEventID, int spriteNum, int playerNum); int32_t VM_OnEventWithReturn__(int nEventID, int spriteNum, int playerNum, int32_t nReturn);
static FORCE_INLINE int VM_HaveEvent(int nEventID) static FORCE_INLINE bool VM_HaveEvent(int const nEventID)
{ {
#ifdef LUNATIC #ifdef LUNATIC
return L_IsInitialized(&g_ElState) && El_HaveEvent(nEventID); return L_IsInitialized(&g_ElState) && El_HaveEvent(nEventID);
@ -89,24 +89,24 @@ static FORCE_INLINE int VM_HaveEvent(int nEventID)
#endif #endif
} }
static FORCE_INLINE int32_t VM_OnEventWithBoth(int nEventID, int spriteNum, int playerNum, int nDist, int32_t nReturn) static FORCE_INLINE int32_t VM_OnEvent(int nEventID, int spriteNum, int playerNum)
{ {
return VM_HaveEvent(nEventID) ? VM_OnEventWithBoth_(nEventID, spriteNum, playerNum, nDist, nReturn) : nReturn; return VM_HaveEvent(nEventID) ? VM_OnEvent__(nEventID, spriteNum, playerNum) : 0;
} }
static FORCE_INLINE int32_t VM_OnEventWithReturn(int nEventID, int spriteNum, int playerNum, int nReturn) static FORCE_INLINE int32_t VM_OnEventWithBoth(int nEventID, int spriteNum, int playerNum, int nDist, int32_t nReturn)
{ {
return VM_HaveEvent(nEventID) ? VM_OnEventWithReturn_(nEventID, spriteNum, playerNum, nReturn) : nReturn; return VM_HaveEvent(nEventID) ? VM_OnEventWithBoth__(nEventID, spriteNum, playerNum, nDist, nReturn) : nReturn;
} }
static FORCE_INLINE int32_t VM_OnEventWithDist(int nEventID, int spriteNum, int playerNum, int nDist) static FORCE_INLINE int32_t VM_OnEventWithDist(int nEventID, int spriteNum, int playerNum, int nDist)
{ {
return VM_HaveEvent(nEventID) ? VM_OnEventWithDist_(nEventID, spriteNum, playerNum, nDist) : 0; return VM_HaveEvent(nEventID) ? VM_OnEventWithDist__(nEventID, spriteNum, playerNum, nDist) : 0;
} }
static FORCE_INLINE int32_t VM_OnEvent(int nEventID, int spriteNum, int playerNum) static FORCE_INLINE int32_t VM_OnEventWithReturn(int nEventID, int spriteNum, int playerNum, int nReturn)
{ {
return VM_HaveEvent(nEventID) ? VM_OnEvent_(nEventID, spriteNum, playerNum) : 0; return VM_HaveEvent(nEventID) ? VM_OnEventWithReturn__(nEventID, spriteNum, playerNum, nReturn) : nReturn;
} }
#define CON_ERRPRINTF(Text, ...) do { \ #define CON_ERRPRINTF(Text, ...) do { \

View file

@ -1250,7 +1250,7 @@ void G_DisplayRest(int32_t smoothratio)
if (VM_HaveEvent(EVENT_DISPLAYREST)) if (VM_HaveEvent(EVENT_DISPLAYREST))
{ {
int32_t vr=viewingrange, asp=yxaspect; int32_t vr=viewingrange, asp=yxaspect;
VM_OnEvent_(EVENT_DISPLAYREST, g_player[screenpeek].ps->i, screenpeek); VM_OnEvent__(EVENT_DISPLAYREST, g_player[screenpeek].ps->i, screenpeek);
renderSetAspect(vr, asp); renderSetAspect(vr, asp);
} }