diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 56cd9f5..d6b558e 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,8 +1,4 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.238.1/containers/cpp/.devcontainer/base.Dockerfile - -# [Choice] Debian / Ubuntu version (use Debian 11, Ubuntu 18.04/22.04 on local arm64/Apple Silicon): debian-11, debian-10, ubuntu-22.04, ubuntu-20.04, ubuntu-18.04 -ARG VARIANT="bullseye" -FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT} +FROM mcr.microsoft.com/devcontainers/cpp:ubuntu-22.04 # [Optional] Install CMake version different from what base image has already installed. # CMake reinstall choices: none, 3.21.5, 3.22.2, or versions from https://cmake.org/download/ @@ -15,9 +11,6 @@ RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ fi \ && rm -f /tmp/reinstall-cmake.sh -# [Optional] Uncomment this section to install additional vcpkg ports. -# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install " - -# [Optional] Uncomment this section to install additional packages. -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends clang-14 g++-12 +RUN apt-get update && apt-get -y install --no-install-recommends \ + clang-12 g++-12 \ + libx11-dev libxft-dev libxext-dev diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 65b9752..9d56d77 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,15 +1,17 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.238.1/containers/cpp { - "name": "C++", + "name": "Container for go-cpp project", "build": { - "dockerfile": "Dockerfile", - // Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, ubuntu-22.04, ubuntu-20.04, ubuntu-18.04 - // Use Debian 11, Ubuntu 18.04 or Ubuntu 22.04 on local arm64/Apple Silicon - "args": { "VARIANT": "ubuntu-22.04" } + "dockerfile": "Dockerfile" }, "runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"], + "features": { + "github-cli": "latest", + "ghcr.io/devcontainers/features/sshd:1": { + "version": "latest" + } + }, + // Configure tool-specific properties. "customizations": { // Configure properties specific to VS Code. @@ -18,20 +20,10 @@ "extensions": [ "ms-vscode.cpptools-extension-pack", "eamodio.gitlens", - "ms-azuretools.vscode-docker" + "ms-azuretools.vscode-docker", + "Github.copilot", + "Github.copilot-chat" ] } - }, - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "gcc -v", - - // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "vscode", - "features": { - "github-cli": "latest" } } diff --git a/.github/workflows/cmake.yaml b/.github/workflows/cmake.yaml index 6b8b6a5..041fb98 100644 --- a/.github/workflows/cmake.yaml +++ b/.github/workflows/cmake.yaml @@ -59,6 +59,6 @@ jobs: uses: dorny/test-reporter@v1.5.0 if: success() || failure() with: - name: go-tests - ${{ matrix.os }} - ${{ matrix.cmake_preset }} + name: goimpl-tests - ${{ matrix.os }} - ${{ matrix.cmake_preset }} path: out/${{ matrix.cmake_preset }}/junit-output/* reporter: java-junit \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 4078fec..0e68d87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.20) project(go-cpp CXX) set(CMAKE_CXX_STANDARD 20) -include_directories(${PROJECT_SOURCE_DIR}/source) enable_testing() @@ -10,28 +9,39 @@ enable_testing() # Library ################################################################################ -file(GLOB SOURCE_FILES ${PROJECT_SOURCE_DIR}/source/*.cpp) -list(REMOVE_ITEM SOURCE_FILES ${PROJECT_SOURCE_DIR}/source/main.cpp) -add_library(goimpl ${SOURCE_FILES}) +set(GOIMPL_ROOT ${PROJECT_SOURCE_DIR}/goimpl) +file(GLOB GOIMPL_SOURCE_FILES ${GOIMPL_ROOT}/source/*.cpp) +include_directories(${GOIMPL_ROOT}/include) +add_library(goimpl ${GOIMPL_SOURCE_FILES}) ################################################################################ -# Main executable +# Library test executable ################################################################################ -add_executable(go ${PROJECT_SOURCE_DIR}/source/main.cpp) -target_link_libraries(go goimpl) +find_package(Catch2 3 CONFIG REQUIRED) + +file(GLOB TEST_GOIMPL_SOURCE_FILES ${GOIMPL_ROOT}/tests/*.cpp) +add_executable(goimpl-tests ${TEST_GOIMPL_SOURCE_FILES}) +target_link_libraries(goimpl-tests PUBLIC goimpl PRIVATE Catch2::Catch2WithMain) +include(CTest) +include(Catch) +catch_discover_tests(goimpl-tests REPORTER junit OUTPUT_DIR junit-output) ################################################################################ -# Test executable +# Commandline executable ################################################################################ -find_package(Catch2 3 CONFIG REQUIRED) +set(GO_COMMANDLINE_ROOT ${PROJECT_SOURCE_DIR}/go) +add_executable(go ${GO_COMMANDLINE_ROOT}/source/main.cpp) +target_link_libraries(go goimpl) + +################################################################################ +# GUI executable +################################################################################ -file(GLOB TEST_SOURCE_FILES ${PROJECT_SOURCE_DIR}/tests/*.cpp) -add_executable(go-tests ${TEST_SOURCE_FILES}) -target_link_libraries(go-tests PUBLIC goimpl PRIVATE Catch2::Catch2WithMain) +find_package (imgui CONFIG REQUIRED) -include(CTest) -include(Catch) -catch_discover_tests(go-tests REPORTER junit OUTPUT_DIR junit-output) \ No newline at end of file +set(GO_GUI_ROOT ${PROJECT_SOURCE_DIR}/go-gui) +add_executable(go-gui ${GO_GUI_ROOT}/source/main.cpp) +target_link_libraries(go-gui goimpl imgui::imgui) diff --git a/go-gui/source/main.cpp b/go-gui/source/main.cpp new file mode 100644 index 0000000..7c989f9 --- /dev/null +++ b/go-gui/source/main.cpp @@ -0,0 +1,76 @@ +#include "SDL2/SDL.h" + + +namespace /* private */ { + +struct MyInit +{ + MyInit (const MyInit &) = delete; + MyInit & operator= (const MyInit &) = delete; + MyInit (MyInit &&) = delete; + MyInit & operator= (MyInit &&) = delete; + + SDL_Window* window = nullptr; + bool init_error = false; + + MyInit () + { + // Initialize SDL + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) + { + init_error = true; + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init: %s", SDL_GetError()); + return; + } + + SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + window = SDL_CreateWindow("Dear ImGui SDL2 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags); + + if (window == nullptr) + { + init_error = true; + SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Error: SDL_CreateWindow(): %s\n", SDL_GetError()); + return; + } + } + + ~MyInit () + { + if (window) + { + window = nullptr; + } + } +}; + +} + +int main(int argc, char* argv[]) { + MyInit init; + if (init.init_error) { return -1;} + + bool keepRunning = true; + while (keepRunning) + { + SDL_Event event; + while (SDL_PollEvent(&event) > 0) + { + switch (event.type) + { + case SDL_QUIT: + keepRunning = false; + break; + + case SDL_WINDOWEVENT: + if (event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(init.window)) + { + keepRunning = false; + } + break; + + default: + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Unhandled Event: %d", event.type); + } + } + } +} \ No newline at end of file diff --git a/source/main.cpp b/go/source/main.cpp similarity index 73% rename from source/main.cpp rename to go/source/main.cpp index 00de1cc..67b3137 100644 --- a/source/main.cpp +++ b/go/source/main.cpp @@ -1,9 +1,9 @@ #include -#include "ConsoleUI.hpp" -#include "GameController.hpp" -#include "Logger.hpp" -#include "Player.hpp" +#include "goimpl/ConsoleUI.hpp" +#include "goimpl/GameController.hpp" +#include "goimpl/Logger.hpp" +#include "goimpl/Player.hpp" using namespace Go; diff --git a/source/Board.fwd.hpp b/goimpl/include/goimpl/Board.fwd.hpp similarity index 100% rename from source/Board.fwd.hpp rename to goimpl/include/goimpl/Board.fwd.hpp diff --git a/source/Board.hpp b/goimpl/include/goimpl/Board.hpp similarity index 95% rename from source/Board.hpp rename to goimpl/include/goimpl/Board.hpp index 00a3d72..4f75b00 100644 --- a/source/Board.hpp +++ b/goimpl/include/goimpl/Board.hpp @@ -7,9 +7,9 @@ #include #include #include -#include "Point.hpp" -#include "Chain.fwd.hpp" -#include "Stone.fwd.hpp" +#include "goimpl/Point.hpp" +#include "goimpl/Chain.fwd.hpp" +#include "goimpl/Stone.fwd.hpp" namespace Go { diff --git a/source/Chain.fwd.hpp b/goimpl/include/goimpl/Chain.fwd.hpp similarity index 100% rename from source/Chain.fwd.hpp rename to goimpl/include/goimpl/Chain.fwd.hpp diff --git a/source/Chain.hpp b/goimpl/include/goimpl/Chain.hpp similarity index 93% rename from source/Chain.hpp rename to goimpl/include/goimpl/Chain.hpp index a5808b0..02f39d9 100644 --- a/source/Chain.hpp +++ b/goimpl/include/goimpl/Chain.hpp @@ -4,10 +4,10 @@ #include #include #include -#include "std.fwd.hpp" -#include "Board.fwd.hpp" -#include "Point.fwd.hpp" -#include "Stone.fwd.hpp" +#include "goimpl/std.fwd.hpp" +#include "goimpl/Board.fwd.hpp" +#include "goimpl/Point.fwd.hpp" +#include "goimpl/Stone.fwd.hpp" namespace Go { diff --git a/source/ConsoleUI.hpp b/goimpl/include/goimpl/ConsoleUI.hpp similarity index 84% rename from source/ConsoleUI.hpp rename to goimpl/include/goimpl/ConsoleUI.hpp index 68893f2..bb738bf 100644 --- a/source/ConsoleUI.hpp +++ b/goimpl/include/goimpl/ConsoleUI.hpp @@ -3,9 +3,9 @@ #include -#include "Player.fwd.hpp" -#include "Point.fwd.hpp" -#include "Stone.fwd.hpp" +#include "goimpl/Player.fwd.hpp" +#include "goimpl/Point.fwd.hpp" +#include "goimpl/Stone.fwd.hpp" namespace Go { diff --git a/source/GameController.hpp b/goimpl/include/goimpl/GameController.hpp similarity index 87% rename from source/GameController.hpp rename to goimpl/include/goimpl/GameController.hpp index 1a79bdd..f0c4f2b 100644 --- a/source/GameController.hpp +++ b/goimpl/include/goimpl/GameController.hpp @@ -1,9 +1,9 @@ #ifndef INCL_GAMECONTROLLER_HPP__ #define INCL_GAMECONTROLLER_HPP__ -#include "Board.hpp" +#include "goimpl/Board.hpp" -#include "Player.fwd.hpp" +#include "goimpl/Player.fwd.hpp" namespace Go { diff --git a/source/IPlayer.hpp b/goimpl/include/goimpl/IPlayer.hpp similarity index 93% rename from source/IPlayer.hpp rename to goimpl/include/goimpl/IPlayer.hpp index 17c2029..bead0a6 100644 --- a/source/IPlayer.hpp +++ b/goimpl/include/goimpl/IPlayer.hpp @@ -3,8 +3,8 @@ #include #include -#include "Point.fwd.hpp" -#include "Stone.fwd.hpp" +#include "goimpl/Point.fwd.hpp" +#include "goimpl/Stone.fwd.hpp" namespace Go { diff --git a/source/Logger.hpp b/goimpl/include/goimpl/Logger.hpp similarity index 100% rename from source/Logger.hpp rename to goimpl/include/goimpl/Logger.hpp diff --git a/source/Player.fwd.hpp b/goimpl/include/goimpl/Player.fwd.hpp similarity index 100% rename from source/Player.fwd.hpp rename to goimpl/include/goimpl/Player.fwd.hpp diff --git a/source/Player.hpp b/goimpl/include/goimpl/Player.hpp similarity index 91% rename from source/Player.hpp rename to goimpl/include/goimpl/Player.hpp index ff39879..49e74c3 100644 --- a/source/Player.hpp +++ b/goimpl/include/goimpl/Player.hpp @@ -4,10 +4,10 @@ #include #include #include -#include "IPlayer.hpp" -#include "Board.fwd.hpp" -#include "Point.fwd.hpp" -#include "Stone.fwd.hpp" +#include "goimpl/IPlayer.hpp" +#include "goimpl/Board.fwd.hpp" +#include "goimpl/Point.fwd.hpp" +#include "goimpl/Stone.fwd.hpp" namespace Go { diff --git a/source/Player.tpp b/goimpl/include/goimpl/Player.tpp similarity index 96% rename from source/Player.tpp rename to goimpl/include/goimpl/Player.tpp index bef7cbf..5f187ff 100644 --- a/source/Player.tpp +++ b/goimpl/include/goimpl/Player.tpp @@ -3,11 +3,11 @@ #include #include #include -#include "Board.hpp" -#include "Chain.hpp" -#include "Logger.hpp" -#include "Player.hpp" -#include "Stone.hpp" +#include "goimpl/Board.hpp" +#include "goimpl/Chain.hpp" +#include "goimpl/Logger.hpp" +#include "goimpl/Player.hpp" +#include "goimpl/Stone.hpp" using namespace std; diff --git a/source/Point.fwd.hpp b/goimpl/include/goimpl/Point.fwd.hpp similarity index 100% rename from source/Point.fwd.hpp rename to goimpl/include/goimpl/Point.fwd.hpp diff --git a/source/Point.hpp b/goimpl/include/goimpl/Point.hpp similarity index 94% rename from source/Point.hpp rename to goimpl/include/goimpl/Point.hpp index 90c7e1b..831e369 100644 --- a/source/Point.hpp +++ b/goimpl/include/goimpl/Point.hpp @@ -7,8 +7,8 @@ #include #include -#include "Point.fwd.hpp" -#include "Stone.hpp" +#include "goimpl/Point.fwd.hpp" +#include "goimpl/Stone.hpp" std::ostream & operator<< (std::ostream & out, const Go::PointCoords & coords); std::ostream & operator<< (std::ostream & out, const Go::Point & point); diff --git a/source/Stone.fwd.hpp b/goimpl/include/goimpl/Stone.fwd.hpp similarity index 100% rename from source/Stone.fwd.hpp rename to goimpl/include/goimpl/Stone.fwd.hpp diff --git a/source/Stone.hpp b/goimpl/include/goimpl/Stone.hpp similarity index 100% rename from source/Stone.hpp rename to goimpl/include/goimpl/Stone.hpp diff --git a/source/std.fwd.hpp b/goimpl/include/goimpl/std.fwd.hpp similarity index 90% rename from source/std.fwd.hpp rename to goimpl/include/goimpl/std.fwd.hpp index 01f4614..2168679 100644 --- a/source/std.fwd.hpp +++ b/goimpl/include/goimpl/std.fwd.hpp @@ -1,7 +1,7 @@ #ifndef INCL_STD_FWD_HPP__ #define INCL_STD_FWD_HPP__ -#include "Stone.fwd.hpp" +#include "goimpl/Stone.fwd.hpp" namespace std { diff --git a/source/Board.cpp b/goimpl/source/Board.cpp similarity index 98% rename from source/Board.cpp rename to goimpl/source/Board.cpp index eeefd6a..145e5e7 100644 --- a/source/Board.cpp +++ b/goimpl/source/Board.cpp @@ -3,10 +3,10 @@ #include #include -#include "Board.hpp" -#include "Chain.hpp" -#include "Logger.hpp" -#include "Stone.hpp" +#include "goimpl/Board.hpp" +#include "goimpl/Chain.hpp" +#include "goimpl/Logger.hpp" +#include "goimpl/Stone.hpp" using namespace std; diff --git a/source/Chain.cpp b/goimpl/source/Chain.cpp similarity index 96% rename from source/Chain.cpp rename to goimpl/source/Chain.cpp index aa08733..4981e4e 100644 --- a/source/Chain.cpp +++ b/goimpl/source/Chain.cpp @@ -1,13 +1,13 @@ -#include "Chain.hpp" +#include "goimpl/Chain.hpp" #include #include #include #include -#include "Board.hpp" -#include "Logger.hpp" -#include "Point.hpp" -#include "Stone.hpp" +#include "goimpl/Board.hpp" +#include "goimpl/Logger.hpp" +#include "goimpl/Point.hpp" +#include "goimpl/Stone.hpp" namespace { diff --git a/source/ConsoleUI.cpp b/goimpl/source/ConsoleUI.cpp similarity index 96% rename from source/ConsoleUI.cpp rename to goimpl/source/ConsoleUI.cpp index 305d5bb..94f7629 100644 --- a/source/ConsoleUI.cpp +++ b/goimpl/source/ConsoleUI.cpp @@ -1,11 +1,11 @@ -#include "ConsoleUI.hpp" +#include "goimpl/ConsoleUI.hpp" #include #include #include -#include "Board.hpp" -#include "IPlayer.hpp" -#include "Stone.hpp" +#include "goimpl/Board.hpp" +#include "goimpl/IPlayer.hpp" +#include "goimpl/Stone.hpp" using namespace std; diff --git a/source/GameController.cpp b/goimpl/source/GameController.cpp similarity index 95% rename from source/GameController.cpp rename to goimpl/source/GameController.cpp index 1b78231..7fca6ea 100644 --- a/source/GameController.cpp +++ b/goimpl/source/GameController.cpp @@ -1,14 +1,14 @@ -#include "GameController.hpp" +#include "goimpl/GameController.hpp" #include #include #include #include -#include "Board.hpp" -#include "IPlayer.hpp" -#include "Logger.hpp" -#include "Point.hpp" -#include "Stone.hpp" +#include "goimpl/Board.hpp" +#include "goimpl/IPlayer.hpp" +#include "goimpl/Logger.hpp" +#include "goimpl/Point.hpp" +#include "goimpl/Stone.hpp" using namespace std; diff --git a/source/Logger.cpp b/goimpl/source/Logger.cpp similarity index 75% rename from source/Logger.cpp rename to goimpl/source/Logger.cpp index c31435a..330279b 100644 --- a/source/Logger.cpp +++ b/goimpl/source/Logger.cpp @@ -1,3 +1,3 @@ -#include "Logger.hpp" +#include "goimpl/Logger.hpp" Go::Logger gLogger {Go::LogLevel::kNone}; std::size_t Go::FunctionLogger::nestingLevel = 1; \ No newline at end of file diff --git a/source/Point.cpp b/goimpl/source/Point.cpp similarity index 93% rename from source/Point.cpp rename to goimpl/source/Point.cpp index b3bd84c..547eda4 100644 --- a/source/Point.cpp +++ b/goimpl/source/Point.cpp @@ -1,5 +1,5 @@ -#include "Point.hpp" -#include "Stone.hpp" +#include "goimpl/Point.hpp" +#include "goimpl/Stone.hpp" #include #include #include diff --git a/source/Stone.cpp b/goimpl/source/Stone.cpp similarity index 96% rename from source/Stone.cpp rename to goimpl/source/Stone.cpp index e9a6385..167a302 100644 --- a/source/Stone.cpp +++ b/goimpl/source/Stone.cpp @@ -1,4 +1,4 @@ -#include "Stone.hpp" +#include "goimpl/Stone.hpp" #include #include diff --git a/tests/Point-tests.cpp b/goimpl/tests/Point-tests.cpp similarity index 97% rename from tests/Point-tests.cpp rename to goimpl/tests/Point-tests.cpp index c69ec60..397a47e 100644 --- a/tests/Point-tests.cpp +++ b/goimpl/tests/Point-tests.cpp @@ -1,8 +1,8 @@ #include #include -#include "Point.hpp" -#include "Stone.hpp" +#include "goimpl/Point.hpp" +#include "goimpl/Stone.hpp" using namespace Go; diff --git a/tests/Stone-tests.cpp b/goimpl/tests/Stone-tests.cpp similarity index 97% rename from tests/Stone-tests.cpp rename to goimpl/tests/Stone-tests.cpp index 0d2800b..8a6cc3c 100644 --- a/tests/Stone-tests.cpp +++ b/goimpl/tests/Stone-tests.cpp @@ -1,7 +1,7 @@ #include #include -#include "Stone.hpp" +#include "goimpl/Stone.hpp" using namespace Go; diff --git a/vcpkg.json b/vcpkg.json index 1e17fbc..0ad3a2f 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -6,6 +6,14 @@ { "name": "catch2", "version>=": "3.0.1#2" + }, + { + "name": "imgui", + "version>=": "1.88#1", + "features": [ + "sdl2-binding", + "opengl3-binding" + ] } ] }