diff options
author | Chris Xiong <chirs241097@gmail.com> | 2015-10-02 23:48:34 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2015-10-02 23:48:34 +0800 |
commit | b9d4b60486e224261990c0732852513e86dd94ff (patch) | |
tree | 9f9dd20a888875833af11dc7a67b849a74825b5b /src/core | |
parent | abffe5f72dfb39da8d480ce3c4b546404684a060 (diff) | |
download | bullet-lab-remix-b9d4b60486e224261990c0732852513e86dd94ff.tar.xz |
Add BLR3 files. Modify Readme.
Currently BLR3 is VERY primitive!!
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/bullet.cpp | 101 | ||||
-rw-r--r-- | src/core/bullet.hpp | 49 | ||||
-rw-r--r-- | src/core/corepublic.hpp | 26 | ||||
-rw-r--r-- | src/core/coreshared.hpp | 5 | ||||
-rw-r--r-- | src/core/fncmodules.cpp | 1 | ||||
-rw-r--r-- | src/core/fncmodules.hpp | 1 | ||||
-rw-r--r-- | src/core/fncwrapper.hpp | 1 | ||||
-rw-r--r-- | src/core/gamescene.cpp | 70 | ||||
-rw-r--r-- | src/core/laser.cpp | 1 | ||||
-rw-r--r-- | src/core/player.cpp | 40 | ||||
-rw-r--r-- | src/core/player.hpp | 21 | ||||
-rw-r--r-- | src/core/scriptshared.hpp | 150 | ||||
-rw-r--r-- | src/core/tower.cpp | 1 | ||||
-rw-r--r-- | src/core/vmrunner.cpp | 280 | ||||
-rw-r--r-- | src/core/vmrunner.hpp | 48 |
15 files changed, 795 insertions, 0 deletions
diff --git a/src/core/bullet.cpp b/src/core/bullet.cpp new file mode 100644 index 0000000..175bae4 --- /dev/null +++ b/src/core/bullet.cpp @@ -0,0 +1,101 @@ +#include "bullet.hpp" +#include "../master/resources.hpp" +#include <cstdlib> +const char* bsnames[]={"green_bullet","cyan_bullet","yellow_bullet","purple_bullet", + "red_bullet","white_bullet","blue_bullet","orange_bullet", + "grey_bullet","circle_bullet"}; +void bulletBase::init(...){exist=true;renderscale=1;} +void bulletBase::update() +{ + if(!exist)return; + vel=vel+acc; + if(vel.l()>velim&&velim>0)vel=velim*vel.getNormalized(); + pos=pos-vel; + if(!extborder&&(pos.x<-10||pos.y<-10||pos.x>810||pos.y>610))exist=false; + //check clr & collision +} +void bulletBase::render() +{ + //test view mode + bmInstance->getBulEntity2D(basecolor)->setColor(0xC0FFFFFF); + bmInstance->getBulEntity2D(basecolor)->render(pos.x,pos.y,0,renderscale*0.6); +} +bulletBase::~bulletBase(){} + +void bulletBonus::update() +{ + //the player is not implemented yet... +} + +void bulletManager::init() +{ + alloced=used=0; + for(int i=0;i<(int)COLOR_COUNT;++i) + { + bulent2d[i]=new smEntity2D(ssanm.getTextureInfo(bsnames[i])->tex,ssanm.getTextureInfo(bsnames[i])->rect); + bulent3d[i]=new smEntity3D(ssanm.getTextureInfo(bsnames[i])->tex,ssanm.getTextureInfo(bsnames[i])->rect); + } +} +void bulletManager::deinit() +{ + if(alloced){for(int i=0;i<alloced;++i)delete bullets[i];alloced=used=0;} + for(int i=0;i<(int)COLOR_COUNT;++i) + {delete bulent2d[i];delete bulent3d[i];} +} +template<class T> +int bulletManager::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 bulletManager::createBullet() +{ + //stub... + int ptr=allocBullet<T>(); + bullets[ptr]->init(); + return ptr; +} +void bulletManager::updateBullet() +{ + static int b=0; + ++b; + if(b>15) + { + int a=createBullet<bulletBase>(); + bulletBase* x=getHandle(a); + x->pos=smvec2d(400,300); + x->vel=smvec2d(rand()%100-50,rand()%100-50); + x->vel.normalize(); + b=0; + } + for(int i=0;i<alloced;++i) + if(bullets[i]->exist) + bullets[i]->update(); +} +void bulletManager::renderBullet() +{ + for(int i=0;i<alloced;++i) + if(bullets[i]->exist) + { + bullets[i]->render(); + } +} +smEntity2D* bulletManager::getBulEntity2D(TColors col){return bulent2d[col];} +smEntity3D* bulletManager::getBulEntity3D(TColors col){return bulent3d[col];} +bulletBase* bulletManager::getHandle(int id){if(id<alloced)return bullets[id];else return NULL;} +bulletManager *bmInstance; diff --git a/src/core/bullet.hpp b/src/core/bullet.hpp new file mode 100644 index 0000000..5f4fe2f --- /dev/null +++ b/src/core/bullet.hpp @@ -0,0 +1,49 @@ +#ifndef BULLET_H +#define BULLET_H +#include "smmath.hpp" +#include "smentity.hpp" +#include "coreshared.hpp" +class bulletBase +{ +public: + smvec2d pos,vel,acc; + float velim; + //velim: velocity scalar limit. + float collrange,scollrange,renderscale; + //collision range and semi-collision range. Replacing "collable" and "scollable". + bool extborder,invincible; + //extborder: true=not removed if out of screen. + //invincible: true=not removed if collided with player or in range of CLR. + bool exist,addblend; + int attrd[8]; + float attrf[8]; + TColors basecolor; + virtual void init(...); + virtual void update(); + virtual void render(); + virtual ~bulletBase(); +}; +class bulletBonus:public bulletBase +{ + void update()override; +}; +class bulletManager +{ +private: + bulletBase* bullets[10240]; + int alloced,used; + smEntity2D* bulent2d[COLOR_COUNT]; + smEntity3D* bulent3d[COLOR_COUNT]; +public: + void init(); + void deinit(); + template<class T>int allocBullet(); + template<class T>int createBullet(); + void updateBullet(); + void renderBullet(); + bulletBase* getHandle(int id); + smEntity2D* getBulEntity2D(TColors col); + smEntity3D* getBulEntity3D(TColors col); +}; +extern bulletManager *bmInstance; +#endif diff --git a/src/core/corepublic.hpp b/src/core/corepublic.hpp new file mode 100644 index 0000000..fb06073 --- /dev/null +++ b/src/core/corepublic.hpp @@ -0,0 +1,26 @@ +#ifndef COREPUBLIC_H +#define COREPUBLIC_H +#include "smelt.hpp" +#include "smttfont.hpp" +#include "bullet.hpp" +#include "player.hpp" +#include "../master/master.hpp" +class gameScene:public scenePrototype +{ +private: + bool tpmode; + static SMELT *sm; + SMTRG rtarget; + smQuad tgquad; + smTTFont ttfont; + float udly; + int utime; +public: + gameScene(); + ~gameScene(); + bool sceneUpdate()override; + bool sceneRender()override; + bool threadUpdate()override; +}; +extern gameScene* gameScn; +#endif diff --git a/src/core/coreshared.hpp b/src/core/coreshared.hpp new file mode 100644 index 0000000..7c49afd --- /dev/null +++ b/src/core/coreshared.hpp @@ -0,0 +1,5 @@ +#ifndef CORESHARED_H +#define CORESHARED_H +enum TColors +{green=0,cyan,yellow,purple,red,white,blue,orange,grey,circle,COLOR_COUNT}; +#endif diff --git a/src/core/fncmodules.cpp b/src/core/fncmodules.cpp new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/src/core/fncmodules.cpp @@ -0,0 +1 @@ + diff --git a/src/core/fncmodules.hpp b/src/core/fncmodules.hpp new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/src/core/fncmodules.hpp @@ -0,0 +1 @@ + diff --git a/src/core/fncwrapper.hpp b/src/core/fncwrapper.hpp new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/src/core/fncwrapper.hpp @@ -0,0 +1 @@ + diff --git a/src/core/gamescene.cpp b/src/core/gamescene.cpp new file mode 100644 index 0000000..3bda53f --- /dev/null +++ b/src/core/gamescene.cpp @@ -0,0 +1,70 @@ +#include "../master/master.hpp" +#include "../master/resources.hpp" +#include "corepublic.hpp" +#include "bullet.hpp" +#include "player.hpp" +SMELT* gameScene::sm=NULL; +gameScene::gameScene() +{ + sm=smGetInterface(SMELT_APILEVEL); + rtarget=sm->smTargetCreate(800,600); + tgquad.tex=sm->smTargetTexture(rtarget); + tgquad.blend=BLEND_ALPHABLEND; + tgquad.v[0].x=190;tgquad.v[0].y=75; + tgquad.v[1].x=950;tgquad.v[1].y=75; + tgquad.v[2].x=950;tgquad.v[2].y=645; + tgquad.v[3].x=190;tgquad.v[3].y=645; + for(int i=0;i<4;++i)tgquad.v[i].z=0.5,tgquad.v[i].col=0xFFFFFFFF; + int rw=sm->smTextureGetWidth(tgquad.tex); + int rh=sm->smTextureGetHeight(tgquad.tex); + tgquad.v[0].tx=0;tgquad.v[0].ty=0; + tgquad.v[1].tx=800./rw;tgquad.v[1].ty=0; + tgquad.v[2].tx=800./rw;tgquad.v[2].ty=600./rh; + tgquad.v[3].tx=0;tgquad.v[3].ty=600./rh; + bmInstance=new bulletManager; + player=new playerBase; + utime=0; + ttfont.loadTTFFromMemory(blrdtp.getFilePtr("FreeMono.ttf"),blrdtp.getFileSize("FreeMono.ttf"),12); + bmInstance->init(); +} +gameScene::~gameScene() +{ + bmInstance->deinit(); + delete bmInstance; + delete player; + bmInstance=NULL; + ttfont.releaseTTF(); + sm->smTargetFree(rtarget); + sm->smRelease(); +} +bool gameScene::sceneUpdate() +{ + sm->smRenderBegin2D(true,rtarget); + sm->smClrscr(0xFF000000); + bmInstance->renderBullet(); + player->render(); + sm->smRenderEnd(); + return false; +} +bool gameScene::sceneRender() +{ + sm->smClrscr(0xFF000080); + sm->smRenderQuad(&tgquad); + udly+=sm->smGetDelta(); + extern sceneManager *sceneMgr;float lps=sceneMgr->getLPS(); + if(udly>1){udly=0;utime=sceneMgr->getTHUpdateTime();} + ttfont.updateString(L"LPS: %.2f",lps); + ttfont.render(0,680,0xFFFFFFFF,ALIGN_LEFT); + ttfont.updateString(L"Update Time: %dns",utime); + ttfont.render(0,695,0xFFFFFFFF,ALIGN_LEFT); + ttfont.updateString(L"FPS: %.2f",sm->smGetFPS()); + ttfont.render(0,710,0xFFFFFFFF,ALIGN_LEFT); + return false; +} +bool gameScene::threadUpdate() +{ + bmInstance->updateBullet(); + player->update(); + return false; +} +gameScene* gameScn; diff --git a/src/core/laser.cpp b/src/core/laser.cpp new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/src/core/laser.cpp @@ -0,0 +1 @@ + diff --git a/src/core/player.cpp b/src/core/player.cpp new file mode 100644 index 0000000..3407a0c --- /dev/null +++ b/src/core/player.cpp @@ -0,0 +1,40 @@ +#include "smelt.hpp" +#include "player.hpp" +#include "../master/resources.hpp" +SMELT* playerBase::sm=NULL; +playerBase::playerBase(float _x,float _y) +{ + sm=smGetInterface(SMELT_APILEVEL); + playerent=new smEntity2D(ssanm.getTextureInfo("player")->tex,ssanm.getTextureInfo("player")->rect); + playerent->setCentre(12,12); + pos.x=_x;pos.y=_y; + plyrctl[0]=SMK_UP;plyrctl[1]=SMK_DOWN; + plyrctl[2]=SMK_LEFT;plyrctl[3]=SMK_RIGHT; + plyrctl[4]=SMK_SHIFT; + rot=0; +} +playerBase::~playerBase() +{ + delete playerent;sm->smRelease(); +} +void playerBase::update() +{ + //player control... + static float realspeed=0; + if(sm->smGetKeyState(plyrctl[4])) + realspeed=0.85;else realspeed=3.5; + if(sm->smGetKeyState(plyrctl[0])) + {if(pos.y>15)pos.y-=realspeed;else pos.y=15;} + if(sm->smGetKeyState(plyrctl[1])) + {if(pos.y<585)pos.y+=realspeed;else pos.y=585;} + if(sm->smGetKeyState(plyrctl[2])) + {if(pos.x>15)pos.x-=realspeed;else pos.x=15;} + if(sm->smGetKeyState(plyrctl[3])) + {if(pos.x<785)pos.x+=realspeed;else pos.x=785;} + rot+=17./1800.*PI; +} +void playerBase::render() +{ + playerent->render(pos.x,pos.y,rot,0.7); +} +playerBase* player; diff --git a/src/core/player.hpp b/src/core/player.hpp new file mode 100644 index 0000000..408c174 --- /dev/null +++ b/src/core/player.hpp @@ -0,0 +1,21 @@ +#ifndef PLAYER_H +#define PLAYER_H +#include "smmath.hpp" +#include "smentity.hpp" +class playerBase +{ +private: + smEntity2D* playerent; + static SMELT* sm; +public: + smvec2d pos; + float rot,vel,velp; + int plyrctl[6]; + + playerBase(float _x=400,float _y=400); + ~playerBase(); + void update(); + void render(); +}; +extern playerBase* player; +#endif diff --git a/src/core/scriptshared.hpp b/src/core/scriptshared.hpp new file mode 100644 index 0000000..01d423a --- /dev/null +++ b/src/core/scriptshared.hpp @@ -0,0 +1,150 @@ +#ifndef SCRIPTSHARED_H +#define SCRIPTSHARED_H +#include <cmath> +#define eps 1e-6 +typedef union _Udata{//data union + int i;float r;unsigned long d; + _Udata(){d=0;} +}Udata; +typedef struct _Idata{//data union, with type tag and operators + _Udata D; + int type;//0=int, 1=float + _Idata(){D.d=0;type=0;} + _Idata(int _type,int _data) + {type=_type;if(type==0)D.i=_data;else D.r=(float)_data;} + float &r(){return D.r;} + int &i(){return D.i;} + unsigned long &d(){return D.d;} + _Idata operator =(_Idata r) + { + if(type==1&&r.type==0)this->r()=(float)r.i(); + else if(type==0&&r.type==1)this->i()=(int)r.r(); + else this->d()=r.d(); + return *this; + } + _Idata operator +=(_Idata r) + { + if(type==1&&r.type==0)this->r()+=(float)r.i(); + if(type==0&&r.type==1)this->i()+=(int)r.r(); + if(type==0&&r.type==0)this->i()+=r.i(); + if(type==1&&r.type==1)this->r()+=r.r(); + return *this; + } + _Idata operator -=(_Idata r) + { + if(type==1&&r.type==0)this->r()-=(float)r.i(); + if(type==0&&r.type==1)this->i()-=(int)r.r(); + if(type==0&&r.type==0)this->i()-=r.i(); + if(type==1&&r.type==1)this->r()-=r.r(); + return *this; + } + _Idata operator *=(_Idata r) + { + if(type==1&&r.type==0)this->r()*=(float)r.i(); + if(type==0&&r.type==1)this->i()*=(int)r.r(); + if(type==0&&r.type==0)this->i()*=r.i(); + if(type==1&&r.type==1)this->r()*=r.r(); + return *this; + } + _Idata operator /=(_Idata r) + { + if(type==1&&r.type==0)this->r()/=(float)r.i(); + if(type==0&&r.type==1)this->i()/=(int)r.r(); + if(type==0&&r.type==0)this->i()/=r.i(); + if(type==1&&r.type==1)this->r()/=r.r(); + return *this; + } + _Idata operator %=(_Idata r) + { + if(type==1&&r.type==0)throw; + if(type==0&&r.type==1)throw; + if(type==0&&r.type==0)this->i()%=r.i(); + if(type==1&&r.type==1)throw; + return *this; + } + _Idata operator &=(_Idata r) + { + if(type==1&&r.type==0)throw; + if(type==0&&r.type==1)throw; + if(type==0&&r.type==0)this->i()&=r.i(); + if(type==1&&r.type==1)throw; + return *this; + } + _Idata operator |=(_Idata r) + { + if(type==1&&r.type==0)throw; + if(type==0&&r.type==1)throw; + if(type==0&&r.type==0)this->i()|=r.i(); + if(type==1&&r.type==1)throw; + return *this; + } + _Idata operator ^=(_Idata r) + { + if(type==1&&r.type==0)throw; + if(type==0&&r.type==1)throw; + if(type==0&&r.type==0)this->i()^=r.i(); + if(type==1&&r.type==1)throw; + return *this; + } + _Idata operator ~() + { + if(type==1)throw; + if(type==0)i()=~i(); + return *this; + } + _Idata operator ++() + { + if(type==1)throw; + if(type==0)i()=i()+1; + return *this; + } + _Idata operator --() + { + if(type==1)throw; + if(type==0)i()=i()-1; + return *this; + } + bool ltz() + { + if(type==0)return i()<0; + if(type==1)return fabs(r())>eps&&r()<0; + throw; + } + bool elz() + { + if(type==0)return i()<=0; + if(type==1)return fabs(r())<eps||(fabs(r())>eps&&r()<0); + throw; + } + bool gtz() + { + if(type==0)return i()>0; + if(type==1)return fabs(r())>eps&&r()>0; + throw; + } + bool egz() + { + if(type==0)return i()>=0; + if(type==1)return fabs(r())<eps||(fabs(r())>eps&&r()>0); + throw; + } + bool eqz() + { + if(type==0)return i()==0; + if(type==1)return fabs(r())<eps; + throw; + } + bool nez() + { + if(type==0)return i()!=0; + if(type==1)return fabs(r())>eps; + throw; + } +}Idata; +typedef struct _SPara{Udata data;int type;char *fnc;}SPara;//parameters +typedef struct _SInst//instructions +{ + int id; + SPara para1,para2; +}SInst; +#endif diff --git a/src/core/tower.cpp b/src/core/tower.cpp new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/src/core/tower.cpp @@ -0,0 +1 @@ + diff --git a/src/core/vmrunner.cpp b/src/core/vmrunner.cpp new file mode 100644 index 0000000..1942d74 --- /dev/null +++ b/src/core/vmrunner.cpp @@ -0,0 +1,280 @@ +#include "vmrunner.hpp" +#include "coreshared.hpp" +#include <cstdlib> +unsigned getHash(const char *s) +{ + unsigned r=5381;char c; + while((c=(*s++)))r=((r<<5)+r)+c; + return r; +} +Idata& blrScriptVM::fetchData(SPara para,bool forcerw) +{ + static Idata cret; + switch (para.type) + { + case 0: + if(forcerw)throw; + cret.i()=para.data.i;cret.type=0; + return cret; + case 1: + if(forcerw)throw; + cret.r()=para.data.r;cret.type=1; + return cret; + case 2: + return ir[para.data.i]; + case 3: + return rr[para.data.i]; + case 4: + return ia[para.data.i]; + case 5: + return ra[para.data.i]; + case 6: + return ia[ir[para.data.i].i()]; + case 7: + return ra[ir[para.data.i].i()]; + default: + throw; + } +} +int blrScriptVM::mgetc() +{ + if(cbyte-sbyte<fsize) + {++cbyte;return (int)*(cbyte-1);} + else return -1; +} +void blrScriptVM::readPara(SPara *para) +{ + para->type=mgetc(); + para->data.d=0; + int l=0; + switch(para->type) + { + case 1: l=8;break; + case 0: 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 blrScriptVM::loadLSBFromMemory(const char *ptr,DWORD size) +{ + cbyte=sbyte=ptr;fsize=size; + int ibyt=0,infunc=0; + while(~(ibyt=mgetc())) + { + ++ic;inst[ic].id=ibyt; + switch(inst[ic].id) + { + case 0xFF: case 0x02: + { + int nl=mgetc(); + if(nl==-1)return 1; + if(inst[ic].id==0xFF){if(infunc)return 1;else infunc=1;} + if(inst[ic].id==0x02)if(!infunc)return 1; + inst[ic].para1.fnc=(char*)calloc(sizeof(char),nl+1); + inst[ic].para1.type=8; + for(int i=0;i<nl;++i)inst[ic].para1.fnc[i]=mgetc(); + if(inst[ic].id==0xFF) + { + fncent[fncnt].pos=ic; + fncent[fncnt++].hash=getHash(inst[ic].para1.fnc); + } + } + break; + case 0x00: break; + case 0xFE: + if(!infunc)return 1; + infunc=0; + break; + case 0x0F: + if(!infunc)return 1; + break; + case 0x01: case 0x0C: case 0x0D: + case 0x0E: case 0x11: case 0x12: + case 0x13: case 0x14: case 0x15: + case 0x16: case 0x21: + if(!infunc)return 1; + readPara(&inst[ic].para1); + break; + case 0x03: case 0x04: case 0x05: + case 0x06: case 0x07: case 0x08: + case 0x09: case 0x0A: case 0x0B: + case 0x22: case 0x23: + if(!infunc)return 1; + readPara(&inst[ic].para1); + readPara(&inst[ic].para2); + break; + } + } + return 0; +} +int blrScriptVM::getInstCount(){return pinst;} +void blrScriptVM::runFunction(const char *fncnym) +{ + int nymhash=getHash(fncnym),cur=0;pinst=0; + for(int i=0;i<fncnt;++i)if(nymhash==fncent[i].hash){cur=fncent[i].pos;break;} + while(inst[cur].id!=0xFE) + { + 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: + //no-op + break; + case 0xFF: + //no-op + break; + case 0x01: + callStk.push(fetchData(inst[cur].para1)); + 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); + break; + case 0x04: + fetchData(inst[cur].para1,true)+=fetchData(inst[cur].para2); + break; + case 0x05: + fetchData(inst[cur].para1,true)-=fetchData(inst[cur].para2); + break; + case 0x06: + fetchData(inst[cur].para1,true)*=fetchData(inst[cur].para2); + break; + case 0x07: + fetchData(inst[cur].para1,true)/=fetchData(inst[cur].para2); + break; + case 0x08: + fetchData(inst[cur].para1,true)%=fetchData(inst[cur].para2); + break; + case 0x09: + fetchData(inst[cur].para1,true)&=fetchData(inst[cur].para2); + break; + case 0x0A: + fetchData(inst[cur].para1,true)|=fetchData(inst[cur].para2); + break; + case 0x0B: + fetchData(inst[cur].para1,true)^=fetchData(inst[cur].para2); + break; + case 0x0C: + fetchData(inst[cur].para1,true)=~fetchData(inst[cur].para1,true); + break; + case 0x0D: + ++fetchData(inst[cur].para1,true); + break; + case 0x0E: + --fetchData(inst[cur].para1,true); + break; + case 0x0F: + callStk.clear(); + break; + case 0x11: + switch (fetchData(inst[cur].para1,true).type) + { + case 0: + fetchData(inst[cur].para1,true)= + fetchData(inst[cur].para1,true).ltz()?ione:izero; + break; + case 1: + fetchData(inst[cur].para1,true)= + fetchData(inst[cur].para1,true).ltz()?rone:rzero; + break; + } + break; + case 0x12: + switch (fetchData(inst[cur].para1,true).type) + { + case 0: + fetchData(inst[cur].para1,true)= + fetchData(inst[cur].para1,true).elz()?ione:izero; + break; + case 1: + fetchData(inst[cur].para1,true)= + fetchData(inst[cur].para1,true).elz()?rone:rzero; + break; + } + break; + case 0x13: + switch (fetchData(inst[cur].para1,true).type) + { + case 0: + fetchData(inst[cur].para1,true)= + fetchData(inst[cur].para1,true).gtz()?ione:izero; + break; + case 1: + fetchData(inst[cur].para1,true)= + fetchData(inst[cur].para1,true).gtz()?rone:rzero; + break; + } + break; + case 0x14: + switch (fetchData(inst[cur].para1,true).type) + { + case 0: + fetchData(inst[cur].para1,true)= + fetchData(inst[cur].para1,true).egz()?ione:izero; + break; + case 1: + fetchData(inst[cur].para1,true)= + fetchData(inst[cur].para1,true).egz()?rone:rzero; + break; + } + break; + case 0x15: + switch (fetchData(inst[cur].para1,true).type) + { + case 0: + fetchData(inst[cur].para1,true)= + fetchData(inst[cur].para1,true).eqz()?ione:izero; + break; + case 1: + fetchData(inst[cur].para1,true)= + fetchData(inst[cur].para1,true).eqz()?rone:rzero; + break; + } + break; + case 0x16: + switch (fetchData(inst[cur].para1,true).type) + { + case 0: + fetchData(inst[cur].para1,true)= + fetchData(inst[cur].para1,true).nez()?ione:izero; + break; + case 1: + fetchData(inst[cur].para1,true)= + fetchData(inst[cur].para1,true).nez()?rone:rzero; + break; + } + break; + case 0x21: + cur=fetchData(inst[cur].para1).i(); + jmp=1; + break; + case 0x22: + if(fetchData(inst[cur].para1).eqz()) + cur=fetchData(inst[cur].para2).i(),jmp=1; + break; + case 0x23: + if(fetchData(inst[cur].para1).nez()) + cur=fetchData(inst[cur].para2).i(),jmp=1; + break; + } + if(!jmp)++cur; + } +} +void blrScriptVM::vmInit() +{ +} +void blrScriptVM::vmDeinit() +{ +} diff --git a/src/core/vmrunner.hpp b/src/core/vmrunner.hpp new file mode 100644 index 0000000..60bc2ce --- /dev/null +++ b/src/core/vmrunner.hpp @@ -0,0 +1,48 @@ +#ifndef VMRUNNER_H +#define VMRUNNER_H +#include "smelt.hpp" +#include "smrandom.hpp" +#include "scriptshared.hpp" +const Idata ione=Idata(0,1),izero=Idata(0,0); +const Idata rone=Idata(1,1),rzero=Idata(1,0); +template<class memb> +class callStack//a queue, in fact. +{ +private: + int l,r; + memb data[16]; +public: + callStack(){clear();} + 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;} + memb pop(){if(l<=r+1)return data[l++];else throw;} + 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]; + int ic,fncnt,pinst; + fncEntry fncent[8]; + const char *sbyte,*cbyte; + DWORD fsize; + void readPara(SPara *para); + int mgetc(); + Idata& fetchData(SPara para,bool forcerw=false); +public: + blrScriptVM(){ic=fncnt=pinst=0;} + int loadLSBFromMemory(const char* ptr,DWORD size); + int getInstCount(); + void runFunction(const char *fncnym); + void vmInit(); + void vmDeinit(); +}; +#endif |