From 068cfdc8fb0e31c9ff736ee426f1291d07115c11 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sun, 4 Oct 2015 23:49:49 +0800 Subject: Rewrite the function calling method and enable it in the VM. Yet another stupid commit. --- src/core/fncmodules.cpp | 29 +++++++++++------------------ src/core/fncmodules.hpp | 6 +++--- src/core/fncwrapper.cpp | 8 ++++---- src/core/fncwrapper.hpp | 2 +- src/core/vmrunner.cpp | 9 ++++++--- src/core/vmrunner.hpp | 4 +++- 6 files changed, 28 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/core/fncmodules.cpp b/src/core/fncmodules.cpp index 6ae2570..14d2f48 100644 --- a/src/core/fncmodules.cpp +++ b/src/core/fncmodules.cpp @@ -1,36 +1,29 @@ -#include #include "smmath.hpp" #include "bullet.hpp" #include "scriptshared.hpp" #include "vmrunner.hpp" -Idata randr(Idata a,...) +extern callStack callStk; +Idata randr() { Idata ret;ret.type=1; - va_list val; - va_start(val,a); extern blrScriptVM *vm; - ret.r()=vm->re->nextDouble(a.r(),va_arg(val,Idata).r()); - va_end(val); + ret.r()=(float)vm->re->nextDouble((float&)callStk.pop().r(),(float&)callStk.pop().r()); return ret; } -Idata randi(Idata a,...) +Idata randi() { Idata ret;ret.type=0; - va_list val; - va_start(val,a); extern blrScriptVM *vm; - ret.i()=vm->re->nextInt(a.i(),va_arg(val,Idata).i()); - va_end(val); + ret.i()=vm->re->nextInt(callStk.pop().i(),callStk.pop().i()); return ret; } -Idata createBullet(Idata x,...) +Idata createBullet() { - Idata y,bs,rad; - va_list val; - va_start(val,x); - y=va_arg(val,Idata); - bs=va_arg(val,Idata); - rad=va_arg(val,Idata); + Idata x,y,bs,rad; + x=callStk.pop(); + y=callStk.pop(); + bs=callStk.pop(); + rad=callStk.pop(); extern bulletManager *bmInstance; int i=bmInstance->allocBullet(); bmInstance->getHandle(i)->init(); diff --git a/src/core/fncmodules.hpp b/src/core/fncmodules.hpp index fe8eccf..b36eeb6 100644 --- a/src/core/fncmodules.hpp +++ b/src/core/fncmodules.hpp @@ -1,4 +1,4 @@ #include "scriptshared.hpp" -extern Idata randr(Idata a,...); -extern Idata randi(Idata a,...); -extern Idata createBullet(Idata x,...); +extern Idata randr(); +extern Idata randi(); +extern Idata createBullet(); diff --git a/src/core/fncwrapper.cpp b/src/core/fncwrapper.cpp index b1dd4d7..0927541 100644 --- a/src/core/fncwrapper.cpp +++ b/src/core/fncwrapper.cpp @@ -1,15 +1,15 @@ #include "vmrunner.hpp" #include "fncmodules.hpp" -extern blrScriptVM *vm; extern callStack callStk; +extern blrScriptVM *vm; extern unsigned getHash(const char *s); void callFnc(const char* fnc) { if(getHash(fnc)==getHash("randi")) - randi(callStk.pop(),callStk.pop()); + vm->vmSetRetVald(randi().i()); if(getHash(fnc)==getHash("randr")) - randr(callStk.pop(),callStk.pop()); + vm->vmSetRetValf(randr().r()); if(getHash(fnc)==getHash("createBullet")) - createBullet(callStk.pop(),callStk.pop(),callStk.pop(),callStk.pop()); + vm->vmSetRetValf(createBullet().i()); if(callStk.empty())callStk.clear(); } diff --git a/src/core/fncwrapper.hpp b/src/core/fncwrapper.hpp index 8d1c8b6..d8796b4 100644 --- a/src/core/fncwrapper.hpp +++ b/src/core/fncwrapper.hpp @@ -1 +1 @@ - +extern void callFnc(const char* fnc); diff --git a/src/core/vmrunner.cpp b/src/core/vmrunner.cpp index 4da775b..7cad11a 100644 --- a/src/core/vmrunner.cpp +++ b/src/core/vmrunner.cpp @@ -1,5 +1,6 @@ #include "vmrunner.hpp" #include "coreshared.hpp" +#include "fncwrapper.hpp" #include blrScriptVM *vm; callStack callStk; @@ -115,7 +116,7 @@ int blrScriptVM::loadLSBFromMemory(const char *ptr,DWORD size) return 0; } int blrScriptVM::getInstCount(){return pinst;} -void blrScriptVM::runFunction(const char *fncnym) +void blrScriptVM::vmRunFunction(const char *fncnym) { int nymhash=getHash(fncnym),cur=0;pinst=0; for(int i=0;i