aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2015-12-07 23:47:53 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2015-12-07 23:47:53 +0800
commit308cc42fbc27522615baf7843511571434c34062 (patch)
tree612ac7ee671a27de6c823ed4760c95a9d150f86a
parentcccf71f117f6acd02726d8d72702bdc8cc35d86d (diff)
downloadbullet-lab-remix-master.tar.xz
Update SMELT to the latest revision.HEADmaster
-rw-r--r--ChangeLog7
-rw-r--r--include/smelt.hpp164
-rw-r--r--smelt/sdl/sfx_sdl.cpp35
-rw-r--r--smelt/sdl/smelt_config.hpp20
-rw-r--r--smelt/sdl/smelt_internal.hpp5
5 files changed, 220 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 0ebdfa4..46c678b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2015-12-07 0.0.1(r14)
+Update SMELT.
+
+2015-11-03 0.0.1(r13)
+Avoid incomplete data transfer.
+Fix loop mark stack underflowing.
+
2015-11-01 0.0.1(r12)
Move hge to an archive.
Finish the main part of smPath.
diff --git a/include/smelt.hpp b/include/smelt.hpp
index 0b97e33..5435d15 100644
--- a/include/smelt.hpp
+++ b/include/smelt.hpp
@@ -3,7 +3,7 @@
* Simple MultimEdia LiTerator(SMELT)
* by Chris Xiong 2015
* api level 3
- * Public header
+ * Core header
*
* WARNING: This library is in development and interfaces would be very
* unstable.
@@ -34,19 +34,21 @@
#define SMELT_APILEVEL 3
+//Primitive data types
typedef uint32_t DWORD;
typedef uint16_t WORD;
typedef uint8_t BYTE;
+//PI
#define PI 3.14159265358979323846f
-//Handles
+//Handle types
typedef size_t SMTEX;//Texture Handle
typedef size_t SMTRG;//Target Handle
typedef size_t SMSFX;//SoundFX Handle
-typedef size_t SMCHN;//Channel Handle
+typedef size_t SMCHN;//Audio channel Handle
-//Color Marcos
+//Color Macros
#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)
@@ -67,15 +69,21 @@ typedef size_t SMCHN;//Channel Handle
#define BLEND_ZWRITE 0x4
#define BLEND_NOZWRITE 0x0
+//callback function pointer
typedef bool (*smHook)();
+//Special FPS modes
+//Unlimited FPS
#define FPS_FREE 0
+//VSync
#define FPS_VSYNC -1
+//Primitives
#define PRIM_LINES 2
#define PRIM_TRIANGLES 3
#define PRIM_QUADS 4
+//Texture Region structure
struct smTexRect
{
smTexRect(){x=y=w=h=.0;}
@@ -83,6 +91,7 @@ struct smTexRect
float x,y,w,h;
};
+//Vertex structure
struct smVertex
{
float x,y,z;//Position. Z can be used for depth testing in 2D Mode.
@@ -90,6 +99,7 @@ struct smVertex
float tx,ty;//Texture coords.
};
+//Triangle primitive structure
struct smTriangle
{
smVertex v[3];
@@ -97,6 +107,7 @@ struct smTriangle
int blend;
};
+//Quadrilateral primitive structure
struct smQuad
{
smVertex v[4];
@@ -104,6 +115,7 @@ struct smQuad
int blend;
};
+//Input event structure
struct smInpEvent
{
int type,flag;
@@ -117,33 +129,177 @@ class SMELT
public:
SMELT(){}
virtual ~SMELT(){}
+ /**
+ * Releases the acquired SMELT interface.
+ * Decreases the internal reference counter by one. If the counter
+ * reaches 0, SMELT core will release all resources managed by it
+ * (if smFinale() is not yet called) and destroy the interface.
+ */
virtual void smRelease()=0;
+ /**
+ * Initializes SMELT core.
+ * Creates application window, initializes video, audio and input
+ * handling. No functions in these categories can be called before
+ * the core is initialized.
+ * Returns true on succees, false on failure. Error details will be
+ * written to the log file and stderr.
+ */
virtual bool smInit()=0;
+ /**
+ * Deinitializes SMELT core.
+ * Closes application window and frees resources managed by the core.
+ * The core will return to the status before calling smInit().
+ */
virtual void smFinale()=0;
+ /**
+ * Enters the main loop.
+ * The main loop calls update function, focus gain function, focus
+ * lost function and quit function periodally, handles input events
+ * and flushes the buffers.
+ * Requires the UpdateFunc set and the initialization of the SMELT
+ * interface.
+ * The main loop breaks when the update function returns true.
+ */
virtual void smMainLoop()=0;
+ /**
+ * Sets the update function.
+ * Update function is called every frame.
+ * It returns true when you want to terminate the main loop.
+ */
virtual void smUpdateFunc(smHook func)=0;
+ /**
+ * Sets the focus lost function.
+ * Focus lost function is called when the application window loses
+ * focus.
+ * The return value of the focus lost function has no effect.
+ */
virtual void smUnFocFunc(smHook func)=0;
+ /**
+ * Sets the focus gain function.
+ * Focus gain function is called when the application window gains
+ * focus. Also called when the application window is created.
+ * The return value of the focus gain function has no effect.
+ */
virtual void smFocFunc(smHook func)=0;
+ /**
+ * Sets the quit function.
+ * Quit function is called when the user attempts to close the
+ * application window.
+ * If quit function returns true, the main loop will continue.
+ * Otherwise the main loop will break.
+ */
virtual void smQuitFunc(smHook func)=0;
+ /**
+ * Sets the window title of the application window.
+ * The default window title is "untitled".
+ */
virtual void smWinTitle(const char* title)=0;
+ /**
+ * Tests if the application window has focus.
+ * Returns the test result.
+ */
virtual bool smIsActive()=0;
+ /**
+ * Changes the behavior when the application window loses focus.
+ * By default, the main loop pauses when the application loses focus
+ * (para=false).
+ * If para is set to true, the main loop won't suspend when the
+ * application loses focus.
+ */
virtual void smNoSuspend(bool para)=0;
+ /*
+ * Sets the video mode.
+ * This function can only be called before calling smInit().
+ * The default video mode is 800x600 fullscreen.
+ * Take care with fullscreen video modes. Inappropriate fullscreen
+ * resolutions will cause the failure of smInit().
+ */
virtual void smVidMode(int resX,int resY,bool _windowed)=0;
+ /*
+ * Sets the log file path.
+ * The default value is empty.
+ * In addition, the log will always be written to stderr.
+ */
virtual void smLogFile(const char* path)=0;
+ /*
+ * Write something to the log file.
+ * C-style formatting can be used.
+ */
virtual void smLog(const char* format,...)=0;
+ /*
+ * Saves the content of the application window to the given path.
+ * The picture is saved in the BMP format.
+ */
virtual void smScreenShot(const char* path)=0;
+ /*
+ * Sets the desired FPS value. The macros FPS_* can be used
+ */
virtual void smSetFPS(int fps)=0;
+ /*
+ * Get *current* FPS value your application is running at.
+ * Not the value you set!
+ * Returns the FPS value, which is updated once a second.
+ */
virtual float smGetFPS()=0;
+ /*
+ * Get delta time between the current frame and the last frame.
+ * Return the value in seconds.
+ */
virtual float smGetDelta()=0;
+ /*
+ * Get elapsed time since calling smInit() in seconds.
+ * Returns the result.
+ */
virtual float smGetTime()=0;
+ /*
+ * Load a single sound file into memory.
+ * Currently only ogg and wav files are supported.
+ * This function loads and decodes the ogg data, which may take
+ * noticeable time to complete. Consider running it in a seperate
+ * thread if you are loading a larger file.
+ * Returns the SFX handle on success, or 0 on failure.
+ */
virtual SMSFX smSFXLoad(const char *path)=0;
+ /*
+ * Loads sound file from the given memory block.
+ * Only ogg and wav formats are supported.
+ * Returns the SFX handle on success, or 0 on failure.
+ */
virtual SMSFX smSFXLoadFromMemory(const char *ptr,DWORD size)=0;
+ /*
+ * Plays the sound.
+ * If loop is set to false, the audio won't loop even if loop points
+ * are set.
+ * Volume should be between 0 to 100.
+ * Panning should be between -100 to 100.
+ * The values will be clamped to the range given above.
+ * Returns the audio channel it occupies, or 0 if there's no audio
+ * channel available.
+ * Max audio channels can be modified in smelt_config.hpp.
+ */
virtual SMCHN smSFXPlay(SMSFX fx,int vol=100,int pan=0,float pitch=1.,bool loop=0)=0;
+ /*
+ * Gets the length of the audio, in seconds.
+ * Returns the result.
+ */
virtual float smSFXGetLengthf(SMSFX fx)=0;
+ /*
+ * Gets the length of the audio, in sample numbers.
+ * Returns the result.
+ */
virtual DWORD smSFXGetLengthd(SMSFX fx)=0;
+ /*
+ * Sets the loop points of the given sound.
+ * By default, the whole sound is looped.
+ * This function uses AL_SOFT_loop_points. So it may not work if
+ * SMELT isn't build against OpenAL Soft
+ */
virtual void smSFXSetLoopPoint(SMSFX fx,DWORD l,DWORD r)=0;
+ /*
+ * Unloads the audio file from memory.
+ */
virtual void smSFXFree(SMSFX fx)=0;
virtual void smChannelVol(SMCHN chn,int vol)=0;
diff --git a/smelt/sdl/sfx_sdl.cpp b/smelt/sdl/sfx_sdl.cpp
index b61a8a0..c49162a 100644
--- a/smelt/sdl/sfx_sdl.cpp
+++ b/smelt/sdl/sfx_sdl.cpp
@@ -13,6 +13,7 @@
static const char* SFX_SDL_SRCFN="smelt/sdl/sfx_sdl.cpp";
struct oggdata{const BYTE *data;DWORD size,pos;};
static void* readVorbis(const BYTE *data,const DWORD size, ALsizei *decomp_size,ALenum *fmt,ALsizei *freq);
+static void* readRiffWv(const BYTE *data,const DWORD size, ALsizei *decomp_size,ALenum *fmt,ALsizei *freq);
SMSFX SMELT_IMPL::smSFXLoad(const char *path)
{
FILE *pFile;DWORD size,rsize; char *buff;
@@ -33,15 +34,20 @@ SMSFX SMELT_IMPL::smSFXLoadFromMemory(const char *ptr,DWORD size)
if(pOpenALDevice&&!mute)
{
bool isOgg=size>4&&ptr[0]=='O'&&ptr[1]=='g'&&ptr[2]=='g'&&ptr[3]=='S';
- if(!isOgg)return 0;
void *decompdata=NULL,*decomp=NULL;
ALsizei decompsize=0,freq=0;
ALenum fmt=AL_FORMAT_STEREO16;
- decompdata=readVorbis((const BYTE*)ptr,size,&decompsize,&fmt,&freq);
+ decompdata=readRiffWv((const BYTE*)ptr,size,&decompsize,&fmt,&freq);
+ if(!decompdata)
+ {
+ if(!isOgg)return 0;
+ else decompdata=readVorbis((const BYTE*)ptr,size,&decompsize,&fmt,&freq);
+ }
+ if(!decompdata)return 0;
decomp=decompdata;
ALuint buff=0;alGenBuffers(1,&buff);
alBufferData(buff,fmt,decomp,decompsize,freq);
- free(decompdata);return (SMSFX)buff;
+ free(decompdata);return(SMSFX)buff;
}
return 0;
}
@@ -270,6 +276,29 @@ static void* readVorbis(const BYTE *data,const DWORD size, ALsizei *decomp_size,
}
return NULL;
}
+static void* readRiffWv(const BYTE *data,const DWORD size, ALsizei *decomp_size,ALenum *fmt,ALsizei *freq)
+{
+ if(data[0x0]!='R'||data[0x1]!='I'||data[0x2]!='F'||data[0x3]!='F')return NULL;
+ if(data[0x8]!='W'||data[0x9]!='A'||data[0xA]!='V'||data[0xB]!='E')return NULL;
+ if(data[0xC]!='f'||data[0xD]!='m'||data[0xE]!='t'||data[0xF]!=' ')return NULL;
+ if(data[0x16]==2)
+ {
+ if(data[0x22]==16)*fmt=AL_FORMAT_STEREO16;
+ else if(data[0x22]==8)*fmt=AL_FORMAT_STEREO8;
+ else return NULL;
+ }
+ else if(data[0x16]==1)
+ {
+ if(data[0x22]==16)*fmt=AL_FORMAT_MONO16;
+ else if(data[0x22]==8)*fmt=AL_FORMAT_MONO8;
+ else return NULL;
+ }else return NULL;
+ *decomp_size=(ALsizei)(data[0x28]|(data[0x29]<<8L)|(data[0x2A]<<16L)|(data[0x2B]<<24L));
+ *freq=(ALsizei)(data[0x18]|(data[0x19]<<8L)|(data[0x1A]<<16L)|(data[0x1B]<<24L));
+ ALubyte *ret=(ALubyte*)malloc(*decomp_size);
+ memcpy(ret,data+44,*decomp_size);
+ return ret;
+}
ALuint SMELT_IMPL::getSource()
{
for(int i=0;i<scnt;++i)
diff --git a/smelt/sdl/smelt_config.hpp b/smelt/sdl/smelt_config.hpp
new file mode 100644
index 0000000..0e56e8a
--- /dev/null
+++ b/smelt/sdl/smelt_config.hpp
@@ -0,0 +1,20 @@
+// -*- C++ -*-
+/*
+ * Simple MultimEdia LiTerator(SMELT)
+ * by Chris Xiong 2015
+ * Configuration header for SDL version
+ *
+ * Modify this header according to your own requirements.
+ *
+ */
+
+/*
+ * Maximum audio channels.
+ * (How many audio can be played simultaneously?)
+ */
+#define SRC_MAX 128
+
+/*
+ * Client-side vertex buffer size.
+ */
+#define VERTEX_BUFFER_SIZE 4000
diff --git a/smelt/sdl/smelt_internal.hpp b/smelt/sdl/smelt_internal.hpp
index 2d75e9a..a434079 100644
--- a/smelt/sdl/smelt_internal.hpp
+++ b/smelt/sdl/smelt_internal.hpp
@@ -12,6 +12,7 @@
#define SMELT_INTERNAL_H
#include "../../include/smelt.hpp"
+#include "smelt_config.hpp"
#include <cstdio>
#include <cstring>
#include <cstdlib>
@@ -42,8 +43,6 @@
#include "glimports.hpp"
#undef GL_PROC
-#define SRC_MAX 128
-
class TOpenGLDevice
{
public:
@@ -59,8 +58,6 @@ public:
bool have_GL_ARB_vertex_buffer_object;
};
-#define VERTEX_BUFFER_SIZE 4000
-
struct glTexture;
class TRenderTargetList
{