diff --git a/src/bgi.c b/src/bgi.c index 12e8d52..f9a9f9d 100644 --- a/src/bgi.c +++ b/src/bgi.c @@ -48,14 +48,14 @@ static char *bgi_gets(char *buf, int n, FILE *fp) { return buf; } -int bgi_read(const char *path) { +bool bgi_read(const char *path) { if (!path) - return NG; + return false; FILE *fp = fopen(path, "rb"); if (!fp) { WARNING("Could not open %s", path); - return NG; + return false; } char buf[100]; @@ -72,7 +72,7 @@ int bgi_read(const char *path) { } bgi_nfile++; } - return OK; + return true; } bgi_t *bgi_find(int no) { diff --git a/src/bgi.h b/src/bgi.h index 7589c0d..0ede362 100644 --- a/src/bgi.h +++ b/src/bgi.h @@ -23,6 +23,8 @@ #ifndef _BGI_H__ #define _BGI_H__ +#include + typedef struct { int no; // シナリオ上での曲番号 int loopno; // ループ回数 (0の場合は無限) @@ -30,7 +32,7 @@ typedef struct { int len; // 曲長さ (サンプル数) } bgi_t; -extern int bgi_read(const char *path); +extern bool bgi_read(const char *path); extern bgi_t *bgi_find(int no); #endif /* _BGI_H__ */ diff --git a/src/bgm.emscripten.c b/src/bgm.emscripten.c index d0d3647..b3722eb 100644 --- a/src/bgm.emscripten.c +++ b/src/bgm.emscripten.c @@ -26,38 +26,34 @@ #include "bgi.h" #include "sdl_core.h" -int musbgm_init(DRIFILETYPE type, int base_no) { +bool musbgm_init(DRIFILETYPE type, int base_no) { if (type == DRIFILE_BGM) return bgi_read(nact->files.bgi); else EM_ASM({ xsystem35.cdPlayer.setBGMLoader($0, $1); }, type, base_no); - return OK; + return true; } -int musbgm_exit(void) { +void musbgm_exit(void) { musbgm_stopall(0); - return OK; } -int musbgm_reset(void) { +void musbgm_reset(void) { musbgm_stopall(0); - return OK; } -EM_JS(int, musbgm_play, (int no, int time, int vol, int loop_count), { +EM_JS(bool, musbgm_play, (int no, int time, int vol, int loop_count), { xsystem35.cdPlayer.fade(time * 10, vol / 100); xsystem35.cdPlayer.play(no, loop_count == 0); - return xsystem35.Status.OK; + return 1; }); -EM_JS(int, musbgm_stop, (int no, int time), { +EM_JS(void, musbgm_stop, (int no, int time), { xsystem35.cdPlayer.stop(time * 10); - return xsystem35.Status.OK; }); -EM_JS(int, musbgm_fade, (int no, int time, int vol), { +EM_JS(void, musbgm_fade, (int no, int time, int vol), { xsystem35.cdPlayer.fade(time * 10, vol / 100); - return xsystem35.Status.OK; }); int musbgm_getpos(int no) { @@ -75,20 +71,19 @@ int musbgm_getlen(int no) { return bgi->len / 441; } -int musbgm_isplaying(int no) { +bool musbgm_isplaying(int no) { int t = EM_ASM_INT_V( return xsystem35.cdPlayer.getPosition(); ); return ((t & 0xff) == no); } -int musbgm_stopall(int time) { - return musbgm_stop(0, time); +void musbgm_stopall(int time) { + musbgm_stop(0, time); } -int musbgm_wait(int no, int timeout) { +void musbgm_wait(int no, int timeout) { for (int i = 0; i * 16 < timeout * 10; i++) { if (!musbgm_isplaying(no)) break; sdl_wait_vsync(); } - return OK; } diff --git a/src/bgm.h b/src/bgm.h index 3c85df9..1c5d57a 100644 --- a/src/bgm.h +++ b/src/bgm.h @@ -19,18 +19,19 @@ #ifndef __BGM_H__ #define __BGM_H__ +#include #include "ald_manager.h" -int musbgm_init(DRIFILETYPE type, int base_no); -int musbgm_exit(void); -int musbgm_reset(void); -int musbgm_play(int no, int time, int vol, int loop_count); -int musbgm_stop(int no, int time); -int musbgm_fade(int no, int time, int vol); +bool musbgm_init(DRIFILETYPE type, int base_no); +void musbgm_exit(void); +void musbgm_reset(void); +bool musbgm_play(int no, int time, int vol, int loop_count); +void musbgm_stop(int no, int time); +void musbgm_fade(int no, int time, int vol); int musbgm_getpos(int no); int musbgm_getlen(int no); -int musbgm_isplaying(int no); -int musbgm_stopall(int time); -int musbgm_wait(int no, int timeout); +bool musbgm_isplaying(int no); +void musbgm_stopall(int time); +void musbgm_wait(int no, int timeout); #endif /* __BGM_H__ */ diff --git a/src/bgm.sdlmixer.c b/src/bgm.sdlmixer.c index a62b7b7..bdbdf23 100644 --- a/src/bgm.sdlmixer.c +++ b/src/bgm.sdlmixer.c @@ -78,30 +78,28 @@ static Mix_Music *bgm_load(int no) { return mix_music; } -int musbgm_init(DRIFILETYPE type, int base) { +bool musbgm_init(DRIFILETYPE type, int base) { dri_type = type; base_no = base; if (type == DRIFILE_BGM) return bgi_read(nact->files.bgi); - return OK; + return true; } -int musbgm_exit(void) { +void musbgm_exit(void) { free_music(); - return OK; } -int musbgm_reset(void) { +void musbgm_reset(void) { free_music(); - return OK; } -int musbgm_play(int no, int time, int vol, int loop_count) { +bool musbgm_play(int no, int time, int vol, int loop_count) { if (current_no) musbgm_stop(current_no, 0); if (!bgm_load(no)) - return NG; + return false; // We don't use the loop information in the BGI file, but SDL_mixer // understands loop info in the WAVE's "smpl" chunk. @@ -109,26 +107,24 @@ int musbgm_play(int no, int time, int vol, int loop_count) { Mix_VolumeMusic(vol * MIX_MAX_VOLUME / 100); if (Mix_FadeInMusic(mix_music, loop_count == 0 ? -1 : loop_count, time * 10) != 0) { free_music(); - return NG; + return false; } start_time = SDL_GetTicks(); - return OK; + return true; } -int musbgm_stop(int no, int time) { +void musbgm_stop(int no, int time) { if (no == current_no) Mix_FadeOutMusic(time * 10); - return OK; } -int musbgm_fade(int no, int time, int vol) { +void musbgm_fade(int no, int time, int vol) { if (no != current_no) - return NG; + return; // SDL_mixer doesn't provide arbitrary fading, so just set the volume immediately. Mix_VolumeMusic(vol * MIX_MAX_VOLUME / 100); - return OK; } int musbgm_getpos(int no) { @@ -147,16 +143,15 @@ int musbgm_getlen(int no) { return bgi->len / 441; } -int musbgm_isplaying(int no) { +bool musbgm_isplaying(int no) { return no == current_no && Mix_PlayingMusic(); } -int musbgm_stopall(int time) { - return musbgm_stop(current_no, time); +void musbgm_stopall(int time) { + musbgm_stop(current_no, time); } -int musbgm_wait(int no, int timeout) { +void musbgm_wait(int no, int timeout) { while (timeout-- > 0 && musbgm_isplaying(no)) SDL_Delay(10); - return OK; } diff --git a/src/cdrom.bgm.c b/src/cdrom.bgm.c index feeca4a..10cf1bd 100644 --- a/src/cdrom.bgm.c +++ b/src/cdrom.bgm.c @@ -42,7 +42,7 @@ static void cdrom_bgm_reset(void) { } static bool cdrom_bgm_start(int trk, int loop) { - if (musbgm_play(trk, 0, 100, loop) != OK) + if (!musbgm_play(trk, 0, 100, loop)) return false; current_track = trk; return true; diff --git a/src/music_cdrom.c b/src/music_cdrom.c index 2a2151d..f1d163e 100644 --- a/src/music_cdrom.c +++ b/src/music_cdrom.c @@ -58,7 +58,7 @@ int muscd_init(void) { int muscd_init_bgm(DRIFILETYPE type, int base_no) { muscd_exit(); prv.cddev = &cdrom_bgm; - return musbgm_init(type, base_no); + return musbgm_init(type, base_no) ? OK : NG; } int muscd_exit(void) {