From 5ec4182519bf263d14bec65010dd405df1e5785f Mon Sep 17 00:00:00 2001 From: zv0n Date: Tue, 20 Oct 2020 11:04:07 +0200 Subject: [PATCH] Tetris: make playable on macOS --- tetris/Makefile | 2 +- tetris/scenes.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tetris/Makefile b/tetris/Makefile index 751cf44..14affa7 100644 --- a/tetris/Makefile +++ b/tetris/Makefile @@ -1,5 +1,5 @@ CXX ?= g++ -CFLAGS ?= -O2 -Wall -Wextra +CFLAGS ?= -O2 -Wall -Wextra -std=c++14 PREFIX ?= /usr/local/bin LDFLAGS ?= -lSDL2 -lSDL2_image -lSDL2_gfx -lSDL2_ttf -pthread diff --git a/tetris/scenes.cpp b/tetris/scenes.cpp index 7063bd4..74acbdb 100644 --- a/tetris/scenes.cpp +++ b/tetris/scenes.cpp @@ -389,7 +389,8 @@ void handleKeyUpMain( SDL_Keycode key ) { void pollEventsMain( SDLPP::Scene &scene ) { SDL_Event event; - while ( SDL_PollEvent( &event ) != 0 ) { + while ( SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 ) { + SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT); switch ( event.type ) { case SDL_QUIT: quitGame(); @@ -501,7 +502,8 @@ void handleKeyDownMenu( SDL_Keycode key ) { void pollEventsMenu() { SDL_Event event; - while ( SDL_PollEvent( &event ) != 0 ) { + while ( SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 ) { + SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT); switch ( event.type ) { case SDL_QUIT: quitGame(); @@ -566,7 +568,8 @@ void handleKeyDownGameOver( SDL_Keycode key ) { void pollEventsGameOver() { SDL_Event event; - while ( SDL_PollEvent( &event ) != 0 ) { + while ( SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 ) { + SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT); switch ( event.type ) { case SDL_QUIT: quitGame(); @@ -689,7 +692,8 @@ void handleKeyDownOptions( SDL_Keycode key ) { void pollEventsOptions() { SDL_Event event; - while ( SDL_PollEvent( &event ) != 0 ) { + while ( SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 ) { + SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT); switch ( event.type ) { case SDL_QUIT: quitGame();