diff options
author | kdx <kikoodx@paranoici.org> | 2023-05-02 23:54:10 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-05-02 23:54:10 +0200 |
commit | 90ece2581ea402b960543f470c7972e1bd329e6d (patch) | |
tree | b547e80f35c809eda0f1db035fbd33ea6bc3154e | |
parent | 34bdf3c6c5fc1853c0e2b7c8cdfb2425b1013cd7 (diff) | |
download | px-90ece2581ea402b960543f470c7972e1bd329e6d.tar.gz |
update tzr
-rw-r--r-- | src/TZR.c | 33 | ||||
-rw-r--r-- | src/TZR.h | 9 |
2 files changed, 40 insertions, 2 deletions
@@ -81,6 +81,7 @@ TZR_KeyState ___tzr_mousestates[256] = {0}; //doc says than mouse button is u8 float ___tzr_scale = 1.0; int ___tzr_off_x = 1.0; int ___tzr_off_y = 1.0; +Mix_Music *___tzr_music = NULL; /* sources/TZR_CycleEvents.c */ void @@ -763,6 +764,23 @@ TZR_MainLoop(int (*main_loop)(void *udata), void *udata) } #endif +/* sources/TZR_PlayMusic.c */ + +int +TZR_PlayMusic(const char *path, int loop) +{ + if (!___tzr_config.mixer) { + fprintf(stderr, "mixer is disabled\n"); + return -1; + } + TZR_StopMusic(); + ___tzr_music = Mix_LoadMUS(path); + if (___tzr_music == NULL) + return sdl_error(-1); + if (Mix_PlayMusic(___tzr_music, loop) < 0) + return sdl_error(-1); + return 0; +} /* sources/TZR_PlaySound.c */ int @@ -936,6 +954,19 @@ TZR_ShouldQuit(void) { return ___tzr_should_quit; } +/* sources/TZR_StopMusic.c */ + +void +TZR_StopMusic(void) +{ + if (!___tzr_config.mixer) + return; + if (Mix_PlayingMusic()) + Mix_HaltMusic(); + if (___tzr_music != NULL) + Mix_FreeMusic(___tzr_music); + ___tzr_music = NULL; +} /* ** Copyright (c) 2023 kdx @@ -958,4 +989,4 @@ TZR_ShouldQuit(void) ** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS ** IN THE SOFTWARE. */ -/* commit hash: 6044a3bac4433e9ce8d114bdbc180ca7b48b2344 */ +/* commit hash: a4112e4311eb226c4f43cb697aa7f6c34bd7b9a5 */ @@ -51,6 +51,7 @@ typedef struct TZR_Sound TZR_Sound; typedef struct TZR_Resource TZR_Resource; typedef enum TZR_EventType TZR_EventType; typedef struct TZR_Event TZR_Event; +typedef struct TZR_Music TZR_Music; typedef struct TZR_DrawImageArgs TZR_DrawImageArgs; typedef struct TZR_DrawRectangleArgs TZR_DrawRectangleArgs; typedef struct TZR_PlaySoundArgs TZR_PlaySoundArgs; @@ -174,6 +175,7 @@ extern TZR_KeyState ___tzr_mousestates[256]; extern float ___tzr_scale; extern int ___tzr_off_x; extern int ___tzr_off_y; +extern Mix_Music *___tzr_music; /* headers/TZR_resource.h */ #define TZR_RES TZR_LoadResource @@ -236,6 +238,11 @@ void TZR_DestroyResource(TZR_Resource *res, int free_path); #endif #endif int _TZR_PlaySound(const TZR_PlaySoundArgs *args); + +/* Return -1 on error. */ +int TZR_PlayMusic(const char *path, int loop); + +void TZR_StopMusic(void); /* headers/TZR_events.h */ /* Write event data to `e`. Return 0 when event queue is empty. */ @@ -407,4 +414,4 @@ unsigned long TZR_GetTick(void); ** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS ** IN THE SOFTWARE. */ -/* commit hash: 6044a3bac4433e9ce8d114bdbc180ca7b48b2344 */ +/* commit hash: a4112e4311eb226c4f43cb697aa7f6c34bd7b9a5 */ |