Mercurial > molko
changeset 514:daf085bf8a8c
misc: fix build
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 04 Mar 2023 10:49:20 +0100 |
parents | b59a1f00bf80 |
children | 2e05c1804b25 |
files | examples/example-action/chest.c examples/example-animation/example-animation.c examples/example-battle/example-battle.c examples/example-drawable/example-drawable.c libmlk-core/mlk/core/action-stack.c libmlk-example/mlk/example/spell-fire.c libmlk-rpg/mlk/rpg/battle-entity-state-attacking.c libmlk-rpg/mlk/rpg/tileset-file.c libmlk-ui/mlk/ui/label.c libmlk-ui/mlk/ui/label.h libmlk-ui/mlk/ui/ui_p.h tests/test-action.c |
diffstat | 12 files changed, 91 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/example-action/chest.c Sat Mar 04 10:33:34 2023 +0100 +++ b/examples/example-action/chest.c Sat Mar 04 10:49:20 2023 +0100 @@ -107,12 +107,12 @@ assert(chest); chest->state = CHEST_STATE_CLOSED; + chest->animation.sprite = &mlk_registry_sprites[MLK_REGISTRY_TEXTURE_CHEST]; + chest->animation.delay = CHEST_DELAY; chest->action.data = chest; chest->action.handle = handle; chest->action.update = update; chest->action.draw = draw; - mlk_animation_init(&chest->animation, &mlk_registry_sprites[MLK_REGISTRY_TEXTURE_CHEST], CHEST_DELAY); - return &chest->action; }
--- a/examples/example-animation/example-animation.c Sat Mar 04 10:33:34 2023 +0100 +++ b/examples/example-animation/example-animation.c Sat Mar 04 10:49:20 2023 +0100 @@ -41,8 +41,11 @@ .y = 10, }; -static struct mlk_state *states[1]; -static struct mlk_animation animation; +static struct mlk_state *states[8]; +static struct mlk_animation animation = { + .sprite = &mlk_registry_sprites[MLK_REGISTRY_TEXTURE_EXPLOSION], + .delay = 25 +}; static int completed = 1; static void @@ -94,8 +97,8 @@ unsigned int cellw, cellh; - cellw = mlk_registry_sprites[MLK_REGISTRY_TEXTURE_NUMBERS].cellw; - cellh = mlk_registry_sprites[MLK_REGISTRY_TEXTURE_NUMBERS].cellh; + cellw = animation.sprite->cellw; + cellh = animation.sprite->cellh; mlk_painter_set_color(MLK_EXAMPLE_BG); mlk_painter_clear(); @@ -116,8 +119,6 @@ .draw = draw }; - mlk_animation_init(&animation, &mlk_registry_sprites[MLK_REGISTRY_TEXTURE_NUMBERS], 1000); - mlk_game_init(states, MLK_UTIL_SIZE(states)); mlk_game_push(&state); mlk_game_loop();
--- a/examples/example-battle/example-battle.c Sat Mar 04 10:33:34 2023 +0100 +++ b/examples/example-battle/example-battle.c Sat Mar 04 10:49:20 2023 +0100 @@ -188,7 +188,10 @@ static struct mlk_drawable_stack drawable_stack; static struct mlk_action *actions[16]; -static struct mlk_action_stack action_stack; +static struct mlk_action_stack action_stack = { + .actions = actions, + .actionsz = MLK_UTIL_SIZE(actions) +}; static struct battle_entity *entities_enemies[1]; static struct battle_entity *entities_team[1]; @@ -199,7 +202,7 @@ static void prepare_to_fight(void) { - mlk_action_stack_init(&action_stack, actions, MLK_UTIL_SIZE(actions)); + mlk_action_stack_init(&action_stack); mlk_drawable_stack_init(&drawable_stack, drawables, MLK_UTIL_SIZE(drawables)); battle_init(&bt);
--- a/examples/example-drawable/example-drawable.c Sat Mar 04 10:33:34 2023 +0100 +++ b/examples/example-drawable/example-drawable.c Sat Mar 04 10:49:20 2023 +0100 @@ -106,15 +106,16 @@ { struct explosion *ex = mlk_alloc_new0(1, sizeof (*ex)); - mlk_animation_init(&ex->anim, explosion_sprite, 15); - ex->dw.data = ex; + ex->anim.sprite = explosion_sprite; + ex->anim.delay = 18; ex->dw.x = x - (int)(explosion_sprite->cellw / 2); ex->dw.y = y - (int)(explosion_sprite->cellh / 2); ex->dw.update = explosion_update; ex->dw.draw = explosion_draw; ex->dw.finish = explosion_finish; + mlk_animation_start(&ex->anim); mlk_drawable_stack_add(&stack, &ex->dw); }
--- a/libmlk-core/mlk/core/action-stack.c Sat Mar 04 10:33:34 2023 +0100 +++ b/libmlk-core/mlk/core/action-stack.c Sat Mar 04 10:49:20 2023 +0100 @@ -27,13 +27,10 @@ for (size_t i = 0; i < (st)->actionsz && ((iter) = (st)->actions[i], 1); ++i) void -mlk_action_stack_init(struct mlk_action_stack *st, struct mlk_action **actions, size_t actionsz) +mlk_action_stack_init(struct mlk_action_stack *st) { assert(st); - st->actions = actions; - st->actionsz = actionsz; - for (size_t i = 0; i < st->actionsz; ++i) st->actions[i] = NULL; }
--- a/libmlk-example/mlk/example/spell-fire.c Sat Mar 04 10:33:34 2023 +0100 +++ b/libmlk-example/mlk/example/spell-fire.c Sat Mar 04 10:49:20 2023 +0100 @@ -107,16 +107,17 @@ self = mlk_alloc_new0(1, sizeof (*self)); self->selection = slt->index_character; self->battle = bt; + self->animation.sprite = &mlk_registry_sprites[MLK_REGISTRY_TEXTURE_EXPLOSION], + self->animation.delay = 12; self->drawable.data = self; self->drawable.update = update; self->drawable.draw = draw; self->drawable.finish = finish; self->drawable.end = end; - mlk_animation_init(&self->animation, &mlk_registry_sprites[MLK_REGISTRY_TEXTURE_EXPLOSION], 12); mlk_animation_start(&self->animation); + mlk_sound_play(&mlk_registry_sounds[MLK_REGISTRY_SOUND_FIRE]); - mlk_sound_play(&mlk_registry_sounds[MLK_REGISTRY_SOUND_FIRE]); battle_state_rendering(bt, &self->drawable); }
--- a/libmlk-rpg/mlk/rpg/battle-entity-state-attacking.c Sat Mar 04 10:33:34 2023 +0100 +++ b/libmlk-rpg/mlk/rpg/battle-entity-state-attacking.c Sat Mar 04 10:49:20 2023 +0100 @@ -61,7 +61,8 @@ assert(atk); assert(mlk_sprite_ok(which)); - mlk_animation_init(&atk->anim, which, 100); + atk->anim.sprite = which; + atk->anim.delay = 100; mlk_animation_start(&atk->anim); }
--- a/libmlk-rpg/mlk/rpg/tileset-file.c Sat Mar 04 10:33:34 2023 +0100 +++ b/libmlk-rpg/mlk/rpg/tileset-file.c Sat Mar 04 10:49:20 2023 +0100 @@ -196,7 +196,9 @@ return -1; mlk_sprite_init(&anim->sprite, &anim->texture, ctx->tilewidth, ctx->tileheight); - mlk_animation_init(&anim->animation, &anim->sprite, delay); + + anim->animation.sprite = &anim->sprite; + anim->animation.delay = delay; } /*
--- a/libmlk-ui/mlk/ui/label.c Sat Mar 04 10:33:34 2023 +0100 +++ b/libmlk-ui/mlk/ui/label.c Sat Mar 04 10:49:20 2023 +0100 @@ -40,7 +40,7 @@ return mlk_ui_fonts[MLK_UI_FONT_INTERFACE]; } -static void +static int delegate_query(struct mlk_label_delegate *delegate, const struct mlk_label *label, unsigned int *w, unsigned *h) { (void)delegate; @@ -51,7 +51,9 @@ font = style_font(label); if ((err = mlk_font_query(font, label->text, w, h)) < 0) - mlk_tracef("mlk_font_query: %s", mlk_err_string(err)); + return err; + + return 0; } static void @@ -93,7 +95,18 @@ { assert(mlk_label_ok(label)); - MLK__DELEGATE_INVOKE(label->delegate, mlk_label_delegate, query, label, w, h); + MLK__DELEGATE_INVOKE_RET(label->delegate, mlk_label_delegate, query, label, w, h); + + /* + * Reached only if user decided to set NULL to query which isn't the + * default. + */ + if (w) + *w = 0; + if (h) + *h = 0; + + return MLK_ERR_NO_SUPPORT; } void
--- a/libmlk-ui/mlk/ui/label.h Sat Mar 04 10:33:34 2023 +0100 +++ b/libmlk-ui/mlk/ui/label.h Sat Mar 04 10:49:20 2023 +0100 @@ -31,7 +31,7 @@ struct mlk_label_delegate { void *data; - void (*query)(struct mlk_label_delegate *, const struct mlk_label *, unsigned int *, unsigned *); + int (*query)(struct mlk_label_delegate *, const struct mlk_label *, unsigned int *, unsigned *); void (*update)(struct mlk_label_delegate *, struct mlk_label *, unsigned int); void (*draw)(struct mlk_label_delegate *, const struct mlk_label *); };
--- a/libmlk-ui/mlk/ui/ui_p.h Sat Mar 04 10:33:34 2023 +0100 +++ b/libmlk-ui/mlk/ui/ui_p.h Sat Mar 04 10:49:20 2023 +0100 @@ -19,15 +19,23 @@ #ifndef MLK_UI_P_H #define MLK_UI_P_H -#define MLK__DELEGATE_INVOKE(d, def, f, ...) \ -do { \ - if (d && d->f) \ - d->f(d, __VA_ARGS__); \ - else if (def.f) \ - def.f(&def, __VA_ARGS__); \ +#define MLK__DELEGATE_INVOKE(d, def, f, ...) \ +do { \ + if (d && d->f) \ + d->f(d, __VA_ARGS__); \ + else if (def.f) \ + def.f(&def, __VA_ARGS__); \ } while (0) -#define MLK__STYLE(w, d) \ +#define MLK__DELEGATE_INVOKE_RET(d, def, f, ...) \ +do { \ + if (d && d->f) \ + return d->f(d, __VA_ARGS__); \ + if (def.f) \ + return def.f(&def, __VA_ARGS__); \ +} while (0) + +#define MLK__STYLE(w, d) \ (w->style ? w->style : &d) #endif /* !MLK_UI_P_H */
--- a/tests/test-action.c Sat Mar 04 10:33:34 2023 +0100 +++ b/tests/test-action.c Sat Mar 04 10:49:20 2023 +0100 @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <mlk/core/util.h> + #include <mlk/core/action-stack.h> #include <mlk/core/action.h> #include <mlk/core/err.h> @@ -209,11 +211,14 @@ static void test_stack_add(void) { + struct mlk_action act = {0}; struct mlk_action *actions[10]; - struct mlk_action_stack st = {0}; - struct mlk_action act = {0}; + struct mlk_action_stack st = { + .actions = actions, + .actionsz = MLK_UTIL_SIZE(actions) + }; - mlk_action_stack_init(&st, actions, 10); + mlk_action_stack_init(&st); DT_EQ_INT(mlk_action_stack_add(&st, &act), 0); @@ -237,9 +242,12 @@ }; struct mlk_action *actions[10]; - struct mlk_action_stack st = {0}; + struct mlk_action_stack st = { + .actions = actions, + .actionsz = MLK_UTIL_SIZE(actions) + }; - mlk_action_stack_init(&st, actions, 10); + mlk_action_stack_init(&st); mlk_action_stack_add(&st, &table[0].act); mlk_action_stack_add(&st, &table[1].act); mlk_action_stack_start(&st); @@ -271,9 +279,12 @@ }; struct mlk_action *actions[10]; - struct mlk_action_stack st = {0}; + struct mlk_action_stack st = { + .actions = actions, + .actionsz = MLK_UTIL_SIZE(actions) + }; - mlk_action_stack_init(&st, actions, 10); + mlk_action_stack_init(&st); mlk_action_stack_add(&st, &table[0].act); mlk_action_stack_add(&st, &table[1].act); mlk_action_stack_handle(&st, &dummy); @@ -310,9 +321,12 @@ }; struct mlk_action *actions[10]; - struct mlk_action_stack st = {0}; + struct mlk_action_stack st = { + .actions = actions, + .actionsz = MLK_UTIL_SIZE(actions) + }; - mlk_action_stack_init(&st, actions, 10); + mlk_action_stack_init(&st); mlk_action_stack_add(&st, &table[0].act); mlk_action_stack_add(&st, &table[1].act); mlk_action_stack_add(&st, &table[2].act); @@ -409,9 +423,12 @@ }; struct mlk_action *actions[10]; - struct mlk_action_stack st = {0}; + struct mlk_action_stack st = { + .actions = actions, + .actionsz = MLK_UTIL_SIZE(actions) + }; - mlk_action_stack_init(&st, actions, 10); + mlk_action_stack_init(&st); mlk_action_stack_add(&st, &table[0].act); mlk_action_stack_add(&st, &table[1].act); mlk_action_stack_add(&st, &table[2].act); @@ -474,9 +491,12 @@ }; struct mlk_action *actions[10]; - struct mlk_action_stack st = {0}; + struct mlk_action_stack st = { + .actions = actions, + .actionsz = MLK_UTIL_SIZE(actions) + }; - mlk_action_stack_init(&st, actions, 10); + mlk_action_stack_init(&st); mlk_action_stack_add(&st, &table[0].act); mlk_action_stack_add(&st, &table[1].act); mlk_action_stack_finish(&st);