From 931ec082b8afc19b7605f43b156a6a5b25a38f25 Mon Sep 17 00:00:00 2001 From: Henri Vasserman Date: Thu, 9 Jan 2025 17:43:06 +0200 Subject: [PATCH] enable vsync for smooth scrolling --- xormod.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/xormod.c b/xormod.c index f1a631f..e13d7bb 100644 --- a/xormod.c +++ b/xormod.c @@ -5,6 +5,7 @@ #include "platform.h" #include "types.h" +#include #include #include #include @@ -28,6 +29,8 @@ int main() { SDL_Renderer *rend = SDL_CreateRenderer(window, NULL); + SDL_SetRenderVSync(rend, 1); + Field f; Field_init(&f, w, h); @@ -50,16 +53,16 @@ int main() { const bool *keys = SDL_GetKeyboardState(NULL); if (keys[SDL_SCANCODE_LEFT] || keys[SDL_SCANCODE_A]) { - f.offset.x -= 16; + f.offset.x -= delta; } if (keys[SDL_SCANCODE_RIGHT] || keys[SDL_SCANCODE_D]) { - f.offset.x += 16; + f.offset.x += delta; } if (keys[SDL_SCANCODE_UP] || keys[SDL_SCANCODE_W]) { - f.offset.y -= 16; + f.offset.y -= delta; } if (keys[SDL_SCANCODE_DOWN] || keys[SDL_SCANCODE_S]) { - f.offset.y += 16; + f.offset.y += delta; } SDL_Event event; @@ -128,10 +131,6 @@ int main() { } SDL_RenderPresent(rend); - - if (delta < 16) { - SDL_Delay(16 - delta); - } } SDL_DestroyRenderer(rend);