From 128fc4f540fb1993863ca2e5bf306a3ab8457a8c Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 10 Jan 2025 15:22:37 -0500 Subject: [PATCH] Turned on all the warnings I could handle and made them into errors then fixed them all. Worldbuilder needs a refactor in random_path. --- ansi_parser.cpp | 18 ++++++++-------- ansi_parser.rl | 18 ++++++++-------- gui.cpp | 2 +- inventory.hpp | 6 +++--- map.cpp | 8 +++---- map.hpp | 5 ++--- meson.build | 48 +++++++++++++++-------------------------- scripts/quick_clean.ps1 | 2 ++ scripts/reset_build.ps1 | 9 ++++++++ status.txt | 1 + systems.cpp | 10 ++++----- systems.hpp | 2 +- tests/ansi_parser.cpp | 3 +-- tests/dinkyecs.cpp | 6 ++++++ tests/fsm.cpp | 4 ++-- tests/panel.cpp | 4 ++-- tilemap.hpp | 12 +++++------ tools/designer.cpp | 6 +++--- worldbuilder.cpp | 6 ++---- 19 files changed, 85 insertions(+), 85 deletions(-) create mode 100644 scripts/quick_clean.ps1 diff --git a/ansi_parser.cpp b/ansi_parser.cpp index ff5f9db..5a1224a 100644 --- a/ansi_parser.cpp +++ b/ansi_parser.cpp @@ -219,15 +219,15 @@ _match: dbc::check(start[0] != '-', "negative numbers not supported"); switch(len) { - case 10: value += (start[len-10] - '0') * 1000000000; - case 9: value += (start[len- 9] - '0') * 100000000; - case 8: value += (start[len- 8] - '0') * 10000000; - case 7: value += (start[len- 7] - '0') * 1000000; - case 6: value += (start[len- 6] - '0') * 100000; - case 5: value += (start[len- 5] - '0') * 10000; - case 4: value += (start[len- 4] - '0') * 1000; - case 3: value += (start[len- 3] - '0') * 100; - case 2: value += (start[len- 2] - '0') * 10; + case 10: value += (start[len-10] - '0') * 1000000000; [[fallthrough]]; + case 9: value += (start[len- 9] - '0') * 100000000; [[fallthrough]]; + case 8: value += (start[len- 8] - '0') * 10000000; [[fallthrough]]; + case 7: value += (start[len- 7] - '0') * 1000000; [[fallthrough]]; + case 6: value += (start[len- 6] - '0') * 100000; [[fallthrough]]; + case 5: value += (start[len- 5] - '0') * 10000; [[fallthrough]]; + case 4: value += (start[len- 4] - '0') * 1000; [[fallthrough]]; + case 3: value += (start[len- 3] - '0') * 100; [[fallthrough]]; + case 2: value += (start[len- 2] - '0') * 10; [[fallthrough]]; case 1: value += (start[len- 1] - '0'); break; default: diff --git a/ansi_parser.rl b/ansi_parser.rl index 37a9fff..dac3e03 100644 --- a/ansi_parser.rl +++ b/ansi_parser.rl @@ -21,15 +21,15 @@ using namespace fmt; dbc::check(start[0] != '-', "negative numbers not supported"); switch(len) { - case 10: value += (start[len-10] - '0') * 1000000000; - case 9: value += (start[len- 9] - '0') * 100000000; - case 8: value += (start[len- 8] - '0') * 10000000; - case 7: value += (start[len- 7] - '0') * 1000000; - case 6: value += (start[len- 6] - '0') * 100000; - case 5: value += (start[len- 5] - '0') * 10000; - case 4: value += (start[len- 4] - '0') * 1000; - case 3: value += (start[len- 3] - '0') * 100; - case 2: value += (start[len- 2] - '0') * 10; + case 10: value += (start[len-10] - '0') * 1000000000; [[fallthrough]]; + case 9: value += (start[len- 9] - '0') * 100000000; [[fallthrough]]; + case 8: value += (start[len- 8] - '0') * 10000000; [[fallthrough]]; + case 7: value += (start[len- 7] - '0') * 1000000; [[fallthrough]]; + case 6: value += (start[len- 6] - '0') * 100000; [[fallthrough]]; + case 5: value += (start[len- 5] - '0') * 10000; [[fallthrough]]; + case 4: value += (start[len- 4] - '0') * 1000; [[fallthrough]]; + case 3: value += (start[len- 3] - '0') * 100; [[fallthrough]]; + case 2: value += (start[len- 2] - '0') * 10; [[fallthrough]]; case 1: value += (start[len- 1] - '0'); break; default: diff --git a/gui.cpp b/gui.cpp index e09cebc..78220fe 100644 --- a/gui.cpp +++ b/gui.cpp @@ -392,7 +392,7 @@ void GUI::run_systems() { auto player = $world.get_the(); System::motion($world, $game_map); System::enemy_pathing($world, $game_map, player); - System::lighting($world, $game_map, $lights, player); + System::lighting($world, $game_map, $lights); System::collision($world, player); System::death($world); } diff --git a/inventory.hpp b/inventory.hpp index 2f1cebe..8ba912b 100644 --- a/inventory.hpp +++ b/inventory.hpp @@ -14,9 +14,9 @@ namespace components { }; struct Inventory { - int gold; - LightSource light; - std::vector items; + int gold=0; + LightSource light{0, 0}; + std::vector items{}; size_t count() { return items.size(); } diff --git a/map.cpp b/map.cpp index aac0a85..a4aeb31 100644 --- a/map.cpp +++ b/map.cpp @@ -173,11 +173,11 @@ bool Map::INVARIANT() { for(auto room : $rooms) { check(int(room.x) >= 0 && int(room.y) >= 0, - format("room depth={} has invalid position {},{}", - room.depth, room.x, room.y)); + format("room invalid position {},{}", + room.x, room.y)); check(int(room.width) > 0 && int(room.height) > 0, - format("room depth={} has invalid dims {},{}", - room.depth, room.width, room.height)); + format("room has invalid dims {},{}", + room.width, room.height)); } return true; diff --git a/map.hpp b/map.hpp index a62a06a..0403b70 100644 --- a/map.hpp +++ b/map.hpp @@ -16,13 +16,12 @@ using lighting::LightSource; struct Room { - int depth; size_t x = 0; size_t y = 0; size_t width = 0; size_t height = 0; - Point entry; - Point exit; + Point entry{(size_t)-1, (size_t)-1}; + Point exit{(size_t)-1, (size_t)-1}; DEFINE_SERIALIZABLE(Room, x, y, width, height); }; diff --git a/meson.build b/meson.build index 5be9e56..21cc7e0 100644 --- a/meson.build +++ b/meson.build @@ -9,33 +9,38 @@ ftxui_dom = dependency('ftxui-dom') ftxui_component = dependency('ftxui-component') sfml = dependency('sfml') freetype2 = dependency('freetype2') +thread_dep = dependency('threads') dependencies = [ fmt, ftxui_screen, ftxui_dom, ftxui_component, json, - sfml, freetype2 + sfml, freetype2, thread_dep ] -runtests = executable('runtests', [ - 'matrix.cpp', +source=[ 'dbc.cpp', + 'matrix.cpp', 'tilemap.cpp', 'map.cpp', + 'gui.cpp', 'rand.cpp', 'sound.cpp', - 'combat.cpp', 'spatialmap.cpp', + 'combat.cpp', + 'systems.cpp', 'ansi_parser.cpp', + 'render.cpp', 'config.cpp', 'save.cpp', 'panel.cpp', - 'render.cpp', 'pathing.cpp', 'lights.cpp', - 'systems.cpp', - 'gui.cpp', 'worldbuilder.cpp', 'inventory.cpp', +] + +runtests = executable('runtests', + source + [ 'tests/tilemap.cpp', 'tests/matrix.cpp', 'tests/fsm.cpp', @@ -55,31 +60,12 @@ runtests = executable('runtests', [ 'tests/gui.cpp', 'tests/worldbuilder.cpp', 'tests/inventory.cpp', - ], + ], cpp_args:['-Wextra','-Werror'], dependencies: dependencies + catch2) -roguish = executable('roguish', [ - 'dbc.cpp', - 'matrix.cpp', - 'tilemap.cpp', - 'map.cpp', - 'main.cpp', - 'gui.cpp', - 'rand.cpp', - 'sound.cpp', - 'spatialmap.cpp', - 'combat.cpp', - 'systems.cpp', - 'ansi_parser.cpp', - 'render.cpp', - 'config.cpp', - 'save.cpp', - 'panel.cpp', - 'pathing.cpp', - 'lights.cpp', - 'worldbuilder.cpp', - 'inventory.cpp', - ], +roguish = executable('roguish', + source + ['main.cpp'], + cpp_args:['-Wextra','-Werror'], dependencies: dependencies) designer = executable('designer', [ @@ -93,7 +79,7 @@ designer = executable('designer', [ 'pathing.cpp', 'lights.cpp', 'tools/designer.cpp' - ], + ], cpp_args:['-Wextra','-Werror'], dependencies: dependencies) fontextract = executable('fontextract', [ diff --git a/scripts/quick_clean.ps1 b/scripts/quick_clean.ps1 new file mode 100644 index 0000000..c988806 --- /dev/null +++ b/scripts/quick_clean.ps1 @@ -0,0 +1,2 @@ +rm -recurse -force .\builddir\runtests.exe* +rm -recurse -force .\builddir\roguish.exe* diff --git a/scripts/reset_build.ps1 b/scripts/reset_build.ps1 index af8305b..e396c4c 100644 --- a/scripts/reset_build.ps1 +++ b/scripts/reset_build.ps1 @@ -4,4 +4,13 @@ mkdir subprojects mv .\packagecache .\subprojects\ mkdir builddir cp wraps\*.wrap subprojects\ + +# clang doesn't actually work on Windows, it almost works but Catch2 fails to link against librt, look at https://mesonbuild.com/Builtin-options.html#compiler-options also there's a bug for it https://github.com/brechtsanders/winlibs_mingw/issues/127 +# -fsafe-buffer-usage-suggestions + +# $env:CC="clang" +# $env:CXX="clang++" +# $env:CC_LD="lld" +# $env:CXX_LD="lld" + meson setup --default-library=static --prefer-static builddir diff --git a/status.txt b/status.txt index a645e57..00486e8 100644 --- a/status.txt +++ b/status.txt @@ -1,5 +1,6 @@ TODAY'S GOAL: +* https://github.com/Ericsson/codechecker?tab=readme-ov-file * Goblins will be in the world and not move or are already dead. * https://pkl-lang.org/ * Check out https://github.com/stephenberry/glaze diff --git a/systems.cpp b/systems.cpp index 35f23fb..f8cd347 100644 --- a/systems.cpp +++ b/systems.cpp @@ -16,16 +16,16 @@ using namespace components; using ftxui::Color; using lighting::LightSource; -void System::lighting(DinkyECS::World &world, Map &game_map, LightRender &light, Player &player) { +void System::lighting(DinkyECS::World &world, Map &game_map, LightRender &light) { light.reset_light(); - world.query([&](const auto &ent, auto &position, auto &lightsource) { + world.query([&](const auto &ent[[maybe_unused]], auto &position) { light.set_light_target(position.location); }); light.path_light(game_map.walls()); - world.query([&](const auto &ent, auto &position, auto &lightsource) { + world.query([&](const auto &ent[[maybe_unused]], auto &position, auto &lightsource) { light.render_light(lightsource, position.location); }); } @@ -62,7 +62,7 @@ void System::init_positions(DinkyECS::World &world) { } }); - world.query([&](const auto &ent, auto &pos, auto &item) { + world.query([&](const auto &ent, auto &pos) { collider.insert(pos.location, ent); }); } @@ -185,7 +185,7 @@ void System::collision(DinkyECS::World &world, Player &player) { void System::draw_entities(DinkyECS::World &world, Map &game_map, const Matrix &lighting, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y) { auto &tiles = game_map.tiles(); - world.query([&](const auto &ent, auto &pos, auto &tile) { + world.query([&](auto &ent[[maybe_unused]], auto &pos, auto &tile) { if(pos.location.x >= cam_orig.x && pos.location.x <= cam_orig.x + view_x && pos.location.y >= cam_orig.y && pos.location.y <= cam_orig.y + view_y) { Point loc = game_map.map_to_camera(pos.location, cam_orig); diff --git a/systems.hpp b/systems.hpp index a6be026..ff96b2e 100644 --- a/systems.hpp +++ b/systems.hpp @@ -9,7 +9,7 @@ namespace System { using namespace components; using namespace lighting; - void lighting(DinkyECS::World &world, Map &game_map, LightRender &light, Player &player); + void lighting(DinkyECS::World &world, Map &game_map, LightRender &light); void motion(DinkyECS::World &world, Map &game_map); void collision(DinkyECS::World &world, Player &player); void death(DinkyECS::World &world); diff --git a/tests/ansi_parser.cpp b/tests/ansi_parser.cpp index 3796d2d..1c7a1b9 100644 --- a/tests/ansi_parser.cpp +++ b/tests/ansi_parser.cpp @@ -66,8 +66,7 @@ TEST_CASE("test out ragel parser", "[gui]") { std::wstring colors_utf = $converter.from_bytes(colors); bool good = ansi.parse(colors_utf, - [&](sf::Color color, sf::Color bgcolor){ - // ignore color + [&](sf::Color color[[maybe_unused]], sf::Color bgcolor[[maybe_unused]]){ }, [&](wchar_t ch) { bool correct_char = ch == '#' || ch == ' ' || ch == '\n' || ch == '\r'; diff --git a/tests/dinkyecs.cpp b/tests/dinkyecs.cpp index d8ab9ec..730bca9 100644 --- a/tests/dinkyecs.cpp +++ b/tests/dinkyecs.cpp @@ -119,8 +119,14 @@ TEST_CASE("confirm ECS system works", "[ecs]") { println("--- After remove test, should only result in test2:"); world.query([&](const auto &ent, auto &pos, auto &vel) { + auto &in_position = world.get(ent); + auto &in_velocity = world.get(ent); REQUIRE(pos.x >= 0); REQUIRE(pos.y >= 0); + REQUIRE(in_position.x == pos.x); + REQUIRE(in_position.y == pos.y); + REQUIRE(in_velocity.x == vel.x); + REQUIRE(in_velocity.y == vel.y); }); } diff --git a/tests/fsm.cpp b/tests/fsm.cpp index bee3219..4c2f0d6 100644 --- a/tests/fsm.cpp +++ b/tests/fsm.cpp @@ -25,7 +25,7 @@ public: } void START(MyEvent ev) { - println("<<< START"); + println("<<< START {}", (int)ev); state(MyState::RUNNING); } @@ -40,7 +40,7 @@ public: } void END(MyEvent ev) { - println("<<< STOP"); + println("<<< STOP {}", (int)ev); state(MyState::END); } }; diff --git a/tests/panel.cpp b/tests/panel.cpp index 5f6ec4b..c0f5224 100644 --- a/tests/panel.cpp +++ b/tests/panel.cpp @@ -17,10 +17,10 @@ void test_ansi_parsing(Panel &panel) { ANSIParser ansi(default_fg, default_bg); bool good = ansi.parse(panel.to_string(), - [&](sf::Color color, sf::Color bgcolor){ + [&](sf::Color color[[maybe_unused]], sf::Color bgcolor[[maybe_unused]]){ // ignore color }, - [&](wchar_t ch) { + [&](wchar_t ch[[maybe_unused]]) { // ignore char }); diff --git a/tilemap.hpp b/tilemap.hpp index 6f334a7..c3f7ae7 100644 --- a/tilemap.hpp +++ b/tilemap.hpp @@ -11,12 +11,12 @@ struct TileCell { std::string display; - uint8_t fg_h; - uint8_t fg_s; - uint8_t fg_v; - uint8_t bg_h; - uint8_t bg_s; - uint8_t bg_v; + uint8_t fg_h = 0; + uint8_t fg_s = 0; + uint8_t fg_v = 0; + uint8_t bg_h = 0; + uint8_t bg_s = 0; + uint8_t bg_v = 0; }; typedef std::vector TileRow; diff --git a/tools/designer.cpp b/tools/designer.cpp index bf6c6be..b40b7c4 100644 --- a/tools/designer.cpp +++ b/tools/designer.cpp @@ -118,9 +118,9 @@ struct WhatTheColor { int h; int s; int v; - Component h_slider; - Component s_slider; - Component v_slider; + Component h_slider = nullptr; + Component s_slider = nullptr; + Component v_slider = nullptr; }; class GUI { diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 7a3a20b..e732fb6 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -82,13 +82,11 @@ void WorldBuilder::partition_map(Room &cur, int depth) { // BUG: min room size should be configurable if(depth > 0 && left.width > 2 && left.height > 2) { - left.depth = depth - 1; partition_map(left, depth-1); } // BUG: min room size should be configurable if(depth > 0 && right.width > 2 && right.height > 2) { - right.depth = depth - 1; partition_map(right, depth-1); } } @@ -273,7 +271,7 @@ void WorldBuilder::place_rooms() { } } -inline bool random_path(Map &map, PointList &holes, Point src, Point target) { +inline bool random_path(Map &map, PointList &holes, Point src) { bool found = false; Matrix &paths = map.paths(); Point out{src.x, src.y}; @@ -306,7 +304,7 @@ bool WorldBuilder::dig_tunnel(PointList &holes, Point &src, Point &target) { dbc::check(paths[target.y][target.x] != WALL_PATH_LIMIT, "target room has path as a wall"); - if(!random_path($map, holes, src, target)) { + if(!random_path($map, holes, src)) { straight_path(holes, src, target); }