Mercurial > molko
changeset 441:31c1bbc33813
man: document mlk-action
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 24 Oct 2022 21:29:39 +0200 |
parents | c9bd1ff1ebe1 |
children | 9c3b3935f0aa |
files | GNUmakefile examples/example-action/example-action.c examples/example/trace_hud.c examples/example/trace_hud.h libmlk-core/mlk/core/action-stack.c libmlk-core/mlk/core/action-stack.h libmlk-core/mlk/core/action.c libmlk-core/mlk/core/action.h libmlk-core/mlk/core/script.c libmlk-core/mlk/core/script.h libmlk-rpg/mlk/rpg/message.c libmlk-rpg/mlk/rpg/message.h man/mlk-action.3 man/mlk_action_draw.3 man/mlk_action_end.3 man/mlk_action_finish.3 man/mlk_action_handle.3 man/mlk_action_update.3 tests/test-action-script.c tests/test-action.c |
diffstat | 20 files changed, 346 insertions(+), 132 deletions(-) [+] |
line wrap: on
line diff
--- a/GNUmakefile Tue Oct 18 09:04:02 2022 +0200 +++ b/GNUmakefile Mon Oct 24 21:29:39 2022 +0200 @@ -415,9 +415,15 @@ # {{{ manual pages -MAN3 := man/mlk-alloc.3 \ +MAN3 := man/mlk-action.3 \ + man/mlk-alloc.3 \ man/mlk-err.3 \ man/mlk_err_string.3 + man/mlk_action_draw.3 \ + man/mlk_action_end.3 \ + man/mlk_action_finish.3 \ + man/mlk_action_handle.3 \ + man/mlk_action_update.3 # }}}
--- a/examples/example-action/example-action.c Tue Oct 18 09:04:02 2022 +0200 +++ b/examples/example-action/example-action.c Mon Oct 24 21:29:39 2022 +0200 @@ -52,11 +52,11 @@ #define MY (100) /* This is a stack of "parallel" events. */ -static struct action *events_actions[32]; +static struct mlk_action *events_actions[32]; static struct action_stack events; /* This is a stack of modal events. */ -static struct action *modal_actions[32]; +static struct mlk_action *modal_actions[32]; static struct action_stack modal; /* Maximum number of states. */ @@ -68,13 +68,13 @@ static struct { const char *text[2]; struct message msg; - struct action msg_act; + struct mlk_action msg_act; int x; int y; int opened; struct texture image; struct sprite sprite; - struct action event; + struct mlk_action event; } chest = { .text = { "100000 pièces.", @@ -110,7 +110,7 @@ struct { const char *text[6]; struct message msg; - struct action act; + struct mlk_action act; } msgs[5]; /* This is the sprite and action to click on. */ @@ -118,13 +118,13 @@ int y; struct texture image; struct sprite sprite; - struct action event; + struct mlk_action event; /* This is the event for the response. */ - struct action response; + struct mlk_action response; struct script script; - struct action script_act; + struct mlk_action script_act; } guide = { .msgs = { { @@ -199,7 +199,7 @@ }; static int -guide_response_update(struct action *act, unsigned int ticks) +guide_response_update(struct mlk_action *act, unsigned int ticks) { /* Immediately return to get access to end. */ (void)act; @@ -209,7 +209,7 @@ } static void -guide_response_end(struct action *act) +guide_response_end(struct mlk_action *act) { (void)act; @@ -244,7 +244,7 @@ } static void -guide_handle(struct action *act, const union event *ev) +guide_handle(struct mlk_action *act, const union event *ev) { (void)act; @@ -264,7 +264,7 @@ } static void -guide_draw(struct action *act) +guide_draw(struct mlk_action *act) { (void)act; @@ -287,7 +287,7 @@ } static void -chest_handle(struct action *act, const union event *ev) +chest_handle(struct mlk_action *act, const union event *ev) { (void)act; @@ -309,7 +309,7 @@ } static void -chest_draw(struct action *act) +chest_draw(struct mlk_action *act) { (void)act;
--- a/examples/example/trace_hud.c Tue Oct 18 09:04:02 2022 +0200 +++ b/examples/example/trace_hud.c Mon Oct 24 21:29:39 2022 +0200 @@ -116,7 +116,7 @@ } static int -update(struct action *a, unsigned int ticks) +update(struct mlk_action *a, unsigned int ticks) { (void)a; @@ -126,17 +126,17 @@ } static void -draw(struct action *a) +draw(struct mlk_action *a) { (void)a; trace_hud_draw(); } -struct action * +struct mlk_action * trace_hud_action(void) { - static struct action a = { + static struct mlk_action a = { .update = update, .draw = draw };
--- a/examples/example/trace_hud.h Tue Oct 18 09:04:02 2022 +0200 +++ b/examples/example/trace_hud.h Mon Oct 24 21:29:39 2022 +0200 @@ -43,7 +43,7 @@ void trace_hud_clear(void); -struct action * +struct mlk_action * trace_hud_action(void); #endif /* !EXAMPLES_TRACE_TRACE_HUD_H */
--- a/libmlk-core/mlk/core/action-stack.c Tue Oct 18 09:04:02 2022 +0200 +++ b/libmlk-core/mlk/core/action-stack.c Mon Oct 24 21:29:39 2022 +0200 @@ -27,7 +27,7 @@ for (size_t i = 0; i < (st)->actionsz && ((iter) = (st)->actions[i], 1); ++i) void -action_stack_init(struct action_stack *st, struct action **actions, size_t actionsz) +action_stack_init(struct action_stack *st, struct mlk_action **actions, size_t actionsz) { assert(st); @@ -39,7 +39,7 @@ } int -action_stack_add(struct action_stack *st, struct action *act) +action_stack_add(struct action_stack *st, struct mlk_action *act) { assert(st); assert(act); @@ -60,11 +60,11 @@ assert(st); assert(ev); - struct action *act; + struct mlk_action *act; ACTION_FOREACH(st, act) if (act) - action_handle(act, ev); + mlk_action_handle(act, ev); } int @@ -72,14 +72,14 @@ { assert(st); - struct action *act; + struct mlk_action *act; for (size_t i = 0; i < st->actionsz; ++i) { act = st->actions[i]; - if (act && action_update(act, ticks)) { - action_end(act); - action_finish(act); + if (act && mlk_action_update(act, ticks)) { + mlk_action_end(act); + mlk_action_finish(act); st->actions[i] = NULL; } } @@ -96,11 +96,11 @@ { assert(st); - struct action *act; + struct mlk_action *act; ACTION_FOREACH(st, act) if (act) - action_draw(act); + mlk_action_draw(act); } int @@ -108,7 +108,7 @@ { assert(st); - struct action *act; + struct mlk_action *act; ACTION_FOREACH(st, act) if (act) @@ -122,12 +122,12 @@ { assert(st); - struct action *act; + struct mlk_action *act; ACTION_FOREACH(st, act) { if (act) { - action_end(act); - action_finish(act); + mlk_action_end(act); + mlk_action_finish(act); } }
--- a/libmlk-core/mlk/core/action-stack.h Tue Oct 18 09:04:02 2022 +0200 +++ b/libmlk-core/mlk/core/action-stack.h Mon Oct 24 21:29:39 2022 +0200 @@ -23,20 +23,22 @@ #include "core.h" +struct mlk_action; + union event; struct action_stack { - struct action **actions; + struct mlk_action **actions; size_t actionsz; }; CORE_BEGIN_DECLS void -action_stack_init(struct action_stack *, struct action **, size_t); +action_stack_init(struct action_stack *, struct mlk_action **, size_t); int -action_stack_add(struct action_stack *, struct action *); +action_stack_add(struct action_stack *, struct mlk_action *); void action_stack_handle(struct action_stack *, const union event *);
--- a/libmlk-core/mlk/core/action.c Tue Oct 18 09:04:02 2022 +0200 +++ b/libmlk-core/mlk/core/action.c Mon Oct 24 21:29:39 2022 +0200 @@ -21,7 +21,7 @@ #include "action.h" void -action_handle(struct action *act, const union event *ev) +mlk_action_handle(struct mlk_action *act, const union event *ev) { assert(act); assert(ev); @@ -31,7 +31,7 @@ } int -action_update(struct action *act, unsigned int ticks) +mlk_action_update(struct mlk_action *act, unsigned int ticks) { assert(act); @@ -43,7 +43,7 @@ } void -action_draw(struct action *act) +mlk_action_draw(struct mlk_action *act) { assert(act); @@ -52,7 +52,7 @@ } void -action_end(struct action *act) +mlk_action_end(struct mlk_action *act) { assert(act); @@ -61,7 +61,7 @@ } void -action_finish(struct action *act) +mlk_action_finish(struct mlk_action *act) { assert(act);
--- a/libmlk-core/mlk/core/action.h Tue Oct 18 09:04:02 2022 +0200 +++ b/libmlk-core/mlk/core/action.h Mon Oct 24 21:29:39 2022 +0200 @@ -23,31 +23,31 @@ union event; -struct action { +struct mlk_action { void *data; - void (*handle)(struct action *, const union event *); - int (*update)(struct action *, unsigned int); - void (*draw)(struct action *); - void (*end)(struct action *); - void (*finish)(struct action *); + void (*handle)(struct mlk_action *, const union event *); + int (*update)(struct mlk_action *, unsigned int); + void (*draw)(struct mlk_action *); + void (*end)(struct mlk_action *); + void (*finish)(struct mlk_action *); }; CORE_BEGIN_DECLS void -action_handle(struct action *, const union event *); +mlk_action_handle(struct mlk_action *, const union event *); int -action_update(struct action *, unsigned int); +mlk_action_update(struct mlk_action *, unsigned int); void -action_draw(struct action *); +mlk_action_draw(struct mlk_action *); void -action_end(struct action *); +mlk_action_end(struct mlk_action *); void -action_finish(struct action *); +mlk_action_finish(struct mlk_action *); CORE_END_DECLS
--- a/libmlk-core/mlk/core/script.c Tue Oct 18 09:04:02 2022 +0200 +++ b/libmlk-core/mlk/core/script.c Mon Oct 24 21:29:39 2022 +0200 @@ -24,7 +24,7 @@ #include "err.h" #include "script.h" -static struct action * +static struct mlk_action * current(struct script *s) { if (s->cur >= s->actionsz) @@ -34,25 +34,25 @@ } static void -handle(struct action *a, const union event *ev) +handle(struct mlk_action *a, const union event *ev) { script_handle(a->data, ev); } static int -update(struct action *a, unsigned int ticks) +update(struct mlk_action *a, unsigned int ticks) { return script_update(a->data, ticks); } static void -draw(struct action *a) +draw(struct mlk_action *a) { script_draw(a->data); } static void -finish(struct action *a) +finish(struct mlk_action *a) { script_finish(a->data); } @@ -66,7 +66,7 @@ } int -script_append(struct script *s, struct action *a) +script_append(struct script *s, struct mlk_action *a) { assert(s); assert(a); @@ -85,10 +85,10 @@ assert(s); assert(ev); - struct action *a = current(s); + struct mlk_action *a = current(s); if (a) - action_handle(a, ev); + mlk_action_handle(a, ev); } int @@ -96,13 +96,13 @@ { assert(s); - struct action *a = current(s); + struct mlk_action *a = current(s); if (!a) return 1; - if (action_update(a, ticks)) { - action_end(a); + if (mlk_action_update(a, ticks)) { + mlk_action_end(a); s->cur++; } @@ -114,10 +114,10 @@ { assert(s); - struct action *a = current(s); + struct mlk_action *a = current(s); if (a) - action_draw(a); + mlk_action_draw(a); } int @@ -134,13 +134,13 @@ assert(s); for (size_t i = 0; i < s->actionsz; ++i) - action_finish(s->actions[i]); + mlk_action_finish(s->actions[i]); memset(s, 0, sizeof (*s)); } void -script_action(struct script *s, struct action *action) +script_action(struct script *s, struct mlk_action *action) { assert(s); assert(action);
--- a/libmlk-core/mlk/core/script.h Tue Oct 18 09:04:02 2022 +0200 +++ b/libmlk-core/mlk/core/script.h Mon Oct 24 21:29:39 2022 +0200 @@ -25,12 +25,12 @@ #define SCRIPT_ACTION_MAX (128) -struct action; +struct mlk_action; union event; struct script { - struct action *actions[SCRIPT_ACTION_MAX]; + struct mlk_action *actions[SCRIPT_ACTION_MAX]; size_t actionsz; size_t cur; }; @@ -41,7 +41,7 @@ script_init(struct script *); int -script_append(struct script *, struct action *); +script_append(struct script *, struct mlk_action *); void script_handle(struct script *, const union event *); @@ -59,7 +59,7 @@ script_finish(struct script *); void -script_action(struct script*s, struct action *); +script_action(struct script *s, struct mlk_action *); CORE_END_DECLS
--- a/libmlk-rpg/mlk/rpg/message.c Tue Oct 18 09:04:02 2022 +0200 +++ b/libmlk-rpg/mlk/rpg/message.c Mon Oct 24 21:29:39 2022 +0200 @@ -40,7 +40,7 @@ #define THEME(msg) (msg->theme ? msg->theme : theme_default()) static void -handle(struct action *action, const union event *ev) +handle(struct mlk_action *action, const union event *ev) { assert(action); assert(ev); @@ -49,7 +49,7 @@ } static int -update(struct action *action, unsigned int ticks) +update(struct mlk_action *action, unsigned int ticks) { assert(action); @@ -57,7 +57,7 @@ } static void -draw(struct action *action) +draw(struct mlk_action *action) { assert(action); @@ -301,12 +301,12 @@ } void -message_action(struct message *msg, struct action *action) +message_action(struct message *msg, struct mlk_action *action) { assert(msg); assert(action); - memset(action, 0, sizeof (struct action)); + memset(action, 0, sizeof (struct mlk_action)); action->data = msg; action->handle = handle; action->update = update;
--- a/libmlk-rpg/mlk/rpg/message.h Tue Oct 18 09:04:02 2022 +0200 +++ b/libmlk-rpg/mlk/rpg/message.h Mon Oct 24 21:29:39 2022 +0200 @@ -22,7 +22,7 @@ #include <mlk/core/core.h> #include <mlk/core/texture.h> -struct action; +struct mlk_action; struct font; struct theme; @@ -84,7 +84,7 @@ message_hide(struct message *msg); void -message_action(struct message *msg, struct action *act); +message_action(struct message *msg, struct mlk_action *act); CORE_END_DECLS
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/man/mlk-action.3 Mon Oct 24 21:29:39 2022 +0200 @@ -0,0 +1,79 @@ +.Dd $Mdocdate$ +.Dt MLK-ACTION 3 +.Os +.Sh NAME +.Nm mlk-action +.Nd generic in game actions +.Sh LIBRARY +libmlk-core (-lmlk-core) +.Sh SYNOPSIS +.In mlk/core/action.h +.Sh DESCRIPTION +Generic updatable and drawable actions. +.Pp +This module help creating user interaction within the gameplay by adding +actions. They have the following properties: +.Pp +.Bl -dash -compact +.It +Can handle user input and events, +.It +Can be updated through the game loop, +.It +Can be drawn. +.El +.Pp +Most more high level objects can handle actions to add flexibility (like in +battles, maps, etc). +.Pp +This header defines the +.Vt "struct mlk_action" : +.Bd -literal +struct mlk_action { + void *data; + void (*handle)(struct mlk_action *self, const union mlk_event *ev); + int (*update)(struct mlk_action *self, unsigned int ticks); + void (*draw)(struct mlk_action *self); + void (*end)(struct mlk_action *self); + void (*finish)(struct mlk_action *self); +}; +.Ed +.Pp +Each member function takes the original action as first argument and other +arguments after. Its fields are: +.Bl -tag +.It Va data +Optional user data. +.It Va handle +Handle the event +.Fa ev . +.It Va update +Update the action with the +.Fa ticks +since last frame expressed as milliseconds. The callback should return non-zero +if it is considered complete. +.It Va draw +Draw the action. +.It Va end +Called when the action was completed. +.Pp +This callback is mostly provided to allow the user doing something else once an +action is complete. Predefined actions from the framework should not use this +callback by themselves. +.It Va finish +Destroy internal resources for this action. +.Pp +Close the action before removal. This function should be used to deallocate +memory if necessary. +.El +.Sh SEE ALSO +.Xr mlk_action_draw 3 , +.Xr mlk_action_end 3 , +.Xr mlk_action_finish 3 , +.Xr mlk_action_handle 3 , +.Xr mlk_action_update 3 +.Sh AUTHORS +The +.Nm +library was written by +.An David Demelier Aq Mt markand@malikania.fr .
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/man/mlk_action_draw.3 Mon Oct 24 21:29:39 2022 +0200 @@ -0,0 +1,23 @@ +.Dd $Mdocdate$ +.Dt MLK_ACTION_DRAW 3 +.Os +.Sh NAME +.Nm mlk_action_draw +.Nd draw an action +.Sh LIBRARY +libmlk-core (-lmlk-core) +.Sh SYNOPSIS +.In mlk/core/action.h +.Ft void +.Fn mlk_action_draw "struct mlk_action *self" +.Sh DESCRIPTION +Invoke the draw callback on the action +.Fa self +if it is not null. +.Sh SEE ALSO +.Xr mlk-action 3 +.Sh AUTHORS +The +.Nm +library was written by +.An David Demelier Aq Mt markand@malikania.fr .
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/man/mlk_action_end.3 Mon Oct 24 21:29:39 2022 +0200 @@ -0,0 +1,25 @@ +.Dd $Mdocdate$ +.Dt MLK_ACTION_END 3 +.Os +.Sh NAME +.Nm mlk_action_end +.Nd terminate an action +.Sh LIBRARY +libmlk-core (-lmlk-core) +.Sh SYNOPSIS +.In mlk/core/action.h +.Ft void +.Fn mlk_action_end "struct mlk_action *self" +.Sh DESCRIPTION +Invoke the +.Va end +callback on the action +.Fa self +if it is not null. +.Sh SEE ALSO +.Xr mlk-action 3 +.Sh AUTHORS +The +.Nm mlk-core +library was written by +.An David Demelier Aq Mt markand@malikania.fr .
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/man/mlk_action_finish.3 Mon Oct 24 21:29:39 2022 +0200 @@ -0,0 +1,25 @@ +.Dd $Mdocdate$ +.Dt MLK_ACTION_FINISH 3 +.Os +.Sh NAME +.Nm mlk_action_finish +.Nd cleanup action resources +.Sh LIBRARY +libmlk-core (-lmlk-core) +.Sh SYNOPSIS +.In mlk/core/action.h +.Ft void +.Fn mlk_action_finish "struct mlk_action *self" +.Sh DESCRIPTION +Invoke the +.Va finish +callback on the action +.Fa self +if it is not null. +.Sh SEE ALSO +.Xr mlk-action 3 +.Sh AUTHORS +The +.Nm mlk-core +library was written by +.An David Demelier Aq Mt markand@malikania.fr .
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/man/mlk_action_handle.3 Mon Oct 24 21:29:39 2022 +0200 @@ -0,0 +1,26 @@ +.Dd $Mdocdate$ +.Dt MLK_ACTION_HANDLE 3 +.Os +.Sh NAME +.Nm mlk_action_handle +.Nd handle an event +.Sh LIBRARY +libmlk-core (-lmlk-core) +.Sh SYNOPSIS +.In mlk/core/action.h +.Ft void +.Fn mlk_action_handle "struct mlk_action *self, const union mlk_event *ev" +.Sh DESCRIPTION +Invoke the +.Va handle +callback on the action +.Fa self +if it is not null with the event +.Fa ev +.Sh SEE ALSO +.Xr mlk-action 3 +.Sh AUTHORS +The +.Nm mlk-core +library was written by +.An David Demelier Aq Mt markand@malikania.fr .
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/man/mlk_action_update.3 Mon Oct 24 21:29:39 2022 +0200 @@ -0,0 +1,28 @@ +.Dd $Mdocdate$ +.Dt MLK_ACTION_UPDATE 3 +.Os +.Sh NAME +.Nm mlk_action_update +.Nd update an action +.Sh LIBRARY +libmlk-core (-lmlk-core) +.Sh SYNOPSIS +.In mlk/core/action.h +.Ft void +.Fn mlk_action_update "struct mlk_action *self, unsigned int ticks" +.Sh DESCRIPTION +Invoke the update callback on the action +.Fa self +if it is not null. +.Sh RETURN VALUES +The functions return the same value as the +.Va update +callback from the action and it should be non-zero if the action is considered +complete. +.Sh SEE ALSO +.Xr mlk-action 3 +.Sh AUTHORS +The +.Nm mlk-core +library was written by +.An David Demelier Aq Mt markand@malikania.fr .
--- a/tests/test-action-script.c Tue Oct 18 09:04:02 2022 +0200 +++ b/tests/test-action-script.c Mon Oct 24 21:29:39 2022 +0200 @@ -40,7 +40,7 @@ } static void -my_handle(struct action *act, const union event *ev) +my_handle(struct mlk_action *act, const union event *ev) { (void)ev; @@ -48,7 +48,7 @@ } static int -my_update_false(struct action *act, unsigned int ticks) +my_update_false(struct mlk_action *act, unsigned int ticks) { (void)ticks; @@ -58,7 +58,7 @@ } static int -my_update_true(struct action *act, unsigned int ticks) +my_update_true(struct mlk_action *act, unsigned int ticks) { (void)ticks; @@ -68,19 +68,19 @@ } static void -my_draw(struct action *act) +my_draw(struct mlk_action *act) { ((struct invokes *)act->data)->draw++; } static void -my_end(struct action *act) +my_end(struct mlk_action *act) { ((struct invokes *)act->data)->end++; } static void -my_finish(struct action *act) +my_finish(struct mlk_action *act) { ((struct invokes *)act->data)->finish++; } @@ -99,7 +99,7 @@ static void test_basics_append(void) { - struct action act[3] = {0}; + struct mlk_action act[3] = {0}; struct script sc = {0}; DT_ASSERT(script_append(&sc, &act[0]) == 0); @@ -128,7 +128,7 @@ { struct { struct invokes inv; - struct action act; + struct mlk_action act; } table[] = { { .act = INIT(&table[0].inv, my_update_true) }, { .act = INIT(&table[1].inv, my_update_true) }, @@ -205,7 +205,7 @@ { struct { struct invokes inv; - struct action act; + struct mlk_action act; } table[] = { { .act = INIT(&table[0].inv, my_update_true) }, { .act = INIT(&table[1].inv, my_update_true) }, @@ -299,7 +299,7 @@ { struct { struct invokes inv; - struct action act; + struct mlk_action act; } table[] = { { .act = INIT(&table[0].inv, my_update_true) }, { .act = INIT(&table[1].inv, my_update_true) }, @@ -376,7 +376,7 @@ { struct { struct invokes inv; - struct action act; + struct mlk_action act; } table[] = { { .act = INIT(&table[0].inv, my_update_true) }, { .act = INIT(&table[1].inv, my_update_true) }, @@ -416,7 +416,7 @@ { struct { struct invokes inv; - struct action act; + struct mlk_action act; } table[] = { { .act = INIT(&table[0].inv, my_update_true) }, { .act = INIT(&table[1].inv, my_update_true) }, @@ -424,7 +424,7 @@ }; struct script sc = {0}; - struct action act; + struct mlk_action act; DT_ASSERT(script_append(&sc, &table[0].act) == 0); DT_ASSERT(script_append(&sc, &table[1].act) == 0); @@ -434,11 +434,11 @@ script_action(&sc, &act); /* Draw and input before updating. */ - action_handle(&act, &(union event){0}); - action_draw(&act); + mlk_action_handle(&act, &(union event){0}); + mlk_action_draw(&act); /* [0] -> [1] */ - DT_ASSERT(!action_update(&act, 0)); + DT_ASSERT(!mlk_action_update(&act, 0)); DT_EQ_INT(table[0].inv.handle, 1); DT_EQ_INT(table[0].inv.update, 1); DT_EQ_INT(table[0].inv.draw, 1); @@ -455,11 +455,11 @@ DT_EQ_INT(table[2].inv.end, 0); DT_EQ_INT(table[2].inv.finish, 0); - action_handle(&act, &(union event){0}); - action_draw(&act); + mlk_action_handle(&act, &(union event){0}); + mlk_action_draw(&act); /* [1] -> [2] */ - DT_ASSERT(!action_update(&act, 0)); + DT_ASSERT(!mlk_action_update(&act, 0)); DT_EQ_INT(table[0].inv.handle, 1); DT_EQ_INT(table[0].inv.update, 1); DT_EQ_INT(table[0].inv.draw, 1); @@ -476,13 +476,13 @@ DT_EQ_INT(table[2].inv.end, 0); DT_EQ_INT(table[2].inv.finish, 0); - action_handle(&act, &(union event){0}); - action_draw(&act); + mlk_action_handle(&act, &(union event){0}); + mlk_action_draw(&act); /* 2 stays, it never ends. */ - DT_ASSERT(!action_update(&act, 0)); - DT_ASSERT(!action_update(&act, 0)); - DT_ASSERT(!action_update(&act, 0)); + DT_ASSERT(!mlk_action_update(&act, 0)); + DT_ASSERT(!mlk_action_update(&act, 0)); + DT_ASSERT(!mlk_action_update(&act, 0)); DT_EQ_INT(table[0].inv.handle, 1); DT_EQ_INT(table[0].inv.update, 1); DT_EQ_INT(table[0].inv.draw, 1); @@ -500,7 +500,7 @@ DT_EQ_INT(table[2].inv.finish, 0); table[2].act.update = my_update_true; - DT_ASSERT(action_update(&act, 0)); + DT_ASSERT(mlk_action_update(&act, 0)); DT_EQ_INT(table[0].inv.handle, 1); DT_EQ_INT(table[0].inv.update, 1); DT_EQ_INT(table[0].inv.draw, 1); @@ -518,7 +518,7 @@ DT_EQ_INT(table[2].inv.finish, 0); /* Also dispose resources. */ - action_finish(&act); + mlk_action_finish(&act); DT_EQ_INT(table[0].inv.handle, 1); DT_EQ_INT(table[0].inv.update, 1); DT_EQ_INT(table[0].inv.draw, 1);
--- a/tests/test-action.c Tue Oct 18 09:04:02 2022 +0200 +++ b/tests/test-action.c Mon Oct 24 21:29:39 2022 +0200 @@ -43,7 +43,7 @@ } static void -my_handle(struct action *act, const union event *ev) +my_handle(struct mlk_action *act, const union event *ev) { (void)ev; @@ -51,7 +51,7 @@ } static int -my_update_false(struct action *act, unsigned int ticks) +my_update_false(struct mlk_action *act, unsigned int ticks) { (void)ticks; @@ -61,7 +61,7 @@ } static int -my_update_true(struct action *act, unsigned int ticks) +my_update_true(struct mlk_action *act, unsigned int ticks) { (void)ticks; @@ -71,19 +71,19 @@ } static void -my_draw(struct action *act) +my_draw(struct mlk_action *act) { ((struct invokes *)act->data)->draw = 1; } static void -my_end(struct action *act) +my_end(struct mlk_action *act) { ((struct invokes *)act->data)->end = 1; } static void -my_finish(struct action *act) +my_finish(struct mlk_action *act) { ((struct invokes *)act->data)->finish = 1; } @@ -92,9 +92,9 @@ test_basics_handle(void) { struct invokes inv = {0}; - struct action act = INIT(&inv, my_update_true); + struct mlk_action act = INIT(&inv, my_update_true); - action_handle(&act, &dummy); + mlk_action_handle(&act, &dummy); DT_ASSERT(inv.handle); DT_ASSERT(!inv.update); @@ -108,14 +108,14 @@ { struct { struct invokes inv; - struct action act; + struct mlk_action act; } table[] = { { .act = INIT(&table[0], my_update_true) }, { .act = INIT(&table[1], my_update_false) } }; /* True version. */ - DT_ASSERT(action_update(&table[0].act, 0)); + DT_ASSERT(mlk_action_update(&table[0].act, 0)); DT_ASSERT(!table[0].inv.handle); DT_ASSERT(table[0].inv.update); DT_ASSERT(!table[0].inv.draw); @@ -123,7 +123,7 @@ DT_ASSERT(!table[0].inv.finish); /* False version. */ - DT_ASSERT(!action_update(&table[1].act, 0)); + DT_ASSERT(!mlk_action_update(&table[1].act, 0)); DT_ASSERT(!table[1].inv.handle); DT_ASSERT(table[1].inv.update); DT_ASSERT(!table[1].inv.draw); @@ -135,9 +135,9 @@ test_basics_draw(void) { struct invokes inv = {0}; - struct action act = INIT(&inv, my_update_true); + struct mlk_action act = INIT(&inv, my_update_true); - action_draw(&act); + mlk_action_draw(&act); DT_ASSERT(!inv.handle); DT_ASSERT(!inv.update); @@ -150,9 +150,9 @@ test_basics_end(void) { struct invokes inv = {0}; - struct action act = INIT(&inv, my_update_true); + struct mlk_action act = INIT(&inv, my_update_true); - action_end(&act); + mlk_action_end(&act); DT_ASSERT(!inv.handle); DT_ASSERT(!inv.update); @@ -165,9 +165,9 @@ test_basics_finish(void) { struct invokes inv = {0}; - struct action act = INIT(&inv, my_update_true); + struct mlk_action act = INIT(&inv, my_update_true); - action_finish(&act); + mlk_action_finish(&act); DT_ASSERT(!inv.handle); DT_ASSERT(!inv.update); @@ -179,9 +179,9 @@ static void test_stack_add(void) { - struct action *actions[10]; + struct mlk_action *actions[10]; struct action_stack st = {0}; - struct action act = {0}; + struct mlk_action act = {0}; action_stack_init(&st, actions, 10); @@ -200,14 +200,14 @@ { struct { int called; - struct action act; + struct mlk_action act; } table[] = { { 0, { .data = &table[0].called, .handle = my_handle } }, { 0, { .data = &table[1].called, .handle = my_handle } }, { 0, { .data = &table[2].called, .handle = my_handle } }, }; - struct action *actions[10]; + struct mlk_action *actions[10]; struct action_stack st = {0}; action_stack_init(&st, actions, 10); @@ -226,7 +226,7 @@ { struct { struct invokes inv; - struct action act; + struct mlk_action act; } table[] = { { .act = INIT(&table[0], my_update_false) }, { .act = INIT(&table[1], my_update_true) }, @@ -237,7 +237,7 @@ { .act = INIT(&table[6], my_update_false) }, }; - struct action *actions[10]; + struct mlk_action *actions[10]; struct action_stack st = {0}; action_stack_init(&st, actions, 10); @@ -325,7 +325,7 @@ { struct { struct invokes inv; - struct action act; + struct mlk_action act; } table[] = { { .act = INIT(&table[0], my_update_false) }, { .act = INIT(&table[1], my_update_true) }, @@ -336,7 +336,7 @@ { .act = INIT(&table[6], my_update_false) }, }; - struct action *actions[10]; + struct mlk_action *actions[10]; struct action_stack st = {0}; action_stack_init(&st, actions, 10); @@ -395,13 +395,13 @@ { struct { struct invokes inv; - struct action act; + struct mlk_action act; } table[] = { { .act = INIT(&table[0], my_update_true) }, { .act = INIT(&table[0], my_update_false) }, }; - struct action *actions[10]; + struct mlk_action *actions[10]; struct action_stack st = {0}; action_stack_init(&st, actions, 10);