Fixed event polling loop which fixed laggy input
This commit is contained in:
parent
966027815c
commit
e383f8bf93
1 changed files with 20 additions and 9 deletions
23
src/main.c
23
src/main.c
|
|
@ -1,9 +1,11 @@
|
|||
#include <SDL3/SDL.h>
|
||||
#include <GL/glew.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "SDL3/SDL_events.h"
|
||||
#include "SDL3/SDL_keycode.h"
|
||||
#include "camera.h"
|
||||
#include "cglm/io.h"
|
||||
|
||||
|
|
@ -145,16 +147,25 @@ int main(int argc, char *argv[]) {
|
|||
// Initialise camera
|
||||
Camera camera = Camera_default;
|
||||
|
||||
// Lock and hide mouse to window
|
||||
// Lock and hide mouse
|
||||
SDL_SetWindowRelativeMouseMode(window, true);
|
||||
SDL_GetRelativeMouseState(NULL, NULL);
|
||||
|
||||
bool wants_running = true;
|
||||
while (wants_running) {
|
||||
|
||||
while (1) {
|
||||
// handle input
|
||||
SDL_PollEvent(&event);
|
||||
if (event.type == SDL_EVENT_QUIT) {
|
||||
// handle input events
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_QUIT:
|
||||
wants_running = false;
|
||||
break;
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
if (event.key.key == SDLK_ESCAPE) {
|
||||
wants_running = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle camera
|
||||
|
|
|
|||
Loading…
Reference in a new issue