From 4dfdf823dc7aa2cd6f9a872f7b04e62585b5d30d Mon Sep 17 00:00:00 2001 From: Jamie Bray Date: Sun, 3 Oct 2021 22:43:51 +0800 Subject: [PATCH] Recreate board on window resize, and rename interactive entrypoint to main --- makefile | 8 ++++---- src/entrypoints/{interactive.cpp => main.cpp} | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) rename src/entrypoints/{interactive.cpp => main.cpp} (85%) diff --git a/makefile b/makefile index cacdba4..390ab5e 100644 --- a/makefile +++ b/makefile @@ -12,15 +12,15 @@ OUTPUT = build/out OBJS = src/util/profile.cpp src/board/next.cpp src/board/generate.cpp OBJS_GRAPHICS = $(OBJS) src/board/sdl.cpp -interactive: build - $(CC) src/entrypoints/interactive.cpp $(COMPILER_FLAGS) $(LINKER_FLAGS_GRAPHICS) -o $(OUTPUT) $(OBJS_GRAPHICS) +main: build + $(CC) src/entrypoints/main.cpp $(COMPILER_FLAGS) $(LINKER_FLAGS_GRAPHICS) -o $(OUTPUT) $(OBJS_GRAPHICS) ./$(OUTPUT) debug: build - $(CC) src/entrypoints/interactive.cpp -DENABLE_THREADING=0 $(COMPILER_FLAGS_DEBUG) $(LINKER_FLAGS_GRAPHICS) -o $(OUTPUT) $(OBJS_GRAPHICS) + $(CC) src/entrypoints/main.cpp -DENABLE_THREADING=0 $(COMPILER_FLAGS_DEBUG) $(LINKER_FLAGS_GRAPHICS) -o $(OUTPUT) $(OBJS_GRAPHICS) profile: build - $(CC) src/entrypoints/interactive.cpp -DENABLE_THREADING=0 $(COMPILER_FLAGS_PROFILE) $(LINKER_FLAGS_GRAPHICS) -o $(OUTPUT) $(OBJS_GRAPHICS) + $(CC) src/entrypoints/main.cpp -DENABLE_THREADING=0 $(COMPILER_FLAGS_PROFILE) $(LINKER_FLAGS_GRAPHICS) -o $(OUTPUT) $(OBJS_GRAPHICS) test: build $(CC) src/entrypoints/test.cpp $(COMPILER_FLAGS) -ggdb -o $(OUTPUT) $(OBJS) diff --git a/src/entrypoints/interactive.cpp b/src/entrypoints/main.cpp similarity index 85% rename from src/entrypoints/interactive.cpp rename to src/entrypoints/main.cpp index 36b9614..cef02cc 100644 --- a/src/entrypoints/interactive.cpp +++ b/src/entrypoints/main.cpp @@ -40,7 +40,7 @@ int main() { bool running = true; bool recreateBoard = false; while (running) { - auto loopTimer = startProfiling(); + /* auto loopTimer = startProfiling(); */ #ifdef ENABLE_THREADING std::promise nextBoardPromise; @@ -56,9 +56,10 @@ int main() { (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE)) running = false; - // Re-create board when Enter is pressed - else if (event.type == SDL_KEYDOWN && - event.key.keysym.scancode == SDL_SCANCODE_RETURN) { + // Re-create board when Enter is pressed, or window is resized + else if ((event.type == SDL_KEYDOWN && + event.key.keysym.scancode == SDL_SCANCODE_RETURN) || (event.type == SDL_WINDOWEVENT && + event.window.event == SDL_WINDOWEVENT_RESIZED)) { recreateBoard = true; } else if (event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_J) { @@ -89,9 +90,10 @@ int main() { SDL_DestroyTexture(texture); texture = createTexture(renderer, width, height); recreateBoard = false; + std::cout << "Re-created board: " << width << "x" << height << std::endl; } - stopProfiling(loopTimer, "Done loop"); + /* stopProfiling(loopTimer, "Done loop"); */ } free(get<0>(board));