From d2155bf27e294d1b45a434c3761f38268ff06a34 Mon Sep 17 00:00:00 2001 From: cat Date: Wed, 28 May 2025 16:45:15 +1000 Subject: [PATCH] move texture logic to samply.c --- fns.h | 1 + samply.c | 18 ++++++++++++++++++ slutpet.c | 12 +++--------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/fns.h b/fns.h index 6e26cb6..b85c96d 100644 --- a/fns.h +++ b/fns.h @@ -6,5 +6,6 @@ void free_image(Image *i); Image *load_image(SDL_Renderer *ren, char *path); +int samply_step(State *st); void put_samply_to_bed(Samply *sam); Samply *wake_samply_up(SDL_Renderer *ren); diff --git a/samply.c b/samply.c index a82bd31..6e8bd9f 100644 --- a/samply.c +++ b/samply.c @@ -3,6 +3,24 @@ #include "dat.h" #include "fns.h" +int +samply_step(State *st) +{ + Uint64 ms; + SDL_Texture *tx; + + ms = SDL_GetTicks(); + if ((ms / 100) % 2) + tx = st->sam->walka->tex; + else + tx = st->sam->walkb->tex; + + if (SDL_RenderTexture(st->ren, tx, NULL, NULL) == false) { + fuck("rendertexture fail: %s", SDL_GetError()); + return -1; + } +} + void put_samply_to_bed(Samply *sam) { diff --git a/slutpet.c b/slutpet.c index 883cd73..f0e4724 100644 --- a/slutpet.c +++ b/slutpet.c @@ -53,18 +53,12 @@ SDL_AppIterate(void *as) SDL_SetRenderDrawColor(st->ren, 0, 0, 0, SDL_ALPHA_TRANSPARENT); SDL_RenderClear(st->ren); - ms = SDL_GetTicks(); - if ((ms / 100) % 2) - tx = st->sam->walka->tex; - else - tx = st->sam->walkb->tex; - - if (SDL_RenderTexture(st->ren, tx, NULL, NULL) == false) { - fuck("rendertexture fail: %s", SDL_GetError()); + if (samply_step(st) < 0) return SDL_APP_FAILURE; - } + SDL_RenderPresent(st->ren); st->lastframe = SDL_GetTicks(); + return SDL_APP_CONTINUE; }