From f2b31713b7f6a55eabc0864b485c6cc2ae4952de Mon Sep 17 00:00:00 2001 From: zicodxx <> Date: Sun, 27 Jun 2010 14:30:12 +0000 Subject: [PATCH] For playing music over SDL_mixer always use handle over PhysFS to save the path building mess; When building Jukebox path, only try to build full path if given path is actually a child of Searchpath --- CHANGELOG.txt | 1 + arch/sdl/digi_mixer_music.c | 38 +++++++++++-------------------------- arch/sdl/jukebox.c | 25 +++++++++--------------- 3 files changed, 21 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 9f4809799..522a1e4c0 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D1X-Rebirth Changelog 20100627 -------- main/game.c, main/game.h, main/gameseq.c: When starting, leaving or changing a level in any way, use more ordered approach to set Game_wind visible or invisible. Fixing timer-issues after level-change and makes hiding of Game_wind obsolete for certain messageboxes; Moved GameTime and weapon timer variables out of reset_time since this function is not appropriate for this and is not needed between levels anymore due to window management handling start/stop_time properly +arch/sdl/digi_mixer_music.c, main/jukebox.c: For playing music over SDL_mixer always use handle over PhysFS to save the path building mess; When building Jukebox path, only try to build full path if given path is actually a child of Searchpath 20100625 -------- diff --git a/arch/sdl/digi_mixer_music.c b/arch/sdl/digi_mixer_music.c index 0b28ec094..dc2011afd 100644 --- a/arch/sdl/digi_mixer_music.c +++ b/arch/sdl/digi_mixer_music.c @@ -70,8 +70,11 @@ void convert_hmp(char *filename, char *mid_filename) int mix_play_file(char *filename, int loop, void (*hook_finished_track)()) { + SDL_RWops *rw = NULL; + PHYSFS_file *filehandle = NULL; char tmp_file[PATH_MAX], real_filename[PATH_MAX], real_filename_absolute[PATH_MAX]; - char *basedir = "music", *fptr; + char *basedir = "music", *fptr, *buf = NULL; + int bufsize = 0; mix_free_music(); // stop and free what we're already playing, if anything @@ -98,33 +101,14 @@ int mix_play_file(char *filename, int loop, void (*hook_finished_track)()) loop = loop ? -1 : 1; // loop means loop infinitely, otherwise play once - current_music = Mix_LoadMUS(real_filename); - - // Could not open the file, yet. Try to get absolute path. - if (!current_music) + filehandle = PHYSFS_openRead(real_filename); + if (filehandle != NULL) { - PHYSFSX_getRealPath(real_filename, real_filename_absolute); - current_music = Mix_LoadMUS(real_filename_absolute); - } - - // Still no luck. Maybe the music is stored in an archive. Try that. - // NOTE: This method should basically always work - making the above steps unnecessary. But for now it stays the last resort for the sake of memory swallowed by 'buf'. - if (!current_music) - { - SDL_RWops *rw = NULL; - PHYSFS_file *filehandle = NULL; - char *buf = NULL; - int bufsize = 0; - - filehandle = PHYSFS_openRead(real_filename); - if (filehandle != NULL) - { - buf = realloc(buf, sizeof(char *)*PHYSFS_fileLength(filehandle)); - bufsize = PHYSFS_read(filehandle, buf, sizeof(char), PHYSFS_fileLength(filehandle)); - rw = SDL_RWFromConstMem(buf,bufsize*sizeof(char)); - PHYSFS_close(filehandle); - current_music = Mix_LoadMUS_RW(rw); - } + buf = realloc(buf, sizeof(char *)*PHYSFS_fileLength(filehandle)); + bufsize = PHYSFS_read(filehandle, buf, sizeof(char), PHYSFS_fileLength(filehandle)); + rw = SDL_RWFromConstMem(buf,bufsize*sizeof(char)); + PHYSFS_close(filehandle); + current_music = Mix_LoadMUS_RW(rw); } if (current_music) diff --git a/arch/sdl/jukebox.c b/arch/sdl/jukebox.c index cc1374104..4add08eca 100644 --- a/arch/sdl/jukebox.c +++ b/arch/sdl/jukebox.c @@ -60,33 +60,26 @@ void jukebox_load() char *p; const char *sep = PHYSFS_getDirSeparator(); - // make sure there's a proper path separator. + // build path properly. if (strlen(GameCfg.CMLevelMusicPath) >= strlen(sep)) { + char abspath[PATH_MAX+1]; + p = GameCfg.CMLevelMusicPath + strlen(GameCfg.CMLevelMusicPath) - strlen(sep); if (strcmp(p, sep)) strncat(GameCfg.CMLevelMusicPath, sep, PATH_MAX - 1 - strlen(GameCfg.CMLevelMusicPath)); + + if (PHYSFS_isDirectory(GameCfg.CMLevelMusicPath)) // it's a child of Sharepath, build full path + { + PHYSFSX_getRealPath(GameCfg.CMLevelMusicPath,abspath); + snprintf(GameCfg.CMLevelMusicPath,sizeof(char)*PATH_MAX,abspath); + } } PHYSFS_addToSearchPath(GameCfg.CMLevelMusicPath, 0); // as mountpoints are no option (yet), make sure only files originating from GameCfg.CMLevelMusicPath are aded to the list. JukeboxSongs = PHYSFSX_findabsoluteFiles("", GameCfg.CMLevelMusicPath, music_exts); - // If we do not find anything, try to see if given path is child of Searchpath - if (JukeboxSongs != NULL) - { - for (count = 0; JukeboxSongs[count]!=NULL; count++) {} - if (!count) - { - char absolute_path[PATH_MAX + 1]; - PHYSFS_removeFromSearchPath(GameCfg.CMLevelMusicPath); - PHYSFSX_getRealPath(GameCfg.CMLevelMusicPath,absolute_path); - memcpy(GameCfg.CMLevelMusicPath,absolute_path,sizeof(char)*PATH_MAX); - PHYSFS_addToSearchPath(GameCfg.CMLevelMusicPath, 0); - JukeboxSongs = PHYSFSX_findabsoluteFiles("", GameCfg.CMLevelMusicPath, music_exts); - } - } - if (JukeboxSongs != NULL) { for (count = 0; JukeboxSongs[count]!=NULL; count++) {}