From 93ddcefc14498857e62a64d35a51971325a63d6b Mon Sep 17 00:00:00 2001 From: Slade Getz Date: Mon, 4 Sep 2023 12:15:06 -0500 Subject: [PATCH] Added comments and changed inline assignments to increase readability for animation functions. Removed draw_free() definition, as it is not used anymore. Added animation free function to the dgn_catch() clause in main. --- src/animations.c | 19 +++++++++++++------ src/draw.h | 1 - src/main.c | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/animations.c b/src/animations.c index 231c29e..75df89f 100644 --- a/src/animations.c +++ b/src/animations.c @@ -374,9 +374,11 @@ void animate_free(struct term_buf* buf) { if (config.animate) { - int i; - if ((i = config.animation) < ANIMATION_NUM) + int i = config.animation; + // make sure the animation chosen is valid + if (i < ANIMATION_NUM) { + // load appropriate free function and execute void (*fun_ptr)(struct term_buf*); fun_ptr = ANIM_FREES[i]; (*fun_ptr)(buf); @@ -391,9 +393,11 @@ void animate(struct term_buf* buf) if (config.animate) { - int i; - if ((i = config.animation) < ANIMATION_NUM) + int i = config.animation; + // make sure the animation chosen is valid + if (i < ANIMATION_NUM) { + // runs corresponding animation function void (*fun_ptr)(struct term_buf*); fun_ptr = ANIM_RUNS[i]; (*fun_ptr)(buf); @@ -405,9 +409,12 @@ void animate_init(struct term_buf* buf) { if (config.animate) { - int i; - if ((i = config.animation) < ANIMATION_NUM) + int i = config.animation; + // make sure the animation chosen is valid + if (i < ANIMATION_NUM) { + // grab the corresponding animation + // initialize function and execute void (*fun_ptr)(struct term_buf*); fun_ptr = ANIM_INITS[i]; (*fun_ptr)(buf); diff --git a/src/draw.h b/src/draw.h index 482490f..4d6e836 100644 --- a/src/draw.h +++ b/src/draw.h @@ -41,7 +41,6 @@ struct term_buf void draw_init(struct term_buf* buf); -void draw_free(struct term_buf* buf); void draw_box(struct term_buf* buf); struct tb_cell* strn_cell(char* s, uint16_t len); diff --git a/src/main.c b/src/main.c index b1c277b..fa3a1a9 100644 --- a/src/main.c +++ b/src/main.c @@ -164,6 +164,7 @@ int main(int argc, char** argv) if (dgn_catch()) { config.animate = false; + animate_free(&buf); dgn_reset(); } }