Got the suite rebuilding, most tests pass, actor and sprite are failing
This commit is contained in:
122
src/actor.c
122
src/actor.c
@@ -11,11 +11,11 @@
|
||||
#include <sdl3game/staticstring.h>
|
||||
#include <sdl3game/iterator.h>
|
||||
|
||||
ErrorContext *actor_initialize(actor *obj, char *name)
|
||||
akerr_ErrorContext *actor_initialize(actor *obj, char *name)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "actor_initialize received null actor pointer");
|
||||
FAIL_ZERO_RETURN(errctx, name, ERR_NULLPOINTER, "actor_initialize received null name string pointer");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "actor_initialize received null actor pointer");
|
||||
FAIL_ZERO_RETURN(errctx, name, AKERR_NULLPOINTER, "actor_initialize received null name string pointer");
|
||||
|
||||
memset(obj, 0x00, sizeof(actor));
|
||||
strncpy((char *)obj->name, name, ACTOR_MAX_NAME_LENGTH);
|
||||
@@ -32,7 +32,7 @@ ErrorContext *actor_initialize(actor *obj, char *name)
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
SDL_SetPointerProperty(REGISTRY_ACTOR, name, (void *)obj),
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Unable to add actor to registry"
|
||||
);
|
||||
obj->refcount += 1;
|
||||
@@ -40,22 +40,22 @@ ErrorContext *actor_initialize(actor *obj, char *name)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *actor_set_character(actor *obj, char *basecharname)
|
||||
akerr_ErrorContext *actor_set_character(actor *obj, char *basecharname)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "Null actor reference");
|
||||
FAIL_ZERO_RETURN(errctx, basecharname, ERR_NULLPOINTER, "Null character reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Null actor reference");
|
||||
FAIL_ZERO_RETURN(errctx, basecharname, AKERR_NULLPOINTER, "Null character reference");
|
||||
|
||||
obj->basechar = SDL_GetPointerProperty(REGISTRY_CHARACTER, basecharname, NULL);
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, obj->basechar, ERR_NULLPOINTER, "Character not found in the registry");
|
||||
FAIL_ZERO_RETURN(errctx, obj->basechar, AKERR_NULLPOINTER, "Character not found in the registry");
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *actor_automatic_face(actor *obj)
|
||||
akerr_ErrorContext *actor_automatic_face(actor *obj)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "Null actor reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Null actor reference");
|
||||
ATTEMPT {
|
||||
if ( obj->movement_controls_face == true ) {
|
||||
// TODO : This doesn't really work properly
|
||||
@@ -76,10 +76,10 @@ ErrorContext *actor_automatic_face(actor *obj)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *actor_logic_changeframe(actor *obj, sprite *curSprite, SDL_Time curtimems)
|
||||
akerr_ErrorContext *actor_logic_changeframe(actor *obj, sprite *curSprite, SDL_Time curtimems)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "Null actor reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Null actor reference");
|
||||
ATTEMPT {
|
||||
// are we currently looping in reverse?
|
||||
if ( curSprite->loop == true && obj->curSpriteReversing == true ) {
|
||||
@@ -111,10 +111,10 @@ ErrorContext *actor_logic_changeframe(actor *obj, sprite *curSprite, SDL_Time cu
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *actor_logic_movement(actor *obj, SDL_Time curtimems)
|
||||
akerr_ErrorContext *actor_logic_movement(actor *obj, SDL_Time curtimems)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "Null actor reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Null actor reference");
|
||||
if ( obj->parent != NULL ) {
|
||||
// Children don't move independently of their parents, they just have an offset
|
||||
SUCCEED_RETURN(errctx);
|
||||
@@ -135,15 +135,15 @@ ErrorContext *actor_logic_movement(actor *obj, SDL_Time curtimems)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *actor_update(actor *obj)
|
||||
akerr_ErrorContext *actor_update(actor *obj)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
SDL_Time curtime = 0;
|
||||
SDL_Time curtimems = 0;
|
||||
sprite *curSprite = NULL;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj->basechar, ERR_NULLPOINTER, "Actor has NULL base character reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj->basechar, AKERR_NULLPOINTER, "Actor has NULL base character reference");
|
||||
|
||||
ATTEMPT {
|
||||
SDL_GetCurrentTime(&curtime);
|
||||
@@ -167,27 +167,27 @@ ErrorContext *actor_update(actor *obj)
|
||||
}
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_KEY) {
|
||||
} HANDLE(errctx, AKERR_KEY) {
|
||||
SUCCEED_RETURN(errctx);
|
||||
} FINISH(errctx, true);
|
||||
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
static ErrorContext *actor_visible(actor *obj, SDL_FRect *camera, bool *visible)
|
||||
static akerr_ErrorContext *actor_visible(actor *obj, SDL_FRect *camera, bool *visible)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
sprite *curSprite = NULL;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, renderer, ERR_NULLPOINTER, "NULL renderer");
|
||||
FAIL_ZERO_RETURN(errctx, obj->basechar, ERR_NULLPOINTER, "Actor has NULL base character reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, renderer, AKERR_NULLPOINTER, "NULL renderer");
|
||||
FAIL_ZERO_RETURN(errctx, obj->basechar, AKERR_NULLPOINTER, "Actor has NULL base character reference");
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, character_sprite_get(obj->basechar, obj->state, &curSprite));
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_KEY) {
|
||||
} HANDLE(errctx, AKERR_KEY) {
|
||||
// TODO: Actor has no sprite matching the current state. Should we treat this as an error and throw?
|
||||
*visible = false;
|
||||
SUCCEED_RETURN(errctx);
|
||||
@@ -204,7 +204,7 @@ static ErrorContext *actor_visible(actor *obj, SDL_FRect *camera, bool *visible)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *actor_render(actor *obj, SDL_Renderer *renderer)
|
||||
akerr_ErrorContext *actor_render(actor *obj, SDL_Renderer *renderer)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
sprite *curSprite = NULL;
|
||||
@@ -212,17 +212,17 @@ ErrorContext *actor_render(actor *obj, SDL_Renderer *renderer)
|
||||
SDL_FRect src;
|
||||
SDL_FRect dest;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, renderer, ERR_NULLPOINTER, "NULL renderer");
|
||||
FAIL_ZERO_RETURN(errctx, obj->basechar, ERR_NULLPOINTER, "Actor has NULL base character reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, renderer, AKERR_NULLPOINTER, "NULL renderer");
|
||||
FAIL_ZERO_RETURN(errctx, obj->basechar, AKERR_NULLPOINTER, "Actor has NULL base character reference");
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, character_sprite_get(obj->basechar, obj->state, &curSprite));
|
||||
CATCH(errctx, actor_visible(obj, &camera, &visible));
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_KEY) {
|
||||
} HANDLE_GROUP(errctx, ERR_OUTOFBOUNDS) {
|
||||
} HANDLE(errctx, AKERR_KEY) {
|
||||
} HANDLE_GROUP(errctx, AKERR_OUTOFBOUNDS) {
|
||||
// If an actor doesn't have a sprite for a state, just log it and move on
|
||||
LOG_ERROR(errctx);
|
||||
} FINISH(errctx, true);
|
||||
@@ -261,14 +261,14 @@ ErrorContext *actor_render(actor *obj, SDL_Renderer *renderer)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *actor_add_child(actor *obj, actor *child)
|
||||
akerr_ErrorContext *actor_add_child(actor *obj, actor *child)
|
||||
{
|
||||
int i = 0;
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL parent pointer");
|
||||
FAIL_ZERO_RETURN(errctx, child, ERR_NULLPOINTER, "NULL child pointer");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL parent pointer");
|
||||
FAIL_ZERO_RETURN(errctx, child, AKERR_NULLPOINTER, "NULL child pointer");
|
||||
|
||||
FAIL_NONZERO_RETURN(errctx, child->parent, ERR_RELATIONSHIP, "Child object already has a parent");
|
||||
FAIL_NONZERO_RETURN(errctx, child->parent, AKERR_RELATIONSHIP, "Child object already has a parent");
|
||||
for ( i = 0; i < ACTOR_MAX_CHILDREN ; i++ ) {
|
||||
if ( obj->children[i] == NULL ) {
|
||||
obj->children[i] = child;
|
||||
@@ -277,7 +277,7 @@ ErrorContext *actor_add_child(actor *obj, actor *child)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
}
|
||||
FAIL_RETURN(errctx, ERR_OUTOFBOUNDS, "Parent object has no remaining child slots left");
|
||||
FAIL_RETURN(errctx, AKERR_OUTOFBOUNDS, "Parent object has no remaining child slots left");
|
||||
}
|
||||
|
||||
// SDL iterator so we can't return error information here, void only
|
||||
@@ -288,10 +288,10 @@ void registry_iterate_actor(void *userdata, SDL_PropertiesID registry, const cha
|
||||
iterator *opflags = (iterator *)userdata;
|
||||
|
||||
ATTEMPT {
|
||||
FAIL_ZERO_BREAK(errctx, name, ERR_NULLPOINTER, "registry_iterate_actor received NULL property name");
|
||||
FAIL_ZERO_BREAK(errctx, opflags, ERR_NULLPOINTER, "received NULL iterator flags");
|
||||
FAIL_ZERO_BREAK(errctx, name, AKERR_NULLPOINTER, "registry_iterate_actor received NULL property name");
|
||||
FAIL_ZERO_BREAK(errctx, opflags, AKERR_NULLPOINTER, "received NULL iterator flags");
|
||||
actor *obj = (actor *)SDL_GetPointerProperty(registry, name, NULL);
|
||||
FAIL_ZERO_BREAK(errctx, obj, ERR_KEY, "registry_iterate_actor received property name that was not in the registry");
|
||||
FAIL_ZERO_BREAK(errctx, obj, AKERR_KEY, "registry_iterate_actor received property name that was not in the registry");
|
||||
if ( BITMASK_HAS(opflags->flags, ITERATOR_OP_LAYERMASK) ) {
|
||||
if ( obj->layer != opflags->layerid ) {
|
||||
break;
|
||||
@@ -308,11 +308,11 @@ void registry_iterate_actor(void *userdata, SDL_PropertiesID registry, const cha
|
||||
} FINISH_NORETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *SDL3GActor_cmhf_left_on(actor *obj, SDL_Event *event)
|
||||
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_left_on(actor *obj, SDL_Event *event)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, ERR_NULLPOINTER, "NULL event");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||
//SDL_Log("event %d (button %d / key %d) moves actor left", event->type, event->gbutton.which, event->key.key);
|
||||
BITMASK_DEL(obj->state, (ACTOR_STATE_FACE_ALL | ACTOR_STATE_MOVING_ALL));
|
||||
BITMASK_ADD(obj->state, (ACTOR_STATE_MOVING_LEFT | ACTOR_STATE_FACE_LEFT));
|
||||
@@ -320,22 +320,22 @@ ErrorContext ERROR_NOIGNORE *SDL3GActor_cmhf_left_on(actor *obj, SDL_Event *even
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *SDL3GActor_cmhf_left_off(actor *obj, SDL_Event *event)
|
||||
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_left_off(actor *obj, SDL_Event *event)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, ERR_NULLPOINTER, "NULL event");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||
//SDL_Log("event %d (button %d / key %d) stops moving actor left", event->type, event->gbutton.which, event->key.key);
|
||||
BITMASK_DEL(obj->state, ACTOR_STATE_MOVING_LEFT);
|
||||
//SDL_Log("new target actor state: %b", obj->state);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *SDL3GActor_cmhf_right_on(actor *obj, SDL_Event *event)
|
||||
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_right_on(actor *obj, SDL_Event *event)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, ERR_NULLPOINTER, "NULL event");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||
//SDL_Log("event %d (button %d / key %d) moves actor right", event->type, event->gbutton.which, event->key.key);
|
||||
BITMASK_DEL(obj->state, (ACTOR_STATE_FACE_ALL | ACTOR_STATE_MOVING_ALL));
|
||||
BITMASK_ADD(obj->state, (ACTOR_STATE_MOVING_RIGHT | ACTOR_STATE_FACE_RIGHT));
|
||||
@@ -343,22 +343,22 @@ ErrorContext ERROR_NOIGNORE *SDL3GActor_cmhf_right_on(actor *obj, SDL_Event *eve
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *SDL3GActor_cmhf_right_off(actor *obj, SDL_Event *event)
|
||||
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_right_off(actor *obj, SDL_Event *event)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, ERR_NULLPOINTER, "NULL event");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||
//SDL_Log("event %d (button %d / key %d) stops moving actor right", event->type, event->gbutton.which, event->key.key);
|
||||
BITMASK_DEL(obj->state, ACTOR_STATE_MOVING_RIGHT);
|
||||
//SDL_Log("new target actor state: %b", obj->state);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *SDL3GActor_cmhf_up_on(actor *obj, SDL_Event *event)
|
||||
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_up_on(actor *obj, SDL_Event *event)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, ERR_NULLPOINTER, "NULL event");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||
//SDL_Log("event %d (button %d / key %d) moves actor up", event->type, event->gbutton.which, event->key.key);
|
||||
BITMASK_DEL(obj->state, (ACTOR_STATE_FACE_ALL | ACTOR_STATE_MOVING_ALL));
|
||||
BITMASK_ADD(obj->state, (ACTOR_STATE_FACE_UP | ACTOR_STATE_MOVING_UP));
|
||||
@@ -366,22 +366,22 @@ ErrorContext ERROR_NOIGNORE *SDL3GActor_cmhf_up_on(actor *obj, SDL_Event *event)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *SDL3GActor_cmhf_up_off(actor *obj, SDL_Event *event)
|
||||
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_up_off(actor *obj, SDL_Event *event)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, ERR_NULLPOINTER, "NULL event");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||
//SDL_Log("event %d (button %d / key %d) stops moving actor up", event->type, event->gbutton.which, event->key.key);
|
||||
BITMASK_DEL(obj->state, ACTOR_STATE_MOVING_UP);
|
||||
//SDL_Log("new target actor state: %b", obj->state);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *SDL3GActor_cmhf_down_on(actor *obj, SDL_Event *event)
|
||||
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_down_on(actor *obj, SDL_Event *event)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, ERR_NULLPOINTER, "NULL event");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||
//SDL_Log("event %d (button %d / key %d) moves actor down", event->type, event->gbutton.which, event->key.key);
|
||||
BITMASK_DEL(obj->state, (ACTOR_STATE_FACE_ALL | ACTOR_STATE_MOVING_ALL));
|
||||
BITMASK_ADD(obj->state, (ACTOR_STATE_MOVING_DOWN | ACTOR_STATE_FACE_DOWN));
|
||||
@@ -389,11 +389,11 @@ ErrorContext ERROR_NOIGNORE *SDL3GActor_cmhf_down_on(actor *obj, SDL_Event *even
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *SDL3GActor_cmhf_down_off(actor *obj, SDL_Event *event)
|
||||
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_down_off(actor *obj, SDL_Event *event)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, ERR_NULLPOINTER, "NULL event");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||
//SDL_Log("event %d (button %d / key %d) stops moving actor down", event->type, event->gbutton.which, event->key.key);
|
||||
BITMASK_DEL(obj->state, ACTOR_STATE_MOVING_DOWN);
|
||||
//SDL_Log("new target actor state: %b", obj->state);
|
||||
|
||||
13
src/assets.c
13
src/assets.c
@@ -5,8 +5,9 @@
|
||||
#include <sdl3game/game.h>
|
||||
#include <sdl3game/staticstring.h>
|
||||
#include <sdl3game/heap.h>
|
||||
#include <sdl3game/error.h>
|
||||
|
||||
ErrorContext *load_start_bgm(char *fname)
|
||||
akerr_ErrorContext *load_start_bgm(char *fname)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
//string *tmpstr = NULL;
|
||||
@@ -14,31 +15,31 @@ ErrorContext *load_start_bgm(char *fname)
|
||||
SDL_PropertiesID bgmprops = 0;
|
||||
|
||||
ATTEMPT {
|
||||
FAIL_ZERO_BREAK(errctx, fname, ERR_NULLPOINTER, "load_start_bgm received NULL filename");
|
||||
FAIL_ZERO_BREAK(errctx, fname, AKERR_NULLPOINTER, "load_start_bgm received NULL filename");
|
||||
//CATCH(errctx, heap_next_string(&tmpstr));
|
||||
//CATCH(errctx, string_initialize(tmpstr, NULL));
|
||||
|
||||
//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());
|
||||
FAIL_ZERO_BREAK(errctx, bgm, AKERR_NULLPOINTER, "Failed to load music asset %s : %s", fname, SDL_GetError());
|
||||
|
||||
bgmtrack = MIX_CreateTrack(game.mixer);
|
||||
FAIL_ZERO_BREAK(errctx, bgmtrack, ERR_NULLPOINTER, "Failed to create audio track for background music: %s", SDL_GetError());
|
||||
FAIL_ZERO_BREAK(errctx, bgmtrack, AKERR_NULLPOINTER, "Failed to create audio track for background music: %s", SDL_GetError());
|
||||
|
||||
game.tracks[GAME_AUDIO_TRACK_BGM] = bgmtrack;
|
||||
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
MIX_SetTrackAudio(bgmtrack, bgm),
|
||||
ERR_SDL,
|
||||
AKERR_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);
|
||||
FAIL_BREAK(errctx, AKERR_SDL, "Failed to play music asset %s", fname);
|
||||
}
|
||||
} CLEANUP {
|
||||
//IGNORE(heap_release_string(tmpstr));
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
SDL3GControlMap GAME_ControlMaps[MAX_CONTROL_MAPS];
|
||||
|
||||
ErrorContext *controller_handle_event(void *appstate, SDL_Event *event)
|
||||
akerr_ErrorContext *controller_handle_event(void *appstate, SDL_Event *event)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
@@ -55,16 +55,16 @@ _controller_handle_event_success:
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *gamepad_handle_button_down(void *appstate, SDL_Event *event)
|
||||
akerr_ErrorContext *gamepad_handle_button_down(void *appstate, SDL_Event *event)
|
||||
{
|
||||
actor *player = NULL;
|
||||
|
||||
PREPARE_ERROR(errctx);
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, appstate, ERR_NULLPOINTER, "NULL appstate");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, ERR_NULLPOINTER, "NULL event");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, AKERR_NULLPOINTER, "NULL appstate");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, AKERR_NULLPOINTER, "NULL event");
|
||||
player = SDL_GetPointerProperty(REGISTRY_ACTOR, "player", NULL);
|
||||
FAIL_ZERO_RETURN(errctx, appstate, ERR_NULLPOINTER, "Player actor does not exist");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, AKERR_NULLPOINTER, "Player actor does not exist");
|
||||
|
||||
if ( event->gbutton.button == SDL_GAMEPAD_BUTTON_DPAD_DOWN ||
|
||||
event->key.key == SDLK_DOWN ) {
|
||||
@@ -106,16 +106,16 @@ ErrorContext *gamepad_handle_button_down(void *appstate, SDL_Event *event)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *gamepad_handle_button_up(void *appstate, SDL_Event *event)
|
||||
akerr_ErrorContext *gamepad_handle_button_up(void *appstate, SDL_Event *event)
|
||||
{
|
||||
actor *player = NULL;
|
||||
|
||||
PREPARE_ERROR(errctx);
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, appstate, ERR_NULLPOINTER, "NULL appstate");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, ERR_NULLPOINTER, "NULL event");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, AKERR_NULLPOINTER, "NULL appstate");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, AKERR_NULLPOINTER, "NULL event");
|
||||
player = SDL_GetPointerProperty(REGISTRY_ACTOR, "player", NULL);
|
||||
FAIL_ZERO_RETURN(errctx, appstate, ERR_NULLPOINTER, "Player actor does not exist");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, AKERR_NULLPOINTER, "Player actor does not exist");
|
||||
|
||||
if ( event->gbutton.button == SDL_GAMEPAD_BUTTON_DPAD_DOWN ||
|
||||
event->key.key == SDLK_DOWN ) {
|
||||
@@ -145,15 +145,15 @@ ErrorContext *gamepad_handle_button_up(void *appstate, SDL_Event *event)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *gamepad_handle_added(void *appstate, SDL_Event *event)
|
||||
akerr_ErrorContext *gamepad_handle_added(void *appstate, SDL_Event *event)
|
||||
{
|
||||
SDL_JoystickID which;
|
||||
SDL_Gamepad *gamepad = NULL;
|
||||
char *mapping = NULL;
|
||||
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, appstate, ERR_NULLPOINTER, "NULL appstate");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, ERR_NULLPOINTER, "NULL event");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, AKERR_NULLPOINTER, "NULL appstate");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, AKERR_NULLPOINTER, "NULL event");
|
||||
|
||||
which = event->gbutton.which;
|
||||
gamepad = SDL_GetGamepadFromID(which);
|
||||
@@ -175,14 +175,14 @@ ErrorContext *gamepad_handle_added(void *appstate, SDL_Event *event)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *gamepad_handle_removed(void *appstate, SDL_Event *event)
|
||||
akerr_ErrorContext *gamepad_handle_removed(void *appstate, SDL_Event *event)
|
||||
{
|
||||
SDL_JoystickID which;
|
||||
SDL_Gamepad *gamepad = NULL;
|
||||
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, appstate, ERR_NULLPOINTER, "NULL appstate");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, ERR_NULLPOINTER, "NULL event");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, AKERR_NULLPOINTER, "NULL appstate");
|
||||
FAIL_ZERO_RETURN(errctx, appstate, AKERR_NULLPOINTER, "NULL event");
|
||||
|
||||
which = event->gbutton.which;
|
||||
gamepad = SDL_GetGamepadFromID(which);
|
||||
@@ -194,7 +194,7 @@ ErrorContext *gamepad_handle_removed(void *appstate, SDL_Event *event)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *SDL3G_controller_default(int controlmapid, char *actorname, int kbid, int jsid)
|
||||
akerr_ErrorContext AKERR_NOIGNORE *SDL3G_controller_default(int controlmapid, char *actorname, int kbid, int jsid)
|
||||
{
|
||||
SDL3GControlMap *controlmap;
|
||||
PREPARE_ERROR(errctx);
|
||||
@@ -205,7 +205,7 @@ ErrorContext ERROR_NOIGNORE *SDL3G_controller_default(int controlmapid, char *ac
|
||||
controlmap->jsid = jsid;
|
||||
|
||||
controlmap->target = SDL_GetPointerProperty(REGISTRY_ACTOR, actorname, NULL);
|
||||
FAIL_ZERO_BREAK(errctx, controlmap->target, ERR_REGISTRY, "Actor %s not found in registry", actorname);
|
||||
FAIL_ZERO_BREAK(errctx, controlmap->target, AKERR_REGISTRY, "Actor %s not found in registry", actorname);
|
||||
|
||||
// ---- KEYBOARD CONTROLS ----
|
||||
|
||||
|
||||
18
src/game.c
18
src/game.c
@@ -27,14 +27,14 @@ MIX_Track *GAME_tracks[64];
|
||||
SDL_FRect camera;
|
||||
Game game;
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *GAME_init()
|
||||
akerr_ErrorContext AKERR_NOIGNORE *GAME_init()
|
||||
{
|
||||
int i = 0;
|
||||
PREPARE_ERROR(errctx);
|
||||
ATTEMPT {
|
||||
FAIL_ZERO_BREAK(errctx, strlen((char *)&game.name), ERR_NULLPOINTER, "Must provide game name");
|
||||
FAIL_ZERO_BREAK(errctx, strlen((char *)&game.version), ERR_NULLPOINTER, "Must provide game version");
|
||||
FAIL_ZERO_BREAK(errctx, strlen((char *)&game.uri), ERR_NULLPOINTER, "Must provide game uri");
|
||||
FAIL_ZERO_BREAK(errctx, strlen((char *)&game.name), AKERR_NULLPOINTER, "Must provide game name");
|
||||
FAIL_ZERO_BREAK(errctx, strlen((char *)&game.version), AKERR_NULLPOINTER, "Must provide game version");
|
||||
FAIL_ZERO_BREAK(errctx, strlen((char *)&game.uri), AKERR_NULLPOINTER, "Must provide game uri");
|
||||
CATCH(errctx, heap_init());
|
||||
CATCH(errctx, registry_init_actor());
|
||||
CATCH(errctx, registry_init_sprite());
|
||||
@@ -54,7 +54,7 @@ ErrorContext ERROR_NOIGNORE *GAME_init()
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD | SDL_INIT_AUDIO),
|
||||
ERR_SDL,
|
||||
AKERR_SDL,
|
||||
"Couldn't initialize SDL: %s",
|
||||
SDL_GetError());
|
||||
|
||||
@@ -62,28 +62,28 @@ ErrorContext ERROR_NOIGNORE *GAME_init()
|
||||
|
||||
for ( i = 0; i < SDL_GAMECONTROLLER_DB_LEN ; i++ ) {
|
||||
if ( SDL_AddGamepadMapping(SDL_GAMECONTROLLER_DB[i]) == -1 ) {
|
||||
FAIL_ZERO_RETURN(errctx, 0, ERR_SDL, "%s", SDL_GetError());
|
||||
FAIL_ZERO_RETURN(errctx, 0, AKERR_SDL, "%s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
SDL_CreateWindowAndRenderer(game.uri, game.screenwidth, game.screenheight, 0, &window, &renderer),
|
||||
ERR_SDL,
|
||||
AKERR_SDL,
|
||||
"Couldn't create window/renderer: %s",
|
||||
SDL_GetError());
|
||||
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
MIX_Init(),
|
||||
ERR_SDL,
|
||||
AKERR_SDL,
|
||||
"Couldn't initialize audio: %s",
|
||||
SDL_GetError());
|
||||
game.mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, 0);
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
game.mixer,
|
||||
ERR_SDL,
|
||||
AKERR_SDL,
|
||||
"Unable to create mixer device: %s",
|
||||
SDL_GetError());
|
||||
|
||||
|
||||
44
src/heap.c
44
src/heap.c
@@ -7,6 +7,7 @@
|
||||
#include <sdl3game/registry.h>
|
||||
#include <sdl3game/staticstring.h>
|
||||
#include <sdl3game/iterator.h>
|
||||
#include <sdl3game/error.h>
|
||||
|
||||
actor HEAP_ACTOR[MAX_HEAP_ACTOR];
|
||||
sprite HEAP_SPRITE[MAX_HEAP_SPRITE];
|
||||
@@ -14,10 +15,11 @@ spritesheet HEAP_SPRITESHEET[MAX_HEAP_SPRITESHEET];
|
||||
character HEAP_CHARACTER[MAX_HEAP_CHARACTER];
|
||||
string HEAP_STRING[MAX_HEAP_STRING];
|
||||
|
||||
ErrorContext *heap_init()
|
||||
akerr_ErrorContext *heap_init()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
int i = 0;
|
||||
akerr_name_for_status(AKERR_SDL, "SDL Error");
|
||||
for ( i = 0; i < MAX_HEAP_ACTOR; i++) {
|
||||
memset(&HEAP_ACTOR[i], 0x00, sizeof(actor));
|
||||
}
|
||||
@@ -36,7 +38,7 @@ ErrorContext *heap_init()
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *heap_next_actor(actor **dest)
|
||||
akerr_ErrorContext *heap_next_actor(actor **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < MAX_HEAP_ACTOR; i++ ) {
|
||||
@@ -46,10 +48,10 @@ ErrorContext *heap_next_actor(actor **dest)
|
||||
*dest = &HEAP_ACTOR[i];
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
FAIL_RETURN(errctx, ERR_HEAP, "Unable to find unused actor on the heap");
|
||||
FAIL_RETURN(errctx, AKERR_HEAP, "Unable to find unused actor on the heap");
|
||||
}
|
||||
|
||||
ErrorContext *heap_next_sprite(sprite **dest)
|
||||
akerr_ErrorContext *heap_next_sprite(sprite **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < MAX_HEAP_SPRITE; i++ ) {
|
||||
@@ -59,10 +61,10 @@ ErrorContext *heap_next_sprite(sprite **dest)
|
||||
*dest = &HEAP_SPRITE[i];
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
FAIL_RETURN(errctx, ERR_HEAP, "Unable to find unused sprite on the heap");
|
||||
FAIL_RETURN(errctx, AKERR_HEAP, "Unable to find unused sprite on the heap");
|
||||
}
|
||||
|
||||
ErrorContext *heap_next_spritesheet(spritesheet **dest)
|
||||
akerr_ErrorContext *heap_next_spritesheet(spritesheet **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < MAX_HEAP_SPRITESHEET; i++ ) {
|
||||
@@ -72,10 +74,10 @@ ErrorContext *heap_next_spritesheet(spritesheet **dest)
|
||||
*dest = &HEAP_SPRITESHEET[i];
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
FAIL_RETURN(errctx, ERR_HEAP, "Unable to find unused spritesheet on the heap");
|
||||
FAIL_RETURN(errctx, AKERR_HEAP, "Unable to find unused spritesheet on the heap");
|
||||
}
|
||||
|
||||
ErrorContext *heap_next_character(character **dest)
|
||||
akerr_ErrorContext *heap_next_character(character **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < MAX_HEAP_CHARACTER; i++ ) {
|
||||
@@ -85,10 +87,10 @@ ErrorContext *heap_next_character(character **dest)
|
||||
*dest = &HEAP_CHARACTER[i];
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
FAIL_RETURN(errctx, ERR_HEAP, "Unable to find unused character on the heap");
|
||||
FAIL_RETURN(errctx, AKERR_HEAP, "Unable to find unused character on the heap");
|
||||
}
|
||||
|
||||
ErrorContext *heap_next_string(string **dest)
|
||||
akerr_ErrorContext *heap_next_string(string **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < MAX_HEAP_STRING; i++ ) {
|
||||
@@ -98,14 +100,14 @@ ErrorContext *heap_next_string(string **dest)
|
||||
*dest = &HEAP_STRING[i];
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
FAIL_RETURN(errctx, ERR_HEAP, "Unable to find unused string on the heap");
|
||||
FAIL_RETURN(errctx, AKERR_HEAP, "Unable to find unused string on the heap");
|
||||
}
|
||||
|
||||
ErrorContext *heap_release_actor(actor *ptr)
|
||||
akerr_ErrorContext *heap_release_actor(actor *ptr)
|
||||
{
|
||||
int i = 0;
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, ptr, ERR_NULLPOINTER, "NULL actor reference");
|
||||
FAIL_ZERO_RETURN(errctx, ptr, AKERR_NULLPOINTER, "NULL actor reference");
|
||||
if ( ptr->refcount > 0 ) {
|
||||
ptr->refcount -= 1;
|
||||
}
|
||||
@@ -124,11 +126,11 @@ ErrorContext *heap_release_actor(actor *ptr)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *heap_release_character(character *basechar)
|
||||
akerr_ErrorContext *heap_release_character(character *basechar)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
iterator opflags;
|
||||
FAIL_ZERO_RETURN(errctx, basechar, ERR_NULLPOINTER, "NULL character reference");
|
||||
FAIL_ZERO_RETURN(errctx, basechar, AKERR_NULLPOINTER, "NULL character reference");
|
||||
BITMASK_CLEAR(opflags.flags);
|
||||
BITMASK_ADD(opflags.flags, ITERATOR_OP_RELEASE);
|
||||
|
||||
@@ -142,10 +144,10 @@ ErrorContext *heap_release_character(character *basechar)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *heap_release_sprite(sprite *ptr)
|
||||
akerr_ErrorContext *heap_release_sprite(sprite *ptr)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, ptr, ERR_NULLPOINTER, "Received NULL sprite reference");
|
||||
FAIL_ZERO_RETURN(errctx, ptr, AKERR_NULLPOINTER, "Received NULL sprite reference");
|
||||
if ( ptr->refcount > 0 ) {
|
||||
ptr->refcount -= 1;
|
||||
}
|
||||
@@ -160,10 +162,10 @@ ErrorContext *heap_release_sprite(sprite *ptr)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *heap_release_spritesheet(spritesheet *ptr)
|
||||
akerr_ErrorContext *heap_release_spritesheet(spritesheet *ptr)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, ptr, ERR_NULLPOINTER, "Received NULL spritesheet reference");
|
||||
FAIL_ZERO_RETURN(errctx, ptr, AKERR_NULLPOINTER, "Received NULL spritesheet reference");
|
||||
if ( ptr->refcount > 0 ) {
|
||||
ptr->refcount -= 1;
|
||||
}
|
||||
@@ -177,10 +179,10 @@ ErrorContext *heap_release_spritesheet(spritesheet *ptr)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *heap_release_string(string *ptr)
|
||||
akerr_ErrorContext *heap_release_string(string *ptr)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, ptr, ERR_NULLPOINTER, "Received NULL string reference");
|
||||
FAIL_ZERO_RETURN(errctx, ptr, AKERR_NULLPOINTER, "Received NULL string reference");
|
||||
if ( ptr->refcount > 0 ) {
|
||||
ptr->refcount -= 1;
|
||||
}
|
||||
|
||||
@@ -8,61 +8,61 @@
|
||||
#include <sdl3game/staticstring.h>
|
||||
#include <sdl3game/registry.h>
|
||||
|
||||
ErrorContext *get_json_object_value(json_t *obj, char *key, json_t **dest)
|
||||
akerr_ErrorContext *get_json_object_value(json_t *obj, char *key, json_t **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL object pointer");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL object pointer");
|
||||
json_t *value = json_object_get(obj, key);
|
||||
FAIL_ZERO_RETURN(errctx, value, ERR_KEY, "Key %s not found in object", key);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_object(value)), ERR_TYPE, "Key %s in object has incorrect type", key);
|
||||
FAIL_ZERO_RETURN(errctx, value, AKERR_KEY, "Key %s not found in object", key);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_object(value)), AKERR_TYPE, "Key %s in object has incorrect type", key);
|
||||
*dest = value;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *get_json_boolean_value(json_t *obj, char *key, bool *dest)
|
||||
akerr_ErrorContext *get_json_boolean_value(json_t *obj, char *key, bool *dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL object pointer");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL object pointer");
|
||||
json_t *value = json_object_get(obj, key);
|
||||
FAIL_ZERO_RETURN(errctx, value, ERR_KEY, "Key %s not found in object", key);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_boolean(value)), ERR_TYPE, "Key %s in object has incorrect type", key);
|
||||
FAIL_ZERO_RETURN(errctx, value, AKERR_KEY, "Key %s not found in object", key);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_boolean(value)), AKERR_TYPE, "Key %s in object has incorrect type", key);
|
||||
*dest = json_boolean_value(value);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *get_json_integer_value(json_t *obj, char *key, int *dest)
|
||||
akerr_ErrorContext *get_json_integer_value(json_t *obj, char *key, int *dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL object pointer");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL object pointer");
|
||||
json_t *value = json_object_get(obj, key);
|
||||
FAIL_ZERO_RETURN(errctx, value, ERR_KEY, "Key %s not found in object", key);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_integer(value)), ERR_TYPE, "Key %s in object has incorrect type", key);
|
||||
FAIL_ZERO_RETURN(errctx, value, AKERR_KEY, "Key %s not found in object", key);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_integer(value)), AKERR_TYPE, "Key %s in object has incorrect type", key);
|
||||
*dest = json_integer_value(value);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *get_json_number_value(json_t *obj, char *key, float *dest)
|
||||
akerr_ErrorContext *get_json_number_value(json_t *obj, char *key, float *dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL pointer reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL pointer reference");
|
||||
json_t *value = json_object_get(obj, key);
|
||||
FAIL_ZERO_RETURN(errctx, value, ERR_KEY, "Key %s not found in object", key);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_number(value)), ERR_TYPE, "Key %s in object has incorrect type", key);
|
||||
FAIL_ZERO_RETURN(errctx, value, AKERR_KEY, "Key %s not found in object", key);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_number(value)), AKERR_TYPE, "Key %s in object has incorrect type", key);
|
||||
*dest = json_number_value(value);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *get_json_string_value(json_t *obj, char *key, string **dest)
|
||||
akerr_ErrorContext *get_json_string_value(json_t *obj, char *key, string **dest)
|
||||
{
|
||||
json_t *value = NULL;
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL pointer reference");
|
||||
FAIL_ZERO_RETURN(errctx, key, ERR_NULLPOINTER, "NULL pointer reference");
|
||||
FAIL_ZERO_RETURN(errctx, dest, ERR_NULLPOINTER, "NULL pointer reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL pointer reference");
|
||||
FAIL_ZERO_RETURN(errctx, key, AKERR_NULLPOINTER, "NULL pointer reference");
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "NULL pointer reference");
|
||||
|
||||
value = json_object_get(obj, key);
|
||||
FAIL_ZERO_RETURN(errctx, value, ERR_KEY, "Key %s not found in object", key);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_string(value)), ERR_TYPE, "Key %s in object has incorrect type", key);
|
||||
FAIL_ZERO_RETURN(errctx, value, AKERR_KEY, "Key %s not found in object", key);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_string(value)), AKERR_TYPE, "Key %s in object has incorrect type", key);
|
||||
ATTEMPT {
|
||||
if ( *dest == NULL ) {
|
||||
CATCH(errctx, heap_next_string(dest));
|
||||
@@ -76,47 +76,47 @@ ErrorContext *get_json_string_value(json_t *obj, char *key, string **dest)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *get_json_array_value(json_t *obj, char *key, json_t **dest)
|
||||
akerr_ErrorContext *get_json_array_value(json_t *obj, char *key, json_t **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL pointer reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL pointer reference");
|
||||
json_t *value = json_object_get(obj, key);
|
||||
FAIL_ZERO_RETURN(errctx, value, ERR_KEY, "Key %s not found in object", key);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_array(value)), ERR_TYPE, "Key %s in object has incorrect type", key);
|
||||
FAIL_ZERO_RETURN(errctx, value, AKERR_KEY, "Key %s not found in object", key);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_array(value)), AKERR_TYPE, "Key %s in object has incorrect type", key);
|
||||
*dest = value;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *get_json_array_index_object(json_t *array, int index, json_t **dest)
|
||||
akerr_ErrorContext *get_json_array_index_object(json_t *array, int index, json_t **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, array, ERR_NULLPOINTER, "NULL pointer reference");
|
||||
FAIL_ZERO_RETURN(errctx, array, AKERR_NULLPOINTER, "NULL pointer reference");
|
||||
json_t *value = json_array_get(array, index);
|
||||
FAIL_ZERO_RETURN(errctx, value, ERR_OUTOFBOUNDS, "Index %d out of bounds for array", index);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_object(value)), ERR_TYPE, "Index %d in object has incorrect type", index);
|
||||
FAIL_ZERO_RETURN(errctx, value, AKERR_OUTOFBOUNDS, "Index %d out of bounds for array", index);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_object(value)), AKERR_TYPE, "Index %d in object has incorrect type", index);
|
||||
*dest = value;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *get_json_array_index_integer(json_t *array, int index, int *dest)
|
||||
akerr_ErrorContext *get_json_array_index_integer(json_t *array, int index, int *dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, array, ERR_NULLPOINTER, "NULL pointer reference");
|
||||
FAIL_ZERO_RETURN(errctx, array, AKERR_NULLPOINTER, "NULL pointer reference");
|
||||
json_t *value = json_array_get(array, index);
|
||||
FAIL_ZERO_RETURN(errctx, value, ERR_OUTOFBOUNDS, "Index %d out of bounds for array", index);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_integer(value)), ERR_TYPE, "Index %d in object has incorrect type", index);
|
||||
FAIL_ZERO_RETURN(errctx, value, AKERR_OUTOFBOUNDS, "Index %d out of bounds for array", index);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_integer(value)), AKERR_TYPE, "Index %d in object has incorrect type", index);
|
||||
*dest = json_integer_value(value);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *get_json_array_index_string(json_t *array, int index, string **dest)
|
||||
akerr_ErrorContext *get_json_array_index_string(json_t *array, int index, string **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, array, ERR_NULLPOINTER, "NULL pointer reference");
|
||||
FAIL_ZERO_RETURN(errctx, dest, ERR_NULLPOINTER, "NULL destination pointer reference");
|
||||
FAIL_ZERO_RETURN(errctx, array, AKERR_NULLPOINTER, "NULL pointer reference");
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "NULL destination pointer reference");
|
||||
json_t *value = json_array_get(array, index);
|
||||
FAIL_ZERO_RETURN(errctx, value, ERR_OUTOFBOUNDS, "Index %d out of bounds for array", index);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_string(value)), ERR_TYPE, "Index %d in object has incorrect type", index);
|
||||
FAIL_ZERO_RETURN(errctx, value, AKERR_OUTOFBOUNDS, "Index %d out of bounds for array", index);
|
||||
FAIL_ZERO_RETURN(errctx, (json_is_string(value)), AKERR_TYPE, "Index %d in object has incorrect type", index);
|
||||
ATTEMPT {
|
||||
if ( *dest == NULL ) {
|
||||
CATCH(errctx, heap_next_string(dest));
|
||||
|
||||
@@ -12,7 +12,7 @@ SDL_PropertiesID REGISTRY_SPRITE;
|
||||
SDL_PropertiesID REGISTRY_SPRITESHEET;
|
||||
SDL_PropertiesID REGISTRY_CHARACTER;
|
||||
|
||||
ErrorContext *registry_init()
|
||||
akerr_ErrorContext *registry_init()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
ATTEMPT {
|
||||
@@ -27,21 +27,21 @@ ErrorContext *registry_init()
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *registry_init_actor()
|
||||
akerr_ErrorContext *registry_init_actor()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
REGISTRY_ACTOR = SDL_CreateProperties();
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_ACTOR, ERR_NULLPOINTER, "Error initializing actor registry");
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_ACTOR, AKERR_NULLPOINTER, "Error initializing actor registry");
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *registry_init_actor_state_strings()
|
||||
akerr_ErrorContext *registry_init_actor_state_strings()
|
||||
{
|
||||
int i = 0;
|
||||
int flag = 0;
|
||||
PREPARE_ERROR(errctx);
|
||||
REGISTRY_ACTOR_STATE_STRINGS = SDL_CreateProperties();
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_ACTOR_STATE_STRINGS, ERR_NULLPOINTER, "Error initializing actor state strings registry");
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_ACTOR_STATE_STRINGS, AKERR_NULLPOINTER, "Error initializing actor state strings registry");
|
||||
for ( i = 0 ; i < ACTOR_MAX_STATES; i++ ) {
|
||||
flag = (1 << i);
|
||||
SDL_SetNumberProperty(
|
||||
@@ -52,26 +52,26 @@ ErrorContext *registry_init_actor_state_strings()
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *registry_init_sprite()
|
||||
akerr_ErrorContext *registry_init_sprite()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
REGISTRY_SPRITE = SDL_CreateProperties();
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_SPRITE, ERR_NULLPOINTER, "Error initializing sprite registry");
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_SPRITE, AKERR_NULLPOINTER, "Error initializing sprite registry");
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *registry_init_spritesheet()
|
||||
akerr_ErrorContext *registry_init_spritesheet()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
REGISTRY_SPRITESHEET = SDL_CreateProperties();
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_SPRITESHEET, ERR_NULLPOINTER, "Error initializing spritesheet registry");
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_SPRITESHEET, AKERR_NULLPOINTER, "Error initializing spritesheet registry");
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *registry_init_character()
|
||||
akerr_ErrorContext *registry_init_character()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
REGISTRY_CHARACTER = SDL_CreateProperties();
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_CHARACTER, ERR_NULLPOINTER, "Error initializing character registry");
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_CHARACTER, AKERR_NULLPOINTER, "Error initializing character registry");
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
28
src/sprite.c
28
src/sprite.c
@@ -13,7 +13,7 @@
|
||||
#include <sdl3game/staticstring.h>
|
||||
#include <sdl3game/iterator.h>
|
||||
|
||||
static ErrorContext *sprite_load_json_spritesheet(json_t *json, spritesheet **sheet, char *relative_path)
|
||||
static akerr_ErrorContext *sprite_load_json_spritesheet(json_t *json, spritesheet **sheet, char *relative_path)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
json_t *spritesheet_json = NULL;
|
||||
@@ -58,7 +58,7 @@ static ErrorContext *sprite_load_json_spritesheet(json_t *json, spritesheet **sh
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *sprite_load_json(char *filename)
|
||||
akerr_ErrorContext *sprite_load_json(char *filename)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
json_t *json = NULL;
|
||||
@@ -70,7 +70,7 @@ ErrorContext *sprite_load_json(char *filename)
|
||||
//string *tmpstr = NULL;
|
||||
int i = 0;
|
||||
|
||||
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_sprite(&obj));
|
||||
//CATCH(errctx, heap_next_string(&tmpstr));
|
||||
@@ -83,7 +83,7 @@ ErrorContext *sprite_load_json(char *filename)
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
json,
|
||||
ERR_NULLPOINTER,
|
||||
AKERR_NULLPOINTER,
|
||||
"Error while loading sprite from %s on line %d: %s", filename, error.line, error.text
|
||||
);
|
||||
|
||||
@@ -119,12 +119,12 @@ ErrorContext *sprite_load_json(char *filename)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *sprite_initialize(sprite *spr, char *name, spritesheet *sheet)
|
||||
akerr_ErrorContext *sprite_initialize(sprite *spr, char *name, spritesheet *sheet)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, spr, ERR_NULLPOINTER, "Null sprite reference");
|
||||
FAIL_ZERO_RETURN(errctx, name, ERR_NULLPOINTER, "Empty sprite name");
|
||||
FAIL_ZERO_RETURN(errctx, sheet, ERR_NULLPOINTER, "Null spritesheet reference");
|
||||
FAIL_ZERO_RETURN(errctx, spr, AKERR_NULLPOINTER, "Null sprite reference");
|
||||
FAIL_ZERO_RETURN(errctx, name, AKERR_NULLPOINTER, "Empty sprite name");
|
||||
FAIL_ZERO_RETURN(errctx, sheet, AKERR_NULLPOINTER, "Null spritesheet reference");
|
||||
|
||||
memset(spr, 0x00, sizeof(sprite));
|
||||
memcpy(spr->name, name, SPRITE_MAX_NAME_LENGTH);
|
||||
@@ -132,20 +132,20 @@ ErrorContext *sprite_initialize(sprite *spr, char *name, spritesheet *sheet)
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
SDL_SetPointerProperty(REGISTRY_SPRITE, (char *)&spr->name, (void *)spr),
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Unable to add sprite to registry");
|
||||
spr->refcount += 1;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *spritesheet_initialize(spritesheet *sheet, int sprite_w, int sprite_h, char *filename)
|
||||
akerr_ErrorContext *spritesheet_initialize(spritesheet *sheet, int sprite_w, int sprite_h, char *filename)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
//string *tmpstr = NULL;
|
||||
|
||||
ATTEMPT {
|
||||
FAIL_ZERO_BREAK(errctx, sheet, ERR_NULLPOINTER, "Null spritesheet pointer");
|
||||
FAIL_ZERO_BREAK(errctx, filename, ERR_NULLPOINTER, "Null filename pointer");
|
||||
FAIL_ZERO_BREAK(errctx, sheet, AKERR_NULLPOINTER, "Null spritesheet pointer");
|
||||
FAIL_ZERO_BREAK(errctx, filename, AKERR_NULLPOINTER, "Null filename pointer");
|
||||
|
||||
memset(sheet, 0x00, sizeof(spritesheet));
|
||||
|
||||
@@ -156,12 +156,12 @@ ErrorContext *spritesheet_initialize(spritesheet *sheet, int sprite_w, int sprit
|
||||
|
||||
//snprintf((char *)&tmpstr->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), filename);
|
||||
sheet->texture = IMG_LoadTexture(renderer, filename);
|
||||
FAIL_ZERO_BREAK(errctx, sheet->texture, ERR_SDL, "Failed loading asset %s : %s", filename, SDL_GetError());
|
||||
FAIL_ZERO_BREAK(errctx, sheet->texture, AKERR_SDL, "Failed loading asset %s : %s", filename, SDL_GetError());
|
||||
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
SDL_SetPointerProperty(REGISTRY_SPRITESHEET, (char *)sheet->name, (void *)sheet),
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Unable to add spritesheet to registry: %s",
|
||||
SDL_GetError());
|
||||
sheet->refcount += 1;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <akerror.h>
|
||||
#include <sdl3game/staticstring.h>
|
||||
|
||||
ErrorContext *string_initialize(string *obj, char *init)
|
||||
akerr_ErrorContext *string_initialize(string *obj, char *init)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "Attempted to initialize NULL string reference");
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Attempted to initialize NULL string reference");
|
||||
if ( init != NULL ) {
|
||||
strncpy((char *)&obj->data, init, MAX_STRING_LENGTH);
|
||||
} else {
|
||||
|
||||
@@ -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
|
||||
|
||||
46
src/util.c
46
src/util.c
@@ -10,11 +10,11 @@
|
||||
#include <sdl3game/registry.h>
|
||||
#include <sdl3game/game.h>
|
||||
|
||||
ErrorContext *rectangle_points(RectanglePoints *dest, SDL_FRect *rect)
|
||||
akerr_ErrorContext *rectangle_points(RectanglePoints *dest, SDL_FRect *rect)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, dest, ERR_NULLPOINTER, "NULL RectanglePoints reference");
|
||||
FAIL_ZERO_RETURN(errctx, rect, ERR_NULLPOINTER, "NULL Rectangle reference");
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "NULL RectanglePoints reference");
|
||||
FAIL_ZERO_RETURN(errctx, rect, AKERR_NULLPOINTER, "NULL Rectangle reference");
|
||||
dest->topleft.x = rect->x;
|
||||
dest->topleft.y = rect->y;
|
||||
dest->bottomleft.x = rect->x;
|
||||
@@ -26,12 +26,12 @@ ErrorContext *rectangle_points(RectanglePoints *dest, SDL_FRect *rect)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *collide_point_rectangle(point *p, RectanglePoints *rp, bool *collide)
|
||||
akerr_ErrorContext *collide_point_rectangle(point *p, RectanglePoints *rp, bool *collide)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, p, ERR_NULLPOINTER, "NULL Point reference");
|
||||
FAIL_ZERO_RETURN(errctx, rp, ERR_NULLPOINTER, "NULL RectanglePoints reference");
|
||||
FAIL_ZERO_RETURN(errctx, collide, ERR_NULLPOINTER, "NULL boolean reference");
|
||||
FAIL_ZERO_RETURN(errctx, p, AKERR_NULLPOINTER, "NULL Point reference");
|
||||
FAIL_ZERO_RETURN(errctx, rp, AKERR_NULLPOINTER, "NULL RectanglePoints reference");
|
||||
FAIL_ZERO_RETURN(errctx, collide, AKERR_NULLPOINTER, "NULL boolean reference");
|
||||
if ( (p->x >= rp->topleft.x) && (p->y >= rp->topleft.y) &&
|
||||
(p->x <= rp->bottomright.x) && (p->y <= rp->bottomright.y) ) {
|
||||
*collide = true;
|
||||
@@ -41,14 +41,14 @@ ErrorContext *collide_point_rectangle(point *p, RectanglePoints *rp, bool *colli
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *collide)
|
||||
akerr_ErrorContext *collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *collide)
|
||||
{
|
||||
RectanglePoints r1p;
|
||||
RectanglePoints r2p;
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, r1, ERR_NULLPOINTER, "NULL rectangle reference");
|
||||
FAIL_ZERO_RETURN(errctx, r2, ERR_NULLPOINTER, "NULL rectangle reference");
|
||||
FAIL_ZERO_RETURN(errctx, collide, ERR_NULLPOINTER, "NULL collision flag reference");
|
||||
FAIL_ZERO_RETURN(errctx, r1, AKERR_NULLPOINTER, "NULL rectangle reference");
|
||||
FAIL_ZERO_RETURN(errctx, r2, AKERR_NULLPOINTER, "NULL rectangle reference");
|
||||
FAIL_ZERO_RETURN(errctx, collide, AKERR_NULLPOINTER, "NULL collision flag reference");
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, rectangle_points(&r1p, r1));
|
||||
@@ -95,16 +95,16 @@ ErrorContext *collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *collide)
|
||||
}
|
||||
|
||||
|
||||
ErrorContext *compare_sdl_surfaces(SDL_Surface *s1, SDL_Surface *s2)
|
||||
akerr_ErrorContext *compare_sdl_surfaces(SDL_Surface *s1, SDL_Surface *s2)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, s1, ERR_NULLPOINTER, "NULL Surface pointer");
|
||||
FAIL_ZERO_RETURN(errctx, s2, ERR_NULLPOINTER, "NULL Surface pointer");
|
||||
FAIL_NONZERO_RETURN(errctx, memcmp(s1->pixels, s2->pixels, (s1->pitch * s1->h)), ERR_VALUE, "Comparison surfaces are not equal");
|
||||
FAIL_ZERO_RETURN(errctx, s1, AKERR_NULLPOINTER, "NULL Surface pointer");
|
||||
FAIL_ZERO_RETURN(errctx, s2, AKERR_NULLPOINTER, "NULL Surface pointer");
|
||||
FAIL_NONZERO_RETURN(errctx, memcmp(s1->pixels, s2->pixels, (s1->pitch * s1->h)), AKERR_VALUE, "Comparison surfaces are not equal");
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y, int w, int h, char *writeout)
|
||||
akerr_ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y, int w, int h, char *writeout)
|
||||
{
|
||||
SDL_Surface *s1 = NULL;
|
||||
SDL_Surface *s2 = NULL;
|
||||
@@ -115,8 +115,8 @@ ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y,
|
||||
|
||||
PREPARE_ERROR(errctx);
|
||||
ATTEMPT {
|
||||
FAIL_ZERO_BREAK(errctx, t1, ERR_NULLPOINTER, "NULL texture");
|
||||
FAIL_ZERO_BREAK(errctx, t2, ERR_NULLPOINTER, "NULL texture");
|
||||
FAIL_ZERO_BREAK(errctx, t1, AKERR_NULLPOINTER, "NULL texture");
|
||||
FAIL_ZERO_BREAK(errctx, t2, AKERR_NULLPOINTER, "NULL texture");
|
||||
|
||||
CATCH(errctx, heap_next_string(&tmpstring));
|
||||
SDL_RenderClear(renderer);
|
||||
@@ -127,17 +127,17 @@ ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y,
|
||||
t1,
|
||||
&src,
|
||||
&dest),
|
||||
ERR_SDL,
|
||||
AKERR_SDL,
|
||||
"Failed to render test texture");
|
||||
s1 = SDL_RenderReadPixels(renderer, &read);
|
||||
FAIL_ZERO_BREAK(errctx, s1, ERR_SDL, "Failed to read pixels from renderer");
|
||||
FAIL_ZERO_BREAK(errctx, s1, AKERR_SDL, "Failed to read pixels from renderer");
|
||||
|
||||
if ( writeout != NULL ) {
|
||||
snprintf((char *)&tmpstring->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), writeout);
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
IMG_SavePNG(s1, (char *)&tmpstring->data),
|
||||
ERR_IO,
|
||||
AKERR_IO,
|
||||
"Unable to save %s: %s",
|
||||
(char *)&tmpstring->data,
|
||||
SDL_GetError());
|
||||
@@ -152,10 +152,10 @@ ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y,
|
||||
t2,
|
||||
&src,
|
||||
&dest),
|
||||
ERR_SDL,
|
||||
AKERR_SDL,
|
||||
"Failed to render test texture");
|
||||
s2 = SDL_RenderReadPixels(renderer, &read);
|
||||
FAIL_ZERO_BREAK(errctx, s2, ERR_SDL, "Failed to read pixels from renderer");
|
||||
FAIL_ZERO_BREAK(errctx, s2, AKERR_SDL, "Failed to read pixels from renderer");
|
||||
|
||||
CATCH(errctx, compare_sdl_surfaces(s1, s2));
|
||||
} CLEANUP {
|
||||
|
||||
Reference in New Issue
Block a user