From 6206029f2d0af3ef76a0a61ef024ca758307ba19 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Tue, 25 Oct 2016 22:28:57 +0800 Subject: Add more options to the config file. --- examples/SpriteSheet.png | Bin examples/tap.ogg | Bin smelt/sdl/makefile | 16 +++++++--------- smelt/sdl/sfx_dumb.cpp | 13 +------------ smelt/sdl/sfx_sdl.cpp | 12 ++++++++++++ smelt/sdl/smelt_config.hpp | 10 ++++++++++ smelt/sdl/smelt_internal.hpp | 8 +++++++- smelt/sdl/sys_sdl.cpp | 1 + 8 files changed, 38 insertions(+), 22 deletions(-) mode change 100755 => 100644 examples/SpriteSheet.png mode change 100755 => 100644 examples/tap.ogg diff --git a/examples/SpriteSheet.png b/examples/SpriteSheet.png old mode 100755 new mode 100644 diff --git a/examples/tap.ogg b/examples/tap.ogg old mode 100755 new mode 100644 diff --git a/smelt/sdl/makefile b/smelt/sdl/makefile index fc513d5..d58f077 100644 --- a/smelt/sdl/makefile +++ b/smelt/sdl/makefile @@ -1,29 +1,27 @@ CC= g++ CXXFLAGS= -c -g -O2 -std=c++11 -Wall -I/usr/include/SDL/ -I../include -D_LINUX -fPIC +TARGET= libsmelt.a all: objects-normal archive-normal -dumb: objects-dumb archive-dumb +dumb: CXXFLAGS += -DENABLE_DUMB +dumb: TARGET= libsmelt-dumb.a +dumb: all objects-normal: gfx inp sfx sys -objects-dumb: gfx inp sfx-dumb sys - gfx: $(CC) gfx_sdl.cpp $(CXXFLAGS) sfx: $(CC) sfx_sdl.cpp $(CXXFLAGS) -sfx-dumb: - $(CC) sfx_dumb.cpp $(CXXFLAGS) inp: $(CC) inp_sdl.cpp $(CXXFLAGS) sys: $(CC) sys_sdl.cpp $(CXXFLAGS) archive-normal: - $(AR) rcs libsmelt.a gfx_sdl.o sfx_sdl.o inp_sdl.o sys_sdl.o -archive-dumb: - $(AR) rcs libsmelt-dumb.a gfx_sdl.o sfx_dumb.o inp_sdl.o sys_sdl.o + $(AR) rcs $(TARGET) gfx_sdl.o sfx_sdl.o inp_sdl.o sys_sdl.o + clean: rm -f *.o clean-all: clean - rm *.a \ No newline at end of file + rm *.a diff --git a/smelt/sdl/sfx_dumb.cpp b/smelt/sdl/sfx_dumb.cpp index 4e7a277..69cae6e 100644 --- a/smelt/sdl/sfx_dumb.cpp +++ b/smelt/sdl/sfx_dumb.cpp @@ -6,13 +6,9 @@ * This dumb implementation has everything stubbed, useful if you don't * use the audio routines here. * - * WARNING: This library is in development and interfaces would be very - * unstable. + * WARNING: This file is not intended to be used on its own! * */ -#include "smelt_internal.hpp" - -static const char* SFX_SDL_SRCFN="smelt/sdl/sfx_dumb.cpp"; SMSFX SMELT_IMPL::smSFXLoad(const char *path) {return 0;} @@ -57,18 +53,11 @@ int SMELT_IMPL::smChannelGetPosd(SMCHN chn) void SMELT_IMPL::smChannelSetPosd(SMCHN chn,int pos) {} -ALuint SMELT_IMPL::getSource() -{return 0;} bool SMELT_IMPL::initOAL() { smLog("%s:" SLINE ": I'm dumb!\n",SFX_SDL_SRCFN); - pOpenALDevice=(void*)1; return true; } void SMELT_IMPL::finiOAL() { - if(pOpenALDevice) - { - pOpenALDevice=NULL; - } } diff --git a/smelt/sdl/sfx_sdl.cpp b/smelt/sdl/sfx_sdl.cpp index c49162a..2b0f87a 100644 --- a/smelt/sdl/sfx_sdl.cpp +++ b/smelt/sdl/sfx_sdl.cpp @@ -11,8 +11,11 @@ #include "smelt_internal.hpp" static const char* SFX_SDL_SRCFN="smelt/sdl/sfx_sdl.cpp"; +#ifndef ENABLE_DUMB +#ifdef ENABLE_OGG_SUPPORT struct oggdata{const BYTE *data;DWORD size,pos;}; static void* readVorbis(const BYTE *data,const DWORD size, ALsizei *decomp_size,ALenum *fmt,ALsizei *freq); +#endif static void* readRiffWv(const BYTE *data,const DWORD size, ALsizei *decomp_size,ALenum *fmt,ALsizei *freq); SMSFX SMELT_IMPL::smSFXLoad(const char *path) { @@ -33,16 +36,20 @@ SMSFX SMELT_IMPL::smSFXLoadFromMemory(const char *ptr,DWORD size) { if(pOpenALDevice&&!mute) { +#ifdef ENABLE_OGG_SUPPORT bool isOgg=size>4&&ptr[0]=='O'&&ptr[1]=='g'&&ptr[2]=='g'&&ptr[3]=='S'; +#endif void *decompdata=NULL,*decomp=NULL; ALsizei decompsize=0,freq=0; ALenum fmt=AL_FORMAT_STEREO16; decompdata=readRiffWv((const BYTE*)ptr,size,&decompsize,&fmt,&freq); +#ifdef ENABLE_OGG_SUPPORT if(!decompdata) { if(!isOgg)return 0; else decompdata=readVorbis((const BYTE*)ptr,size,&decompsize,&fmt,&freq); } +#endif if(!decompdata)return 0; decomp=decompdata; ALuint buff=0;alGenBuffers(1,&buff); @@ -205,6 +212,7 @@ void SMELT_IMPL::smChannelSetPosd(SMCHN chn,int pos) if(pOpenALDevice)alSourcei((ALuint)chn,AL_SAMPLE_OFFSET,(ALint)pos); } +#ifdef ENABLE_OGG_SUPPORT static size_t oggRead(void *ptr,size_t size,size_t nmemb,void *ds) { oggdata *data=(oggdata*)ds; @@ -276,6 +284,7 @@ static void* readVorbis(const BYTE *data,const DWORD size, ALsizei *decomp_size, } return NULL; } +#endif 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; @@ -354,3 +363,6 @@ void SMELT_IMPL::finiOAL() alcCloseDevice(dev);pOpenALDevice=NULL; } } +#else +#include "sfx_dumb.cpp" +#endif //ifndef ENABLE_DUMB diff --git a/smelt/sdl/smelt_config.hpp b/smelt/sdl/smelt_config.hpp index 0e56e8a..3d8c2ca 100644 --- a/smelt/sdl/smelt_config.hpp +++ b/smelt/sdl/smelt_config.hpp @@ -18,3 +18,13 @@ * Client-side vertex buffer size. */ #define VERTEX_BUFFER_SIZE 4000 + +/* + * Uncomment this to build a "dumb" version with no audio routines. + */ +//#define ENABLE_DUMB + +/* + * Undefine this to disable ogg support. + */ +#define ENABLE_OGG_SUPPORT diff --git a/smelt/sdl/smelt_internal.hpp b/smelt/sdl/smelt_internal.hpp index a14e151..c7a77fd 100644 --- a/smelt/sdl/smelt_internal.hpp +++ b/smelt/sdl/smelt_internal.hpp @@ -21,11 +21,15 @@ #include #include #include +#ifndef ENABLE_DUMB #include #include #include +#ifdef ENABLE_OGG_SUPPORT #include #include +#endif +#endif #ifdef WIN32 #include #include @@ -225,12 +229,14 @@ public: DWORD* decodeImage(BYTE *data,const char *fn,DWORD size,int &w,int &h); void *pOpenALDevice; + bool mute,lpp; bool initOAL(); void finiOAL(); - bool mute,lpp; +#ifndef ENABLE_DUMB int scnt; ALuint src[SRC_MAX]; ALuint getSource(); +#endif int posz,lkey; float posx,posy; diff --git a/smelt/sdl/sys_sdl.cpp b/smelt/sdl/sys_sdl.cpp index 5641f31..2c0ae93 100644 --- a/smelt/sdl/sys_sdl.cpp +++ b/smelt/sdl/sys_sdl.cpp @@ -132,6 +132,7 @@ bool SMELT_IMPL::smInit() if(!pSM->Active)pSM->focusChange(true); } SDL_ShowCursor(hideMouse?SDL_DISABLE:SDL_ENABLE); + SDL_EnableScreenSaver(); initInput(); if(!initOGL()){smFinale();return false;} if(!initOAL()){smFinale();return false;} -- cgit v1.2.3