From 7713f545b9c1556a68596efef83569d3d7d5037b Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Mon, 14 Jan 2019 19:48:01 -0500 Subject: cache SDL_GetTicks() --- src/sdl/draw.c | 13 ++++++------- src/sdl/draw.h | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/sdl/draw.c b/src/sdl/draw.c index f27a6be..f7f9ff7 100644 --- a/src/sdl/draw.c +++ b/src/sdl/draw.c @@ -139,9 +139,7 @@ draw_on_home( void * const data ) { draw_ctx_t * const draw_ctx = data; - const bool is_done = sok_ctx_is_done(draw_ctx->ctx); - const Uint32 ticks = SDL_GetTicks(); - const double angle = is_done ? (10 * sin(ticks * M_2_PI / 1000.0)) : 0; + const double angle = sok_ctx_is_done(draw_ctx->ctx) ? (10 * sin(draw_ctx->ticks * M_2_PI / 1000.0)) : 0; draw_cell(draw_ctx, pos, SPRITE_HOME, angle); @@ -156,9 +154,7 @@ draw_on_box( void * const data ) { draw_ctx_t * const draw_ctx = data; - const Uint32 ticks = SDL_GetTicks(); - const bool is_done = sok_ctx_is_done(draw_ctx->ctx); - const double angle = is_done ? (5 * sin((100 * (pos.y + pos.x) + ticks) * M_2_PI / 1000.0)) : 0; + const double angle = sok_ctx_is_done(draw_ctx->ctx) ? (5 * sin((100 * (pos.y + pos.x) + draw_ctx->ticks) * M_2_PI / 1000.0)) : 0; draw_cell(draw_ctx, pos, SPRITE_BOX, angle); @@ -279,7 +275,7 @@ draw_bg( // get color const SDL_Color c = bg_style_get_color( BG_STYLES + (sok_ctx_is_done(draw_ctx->ctx) ? 1 : 0), - SDL_GetTicks() + draw_ctx->ticks ); // set color @@ -295,6 +291,9 @@ void draw( draw_ctx_t * const draw_ctx ) { + // update timestamp + draw_ctx->ticks = SDL_GetTicks(); + // clear background draw_bg(draw_ctx); diff --git a/src/sdl/draw.h b/src/sdl/draw.h index b8aeed4..19d8837 100644 --- a/src/sdl/draw.h +++ b/src/sdl/draw.h @@ -22,6 +22,7 @@ typedef struct { // render offset int render_ofs_x, render_ofs_y; + Uint32 ticks; } draw_ctx_t; void draw(draw_ctx_t * const); -- cgit v1.2.3