Fix warnings

This commit is contained in:
Patricia Aas 2021-08-02 15:28:07 +02:00
parent d4ae224a67
commit d3cc1d90c7
7 changed files with 15 additions and 17 deletions

View file

@ -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'

View file

@ -1,7 +1,5 @@
cmake_minimum_required(VERSION 3.17) cmake_minimum_required(VERSION 3.17)
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/toolchain.cmake")
find_package(Git QUIET) find_package(Git QUIET)
if (GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") if (GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
# Update submodules as needed # Update submodules as needed
@ -28,6 +26,8 @@ set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/
enable_language(CXX) enable_language(CXX)
project(pacman) project(pacman)
include(cmake/toolchain.cmake)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
add_subdirectory(scaling-lib) add_subdirectory(scaling-lib)

View file

@ -13,9 +13,7 @@ else()
add_link_options("$<$<CONFIG:DEBUG>:-fsanitize=address>") add_link_options("$<$<CONFIG:DEBUG>:-fsanitize=address>")
endif() endif()
#enable ubsan in debug #enable ubsan in debug
if(NOT MSVC) if(NOT MSVC)
add_compile_options("$<$<CONFIG:DEBUG>:-fsanitize=undefined>" add_compile_options("$<$<CONFIG:DEBUG>:-fsanitize=undefined>"
"$<$<CONFIG:DEBUG>:-fno-omit-frame-pointer>") "$<$<CONFIG:DEBUG>:-fno-omit-frame-pointer>")

View file

@ -8,10 +8,10 @@
namespace pacman { namespace pacman {
Canvas::Canvas() Canvas::Canvas()
: window(sf::VideoMode((viewDimensions().width / 2.0), (viewDimensions().height / 2.0)), : window(sf::VideoMode((viewDimensions().width / 2), (viewDimensions().height / 2)),
"Pacman", "Pacman",
sf::Style::Titlebar | sf::Style::Close), 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.setView(view);
window.setFramerateLimit(60); window.setFramerateLimit(60);
@ -21,9 +21,9 @@ Canvas::Canvas()
// Then project it on a scaled window - on some mac we get the // Then project it on a scaled window - on some mac we get the
// scaling factor of the window to adjust the resolution // scaling factor of the window to adjust the resolution
const auto scale = scaling_factor_for_window(window.getSystemHandle()); const auto scale = scaling_factor_for_window(window.getSystemHandle());
const auto width = viewDimensions().width / 2.0 * scale; const auto width = (viewDimensions().width / 2) * scale;
const auto height = viewDimensions().height / 2.0 * scale; const auto height = (viewDimensions().height / 2) * scale;
window.setSize(sf::Vector2u(width, height)); window.setSize(sf::Vector2u(unsigned(width), unsigned(height)));
maze_texture = loadTexture("maze.png"); maze_texture = loadTexture("maze.png");
sprites_texture = loadTexture("sprites32.png"); sprites_texture = loadTexture("sprites32.png");
@ -126,8 +126,8 @@ void Canvas::renderLives(int lives) {
Sprite pacmanSprite = getSprite(liveSprite); Sprite pacmanSprite = getSprite(liveSprite);
for (int i = 0; i < lives - 1; i++) { for (int i = 0; i < lives - 1; i++) {
size_t life_position = i * SPRITE_WIDTH * 1.5; auto life_position = i * SPRITE_WIDTH * 1.5f;
GridPosition pos{ x + life_position, y }; sf::Vector2f pos{ x + life_position, y };
pacmanSprite.setPosition(pos.x, pos.y); pacmanSprite.setPosition(pos.x, pos.y);
window.draw(pacmanSprite); window.draw(pacmanSprite);
} }
@ -152,7 +152,7 @@ Sprite Canvas::getSprite(GridPosition coordinate) const {
void Canvas::renderSprite(Sprite sprite, Position pos) { void Canvas::renderSprite(Sprite sprite, Position pos) {
pos.x = LEFT_MARGIN + (pos.x * SPRITE_WIDTH); pos.x = LEFT_MARGIN + (pos.x * SPRITE_WIDTH);
pos.y = TOP_MARGIN + (pos.y * SPRITE_HEIGHT); 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); window.draw(sprite);
} }

View file

@ -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 // And selects a point on the line crossing blinky and this position that is at twice that distance
// away from blinky // away from blinky
targetPosition.x += ((targetPosition.x - blinkyPosition.x) / distanceBetweenBlinkyAndTarget) * 2; targetPosition.x += size_t((targetPosition.x - blinkyPosition.x) / distanceBetweenBlinkyAndTarget) * 2;
targetPosition.y += ((targetPosition.y - blinkyPosition.y) / distanceBetweenBlinkyAndTarget) * 2; targetPosition.y += size_t((targetPosition.y - blinkyPosition.y) / distanceBetweenBlinkyAndTarget) * 2;
return gridPositionToPosition(targetPosition); return gridPositionToPosition(targetPosition);
} }

View file

@ -8,7 +8,7 @@
namespace pacman { namespace pacman {
class GameState; struct GameState;
class Ghost { class Ghost {
public: public:

View file

@ -18,7 +18,7 @@ public:
void pause(); void pause();
private: private:
uint8_t animation_position = 0; size_t animation_position = 0;
double animation_position_delta = 0.0; double animation_position_delta = 0.0;
}; };