enable vsync for smooth scrolling
parent
a9fb1da7a5
commit
931ec082b8
15
xormod.c
15
xormod.c
|
@ -5,6 +5,7 @@
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
#include <SDL3/SDL_render.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
@ -28,6 +29,8 @@ int main() {
|
||||||
|
|
||||||
SDL_Renderer *rend = SDL_CreateRenderer(window, NULL);
|
SDL_Renderer *rend = SDL_CreateRenderer(window, NULL);
|
||||||
|
|
||||||
|
SDL_SetRenderVSync(rend, 1);
|
||||||
|
|
||||||
Field f;
|
Field f;
|
||||||
Field_init(&f, w, h);
|
Field_init(&f, w, h);
|
||||||
|
|
||||||
|
@ -50,16 +53,16 @@ int main() {
|
||||||
|
|
||||||
const bool *keys = SDL_GetKeyboardState(NULL);
|
const bool *keys = SDL_GetKeyboardState(NULL);
|
||||||
if (keys[SDL_SCANCODE_LEFT] || keys[SDL_SCANCODE_A]) {
|
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]) {
|
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]) {
|
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]) {
|
if (keys[SDL_SCANCODE_DOWN] || keys[SDL_SCANCODE_S]) {
|
||||||
f.offset.y += 16;
|
f.offset.y += delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
@ -128,10 +131,6 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RenderPresent(rend);
|
SDL_RenderPresent(rend);
|
||||||
|
|
||||||
if (delta < 16) {
|
|
||||||
SDL_Delay(16 - delta);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_DestroyRenderer(rend);
|
SDL_DestroyRenderer(rend);
|
||||||
|
|
Loading…
Reference in New Issue