Skip to content

Commit fd9914f

Browse files
authored
Address some of the CI failures (#3)
1 parent d57f380 commit fd9914f

File tree

12 files changed

+127
-93
lines changed

12 files changed

+127
-93
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ jobs:
6464
developer_mode: OFF
6565
package_generator: TBZ2
6666

67-
# This exists solely to make sure a non-multiconfig build works
68-
- os: ubuntu-20.04
69-
compiler: gcc-11
70-
generator: "Unix Makefiles"
71-
build_type: Debug
72-
gcov_executable: gcov
73-
developer_mode: On
7467

7568
- os: windows-2022
7669
compiler: msvc

CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,27 @@ dynamic_project_options(
111111
# MSVC_WARNINGS # Override the defaults for the MSVC warnings
112112
# CLANG_WARNINGS # Override the defaults for the CLANG warnings
113113
# GCC_WARNINGS # Override the defaults for the GCC warnings
114-
# CPPCHECK_OPTIONS # Override the defaults for CppCheck
114+
CPPCHECK_OPTIONS
115+
--enable=style,performance,warning,portability
116+
--inline-suppr
117+
# We cannot act on a bug/missing feature of cppcheck
118+
--suppress=cppcheckError
119+
--suppress=internalAstError
120+
--suppress=syntaxError
121+
# if a file does not have an internalAstError, we get an unmatchedSuppression error
122+
--suppress=unmatchedSuppression
123+
# There are too many false positives with this check
124+
--suppress=passedByValue
125+
--inconclusive
126+
115127
)
116128

117129
target_compile_features(project_options INTERFACE cxx_std_${CMAKE_CXX_STANDARD})
118130

131+
# We don't have any way of ensuring that all static dependencies are compiled with
132+
# address sanitizer enabled.
133+
target_compile_definitions(project_options INTERFACE _DISABLE_VECTOR_ANNOTATION)
134+
119135
# configure files based on CMake configuration options
120136
add_subdirectory(configured_files)
121137

src/bitmap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ Vector2D<Color> load_png(const std::filesystem::path &filename)
3535

3636
return results;
3737
}
38-
}// namespace lefticus::my_awesome_game
38+
}// namespace lefticus::awesome_game

src/bitmap.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ struct Bitmap : ftxui::Node
4242

4343
Vector2D<Color> load_png(const std::filesystem::path &filename);
4444

45-
}// namespace lefticus::my_awesome_game
45+
}// namespace lefticus::awesome_game
4646

4747
#endif// AWESOME_GAME_BITMAP_HPP

src/color.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ template<typename Type> struct Basic_Color
8484
};
8585

8686
using Color = Basic_Color<std::uint8_t>;
87-
}// namespace lefticus::my_awesome_game
87+
}// namespace lefticus::awesome_game
8888

8989
#endif// AWESOME_GAME_COLOR_HPP

src/game.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ Game_Map make_store()
3737
};
3838

3939
map.locations.at(Point{ 3, 3 }).enter_action = [](Game &game, Point, Direction) {
40-
game.set_menu(
41-
Menu{ { "Ask about town", "This is the quiet town of 'Quad Corners'. The economy has been down for the last few years. People have been moving away. It's a bit depressing, really." },
42-
set_flag("Tell about present", "Ah yes, the Xstation6, all of the kids want one. You'll probably have a hard time finding one of those around here.", variable{"xstation"}),
43-
check_flag("Ask about Xstation6", "I think bob has one.", variable{"xstation"}),
44-
45-
exit_menu() });
40+
game.set_menu(Menu{ { "Ask about town",
41+
"This is the quiet town of 'Quad Corners'. The economy has been down for the last few years. "
42+
"People have been moving away. It's a bit depressing, really." },
43+
set_flag("Tell about present",
44+
"Ah yes, the Xstation6, all of the kids want one. You'll probably have a hard time finding one of those around "
45+
"here.",
46+
variable{ "xstation" }),
47+
check_flag("Ask about Xstation6", "I think bob has one.", variable{ "xstation" }),
48+
49+
exit_menu() });
4650
};
4751

4852
return map;

src/game_components.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
#include <filesystem>
44
#include <fstream>
55
#include <nlohmann/json.hpp>
6+
7+
#ifdef _MSC_VER
8+
#pragma warning(disable : 4189)
9+
#endif
610
#include <spdlog/spdlog.h>
11+
#ifdef _MSC_VER
12+
#pragma warning(default : 4189)
13+
#endif
714

