# HG changeset patch # User David Demelier # Date 1601985172 -7200 # Node ID 6691c9f69028f5b5e0a8439c0435cb1133fb556b # Parent 52148edddcc6f5a1591c29f7b4eb6c82b6c36c1f core: animation_update now returns true when complete diff -r 52148edddcc6 -r 6691c9f69028 libcore/core/animation.c --- a/libcore/core/animation.c Tue Oct 06 13:52:18 2020 +0200 +++ b/libcore/core/animation.c Tue Oct 06 13:52:52 2020 +0200 @@ -54,7 +54,7 @@ an->elapsed = 0; } -void +bool animation_update(struct animation *an, unsigned int ticks) { assert(an); @@ -62,7 +62,7 @@ an->elapsed += ticks; if (an->elapsed < an->delay) - return; + return false; /* Increment column first */ if (++an->column >= an->sprite->ncols) { @@ -75,6 +75,10 @@ else an->column = 0; } + + return an->elapsed >= an->delay && + an->row >= an->sprite->nrows && + an->column >= an->sprite->ncols; } void diff -r 52148edddcc6 -r 6691c9f69028 libcore/core/animation.h --- a/libcore/core/animation.h Tue Oct 06 13:52:18 2020 +0200 +++ b/libcore/core/animation.h Tue Oct 06 13:52:52 2020 +0200 @@ -33,11 +33,11 @@ * \brief Animation object */ struct animation { - struct sprite *sprite; /*!< Sprite to use (RW) */ - unsigned int row; /*!< current row (RO) */ - unsigned int column; /*!< current column (RO) */ - unsigned int delay; /*!< delay between frames (RW) */ - unsigned int elapsed; /*!< elapsed time since last frame (RO) */ + struct sprite *sprite; /*!< (RW, ref) Sprite to use. */ + unsigned int row; /*!< (RO) Current row. */ + unsigned int column; /*!< (RO) Current column. */ + unsigned int delay; /*!< (RO) Delay between frames. */ + unsigned int elapsed; /*!< (RO) Elapsed time since last frame. */ }; /** @@ -73,8 +73,9 @@ * \pre an != NULL * \param an the animation * \param ticks the elapsed ticks since the last call + * \return true if the animation is complete */ -void +bool animation_update(struct animation *an, unsigned int ticks); /**