- State code now properly calls action functions and has a RET instruction. As expected,

running with the checked VM can be quite slow, since it has asserts everywhere. Some other
  fixes were needed before the code actually worked:
  - A_CallSpecial needs to have its arguments cast to ints.
  - Some functions that set pnum/paramnum directly did not decrement it by 1. This also applies
    to A_Jump, though it just uses the value of paramnum instead of changing it.
  - Renamed pnum in the PARAM macros to paramnum, since pnum is already used in a few other
    places for something different, so this makes searching for it easier.
  This has not been tested especially thoroughly, but a first glance seems to indicate success.

SVN r2163 (scripting)
This commit is contained in:
Randy Heit 2010-02-14 19:59:21 +00:00
commit 6f1bf257e9
9 changed files with 130 additions and 108 deletions

View file

@ -452,11 +452,12 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Jump)
PARAM_ACTION_PROLOGUE;
PARAM_INT_OPT(maxchance) { maxchance = 256; }
int count = numparam - pnum;
paramnum++; // Increment paramnum to point at the first jump target
int count = numparam - paramnum;
if (count > 0 && (maxchance >= 256 || pr_cajump() < maxchance))
{
int jumpnum = (count == 1 ? 0 : (pr_cajump() % count));
PARAM_STATE_AT(pnum + jumpnum, jumpto);
PARAM_STATE_AT(paramnum + jumpnum, jumpto);
ACTION_JUMP(jumpto);
}
ACTION_SET_RESULT(false); // Jumps should never set the result for inventory state chains!
@ -529,7 +530,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfCloser)
//==========================================================================
void DoJumpIfInventory(AActor *owner, AActor *self, StateCallData *statecall, FState *callingstate, VMValue *param, int numparam)
{
int pnum = NAP;
int paramnum = NAP-1;
PARAM_CLASS (itemtype, AInventory);
PARAM_INT (itemamount);
PARAM_STATE (label);
@ -1314,7 +1315,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomRailgun)
static void DoGiveInventory(AActor *receiver, StateCallData *statecall, VM_ARGS)
{
int pnum = NAP;
int paramnum = NAP-1;
PARAM_CLASS (mi, AInventory);
PARAM_INT_OPT (amount) { amount = 1; }
@ -1381,7 +1382,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveToTarget)
void DoTakeInventory(AActor *receiver, StateCallData *statecall, VM_ARGS)
{
int pnum = NAP;
int paramnum = NAP-1;
PARAM_CLASS (itemtype, AInventory);
PARAM_INT_OPT (amount) { amount = 0; }