815
namespace lefticus::awesome_game {
916

@@ -44,7 +51,8 @@ Game_Map load_tiled_map(const std::filesystem::path &map_json)// NOLINT cofnitiv
4451

4552
if (tile.contains("properties")) {
4653
for (const auto &property : tile["properties"]) {
47-
if (property["name"] == "passable") { passable = property["value"]; }// cppcheck-suppress useStlAlgorithm
54+
// cppcheck-suppress useStlAlgorithm
55+
if (property["name"] == "passable") { passable = property["value"]; }
4856
}
4957
}
5058

@@ -134,7 +142,7 @@ Game_Map load_tiled_map(const std::filesystem::path &map_json)// NOLINT cofnitiv
134142

135143
map.locations.at(point).can_enter = [tiles = tile_data](const Game &game, Point, Direction) {
136144
const auto &tile_sets = game.get_current_map().tile_sets;
137-
return std::ranges::all_of(tiles, [&](const auto &tile) {
145+
return std::all_of(tiles.begin(), tiles.end(), [&](const auto &tile) {
138146
return tile.foreground || tile.background || tile.tileid == 0
139147
|| tile_sets[0].properties.at(tile.tileid).passable;
140148
});

src/game_components.hpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include <variant>
1111

1212
#include "color.hpp"
13-
#include "vector2d.hpp"
1413
#include "tile_set.hpp"
14+
#include "vector2d.hpp"
1515

1616
namespace lefticus::awesome_game {
1717

@@ -86,8 +86,6 @@ struct variable
8686
};
8787

8888

89-
90-
9189
inline std::string to_string(const Variable &variable)
9290
{
9391
return std::visit([](const auto &value) { return fmt::format("{}", value); }, variable);
@@ -100,16 +98,15 @@ struct Menu
10098
std::string text;
10199
std::function<void(Game &)> action;
102100
std::function<bool(const Game &)> visible;
103-
MenuItem(std::string text_, std::string message_, std::function<bool (const Game &)> = {});
101+
MenuItem(std::string text_, std::string message_, std::function<bool(const Game &)> = {});
104102

105103
template<typename Compare>
106104
MenuItem(std::string text_, std::string message_, Variable_Comparison<Compare> comp)
107-
: MenuItem(std::move(text_), std::move(message_), std::function<bool(const Game &)>(std::move(comp.comparitor)))
108-
{
109-
}
105+
: MenuItem(std::move(text_), std::move(message_), std::function<bool(const Game &)>(std::move(comp.comparitor)))
106+
{}
107+
108+
MenuItem(std::string text_, std::function<void(Game &)> action_, std::function<bool(const Game &)> visible_ = {});
110109

111-
MenuItem(std::string text_, std::function<void(Game &)> action_, std::function<bool (const Game &)> visible_ = {});
112-
113110
template<typename Compare>
114111
MenuItem(std::string text_, std::function<void(Game &)> action_, Variable_Comparison<Compare> comp)
115112
: MenuItem(std::move(text_), std::move(action_), std::function<bool(const Game &)>(std::move(comp.comparitor)))
@@ -178,77 +175,80 @@ struct Game
178175
bool menu_is_new = false;
179176
};
180177

178+
// cppcheck is wrong about these wanting to be passed by const &.
179+
// that is because these are sinks
180+
181181
template<typename Value> auto operator==(variable var, Value value)
182182
{
183-
return Variable_Comparison{ [name = std::move(var.name), value = Variable{ std::move(value) }](
183+
return Variable_Comparison{ [name = std::move(var).name, value = Variable{ std::move(value) }](
184184
const Game &game) { return game.variables.at(name) == value; } };
185185
}
186186

187187
template<typename Value> auto operator==(Value value, variable var)
188188
{
189-
return Variable_Comparison{ [name = std::move(var.name), value = Variable{ std::move(value) }](
189+
return Variable_Comparison{ [name = std::move(var).name, value = Variable{ std::move(value) }](
190190
const Game &game) { return value == game.variables.at(name); } };
191191
}
192192

193193

194194
template<typename Value> auto operator!=(variable var, Value value)
195195
{
196-
return Variable_Comparison{ [name = std::move(var.name), value = Variable{ std::move(value) }](
196+
return Variable_Comparison{ [name = std::move(var).name, value = Variable{ std::move(value) }](
197197
const Game &game) { return game.variables.at(name) != value; } };
198198
}
199199

200200
template<typename Value> auto operator!=(Value value, variable var)
201201
{
202-
return Variable_Comparison{ [name = std::move(var.name), value = Variable{ std::move(value) }](
202+
return Variable_Comparison{ [name = std::move(var).name, value = Variable{ std::move(value) }](
203203
const Game &game) { return value != game.variables.at(name); } };
204204
}
205205

206206
template<typename Value> auto operator<(variable var, Value value)
207207
{
208-
return Variable_Comparison{ [name = std::move(var.name), value = Variable{ std::move(value) }](
208+
return Variable_Comparison{ [name = std::move(var).name, value = Variable{ std::move(value) }](
209209
const Game &game) { return game.variables.at(name) < value; } };
210210
}
211211

212212
template<typename Value> auto operator<(Value value, variable var)
213213
{
214-
return Variable_Comparison{ [name = std::move(var.name), value = Variable{ std::move(value) }](
214+
return Variable_Comparison{ [name = std::move(var).name, value = Variable{ std::move(value) }](
215215
const Game &game) { return value < game.variables.at(name); } };
216216
}
217217

218218

219219
template<typename Value> auto operator<=(variable var, Value value)
220220
{
221-
return Variable_Comparison{ [name = std::move(var.name), value = Variable{ std::move(value) }](
221+
return Variable_Comparison{ [name = std::move(var).name, value = Variable{ std::move(value) }](
222222
const Game &game) { return game.variables.at(name) <= value; } };
223223
}
224224

225225
template<typename Value> auto operator<=(Value value, variable var)
226226
{
227-
return Variable_Comparison{ [name = std::move(var.name), value = Variable{ std::move(value) }](
227+
return Variable_Comparison{ [name = std::move(var).name, value = Variable{ std::move(value) }](
228228
const Game &game) { return value <= game.variables.at(name); } };
229229
}
230230

231231
template<typename Value> auto operator>(variable var, Value value)
232232
{
233-
return Variable_Comparison{ [name = std::move(var.name), value = Variable{ std::move(value) }](
233+
return Variable_Comparison{ [name = std::move(var).name, value = Variable{ std::move(value) }](
234234
const Game &game) { return game.variables.at(name) > value; } };
235235
}
236236

237237
template<typename Value> auto operator>(Value value, variable var)
238238
{
239-
return Variable_Comparison{ [name = std::move(var.name), value = Variable{ std::move(value) }](
239+
return Variable_Comparison{ [name = std::move(var).name, value = Variable{ std::move(value) }](
240240
const Game &game) { return value > game.variables.at(name); } };
241241
}
242242

243243
template<typename Value> auto operator>=(variable var, Value value)
244244
{
245-
return Variable_Comparison{ [name = std::move(var.name), value = Variable{ std::move(value) }](
245+
return Variable_Comparison{ [name = std::move(var).name, value = Variable{ std::move(value) }](
246246
const Game &game) { return game.variables.at(name) >= value; } };
247247
}
248248

249249
template<typename Value> auto operator>=(Value value, variable var)
250250
{
251-
return Variable_Comparison{ [name = std::move(var.name), value = Variable{ std::move(value) }](
251+
return Variable_Comparison{ [name = std::move(var).name, value = Variable{ std::move(value) }](
252252
const Game &game) { return value >= game.variables.at(name); } };
253253
}
254254

src/game_hacking_lesson_01.cpp

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,47 @@ Game_Map make_map()// NOLINT cognitive complexity
1414
{
1515
Game_Map map{ Size{ 10, 10 } };// NOLINT magic numbers
1616

17-
auto button_draw =
18-
[](Vector2D_Span<Color> &pixels, [[maybe_unused]] const Game &game, [[maybe_unused]] Point map_location, Layer layer) {
19-
if (layer == Layer::Background) {
20-
if (button_pressed(game)) {
21-
// Light grey if button is pressed
22-
fill(pixels, Color{ 45, 45, 45, 255 });// NOLINT magic number
23-
} else {
24-
// dark grey if button is not pressed
25-
fill(pixels, Color{ 15, 15, 15, 255 });// NOLINT magic number
26-
}
17+
auto button_draw = [](Vector2D_Span<Color> &pixels,
18+
[[maybe_unused]] const Game &game,
19+
[[maybe_unused]] Point map_location,
20+
Layer layer) {
21+
if (layer == Layer::Background) {
22+
if (button_pressed(game)) {
23+
// Light grey if button is pressed
24+
fill(pixels, Color{ 45, 45, 45, 255 });// NOLINT magic number
25+
} else {
26+
// dark grey if button is not pressed
27+
fill(pixels, Color{ 15, 15, 15, 255 });// NOLINT magic number
2728
}
28-
};
29+
}
30+
};
2931

30-
auto empty_draw =
31-
[](Vector2D_Span<Color> &pixels, [[maybe_unused]] const Game &game, [[maybe_unused]] Point map_location, Layer layer) {
32-
if (layer == Layer::Background) {
33-
fill(pixels, Color{ 5, 5, 25, 255 });// NOLINT magic number
34-
}
35-
};
32+
auto empty_draw = [](Vector2D_Span<Color> &pixels,
33+
[[maybe_unused]] const Game &game,
34+
[[maybe_unused]] Point map_location,
35+
Layer layer) {
36+
if (layer == Layer::Background) {
37+
fill(pixels, Color{ 5, 5, 25, 255 });// NOLINT magic number
38+
}
39+
};
3640

3741
auto cannot_enter = [](const Game &, Point, Direction) -> bool { return false; };
3842

39-
auto water_draw =
40-
[](Vector2D_Span<Color> &pixels, [[maybe_unused]] const Game &game, [[maybe_unused]] Point map_location, Layer layer) {
41-
if (layer == Layer::Background) {
42-
fill(pixels, Color{ 0, 0, 250, 255 });// NOLINT magic number
43-
}
44-
};
43+
auto water_draw = [](Vector2D_Span<Color> &pixels,
44+
[[maybe_unused]] const Game &game,
45+
[[maybe_unused]] Point map_location,
46+
Layer layer) {
47+
if (layer == Layer::Background) {
48+
fill(pixels, Color{ 0, 0, 250, 255 });// NOLINT magic number
49+
}
50+
};
4551

4652

4753
auto wall_draw = []([[maybe_unused]] Vector2D_Span<Color> &pixels,
4854
[[maybe_unused]] const Game &game,
4955
[[maybe_unused]] Point map_location,
5056
Layer layer) {
51-
if (layer == Layer::Foreground) {
52-
return;
53-
}
57+
if (layer == Layer::Foreground) { return; }
5458

5559
static constexpr auto wall_color = Color{ 100, 100, 100, 128 };
5660

src/game_hacking_lesson_02.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,29 @@ Game_Map make_map()// NOLINT cognitive complexity
1111

1212
auto colors_used = std::make_shared<std::set<Color>>();
1313

14-
auto empty_draw =
15-
[](Vector2D_Span<Color> &pixels, [[maybe_unused]] const Game &game, [[maybe_unused]] Point map_location, Layer layer) {
16-
if (layer == Layer::Foreground) { return; }
17-
fill(pixels, Color{ 5, 5, 25, 255 });// NOLINT magic number
18-
};
14+
auto empty_draw = [](Vector2D_Span<Color> &pixels,
15+
[[maybe_unused]] const Game &game,
16+
[[maybe_unused]] Point map_location,
17+
Layer layer) {
18+
if (layer == Layer::Foreground) { return; }
19+
fill(pixels, Color{ 5, 5, 25, 255 });// NOLINT magic number
20+
};
1921

2022
auto cannot_enter = [](const Game &, Point, Direction) -> bool { return false; };
2123

22-
auto water_draw =
23-
[](Vector2D_Span<Color> &pixels, [[maybe_unused]] const Game &game, [[maybe_unused]] Point map_location, Layer layer) {
24+
auto water_draw = [](Vector2D_Span<Color> &pixels,
25+
[[maybe_unused]] const Game &game,
26+
[[maybe_unused]] Point map_location,
27+
Layer layer) {
2428
if (layer == Layer::Foreground) { return; }
25-
fill(pixels, Color{ 0, 0, 250, 255 });// NOLINT magic number
26-
};
29+
fill(pixels, Color{ 0, 0, 250, 255 });// NOLINT magic number
30+
};
2731

2832

2933
auto wall_draw = [colors_used]([[maybe_unused]] Vector2D_Span<Color> &pixels,
3034
[[maybe_unused]] const Game &game,
31-
[[maybe_unused]] Point map_location, Layer layer) {
35+
[[maybe_unused]] Point map_location,
36+
Layer layer) {
3237
if (layer == Layer::Foreground) { return; }
3338
static constexpr auto wall_color = Color{ 100, 100, 100, 128 };
3439

0 commit comments

Comments
 (0)