From 038b31f0158a0018dbf2eceb71026cc4e665faa9 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Tue, 6 Oct 2015 21:28:40 +0800 Subject: Add the SMELT files... Please, do not laugh too loudly. --- include/smanim.hpp | 70 ++++++++++ include/smbmfont.hpp | 61 +++++++++ include/smcolor.hpp | 90 +++++++++++++ include/smdatapack.hpp | 56 ++++++++ include/smelt.hpp | 340 +++++++++++++++++++++++++++++++++++++++++++++++ include/smentity.hpp | 65 +++++++++ include/smgrid.hpp | 44 ++++++ include/smindicator.hpp | 113 ++++++++++++++++ include/smmath.hpp | 133 ++++++++++++++++++ include/smprogresser.hpp | 68 ++++++++++ include/smrandom.hpp | 29 ++++ include/smttfont.hpp | 59 ++++++++ 12 files changed, 1128 insertions(+) create mode 100644 include/smanim.hpp create mode 100644 include/smbmfont.hpp create mode 100644 include/smcolor.hpp create mode 100644 include/smdatapack.hpp create mode 100644 include/smelt.hpp create mode 100644 include/smentity.hpp create mode 100644 include/smgrid.hpp create mode 100644 include/smindicator.hpp create mode 100644 include/smmath.hpp create mode 100644 include/smprogresser.hpp create mode 100644 include/smrandom.hpp create mode 100644 include/smttfont.hpp (limited to 'include') diff --git a/include/smanim.hpp b/include/smanim.hpp new file mode 100644 index 0000000..c203961 --- /dev/null +++ b/include/smanim.hpp @@ -0,0 +1,70 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * 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 +#include + +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(const char* meta,DWORD size); + std::map tm; + std::map am; + std::map xm; +public: + bool loadAnmFromMemory(const 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..44f2e2f --- /dev/null +++ b/include/smbmfont.hpp @@ -0,0 +1,61 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * 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 +#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 xm; + void parseMeta(const char* meta,DWORD size); +public: + bool loadAnmFromMemory(const 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 xm; + std::map chars; + std::map 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..94ff4f3 --- /dev/null +++ b/include/smcolor.hpp @@ -0,0 +1,90 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * 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 +#include +#include +#include +class smFileInfo +{ +public: + char *path,*data; + DWORD size,offset,crc; +}; +class smDtpFileR +{ +private: + int fcnt; + gzFile file; + std::map m; + + bool enmemory; + DWORD msize; + const char *cp,*bp; +public: + bool openDtp(const char* path); + bool openDtpFromMemory(const 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..0b97e33 --- /dev/null +++ b/include/smelt.hpp @@ -0,0 +1,340 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * api level 3 + * Public header + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * This library is developed for the BLR series games. + * + * This file is part of the SMELT library. + * + * SMELT is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SMELT 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Foobar. If not, see . + * + */ + +#ifndef SMELT_H +#define SMELT_H + +#include +#include + +#define SMELT_APILEVEL 3 + +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;//SoundFX 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_COLORADD 0x1 +#define BLEND_COLORMUL 0x0 +#define BLEND_COLORINV 0x8 +#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 float smGetTime()=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 smSFXSetLoopPoint(SMSFX fx,DWORD l,DWORD r)=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 int smGetKey()=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 smMultViewMatrix(float *mat)=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..54fb3fb --- /dev/null +++ b/include/smentity.hpp @@ -0,0 +1,65 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * 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..ce1aabb --- /dev/null +++ b/include/smgrid.hpp @@ -0,0 +1,44 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * 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..0595dc8 --- /dev/null +++ b/include/smindicator.hpp @@ -0,0 +1,113 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * 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 "smentity.hpp" +#include "smgrid.hpp" +class indicatorCircular +{ +private: + smGrid *circle; + float value,radius,thickness; + DWORD color; + BYTE alpha; +public: + void init(float r,float 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) + { + float tang,tx,ty; + tang=(float)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(float 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((float)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;} +}; +class indicatorLinear +{ +private: + smEntity2D *upper,*lower; + float value,maxlength,thickness; + DWORD color;smTexRect trect; + BYTE alpha; +public: + void init(float ml,float thkns,BYTE a,SMTEX tex,smTexRect tr) + { + upper=new smEntity2D(tex,tr.x,tr.y,tr.w,tr.h/2); + lower=new smEntity2D(tex,tr.x,tr.y+tr.h/2,tr.w,tr.h/2); + maxlength=ml;thickness=thkns;alpha=a;color=0;trect=tr; + } + void overrideColor(DWORD col){color=col;} + void setAlpha(BYTE a){alpha=a;} + void setValue(float v) + { + value=v; + 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; + upper->setColor(tcolor,0);upper->setColor(tcolor,1); + upper->setColor(0,2);upper->setColor(0,3); + lower->setColor(0,0);lower->setColor(0,1); + lower->setColor(tcolor,2);lower->setColor(tcolor,3); + } + void render(float x,float y) + { + upper->render(x,y,0,value*maxlength/trect.w,thickness/trect.h/2); + lower->render(x,y+thickness/2,0,value*maxlength/trect.w,thickness/trect.h/2); + } + void deinit(){delete upper;delete lower;upper=lower=NULL;} +}; +#endif diff --git a/include/smmath.hpp b/include/smmath.hpp new file mode 100644 index 0000000..5172772 --- /dev/null +++ b/include/smmath.hpp @@ -0,0 +1,133 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * Math header & implementation + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * + */ +#ifndef SMMATH_H +#define SMMATH_H +#include +#include +#define sqr(x) ((x)*(x)) +#define EPS 1e-8 +#ifndef PI +#define PI 3.14159265358979323846f +#endif +templateconst T& min(const T& a,const T& b){return aconst 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=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; + } + void lookat(double *eye,double *at,double *up) + { + smvec3d f=smvec3d(at[0],at[1],at[2])-smvec3d(eye[0],eye[1],eye[2]);f.normalize(); + smvec3d UP=smvec3d(up[0],up[1],up[2]);UP.normalize(); + smvec3d s=f*UP;smvec3d u=s.getNormalized()*f; + *this[0][0]= s.x;*this[1][0]= s.y;*this[2][0]= s.z;*this[3][0]=0; + *this[0][1]= u.x;*this[1][1]= u.y;*this[2][1]= u.z;*this[3][1]=0; + *this[0][2]=-f.x;*this[1][2]=-f.y;*this[2][2]=-f.z;*this[3][2]=0; + *this[0][3]= 0;*this[1][3]= 0;*this[2][3]= 0;*this[3][3]=1; + } + 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..50edd2d --- /dev/null +++ b/include/smprogresser.hpp @@ -0,0 +1,68 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * 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..ed560e0 --- /dev/null +++ b/include/smrandom.hpp @@ -0,0 +1,29 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * 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..777d8ed --- /dev/null +++ b/include/smttfont.hpp @@ -0,0 +1,59 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * 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 +#include +#include +#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 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 -- cgit v1.2.3