- Converted all action functions be directly callable by the VM (though they are not yet
usable). SVN r2154 (scripting)
This commit is contained in:
parent
7ea11cd169
commit
739e684549
108 changed files with 2827 additions and 1295 deletions
68
src/info.cpp
68
src/info.cpp
|
|
@ -51,79 +51,13 @@
|
|||
|
||||
extern void LoadActors ();
|
||||
|
||||
int CallDecorateAction(VMFrameStack *stack, VMValue *param, int numparam, VMReturn *ret, int numret)
|
||||
{
|
||||
assert(numparam == 6);
|
||||
actionf_p action = (actionf_p)param[5].a;
|
||||
action((AActor *)param[0].a, (AActor *)param[1].a, (FState *)param[2].a, param[3].i, (StateCallData *)param[4].a);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FState::SetAction(PSymbolActionFunction *func, bool setdefaultparams)
|
||||
{
|
||||
if (func != NULL)
|
||||
{
|
||||
// All generated functions use this code.
|
||||
static const VM_UBYTE codetemplate[] =
|
||||
{
|
||||
OP_PARAM, 0, REGT_POINTER, 0,
|
||||
OP_PARAM, 0, REGT_POINTER, 1,
|
||||
OP_PARAM, 0, REGT_POINTER, 2,
|
||||
OP_PARAM, 0, REGT_INT, 0,
|
||||
OP_PARAM, 0, REGT_POINTER, 3,
|
||||
OP_PARAM, 0, REGT_POINTER|REGT_KONST, 0,
|
||||
OP_CALL_K, 1, 6, 0,
|
||||
OP_RET, 0, REGT_NIL, 0
|
||||
};
|
||||
|
||||
// Find the CallDecorateAction function. If not found, create it and install it
|
||||
// in Actor.
|
||||
VMFunction *callfunc;
|
||||
PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("CallDecorateAction", false);
|
||||
if (sym == NULL)
|
||||
{
|
||||
PSymbolVMFunction *symfunc = new PSymbolVMFunction("CallDecorateAction");
|
||||
VMNativeFunction *calldec = new VMNativeFunction(CallDecorateAction);
|
||||
symfunc->Function = calldec;
|
||||
sym = symfunc;
|
||||
RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym);
|
||||
}
|
||||
assert(sym->SymbolType == SYM_VMFunction);
|
||||
assert(((PSymbolVMFunction *)sym)->Function != NULL);
|
||||
callfunc = ((PSymbolVMFunction *)sym)->Function;
|
||||
|
||||
// Create a function for this state.
|
||||
VMScriptFunction *vmfunc = new VMScriptFunction;
|
||||
vmfunc->Alloc(sizeof(codetemplate)/sizeof(VMOP), 0, 0, 0, 2);
|
||||
memcpy(vmfunc->Code, codetemplate, sizeof(codetemplate));
|
||||
FVoidObj *konsta = vmfunc->KonstA;
|
||||
VM_ATAG *atag = vmfunc->KonstATags();
|
||||
konsta[0].v = (void *)func->Function;
|
||||
konsta[1].o = callfunc;
|
||||
atag[0] = ATAG_GENERIC;
|
||||
atag[1] = ATAG_OBJECT;
|
||||
vmfunc->NumRegA = 4;
|
||||
vmfunc->NumRegD = 1;
|
||||
vmfunc->MaxParam = 6;
|
||||
vmfunc->NumArgs = 5;
|
||||
ActionFunc = vmfunc;
|
||||
|
||||
if (setdefaultparams) ParameterIndex = func->defaultparameterindex+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ActionFunc = NULL;
|
||||
if (setdefaultparams) ParameterIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool FState::CallAction(AActor *self, AActor *stateowner, StateCallData *statecall)
|
||||
{
|
||||
if (ActionFunc != NULL)
|
||||
{
|
||||
//ActionFunc(self, stateowner, this, ParameterIndex-1, statecall);
|
||||
VMFrameStack stack;
|
||||
VMValue params[5] = { self, stateowner, this, ParameterIndex - 1, VMValue(statecall, ATAG_STATE) };
|
||||
VMValue params[4] = { self, stateowner, VMValue(this, ATAG_STATE), statecall };
|
||||
stack.Call(ActionFunc, params, countof(params), NULL, 0, NULL);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue