Fix bug SDL-window freezing on windows

apparently SDL window freezes on windows,
when the input events are not repeatedly handled.
This commit is contained in:
jonny_jr9 2023-12-10 18:03:02 +01:00
parent abad211084
commit ac5873c9e7
4 changed files with 16 additions and 16 deletions

View File

@ -9,4 +9,4 @@ void renderGame();
int CreateSDLWindow();
void DestroyWindwo();
void DestroyWindow();

View File

@ -5,7 +5,7 @@
config_t config = {
.windowSize = 800,
.blockSizePx = 800/10, //default map is 10x10 blocks
.cycleDurationMs = 1000,
.cycleDurationMs = 400,
.difficulty = 1,
.snakeDefaultLength = 2,
.leaderboardFilename = ""

View File

@ -1,16 +1,11 @@
#include <stdio.h>
extern "C" {
#include "food.h"
}
extern "C"{
#include "render.h"
}
extern "C"{
extern "C"
{
#include "game.h"
#include "common.h"
#include "input.h"
#include "render.h"
}
//initialize SDL window
@ -46,11 +41,16 @@ int main(int argc, char *argv[])
while(1){
if(game.gameState != EXIT) {
if (game.gameState == RUNNING) {
processInputEvent();
DELAY(config.cycleDurationMs);
processInputEvent();
runGameCycle();
}
} else {SDL_Quit(); return 0;}
} else {
DestroyWindow();
SDL_Quit();
return 0;}
}

View File

@ -11,7 +11,7 @@ SDL_Window* window;
void renderGame(){
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
/* SDL_RenderClear(renderer);
SDL_RenderClear(renderer);
//Head__________________________________________________
SDL_SetRenderDrawColor(renderer, 0, 200, 100, 255); //RGB-Farbe Kopf
@ -72,7 +72,7 @@ void renderGame(){
SDL_RenderFillRect(renderer, &rect); //Rechteck rendern
}
*/
SDL_RenderPresent(renderer); //Fenster aktualisieren
}