aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/bullet.cpp3
-rw-r--r--src/core/bullet.hpp1
-rw-r--r--src/core/fncmodules.cpp48
-rw-r--r--src/core/fncmodules.hpp5
-rw-r--r--src/core/fncwrapper.cpp15
-rw-r--r--src/core/vmrunner.cpp10
-rw-r--r--src/core/vmrunner.hpp5
7 files changed, 80 insertions, 7 deletions
diff --git a/src/core/bullet.cpp b/src/core/bullet.cpp
index 175bae4..f7bcc90 100644
--- a/src/core/bullet.cpp
+++ b/src/core/bullet.cpp
@@ -17,7 +17,7 @@ void bulletBase::update()
void bulletBase::render()
{
//test view mode
- bmInstance->getBulEntity2D(basecolor)->setColor(0xC0FFFFFF);
+ bmInstance->getBulEntity2D(basecolor)->setColor(rendercolor);
bmInstance->getBulEntity2D(basecolor)->render(pos.x,pos.y,0,renderscale*0.6);
}
bulletBase::~bulletBase(){}
@@ -81,6 +81,7 @@ void bulletManager::updateBullet()
x->pos=smvec2d(400,300);
x->vel=smvec2d(rand()%100-50,rand()%100-50);
x->vel.normalize();
+ x->rendercolor=0xC0FFFFFF;
b=0;
}
for(int i=0;i<alloced;++i)
diff --git a/src/core/bullet.hpp b/src/core/bullet.hpp
index 5f4fe2f..b240e81 100644
--- a/src/core/bullet.hpp
+++ b/src/core/bullet.hpp
@@ -18,6 +18,7 @@ public:
int attrd[8];
float attrf[8];
TColors basecolor;
+ DWORD rendercolor;
virtual void init(...);
virtual void update();
virtual void render();
diff --git a/src/core/fncmodules.cpp b/src/core/fncmodules.cpp
index 8d1c8b6..6ae2570 100644
--- a/src/core/fncmodules.cpp
+++ b/src/core/fncmodules.cpp
@@ -1 +1,47 @@
-
+#include <cstdarg>
+#include "smmath.hpp"
+#include "bullet.hpp"
+#include "scriptshared.hpp"
+#include "vmrunner.hpp"
+Idata randr(Idata a,...)
+{
+ 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);
+ return ret;
+}
+Idata randi(Idata a,...)
+{
+ 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);
+ return ret;
+}
+Idata createBullet(Idata x,...)
+{
+ 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);
+ extern bulletManager *bmInstance;
+ int i=bmInstance->allocBullet<bulletBase>();
+ bmInstance->getHandle(i)->init();
+ bmInstance->getHandle(i)->pos.x=x.r();
+ bmInstance->getHandle(i)->pos.y=y.r();
+ bmInstance->getHandle(i)->vel=bs.r()*smvec2d(cos(rad.r()),sin(rad.r()));
+ bmInstance->getHandle(i)->acc=smvec2d(0,0);
+ bmInstance->getHandle(i)->basecolor=blue;
+ bmInstance->getHandle(i)->rendercolor=0xC0FFFFFF;
+ bmInstance->getHandle(i)->collrange=4;
+ bmInstance->getHandle(i)->scollrange=16;
+ Idata ret;ret.type=0;ret.i()=i;
+ return ret;
+}
diff --git a/src/core/fncmodules.hpp b/src/core/fncmodules.hpp
index 8d1c8b6..fe8eccf 100644
--- a/src/core/fncmodules.hpp
+++ b/src/core/fncmodules.hpp
@@ -1 +1,4 @@
-
+#include "scriptshared.hpp"
+extern Idata randr(Idata a,...);
+extern Idata randi(Idata a,...);
+extern Idata createBullet(Idata x,...);
diff --git a/src/core/fncwrapper.cpp b/src/core/fncwrapper.cpp
new file mode 100644
index 0000000..b1dd4d7
--- /dev/null
+++ b/src/core/fncwrapper.cpp
@@ -0,0 +1,15 @@
+#include "vmrunner.hpp"
+#include "fncmodules.hpp"
+extern blrScriptVM *vm;
+extern callStack<Idata> callStk;
+extern unsigned getHash(const char *s);
+void callFnc(const char* fnc)
+{
+ if(getHash(fnc)==getHash("randi"))
+ randi(callStk.pop(),callStk.pop());
+ if(getHash(fnc)==getHash("randr"))
+ randr(callStk.pop(),callStk.pop());
+ if(getHash(fnc)==getHash("createBullet"))
+ createBullet(callStk.pop(),callStk.pop(),callStk.pop(),callStk.pop());
+ if(callStk.empty())callStk.clear();
+}
diff --git a/src/core/vmrunner.cpp b/src/core/vmrunner.cpp
index 1942d74..4da775b 100644
--- a/src/core/vmrunner.cpp
+++ b/src/core/vmrunner.cpp
@@ -1,6 +1,8 @@
#include "vmrunner.hpp"
#include "coreshared.hpp"
#include <cstdlib>
+blrScriptVM *vm;
+callStack<Idata> callStk;
unsigned getHash(const char *s)
{
unsigned r=5381;char c;
@@ -272,9 +274,15 @@ void blrScriptVM::runFunction(const char *fncnym)
if(!jmp)++cur;
}
}
-void blrScriptVM::vmInit()
+void blrScriptVM::vmInit(unsigned int seed)
{
+ for(int i=0;i<103;++i)rr[i].type=1;
+ for(int i=0;i<101;++i)ir[i].type=0;
+ for(int i=0;i<10000;++i)ra[i].type=1,ia[i].type=0;
+ re=new smRandomEngine;
+ re->setSeed(seed);
}
void blrScriptVM::vmDeinit()
{
+ delete re;
}
diff --git a/src/core/vmrunner.hpp b/src/core/vmrunner.hpp
index 60bc2ce..d9d9a59 100644
--- a/src/core/vmrunner.hpp
+++ b/src/core/vmrunner.hpp
@@ -21,12 +21,10 @@ public:
memb front(){return data[l];}
memb back(){return data[r];}
};
-callStack<Idata> callStk;
typedef struct _fncEntry{int hash,pos;}fncEntry;
class blrScriptVM
{
private:
- smRandomEngine* re;
Idata ir[101],ia[10000];
Idata rr[103],ra[10000];
SInst inst[65537];
@@ -38,11 +36,12 @@ private:
int mgetc();
Idata& fetchData(SPara para,bool forcerw=false);
public:
+ smRandomEngine* re;
blrScriptVM(){ic=fncnt=pinst=0;}
int loadLSBFromMemory(const char* ptr,DWORD size);
int getInstCount();
void runFunction(const char *fncnym);
- void vmInit();
+ void vmInit(unsigned int seed);
void vmDeinit();
};
#endif