diff --git a/.clang-tidy b/.clang-tidy index a2cc3ce..dfe8dd1 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1 +1 @@ -Checks: 'modernize-*,-modernize-use-nodiscard,-modernize-use-trailing-return-type,cppcoreguidelines-*,bugprone-*,-cppcoreguidelines-non-private-member-variables-in-classes' +Checks: 'modernize-*,-modernize-use-nodiscard,-modernize-use-trailing-return-type,cppcoreguidelines-*,bugprone-*,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-avoid-magic-numbers' diff --git a/CMakeLists.txt b/CMakeLists.txt index 466a7fa..8c0031a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,5 @@ cmake_minimum_required(VERSION 3.17) -set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/toolchain.cmake") - find_package(Git QUIET) if (GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") # Update submodules as needed @@ -28,6 +26,8 @@ set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/ enable_language(CXX) project(pacman) +include(cmake/toolchain.cmake) + set(CMAKE_CXX_STANDARD 20) add_subdirectory(scaling-lib) diff --git a/toolchain.cmake b/cmake/toolchain.cmake similarity index 99% rename from toolchain.cmake rename to cmake/toolchain.cmake index bd1e543..017c1c2 100644 --- a/toolchain.cmake +++ b/cmake/toolchain.cmake @@ -13,9 +13,7 @@ else() add_link_options("$<$:-fsanitize=address>") endif() - #enable ubsan in debug - if(NOT MSVC) add_compile_options("$<$:-fsanitize=undefined>" "$<$:-fno-omit-frame-pointer>") diff --git a/lib/Canvas.cpp b/lib/Canvas.cpp index db365c3..c51a522 100644 --- a/lib/Canvas.cpp +++ b/lib/Canvas.cpp @@ -8,10 +8,10 @@ namespace pacman { Canvas::Canvas() - : window(sf::VideoMode((viewDimensions().width / 2.0), (viewDimensions().height / 2.0)), + : window(sf::VideoMode((viewDimensions().width / 2), (viewDimensions().height / 2)), "Pacman", sf::Style::Titlebar | sf::Style::Close), - view(sf::FloatRect(0, 0, viewDimensions().width, viewDimensions().height)) { + view(sf::FloatRect(0, 0, float(viewDimensions().width), float(viewDimensions().height))) { window.setView(view); window.setFramerateLimit(60); @@ -21,9 +21,9 @@ Canvas::Canvas() // Then project it on a scaled window - on some mac we get the // scaling factor of the window to adjust the resolution const auto scale = scaling_factor_for_window(window.getSystemHandle()); - const auto width = viewDimensions().width / 2.0 * scale; - const auto height = viewDimensions().height / 2.0 * scale; - window.setSize(sf::Vector2u(width, height)); + const auto width = (viewDimensions().width / 2) * scale; + const auto height = (viewDimensions().height / 2) * scale; + window.setSize(sf::Vector2u(unsigned(width), unsigned(height))); maze_texture = loadTexture("maze.png"); sprites_texture = loadTexture("sprites32.png"); @@ -126,8 +126,8 @@ void Canvas::renderLives(int lives) { Sprite pacmanSprite = getSprite(liveSprite); for (int i = 0; i < lives - 1; i++) { - size_t life_position = i * SPRITE_WIDTH * 1.5; - GridPosition pos{ x + life_position, y }; + auto life_position = i * SPRITE_WIDTH * 1.5f; + sf::Vector2f pos{ x + life_position, y }; pacmanSprite.setPosition(pos.x, pos.y); window.draw(pacmanSprite); } @@ -152,7 +152,7 @@ Sprite Canvas::getSprite(GridPosition coordinate) const { void Canvas::renderSprite(Sprite sprite, Position pos) { pos.x = LEFT_MARGIN + (pos.x * SPRITE_WIDTH); pos.y = TOP_MARGIN + (pos.y * SPRITE_HEIGHT); - sprite.setPosition(pos.x, pos.y); + sprite.setPosition(float(pos.x), float(pos.y)); window.draw(sprite); } diff --git a/lib/Inky.cpp b/lib/Inky.cpp index 9593ee2..6b258ac 100644 --- a/lib/Inky.cpp +++ b/lib/Inky.cpp @@ -53,8 +53,8 @@ Position Inky::target(const GameState & gameState) const { // And selects a point on the line crossing blinky and this position that is at twice that distance // away from blinky - targetPosition.x += ((targetPosition.x - blinkyPosition.x) / distanceBetweenBlinkyAndTarget) * 2; - targetPosition.y += ((targetPosition.y - blinkyPosition.y) / distanceBetweenBlinkyAndTarget) * 2; + targetPosition.x += size_t((targetPosition.x - blinkyPosition.x) / distanceBetweenBlinkyAndTarget) * 2; + targetPosition.y += size_t((targetPosition.y - blinkyPosition.y) / distanceBetweenBlinkyAndTarget) * 2; return gridPositionToPosition(targetPosition); } diff --git a/lib/include/Ghost.hpp b/lib/include/Ghost.hpp index 421f8cf..c353090 100644 --- a/lib/include/Ghost.hpp +++ b/lib/include/Ghost.hpp @@ -8,7 +8,7 @@ namespace pacman { -class GameState; +struct GameState; class Ghost { public: diff --git a/lib/include/PacManAnimation.hpp b/lib/include/PacManAnimation.hpp index a286f84..cd49ee4 100644 --- a/lib/include/PacManAnimation.hpp +++ b/lib/include/PacManAnimation.hpp @@ -18,7 +18,7 @@ public: void pause(); private: - uint8_t animation_position = 0; + size_t animation_position = 0; double animation_position_delta = 0.0; };