Improved control map handling
This commit is contained in:
120
src/actor.c
120
src/actor.c
@@ -298,3 +298,123 @@ void registry_iterate_actor(void *userdata, SDL_PropertiesID registry, const cha
|
||||
} PROCESS(errctx) {
|
||||
} FINISH_NORETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_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");
|
||||
if ( BITMASK_HAS(obj->state, ACTOR_STATE_MOVING_LEFT) ) {
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
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));
|
||||
SDL_Log("new target actor state: %b", obj->state);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_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");
|
||||
if ( !BITMASK_HAS(obj->state, ACTOR_STATE_MOVING_LEFT) ) {
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
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_FACE_ALL | ACTOR_STATE_MOVING_ALL));
|
||||
BITMASK_ADD(obj->state, ACTOR_STATE_FACE_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)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, ERR_NULLPOINTER, "NULL event");
|
||||
if ( BITMASK_HAS(obj->state, ACTOR_STATE_MOVING_RIGHT) ) {
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
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));
|
||||
SDL_Log("new target actor state: %b", obj->state);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_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");
|
||||
if ( !BITMASK_HAS(obj->state, ACTOR_STATE_MOVING_RIGHT) ) {
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
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_FACE_ALL | ACTOR_STATE_MOVING_ALL));
|
||||
BITMASK_ADD(obj->state, ACTOR_STATE_FACE_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)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, ERR_NULLPOINTER, "NULL event");
|
||||
if ( BITMASK_HAS(obj->state, ACTOR_STATE_MOVING_UP) ) {
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
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));
|
||||
SDL_Log("new target actor state: %b", obj->state);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_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");
|
||||
if ( !BITMASK_HAS(obj->state, ACTOR_STATE_MOVING_UP) ) {
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
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_FACE_ALL | ACTOR_STATE_MOVING_ALL));
|
||||
BITMASK_ADD(obj->state, ACTOR_STATE_FACE_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)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, ERR_NULLPOINTER, "NULL actor");
|
||||
FAIL_ZERO_RETURN(errctx, event, ERR_NULLPOINTER, "NULL event");
|
||||
if ( BITMASK_HAS(obj->state, ACTOR_STATE_MOVING_DOWN) ) {
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
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));
|
||||
SDL_Log("new target actor state: %b", obj->state);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext ERROR_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");
|
||||
if ( !BITMASK_HAS(obj->state, ACTOR_STATE_MOVING_DOWN) ) {
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
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_FACE_ALL | ACTOR_STATE_MOVING_ALL));
|
||||
BITMASK_ADD(obj->state, ACTOR_STATE_FACE_DOWN);
|
||||
SDL_Log("new target actor state: %b", obj->state);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <sdl3game/registry.h>
|
||||
#include <sdl3game/staticstring.h>
|
||||
#include <sdl3game/iterator.h>
|
||||
|
||||
#include <sdl3game/util.h>
|
||||
|
||||
ErrorContext *character_initialize(character *obj, char *name)
|
||||
{
|
||||
@@ -44,7 +44,7 @@ ErrorContext *character_sprite_add(character *basechar, sprite *ref, int state)
|
||||
memset(&stateval, 0x00, 32);
|
||||
SDL_itoa(state, (char *)&stateval, 10);
|
||||
SDL_SetPointerProperty(basechar->state_sprites, (char *)&stateval, ref);
|
||||
SDL_Log("Added sprite %s to character %s for state %s", (char *)&ref->name, (char *)&basechar->name, (char *)&stateval);
|
||||
SDL_Log("Added sprite %s to character %s for state %b", (char *)&ref->name, (char *)&basechar->name, state);
|
||||
ref->refcount += 1;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
@@ -59,9 +59,9 @@ ErrorContext *character_sprite_get(character *basechar, int state, sprite **dest
|
||||
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 (%s) not found in the character's registry", state, (char *)&stateval);
|
||||
FAIL_ZERO_RETURN(errctx, *dest, ERR_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);
|
||||
//SDL_Log("Sprite state %d (%s) has character %s", state, (char *)&stateval, target->name);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ static ErrorContext *character_load_json_inner(json_t *json, character *obj)
|
||||
errctx,
|
||||
spriteptr,
|
||||
ERR_NULLPOINTER,
|
||||
"Character %s for state %d references sprite %s but not found in the registry",
|
||||
"Character %s for state %b references sprite %s but not found in the registry",
|
||||
tmpstr2->data,
|
||||
stateval,
|
||||
tmpstr->data
|
||||
|
||||
@@ -40,16 +40,10 @@ ErrorContext *controller_handle_event(void *appstate, SDL_Event *event)
|
||||
event->key.key == curcontrol->key)
|
||||
);
|
||||
if ( event->type == curcontrol->event_on && eventButtonComboMatch) {
|
||||
SDL_Log("event %d (button %d / key %d) ACTIVATES controlmap %d control %d", event->type, event->gbutton.which, event->key.key, i, j);
|
||||
BITMASK_DEL(curmap->target->state, curcontrol->target_del_state_on);
|
||||
BITMASK_ADD(curmap->target->state, curcontrol->target_add_state_on);
|
||||
SDL_Log("new target actor state: %d", curmap->target->state);
|
||||
CATCH(errctx, curcontrol->handler_on(curmap->target, event));
|
||||
goto _controller_handle_event_success;
|
||||
} else if ( event->type == curcontrol->event_off && eventButtonComboMatch ) {
|
||||
SDL_Log("event %d (button %d / key %d) DE-ACTIVATES controlmap %d control %d", event->type, event->gbutton.which, event->key.key, i, j);
|
||||
BITMASK_DEL(curmap->target->state, curcontrol->target_del_state_off);
|
||||
BITMASK_ADD(curmap->target->state, curcontrol->target_add_state_off);
|
||||
SDL_Log("new target actor state: %d", curmap->target->state);
|
||||
CATCH(errctx, curcontrol->handler_off(curmap->target, event));
|
||||
goto _controller_handle_event_success;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3_image/SDL_image.h>
|
||||
#include <sdlerror.h>
|
||||
|
||||
Reference in New Issue
Block a user