diff --git a/Rules.make.standalone b/Rules.make.standalone index cb275c2..afe4404 100644 --- a/Rules.make.standalone +++ b/Rules.make.standalone @@ -27,7 +27,7 @@ LUA_LFLAGS=$(shell pkg-config --libs lua5.1) SDL_CFLAGS=$(shell sdl-config --cflags) SDL_LFLAGS=$(shell sdl-config --libs) -lSDL_ttf -lSDL_mixer -lSDL_image -CFLAGS += -g -Wall -D_HAVE_ICONV -Dunix -D_USE_UNPACK -D_LOCAL_APPDATA +CFLAGS += -g -Wall -D_HAVE_ICONV -Dunix -D_USE_UNPACK -D_LOCAL_APPDATA # -D_SDL_MOD_BUG INSTALLD=echo "Do not install standalone version!" INSTALLB=echo "Do not install standalone version!" diff --git a/Rules.make.system b/Rules.make.system index c5f71e9..bc70dec 100644 --- a/Rules.make.system +++ b/Rules.make.system @@ -28,7 +28,7 @@ LUA_LFLAGS=$(shell pkg-config --libs lua5.1) SDL_CFLAGS=$(shell sdl-config --cflags) SDL_LFLAGS=$(shell sdl-config --libs) -lSDL_ttf -lSDL_mixer -lSDL_image -CFLAGS += -Wall -Dunix -D_HAVE_ICONV -D_USE_UNPACK +CFLAGS += -Wall -Dunix -D_HAVE_ICONV -D_USE_UNPACK # -D_SDL_MOD_BUG INSTALLD=install -d -m 0755 INSTALLB=install -m 0755 diff --git a/Rules.mingw b/Rules.mingw index 5b6965d..3416fef 100644 --- a/Rules.mingw +++ b/Rules.mingw @@ -21,7 +21,7 @@ LUA_LFLAGS=-llua5.1 -L../windows/ SDL_CFLAGS=-I../windows/SDL SDL_LFLAGS=-lSDL -lSDLmain -lSDL_ttf -lSDL_mixer -lSDL_image -L../windows/SDL -CFLAGS += -Wall -mwindows -D_HAVE_ICONV -D_USE_UNPACK -D_USE_BROWSE -D_LOCAL_APPDATA +CFLAGS += -Wall -mwindows -D_HAVE_ICONV -D_USE_UNPACK -D_USE_BROWSE -D_LOCAL_APPDATA -D_SDL_MOD_BUG LDFLAGS += -liconv CC=i486-mingw32-gcc diff --git a/Rules.windows b/Rules.windows index 1bb7b70..35c4c3c 100644 --- a/Rules.windows +++ b/Rules.windows @@ -20,7 +20,7 @@ LUA_LFLAGS=-llua5.1 SDL_CFLAGS=-IC:\MinGW\include\SDL SDL_LFLAGS=-lSDL -lSDLmain -lSDL_ttf -lSDL_mixer -lSDL_image -CFLAGS += -Wall -mwindows -D_HAVE_ICONV -D_USE_UNPACK -D_USE_BROWSE -D_LOCAL_APPDATA +CFLAGS += -Wall -mwindows -D_HAVE_ICONV -D_USE_UNPACK -D_USE_BROWSE -D_LOCAL_APPDATA -D_SDL_MOD_BUG LDFLAGS += -liconv CC=gcc diff --git a/src/sdl-instead/graphics.c b/src/sdl-instead/graphics.c index 9f9e67e..4414529 100644 --- a/src/sdl-instead/graphics.c +++ b/src/sdl-instead/graphics.c @@ -640,7 +640,6 @@ static img_t _gfx_load_image(char *filename) if (IMG_isBMP(rwop)) SDL_SetAlpha(img, SDL_RLEACCEL, SDL_ALPHA_OPAQUE); SDL_RWclose(rwop); -/* SDL_FreeRW(rwop); */ } } return img; diff --git a/src/sdl-instead/sound.c b/src/sdl-instead/sound.c index b9a189c..b9af001 100644 --- a/src/sdl-instead/sound.c +++ b/src/sdl-instead/sound.c @@ -4,14 +4,12 @@ #include #include -Mix_Music *music = NULL; - int audio_rate = 22050; Uint16 audio_format = MIX_DEFAULT_FORMAT; int audio_channels = 2; int audio_buffers = 8192; -static Mix_Music *mus; +static mus_t mus; static char *next_mus = NULL; static int next_fadein = 0; static int next_loop = -1; @@ -19,6 +17,11 @@ static SDL_TimerID timer_id = NULL; static int sound_on = 0; +struct _mus_t { + Mix_Music *mus; + SDL_RWops *rw; +}; + static void mus_callback(void *aux) { if (!timer_id) @@ -135,13 +138,26 @@ void snd_halt_chan(int han, int ms) Mix_HaltChannel(han); } -Mix_Music *snd_load_mus(const char *fname) +mus_t snd_load_mus(const char *fname) { - Mix_Music *mus; + mus_t mus = NULL; if (!sound_on) return NULL; - mus = Mix_LoadMUS(fname); + mus = malloc(sizeof(struct _mus_t)); + if (!mus) + return NULL; + mus->rw = SDL_RWFromFile(fname, "rb"); + if (!mus->rw) + goto err; + mus->mus = Mix_LoadMUS_RW(mus->rw); + if (!mus->mus) + goto err1; return mus; +err1: + SDL_RWclose(mus->rw); +err: + free(mus); + return NULL; } extern void game_music_finished(void); @@ -174,9 +190,9 @@ int snd_play_mus(char *fname, int ms, int loop) else Mix_HookMusicFinished(NULL); if (ms) - Mix_FadeInMusic((Mix_Music*)mus, loop, ms); + Mix_FadeInMusic(mus->mus, loop, ms); else - Mix_PlayMusic((Mix_Music*)mus, loop); + Mix_PlayMusic(mus->mus, loop); snd_volume_mus(snd_volume_mus(-1)); // SDL hack? return 0; } @@ -216,8 +232,17 @@ void snd_free_mus(mus_t mus) { if (!sound_on) return; + if (!mus) + return; Mix_HaltMusic(); - Mix_FreeMusic((Mix_Music*) mus); + if (mus->mus) { +#ifdef _SDL_MOD_BUG + if (Mix_GetMusicType(mus->mus) == MUS_MOD) + SDL_RWclose(mus->rw); +#endif + Mix_FreeMusic((Mix_Music*) mus->mus); + } + free(mus); } int snd_play(void *chunk, int channel, int loop) @@ -246,7 +271,7 @@ void snd_done(void) Mix_HaltMusic(); timer_id = NULL; if (mus) - Mix_FreeMusic((Mix_Music*) mus); + snd_free_mus(mus); mus = NULL; if (next_mus) free(next_mus); diff --git a/src/sdl-instead/sound.h b/src/sdl-instead/sound.h index 346f0dc..3044d66 100644 --- a/src/sdl-instead/sound.h +++ b/src/sdl-instead/sound.h @@ -2,7 +2,7 @@ #define __SOUND_H__ typedef void* wav_t; -typedef void* mus_t; +typedef struct _mus_t *mus_t; //extern mus_t snd_load_mus(const char *path); extern void snd_free_mus(mus_t mus);