Got the suite rebuilding, most tests pass, actor and sprite are failing
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
#include <sdl3game/staticstring.h>
|
||||
#include <sdl3game/game.h>
|
||||
|
||||
ErrorContext *get_json_tilemap_property(json_t *obj, char *key, char *type, json_t **dest)
|
||||
akerr_ErrorContext *get_json_tilemap_property(json_t *obj, char *key, char *type, json_t **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
json_t *properties = NULL;
|
||||
@@ -22,8 +22,8 @@ ErrorContext *get_json_tilemap_property(json_t *obj, char *key, char *type, json
|
||||
int i = 0;
|
||||
// This is not a generic JSON helper. It assumes we are receiving an object with a 'properties' key
|
||||
// inside of it. That key is an array of objects, and each object has a name, type, and value.
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL json obj reference");
|
||||
FAIL_ZERO_RETURN(errctx, key, ERR_NULLPOINTER, "NULL key string");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL json obj reference");
|
||||
FAIL_ZERO_RETURN(errctx, key, AKERR_NULLPOINTER, "NULL key string");
|
||||
ATTEMPT {
|
||||
CATCH(errctx, get_json_array_value(obj, "properties", &properties));
|
||||
for (i = 0; i < json_array_size(properties); i++) {
|
||||
@@ -35,7 +35,7 @@ ErrorContext *get_json_tilemap_property(json_t *obj, char *key, char *type, json
|
||||
}
|
||||
CATCH(errctx, get_json_string_value(property, "type", &tmpstr));
|
||||
if ( strcmp(tmpstr->data, type) != 0 ) {
|
||||
FAIL_BREAK(errctx, ERR_TYPE, "Character property is present but is incorrect type");
|
||||
FAIL_BREAK(errctx, AKERR_TYPE, "Character property is present but is incorrect type");
|
||||
}
|
||||
*dest = property;
|
||||
SUCCEED_RETURN(errctx);
|
||||
@@ -47,11 +47,11 @@ ErrorContext *get_json_tilemap_property(json_t *obj, char *key, char *type, json
|
||||
} PROCESS(errctx) {
|
||||
} FINISH(errctx, true);
|
||||
|
||||
FAIL_RETURN(errctx, ERR_KEY, "Property not found in properties map");
|
||||
FAIL_RETURN(errctx, AKERR_KEY, "Property not found in properties map");
|
||||
}
|
||||
|
||||
|
||||
ErrorContext *get_json_properties_string(json_t *obj, char *key, string **dest)
|
||||
akerr_ErrorContext *get_json_properties_string(json_t *obj, char *key, string **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
json_t *property;
|
||||
@@ -68,7 +68,7 @@ ErrorContext *get_json_properties_string(json_t *obj, char *key, string **dest)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *get_json_properties_integer(json_t *obj, char *key, int *dest)
|
||||
akerr_ErrorContext *get_json_properties_integer(json_t *obj, char *key, int *dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
json_t *property = NULL;
|
||||
@@ -82,7 +82,7 @@ ErrorContext *get_json_properties_integer(json_t *obj, char *key, int *dest)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *tilemap_load_tilesets_each(json_t *tileset, tilemap *dest, int tsidx)
|
||||
akerr_ErrorContext *tilemap_load_tilesets_each(json_t *tileset, tilemap *dest, int tsidx)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
string *tmpstr = NULL;
|
||||
@@ -113,7 +113,7 @@ ErrorContext *tilemap_load_tilesets_each(json_t *tileset, tilemap *dest, int tsi
|
||||
);
|
||||
|
||||
dest->tilesets[tsidx].texture = IMG_LoadTexture(renderer, (char *)&dest->tilesets[tsidx].imagefilename);
|
||||
FAIL_ZERO_BREAK(errctx, dest->tilesets[tsidx].texture, ERR_NULLPOINTER, "Failed loading tileset image");
|
||||
FAIL_ZERO_BREAK(errctx, dest->tilesets[tsidx].texture, AKERR_NULLPOINTER, "Failed loading tileset image");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} FINISH(errctx, true);
|
||||
@@ -121,7 +121,7 @@ ErrorContext *tilemap_load_tilesets_each(json_t *tileset, tilemap *dest, int tsi
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *tilemap_compute_tileset_offsets(tilemap *dest, int tilesetidx)
|
||||
akerr_ErrorContext *tilemap_compute_tileset_offsets(tilemap *dest, int tilesetidx)
|
||||
{
|
||||
int x_offset = 0;
|
||||
int y_offset = 0;
|
||||
@@ -176,11 +176,11 @@ ErrorContext *tilemap_compute_tileset_offsets(tilemap *dest, int tilesetidx)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *tilemap_load_tilesets(tilemap *dest, json_t *root)
|
||||
akerr_ErrorContext *tilemap_load_tilesets(tilemap *dest, json_t *root)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, dest, ERR_NULLPOINTER, "Received NULL tilemap pointer");
|
||||
FAIL_ZERO_RETURN(errctx, root, ERR_NULLPOINTER, "Received NULL json object pointer");
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "Received NULL tilemap pointer");
|
||||
FAIL_ZERO_RETURN(errctx, root, AKERR_NULLPOINTER, "Received NULL json object pointer");
|
||||
|
||||
json_t *tilesets = NULL;
|
||||
json_t *jstileset = NULL;
|
||||
@@ -202,7 +202,7 @@ ErrorContext *tilemap_load_tilesets(tilemap *dest, json_t *root)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *tilemap_load_layer_object_actor(tilemap_object *curobj, json_t *layerdatavalue, int layerid)
|
||||
akerr_ErrorContext *tilemap_load_layer_object_actor(tilemap_object *curobj, json_t *layerdatavalue, int layerid)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
string *tmpstr = NULL;
|
||||
@@ -210,7 +210,7 @@ ErrorContext *tilemap_load_layer_object_actor(tilemap_object *curobj, json_t *la
|
||||
|
||||
curobj->type = TILEMAP_OBJECT_TYPE_ACTOR;
|
||||
if ( strlen((char *)&curobj->name) == 0 ) {
|
||||
FAIL_RETURN(errctx, ERR_KEY, "Actor in tile object layer cannot have empty name");
|
||||
FAIL_RETURN(errctx, AKERR_KEY, "Actor in tile object layer cannot have empty name");
|
||||
}
|
||||
|
||||
ATTEMPT {
|
||||
@@ -246,7 +246,7 @@ ErrorContext *tilemap_load_layer_object_actor(tilemap_object *curobj, json_t *la
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *tilemap_load_layer_objects(tilemap *dest, json_t *root, int layerid)
|
||||
akerr_ErrorContext *tilemap_load_layer_objects(tilemap *dest, json_t *root, int layerid)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
json_t *layerdata = NULL;
|
||||
@@ -257,8 +257,8 @@ ErrorContext *tilemap_load_layer_objects(tilemap *dest, json_t *root, int layeri
|
||||
tilemap_object *curobj = NULL;
|
||||
string *tmpstr = NULL;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, dest, ERR_NULLPOINTER, "NULL destination tilemap reference");
|
||||
FAIL_ZERO_RETURN(errctx, root, ERR_NULLPOINTER, "NULL tilemap root reference");
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "NULL destination tilemap reference");
|
||||
FAIL_ZERO_RETURN(errctx, root, AKERR_NULLPOINTER, "NULL tilemap root reference");
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, get_json_array_value(root, "objects", &layerdata));
|
||||
@@ -287,15 +287,15 @@ ErrorContext *tilemap_load_layer_objects(tilemap *dest, json_t *root, int layeri
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *tilemap_load_layer_tile(tilemap *dest, json_t *root, int layerid)
|
||||
akerr_ErrorContext *tilemap_load_layer_tile(tilemap *dest, json_t *root, int layerid)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
json_t *layerdata = NULL;
|
||||
int j;
|
||||
int layerdatalen;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, dest, ERR_NULLPOINTER, "NULL destination tilemap reference");
|
||||
FAIL_ZERO_RETURN(errctx, root, ERR_NULLPOINTER, "NULL tilemap root reference");
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "NULL destination tilemap reference");
|
||||
FAIL_ZERO_RETURN(errctx, root, AKERR_NULLPOINTER, "NULL tilemap root reference");
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, get_json_integer_value(root, "height", &dest->layers[layerid].height));
|
||||
@@ -303,7 +303,7 @@ ErrorContext *tilemap_load_layer_tile(tilemap *dest, json_t *root, int layerid)
|
||||
CATCH(errctx, get_json_array_value(root, "data", &layerdata));
|
||||
layerdatalen = (dest->layers[layerid].width * dest->layers[layerid].height);
|
||||
if ( layerdatalen >= (TILEMAP_MAX_WIDTH * TILEMAP_MAX_HEIGHT) ) {
|
||||
FAIL_BREAK(errctx, ERR_OUTOFBOUNDS, "Map layer exceeds the maximum size");
|
||||
FAIL_BREAK(errctx, AKERR_OUTOFBOUNDS, "Map layer exceeds the maximum size");
|
||||
}
|
||||
for ( j = 0; j < layerdatalen; j++ ) {
|
||||
CATCH(errctx, get_json_array_index_integer(layerdata, j, &dest->layers[layerid].data[j]));
|
||||
@@ -315,11 +315,11 @@ ErrorContext *tilemap_load_layer_tile(tilemap *dest, json_t *root, int layerid)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *tilemap_load_layers(tilemap *dest, json_t *root)
|
||||
akerr_ErrorContext *tilemap_load_layers(tilemap *dest, json_t *root)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, dest, ERR_NULLPOINTER, "tilemap_load_layers received NULL tilemap pointer");
|
||||
FAIL_ZERO_RETURN(errctx, root, ERR_NULLPOINTER, "tilemap_load_layers received NULL json object pointer");
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "tilemap_load_layers received NULL tilemap pointer");
|
||||
FAIL_ZERO_RETURN(errctx, root, AKERR_NULLPOINTER, "tilemap_load_layers received NULL json object pointer");
|
||||
json_t *layers = NULL;
|
||||
json_t *layer = NULL;
|
||||
string *tmpstr = NULL;
|
||||
@@ -331,7 +331,7 @@ ErrorContext *tilemap_load_layers(tilemap *dest, json_t *root)
|
||||
dest->numlayers = json_array_size((json_t *)layers);
|
||||
for ( i = 0; i < dest->numlayers; i++) {
|
||||
if ( i >= TILEMAP_MAX_LAYERS ) {
|
||||
FAIL_BREAK(errctx, ERR_OUTOFBOUNDS, "Map exceeds the maximum number of layers");
|
||||
FAIL_BREAK(errctx, AKERR_OUTOFBOUNDS, "Map exceeds the maximum number of layers");
|
||||
}
|
||||
CATCH(errctx, get_json_array_index_object((json_t *)layers, i, &layer));
|
||||
CATCH(errctx, get_json_integer_value((json_t *)layer, "id", &tmpint));
|
||||
@@ -363,15 +363,15 @@ ErrorContext *tilemap_load_layers(tilemap *dest, json_t *root)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *tilemap_load(char *fname, tilemap *dest)
|
||||
akerr_ErrorContext *tilemap_load(char *fname, tilemap *dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
json_t *json = NULL;
|
||||
//string *tmpstr = NULL;
|
||||
json_error_t error;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, fname, ERR_NULLPOINTER, "load_tilemap received null filename");
|
||||
FAIL_ZERO_RETURN(errctx, dest, ERR_NULLPOINTER, "load_tilemap received null tilemap");
|
||||
FAIL_ZERO_RETURN(errctx, fname, AKERR_NULLPOINTER, "load_tilemap received null filename");
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "load_tilemap received null tilemap");
|
||||
|
||||
memset(dest, 0x00, sizeof(tilemap));
|
||||
|
||||
@@ -384,7 +384,7 @@ ErrorContext *tilemap_load(char *fname, tilemap *dest)
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
json,
|
||||
ERR_NULLPOINTER,
|
||||
AKERR_NULLPOINTER,
|
||||
"Error while loading tilemap from %s on line %d: %s-",
|
||||
fname,
|
||||
error.line,
|
||||
@@ -397,7 +397,7 @@ ErrorContext *tilemap_load(char *fname, tilemap *dest)
|
||||
|
||||
dest->orientation = 0;
|
||||
if ( (dest->width * dest->height) >= (TILEMAP_MAX_WIDTH * TILEMAP_MAX_HEIGHT) ) {
|
||||
FAIL_RETURN(errctx, ERR_OUTOFBOUNDS, "Map exceeds the maximum size");
|
||||
FAIL_RETURN(errctx, AKERR_OUTOFBOUNDS, "Map exceeds the maximum size");
|
||||
}
|
||||
|
||||
CATCH(errctx, tilemap_load_layers((tilemap *)dest, (json_t *)json));
|
||||
@@ -409,7 +409,7 @@ ErrorContext *tilemap_load(char *fname, tilemap *dest)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *tilemap_draw(SDL_Renderer *renderer, tilemap *map, SDL_FRect *viewport, int layeridx)
|
||||
akerr_ErrorContext *tilemap_draw(SDL_Renderer *renderer, tilemap *map, SDL_FRect *viewport, int layeridx)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
SDL_FRect dest = {.x = 0, .y = 0, .w = 0, .h = 0};;
|
||||
@@ -439,8 +439,8 @@ ErrorContext *tilemap_draw(SDL_Renderer *renderer, tilemap *map, SDL_FRect *view
|
||||
* 0 and 8 would not be rendered. 1, 9, 6, and E would be partially rendered at their corner.
|
||||
* 2,3,4,5 and A,B,C,D would be partially rendered with a slice from their center.
|
||||
*/
|
||||
FAIL_ZERO_RETURN(errctx, map, ERR_NULLPOINTER, "tilemap_draw received NULL pointer to tilemap");
|
||||
FAIL_ZERO_RETURN(errctx, viewport, ERR_NULLPOINTER, "tilemap_draw received NULL pointer to viewport");
|
||||
FAIL_ZERO_RETURN(errctx, map, AKERR_NULLPOINTER, "tilemap_draw received NULL pointer to tilemap");
|
||||
FAIL_ZERO_RETURN(errctx, viewport, AKERR_NULLPOINTER, "tilemap_draw received NULL pointer to viewport");
|
||||
|
||||
/* Only try to render the stuff that is partially within the viewport */
|
||||
|
||||
@@ -519,7 +519,7 @@ ErrorContext *tilemap_draw(SDL_Renderer *renderer, tilemap *map, SDL_FRect *view
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *tilemap_draw_tileset(SDL_Renderer *renderer, tilemap *map, int tilesetidx)
|
||||
akerr_ErrorContext *tilemap_draw_tileset(SDL_Renderer *renderer, tilemap *map, int tilesetidx)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
SDL_FRect dest;
|
||||
@@ -531,8 +531,8 @@ ErrorContext *tilemap_draw_tileset(SDL_Renderer *renderer, tilemap *map, int til
|
||||
* by proving that we can reconstruct the original tileset image)
|
||||
*/
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, map, ERR_NULLPOINTER, "tilemap_draw_tileset received NULL pointer to tilemap");
|
||||
FAIL_NONZERO_RETURN(errctx, (tilesetidx >= map->numtilesets), ERR_OUTOFBOUNDS, "tilemap_draw_tileset received a tileset index out of bounds");
|
||||
FAIL_ZERO_RETURN(errctx, map, AKERR_NULLPOINTER, "tilemap_draw_tileset received NULL pointer to tilemap");
|
||||
FAIL_NONZERO_RETURN(errctx, (tilesetidx >= map->numtilesets), AKERR_OUTOFBOUNDS, "tilemap_draw_tileset received a tileset index out of bounds");
|
||||
|
||||
for ( tilenum = 0; tilenum < map->tilesets[tilesetidx].tilecount; tilenum++) {
|
||||
// Render this tile to the correct screen position
|
||||
|
||||
Reference in New Issue
Block a user