Start moving away from wrapping libc stuff in akerror, and move towards akstdlib that does this for me
This commit is contained in:
31
src/game.c
31
src/game.c
@@ -6,6 +6,7 @@
|
||||
#include <akerror.h>
|
||||
#include <semver.h>
|
||||
|
||||
#include <akstdlib.h>
|
||||
#include <akgl/game.h>
|
||||
#include <akgl/controller.h>
|
||||
#include <akgl/tilemap.h>
|
||||
@@ -235,9 +236,8 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_save(char *fpath)
|
||||
|
||||
ATTEMPT {
|
||||
FAIL_ZERO_BREAK(errctx, fpath, AKERR_NULLPOINTER, "NULL file path");
|
||||
fp = fopen(fpath, "wb");
|
||||
FAIL_ZERO_BREAK(errctx, fp, errno, "%s", fpath);
|
||||
fwrite(&game, 1, sizeof(akgl_Game), fp);
|
||||
CATCH(errctx, aksl_fopen(fpath, "wb", &fp));
|
||||
CATCH(errctx, aksl_fwrite(&game, 1, sizeof(akgl_Game), fp));
|
||||
CATCH(errctx, akgl_game_save_actors(fp));
|
||||
} PROCESS(errctx) {
|
||||
} CLEANUP {
|
||||
@@ -256,18 +256,8 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_load_objectnamemap(FILE *fp, SDL_Pr
|
||||
|
||||
PREPARE_ERROR(errctx);
|
||||
while ( 1 ) {
|
||||
retval = fread((void *)&objname, 1, namelength, fp);
|
||||
FAIL_NONZERO_RETURN(
|
||||
errctx,
|
||||
(retval != namelength),
|
||||
AKERR_IO,
|
||||
"Corrupt save file");
|
||||
retval = fread((void *)&ptr, 1, ptrlength, fp);
|
||||
FAIL_NONZERO_RETURN(
|
||||
errctx,
|
||||
(retval != ptrlength),
|
||||
AKERR_IO,
|
||||
"Corrupt save file");
|
||||
CATCH(errctx, aksl_fread((void *)&objname, 1, namelength, fp));
|
||||
CATCH(errctx, aksl_fread((void *)&ptr, 1, ptrlength, fp));
|
||||
// End of the map
|
||||
if ( ptr == 0x00 && objname[0] == 0x00 ) {
|
||||
break;
|
||||
@@ -280,7 +270,7 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_load_objectnamemap(FILE *fp, SDL_Pr
|
||||
|
||||
// SDL_Properties objects can only use string keys, so we can't use the
|
||||
// old pointer as a key without first converting it to a string.
|
||||
memset((void *)&ptrstring, 0x00, 32);
|
||||
CATCH(errctx, aksl_memset((void *)&ptrstring, 0x00, 32));
|
||||
snprintf((char *)&ptrstring, 32, "%p", ptr);
|
||||
SDL_SetPointerProperty(
|
||||
map,
|
||||
@@ -344,13 +334,8 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_load(char *fpath)
|
||||
FAIL_ZERO_RETURN(errctx, fpath, AKERR_NULLPOINTER, "NULL file path");
|
||||
|
||||
ATTEMPT {
|
||||
fp = fopen(fpath, "rb");
|
||||
FAIL_ZERO_BREAK(errctx, fp, errno, "%s", fpath);
|
||||
FAIL_NONZERO_BREAK(
|
||||
errctx,
|
||||
(fread((void *)&savegame, 1, sizeof(akgl_Game), fp) < sizeof(akgl_Game)),
|
||||
AKERR_IO,
|
||||
"Corrupt save file");
|
||||
CATCH(errctx, aksl_fopen(fpath, "rb", &fp));
|
||||
CATCH(errctx, aksl_fread((void *)&savegame, 1, sizeof(akgl_Game), fp));
|
||||
CATCH(errctx, akgl_game_load_versioncmp("library", (char *)&savegame.libversion, (char *)AKGL_VERSION));
|
||||
CATCH(errctx, akgl_game_load_versioncmp("game", (char *)&savegame.version, (char *)&game.version));
|
||||
FAIL_NONZERO_RETURN(
|
||||
|
||||
Reference in New Issue
Block a user