Got the suite rebuilding, most tests pass, actor and sprite are failing
This commit is contained in:
@@ -13,15 +13,15 @@
|
||||
#include <sdl3game/iterator.h>
|
||||
#include <sdl3game/util.h>
|
||||
|
||||
ErrorContext *character_initialize(character *obj, char *name)
|
||||
akerr_ErrorContext *character_initialize(character *obj, char *name)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL character reference");
|
||||
FAIL_ZERO_RETURN(errctx, name, ERR_NULLPOINTER, "NULL name string pointer");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL character reference");
|
||||
FAIL_ZERO_RETURN(errctx, name, AKERR_NULLPOINTER, "NULL name string pointer");
|
||||
memset(obj, 0x00, sizeof(character));
|
||||
strncpy(obj->name, name, SPRITE_MAX_CHARACTER_NAME_LENGTH);
|
||||
obj->state_sprites = SDL_CreateProperties();
|
||||
FAIL_ZERO_RETURN(errctx, obj->state_sprites, ERR_NULLPOINTER, "Unable to initialize SDL_PropertiesID for character state map");
|
||||
FAIL_ZERO_RETURN(errctx, obj->state_sprites, AKERR_NULLPOINTER, "Unable to initialize SDL_PropertiesID for character state map");
|
||||
|
||||
obj->sprite_add = &character_sprite_add;
|
||||
obj->sprite_get = &character_sprite_get;
|
||||
@@ -29,18 +29,18 @@ ErrorContext *character_initialize(character *obj, char *name)
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
SDL_SetPointerProperty(REGISTRY_CHARACTER, name, (void *)obj),
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Unable to add character to registry");
|
||||
obj->refcount += 1;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *character_sprite_add(character *basechar, sprite *ref, int state)
|
||||
akerr_ErrorContext *character_sprite_add(character *basechar, sprite *ref, int state)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
char stateval[32];
|
||||
FAIL_ZERO_RETURN(errctx, basechar, ERR_NULLPOINTER, "NULL character reference");
|
||||
FAIL_ZERO_RETURN(errctx, ref, ERR_NULLPOINTER, "NULL sprite reference");
|
||||
FAIL_ZERO_RETURN(errctx, basechar, AKERR_NULLPOINTER, "NULL character reference");
|
||||
FAIL_ZERO_RETURN(errctx, ref, AKERR_NULLPOINTER, "NULL sprite reference");
|
||||
memset(&stateval, 0x00, 32);
|
||||
SDL_itoa(state, (char *)&stateval, 10);
|
||||
SDL_SetPointerProperty(basechar->state_sprites, (char *)&stateval, ref);
|
||||
@@ -49,17 +49,17 @@ ErrorContext *character_sprite_add(character *basechar, sprite *ref, int state)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *character_sprite_get(character *basechar, int state, sprite **dest)
|
||||
akerr_ErrorContext *character_sprite_get(character *basechar, int state, sprite **dest)
|
||||
{
|
||||
sprite *target = NULL;
|
||||
PREPARE_ERROR(errctx);
|
||||
char stateval[32];
|
||||
FAIL_ZERO_RETURN(errctx, dest, ERR_NULLPOINTER, "NULL pointer to sprite pointer (**dest)");
|
||||
FAIL_ZERO_RETURN(errctx, basechar, ERR_NULLPOINTER, "NULL character reference");
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "NULL pointer to sprite pointer (**dest)");
|
||||
FAIL_ZERO_RETURN(errctx, basechar, AKERR_NULLPOINTER, "NULL character reference");
|
||||
memset(&stateval, 0x00, 32);
|
||||
SDL_itoa(state, (char *)&stateval, 10);
|
||||
*dest = (sprite *)SDL_GetPointerProperty(basechar->state_sprites, (char *)&stateval, NULL);
|
||||
FAIL_ZERO_RETURN(errctx, *dest, ERR_KEY, "Sprite for state %d (%b) not found in the character's registry", state, state);
|
||||
FAIL_ZERO_RETURN(errctx, *dest, AKERR_KEY, "Sprite for state %d (%b) not found in the character's registry", state, state);
|
||||
target = *dest;
|
||||
//SDL_Log("Sprite state %d (%s) has character %s", state, (char *)&stateval, target->name);
|
||||
SUCCEED_RETURN(errctx);
|
||||
@@ -73,10 +73,10 @@ void character_state_sprites_iterate(void *userdata, SDL_PropertiesID registry,
|
||||
sprite *spriteptr;
|
||||
iterator *opflags = (iterator *)userdata;
|
||||
ATTEMPT {
|
||||
FAIL_ZERO_BREAK(errctx, opflags, ERR_NULLPOINTER, "Character state sprite iterator received null iterator op pointer");
|
||||
FAIL_ZERO_BREAK(errctx, name, ERR_NULLPOINTER, "Character state sprite iterator received null sprite name");
|
||||
FAIL_ZERO_BREAK(errctx, opflags, AKERR_NULLPOINTER, "Character state sprite iterator received null iterator op pointer");
|
||||
FAIL_ZERO_BREAK(errctx, name, AKERR_NULLPOINTER, "Character state sprite iterator received null sprite name");
|
||||
spriteptr = (sprite *)SDL_GetPointerProperty(registry, name, NULL);
|
||||
FAIL_ZERO_BREAK(errctx, spriteptr, ERR_NULLPOINTER, "Character state sprite for %s not found", name);
|
||||
FAIL_ZERO_BREAK(errctx, spriteptr, AKERR_NULLPOINTER, "Character state sprite for %s not found", name);
|
||||
if ( BITMASK_HAS(opflags->flags, ITERATOR_OP_RELEASE) ) {
|
||||
CATCH(errctx, heap_release_sprite(spriteptr));
|
||||
}
|
||||
@@ -85,21 +85,21 @@ void character_state_sprites_iterate(void *userdata, SDL_PropertiesID registry,
|
||||
} FINISH_NORETURN(errctx);
|
||||
}
|
||||
|
||||
static ErrorContext *character_load_json_state_int_from_strings(json_t *states, int *dest)
|
||||
static akerr_ErrorContext *character_load_json_state_int_from_strings(json_t *states, int *dest)
|
||||
{
|
||||
int i = 0;
|
||||
long newstate = 0;
|
||||
string *tmpstring = NULL;
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, states, ERR_NULLPOINTER, "NULL states array");
|
||||
FAIL_ZERO_RETURN(errctx, states, ERR_NULLPOINTER, "NULL destination integer");
|
||||
FAIL_ZERO_RETURN(errctx, states, AKERR_NULLPOINTER, "NULL states array");
|
||||
FAIL_ZERO_RETURN(errctx, states, AKERR_NULLPOINTER, "NULL destination integer");
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, heap_next_string(&tmpstring));
|
||||
for ( i = 0; i < json_array_size((json_t *)states) ; i++ ) {
|
||||
CATCH(errctx, get_json_array_index_string(states, i, &tmpstring));
|
||||
newstate = (long)SDL_GetNumberProperty(REGISTRY_ACTOR_STATE_STRINGS, (char *)&tmpstring->data, 0);
|
||||
FAIL_ZERO_BREAK(errctx, newstate, ERR_KEY, "Unknown actor state %s", (char *)&tmpstring->data);
|
||||
FAIL_ZERO_BREAK(errctx, newstate, AKERR_KEY, "Unknown actor state %s", (char *)&tmpstring->data);
|
||||
*dest = (*dest | (int)(newstate));
|
||||
}
|
||||
} CLEANUP {
|
||||
@@ -109,7 +109,7 @@ static ErrorContext *character_load_json_state_int_from_strings(json_t *states,
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
static ErrorContext *character_load_json_inner(json_t *json, character *obj)
|
||||
static akerr_ErrorContext *character_load_json_inner(json_t *json, character *obj)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
json_t *mappings = NULL;
|
||||
@@ -143,7 +143,7 @@ static ErrorContext *character_load_json_inner(json_t *json, character *obj)
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
spriteptr,
|
||||
ERR_NULLPOINTER,
|
||||
AKERR_NULLPOINTER,
|
||||
"Character %s for state %b references sprite %s but not found in the registry",
|
||||
tmpstr2->data,
|
||||
stateval,
|
||||
@@ -163,7 +163,7 @@ static ErrorContext *character_load_json_inner(json_t *json, character *obj)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *character_load_json(char *filename)
|
||||
akerr_ErrorContext *character_load_json(char *filename)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
json_t *json;
|
||||
@@ -171,7 +171,7 @@ ErrorContext *character_load_json(char *filename)
|
||||
character *obj = NULL;
|
||||
//string *tmpstr = NULL;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, filename, ERR_NULLPOINTER, "Received null filename");
|
||||
FAIL_ZERO_RETURN(errctx, filename, AKERR_NULLPOINTER, "Received null filename");
|
||||
ATTEMPT {
|
||||
CATCH(errctx, heap_next_character(&obj));
|
||||
//CATCH(errctx, heap_next_string(&tmpstr));
|
||||
@@ -181,7 +181,7 @@ ErrorContext *character_load_json(char *filename)
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
json,
|
||||
ERR_NULLPOINTER,
|
||||
AKERR_NULLPOINTER,
|
||||
"Error while loading character from %s on line %d: %s", filename, error.line, error.text
|
||||
);
|
||||
CATCH(errctx, character_load_json_inner(json, obj));
|
||||
|
||||
Reference in New Issue
Block a user