Mercurial > molko
diff libcore/core/drawable.c @ 142:fea0cc899931
core: drawable_stack_update returns a bool (similar to action_stack_update)
While here, give the opportunity to do something on the end of the drawable
with the help of the new end field.
While here, add a test and fix some documentation.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 14 Oct 2020 14:48:07 +0200 |
parents | 30b68089ae70 |
children |
line wrap: on
line diff
--- a/libcore/core/drawable.c Wed Oct 14 10:29:53 2020 +0200 +++ b/libcore/core/drawable.c Wed Oct 14 14:48:07 2020 +0200 @@ -46,8 +46,19 @@ } void +drawable_end(struct drawable *dw) +{ + assert(dw); + + if (dw->end) + dw->end(dw); +} + +void drawable_finish(struct drawable *dw) { + assert(dw); + if (dw->finish) dw->finish(dw); } @@ -76,7 +87,7 @@ return false; } -void +bool drawable_stack_update(struct drawable_stack *st, unsigned int ticks) { assert(st); @@ -85,10 +96,17 @@ struct drawable *dw = st->objects[i]; if (dw && drawable_update(dw, ticks)) { + drawable_end(dw); drawable_finish(dw); st->objects[i] = NULL; } } + + /* + * We process the array again in case a drawable added a new drawable + * within the update function. + */ + return drawable_stack_completed(st); } void @@ -103,14 +121,32 @@ drawable_draw(dw); } +bool +drawable_stack_completed(const struct drawable_stack *st) +{ + assert(st); + + struct drawable *dw; + + DRAWABLE_FOREACH(st, dw) + if (dw) + return false; + + return true; +} + void drawable_stack_finish(struct drawable_stack *st) { - for (size_t i = 0; i < DRAWABLE_STACK_MAX; ++i) { - struct drawable *dw = st->objects[i]; + assert(st); + + struct drawable *dw; - if (dw && dw->finish) - dw->finish(dw); + DRAWABLE_FOREACH(st, dw) { + if (dw) { + drawable_end(dw); + drawable_finish(dw); + } } memset(st, 0, sizeof (*st));