2025-08-03 10:07:35 -04:00
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
|
#include <SDL3_image/SDL_image.h>
|
|
|
|
|
#include <SDL3_mixer/SDL_mixer.h>
|
2026-01-05 08:58:06 -05:00
|
|
|
#include <akerror.h>
|
2025-08-03 10:41:09 -04:00
|
|
|
#include <sdl3game/game.h>
|
|
|
|
|
#include <sdl3game/staticstring.h>
|
|
|
|
|
#include <sdl3game/heap.h>
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
ErrorContext *load_start_bgm(char *fname)
|
|
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2025-08-09 08:54:12 -04:00
|
|
|
//string *tmpstr = NULL;
|
2025-08-03 10:07:35 -04:00
|
|
|
MIX_Track *bgmtrack = NULL;
|
|
|
|
|
SDL_PropertiesID bgmprops = 0;
|
|
|
|
|
|
|
|
|
|
ATTEMPT {
|
|
|
|
|
FAIL_ZERO_BREAK(errctx, fname, ERR_NULLPOINTER, "load_start_bgm received NULL filename");
|
2025-08-09 08:54:12 -04:00
|
|
|
//CATCH(errctx, heap_next_string(&tmpstr));
|
|
|
|
|
//CATCH(errctx, string_initialize(tmpstr, NULL));
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2025-08-09 08:54:12 -04:00
|
|
|
//SDL_snprintf((char *)&tmpstr->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), fname);
|
|
|
|
|
SDL_Log("Loading music asset from %s", fname);
|
|
|
|
|
bgm = MIX_LoadAudio(game.mixer, fname, true);
|
|
|
|
|
FAIL_ZERO_BREAK(errctx, bgm, ERR_NULLPOINTER, "Failed to load music asset %s : %s", fname, SDL_GetError());
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2025-08-03 15:14:36 -04:00
|
|
|
bgmtrack = MIX_CreateTrack(game.mixer);
|
2025-08-03 10:07:35 -04:00
|
|
|
FAIL_ZERO_BREAK(errctx, bgmtrack, ERR_NULLPOINTER, "Failed to create audio track for background music: %s", SDL_GetError());
|
|
|
|
|
|
2025-08-03 15:14:36 -04:00
|
|
|
game.tracks[GAME_AUDIO_TRACK_BGM] = bgmtrack;
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
FAIL_ZERO_BREAK(
|
|
|
|
|
errctx,
|
|
|
|
|
MIX_SetTrackAudio(bgmtrack, bgm),
|
|
|
|
|
ERR_SDL,
|
|
|
|
|
"%s",
|
|
|
|
|
SDL_GetError());
|
|
|
|
|
|
|
|
|
|
SDL_SetNumberProperty(bgmprops, MIX_PROP_PLAY_LOOPS_NUMBER, -1);
|
|
|
|
|
|
|
|
|
|
if (!MIX_PlayTrack(bgmtrack, bgmprops)) {
|
|
|
|
|
FAIL_BREAK(errctx, ERR_SDL, "Failed to play music asset %s", fname);
|
|
|
|
|
}
|
|
|
|
|
} CLEANUP {
|
2025-08-09 08:54:12 -04:00
|
|
|
//IGNORE(heap_release_string(tmpstr));
|
2025-08-03 10:07:35 -04:00
|
|
|
if ( errctx != NULL ) {
|
|
|
|
|
if ( errctx->status != 0 && bgm != NULL) {
|
|
|
|
|
MIX_DestroyAudio(bgm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} PROCESS(errctx) {
|
|
|
|
|
} FINISH(errctx, true);
|
|
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|