flappychik

Silly SDL2 game
git clone git://bsandro.tech/flappychik
Log | Files | Refs

commit 2ca39cb071b6776f0b533db8c411246686cc8a9c
parent dfce13126b810d8981fb4c2536c731918c7fc0e0
Author: bsandro <brian.drosan@gmail.com>
Date:   Mon, 14 Feb 2022 03:11:14 +0200

debugging frame time

Diffstat:
Mmain.c | 18++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/main.c b/main.c @@ -5,6 +5,12 @@ #include <SDL.h> #include <SDL_image.h> +#ifdef __APPLE__ +#define WINDOW_FLAGS SDL_WINDOW_METAL | SDL_WINDOW_ALLOW_HIGHDPI +#else +#define WINDOW_FLAGS SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI +#endif + int main(int argc, char *argv[]) { (void)argc; (void)argv; @@ -13,11 +19,8 @@ int main(int argc, char *argv[]) { SDL_Event event; SDL_Init(SDL_INIT_VIDEO); -#ifdef __APPLE__ - SDL_Window *screen = SDL_CreateWindow("flappychik", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_METAL | SDL_WINDOW_ALLOW_HIGHDPI); -#else - SDL_Window *screen = SDL_CreateWindow("flappychik", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI); -#endif + SDL_Window *screen = SDL_CreateWindow("flappychik", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, WINDOW_FLAGS); + assert(screen != NULL); SDL_Renderer *renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); @@ -40,6 +43,7 @@ int main(int argc, char *argv[]) { SDL_RenderPresent(renderer); + uint64_t t = SDL_GetTicks64(); while (!quit) { if (SDL_WaitEventTimeout(&event, 1000/60)) { switch (event.type) { @@ -55,7 +59,9 @@ int main(int argc, char *argv[]) { SDL_RenderCopy(renderer, tex_bg, NULL, NULL); SDL_RenderCopy(renderer, tex_knife, NULL, &knife_rect); SDL_RenderPresent(renderer); - //printf("hello\n"); + uint64_t t1 = SDL_GetTicks64(); + printf("frame time: %llu\n", t1 - t); + t = t1; } SDL_DestroyTexture(tex_bg);