ref: 4ec7962877652b2ea56a9ae50ee8ff1921e06290
parent: 5e51c2032749df58fadc8182da345acb18b19885
author: Simon Howard <[email protected]>
date: Fri Jan 5 14:44:38 EST 2018
hexen: Eliminate most direct usage of PCodePtr. ReadCodeImmediate() will be a safer and simpler way to read additional arguments from the code buffer.
--- a/src/hexen/p_acs.c
+++ b/src/hexen/p_acs.c
@@ -888,7 +888,7 @@
{
int result;
// TODO: Add bounds checking
- result = *PCodePtr;
+ result = LONG(*PCodePtr);
++PCodePtr;
return result;
}
@@ -989,8 +989,7 @@
static int CmdPushNumber(void)
{
- Push(LONG(*PCodePtr));
- ++PCodePtr;
+ Push(ReadCodeImmediate());
return SCRIPT_CONTINUE;
}
@@ -998,8 +997,7 @@
{
int special;
- special = LONG(*PCodePtr);
- ++PCodePtr;
+ special = ReadCodeImmediate();
SpecArgs[0] = Pop();
P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
ACScript->side, ACScript->activator);
@@ -1010,8 +1008,7 @@
{
int special;
- special = LONG(*PCodePtr);
- ++PCodePtr;
+ special = ReadCodeImmediate();
SpecArgs[1] = Pop();
SpecArgs[0] = Pop();
P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
@@ -1023,8 +1020,7 @@
{
int special;
- special = LONG(*PCodePtr);
- ++PCodePtr;
+ special = ReadCodeImmediate();
SpecArgs[2] = Pop();
SpecArgs[1] = Pop();
SpecArgs[0] = Pop();
@@ -1037,8 +1033,7 @@
{
int special;
- special = LONG(*PCodePtr);
- ++PCodePtr;
+ special = ReadCodeImmediate();
SpecArgs[3] = Pop();
SpecArgs[2] = Pop();
SpecArgs[1] = Pop();
@@ -1052,8 +1047,7 @@
{
int special;
- special = LONG(*PCodePtr);
- ++PCodePtr;
+ special = ReadCodeImmediate();
SpecArgs[4] = Pop();
SpecArgs[3] = Pop();
SpecArgs[2] = Pop();
@@ -1068,10 +1062,8 @@
{
int special;
- special = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[0] = LONG(*PCodePtr);
- ++PCodePtr;
+ special = ReadCodeImmediate();
+ SpecArgs[0] = ReadCodeImmediate();
P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
ACScript->side, ACScript->activator);
return SCRIPT_CONTINUE;
@@ -1081,12 +1073,9 @@
{
int special;
- special = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[0] = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[1] = LONG(*PCodePtr);
- ++PCodePtr;
+ special = ReadCodeImmediate();
+ SpecArgs[0] = ReadCodeImmediate();
+ SpecArgs[1] = ReadCodeImmediate();
P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
ACScript->side, ACScript->activator);
return SCRIPT_CONTINUE;
@@ -1096,14 +1085,10 @@
{
int special;
- special = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[0] = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[1] = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[2] = LONG(*PCodePtr);
- ++PCodePtr;
+ special = ReadCodeImmediate();
+ SpecArgs[0] = ReadCodeImmediate();
+ SpecArgs[1] = ReadCodeImmediate();
+ SpecArgs[2] = ReadCodeImmediate();
P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
ACScript->side, ACScript->activator);
return SCRIPT_CONTINUE;
@@ -1113,16 +1098,11 @@
{
int special;
- special = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[0] = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[1] = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[2] = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[3] = LONG(*PCodePtr);
- ++PCodePtr;
+ special = ReadCodeImmediate();
+ SpecArgs[0] = ReadCodeImmediate();
+ SpecArgs[1] = ReadCodeImmediate();
+ SpecArgs[2] = ReadCodeImmediate();
+ SpecArgs[3] = ReadCodeImmediate();
P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
ACScript->side, ACScript->activator);
return SCRIPT_CONTINUE;
@@ -1132,18 +1112,12 @@
{
int special;
- special = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[0] = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[1] = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[2] = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[3] = LONG(*PCodePtr);
- ++PCodePtr;
- SpecArgs[4] = LONG(*PCodePtr);
- ++PCodePtr;
+ special = ReadCodeImmediate();
+ SpecArgs[0] = ReadCodeImmediate();
+ SpecArgs[1] = ReadCodeImmediate();
+ SpecArgs[2] = ReadCodeImmediate();
+ SpecArgs[3] = ReadCodeImmediate();
+ SpecArgs[4] = ReadCodeImmediate();
P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
ACScript->side, ACScript->activator);
return SCRIPT_CONTINUE;
@@ -1400,20 +1374,20 @@
static int CmdGoto(void)
{
- PCodePtr = (int *) (ActionCodeBase + LONG(*PCodePtr));
+ PCodePtr = (int *) (ActionCodeBase + ReadCodeImmediate());
return SCRIPT_CONTINUE;
}
static int CmdIfGoto(void)
{
+ int offset;
+
+ offset = ReadCodeImmediate();
+
if (Pop() != 0)
{
- PCodePtr = (int *) (ActionCodeBase + LONG(*PCodePtr));
+ PCodePtr = (int *) (ActionCodeBase + offset);
}
- else
- {
- ++PCodePtr;
- }
return SCRIPT_CONTINUE;
}
@@ -1431,8 +1405,7 @@
static int CmdDelayDirect(void)
{
- ACScript->delayCount = LONG(*PCodePtr);
- ++PCodePtr;
+ ACScript->delayCount = ReadCodeImmediate();
return SCRIPT_STOP;
}
@@ -1452,10 +1425,8 @@
int low;
int high;
- low = LONG(*PCodePtr);
- ++PCodePtr;
- high = LONG(*PCodePtr);
- ++PCodePtr;
+ low = ReadCodeImmediate();
+ high = ReadCodeImmediate();
Push(low + (P_Random() % (high - low + 1)));
return SCRIPT_CONTINUE;
}
@@ -1473,10 +1444,8 @@
{
int type;
- type = LONG(*PCodePtr);
- ++PCodePtr;
- ThingCount(type, LONG(*PCodePtr));
- ++PCodePtr;
+ type = ReadCodeImmediate();
+ ThingCount(type, ReadCodeImmediate());
return SCRIPT_CONTINUE;
}
@@ -1546,8 +1515,7 @@
static int CmdTagWaitDirect(void)
{
- ACSInfo[ACScript->infoIndex].waitValue = LONG(*PCodePtr);
- ++PCodePtr;
+ ACSInfo[ACScript->infoIndex].waitValue = ReadCodeImmediate();
ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORTAG;
return SCRIPT_STOP;
}
@@ -1561,8 +1529,7 @@
static int CmdPolyWaitDirect(void)
{
- ACSInfo[ACScript->infoIndex].waitValue = LONG(*PCodePtr);
- ++PCodePtr;
+ ACSInfo[ACScript->infoIndex].waitValue = ReadCodeImmediate();
ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORPOLY;
return SCRIPT_STOP;
}
@@ -1589,10 +1556,8 @@
int flat;
int sectorIndex;
- tag = LONG(*PCodePtr);
- ++PCodePtr;
- flat = R_FlatNumForName(StringLookup(LONG(*PCodePtr)));
- ++PCodePtr;
+ tag = ReadCodeImmediate();
+ flat = R_FlatNumForName(StringLookup(ReadCodeImmediate()));
sectorIndex = -1;
while ((sectorIndex = P_FindSectorFromTag(tag, sectorIndex)) >= 0)
{
@@ -1623,10 +1588,8 @@
int flat;
int sectorIndex;
- tag = LONG(*PCodePtr);
- ++PCodePtr;
- flat = R_FlatNumForName(StringLookup(LONG(*PCodePtr)));
- ++PCodePtr;
+ tag = ReadCodeImmediate();
+ flat = R_FlatNumForName(StringLookup(ReadCodeImmediate()));
sectorIndex = -1;
while ((sectorIndex = P_FindSectorFromTag(tag, sectorIndex)) >= 0)
{
@@ -1703,14 +1666,14 @@
static int CmdIfNotGoto(void)
{
- if (Pop() != 0)
+ int offset;
+
+ offset = ReadCodeImmediate();
+
+ if (Pop() == 0)
{
- ++PCodePtr;
+ PCodePtr = (int *) (ActionCodeBase + offset);
}
- else
- {
- PCodePtr = (int *) (ActionCodeBase + LONG(*PCodePtr));
- }
return SCRIPT_CONTINUE;
}
@@ -1729,8 +1692,7 @@
static int CmdScriptWaitDirect(void)
{
- ACSInfo[ACScript->infoIndex].waitValue = LONG(*PCodePtr);
- ++PCodePtr;
+ ACSInfo[ACScript->infoIndex].waitValue = ReadCodeImmediate();
ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORSCRIPT;
return SCRIPT_STOP;
}
@@ -1747,18 +1709,15 @@
static int CmdCaseGoto(void)
{
int value;
+ int offset;
- value = LONG(*PCodePtr);
- ++PCodePtr;
+ value = ReadCodeImmediate();
+ offset = ReadCodeImmediate();
if (Top() == value)
{
- PCodePtr = (int *) (ActionCodeBase + LONG(*PCodePtr));
+ PCodePtr = (int *) (ActionCodeBase + offset);
Drop();
- }
- else
- {
- ++PCodePtr;
}
return SCRIPT_CONTINUE;