- put the CON interpreter into a class to get rid of its global variables.

This commit is contained in:
Christoph Oelckers 2020-07-18 12:37:35 +02:00
parent 28965eefd5
commit e70115ff5c

View file

@ -63,15 +63,19 @@ enum playeraction_t {
// curse these global variables for parameter passing... struct ParseState
static int g_i, g_p; {
static int g_x; int g_i, g_p;
static int* g_t; int g_x;
static uint8_t killit_flag; int* g_t;
static spritetype* g_sp; uint8_t killit_flag;
static int* insptr; spritetype* g_sp;
int* insptr;
int parse(void);
void parseifelse(int condition);
};
int parse(void);
int furthestcanseepoint(int i, spritetype* ts, int* dax, int* day); int furthestcanseepoint(int i, spritetype* ts, int* dax, int* day);
bool ifsquished(int i, int p); bool ifsquished(int i, int p);
void fakebubbaspawn(int g_i, int g_p); void fakebubbaspawn(int g_i, int g_p);
@ -80,7 +84,8 @@ void destroyit(int g_i);
void mamaspawn(int g_i); void mamaspawn(int g_i);
void forceplayerangle(struct player_struct* p); void forceplayerangle(struct player_struct* p);
static bool killthesprite = false; bool killthesprite = false;
void addspritetodelete(int spnum) void addspritetodelete(int spnum)
{ {
killthesprite = true; killthesprite = true;
@ -93,7 +98,7 @@ void addspritetodelete(int spnum)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void VM_Execute(native_t loop); void VM_Execute(native_t loop);
void parseifelse(int condition) void ParseState::parseifelse(int condition)
{ {
if( condition ) if( condition )
{ {
@ -251,7 +256,7 @@ static bool ifcansee(int g_i, int g_p)
// int *it = 0x00589a04; // int *it = 0x00589a04;
int parse(void) int ParseState::parse(void)
{ {
int j, l, s; int j, l, s;
@ -1598,30 +1603,32 @@ void execute(int i,int p,int x)
if (actorinfo[sprite[i].picnum].scriptaddress == 0) return; if (actorinfo[sprite[i].picnum].scriptaddress == 0) return;
int done; int done;
spritetype* g_sp;
g_i = i; // Sprite ID ParseState s;
g_p = p; // Player ID s.g_i = i; // Sprite ID
g_x = x; // ?? s.g_p = p; // Player ID
g_sp = &sprite[g_i]; // Pointer to sprite structure s.g_x = x; // ??
g_t = &hittype[g_i].temp_data[0]; // Sprite's 'extra' data g_sp = s.g_sp = &sprite[i]; // Pointer to sprite structure
s.g_t = &hittype[i].temp_data[0]; // Sprite's 'extra' data
if (actorinfo[g_sp->picnum].scriptaddress == 0) return; if (actorinfo[g_sp->picnum].scriptaddress == 0) return;
insptr = &ScriptCode[4 + (actorinfo[g_sp->picnum].scriptaddress)]; s.insptr = &ScriptCode[4 + (actorinfo[g_sp->picnum].scriptaddress)];
killit_flag = 0; s.killit_flag = 0;
if(g_sp->sectnum < 0 || g_sp->sectnum >= MAXSECTORS) if(g_sp->sectnum < 0 || g_sp->sectnum >= MAXSECTORS)
{ {
if(badguy(g_sp)) if(badguy(g_sp))
ps[g_p].actors_killed++; ps[p].actors_killed++;
deletesprite(g_i); deletesprite(i);
return; return;
} }
if (g_t[4]) if (s.g_t[4])
{ {
// This code was utterly cryptic in the original source. // This code was utterly cryptic in the original source.
auto ptr = &ScriptCode[g_t[4]]; auto ptr = &ScriptCode[s.g_t[4]];
int numframes = ptr[1]; int numframes = ptr[1];
int increment = ptr[3]; int increment = ptr[3];
int delay = ptr[4]; int delay = ptr[4];
@ -1629,28 +1636,28 @@ void execute(int i,int p,int x)
g_sp->lotag += TICSPERFRAME; g_sp->lotag += TICSPERFRAME;
if (g_sp->lotag > delay) if (g_sp->lotag > delay)
{ {
g_t[2]++; s.g_t[2]++;
g_sp->lotag = 0; g_sp->lotag = 0;
g_t[3] += increment; s.g_t[3] += increment;
} }
if (abs(g_t[3]) >= abs(numframes * increment)) if (abs(s.g_t[3]) >= abs(numframes * increment))
g_t[3] = 0; s.g_t[3] = 0;
} }
do do
done = parse(); done = s.parse();
while( done == 0 ); while( done == 0 );
if(killit_flag == 1) if(s.killit_flag == 1)
{ {
// if player was set to squish, first stop that... // if player was set to squish, first stop that...
if(ps[g_p].actorsqu == g_i) if(ps[p].actorsqu == i)
ps[g_p].actorsqu = -1; ps[p].actorsqu = -1;
killthesprite = true; killthesprite = true;
} }
else else
{ {
fi.move(g_i, g_p, g_x); fi.move(i, p, x);
if (g_sp->statnum == STAT_ACTOR) if (g_sp->statnum == STAT_ACTOR)
{ {
@ -1661,14 +1668,14 @@ void execute(int i,int p,int x)
} }
else if (ud.respawn_items == 1 && (g_sp->cstat & 32768)) goto quit; else if (ud.respawn_items == 1 && (g_sp->cstat & 32768)) goto quit;
if (hittype[g_i].timetosleep > 1) if (hittype[i].timetosleep > 1)
hittype[g_i].timetosleep--; hittype[i].timetosleep--;
else if (hittype[g_i].timetosleep == 1) else if (hittype[i].timetosleep == 1)
changespritestat(g_i, STAT_ZOMBIEACTOR); changespritestat(i, STAT_ZOMBIEACTOR);
} }
else if (g_sp->statnum == STAT_STANDABLE) else if (g_sp->statnum == STAT_STANDABLE)
fi.checktimetosleep(g_i); fi.checktimetosleep(i);
} }
quit: quit:
if (killthesprite) deletesprite(i); if (killthesprite) deletesprite(i);
@ -1684,13 +1691,6 @@ quit:
void OnEvent(int iEventID, int p, int i, int x) void OnEvent(int iEventID, int p, int i, int x)
{ {
int og_i, og_p;
int og_x;
int* og_t;
spritetype* og_sp;
uint8_t okillit_flag;
int* oinsptr;
char done; char done;
if (iEventID >= MAXGAMEEVENTS) if (iEventID >= MAXGAMEEVENTS)
@ -1703,36 +1703,19 @@ void OnEvent(int iEventID, int p, int i, int x)
return; return;
} }
// save current values... ParseState s;
og_i = g_i; s.g_i = i; // current sprite ID
og_p = g_p; s.g_p = p; /// current player ID
og_x = g_x; s.g_x = x; // ?
og_sp = g_sp; s.g_sp = &sprite[i];
og_t = g_t; s.g_t = &hittype[i].temp_data[0];
okillit_flag = killit_flag;
oinsptr = insptr;
g_i = i; // current sprite ID s.insptr = &ScriptCode[apScriptGameEvent[iEventID]];
g_p = p; /// current player ID
g_x = x; // ?
g_sp = &sprite[g_i];
g_t = &hittype[g_i].temp_data[0];
insptr = &ScriptCode[apScriptGameEvent[iEventID]]; s.killit_flag = 0;
killit_flag = 0;
do do
done = parse(); done = s.parse();
while (done == 0); while (done == 0);
// restore old values...
g_i = og_i;
g_p = og_p;
g_x = og_x;
g_sp = og_sp;
g_t = og_t;
killit_flag = okillit_flag;
insptr = oinsptr;
} }