commit f1b185e337cc83f0bdee4708a2a7f8066862f4cb
parent 2ca39cb071b6776f0b533db8c411246686cc8a9c
Author: bsandro <brian.drosan@gmail.com>
Date: Mon, 14 Feb 2022 03:31:28 +0200
trying to process events faster than drawing frames
Diffstat:
M | main.c | | | 23 | ++++++++++++++--------- |
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/main.c b/main.c
@@ -45,23 +45,28 @@ int main(int argc, char *argv[]) {
uint64_t t = SDL_GetTicks64();
while (!quit) {
- if (SDL_WaitEventTimeout(&event, 1000/60)) {
+ while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
quit = true;
break;
}
}
- SDL_RenderClear(renderer);
- knife_rect.x += 1;
- knife_rect.y += 1;
- SDL_RenderCopy(renderer, tex_bg, NULL, NULL);
- SDL_RenderCopy(renderer, tex_knife, NULL, &knife_rect);
- SDL_RenderPresent(renderer);
uint64_t t1 = SDL_GetTicks64();
- printf("frame time: %llu\n", t1 - t);
- t = t1;
+
+ if (t1 - t >= 1000/60) {
+ SDL_RenderClear(renderer);
+
+ knife_rect.x += 1;
+ knife_rect.y += 1;
+ SDL_RenderCopy(renderer, tex_bg, NULL, NULL);
+ SDL_RenderCopy(renderer, tex_knife, NULL, &knife_rect);
+ SDL_RenderPresent(renderer);
+
+ printf("frame time: %llu\n", t1 - t);
+ t = t1;
+ }
}
SDL_DestroyTexture(tex_bg);