- most 'if's.

# Conflicts:
#	source/games/duke/src/zz_gamedef.cpp
This commit is contained in:
Christoph Oelckers 2020-05-13 00:29:00 +02:00
parent 72514b0a1d
commit 79c7748e90
4 changed files with 88 additions and 385 deletions

View file

@ -626,11 +626,17 @@ void checkforkeyword()
static TArray<char> parsebuffer; // global so that the storage is persistent across calls.
int C_ParseCommand(int);
void parsecommand() // TRANSITIONAL
{
C_ParseCommand(0);
}
int parsecommand(int tw) // for now just run an externally parsed command.
{
const char* fn = fileSystem.GetFileFullName(g_currentSourceFile);
int i, j, k;
intptr_t* tempscrptr;
int tempscrptr;
uint8_t done, temp_ifelse_check;// , tw;
int temp_line_number;
int temp_current_file;
@ -1419,7 +1425,7 @@ int parsecommand(int tw) // for now just run an externally parsed command.
// prints the line number in the log file.
appendscriptvalue(line_number);
return 0;
#endif
case concmd_ifpinventory:
transnum();
case concmd_ifrnd:
@ -1478,8 +1484,11 @@ int parsecommand(int tw) // for now just run an externally parsed command.
case concmd_ifonboat:
case concmd_ifsizedown:
case concmd_ifplaybackon:
// case concmd_iffindnewspot: // RRDH
// case concmd_ifpupwind:
if (tw == 51)
if (tw == concmd_ifp)
{
j = 0;
do
@ -1491,22 +1500,16 @@ int parsecommand(int tw) // for now just run an externally parsed command.
appendscriptvalue(j);
}
tempscrptr = scriptptr;
scriptptr++; //Leave a spot for the fail location
do
{
j = keyword();
if (j == 20 || j == 39)
parsecommand();
} while (j == 20 || j == 39);
tempscrptr = scriptpos();
reservescriptspace(1); //Leave a spot for the fail location
skipcomments();
parsecommand();
*tempscrptr = (intptr_t)scriptptr;
setscriptvalue(tempscrptr, scriptpos());
checking_ifelse++;
return 0;
#if 0
case concmd_leftbrace:
num_squigilly_brackets++;
do

View file

@ -191,177 +191,6 @@ enum
#include "concmd.h"
enum ScriptKeywords_t
{
CON_ELSE, // 0
CON_ACTOR, // 1
CON_ADDAMMO, // 2
CON_IFRND, // 3
CON_ENDA, // 4
CON_IFCANSEE, // 5
CON_IFHITWEAPON, // 6
CON_ACTION, // 7
CON_IFPDISTL, // 8
CON_IFPDISTG, // 9
CON_DEFINELEVELNAME, // 10
CON_STRENGTH, // 11
CON_BREAK, // 12
CON_SHOOT, // 13
CON_PALFROM, // 14
CON_SOUND, // 15
CON_FALL, // 16
CON_STATE, // 17
CON_ENDS, // 18
CON_DEFINE, // 19
CON_COMMENT, // 20 deprecated
CON_IFAI, // 21
CON_KILLIT, // 22
CON_ADDWEAPON, // 23
CON_AI, // 24
CON_ADDPHEALTH, // 25
CON_IFDEAD, // 26
CON_IFSQUISHED, // 27
CON_SIZETO, // 28
CON_LEFTBRACE, // 29
CON_RIGHTBRACE, // 30
CON_SPAWN, // 31
CON_MOVE, // 32
CON_IFWASWEAPON, // 33
CON_IFACTION, // 34
CON_IFACTIONCOUNT, // 35
CON_RESETACTIONCOUNT, // 36
CON_DEBRIS, // 37
CON_PSTOMP, // 38
CON_BLOCKCOMMENT, // 39 deprecated
CON_CSTAT, // 40
CON_IFMOVE, // 41
CON_RESETPLAYER, // 42
CON_IFONWATER, // 43
CON_IFINWATER, // 44
CON_IFCANSHOOTTARGET, // 45
CON_IFCOUNT, // 46
CON_RESETCOUNT, // 47
CON_ADDINVENTORY, // 48
CON_IFACTORNOTSTAYPUT, // 49
CON_HITRADIUS, // 50
CON_IFP, // 51
CON_COUNT, // 52
CON_IFACTOR, // 53
CON_MUSIC, // 54
CON_INCLUDE, // 55
CON_IFSTRENGTH, // 56
CON_DEFINESOUND, // 57
CON_GUTS, // 58
CON_IFSPAWNEDBY, // 59
CON_GAMESTARTUP, // 60
CON_WACKPLAYER, // 61
CON_IFGAPZL, // 62
CON_IFHITSPACE, // 63
CON_IFOUTSIDE, // 64
CON_IFMULTIPLAYER, // 65
CON_OPERATE, // 66
CON_IFINSPACE, // 67
CON_DEBUG, // 68
CON_ENDOFGAME, // 69
CON_IFBULLETNEAR, // 70
CON_IFRESPAWN, // 71
CON_IFFLOORDISTL, // 72
CON_IFCEILINGDISTL, // 73
CON_SPRITEPAL, // 74
CON_IFPINVENTORY, // 75
CON_BETANAME, // 76
CON_CACTOR, // 77
CON_IFPHEALTHL, // 78
CON_DEFINEQUOTE, // 79
CON_QUOTE, // 80
CON_IFINOUTERSPACE, // 81
CON_IFNOTMOVING, // 82
CON_RESPAWNHITAG, // 83
CON_TIP, // 84
CON_IFSPRITEPAL, // 85
CON_MONEY, // 86
CON_SOUNDONCE, // 87
CON_ADDKILLS, // 88
CON_STOPSOUND, // 89
CON_IFAWAYFROMWALL, // 90
CON_IFCANSEETARGET, // 91
CON_GLOBALSOUND, // 92
CON_LOTSOFGLASS, // 93
CON_IFGOTWEAPONCE, // 94
CON_GETLASTPAL, // 95
CON_PKICK, // 96
CON_MIKESND, // 97
CON_USERACTOR, // 98
CON_SIZEAT, // 99
CON_ADDSTRENGTH, // 100
CON_CSTATOR, // 101
CON_MAIL, // 102
CON_PAPER, // 103
CON_TOSSWEAPON, // 104
CON_SLEEPTIME, // 105
CON_NULLOP, // 106
CON_DEFINEVOLUMENAME, // 107
CON_DEFINESKILLNAME, // 108
CON_IFNOSOUNDS, // 109
CON_CLIPDIST, // 110
CON_IFANGDIFFL, // 111
CON_IFNOCOVER, // 112
CON_IFHITTRUCK, // 113
CON_IFTIPCOW, // 114
CON_ISDRUNK, // 115
CON_ISEAT, // 116
CON_DESTROYIT, // 117
CON_LARRYBIRD, // 118
CON_STRAFELEFT, // 119
CON_STRAFERIGHT, // 120
CON_IFACTORHEALTHG, // 121
CON_IFACTORHEALTHL, // 122
CON_SLAPPLAYER, // 123
CON_IFPDRUNK, // 124
CON_TEARITUP, // 125
CON_SMACKBUBBA, // 126
CON_SOUNDTAGONCE, // 127
CON_SOUNDTAG, // 128
CON_IFSOUNDID, // 129
CON_IFSOUNDDIST, // 130
CON_IFONMUD, // 131
CON_IFCOOP, // 132
CON_IFMOTOFAST, // 133
CON_IFWIND, // 134
CON_SMACKSPRITE, // 135
CON_IFONMOTO, // 136
CON_IFONBOAT, // 137
CON_FAKEBUBBA, // 138
CON_MAMATRIGGER, // 139
CON_MAMASPAWN, // 140
CON_MAMAQUAKE, // 141
CON_MAMAEND, // 142
CON_NEWPIC, // 143
CON_GARYBANJO, // 144
CON_MOTOLOOPSND, // 145
CON_IFSIZEDOWN, // 146
CON_RNDMOVE, // 147
CON_GAMEVAR, // 148
CON_IFVARL, // 149
CON_IFVARG, // 150
CON_SETVARVAR, // 151
CON_SETVAR, // 152
CON_ADDVARVAR, // 153
CON_ADDVAR, // 154
CON_IFVARVARL, // 155
CON_IFVARVARG, // 156
CON_ADDLOGVAR, // 157
CON_ONEVENT, // 158
CON_ENDEVENT, // 159
CON_IFVARE, // 160
CON_IFVARVARE, // 161
CON_IFFINDNEWSPOT, // 162
CON_LEAVETRAX, // 163
CON_LEAVEDROPPINGS, // 164
CON_DEPLOYBIAS, // 165
CON_IFPUPWIND, // 166
CON_END
};
// KEEPINSYNC with the keyword list in lunatic/con_lang.lua
END_DUKE_NS

View file

@ -64,7 +64,8 @@ uint32_t g_scriptcrc;
char g_szBuf[1024];
static char g_szCurrentBlockName[256] = "(none)", g_szLastBlockName[256] = "NULL";
static int32_t g_checkingIfElse, g_lastKeyword = -1;
static int32_t g_lastKeyword = -1;
extern int checking_ifelse;
extern int parsing_state;
// The pointer to the start of the case table in a switch statement.
@ -73,7 +74,7 @@ static intptr_t *g_caseScriptPtr;
static int32_t g_labelsOnly = 0;
extern int num_squigilly_brackets;
static int32_t C_ParseCommand(int32_t loop);
int32_t C_ParseCommand(int32_t loop);
static int32_t C_SetScriptSize(int32_t size);
static intptr_t apScriptGameEventEnd[MAXEVENTS];
@ -802,8 +803,8 @@ static void C_Include(const char *confile)
int32_t temp_ScriptLineNumber = line_number;
line_number = 1;
int32_t temp_ifelse_check = g_checkingIfElse;
g_checkingIfElse = 0;
int32_t temp_ifelse_check = checking_ifelse;
checking_ifelse = 0;
textptr = mptr;
@ -814,7 +815,7 @@ static void C_Include(const char *confile)
g_totalLines += line_number;
line_number = temp_ScriptLineNumber;
g_checkingIfElse = temp_ifelse_check;
checking_ifelse = temp_ifelse_check;
textptr = origtptr;
@ -933,7 +934,7 @@ static inline void C_FinishBitOr(int32_t value)
int parsecommand(int tw); // for now just run an externally parsed command.
static int32_t C_ParseCommand(int32_t loop)
int32_t C_ParseCommand(int32_t loop)
{
int32_t i, j=0, k=0, tw;
TArray<char> buffer;
@ -997,6 +998,61 @@ static int32_t C_ParseCommand(int32_t loop)
case concmd_globalsound:
case concmd_soundonce:
case concmd_stopsound:
case concmd_ifrnd:
case concmd_ifpdistl:
case concmd_ifpdistg:
case concmd_ifai:
case concmd_ifwasweapon:
case concmd_ifaction:
case concmd_ifactioncount:
case concmd_ifmove:
case concmd_ifcount:
case concmd_ifactor:
case concmd_ifstrength:
case concmd_ifspawnedby:
case concmd_ifgapzl:
case concmd_iffloordistl:
case concmd_ifceilingdistl:
case concmd_ifphealthl:
case concmd_ifspritepal:
case concmd_ifgotweaponce:
case concmd_ifangdiffl:
case concmd_ifactorhealthg:
case concmd_ifactorhealthl:
case concmd_ifsoundid:
case concmd_ifsounddist:
case concmd_ifpinventory:
case concmd_ifonwater:
case concmd_ifinwater:
case concmd_ifactornotstayput:
case concmd_ifcansee:
case concmd_ifhitweapon:
case concmd_ifsquished:
case concmd_ifdead:
case concmd_ifcanshoottarget:
case concmd_ifp:
case concmd_ifhitspace:
case concmd_ifoutside:
case concmd_ifmultiplayer:
case concmd_ifinspace:
case concmd_ifbulletnear:
case concmd_ifrespawn:
case concmd_ifinouterspace:
case concmd_ifnotmoving:
case concmd_ifawayfromwall:
case concmd_ifcanseetarget:
case concmd_ifnosounds:
case concmd_ifnocover:
case concmd_ifhittruck:
case concmd_iftipcow:
case concmd_ifonmud:
case concmd_ifcoop:
case concmd_ifmotofast:
case concmd_ifwind:
case concmd_ifonmoto:
case concmd_ifonboat:
case concmd_ifsizedown:
case concmd_ifplaybackon:
parsecommand(g_lastKeyword);
continue;
@ -1112,13 +1168,13 @@ static int32_t C_ParseCommand(int32_t loop)
// if event has already been declared then store previous script location
apScriptEvents[j] = g_scriptEventOffset;
g_checkingIfElse = 0;
checking_ifelse = 0;
continue;
case concmd_else:
{
if (EDUKE32_PREDICT_FALSE(!g_checkingIfElse))
if (EDUKE32_PREDICT_FALSE(!checking_ifelse))
{
scriptptr--;
intptr_t *tempscrptr = scriptptr;
@ -1144,7 +1200,7 @@ static int32_t C_ParseCommand(int32_t loop)
intptr_t const lastScriptPtr = scriptptr - apScript - 1;
g_skipBranch = 0;
g_checkingIfElse--;
checking_ifelse--;
if (C_CheckMalformedBranch(lastScriptPtr))
continue;
@ -1296,166 +1352,11 @@ ifvar:
j = C_GetKeyword();
if (j == concmd_else)
g_checkingIfElse++;
checking_ifelse++;
continue;
}
case concmd_ifrnd:
case concmd_ifpdistl:
case concmd_ifpdistg:
case concmd_ifwasweapon:
case concmd_ifactioncount:
case concmd_ifcount:
case concmd_ifactor:
case concmd_ifstrength:
case concmd_ifspawnedby:
case concmd_ifgapzl:
case concmd_iffloordistl:
case concmd_ifceilingdistl:
case concmd_ifphealthl:
case concmd_ifspritepal:
case concmd_ifgotweaponce:
case concmd_ifangdiffl:
case concmd_ifactorhealthg:
case concmd_ifactorhealthl:
case concmd_ifsoundid:
case concmd_ifsounddist:
case concmd_ifai:
case concmd_ifaction:
case concmd_ifmove:
case concmd_ifp:
case concmd_ifpinventory:
{
intptr_t offset;
intptr_t lastScriptPtr = (scriptptr-&apScript[0]-1);
g_skipBranch = 0;
switch (tw)
{
case concmd_ifai:
C_GetNextValue(LABEL_AI);
break;
case concmd_ifaction:
C_GetNextValue(LABEL_ACTION);
break;
case concmd_ifmove:
C_GetNextValue(LABEL_MOVE | LABEL_DEFINE);
#if 0
if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(scriptptr-1) != 0) && (*(scriptptr-1) != 1)))
{
C_ReportError(-1);
*(scriptptr-1) = 0;
Printf("%s:%d: warning: expected a move, found a constant.\n",g_scriptFileName,line_number);
warningcount++;
}
#endif
break;
case concmd_ifpinventory:
C_GetNextValue(LABEL_DEFINE);
C_GetNextValue(LABEL_DEFINE);
break;
case concmd_ifp:
j = 0;
do
C_BitOrNextValue(&j);
while (C_GetKeyword() == -1);
C_FinishBitOr(j);
break;
default:
C_GetNextValue(LABEL_DEFINE);
break;
}
if (C_CheckMalformedBranch(lastScriptPtr))
continue;
intptr_t *tempscrptr = scriptptr;
offset = (unsigned)(tempscrptr-apScript);
scriptptr++; //Leave a spot for the fail location
C_ParseCommand(0);
if (C_CheckEmptyBranch(tw, lastScriptPtr))
continue;
tempscrptr = (intptr_t *)apScript+offset;
*tempscrptr = (intptr_t) scriptptr;
BITPTR_SET(tempscrptr-apScript);
j = C_GetKeyword();
if (j == concmd_else || j == concmd_leftbrace)
g_checkingIfElse++;
continue;
}
case concmd_ifonwater:
case concmd_ifinwater:
case concmd_ifactornotstayput:
case concmd_ifcansee:
case concmd_ifhitweapon:
case concmd_ifsquished:
case concmd_ifdead:
case concmd_ifcanshoottarget:
case concmd_ifhitspace:
case concmd_ifoutside:
case concmd_ifmultiplayer:
case concmd_ifinspace:
case concmd_ifbulletnear:
case concmd_ifrespawn:
case concmd_ifinouterspace:
case concmd_ifnotmoving:
case concmd_ifawayfromwall:
case concmd_ifcanseetarget:
case concmd_ifnosounds:
case concmd_ifnocover:
case concmd_ifhittruck:
case concmd_iftipcow:
case concmd_ifonmud:
case concmd_ifcoop:
case concmd_ifmotofast:
case concmd_ifwind:
case concmd_ifonmoto:
case concmd_ifonboat:
case concmd_ifsizedown:
case concmd_ifplaybackon:
// case concmd_iffindnewspot:
// case concmd_ifpupwind:
{
intptr_t offset;
intptr_t lastScriptPtr = (scriptptr-&apScript[0]-1);
g_skipBranch = 0;
if (C_CheckMalformedBranch(lastScriptPtr))
continue;
intptr_t *tempscrptr = scriptptr;
offset = (unsigned)(tempscrptr-apScript);
scriptptr++; //Leave a spot for the fail location
C_ParseCommand(0);
if (C_CheckEmptyBranch(tw, lastScriptPtr))
continue;
tempscrptr = (intptr_t *)apScript+offset;
*tempscrptr = (intptr_t) scriptptr;
BITPTR_SET(tempscrptr-apScript);
j = C_GetKeyword();
if (j == concmd_else || j == concmd_leftbrace)
g_checkingIfElse++;
continue;
}
case concmd_leftbrace:
if (EDUKE32_PREDICT_FALSE(!(parsing_state || parsing_actor || g_scriptEventOffset)))
@ -1484,8 +1385,8 @@ ifvar:
j = C_GetKeyword();
if (g_checkingIfElse && j != concmd_else)
g_checkingIfElse--;
if (checking_ifelse && j != concmd_else)
checking_ifelse--;
return 1;
}
@ -1497,8 +1398,8 @@ ifvar:
errorcount++;
}
if (g_checkingIfElse && j != concmd_else)
g_checkingIfElse--;
if (checking_ifelse && j != concmd_else)
checking_ifelse--;
return 1;

