Move music tracks out of akgl_Game to make it more suitable for serialization

This commit is contained in:
2026-05-08 22:16:43 -04:00
parent e0a59e2447
commit 0bd1ae1df8
4 changed files with 32 additions and 11 deletions

View File

@@ -23,8 +23,8 @@ akgl_Frame paddle2;
akgl_Frame table;
akgl_Tilemap gamemap;
MIX_Audio *bgm = NULL;
MIX_Mixer *GAME_mixer = NULL;
MIX_Track *GAME_tracks[64];
MIX_Mixer *akgl_mixer = NULL;
MIX_Track *akgl_tracks[AKGL_GAME_AUDIO_MAX_TRACKS];
SDL_FRect camera;
akgl_Game game;
@@ -86,10 +86,10 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_init()
AKGL_ERR_SDL,
"Couldn't initialize audio: %s",
SDL_GetError());
game.mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, 0);
akgl_mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, 0);
FAIL_ZERO_RETURN(
errctx,
game.mixer,
akgl_mixer,
AKGL_ERR_SDL,
"Unable to create mixer device: %s",
SDL_GetError());
@@ -134,6 +134,27 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_save(char *fpath)
akerr_ErrorContext AKERR_NOIGNORE *akgl_game_load(char *fpath)
{
FILE *fp = NULL;
char version[32];
PREPARE_ERROR(errctx);
FAIL_ZERO_RETURN(errctx, fpath, AKERR_NULLPOINTER, "NULL file path");
fp = fopen(fpath, "rb");
FAIL_ZERO_RETURN(
errctx,
(fread((void *)&version, 1, 32, fp) < 32),
AKERR_IO,
"Corrupt save file");
FAIL_ZERO_RETURN(
errctx,
strncmp((char *)&game.version, (char *)&version, 32),
AKERR_API,
"Save game can not be loaded, it is from an incompatible version");
rewind(fp);
FAIL_ZERO_RETURN(
errctx,
(fread((void *)&game, 1, sizeof(akgl_Game), fp) < sizeof(akgl_Game)),
AKERR_IO,
"Corrupt save file");
SUCCEED(errctx);
}