move texture logic to samply.c

This commit is contained in:
cat 2025-05-28 16:45:15 +10:00
parent aa95148fc9
commit d2155bf27e
3 changed files with 22 additions and 9 deletions

1
fns.h
View file

@ -6,5 +6,6 @@
void free_image(Image *i); void free_image(Image *i);
Image *load_image(SDL_Renderer *ren, char *path); Image *load_image(SDL_Renderer *ren, char *path);
int samply_step(State *st);
void put_samply_to_bed(Samply *sam); void put_samply_to_bed(Samply *sam);
Samply *wake_samply_up(SDL_Renderer *ren); Samply *wake_samply_up(SDL_Renderer *ren);

View file

@ -3,6 +3,24 @@
#include "dat.h" #include "dat.h"
#include "fns.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 void
put_samply_to_bed(Samply *sam) put_samply_to_bed(Samply *sam)
{ {

View file

@ -53,18 +53,12 @@ SDL_AppIterate(void *as)
SDL_SetRenderDrawColor(st->ren, 0, 0, 0, SDL_ALPHA_TRANSPARENT); SDL_SetRenderDrawColor(st->ren, 0, 0, 0, SDL_ALPHA_TRANSPARENT);
SDL_RenderClear(st->ren); SDL_RenderClear(st->ren);
ms = SDL_GetTicks(); if (samply_step(st) < 0)
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 SDL_APP_FAILURE; return SDL_APP_FAILURE;
}
SDL_RenderPresent(st->ren); SDL_RenderPresent(st->ren);
st->lastframe = SDL_GetTicks(); st->lastframe = SDL_GetTicks();
return SDL_APP_CONTINUE; return SDL_APP_CONTINUE;
} }