View file

@ -78,7 +78,7 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop);
#define VM_CONDITIONAL(xxx) \
{ \
if ((xxx) || ((insptr = (intptr_t *)*(insptr + 1)) && (((*insptr) & VM_INSTMASK) == concmd_else))) \
if ((xxx) || ((insptr = apScript + *(insptr + 1)) && (((*insptr) & VM_INSTMASK) == concmd_else))) \
{ \
insptr += 2; \
VM_Execute(0); \
@ -87,36 +87,6 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop);
void VM_ScriptInfo(intptr_t const *ptr, int range)
{
if (!apScript || (!vm.pSprite && !vm.pPlayer))
return;
if (ptr)
{
Printf("\n");
for (auto pScript = max<intptr_t const *>(ptr - (range >> 1), apScript),
p_end = min<intptr_t const *>(ptr + (range >> 1), apScript + g_scriptSize);
pScript < p_end;
++pScript)
{
Printf("%5d: %3d: ", (int32_t)(pScript - apScript), (int32_t)(pScript - ptr));
if (*pScript >> 12 && (*pScript & VM_INSTMASK) < CON_END)
Printf("%5d %s\n", (int32_t)(*pScript >> 12), VM_GetKeywordForID(*pScript & VM_INSTMASK));
else
Printf("%d\n", (int32_t)*pScript);
}
Printf("\n");
}
if (ptr == insptr)
{
if (vm.pUSprite)
Printf("current actor: %d (%d)\n", vm.spriteNum, vm.pUSprite->picnum);
Printf("g_errorLineNum: %d, g_tw: %d\n", g_errorLineNum, g_tw);
}
}
static void VM_DeleteSprite(int const spriteNum, int const playerNum)