aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2015-10-08 22:45:05 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2015-10-08 22:45:05 +0800
commitd3b7682aedf3083bbb3b6ed17b226b97d0171c15 (patch)
tree8d82016ddb867ab5f1b75557ded1dd17bb9661f1
parent0b049c3ea601a7ea6dc441db73af7a5bd75c834a (diff)
downloadbullet-lab-remix-d3b7682aedf3083bbb3b6ed17b226b97d0171c15.tar.xz
Add more VM functions.
The VM now seems complete... Next: the plugin system!
-rw-r--r--Readme9
-rw-r--r--src/core/fncmodules.cpp147
-rw-r--r--src/core/fncmodules.hpp17
-rw-r--r--src/core/fncwrapper.cpp21
-rw-r--r--src/core/vmrunner.cpp5
-rw-r--r--src/core/vmrunner.hpp2
6 files changed, 183 insertions, 18 deletions
diff --git a/Readme b/Readme
index cd70627..9161aca 100644
--- a/Readme
+++ b/Readme
@@ -1,13 +1,10 @@
This text is encoded in UTF-8.
This file is mainly about BulletLabRemix II. BulletLabRemix III is still under
-heavy development and can be found in the 'src' directory. The script virtual
-machine is still incomplete and is not enabled. The current version is extremely
-primitive and is only for testing/debugging purpose.
+heavy development and can be found in the 'src' directory. The implementation
+of the script virtual machine is mostly complete, although many functions are
+still unimplemented.
-There was a old testbed version with virtual machine enabled and 3D first-person
-view implemented. Please contact me or check chirs241097.xicp.net/BulletLabRemix
-/public/BLRScriptTestbed/ (likely to be offline) if you want to get a copy.
BulletLabRemix II readme
diff --git a/src/core/fncmodules.cpp b/src/core/fncmodules.cpp
index 767556e..2a169b1 100644
--- a/src/core/fncmodules.cpp
+++ b/src/core/fncmodules.cpp
@@ -1,3 +1,5 @@
+#include <cmath>
+#include <cstdlib>
#include "smmath.hpp"
#include "bullet.hpp"
#include "scriptshared.hpp"
@@ -6,7 +8,7 @@ Idata randr()
{
Idata ret;ret.type=1;
extern blrScriptVM *vm;
- ret.r()=(float)vm->re->nextDouble(callStk.pop().r(),callStk.pop().r());
+ ret.r()=vm->re->nextDouble(callStk.pop().r(),callStk.pop().r());
return ret;
}
Idata randi()
@@ -36,3 +38,146 @@ Idata createBullet()
Idata ret;ret.type=0;ret.i()=i;
return ret;
}
+void setBulletPropf()
+{
+ int hnd,pid;double data;
+ hnd=callStk.pop().i();
+ pid=callStk.pop().i();
+ data=callStk.pop().r();
+ extern bulletManager *bmInstance;
+ if(!bmInstance->getHandle(hnd))return;
+ if(!bmInstance->getHandle(hnd)->exist)return;
+ switch(pid)
+ {
+ case 1://coord x
+ bmInstance->getHandle(hnd)->pos.x=data;
+ break;
+ case 2://coord y
+ bmInstance->getHandle(hnd)->pos.y=data;
+ break;
+ case 8://velocity x
+ bmInstance->getHandle(hnd)->vel.x=data;
+ break;
+ case 9://velocity y
+ bmInstance->getHandle(hnd)->vel.y=data;
+ break;
+ }
+}
+void setBulletPropi()
+{
+ int hnd,pid,data;
+ hnd=callStk.pop().i();
+ pid=callStk.pop().i();
+ data=callStk.pop().i();
+ extern bulletManager *bmInstance;
+ if(!bmInstance->getHandle(hnd))return;
+ if(!bmInstance->getHandle(hnd)->exist)return;
+ switch(pid)
+ {
+ case 3://base color
+ bmInstance->getHandle(hnd)->basecolor=(TColors)data;
+ break;
+ case 4://color red
+ bmInstance->getHandle(hnd)->rendercolor=SETR(bmInstance->getHandle(hnd)->rendercolor,data);
+ break;
+ case 5://color green
+ bmInstance->getHandle(hnd)->rendercolor=SETG(bmInstance->getHandle(hnd)->rendercolor,data);
+ break;
+ case 6://color blue
+ bmInstance->getHandle(hnd)->rendercolor=SETB(bmInstance->getHandle(hnd)->rendercolor,data);
+ break;
+ case 7://color alpha
+ bmInstance->getHandle(hnd)->rendercolor=SETA(bmInstance->getHandle(hnd)->rendercolor,data);
+ break;
+ }
+}
+Idata vmsin()
+{
+ Idata ret;ret.type=1;
+ ret.r()=sin(callStk.pop().r());
+ return ret;
+}
+Idata vmcos()
+{
+ Idata ret;ret.type=1;
+ ret.r()=cos(callStk.pop().r());
+ return ret;
+}
+Idata vmtan()
+{
+ Idata ret;ret.type=1;
+ ret.r()=tan(callStk.pop().r());
+ return ret;
+}
+Idata vmsqrt()
+{
+ Idata ret;ret.type=1;
+ ret.r()=sqrt(callStk.pop().r());
+ return ret;
+}
+Idata vmabsf()
+{
+ Idata ret;ret.type=1;
+ ret.r()=fabs(callStk.pop().r());
+ return ret;
+}
+Idata vmabsd()
+{
+ Idata ret;ret.type=0;
+ ret.r()=abs(callStk.pop().i());
+ return ret;
+}
+Idata vmasin()
+{
+ Idata ret;ret.type=1;
+ ret.r()=asin(callStk.pop().r());
+ return ret;
+}
+Idata vmacos()
+{
+ Idata ret;ret.type=1;
+ ret.r()=acos(callStk.pop().r());
+ return ret;
+}
+Idata vmatan()
+{
+ Idata ret;ret.type=1;
+ ret.r()=atan(callStk.pop().r());
+ return ret;
+}
+Idata vmatan2()
+{
+ Idata ret;ret.type=1;
+ ret.r()=atan2(callStk.pop().r(),callStk.pop().r());
+ return ret;
+}
+Idata vmlog()
+{
+ Idata ret;ret.type=1;
+ ret.r()=log(callStk.pop().r());
+ return ret;
+}
+Idata vmceil()
+{
+ Idata ret;ret.type=1;
+ ret.r()=ceil(callStk.pop().r());
+ return ret;
+}
+Idata vmfloor()
+{
+ Idata ret;ret.type=1;
+ ret.r()=floor(callStk.pop().r());
+ return ret;
+}
+Idata vmtrunc()
+{
+ Idata ret;ret.type=1;
+ ret.r()=trunc(callStk.pop().r());
+ return ret;
+}
+Idata vmround()
+{
+ Idata ret;ret.type=1;
+ ret.r()=round(callStk.pop().r());
+ return ret;
+}
diff --git a/src/core/fncmodules.hpp b/src/core/fncmodules.hpp
index b36eeb6..978843e 100644
--- a/src/core/fncmodules.hpp
+++ b/src/core/fncmodules.hpp
@@ -2,3 +2,20 @@
extern Idata randr();
extern Idata randi();
extern Idata createBullet();
+extern void setBulletPropf();
+extern void setBulletPropi();
+extern Idata vmsin();
+extern Idata vmcos();
+extern Idata vmtan();
+extern Idata vmsqrt();
+extern Idata vmabsf();
+extern Idata vmabsd();
+extern Idata vmasin();
+extern Idata vmacos();
+extern Idata vmatan();
+extern Idata vmatan2();
+extern Idata vmlog();
+extern Idata vmceil();
+extern Idata vmfloor();
+extern Idata vmtrunc();
+extern Idata vmround();
diff --git a/src/core/fncwrapper.cpp b/src/core/fncwrapper.cpp
index 8f08bae..c19f313 100644
--- a/src/core/fncwrapper.cpp
+++ b/src/core/fncwrapper.cpp
@@ -1,13 +1,22 @@
#include "vmrunner.hpp"
#include "fncmodules.hpp"
+#define bindFuncr(fs,fn) if(getHash(fnc)==getHash(fs))vm->vmSetRetValf(fn().r())
+#define bindFunci(fs,fn) if(getHash(fnc)==getHash(fs))vm->vmSetRetVald(fn().i())
+#define bindFuncv(fs,fn) if(getHash(fnc)==getHash(fs))fn()
extern unsigned getHash(const char *s);
void callFnc(const char* fnc)
{
- if(getHash(fnc)==getHash("randi"))
- vm->vmSetRetVald(randi().i());
- if(getHash(fnc)==getHash("randr"))
- vm->vmSetRetValf(randr().r());
- if(getHash(fnc)==getHash("createBullet"))
- vm->vmSetRetValf(createBullet().i());
+ bindFunci("randi",randi);bindFuncr("randr",randr);
+ bindFunci("createBullet",createBullet);
+ bindFuncv("setBulletPropf",setBulletPropf);
+ bindFuncv("setBulletPropi",setBulletPropi);
+ bindFuncr("sin",vmsin);bindFuncr("cos",vmcos);
+ bindFuncr("tan",vmtan);bindFuncr("sqrt",vmsqrt);
+ bindFuncr("absf",vmabsf);bindFunci("absd",vmabsd);
+ bindFuncr("asin",vmasin);bindFuncr("acos",vmacos);
+ bindFuncr("atan",vmatan);bindFuncr("atan2",vmatan2);
+ bindFuncr("log",vmlog);bindFuncr("ceil",vmceil);
+ bindFuncr("floor",vmfloor);bindFuncr("trunc",vmtrunc);
+ bindFuncr("round",vmround);
if(callStk.empty())callStk.clear();
}
diff --git a/src/core/vmrunner.cpp b/src/core/vmrunner.cpp
index 9df68a0..5569b1c 100644
--- a/src/core/vmrunner.cpp
+++ b/src/core/vmrunner.cpp
@@ -127,7 +127,6 @@ void blrScriptVM::vmRunFunction(const char *fncnym)
int jmp=0;++pinst;
//printf("@offset %d, instId 0x%x\n",cur,inst[cur].id);
rr[100].r()=0.01667;
- //printf("r00: %f, r01: %f\n",rr[0].r(),rr[1].r());
switch(inst[cur].id)
{
case 0x00:
@@ -141,8 +140,6 @@ void blrScriptVM::vmRunFunction(const char *fncnym)
break;
case 0x02:
callFnc(inst[cur].para1.fnc);
- //callStk.clear();
- //printf("stubbed call %s\n",inst[cur].para1.fnc);
break;
case 0x03:
fetchData(inst[cur].para1,true)=fetchData(inst[cur].para2);
@@ -277,7 +274,7 @@ void blrScriptVM::vmRunFunction(const char *fncnym)
if(!jmp)++cur;
}
}
-void blrScriptVM::vmSetRetValf(float v){rr[102].r()=v;}
+void blrScriptVM::vmSetRetValf(double v){rr[102].r()=v;}
void blrScriptVM::vmSetRetVald(int v){ir[100].i()=v;}
void blrScriptVM::vmInit(unsigned int seed)
{
diff --git a/src/core/vmrunner.hpp b/src/core/vmrunner.hpp
index d0e9af5..502ac4a 100644
--- a/src/core/vmrunner.hpp
+++ b/src/core/vmrunner.hpp
@@ -41,7 +41,7 @@ public:
int loadLSBFromMemory(const char* ptr,DWORD size);
int getInstCount();
void vmRunFunction(const char *fncnym);
- void vmSetRetValf(float v);
+ void vmSetRetValf(double v);
void vmSetRetVald(int v);
void vmInit(unsigned int seed);
void vmDeinit();