Skip to content

Commit

Permalink
Recreate board on window resize, and rename interactive entrypoint t…
Browse files Browse the repository at this point in the history
…o main
  • Loading branch information
Jumbub committed Oct 3, 2021
1 parent 1b430c2 commit 4dfdf82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 4 additions & 4 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions src/entrypoints/interactive.cpp → src/entrypoints/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Board> nextBoardPromise;
Expand All @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 4dfdf82

Please sign in to comment.