diff options
author | Chris Xiong <chirs241097@gmail.com> | 2015-08-14 23:45:02 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2015-08-14 23:45:02 +0800 |
commit | 92f17580846c88108aab023092c23e6bcdcf2f75 (patch) | |
tree | 0b05ee9215e46c02482e545989a8f92041bcc4f6 /include | |
parent | fff589be8d4a363c01c698c052fc43de806f5055 (diff) | |
download | bullet-lab-remix-92f17580846c88108aab023092c23e6bcdcf2f75.tar.xz |
SMELT is finally finished! Add the SMELT library for future use.
Add .gitignore.
Diffstat (limited to 'include')
-rw-r--r-- | include/smanim.hpp | 71 | ||||
-rw-r--r-- | include/smbmfont.hpp | 62 | ||||
-rw-r--r-- | include/smcolor.hpp | 91 | ||||
-rw-r--r-- | include/smdatapack.hpp | 57 | ||||
-rw-r--r-- | include/smelt.hpp | 335 | ||||
-rw-r--r-- | include/smentity.hpp | 66 | ||||
-rw-r--r-- | include/smgrid.hpp | 45 | ||||
-rw-r--r-- | include/smindicator.hpp | 75 | ||||
-rw-r--r-- | include/smmath.hpp | 124 | ||||
-rw-r--r-- | include/smprogresser.hpp | 69 | ||||
-rw-r--r-- | include/smrandom.hpp | 30 | ||||
-rw-r--r-- | include/smttfont.hpp | 60 |
12 files changed, 1085 insertions, 0 deletions
diff --git a/include/smanim.hpp b/include/smanim.hpp new file mode 100644 index 0000000..b206d5e --- /dev/null +++ b/include/smanim.hpp @@ -0,0 +1,71 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 1 + * Animation header + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * + */ +#ifndef SMANIM_H +#define SMANIM_H +#include "smelt.hpp" +#include "smentity.hpp" +#include "smdatapack.hpp" +#include <map> +#include <string> + +class smTexInfo +{ +public: + smTexRect rect; + char *name,*path; + SMTEX tex; +}; +class smAnmInfo +{ +public: + smTexInfo frames[256]; + int framedur[256],mode,fc; + char* name; +}; +class smAnmFile +{ +private: + static SMELT *sm; + smDtpFileR anm; + void parseMeta(char* meta,DWORD size); + std::map<std::string,smTexInfo> tm; + std::map<std::string,smAnmInfo> am; + std::map<std::string,SMTEX> xm; +public: + bool loadAnmFromMemory(char* ptr,DWORD size); + void close(); + smTexInfo* getTextureInfo(const char* name); + smAnmInfo* getAnimationInfo(const char* name); +}; +class smAnimation2D:public smEntity2D +{ +private: + smAnmInfo ai; + smAnimation2D(); + int cf,mf,r; +public: + smAnimation2D(smAnmInfo a); + void updateAnim(int f=1); + void resetAnim(); +}; +class smAnimation3D:public smEntity3D +{ +private: + smAnmInfo ai; + smAnimation3D(); + int cf,mf,r; +public: + smAnimation3D(smAnmInfo a); + void updateAnim(int f=1); + void resetAnim(); +}; +#endif diff --git a/include/smbmfont.hpp b/include/smbmfont.hpp new file mode 100644 index 0000000..8dffc1f --- /dev/null +++ b/include/smbmfont.hpp @@ -0,0 +1,62 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 1 + * Bitmap font support header + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * + */ + #ifndef SMBMFONT_H +#define SMBMFONT_H +#include "smanim.hpp" +#include <cwchar> +#ifndef ALIGN_LEFT +#define ALIGN_LEFT 0 +#define ALIGN_RIGHT 1 +#define ALIGN_CENTER 2 +#endif +class smBMFont +{ +private: + static SMELT *sm; + smDtpFileR anm; + float sc,hadv; + smEntity2D* chars[256]; + int pdb[256],pda[256],b; + DWORD color; + std::map<std::string,SMTEX> xm; + void parseMeta(char* meta,DWORD size); +public: + bool loadAnmFromMemory(char* ptr,DWORD size); + void close(); + void render(float x,float y,float z,int align,float *rw,const char* text); + void printf(float x,float y,float z,int align,float *rw,const char* format,...); + void setColor(DWORD col){color=col;} + void setBlend(int blend){b=blend;} + void setScale(float scale){sc=scale;} +}; +class smBMFontw +{ +private: + static SMELT *sm; + smDtpFileR anm; + float sc,hadv; + int b; + DWORD color; + std::map<std::string,SMTEX> xm; + std::map<wchar_t,smEntity2D*> chars; + std::map<wchar_t,int> pdb,pda; + void parseMeta(char* meta,DWORD size); +public: + bool loadAnmFromMemory(char* ptr,DWORD size); + void close(); + void render(float x,float y,float z,int align,float *rw,const wchar_t* text); + void printf(float x,float y,float z,int align,float *rw,const wchar_t* format,...); + void setColor(DWORD col){color=col;} + void setBlend(int blend){b=blend;} + void setScale(float scale){sc=scale;} +}; +#endif diff --git a/include/smcolor.hpp b/include/smcolor.hpp new file mode 100644 index 0000000..9d901de --- /dev/null +++ b/include/smcolor.hpp @@ -0,0 +1,91 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 1 + * Color system header & implementation + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * + */ +#ifndef SMCOLOR_H +#define SMCOLOR_H +#include "smelt.hpp" +#include "smmath.hpp" +#define clmp(a) a=a>1?1:a<0?0:a +class smColorRGBA +{ +public: + float r,g,b,a; + smColorRGBA(){r=g=b=a=.0;} + smColorRGBA(DWORD col){setHWColor(col);} + smColorRGBA(float _r,float _g,float _b,float _a){r=_r;g=_g;b=_b;a=_a;} + void clamp(){clmp(r);clmp(g);clmp(b);clmp(a);} + friend smColorRGBA operator +(smColorRGBA a,smColorRGBA b){return smColorRGBA(a.r+b.r,a.g+b.g,a.b+b.b,a.a+b.a);} + friend smColorRGBA operator -(smColorRGBA a,smColorRGBA b){return smColorRGBA(a.r-b.r,a.g-b.g,a.b-b.b,a.a-b.a);} + friend smColorRGBA operator *(smColorRGBA a,smColorRGBA b){return smColorRGBA(a.r*b.r,a.g*b.g,a.b*b.b,a.a*b.a);} + friend smColorRGBA operator *(smColorRGBA a,float b){return smColorRGBA(b*a.r,b*a.g,b*a.b,b*a.a);} + friend smColorRGBA operator /(smColorRGBA a,float b){return smColorRGBA(a.r/b,a.g/b,a.b/b,a.a/b);} + void setHWColor(DWORD col){a=GETA(col)/255.;r=GETR(col)/255.;g=GETG(col)/255.;b=GETB(col)/255.;} + DWORD getHWColor(){clamp();return RGBA(r,g,b,a);} +}; +class smColorHSVA +{ +public: + float h,s,v,a; + smColorHSVA(){h=s=v=a=.0;} + smColorHSVA(DWORD col){setHWColor(col);} + smColorHSVA(float _h,float _s,float _v,float _a){h=_h;s=_s;v=_v;a=_a;} + void clamp(){clmp(h);clmp(s);clmp(v);clmp(a);} + friend smColorHSVA operator +(smColorHSVA a,smColorHSVA b){return smColorHSVA(a.h+b.h,a.s+b.s,a.v+b.v,a.a+b.a);} + friend smColorHSVA operator -(smColorHSVA a,smColorHSVA b){return smColorHSVA(a.h-b.h,a.s-b.s,a.v-b.v,a.a-b.a);} + friend smColorHSVA operator *(smColorHSVA a,smColorHSVA b){return smColorHSVA(a.h*b.h,a.s*b.s,a.v*b.v,a.a*b.a);} + friend smColorHSVA operator *(smColorHSVA a,float b){return smColorHSVA(b*a.h,b*a.s,b*a.v,b*a.a);} + friend smColorHSVA operator /(smColorHSVA a,float b){return smColorHSVA(a.h/b,a.s/b,a.v/b,a.a/b);} + void setHWColor(DWORD col) + { + float r,g,b,dr,dg,db; + float minv,maxv,dv; + a=GETA(col)/255.;r=GETR(col)/255.; + g=GETG(col)/255.;b=GETB(col)/255.; + minv=min(min(r,g),b);maxv=max(max(r,g),b); + dv=maxv-minv;v=maxv; + if(dv<EPS)h=s=.0; + else + { + s=dv/maxv; + dr=(((maxv-r)/6)+dv/2)/dv; + dg=(((maxv-g)/6)+dv/2)/dv; + db=(((maxv-b)/6)+dv/2)/dv; + if(maxv==r)h=db-dg; + else if(maxv==g)h=(1./3.)+dr-db; + else if(maxv==b)h=(2./3.)+dg-dr; + } + clamp(); + } + DWORD getHWColor() + { + clamp(); + float r,g,b; + float xh,i,p1,p2,p3; + if(s<EPS)r=g=b=v; + else + { + xh=h*6; + if(fabsf(xh-6)<EPS)xh=0; + i=floorf(xh); + p1=v*(1-s); + p2=v*(1-s*(xh-i)); + p3=v*(1-s*(1-(xh-i))); + if(i==0)r=v,g=p3,b=p1; + else if(i==1)r=p2,g=v,b=p1; + else if(i==2)r=p1,g=v,b=p3; + else if(i==3)r=p1,g=p2,b=v; + else if(i==4)r=p3,g=p1,b=v; + else r=v,g=p1,b=p2; + } + return RGBA(DWORD(r*255.0f),DWORD(g*255.0f),DWORD(b*255.0f),DWORD(a*255.0f)); + } +}; +#endif diff --git a/include/smdatapack.hpp b/include/smdatapack.hpp new file mode 100644 index 0000000..ace7c81 --- /dev/null +++ b/include/smdatapack.hpp @@ -0,0 +1,57 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 1 + * DaTaPack format support header + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * + */ +#ifndef SMDTP_H +#define SMDTP_H +#include "smelt.hpp" +#include <cstdlib> +#include <zlib.h> +#include <string> +#include <map> +class smFileInfo +{ +public: + char *path,*data; + DWORD size,offset,crc; +}; +class smDtpFileR +{ +private: + int fcnt; + gzFile file; + std::map<std::string,smFileInfo> m; + + bool enmemory; + DWORD msize; + char *cp,*bp; +public: + bool openDtp(const char* path); + bool openDtpFromMemory(char* ptr,DWORD size); + void closeDtp(); + char* getFirstFile(); + char* getLastFile(); + char* getNextFile(const char* path); + char* getPrevFile(const char* path); + char* getFilePtr(const char* path); + void releaseFilePtr(const char* path); + DWORD getFileSize(const char* path); +}; +class smDtpFileW +{ +private: + smFileInfo files[256]; + int fcnt; +public: + smDtpFileW(); + bool addFile(const char* path,const char* realpath); + bool writeDtp(const char* path); +}; +#endif diff --git a/include/smelt.hpp b/include/smelt.hpp new file mode 100644 index 0000000..105da2a --- /dev/null +++ b/include/smelt.hpp @@ -0,0 +1,335 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 1 + * Public header + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * This library is developed for the BLR series games. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ +#ifndef SMELT_H +#define SMELT_H + +#include <stddef.h> +#include <stdint.h> + +#define SMELT_APILEVEL 1 + +typedef uint32_t DWORD; +typedef uint16_t WORD; +typedef uint8_t BYTE; + +#define PI 3.14159265358979323846f + +//Handles +typedef size_t SMTEX;//Texture Handle +typedef size_t SMTRG;//Target Handle +typedef size_t SMSFX;//Sound/FX Handle +typedef size_t SMCHN;//Channel Handle + +//Color Marcos +#define RGBA(r,g,b,a) ((DWORD(a)<<24)+(DWORD(r)<<16)+(DWORD(g)<<8)+DWORD(b)) +#define ARGB(a,r,g,b) ((DWORD(a)<<24)+(DWORD(r)<<16)+(DWORD(g)<<8)+DWORD(b)) +#define GETA(col) ((col)>>24) +#define GETR(col) (((col)>>16)&0xFF) +#define GETG(col) (((col)>>8)&0xFF) +#define GETB(col) ((col)&0xFF) +#define SETA(col,a) (((col)&0x00FFFFFF)+(DWORD(a)<<24)) +#define SETR(col,r) (((col)&0xFF00FFFF)+(DWORD(r)<<16)) +#define SETG(col,g) (((col)&0xFFFF00FF)+(DWORD(g)<<8)) +#define SETB(col,b) (((col)&0xFFFFFF00)+DWORD(b)) + +//Blend Modes +#define BLEND_COLORINV 0x8 +#define BLEND_COLORADD 0x1 +#define BLEND_COLORMUL 0x0 +#define BLEND_ALPHABLEND 0x2 +#define BLEND_ALPHAADD 0x0 +#define BLEND_ZWRITE 0x4 +#define BLEND_NOZWRITE 0x0 + +typedef bool (*SMHook)(); + +#define FPS_FREE 0 +#define FPS_VSYNC -1 + +#define PRIM_LINES 2 +#define PRIM_TRIANGLES 3 +#define PRIM_QUADS 4 + +struct smTexRect +{ + smTexRect(){x=y=w=h=.0;} + smTexRect(float _x,float _y,float _w,float _h){x=_x;y=_y;w=_w;h=_h;} + float x,y,w,h; +}; + +struct smVertex +{ + float x,y,z;//Position. Z can be used for depth testing in 2D Mode. + DWORD col;//Color. + float tx,ty;//Texture coords. +}; + +struct smTriangle +{ + smVertex v[3]; + SMTEX tex; + int blend; +}; + +struct smQuad +{ + smVertex v[4]; + SMTEX tex; + int blend; +}; + +struct smInpEvent +{ + int type,flag; + int sccode,chcode; + int wheel,x,y; + //TODO: add joystick +}; + +class SMELT +{ +public: + SMELT(){} + virtual ~SMELT(){}; + virtual void smRelease()=0; + virtual bool smInit()=0; + virtual void smFinale()=0; + virtual void smMainLoop()=0; + virtual void smUpdateFunc(SMHook func)=0; + virtual void smUnFocFunc(SMHook func)=0; + virtual void smFocFunc(SMHook func)=0; + virtual void smQuitFunc(SMHook func)=0; + virtual void smWinTitle(const char* title)=0; + virtual bool smIsActive()=0; + virtual void smNoSuspend(bool para)=0; + virtual void smVidMode(int resX,int resY,bool _windowed)=0; + virtual void smLogFile(const char* path)=0; + virtual void smLog(const char* format,...)=0; + virtual void smScreenShot(const char* path)=0; + + virtual void smSetFPS(int fps)=0; + virtual float smGetFPS()=0; + virtual float smGetDelta()=0; + + virtual SMSFX smSFXLoad(const char *path)=0; + virtual SMSFX smSFXLoadFromMemory(const char *ptr,DWORD size)=0; + virtual SMCHN smSFXPlay(SMSFX fx,int vol=100,int pan=0,float pitch=1.,bool loop=0)=0; + virtual float smSFXGetLengthf(SMSFX fx)=0; + virtual DWORD smSFXGetLengthd(SMSFX fx)=0; + virtual void smSFXFree(SMSFX fx)=0; + + virtual void smChannelVol(SMCHN chn,int vol)=0; + virtual void smChannelPan(SMCHN chn,int pan)=0; + virtual void smChannelPitch(SMCHN chn,float pitch)=0; + virtual void smChannelPause(SMCHN chn)=0; + virtual void smChannelResume(SMCHN chn)=0; + virtual void smChannelStop(SMCHN chn)=0; + virtual void smChannelPauseAll()=0; + virtual void smChannelResumeAll()=0; + virtual void smChannelStopAll()=0; + virtual bool smChannelIsPlaying(SMCHN chn)=0; + virtual float smChannelGetPosf(SMCHN chn)=0; + virtual void smChannelSetPosf(SMCHN chn,float pos)=0; + virtual int smChannelGetPosd(SMCHN chn)=0; + virtual void smChannelSetPosd(SMCHN chn,int pos)=0; + + virtual void smGetMouse2f(float *x,float *y)=0; + virtual void smSetMouse2f(float x,float y)=0; + virtual int smGetWheel()=0; + virtual bool smIsMouseOver()=0; + virtual int smGetKeyState(int key)=0; + virtual bool smGetInpEvent(smInpEvent *e)=0; + + virtual bool smRenderBegin2D(bool ztest=0,SMTRG trg=0)=0; + virtual bool smRenderBegin3D(float fov,SMTRG trg=0)=0; + virtual bool smRenderEnd()=0; + virtual void sm3DCamera6f2v(float *pos,float *rot)=0; + virtual void sm2DCamera5f3v(float *pos,float *dpos,float *rot)=0; + virtual void smClrscr(DWORD color)=0; + virtual void smRenderLinefd(float x1,float y1,float z1,float x2,float y2,float z2,DWORD color)=0; + virtual void smRenderLinefvd(float *p1,float *p2,DWORD color)=0; + virtual void smRenderTriangle(smTriangle *t)=0; + virtual void smRenderQuad(smQuad *q)=0; + virtual smVertex* smGetVertArray()=0; + virtual void smDrawVertArray(int prim,SMTEX texture,int blend,int _primcnt)=0; + + virtual SMTRG smTargetCreate(int w,int h)=0; + virtual SMTEX smTargetTexture(SMTRG targ)=0; + virtual void smTargetFree(SMTRG targ)=0; + + virtual SMTEX smTextureCreate(int w,int h)=0; + virtual SMTEX smTextureLoad(const char *path)=0; + virtual SMTEX smTextureLoadFromMemory(const char *ptr,DWORD size)=0; + virtual void smTextureFree(SMTEX tex)=0; + virtual int smTextureGetWidth(SMTEX tex,bool original=false)=0; + virtual int smTextureGetHeight(SMTEX tex,bool original=false)=0; + virtual DWORD* smTextureLock(SMTEX tex,int l,int t,int w,int h,bool ro=true)=0; + virtual void smTexutreUnlock(SMTEX tex)=0; +}; + +SMELT* smGetInterface(int apilevel); + +//event types +#define INPUT_KEYDOWN 1 +#define INPUT_KEYUP 2 +#define INPUT_MBUTTONDOWN 3 +#define INPUT_MBUTTONUP 4 +#define INPUT_MOUSEMOVE 5 +#define INPUT_MOUSEWHEEL 6 + +//key mods/flags +#define SMINP_SHIFT 0x1 +#define SMINP_CTRL 0x2 +#define SMINP_ALT 0x4 +#define SMINP_CAPSLOCK 0x8 +#define SMINP_SCROLLLOCK 0x10 +#define SMINP_NUMLOCK 0x20 +#define SMINP_REPEAT 0x40 + +//key codes +#define SMK_LBUTTON 0x01 +#define SMK_RBUTTON 0x02 +#define SMK_MBUTTON 0x04 + +#define SMK_ESCAPE 0x1B +#define SMK_BACKSPACE 0x08 +#define SMK_TAB 0x09 +#define SMK_ENTER 0x0D +#define SMK_SPACE 0x20 + +#define SMK_SHIFT 0x10 +#define SMK_CTRL 0x11 +#define SMK_ALT 0x12 + +#define SMK_LWIN 0x5B +#define SMK_RWIN 0x5C +#define SMK_APPS 0x5D + +#define SMK_PAUSE 0x13 +#define SMK_CAPSLOCK 0x14 +#define SMK_NUMLOCK 0x90 +#define SMK_SCROLLLOCK 0x91 + +#define SMK_PGUP 0x21 +#define SMK_PGDN 0x22 +#define SMK_HOME 0x24 +#define SMK_END 0x23 +#define SMK_INSERT 0x2D +#define SMK_DELETE 0x2E + +#define SMK_LEFT 0x25 +#define SMK_UP 0x26 +#define SMK_RIGHT 0x27 +#define SMK_DOWN 0x28 + +#define SMK_0 0x30 +#define SMK_1 0x31 +#define SMK_2 0x32 +#define SMK_3 0x33 +#define SMK_4 0x34 +#define SMK_5 0x35 +#define SMK_6 0x36 +#define SMK_7 0x37 +#define SMK_8 0x38 +#define SMK_9 0x39 + +#define SMK_A 0x41 +#define SMK_B 0x42 +#define SMK_C 0x43 +#define SMK_D 0x44 +#define SMK_E 0x45 +#define SMK_F 0x46 +#define SMK_G 0x47 +#define SMK_H 0x48 +#define SMK_I 0x49 +#define SMK_J 0x4A +#define SMK_K 0x4B +#define SMK_L 0x4C +#define SMK_M 0x4D +#define SMK_N 0x4E +#define SMK_O 0x4F +#define SMK_P 0x50 +#define SMK_Q 0x51 +#define SMK_R 0x52 +#define SMK_S 0x53 +#define SMK_T 0x54 +#define SMK_U 0x55 +#define SMK_V 0x56 +#define SMK_W 0x57 +#define SMK_X 0x58 +#define SMK_Y 0x59 +#define SMK_Z 0x5A + +#define SMK_GRAVE 0xC0 +#define SMK_MINUS 0xBD +#define SMK_EQUALS 0xBB +#define SMK_BACKSLASH 0xDC +#define SMK_LBRACKET 0xDB +#define SMK_RBRACKET 0xDD +#define SMK_SEMICOLON 0xBA +#define SMK_APOSTROPHE 0xDE +#define SMK_COMMA 0xBC +#define SMK_PERIOD 0xBE +#define SMK_SLASH 0xBF + +#define SMK_NUMPAD0 0x60 +#define SMK_NUMPAD1 0x61 +#define SMK_NUMPAD2 0x62 +#define SMK_NUMPAD3 0x63 +#define SMK_NUMPAD4 0x64 +#define SMK_NUMPAD5 0x65 +#define SMK_NUMPAD6 0x66 +#define SMK_NUMPAD7 0x67 +#define SMK_NUMPAD8 0x68 +#define SMK_NUMPAD9 0x69 + +#define SMK_MULTIPLY 0x6A +#define SMK_DIVIDE 0x6F +#define SMK_ADD 0x6B +#define SMK_SUBTRACT 0x6D +#define SMK_DECIMAL 0x6E + +#define SMK_F1 0x70 +#define SMK_F2 0x71 +#define SMK_F3 0x72 +#define SMK_F4 0x73 +#define SMK_F5 0x74 +#define SMK_F6 0x75 +#define SMK_F7 0x76 +#define SMK_F8 0x77 +#define SMK_F9 0x78 +#define SMK_F10 0x79 +#define SMK_F11 0x7A +#define SMK_F12 0x7B + +#define SMKST_NONE 0 +#define SMKST_HIT 1 +#define SMKST_KEEP 2 +#define SMKST_RELEASE 3 + +#endif diff --git a/include/smentity.hpp b/include/smentity.hpp new file mode 100644 index 0000000..7ecb8ee --- /dev/null +++ b/include/smentity.hpp @@ -0,0 +1,66 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 1 + * Entity header + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * + */ +#ifndef SMENTITY_H +#define SMENTITY_H +#include "smelt.hpp" +class smEntity2D +{ +private: + smEntity2D(); + static SMELT *sm; + smQuad quad; + float tx,ty,w,h,texw,texh; + float ctrx,ctry; +public: + smEntity2D(SMTEX tex,float _x,float _y,float _w,float _h); + smEntity2D(SMTEX tex,smTexRect rect); + smEntity2D(const smEntity2D ©); + ~smEntity2D(){sm->smRelease();} + void render(float x,float y,float rot=0,float wsc=1.,float hsc=0.); + + void setTexture(SMTEX tex); + void setTextureRect4f(float _x,float _y,float _w,float _h); + void setTextureRectv(smTexRect rect); + void setColor(DWORD col,int v=-1); + void setZ(float z,int v=-1); + void setBlend(int blend); + void setCentre(float x,float y); + float _w(){return w;} + float _h(){return h;} +}; + +class smEntity3D +{ +private: + smEntity3D(); + static SMELT *sm; + smQuad quad; + float tx,ty,w,h,texw,texh; + float ctrx,ctry; +public: + smEntity3D(SMTEX tex,float _x,float _y,float _w,float _h); + smEntity3D(SMTEX tex,smTexRect rect); + smEntity3D(const smEntity3D ©); + ~smEntity3D(){sm->smRelease();} + void render9f(float x,float y,float z,float ra=.0,float rx=.0,float ry=.0,float rz=.0,float wsc=1.,float hsc=0.); + void renderfv(float* pos,float* rot,float* scale); + + void setTexture(SMTEX tex); + void setTextureRect4f(float _x,float _y,float _w,float _h); + void setTextureRectv(smTexRect rect); + void setColor(DWORD col,int v=-1); + void setBlend(int blend); + void setCentre(float x,float y); + float _w(){return w;} + float _h(){return h;} +}; +#endif diff --git a/include/smgrid.hpp b/include/smgrid.hpp new file mode 100644 index 0000000..acd808c --- /dev/null +++ b/include/smgrid.hpp @@ -0,0 +1,45 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 1 + * Distortion grid header + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * + */ +#ifndef SMGRID_H +#define SMGRID_H +#include "smelt.hpp" + +#define GRID_REFNODE 0 +#define GRID_REFTOPLEFT 1 +#define GRID_REFCENTER 2 +#define GRID_REFCURRENT 3 + +class smGrid +{ +private: + smGrid(); + static SMELT *sm; + smVertex *pos; + int cc,rc; + float cw,ch; + float tx,ty,w,h; + smQuad quad; +public: + smGrid(int _cc,int _rc); + smGrid(const smGrid ©); + ~smGrid(); + smGrid& operator =(const smGrid ©); + void render(float x,float y); + void clear(DWORD color=0xFFFFFFFF); + void setTexture(SMTEX tex); + void setTextureRect4f(float _x,float _y,float _w,float _h); + void setTextureRectv(smTexRect rect); + void setBlend(int blend); + void setColor(int c,int r,DWORD col); + void setPos(int c,int r,float x,float y,float z,int ref); +}; +#endif diff --git a/include/smindicator.hpp b/include/smindicator.hpp new file mode 100644 index 0000000..5237a3b --- /dev/null +++ b/include/smindicator.hpp @@ -0,0 +1,75 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 1 + * Indicator header & implementation + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * + */ +#ifndef SMINDICATOR_H +#define SMINDICATOR_H +#include "smelt.hpp" +#include "smmath.hpp" +#include "smcolor.hpp" +#include "smgrid.hpp" +class indicatorCircular +{ +private: + smGrid *circle; + double value,radius,thickness; + DWORD color; + BYTE alpha; +public: + void init(double r,double thkns,BYTE a,SMTEX tex,smTexRect tr) + { + circle=new smGrid(1025,3); + circle->setTexture(tex); + circle->setTextureRectv(tr); + radius=r;thickness=thkns;alpha=a;color=0; + for(int i=0;i<=1024;++i) + { + double tang,tx,ty; + tang=(double)i/1024.*PI*2-PI/2; + tx=-cos(tang)*radius;ty=sin(tang)*radius; + circle->setPos(i,2,tx,ty,0.5,GRID_REFTOPLEFT); + tx=-cos(tang)*(radius-thickness);ty=sin(tang)*(radius-thickness); + circle->setPos(i,1,tx,ty,0.5,GRID_REFTOPLEFT); + tx=-cos(tang)*(radius-2*thickness);ty=sin(tang)*(radius-2*thickness); + circle->setPos(i,0,tx,ty,0.5,GRID_REFTOPLEFT); + } + } + void overrideColor(DWORD col){color=col;} + void setAlpha(BYTE a){alpha=a;} + void setValue(double v) + { + value=v; + for(int i=0;i<=1024;++i) + { + int tr=(int)((1.0f-value)*255); + int tg=(int)(value*255); + DWORD tcolor=ARGB(alpha,tr,tg,0); + smColorHSVA *tc=new smColorHSVA(tcolor); + if(tc->v<0.85)tc->v=0.85; + tcolor=color?SETA(color,alpha):SETA(tc->getHWColor(),alpha); + delete tc; + if((double)i/1024.<=value) + { + circle->setColor(i,2,tcolor); + circle->setColor(i,1,SETA(0x00FFFFFF,alpha)); + circle->setColor(i,0,tcolor); + } + else + { + circle->setColor(i,2,0); + circle->setColor(i,1,0); + circle->setColor(i,0,0); + } + } + } + void render(float x,float y){circle->render(x,y);} + void deinit(){delete circle;circle=NULL;} +}; +#endif diff --git a/include/smmath.hpp b/include/smmath.hpp new file mode 100644 index 0000000..805df50 --- /dev/null +++ b/include/smmath.hpp @@ -0,0 +1,124 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 1 + * Math header & implementation + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * + */ +#ifndef SMMATH_H +#define SMMATH_H +#include <cmath> +#include <cstddef> +#define sqr(x) ((x)*(x)) +#define EPS 1e-8 +#ifndef PI +#define PI 3.14159265358979323846f +#endif +template<class T>const T& min(const T& a,const T& b){return a<b?a:b;} +template<class T>const T& max(const T& a,const T& b){return a>b?a:b;} + +class smMath +{ +public: + double deg2rad(double deg){return deg/180.*PI;} + double rad2deg(double rad){return rad/PI*180.;} + double clamprad(double a){while(a<0)a+=2*PI;while(a>2*PI)a-=2*PI;return a;} + double clampdeg(double a){while(a<0)a+=360.;while(a>360)a-=360.;return a;} +}; +class smvec2d +{ +public: + double x,y; + smvec2d(double _x,double _y){x=_x;y=_y;} + smvec2d(){x=y=.0;} + double l(){return sqrt(sqr(x)+sqr(y));} + void normalize(){double L=l();if(L<EPS)return;x/=L;y/=L;} + smvec2d getNormalized(){double L=l();if(L<EPS)return smvec2d(0,0);return smvec2d(x/L,y/L);} + void swap(){double t=x;x=y;y=t;} + void rotate(double rad){double tx=x*cos(rad)+y*sin(rad),ty=y*cos(rad)-x*sin(rad);x=tx,y=ty;} + smvec2d getRotate(double rad){double tx=x*cos(rad)+y*sin(rad),ty=y*cos(rad)-x*sin(rad);return smvec2d(tx,ty);} + friend smvec2d operator -(smvec2d a,smvec2d b){return smvec2d(a.x-b.x,a.y-b.y);} + friend smvec2d operator +(smvec2d a,smvec2d b){return smvec2d(a.x+b.x,a.y+b.y);} + friend double operator |(smvec2d a,smvec2d b){return a.x*b.x+a.y*b.y;} + friend double operator *(smvec2d a,smvec2d b){return a.x*b.y-b.x*a.y;} + friend smvec2d operator *(double a,smvec2d b){return smvec2d(a*b.x,a*b.y);} + friend smvec2d operator *(smvec2d a,double b){return smvec2d(b*a.x,b*a.y);} + friend double operator ^(smvec2d a,smvec2d b){return (a|b)/a.l()/b.l();} +}; + +class smvec3d +{ +public: + double x,y,z; + smvec3d(double _x,double _y,double _z){x=_x;y=_y;z=_z;} + smvec3d(smvec2d a){x=a.x;y=a.y;z=.0;} + smvec3d(){x=y=z=.0;} + double l(){return sqrt(sqr(x)+sqr(y)+sqr(z));} + void normalize(){double L=l();if(L<EPS)return;x/=L;y/=L;z/=L;} + smvec3d getNormalized(){double L=l();if(L<EPS)return smvec3d(0,0,0);return smvec3d(x/L,y/L,z/L);} + friend smvec3d operator -(smvec3d a,smvec3d b){return smvec3d(a.x-b.x,a.y-b.y,a.z-b.z);} + friend smvec3d operator +(smvec3d a,smvec3d b){return smvec3d(a.x+b.x,a.y+b.y,a.z+b.z);} + friend double operator |(smvec3d a,smvec3d b){return a.x*b.x+a.y*b.y+a.z*b.z;} + friend smvec3d operator *(smvec3d a,smvec3d b){return smvec3d(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);} + friend smvec3d operator *(double a,smvec3d b){return smvec3d(a*b.x,a*b.y,a*b.z);} + friend smvec3d operator *(smvec3d a,double b){return smvec3d(b*a.x,b*a.y,b*a.z);} + friend double operator ^(smvec3d a,smvec3d b){return (a|b)/a.l()/b.l();} +}; + +class smMatrix +{ +public: + double m[16]; + /* sf 0 1 2 3 + * 0 00 04 08 12 + * 1 01 05 09 13 + * 2 02 06 10 14 + * 3 03 07 11 15 + */ + smMatrix(){for(int i=0;i<16;++i)m[i]=.0;} + smMatrix(const smMatrix ©){for(int i=0;i<16;++i)m[i]=copy.m[i];} + double* operator [](int s){if(s>=0&&s<4)return m+s*4;else return NULL;} + void clear(){for(int i=0;i<16;++i)m[i]=.0;} + void loadIdentity(){clear();m[0]=m[5]=m[10]=m[15]=1.;} + void rotate(double a,double x,double y,double z) + { + if(smvec3d(x,y,z).l()<=EPS)return; + if(fabs(smvec3d(x,y,z).l()-1)>EPS) + { + smvec3d a(x,y,z);a.normalize(); + x=a.x;y=a.y;z=a.z; + } + smMatrix tmp; + tmp[0][0]=x*x*(1-cos(a))+cos(a); + tmp[1][0]=x*y*(1-cos(a))-z*sin(a); + tmp[2][0]=x*z*(1-cos(a))+y*sin(a); + tmp[0][1]=y*x*(1-cos(a))+z*sin(a); + tmp[1][1]=y*y*(1-cos(a))+cos(a); + tmp[2][1]=y*z*(1-cos(a))-x*sin(a); + tmp[0][2]=x*z*(1-cos(a))-y*sin(a); + tmp[1][2]=y*z*(1-cos(a))+x*sin(a); + tmp[2][2]=z*z*(1-cos(a))+cos(a); + tmp[3][3]=1; + *this=*this*tmp; + } + friend smMatrix operator *(smMatrix a,smMatrix b) + { + smMatrix ret; + for(int i=0;i<4;++i) + for(int j=0;j<4;++j) + for(int k=0;k<4;++k) + ret[i][j]+=a[i][k]*b[k][j]; + return ret; + } + friend smvec3d operator *(smMatrix a,smvec3d b) + { + return smvec3d(a[0][0]*b.x+a[1][0]*b.y+a[2][0]*b.z, + a[0][1]*b.x+a[1][1]*b.y+a[2][1]*b.z, + a[0][2]*b.x+a[1][2]*b.y+a[2][2]*b.z); + } +}; +#endif diff --git a/include/smprogresser.hpp b/include/smprogresser.hpp new file mode 100644 index 0000000..ca81e62 --- /dev/null +++ b/include/smprogresser.hpp @@ -0,0 +1,69 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 1 + * Progresser header & implementation + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * + */ +#include "smmath.hpp" +class smProgresserLinear +{ +private: + double a,b,val; + double elapsed,lim; + bool done; +public: + void init(double _a,double _b,double _lim){a=_a;b=_b;lim=_lim;} + void launch(){elapsed=.0;val=a;done=false;} + void update(double delta) + { + if(elapsed+delta>=lim)return(void)(val=b,elapsed=lim,done=true); + elapsed+=delta;val=(b-a)*(elapsed/lim)+a; + } + bool isDone(){return done;} + double getValue(){return val;} + double getPercentage(){return elapsed/lim;} + double getDelta(){return val-a;} + double getElapsed(){return elapsed;} +}; +class smProgresserCurve +{ +private: + double a,b,val;int cpara; + double elapsed,lim; + bool done; + double transformFunc(double x) + { + if(cpara>=64)return sqrt(1-sqr(x-1)); + if(cpara>0) + { + double ctrx=(1+sqrt(2*sqr(64-cpara)-1))/2;double ctry=1-ctrx; + return sqrt(sqr(64-cpara)-sqr(x-ctrx))+ctry; + } + if(cpara==0)return x; + if(cpara<=-64)return -sqrt(1-sqr(x))+1; + if(cpara<0) + { + double ctrx=(1-sqrt(2*sqr(64+cpara)-1))/2;double ctry=1-ctrx; + return -sqrt(sqr(64+cpara)-sqr(x-ctrx))+ctry; + } + return NAN; + } +public: + void init(double _a,double _b,double _lim,int _cp){a=_a;b=_b;lim=_lim;cpara=_cp;} + void launch(){elapsed=.0;val=a;done=false;} + void update(double delta) + { + if(elapsed+delta>=lim)return(void)(val=b,elapsed=lim,done=true); + elapsed+=delta;val=(b-a)*transformFunc(elapsed/lim)+a; + } + bool isDone(){return done;} + double getValue(){return val;} + double getPercentage(){return elapsed/lim;} + double getDelta(){return val-a;} + double getElapsed(){return elapsed;} +}; diff --git a/include/smrandom.hpp b/include/smrandom.hpp new file mode 100644 index 0000000..9c47941 --- /dev/null +++ b/include/smrandom.hpp @@ -0,0 +1,30 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 1 + * Random engine header & implementation + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * + */ +class smRandomEngine +{ +private: + unsigned int cseed; +public: + void setSeed(unsigned int seed){cseed=seed;} + int nextInt(int min,int max) + { + if (min>max){int t=min;min=max;max=t;} + cseed*=214013;cseed+=2531011; + return min+(cseed^cseed>>15)%(max-min+1); + } + double nextDouble(double min,double max) + { + if (min>max){double t=min;min=max;max=t;} + cseed*=214013;cseed+=2531011; + return min+(cseed>>16)*(1.0f/65535.0f)*(max-min); + } +}; diff --git a/include/smttfont.hpp b/include/smttfont.hpp new file mode 100644 index 0000000..2fd96d5 --- /dev/null +++ b/include/smttfont.hpp @@ -0,0 +1,60 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 1 + * Truetype font support header + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * This library is developed for the BLR series games. + */ +#ifndef SMTTFONT_H +#define SMTTFONT_H +#include "smelt.hpp" +#include <cwchar> +#include <map> +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifndef ALIGN_LEFT +#define ALIGN_LEFT 0 +#define ALIGN_RIGHT 1 +#define ALIGN_CENTER 2 +#endif + +class smTTChar +{ +private: + smQuad quad; + int rw,rh,_w,_h,xofs,yofs; + static SMELT *sm; +public: + float w(){return (float)_w;} + float h(){return (float)_h;} + void free(); + bool setChar(wchar_t c,FT_Face ttface); + void render(float x,float y,DWORD col); +}; + +class smTTFont +{ +protected: + FT_Library ftlib; + FT_Face ttface; +private: + wchar_t buf[1024]; + std::map<wchar_t,smTTChar> chars; + float w,h; +public: + bool loadTTF(const char* path,int pt); + bool loadTTFFromMemory(char* ptr,DWORD size,int pt); + void releaseTTF(); + float getWidth(){return w;} + float getHeight(){return h;} + void updateString(const wchar_t *format,...); + void render(float x,float y,DWORD col,int align); + DWORD getCacheSize(); + void clearCache(); +}; +#endif |