diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index f0444c395..7dd3d5372 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -676,49 +676,123 @@ static const vec2_t varvartable[] = static const vec2_t globalvartable[] = { - { CON_IFVARA, CON_IFGLOBALVARA }, - { CON_IFVARAE, CON_IFGLOBALVARAE }, - { CON_IFVARAND, CON_IFGLOBALVARAND }, - { CON_IFVARB, CON_IFGLOBALVARB }, - { CON_IFVARBE, CON_IFGLOBALVARBE }, - { CON_IFVARBOTH, CON_IFGLOBALVARBOTH }, - { CON_IFVARE, CON_IFGLOBALVARE }, - { CON_IFVAREITHER, CON_IFGLOBALVAREITHER }, - { CON_IFVARG, CON_IFGLOBALVARG }, - { CON_IFVARGE, CON_IFGLOBALVARGE }, - { CON_IFVARL, CON_IFGLOBALVARL }, - { CON_IFVARLE, CON_IFGLOBALVARLE }, - { CON_IFVARN, CON_IFGLOBALVARN }, - { CON_IFVAROR, CON_IFGLOBALVAROR }, - { CON_IFVARXOR, CON_IFGLOBALVARXOR }, + { CON_IFVARA, CON_IFVARA_GLOBAL }, + { CON_IFVARAE, CON_IFVARAE_GLOBAL }, + { CON_IFVARAND, CON_IFVARAND_GLOBAL }, + { CON_IFVARB, CON_IFVARB_GLOBAL }, + { CON_IFVARBE, CON_IFVARBE_GLOBAL }, + { CON_IFVARBOTH, CON_IFVARBOTH_GLOBAL }, + { CON_IFVARE, CON_IFVARE_GLOBAL }, + { CON_IFVAREITHER, CON_IFVAREITHER_GLOBAL }, + { CON_IFVARG, CON_IFVARG_GLOBAL }, + { CON_IFVARGE, CON_IFVARGE_GLOBAL }, + { CON_IFVARL, CON_IFVARL_GLOBAL }, + { CON_IFVARLE, CON_IFVARLE_GLOBAL }, + { CON_IFVARN, CON_IFVARN_GLOBAL }, + { CON_IFVAROR, CON_IFVAROR_GLOBAL }, + { CON_IFVARXOR, CON_IFVARXOR_GLOBAL }, + { CON_WHILEVARL, CON_WHILEVARL_GLOBAL }, + { CON_WHILEVARN, CON_WHILEVARN_GLOBAL }, - { CON_ADDVAR, CON_ADDGLOBALVAR }, - { CON_ANDVAR, CON_ANDGLOBALVAR }, - { CON_DIVVAR, CON_DIVGLOBALVAR }, - { CON_MODVAR, CON_MODGLOBALVAR }, - { CON_MULVAR, CON_MULGLOBALVAR }, - { CON_ORVAR, CON_ORGLOBALVAR }, - { CON_RANDVAR, CON_RANDGLOBALVAR }, - { CON_SETVAR, CON_SETGLOBALVAR }, - { CON_SHIFTVARL, CON_SHIFTGLOBALVARL }, - { CON_SHIFTVARR, CON_SHIFTGLOBALVARR }, - { CON_SUBVAR, CON_SUBGLOBALVAR }, - { CON_WHILEVARL, CON_WHILEGLOBALVARL }, - { CON_WHILEVARN, CON_WHILEGLOBALVARN }, - { CON_XORVAR, CON_XORGLOBALVAR }, + { CON_ADDVAR, CON_ADDVAR_GLOBAL }, + { CON_ANDVAR, CON_ANDVAR_GLOBAL }, + { CON_DIVVAR, CON_DIVVAR_GLOBAL }, + { CON_MODVAR, CON_MODVAR_GLOBAL }, + { CON_MULVAR, CON_MULVAR_GLOBAL }, + { CON_ORVAR, CON_ORVAR_GLOBAL }, + { CON_RANDVAR, CON_RANDVAR_GLOBAL }, + { CON_SETVAR, CON_SETVAR_GLOBAL }, + { CON_SHIFTVARL, CON_SHIFTVARL_GLOBAL }, + { CON_SHIFTVARR, CON_SHIFTVARR_GLOBAL }, + { CON_SUBVAR, CON_SUBVAR_GLOBAL }, + { CON_XORVAR, CON_XORVAR_GLOBAL }, +}; + +static const vec2_t playervartable[] = +{ + { CON_IFVARA, CON_IFVARA_PLAYER }, + { CON_IFVARAE, CON_IFVARAE_PLAYER }, + { CON_IFVARAND, CON_IFVARAND_PLAYER }, + { CON_IFVARB, CON_IFVARB_PLAYER }, + { CON_IFVARBE, CON_IFVARBE_PLAYER }, + { CON_IFVARBOTH, CON_IFVARBOTH_PLAYER }, + { CON_IFVARE, CON_IFVARE_PLAYER }, + { CON_IFVAREITHER, CON_IFVAREITHER_PLAYER }, + { CON_IFVARG, CON_IFVARG_PLAYER }, + { CON_IFVARGE, CON_IFVARGE_PLAYER }, + { CON_IFVARL, CON_IFVARL_PLAYER }, + { CON_IFVARLE, CON_IFVARLE_PLAYER }, + { CON_IFVARN, CON_IFVARN_PLAYER }, + { CON_IFVAROR, CON_IFVAROR_PLAYER }, + { CON_IFVARXOR, CON_IFVARXOR_PLAYER }, + { CON_WHILEVARL, CON_WHILEVARL_PLAYER }, + { CON_WHILEVARN, CON_WHILEVARN_PLAYER }, + + { CON_ADDVAR, CON_ADDVAR_PLAYER }, + { CON_ANDVAR, CON_ANDVAR_PLAYER }, + { CON_DIVVAR, CON_DIVVAR_PLAYER }, + { CON_MODVAR, CON_MODVAR_PLAYER }, + { CON_MULVAR, CON_MULVAR_PLAYER }, + { CON_ORVAR, CON_ORVAR_PLAYER }, + { CON_RANDVAR, CON_RANDVAR_PLAYER }, + { CON_SETVAR, CON_SETVAR_PLAYER }, + { CON_SHIFTVARL, CON_SHIFTVARL_PLAYER }, + { CON_SHIFTVARR, CON_SHIFTVARR_PLAYER }, + { CON_SUBVAR, CON_SUBVAR_PLAYER }, + { CON_XORVAR, CON_XORVAR_PLAYER }, +}; + +static const vec2_t actorvartable[] = +{ + { CON_IFVARA, CON_IFVARA_ACTOR }, + { CON_IFVARAE, CON_IFVARAE_ACTOR }, + { CON_IFVARAND, CON_IFVARAND_ACTOR }, + { CON_IFVARB, CON_IFVARB_ACTOR }, + { CON_IFVARBE, CON_IFVARBE_ACTOR }, + { CON_IFVARBOTH, CON_IFVARBOTH_ACTOR }, + { CON_IFVARE, CON_IFVARE_ACTOR }, + { CON_IFVAREITHER, CON_IFVAREITHER_ACTOR }, + { CON_IFVARG, CON_IFVARG_ACTOR }, + { CON_IFVARGE, CON_IFVARGE_ACTOR }, + { CON_IFVARL, CON_IFVARL_ACTOR }, + { CON_IFVARLE, CON_IFVARLE_ACTOR }, + { CON_IFVARN, CON_IFVARN_ACTOR }, + { CON_IFVAROR, CON_IFVAROR_ACTOR }, + { CON_IFVARXOR, CON_IFVARXOR_ACTOR }, + { CON_WHILEVARL, CON_WHILEVARL_ACTOR }, + { CON_WHILEVARN, CON_WHILEVARN_ACTOR }, + + { CON_ADDVAR, CON_ADDVAR_ACTOR }, + { CON_ANDVAR, CON_ANDVAR_ACTOR }, + { CON_DIVVAR, CON_DIVVAR_ACTOR }, + { CON_MODVAR, CON_MODVAR_ACTOR }, + { CON_MULVAR, CON_MULVAR_ACTOR }, + { CON_ORVAR, CON_ORVAR_ACTOR }, + { CON_RANDVAR, CON_RANDVAR_ACTOR }, + { CON_SETVAR, CON_SETVAR_ACTOR }, + { CON_SHIFTVARL, CON_SHIFTVARL_ACTOR }, + { CON_SHIFTVARR, CON_SHIFTVARR_ACTOR }, + { CON_SUBVAR, CON_SUBVAR_ACTOR }, + { CON_XORVAR, CON_XORVAR_ACTOR }, }; static inthashtable_t h_varvar = { NULL, INTHASH_SIZE(ARRAY_SIZE(varvartable)) }; static inthashtable_t h_globalvar = { NULL, INTHASH_SIZE(ARRAY_SIZE(globalvartable)) }; +static inthashtable_t h_playervar = { NULL, INTHASH_SIZE(ARRAY_SIZE(playervartable)) }; +static inthashtable_t h_actorvar = { NULL, INTHASH_SIZE(ARRAY_SIZE(actorvartable)) }; static inthashtable_t *const inttables[] = { &h_varvar, &h_globalvar, + &h_playervar, + &h_actorvar, }; static inthashtable_t *const inttables_free[] = { &h_varvar, &h_globalvar, + &h_playervar, + &h_actorvar, }; @@ -750,7 +824,7 @@ char const * VM_GetKeywordForID(int32_t id) if (keyword.val == id) return keyword.token; - return id < CON_OPCODE_END ? "" : ""; + return ""; } #endif @@ -3716,22 +3790,8 @@ setvar: } } #endif - // replace instructions with special versions that operate only on globals - if ((aGameVars[ins[1]].flags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK)) == 0) - { - int const opcode = inthash_find(&h_globalvar, *ins & VM_INSTMASK); - - if (opcode != -1) - { - if (!g_errorCnt && !g_warningCnt && g_scriptDebug > 1) - { - initprintf("%s:%d: %s -> %s\n", g_scriptFileName, g_lineNumber, - VM_GetKeywordForID(*ins & VM_INSTMASK), VM_GetKeywordForID(opcode)); - } - - scriptWriteAtOffset(opcode | LINE_NUMBER, ins); - } - } + // replace instructions with special versions for specific var types + scriptUpdateOpcodeForVariableType(ins); continue; } @@ -4292,8 +4352,7 @@ setvarvar: tw = opcode; g_scriptPtr = &ins[1]; textptr = lasttextptr; - - goto singlevar; + goto ifvar; } } @@ -4339,7 +4398,7 @@ setvarvar: case CON_WHILEVARL: case CON_WHILEVARN: { -singlevar: +ifvar: auto const ins = &g_scriptPtr[-1]; auto const lastScriptPtr = &g_scriptPtr[-1] - apScript; @@ -4351,23 +4410,7 @@ singlevar: if (C_CheckMalformedBranch(lastScriptPtr)) continue; - // substitute instructions that operate on global vars directly if appropriate - if (aGameVars[ins[1] & (MAXGAMEVARS-1)].flags == 0) - { - int const opcode = inthash_find(&h_globalvar, *ins & VM_INSTMASK); - - if (opcode != -1) - { - //if (!g_errorCnt && !g_warningCnt && g_scriptDebug > 1) - { - initprintf("%s:%d: %s -> %s for var %s(%d)\n", g_scriptFileName, g_lineNumber, - VM_GetKeywordForID(*ins & VM_INSTMASK), VM_GetKeywordForID(opcode), aGameVars[ins[1] & (MAXGAMEVARS-1)].szLabel, (int)(ins[1])); - } - - tw = opcode; - scriptWriteAtOffset(opcode | LINE_NUMBER, ins); - } - } + scriptUpdateOpcodeForVariableType(ins); auto const offset = g_scriptPtr - apScript; g_scriptPtr++; //Leave a spot for the fail location @@ -6110,6 +6153,12 @@ void scriptInitTables() for (auto &globalvar : globalvartable) inthash_add(&h_globalvar, globalvar.x, globalvar.y, 0); + + for (auto &playervar : playervartable) + inthash_add(&h_playervar, playervar.x, playervar.y, 0); + + for (auto &actorvar : actorvartable) + inthash_add(&h_actorvar, actorvar.x, actorvar.y, 0); } void C_Compile(const char *fileName) @@ -6244,6 +6293,8 @@ void C_Compile(const char *fileName) inthash_free(&h_varvar); inthash_free(&h_globalvar); + inthash_free(&h_playervar); + inthash_free(&h_actorvar); freehashnames(); freesoundhashnames(); diff --git a/source/duke3d/src/gamedef.h b/source/duke3d/src/gamedef.h index 2b63e1a6a..6bbe7671a 100644 --- a/source/duke3d/src/gamedef.h +++ b/source/duke3d/src/gamedef.h @@ -837,25 +837,212 @@ enum IterationTypes_t // most keywords have opcodes but some opcodes don't have keywords enum ScriptKeywords_t { + CON_IFVARA_GLOBAL, + CON_IFVARAE_GLOBAL, + CON_IFVARAND_GLOBAL, + CON_IFVARB_GLOBAL, + CON_IFVARBE_GLOBAL, + CON_IFVARBOTH_GLOBAL, + CON_IFVARE_GLOBAL, + CON_IFVAREITHER_GLOBAL, + CON_IFVARG_GLOBAL, + CON_IFVARGE_GLOBAL, + CON_IFVARL_GLOBAL, + CON_IFVARLE_GLOBAL, + CON_IFVARN_GLOBAL, + CON_IFVAROR_GLOBAL, + CON_IFVARXOR_GLOBAL, + + CON_ADDVAR_GLOBAL, + CON_ANDVAR_GLOBAL, + CON_DIVVAR_GLOBAL, + CON_MODVAR_GLOBAL, + CON_MULVAR_GLOBAL, + CON_ORVAR_GLOBAL, + CON_RANDVAR_GLOBAL, + CON_SETVAR_GLOBAL, + CON_SHIFTVARL_GLOBAL, + CON_SHIFTVARR_GLOBAL, + CON_SUBVAR_GLOBAL, + CON_WHILEVARL_GLOBAL, + CON_WHILEVARN_GLOBAL, + CON_XORVAR_GLOBAL, + + CON_IFVARA_PLAYER, + CON_IFVARAE_PLAYER, + CON_IFVARAND_PLAYER, + CON_IFVARB_PLAYER, + CON_IFVARBE_PLAYER, + CON_IFVARBOTH_PLAYER, + CON_IFVARE_PLAYER, + CON_IFVAREITHER_PLAYER, + CON_IFVARG_PLAYER, + CON_IFVARGE_PLAYER, + CON_IFVARL_PLAYER, + CON_IFVARLE_PLAYER, + CON_IFVARN_PLAYER, + CON_IFVAROR_PLAYER, + CON_IFVARXOR_PLAYER, + + CON_ADDVAR_PLAYER, + CON_ANDVAR_PLAYER, + CON_DIVVAR_PLAYER, + CON_MODVAR_PLAYER, + CON_MULVAR_PLAYER, + CON_ORVAR_PLAYER, + CON_RANDVAR_PLAYER, + CON_SETVAR_PLAYER, + CON_SHIFTVARL_PLAYER, + CON_SHIFTVARR_PLAYER, + CON_SUBVAR_PLAYER, + CON_WHILEVARL_PLAYER, + CON_WHILEVARN_PLAYER, + CON_XORVAR_PLAYER, + + CON_IFVARA_ACTOR, + CON_IFVARAE_ACTOR, + CON_IFVARAND_ACTOR, + CON_IFVARB_ACTOR, + CON_IFVARBE_ACTOR, + CON_IFVARBOTH_ACTOR, + CON_IFVARE_ACTOR, + CON_IFVAREITHER_ACTOR, + CON_IFVARG_ACTOR, + CON_IFVARGE_ACTOR, + CON_IFVARL_ACTOR, + CON_IFVARLE_ACTOR, + CON_IFVARN_ACTOR, + CON_IFVAROR_ACTOR, + CON_IFVARXOR_ACTOR, + + CON_ADDVAR_ACTOR, + CON_ANDVAR_ACTOR, + CON_DIVVAR_ACTOR, + CON_MODVAR_ACTOR, + CON_MULVAR_ACTOR, + CON_ORVAR_ACTOR, + CON_RANDVAR_ACTOR, + CON_SETVAR_ACTOR, + CON_SHIFTVARL_ACTOR, + CON_SHIFTVARR_ACTOR, + CON_SUBVAR_ACTOR, + CON_WHILEVARL_ACTOR, + CON_WHILEVARN_ACTOR, + CON_XORVAR_ACTOR, + + CON_IFVARVARA, + CON_IFVARVARAE, + CON_IFVARVARAND, + CON_IFVARVARB, + CON_IFVARVARBE, + CON_IFVARVARBOTH, + CON_IFVARVARE, + CON_IFVARVAREITHER, + CON_IFVARVARG, + CON_IFVARVARGE, + CON_IFVARVARL, + CON_IFVARVARLE, + CON_IFVARVARN, + CON_IFVARVAROR, + CON_IFVARVARXOR, + + CON_ADDVARVAR, + CON_ANDVARVAR, + CON_DIVVARVAR, + CON_MODVARVAR, + CON_MULVARVAR, + CON_ORVARVAR, + CON_RANDVARVAR, + CON_SETVARVAR, + CON_SHIFTVARVARL, + CON_SHIFTVARVARR, + CON_SUBVARVAR, + CON_WHILEVARVARL, + CON_WHILEVARVARN, + CON_XORVARVAR, + + CON_IFVARA, + CON_IFVARAE, + CON_IFVARAND, + CON_IFVARB, + CON_IFVARBE, + CON_IFVARBOTH, + CON_IFVARE, + CON_IFVAREITHER, + CON_IFVARG, + CON_IFVARGE, + CON_IFVARL, + CON_IFVARLE, + CON_IFVARN, + CON_IFVAROR, + CON_IFVARXOR, + + CON_ADDVAR, + CON_ANDVAR, + CON_DIVVAR, + CON_MODVAR, + CON_MULVAR, + CON_ORVAR, + CON_RANDVAR, + CON_SETVAR, + CON_SHIFTVARL, + CON_SHIFTVARR, + CON_SUBVAR, + CON_WHILEVARL, + CON_WHILEVARN, + CON_XORVAR, + + CON_ELSE, + CON_ENDA, + CON_ENDEVENT, + CON_ENDS, + CON_ENDSWITCH, + CON_LEFTBRACE, + CON_RIGHTBRACE, + CON_STATE, + + CON_SETACTOR, + CON_SETACTORSTRUCT, + CON_SETACTORVAR, + CON_SETARRAY, + CON_SETPLAYER, + CON_SETPLAYERVAR, + CON_SETPROJECTILE, + CON_SETSECTOR, + CON_SETSPRITEEXT, + CON_SETSPRITESTRUCT, + CON_SETTHISPROJECTILE, + CON_SETTSPR, + CON_SETUSERDEF, + CON_SETWALL, + + CON_GETACTOR, + CON_GETACTORSTRUCT, + CON_GETACTORVAR, + CON_GETANGLE, + CON_GETPLAYER, + CON_GETPLAYERVAR, + CON_GETPROJECTILE, + CON_GETSECTOR, + CON_GETSPRITEEXT, + CON_GETSPRITESTRUCT, + CON_GETTSPR, + CON_GETUSERDEF, + CON_GETWALL, + CON_ACTION, CON_ACTIVATE, CON_ACTIVATEBYSECTOR, CON_ACTIVATECHEAT, CON_ACTORSOUND, CON_ADDAMMO, - CON_ADDGLOBALVAR, CON_ADDINVENTORY, CON_ADDKILLS, CON_ADDLOGVAR, CON_ADDPHEALTH, CON_ADDSTRENGTH, - CON_ADDVAR, - CON_ADDVARVAR, CON_ADDWEAPON, CON_AI, - CON_ANDGLOBALVAR, - CON_ANDVAR, - CON_ANDVARVAR, CON_ANGOFF, CON_BREAK, CON_CACTOR, @@ -883,26 +1070,18 @@ enum ScriptKeywords_t CON_DIGITALNUMBER, CON_DIGITALNUMBERZ, CON_DISPLAYRAND, - CON_DISPLAYRANDVAR, - CON_DISPLAYRANDVARVAR, CON_DIST, - CON_DIVGLOBALVAR, CON_DIVR, CON_DIVRU, CON_DIVSCALE, - CON_DIVVAR, - CON_DIVVARVAR, + CON_DISPLAYRANDVAR, + CON_DISPLAYRANDVARVAR, CON_DRAGPOINT, CON_DRAWLINE256, CON_DRAWLINERGB, CON_ECHO, - CON_ELSE, - CON_ENDA, - CON_ENDEVENT, CON_ENDOFGAME, CON_ENDOFLEVEL, - CON_ENDS, - CON_ENDSWITCH, CON_EQSPAWN, CON_ESHOOT, CON_ESPAWN, @@ -921,11 +1100,7 @@ enum ScriptKeywords_t CON_FOR, CON_GAMETEXT, CON_GAMETEXTZ, - CON_GETACTOR, CON_GETACTORANGLE, - CON_GETACTORSTRUCT, - CON_GETACTORVAR, - CON_GETANGLE, CON_GETANGLETOTARGET, CON_GETARRAYSIZE, CON_GETCEILZOFSLOPE, @@ -937,23 +1112,14 @@ enum ScriptKeywords_t CON_GETKEYNAME, CON_GETLASTPAL, CON_GETMUSICPOSITION, - CON_GETPLAYER, CON_GETPLAYERANGLE, - CON_GETPLAYERVAR, CON_GETPNAME, - CON_GETPROJECTILE, - CON_GETSECTOR, - CON_GETSPRITEEXT, - CON_GETSPRITESTRUCT, CON_GETTEXTURECEILING, CON_GETTEXTUREFLOOR, CON_GETTHISPROJECTILE, CON_GETTICKS, CON_GETTILEDATA, CON_GETTIMEDATE, - CON_GETTSPR, - CON_GETUSERDEF, - CON_GETWALL, CON_GETZRANGE, CON_GLOBALSOUND, CON_GMAXAMMO, @@ -982,21 +1148,6 @@ enum ScriptKeywords_t CON_IFDEAD, CON_IFFLOORDISTL, CON_IFGAPZL, - CON_IFGLOBALVARA, - CON_IFGLOBALVARAE, - CON_IFGLOBALVARAND, - CON_IFGLOBALVARB, - CON_IFGLOBALVARBE, - CON_IFGLOBALVARBOTH, - CON_IFGLOBALVARE, - CON_IFGLOBALVAREITHER, - CON_IFGLOBALVARG, - CON_IFGLOBALVARGE, - CON_IFGLOBALVARL, - CON_IFGLOBALVARLE, - CON_IFGLOBALVARN, - CON_IFGLOBALVAROR, - CON_IFGLOBALVARXOR, CON_IFGOTWEAPONCE, CON_IFHITSPACE, CON_IFHITWEAPON, @@ -1024,36 +1175,6 @@ enum ScriptKeywords_t CON_IFSPRITEPAL, CON_IFSQUISHED, CON_IFSTRENGTH, - CON_IFVARA, - CON_IFVARAE, - CON_IFVARAND, - CON_IFVARB, - CON_IFVARBE, - CON_IFVARBOTH, - CON_IFVARE, - CON_IFVAREITHER, - CON_IFVARG, - CON_IFVARGE, - CON_IFVARL, - CON_IFVARLE, - CON_IFVARN, - CON_IFVAROR, - CON_IFVARVARA, - CON_IFVARVARAE, - CON_IFVARVARAND, - CON_IFVARVARB, - CON_IFVARVARBE, - CON_IFVARVARBOTH, - CON_IFVARVARE, - CON_IFVARVAREITHER, - CON_IFVARVARG, - CON_IFVARVARGE, - CON_IFVARVARL, - CON_IFVARVARLE, - CON_IFVARVARN, - CON_IFVARVAROR, - CON_IFVARVARXOR, - CON_IFVARXOR, CON_IFWASWEAPON, CON_INITTIMER, CON_INSERTSPRITEQ, @@ -1062,7 +1183,6 @@ enum ScriptKeywords_t CON_KILLIT, CON_KLABS, CON_LDIST, - CON_LEFTBRACE, CON_LINEINTERSECT, CON_LOADMAPSTATE, CON_LOCKPLAYER, @@ -1070,17 +1190,11 @@ enum ScriptKeywords_t CON_MAIL, CON_MIKESND, CON_MINITEXT, - CON_MODGLOBALVAR, - CON_MODVAR, - CON_MODVARVAR, CON_MONEY, CON_MOVE, CON_MOVESECTOR, CON_MOVESPRITE, - CON_MULGLOBALVAR, CON_MULSCALE, - CON_MULVAR, - CON_MULVARVAR, CON_MUSIC, CON_MYOS, CON_MYOSPAL, @@ -1096,9 +1210,6 @@ enum ScriptKeywords_t CON_OPERATEMASTERSWITCHES, CON_OPERATERESPAWNS, CON_OPERATESECTORS, - CON_ORGLOBALVAR, - CON_ORVAR, - CON_ORVARVAR, CON_PALFROM, CON_PAPER, CON_PKICK, @@ -1119,9 +1230,6 @@ enum ScriptKeywords_t CON_QSUBSTR, CON_QUAKE, CON_QUOTE, - CON_RANDGLOBALVAR, - CON_RANDVAR, - CON_RANDVARVAR, CON_RAYINTERSECT, CON_READARRAYFROMFILE, CON_READGAMEVAR, @@ -1133,7 +1241,6 @@ enum ScriptKeywords_t CON_RESIZEARRAY, CON_RESPAWNHITAG, CON_RETURN, - CON_RIGHTBRACE, CON_ROTATEPOINT, CON_ROTATESPRITE, CON_ROTATESPRITE16, @@ -1151,39 +1258,16 @@ enum ScriptKeywords_t CON_SECTGETLOTAG, CON_SECTOROFWALL, CON_SECTSETINTERPOLATION, - CON_SETACTOR, CON_SETACTORANGLE, CON_SETACTORSOUNDPITCH, - CON_SETACTORSTRUCT, - CON_SETACTORVAR, - CON_SETARRAY, CON_SETASPECT, CON_SETGAMEPALETTE, - CON_SETGLOBALVAR, CON_SETINPUT, CON_SETMUSICPOSITION, - CON_SETPLAYER, CON_SETPLAYERANGLE, - CON_SETPLAYERVAR, - CON_SETPROJECTILE, - CON_SETSECTOR, CON_SETSPRITE, - CON_SETSPRITEEXT, - CON_SETSPRITESTRUCT, - CON_SETTHISPROJECTILE, CON_SETTILEDATA, - CON_SETTSPR, - CON_SETUSERDEF, - CON_SETVAR, - CON_SETVARVAR, - CON_SETWALL, CON_SHADETO, - CON_SHIFTGLOBALVARL, - CON_SHIFTGLOBALVARR, - CON_SHIFTVARL, - CON_SHIFTVARR, - CON_SHIFTVARVARL, - CON_SHIFTVARVARR, CON_SHOOT, CON_SHOWVIEW, CON_SHOWVIEWQ16, @@ -1211,15 +1295,11 @@ enum ScriptKeywords_t CON_STARTSCREEN, CON_STARTTRACK, CON_STARTTRACKSLOT, - CON_STATE, CON_STOPACTORSOUND, CON_STOPALLMUSIC, CON_STOPALLSOUNDS, CON_STOPSOUND, CON_STRENGTH, - CON_SUBGLOBALVAR, - CON_SUBVAR, - CON_SUBVARVAR, CON_SWAPARRAYS, CON_SWAPTRACKSLOT, CON_SWITCH, @@ -1230,16 +1310,7 @@ enum ScriptKeywords_t CON_UPDATESECTORZ, CON_USERQUOTE, CON_WACKPLAYER, - CON_WHILEGLOBALVARL, - CON_WHILEGLOBALVARN, - CON_WHILEVARL, - CON_WHILEVARN, - CON_WHILEVARVARL, - CON_WHILEVARVARN, CON_WRITEARRAYTOFILE, - CON_XORGLOBALVAR, - CON_XORVAR, - CON_XORVARVAR, CON_ZSHOOT, CON_OPCODE_END, diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index a7629742a..54e131cba 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -99,8 +99,10 @@ void VM_ScriptInfo(intptr_t const *ptr, int range) { initprintf("%5d: %3d: ", (int32_t)(pScript - apScript), (int32_t)(pScript - ptr)); - if (*pScript >> 12 && (*pScript & VM_INSTMASK) < CON_OPCODE_END) - initprintf("%5d %s\n", (int32_t)(*pScript >> 12), VM_GetKeywordForID(*pScript & VM_INSTMASK)); + auto &v = *pScript; + + if (v >> 12 && (v & VM_INSTMASK) < CON_OPCODE_END) + initprintf("%5d %s (%d)\n", (int32_t)(v >> 12), VM_GetKeywordForID(v & VM_INSTMASK), (int)v & VM_INSTMASK); else initprintf("%d\n", (int32_t)*pScript); } @@ -1302,17 +1304,564 @@ next_instruction: } continue; - case CON_SETVAR: + case CON_IFVARE_GLOBAL: insptr++; - Gv_SetVarX(*insptr, insptr[1]); - insptr += 2; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL(tw == *insptr); + continue; + case CON_IFVARN_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL(tw != *insptr); + continue; + case CON_IFVARAND_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL(tw & *insptr); + continue; + case CON_IFVAROR_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL(tw | *insptr); + continue; + case CON_IFVARXOR_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL(tw ^ *insptr); + continue; + case CON_IFVAREITHER_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL(tw || *insptr); + continue; + case CON_IFVARBOTH_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL(tw && *insptr); + continue; + case CON_IFVARG_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL(tw > *insptr); + continue; + case CON_IFVARGE_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL(tw >= *insptr); + continue; + case CON_IFVARL_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL(tw < *insptr); + continue; + case CON_IFVARLE_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL(tw <= *insptr); + continue; + case CON_IFVARA_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL((uint32_t)tw > (uint32_t)*insptr); + continue; + case CON_IFVARAE_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL((uint32_t)tw >= (uint32_t)*insptr); + continue; + case CON_IFVARB_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL((uint32_t)tw < (uint32_t)*insptr); + continue; + case CON_IFVARBE_GLOBAL: + insptr++; + tw = aGameVars[*insptr++].global; + VM_CONDITIONAL((uint32_t)tw <= (uint32_t)*insptr); continue; - case CON_SETGLOBALVAR: + case CON_SETVAR_GLOBAL: insptr++; aGameVars[*insptr].global = insptr[1]; insptr += 2; continue; + case CON_ADDVAR_GLOBAL: + insptr++; + aGameVars[*insptr].global += insptr[1]; + insptr += 2; + continue; + case CON_SUBVAR_GLOBAL: + insptr++; + aGameVars[*insptr].global -= insptr[1]; + insptr += 2; + continue; + case CON_MULVAR_GLOBAL: + insptr++; + aGameVars[*insptr].global *= insptr[1]; + insptr += 2; + continue; + case CON_ANDVAR_GLOBAL: + insptr++; + aGameVars[*insptr].global &= insptr[1]; + insptr += 2; + continue; + case CON_XORVAR_GLOBAL: + insptr++; + aGameVars[*insptr].global ^= insptr[1]; + insptr += 2; + continue; + case CON_ORVAR_GLOBAL: + insptr++; + aGameVars[*insptr].global |= insptr[1]; + insptr += 2; + continue; + case CON_SHIFTVARL_GLOBAL: + insptr++; + aGameVars[*insptr].global <<= insptr[1]; + insptr += 2; + continue; + case CON_SHIFTVARR_GLOBAL: + insptr++; + aGameVars[*insptr].global >>= insptr[1]; + insptr += 2; + continue; + + case CON_IFVARE_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL(tw == *insptr); + continue; + case CON_IFVARN_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL(tw != *insptr); + continue; + case CON_IFVARAND_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL(tw & *insptr); + continue; + case CON_IFVAROR_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL(tw | *insptr); + continue; + case CON_IFVARXOR_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL(tw ^ *insptr); + continue; + case CON_IFVAREITHER_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL(tw || *insptr); + continue; + case CON_IFVARBOTH_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL(tw && *insptr); + continue; + case CON_IFVARG_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL(tw > *insptr); + continue; + case CON_IFVARGE_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL(tw >= *insptr); + continue; + case CON_IFVARL_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL(tw < *insptr); + continue; + case CON_IFVARLE_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL(tw <= *insptr); + continue; + case CON_IFVARA_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL((uint32_t)tw > (uint32_t)*insptr); + continue; + case CON_IFVARAE_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL((uint32_t)tw >= (uint32_t)*insptr); + continue; + case CON_IFVARB_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL((uint32_t)tw < (uint32_t)*insptr); + continue; + case CON_IFVARBE_ACTOR: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.spriteNum & (MAXSPRITES-1)]; + VM_CONDITIONAL((uint32_t)tw <= (uint32_t)*insptr); + continue; + + case CON_SETVAR_ACTOR: + insptr++; + aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES-1)] = insptr[1]; + insptr += 2; + continue; + case CON_ADDVAR_ACTOR: + insptr++; + aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES-1)] += insptr[1]; + insptr += 2; + continue; + case CON_SUBVAR_ACTOR: + insptr++; + aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES-1)] -= insptr[1]; + insptr += 2; + continue; + case CON_MULVAR_ACTOR: + insptr++; + aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES-1)] *= insptr[1]; + insptr += 2; + continue; + case CON_ANDVAR_ACTOR: + insptr++; + aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES-1)] &= insptr[1]; + insptr += 2; + continue; + case CON_XORVAR_ACTOR: + insptr++; + aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES-1)] ^= insptr[1]; + insptr += 2; + continue; + case CON_ORVAR_ACTOR: + insptr++; + aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES-1)] |= insptr[1]; + insptr += 2; + continue; + case CON_SHIFTVARL_ACTOR: + insptr++; + aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES-1)] <<= insptr[1]; + insptr += 2; + continue; + case CON_SHIFTVARR_ACTOR: + insptr++; + aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES-1)] >>= insptr[1]; + insptr += 2; + continue; + + case CON_IFVARE_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL(tw == *insptr); + continue; + case CON_IFVARN_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL(tw != *insptr); + continue; + case CON_IFVARAND_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL(tw & *insptr); + continue; + case CON_IFVAROR_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL(tw | *insptr); + continue; + case CON_IFVARXOR_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL(tw ^ *insptr); + continue; + case CON_IFVAREITHER_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL(tw || *insptr); + continue; + case CON_IFVARBOTH_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL(tw && *insptr); + continue; + case CON_IFVARG_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL(tw > *insptr); + continue; + case CON_IFVARGE_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL(tw >= *insptr); + continue; + case CON_IFVARL_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL(tw < *insptr); + continue; + case CON_IFVARLE_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL(tw <= *insptr); + continue; + case CON_IFVARA_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL((uint32_t)tw > (uint32_t)*insptr); + continue; + case CON_IFVARAE_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL((uint32_t)tw >= (uint32_t)*insptr); + continue; + case CON_IFVARB_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL((uint32_t)tw < (uint32_t)*insptr); + continue; + case CON_IFVARBE_PLAYER: + insptr++; + tw = aGameVars[*insptr++].pValues[vm.playerNum & (MAXPLAYERS-1)]; + VM_CONDITIONAL((uint32_t)tw <= (uint32_t)*insptr); + continue; + + case CON_SETVAR_PLAYER: + insptr++; + aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS-1)] = insptr[1]; + insptr += 2; + continue; + case CON_ADDVAR_PLAYER: + insptr++; + aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS-1)] += insptr[1]; + insptr += 2; + continue; + case CON_SUBVAR_PLAYER: + insptr++; + aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS-1)] -= insptr[1]; + insptr += 2; + continue; + case CON_MULVAR_PLAYER: + insptr++; + aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS-1)] *= insptr[1]; + insptr += 2; + continue; + case CON_ANDVAR_PLAYER: + insptr++; + aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS-1)] &= insptr[1]; + insptr += 2; + continue; + case CON_XORVAR_PLAYER: + insptr++; + aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS-1)] ^= insptr[1]; + insptr += 2; + continue; + case CON_ORVAR_PLAYER: + insptr++; + aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS-1)] |= insptr[1]; + insptr += 2; + continue; + case CON_SHIFTVARL_PLAYER: + insptr++; + aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS-1)] <<= insptr[1]; + insptr += 2; + continue; + case CON_SHIFTVARR_PLAYER: + insptr++; + aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS-1)] >>= insptr[1]; + insptr += 2; + continue; + + case CON_WHILEVARN_GLOBAL: + { + auto const savedinsptr = &insptr[2]; + do + { + insptr = savedinsptr; + tw = (aGameVars[insptr[-1]].global != *insptr); + VM_CONDITIONAL(tw); + } while (tw); + continue; + } + + case CON_WHILEVARL_GLOBAL: + { + auto const savedinsptr = &insptr[2]; + do + { + insptr = savedinsptr; + tw = (aGameVars[insptr[-1]].global < *insptr); + VM_CONDITIONAL(tw); + } while (tw); + continue; + } + + case CON_WHILEVARN_ACTOR: + { + auto const savedinsptr = &insptr[2]; + auto &v = aGameVars[savedinsptr[-1]].pValues[vm.spriteNum & (MAXSPRITES-1)]; + do + { + insptr = savedinsptr; + tw = (v != *insptr); + VM_CONDITIONAL(tw); + } while (tw); + + continue; + } + + case CON_WHILEVARL_ACTOR: + { + auto const savedinsptr = &insptr[2]; + auto &v = aGameVars[savedinsptr[-1]].pValues[vm.spriteNum & (MAXSPRITES-1)]; + do + { + insptr = savedinsptr; + tw = (v < *insptr); + VM_CONDITIONAL(tw); + } while (tw); + + continue; + } + + case CON_WHILEVARN_PLAYER: + { + auto const savedinsptr = &insptr[2]; + auto &v = aGameVars[savedinsptr[-1]].pValues[vm.playerNum & (MAXPLAYERS-1)]; + do + { + insptr = savedinsptr; + tw = (v != *insptr); + VM_CONDITIONAL(tw); + } while (tw); + + continue; + } + + case CON_WHILEVARL_PLAYER: + { + auto const savedinsptr = &insptr[2]; + auto &v = aGameVars[savedinsptr[-1]].pValues[vm.playerNum & (MAXPLAYERS-1)]; + do + { + insptr = savedinsptr; + tw = (v < *insptr); + VM_CONDITIONAL(tw); + } while (tw); + + continue; + } + + case CON_MODVAR_GLOBAL: + insptr++; + if (EDUKE32_PREDICT_FALSE(insptr[1] == 0)) + { + CON_CRITICALERRPRINTF("mod by zero!\n"); + continue; + } + aGameVars[*insptr].global %= insptr[1]; + insptr += 2; + continue; + case CON_MODVAR_ACTOR: + insptr++; + if (EDUKE32_PREDICT_FALSE(insptr[1] == 0)) + { + CON_CRITICALERRPRINTF("mod by zero!\n"); + continue; + } + aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES-1)] %= insptr[1]; + insptr += 2; + continue; + case CON_MODVAR_PLAYER: + insptr++; + if (EDUKE32_PREDICT_FALSE(insptr[1] == 0)) + { + CON_CRITICALERRPRINTF("mod by zero!\n"); + continue; + } + aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS-1)] %= insptr[1]; + insptr += 2; + continue; + + case CON_IFVARAND: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL(tw & *insptr); + continue; + + case CON_IFVAROR: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL(tw | *insptr); + continue; + + case CON_IFVARXOR: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL(tw ^ *insptr); + continue; + + case CON_IFVAREITHER: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL(tw || *insptr); + continue; + + case CON_IFVARBOTH: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL(tw && *insptr); + continue; + + case CON_IFRND: + VM_CONDITIONAL(rnd(*(++insptr))); + continue; + + case CON_IFVARG: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL(tw > *insptr); + continue; + + case CON_IFVARGE: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL(tw >= *insptr); + continue; + + case CON_IFVARL: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL(tw < *insptr); + continue; + + case CON_IFVARLE: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL(tw <= *insptr); + continue; + + case CON_IFVARA: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL((uint32_t)tw > (uint32_t)*insptr); + continue; + + case CON_IFVARAE: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL((uint32_t)tw >= (uint32_t)*insptr); + continue; + + case CON_IFVARB: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL((uint32_t)tw < (uint32_t)*insptr); + continue; + + case CON_IFVARBE: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL((uint32_t)tw <= (uint32_t)*insptr); + continue; case CON_SETVARVAR: insptr++; @@ -1327,68 +1876,46 @@ next_instruction: } continue; - case CON_ADDVAR: - insptr++; - Gv_AddVar(*insptr, insptr[1]); - insptr += 2; - continue; - - case CON_ADDGLOBALVAR: - insptr++; - aGameVars[*insptr].global += insptr[1]; - insptr += 2; - continue; - case CON_ADDVARVAR: insptr++; tw = *insptr++; Gv_AddVar(tw, Gv_GetVarX(*insptr++)); continue; - case CON_SUBVAR: - insptr++; - Gv_SubVar(*insptr, insptr[1]); - insptr += 2; - continue; - - case CON_SUBGLOBALVAR: - insptr++; - aGameVars[*insptr].global -= insptr[1]; - insptr += 2; - continue; - case CON_SUBVARVAR: insptr++; tw = *insptr++; Gv_SubVar(tw, Gv_GetVarX(*insptr++)); continue; - case CON_IFVARVARE: + case CON_ANDVARVAR: insptr++; - tw = Gv_GetVarX(*insptr++); - tw = (tw == Gv_GetVarX(*insptr++)); - insptr--; - VM_CONDITIONAL(tw); + tw = *insptr++; + Gv_AndVar(tw, Gv_GetVarX(*insptr++)); continue; - case CON_IFVARVARN: + case CON_XORVARVAR: insptr++; - tw = Gv_GetVarX(*insptr++); - tw = (tw != Gv_GetVarX(*insptr++)); - insptr--; - VM_CONDITIONAL(tw); + tw = *insptr++; + Gv_XorVar(tw, Gv_GetVarX(*insptr++)); continue; - case CON_MULVAR: + case CON_ORVARVAR: insptr++; - Gv_MulVar(*insptr, insptr[1]); - insptr += 2; + tw = *insptr++; + Gv_OrVar(tw, Gv_GetVarX(*insptr++)); continue; - case CON_MULGLOBALVAR: + case CON_SHIFTVARVARL: insptr++; - aGameVars[*insptr].global *= insptr[1]; - insptr += 2; + tw = *insptr++; + Gv_ShiftVarL(tw, Gv_GetVarX(*insptr++)); + continue; + + case CON_SHIFTVARVARR: + insptr++; + tw = *insptr++; + Gv_ShiftVarR(tw, Gv_GetVarX(*insptr++)); continue; case CON_MULVARVAR: @@ -1397,18 +1924,7 @@ next_instruction: Gv_MulVar(tw, Gv_GetVarX(*insptr++)); continue; - case CON_DIVVAR: - insptr++; - if (EDUKE32_PREDICT_FALSE(insptr[1] == 0)) - { - CON_CRITICALERRPRINTF("divide by zero!\n"); - continue; - } - Gv_DivVar(*insptr, insptr[1]); - insptr += 2; - continue; - - case CON_DIVGLOBALVAR: + case CON_DIVVAR_GLOBAL: insptr++; if (EDUKE32_PREDICT_FALSE(insptr[1] == 0)) { @@ -1419,6 +1935,36 @@ next_instruction: insptr += 2; continue; + case CON_DIVVAR_PLAYER: + { + insptr++; + if (EDUKE32_PREDICT_FALSE(insptr[1] == 0)) + { + CON_CRITICALERRPRINTF("divide by zero!\n"); + continue; + } + auto &v = aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS - 1)]; + + v = tabledivide32(v, insptr[1]); + insptr += 2; + continue; + } + + case CON_DIVVAR_ACTOR: + { + insptr++; + if (EDUKE32_PREDICT_FALSE(insptr[1] == 0)) + { + CON_CRITICALERRPRINTF("divide by zero!\n"); + continue; + } + auto &v = aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES - 1)]; + + v = tabledivide32(v, insptr[1]); + insptr += 2; + continue; + } + case CON_DIVVARVAR: insptr++; { @@ -1442,22 +1988,26 @@ next_instruction: VM_CONDITIONAL(tw == *insptr); continue; - case CON_IFGLOBALVARE: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL(tw == *insptr); - continue; - case CON_IFVARN: insptr++; tw = Gv_GetVarX(*insptr++); VM_CONDITIONAL(tw != *insptr); continue; - case CON_IFGLOBALVARN: + case CON_IFVARVARE: insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL(tw != *insptr); + tw = Gv_GetVarX(*insptr++); + tw = (tw == Gv_GetVarX(*insptr++)); + insptr--; + VM_CONDITIONAL(tw); + continue; + + case CON_IFVARVARN: + insptr++; + tw = Gv_GetVarX(*insptr++); + tw = (tw != Gv_GetVarX(*insptr++)); + insptr--; + VM_CONDITIONAL(tw); continue; case CON_IFVARVARG: @@ -1548,166 +2098,6 @@ next_instruction: VM_CONDITIONAL(tw); continue; - case CON_IFGLOBALVARAND: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL(tw & *insptr); - continue; - - case CON_IFVARAND: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL(tw & *insptr); - continue; - - case CON_IFGLOBALVAROR: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL(tw | *insptr); - continue; - - case CON_IFVAROR: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL(tw | *insptr); - continue; - - case CON_IFGLOBALVARXOR: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL(tw ^ *insptr); - continue; - - case CON_IFVARXOR: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL(tw ^ *insptr); - continue; - - case CON_IFGLOBALVAREITHER: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL(tw || *insptr); - continue; - - case CON_IFVAREITHER: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL(tw || *insptr); - continue; - - case CON_IFGLOBALVARBOTH: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL(tw && *insptr); - continue; - - case CON_IFVARBOTH: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL(tw && *insptr); - continue; - - case CON_IFRND: - VM_CONDITIONAL(rnd(*(++insptr))); - continue; - - case CON_IFGLOBALVARG: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL(tw > *insptr); - continue; - - case CON_IFVARG: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL(tw > *insptr); - continue; - - case CON_IFGLOBALVARGE: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL(tw >= *insptr); - continue; - - case CON_IFVARGE: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL(tw >= *insptr); - continue; - - case CON_IFGLOBALVARL: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL(tw < *insptr); - continue; - - case CON_IFVARL: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL(tw < *insptr); - continue; - - case CON_IFGLOBALVARLE: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL(tw <= *insptr); - continue; - - case CON_IFVARLE: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL(tw <= *insptr); - continue; - - case CON_IFGLOBALVARA: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL((uint32_t)tw > (uint32_t)*insptr); - continue; - - case CON_IFVARA: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL((uint32_t)tw > (uint32_t)*insptr); - continue; - - case CON_IFGLOBALVARAE: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL((uint32_t)tw >= (uint32_t)*insptr); - continue; - - case CON_IFVARAE: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL((uint32_t)tw >= (uint32_t)*insptr); - continue; - - case CON_IFGLOBALVARB: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL((uint32_t)tw < (uint32_t)*insptr); - continue; - - case CON_IFVARB: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL((uint32_t)tw < (uint32_t)*insptr); - continue; - - case CON_IFGLOBALVARBE: - insptr++; - tw = aGameVars[*insptr++].global; - VM_CONDITIONAL((uint32_t)tw <= (uint32_t)*insptr); - continue; - - case CON_IFVARBE: - insptr++; - tw = Gv_GetVarX(*insptr++); - VM_CONDITIONAL((uint32_t)tw <= (uint32_t)*insptr); - continue; - case CON_IFVARVAREITHER: insptr++; tw = Gv_GetVarX(*insptr++); @@ -1736,18 +2126,6 @@ next_instruction: continue; } - case CON_WHILEGLOBALVARN: - { - auto const savedinsptr = &insptr[2]; - do - { - insptr = savedinsptr; - tw = (aGameVars[insptr[-1]].global != *insptr); - VM_CONDITIONAL(tw); - } while (tw); - continue; - } - case CON_WHILEVARVARN: { auto const savedinsptr = &insptr[2]; @@ -1774,18 +2152,6 @@ next_instruction: continue; } - case CON_WHILEGLOBALVARL: - { - auto const savedinsptr = &insptr[2]; - do - { - insptr = savedinsptr; - tw = (aGameVars[insptr[-1]].global < *insptr); - VM_CONDITIONAL(tw); - } while (tw); - continue; - } - case CON_WHILEVARVARL: { auto const savedinsptr = &insptr[2]; @@ -1800,96 +2166,71 @@ next_instruction: continue; } + case CON_SETVAR: + insptr++; + Gv_SetVarX(*insptr, insptr[1]); + insptr += 2; + continue; + + case CON_ADDVAR: + insptr++; + Gv_AddVar(*insptr, insptr[1]); + insptr += 2; + continue; + + case CON_SUBVAR: + insptr++; + Gv_SubVar(*insptr, insptr[1]); + insptr += 2; + continue; + + case CON_MULVAR: + insptr++; + Gv_MulVar(*insptr, insptr[1]); + insptr += 2; + continue; + + case CON_DIVVAR: + insptr++; + if (EDUKE32_PREDICT_FALSE(insptr[1] == 0)) + { + CON_CRITICALERRPRINTF("divide by zero!\n"); + continue; + } + Gv_DivVar(*insptr, insptr[1]); + insptr += 2; + continue; + case CON_ANDVAR: insptr++; Gv_AndVar(*insptr, insptr[1]); insptr += 2; continue; - case CON_ANDGLOBALVAR: - insptr++; - aGameVars[*insptr].global &= insptr[1]; - insptr += 2; - continue; - - case CON_ANDVARVAR: - insptr++; - tw = *insptr++; - Gv_AndVar(tw, Gv_GetVarX(*insptr++)); - continue; - case CON_XORVAR: insptr++; Gv_XorVar(*insptr, insptr[1]); insptr += 2; continue; - case CON_XORGLOBALVAR: - insptr++; - aGameVars[*insptr].global ^= insptr[1]; - insptr += 2; - continue; - - case CON_XORVARVAR: - insptr++; - tw = *insptr++; - Gv_XorVar(tw, Gv_GetVarX(*insptr++)); - continue; - case CON_ORVAR: insptr++; Gv_OrVar(*insptr, insptr[1]); insptr += 2; continue; - case CON_ORGLOBALVAR: - insptr++; - aGameVars[*insptr].global |= insptr[1]; - insptr += 2; - continue; - - case CON_ORVARVAR: - insptr++; - tw = *insptr++; - Gv_OrVar(tw, Gv_GetVarX(*insptr++)); - continue; - case CON_SHIFTVARL: insptr++; Gv_ShiftVarL(*insptr, insptr[1]); insptr += 2; continue; - case CON_SHIFTGLOBALVARL: - insptr++; - aGameVars[*insptr].global <<= insptr[1]; - insptr += 2; - continue; - - case CON_SHIFTVARVARL: - insptr++; - tw = *insptr++; - Gv_ShiftVarL(tw, Gv_GetVarX(*insptr++)); - continue; - case CON_SHIFTVARR: insptr++; Gv_ShiftVarR(*insptr, insptr[1]); insptr += 2; continue; - case CON_SHIFTGLOBALVARR: - insptr++; - aGameVars[*insptr].global >>= insptr[1]; - insptr += 2; - continue; - - case CON_SHIFTVARVARR: - insptr++; - tw = *insptr++; - Gv_ShiftVarR(tw, Gv_GetVarX(*insptr++)); - continue; - case CON_MODVAR: insptr++; if (EDUKE32_PREDICT_FALSE(insptr[1] == 0)) @@ -1902,18 +2243,6 @@ next_instruction: insptr += 2; continue; - case CON_MODGLOBALVAR: - insptr++; - if (EDUKE32_PREDICT_FALSE(insptr[1] == 0)) - { - CON_CRITICALERRPRINTF("mod by zero!\n"); - continue; - } - - aGameVars[*insptr].global %= insptr[1]; - insptr += 2; - continue; - case CON_MODVARVAR: insptr++; { @@ -1937,12 +2266,24 @@ next_instruction: insptr += 2; continue; - case CON_RANDGLOBALVAR: + case CON_RANDVAR_GLOBAL: insptr++; aGameVars[*insptr].global = mulscale16(krand(), insptr[1] + 1); insptr += 2; continue; + case CON_RANDVAR_PLAYER: + insptr++; + aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS-1)] = mulscale16(krand(), insptr[1] + 1); + insptr += 2; + continue; + + case CON_RANDVAR_ACTOR: + insptr++; + aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES-1)] = mulscale16(krand(), insptr[1] + 1); + insptr += 2; + continue; + case CON_RANDVARVAR: insptr++; tw = *insptr++;