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(); int CreateSDLWindow();
void DestroyWindwo(); void DestroyWindow();

View File

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

View File

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

View File

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