aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/blr3.dtpbin459577 -> 459958 bytes
-rw-r--r--src/core/bullet.cpp8
-rw-r--r--src/core/bullet.hpp28
-rw-r--r--src/core/fncmodules.cpp20
-rw-r--r--src/core/fncwrapper.cpp2
-rw-r--r--src/core/gamescene.cpp8
-rw-r--r--src/core/vmrunner.cpp11
-rw-r--r--src/core/vmrunner.hpp7
8 files changed, 58 insertions, 26 deletions
diff --git a/src/blr3.dtp b/src/blr3.dtp
index 1f62320..08d6551 100644
--- a/src/blr3.dtp
+++ b/src/blr3.dtp
Binary files differ
diff --git a/src/core/bullet.cpp b/src/core/bullet.cpp
index f7bcc90..c8cb50f 100644
--- a/src/core/bullet.cpp
+++ b/src/core/bullet.cpp
@@ -42,7 +42,7 @@ void bulletManager::deinit()
for(int i=0;i<(int)COLOR_COUNT;++i)
{delete bulent2d[i];delete bulent3d[i];}
}
-template<class T>
+/*template<class T>
int bulletManager::allocBullet()
{
if(!alloced)
@@ -69,10 +69,10 @@ int bulletManager::createBullet()
int ptr=allocBullet<T>();
bullets[ptr]->init();
return ptr;
-}
+}*/
void bulletManager::updateBullet()
{
- static int b=0;
+ /*static int b=0;
++b;
if(b>15)
{
@@ -83,7 +83,7 @@ void bulletManager::updateBullet()
x->vel.normalize();
x->rendercolor=0xC0FFFFFF;
b=0;
- }
+ }*/
for(int i=0;i<alloced;++i)
if(bullets[i]->exist)
bullets[i]->update();
diff --git a/src/core/bullet.hpp b/src/core/bullet.hpp
index b240e81..e3dc8fe 100644
--- a/src/core/bullet.hpp
+++ b/src/core/bullet.hpp
@@ -38,8 +38,32 @@ private:
public:
void init();
void deinit();
- template<class T>int allocBullet();
- template<class T>int createBullet();
+ template<class T>int allocBullet()
+ {
+ if(!alloced)
+ {
+ alloced=1;
+ bullets[0]=new T;
+ return 0;
+ }
+ else
+ {
+ int i;
+ for(i=0;i<alloced;++i)
+ if(!bullets[i]->exist)break;
+ if(i==alloced)
+ bullets[alloced++]=new T;
+ return i;
+ }
+ return -1;
+ }
+ template<class T>int createBullet()
+ {
+ //stub...
+ int ptr=allocBullet<T>();
+ bullets[ptr]->init();
+ return ptr;
+ }
void updateBullet();
void renderBullet();
bulletBase* getHandle(int id);
diff --git a/src/core/fncmodules.cpp b/src/core/fncmodules.cpp
index 14d2f48..08747c8 100644
--- a/src/core/fncmodules.cpp
+++ b/src/core/fncmodules.cpp
@@ -2,7 +2,6 @@
#include "bullet.hpp"
#include "scriptshared.hpp"
#include "vmrunner.hpp"
-extern callStack<Idata> callStk;
Idata randr()
{
Idata ret;ret.type=1;
@@ -19,17 +18,16 @@ Idata randi()
}
Idata createBullet()
{
- Idata x,y,bs,rad;
- x=callStk.pop();
- y=callStk.pop();
- bs=callStk.pop();
- rad=callStk.pop();
+ float x,y,bs,rad;
+ rad=callStk.pop().r();
+ bs=callStk.pop().r();
+ y=callStk.pop().r();
+ x=callStk.pop().r();
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()));
+ int i=bmInstance->createBullet<bulletBase>();
+ bmInstance->getHandle(i)->pos.x=x;
+ bmInstance->getHandle(i)->pos.y=y;
+ bmInstance->getHandle(i)->vel=bs*smvec2d(cos(rad),sin(rad));
bmInstance->getHandle(i)->acc=smvec2d(0,0);
bmInstance->getHandle(i)->basecolor=blue;
bmInstance->getHandle(i)->rendercolor=0xC0FFFFFF;
diff --git a/src/core/fncwrapper.cpp b/src/core/fncwrapper.cpp
index 0927541..8f08bae 100644
--- a/src/core/fncwrapper.cpp
+++ b/src/core/fncwrapper.cpp
@@ -1,7 +1,5 @@
#include "vmrunner.hpp"
#include "fncmodules.hpp"
-extern callStack<Idata> callStk;
-extern blrScriptVM *vm;
extern unsigned getHash(const char *s);
void callFnc(const char* fnc)
{
diff --git a/src/core/gamescene.cpp b/src/core/gamescene.cpp
index 3bda53f..32fea88 100644
--- a/src/core/gamescene.cpp
+++ b/src/core/gamescene.cpp
@@ -3,6 +3,7 @@
#include "corepublic.hpp"
#include "bullet.hpp"
#include "player.hpp"
+#include "vmrunner.hpp"
SMELT* gameScene::sm=NULL;
gameScene::gameScene()
{
@@ -23,14 +24,20 @@ gameScene::gameScene()
tgquad.v[3].tx=0;tgquad.v[3].ty=600./rh;
bmInstance=new bulletManager;
player=new playerBase;
+ vm=new blrScriptVM;
utime=0;
ttfont.loadTTFFromMemory(blrdtp.getFilePtr("FreeMono.ttf"),blrdtp.getFileSize("FreeMono.ttf"),12);
bmInstance->init();
+ vm->vmInit(61616);
+ vm->loadLSBFromMemory(blrdtp.getFilePtr("test.lsb"),blrdtp.getFileSize("test.lsb"));
+ vm->vmRunFunction("init");
}
gameScene::~gameScene()
{
bmInstance->deinit();
+ vm->vmDeinit();
delete bmInstance;
+ delete vm;
delete player;
bmInstance=NULL;
ttfont.releaseTTF();
@@ -63,6 +70,7 @@ bool gameScene::sceneRender()
}
bool gameScene::threadUpdate()
{
+ vm->vmRunFunction("update");
bmInstance->updateBullet();
player->update();
return false;
diff --git a/src/core/vmrunner.cpp b/src/core/vmrunner.cpp
index 7cad11a..fb4c5e6 100644
--- a/src/core/vmrunner.cpp
+++ b/src/core/vmrunner.cpp
@@ -2,6 +2,7 @@
#include "coreshared.hpp"
#include "fncwrapper.hpp"
#include <cstdlib>
+#include <cstdio>
blrScriptVM *vm;
callStack<Idata> callStk;
unsigned getHash(const char *s)
@@ -42,7 +43,7 @@ Idata& blrScriptVM::fetchData(SPara para,bool forcerw)
int blrScriptVM::mgetc()
{
if(cbyte-sbyte<fsize)
- {++cbyte;return (int)*(cbyte-1);}
+ {++cbyte;return (int)(*(cbyte-1));}
else return -1;
}
void blrScriptVM::readPara(SPara *para)
@@ -52,20 +53,20 @@ void blrScriptVM::readPara(SPara *para)
int l=0;
switch(para->type)
{
- case 1: l=8;break;
- case 0: case 4: case 5: l=4;break;
+ case 0: case 1: case 4: case 5: l=4;break;
case 2: case 3: case 6: case 7: l=1;break;
default: break;
}
for(int i=0;i<l;++i)
{
para->data.d<<=8LL;
- para->data.d|=(unsigned long long)mgetc();
+ int a=mgetc();
+ para->data.d|=(unsigned long long)a;
}
}
int blrScriptVM::loadLSBFromMemory(const char *ptr,DWORD size)
{
- cbyte=sbyte=ptr;fsize=size;
+ cbyte=sbyte=(const unsigned char*)ptr;fsize=size;
int ibyt=0,infunc=0;
while(~(ibyt=mgetc()))
{
diff --git a/src/core/vmrunner.hpp b/src/core/vmrunner.hpp
index 2dec71f..ee03385 100644
--- a/src/core/vmrunner.hpp
+++ b/src/core/vmrunner.hpp
@@ -1,5 +1,6 @@
#ifndef VMRUNNER_H
#define VMRUNNER_H
+#include <cstring>
#include "smelt.hpp"
#include "smrandom.hpp"
#include "scriptshared.hpp"
@@ -16,7 +17,7 @@ public:
void clear(){l=0;r=-1;}
int size(){return r-l+1;}
bool empty(){return size()==0;}
- void push(memb a){data[++r]=a;if(r>15)throw;}
+ void push(memb a){memcpy(data+(++r),&a,sizeof(a));if(r>15)throw;}
memb pop(){if(l<=r+1)return data[l++];else throw;}
memb front(){return data[l];}
memb back(){return data[r];}
@@ -30,7 +31,7 @@ private:
SInst inst[65537];
int ic,fncnt,pinst;
fncEntry fncent[8];
- const char *sbyte,*cbyte;
+ const unsigned char *sbyte,*cbyte;
DWORD fsize;
void readPara(SPara *para);
int mgetc();
@@ -46,4 +47,6 @@ public:
void vmInit(unsigned int seed);
void vmDeinit();
};
+extern blrScriptVM *vm;
+extern callStack<Idata> callStk;
#endif