From a2fd43da2fdde6e947d2c0bb5cd0b5bf05de64a6 Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 7 Dec 2019 23:52:06 +0000 Subject: [PATCH] Clean up CON_FOR a little git-svn-id: https://svn.eduke32.com/eduke32@8395 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/gameexec.cpp | 109 ++++++++++++--------------------- 1 file changed, 38 insertions(+), 71 deletions(-) diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index b05f80dac..6d4b32e12 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -2614,6 +2614,14 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/) dispatch(); } +#define CON_FOR_ITERATION() \ + do \ + { \ + Gv_SetVar(returnVar, jj); \ + insptr = pNext; \ + VM_Execute(); \ + } while (0) + vInstruction(CON_FOR): // special-purpose iteration insptr++; { @@ -2631,113 +2639,76 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/) { if (sprite[jj].statnum == MAXSTATUS) continue; - - Gv_SetVar(returnVar, jj); - insptr = pNext; - VM_Execute(); + CON_FOR_ITERATION(); } break; + case ITER_ALLSPRITESBYSTAT: for (native_t statNum = 0; statNum < MAXSTATUS; ++statNum) { - for (native_t jj = headspritestat[statNum]; jj >= 0;) - { - int const kk = nextspritestat[jj]; - Gv_SetVar(returnVar, jj); - insptr = pNext; - VM_Execute(); - jj = kk; - } + for (native_t jj = headspritestat[statNum], kk = nextspritestat[jj]; jj >= 0; jj = kk, kk = nextspritestat[jj]) + CON_FOR_ITERATION(); } break; + case ITER_ALLSPRITESBYSECT: for (native_t sectNum = 0; sectNum < numsectors; ++sectNum) { - for (native_t jj = headspritesect[sectNum]; jj >= 0;) - { - int const kk = nextspritesect[jj]; - Gv_SetVar(returnVar, jj); - insptr = pNext; - VM_Execute(); - jj = kk; - } + for (native_t jj = headspritesect[sectNum], kk = nextspritesect[jj]; jj >= 0; jj = kk, kk = nextspritesect[jj]) + CON_FOR_ITERATION(); } break; + case ITER_ALLSECTORS: for (native_t jj = 0; jj < numsectors; ++jj) - { - Gv_SetVar(returnVar, jj); - insptr = pNext; - VM_Execute(); - } + CON_FOR_ITERATION(); break; + case ITER_ALLWALLS: for (native_t jj = 0; jj < numwalls; ++jj) - { - Gv_SetVar(returnVar, jj); - insptr = pNext; - VM_Execute(); - } + CON_FOR_ITERATION(); break; + case ITER_ACTIVELIGHTS: #ifdef POLYMER for (native_t jj = 0; jj < PR_MAXLIGHTS; ++jj) { if (!prlights[jj].flags.active) continue; - - Gv_SetVar(returnVar, jj); - insptr = pNext; - VM_Execute(); + CON_FOR_ITERATION(); } #endif break; case ITER_DRAWNSPRITES: - { - for (native_t ii = 0; ii < spritesortcnt; ii++) - { - Gv_SetVar(returnVar, ii); - insptr = pNext; - VM_Execute(); - } + for (native_t jj = 0; jj < spritesortcnt; jj++) + CON_FOR_ITERATION(); break; - } case ITER_SPRITESOFSECTOR: if ((unsigned)nIndex >= MAXSECTORS) goto badindex; - for (native_t jj = headspritesect[nIndex]; jj >= 0;) - { - int const kk = nextspritesect[jj]; - Gv_SetVar(returnVar, jj); - insptr = pNext; - VM_Execute(); - jj = kk; - } + + for (native_t jj = headspritesect[nIndex], kk = nextspritesect[jj]; jj >= 0; jj = kk, kk = nextspritesect[jj]) + CON_FOR_ITERATION(); break; + case ITER_SPRITESOFSTATUS: if ((unsigned)nIndex >= MAXSTATUS) goto badindex; - for (native_t jj = headspritestat[nIndex]; jj >= 0;) - { - int const kk = nextspritestat[jj]; - Gv_SetVar(returnVar, jj); - insptr = pNext; - VM_Execute(); - jj = kk; - } + + for (native_t jj = headspritestat[nIndex], kk = nextspritestat[jj]; jj >= 0; jj = kk, kk = nextspritestat[jj]) + CON_FOR_ITERATION(); break; + case ITER_WALLSOFSECTOR: if ((unsigned)nIndex >= MAXSECTORS) goto badindex; + for (native_t jj = sector[nIndex].wallptr, endwall = jj + sector[nIndex].wallnum - 1; jj <= endwall; jj++) - { - Gv_SetVar(returnVar, jj); - insptr = pNext; - VM_Execute(); - } + CON_FOR_ITERATION(); break; + case ITER_LOOPOFWALL: if ((unsigned)nIndex >= (unsigned)numwalls) goto badindex; @@ -2745,20 +2716,15 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/) int jj = nIndex; do { - Gv_SetVar(returnVar, jj); - insptr = pNext; - VM_Execute(); + CON_FOR_ITERATION(); jj = wall[jj].point2; } while (jj != nIndex); } break; + case ITER_RANGE: for (native_t jj = 0; jj < nIndex; jj++) - { - Gv_SetVar(returnVar, jj); - insptr = pNext; - VM_Execute(); - } + CON_FOR_ITERATION(); break; badindex: OSD_Printf(OSD_ERROR "Line %d, for %s: index %d out of range!\n", VM_DECODE_LINE_NUMBER(g_tw), iter_tokens[iterType].token, nIndex); @@ -2768,6 +2734,7 @@ badindex: insptr = pEnd; } dispatch(); +#undef CON_FOR_ITERATION vInstruction(CON_REDEFINEQUOTE): insptr++;