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
This commit is contained in:
parent
4e3bf92435
commit
f2b31713b7
|
@ -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
|
||||
--------
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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++) {}
|
||||
|
|
Loading…
Reference in a new issue