Turned on all the warnings I could handle and made them into errors then fixed them all. Worldbuilder needs a refactor in random_path.

main
Zed A. Shaw 1 week ago
parent f3f875ee80
commit 128fc4f540
  1. 18
      ansi_parser.cpp
  2. 18
      ansi_parser.rl
  3. 2
      gui.cpp
  4. 6
      inventory.hpp
  5. 8
      map.cpp
  6. 5
      map.hpp
  7. 48
      meson.build
  8. 2
      scripts/quick_clean.ps1
  9. 9
      scripts/reset_build.ps1
  10. 1
      status.txt
  11. 10
      systems.cpp
  12. 2
      systems.hpp
  13. 3
      tests/ansi_parser.cpp
  14. 6
      tests/dinkyecs.cpp
  15. 4
      tests/fsm.cpp
  16. 4
      tests/panel.cpp
  17. 12
      tilemap.hpp
  18. 6
      tools/designer.cpp
  19. 6
      worldbuilder.cpp

@ -219,15 +219,15 @@ _match:
dbc::check(start[0] != '-', "negative numbers not supported"); dbc::check(start[0] != '-', "negative numbers not supported");
switch(len) { switch(len) {
case 10: value += (start[len-10] - '0') * 1000000000; case 10: value += (start[len-10] - '0') * 1000000000; [[fallthrough]];
case 9: value += (start[len- 9] - '0') * 100000000; case 9: value += (start[len- 9] - '0') * 100000000; [[fallthrough]];
case 8: value += (start[len- 8] - '0') * 10000000; case 8: value += (start[len- 8] - '0') * 10000000; [[fallthrough]];
case 7: value += (start[len- 7] - '0') * 1000000; case 7: value += (start[len- 7] - '0') * 1000000; [[fallthrough]];
case 6: value += (start[len- 6] - '0') * 100000; case 6: value += (start[len- 6] - '0') * 100000; [[fallthrough]];
case 5: value += (start[len- 5] - '0') * 10000; case 5: value += (start[len- 5] - '0') * 10000; [[fallthrough]];
case 4: value += (start[len- 4] - '0') * 1000; case 4: value += (start[len- 4] - '0') * 1000; [[fallthrough]];
case 3: value += (start[len- 3] - '0') * 100; case 3: value += (start[len- 3] - '0') * 100; [[fallthrough]];
case 2: value += (start[len- 2] - '0') * 10; case 2: value += (start[len- 2] - '0') * 10; [[fallthrough]];
case 1: value += (start[len- 1] - '0'); case 1: value += (start[len- 1] - '0');
break; break;
default: default:

@ -21,15 +21,15 @@ using namespace fmt;
dbc::check(start[0] != '-', "negative numbers not supported"); dbc::check(start[0] != '-', "negative numbers not supported");
switch(len) { switch(len) {
case 10: value += (start[len-10] - '0') * 1000000000; case 10: value += (start[len-10] - '0') * 1000000000; [[fallthrough]];
case 9: value += (start[len- 9] - '0') * 100000000; case 9: value += (start[len- 9] - '0') * 100000000; [[fallthrough]];
case 8: value += (start[len- 8] - '0') * 10000000; case 8: value += (start[len- 8] - '0') * 10000000; [[fallthrough]];
case 7: value += (start[len- 7] - '0') * 1000000; case 7: value += (start[len- 7] - '0') * 1000000; [[fallthrough]];
case 6: value += (start[len- 6] - '0') * 100000; case 6: value += (start[len- 6] - '0') * 100000; [[fallthrough]];
case 5: value += (start[len- 5] - '0') * 10000; case 5: value += (start[len- 5] - '0') * 10000; [[fallthrough]];
case 4: value += (start[len- 4] - '0') * 1000; case 4: value += (start[len- 4] - '0') * 1000; [[fallthrough]];
case 3: value += (start[len- 3] - '0') * 100; case 3: value += (start[len- 3] - '0') * 100; [[fallthrough]];
case 2: value += (start[len- 2] - '0') * 10; case 2: value += (start[len- 2] - '0') * 10; [[fallthrough]];
case 1: value += (start[len- 1] - '0'); case 1: value += (start[len- 1] - '0');
break; break;
default: default:

@ -392,7 +392,7 @@ void GUI::run_systems() {
auto player = $world.get_the<Player>(); auto player = $world.get_the<Player>();
System::motion($world, $game_map); System::motion($world, $game_map);
System::enemy_pathing($world, $game_map, player); 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::collision($world, player);
System::death($world); System::death($world);
} }

@ -14,9 +14,9 @@ namespace components {
}; };
struct Inventory { struct Inventory {
int gold; int gold=0;
LightSource light; LightSource light{0, 0};
std::vector<InventoryItem> items; std::vector<InventoryItem> items{};
size_t count() { return items.size(); } size_t count() { return items.size(); }

@ -173,11 +173,11 @@ bool Map::INVARIANT() {
for(auto room : $rooms) { for(auto room : $rooms) {
check(int(room.x) >= 0 && int(room.y) >= 0, check(int(room.x) >= 0 && int(room.y) >= 0,
format("room depth={} has invalid position {},{}", format("room invalid position {},{}",
room.depth, room.x, room.y)); room.x, room.y));
check(int(room.width) > 0 && int(room.height) > 0, check(int(room.width) > 0 && int(room.height) > 0,
format("room depth={} has invalid dims {},{}", format("room has invalid dims {},{}",
room.depth, room.width, room.height)); room.width, room.height));
} }
return true; return true;

@ -16,13 +16,12 @@
using lighting::LightSource; using lighting::LightSource;
struct Room { struct Room {
int depth;
size_t x = 0; size_t x = 0;
size_t y = 0; size_t y = 0;
size_t width = 0; size_t width = 0;
size_t height = 0; size_t height = 0;
Point entry; Point entry{(size_t)-1, (size_t)-1};
Point exit; Point exit{(size_t)-1, (size_t)-1};
DEFINE_SERIALIZABLE(Room, x, y, width, height); DEFINE_SERIALIZABLE(Room, x, y, width, height);
}; };

@ -9,33 +9,38 @@ ftxui_dom = dependency('ftxui-dom')
ftxui_component = dependency('ftxui-component') ftxui_component = dependency('ftxui-component')
sfml = dependency('sfml') sfml = dependency('sfml')
freetype2 = dependency('freetype2') freetype2 = dependency('freetype2')
thread_dep = dependency('threads')
dependencies = [ dependencies = [
fmt, ftxui_screen, ftxui_dom, fmt, ftxui_screen, ftxui_dom,
ftxui_component, json, ftxui_component, json,
sfml, freetype2 sfml, freetype2, thread_dep
] ]
runtests = executable('runtests', [ source=[
'matrix.cpp',
'dbc.cpp', 'dbc.cpp',
'matrix.cpp',
'tilemap.cpp', 'tilemap.cpp',
'map.cpp', 'map.cpp',
'gui.cpp',
'rand.cpp', 'rand.cpp',
'sound.cpp', 'sound.cpp',
'combat.cpp',
'spatialmap.cpp', 'spatialmap.cpp',
'combat.cpp',
'systems.cpp',
'ansi_parser.cpp', 'ansi_parser.cpp',
'render.cpp',
'config.cpp', 'config.cpp',
'save.cpp', 'save.cpp',
'panel.cpp', 'panel.cpp',
'render.cpp',
'pathing.cpp', 'pathing.cpp',
'lights.cpp', 'lights.cpp',
'systems.cpp',
'gui.cpp',
'worldbuilder.cpp', 'worldbuilder.cpp',
'inventory.cpp', 'inventory.cpp',
]
runtests = executable('runtests',
source + [
'tests/tilemap.cpp', 'tests/tilemap.cpp',
'tests/matrix.cpp', 'tests/matrix.cpp',
'tests/fsm.cpp', 'tests/fsm.cpp',
@ -55,31 +60,12 @@ runtests = executable('runtests', [
'tests/gui.cpp', 'tests/gui.cpp',
'tests/worldbuilder.cpp', 'tests/worldbuilder.cpp',
'tests/inventory.cpp', 'tests/inventory.cpp',
], ], cpp_args:['-Wextra','-Werror'],
dependencies: dependencies + catch2) dependencies: dependencies + catch2)
roguish = executable('roguish', [ roguish = executable('roguish',
'dbc.cpp', source + ['main.cpp'],
'matrix.cpp', cpp_args:['-Wextra','-Werror'],
'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',
],
dependencies: dependencies) dependencies: dependencies)
designer = executable('designer', [ designer = executable('designer', [
@ -93,7 +79,7 @@ designer = executable('designer', [
'pathing.cpp', 'pathing.cpp',
'lights.cpp', 'lights.cpp',
'tools/designer.cpp' 'tools/designer.cpp'
], ], cpp_args:['-Wextra','-Werror'],
dependencies: dependencies) dependencies: dependencies)
fontextract = executable('fontextract', [ fontextract = executable('fontextract', [

@ -0,0 +1,2 @@
rm -recurse -force .\builddir\runtests.exe*
rm -recurse -force .\builddir\roguish.exe*

@ -4,4 +4,13 @@ mkdir subprojects
mv .\packagecache .\subprojects\ mv .\packagecache .\subprojects\
mkdir builddir mkdir builddir
cp wraps\*.wrap subprojects\ 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 meson setup --default-library=static --prefer-static builddir

@ -1,5 +1,6 @@
TODAY'S GOAL: 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. * Goblins will be in the world and not move or are already dead.
* https://pkl-lang.org/ * https://pkl-lang.org/
* Check out https://github.com/stephenberry/glaze * Check out https://github.com/stephenberry/glaze

@ -16,16 +16,16 @@ using namespace components;
using ftxui::Color; using ftxui::Color;
using lighting::LightSource; 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(); light.reset_light();
world.query<Position, LightSource>([&](const auto &ent, auto &position, auto &lightsource) { world.query<Position>([&](const auto &ent[[maybe_unused]], auto &position) {
light.set_light_target(position.location); light.set_light_target(position.location);
}); });
light.path_light(game_map.walls()); light.path_light(game_map.walls());
world.query<Position, LightSource>([&](const auto &ent, auto &position, auto &lightsource) { world.query<Position, LightSource>([&](const auto &ent[[maybe_unused]], auto &position, auto &lightsource) {
light.render_light(lightsource, position.location); light.render_light(lightsource, position.location);
}); });
} }
@ -62,7 +62,7 @@ void System::init_positions(DinkyECS::World &world) {
} }
}); });
world.query<Position, InventoryItem>([&](const auto &ent, auto &pos, auto &item) { world.query<Position>([&](const auto &ent, auto &pos) {
collider.insert(pos.location, ent); 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) { 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(); auto &tiles = game_map.tiles();
world.query<Position, Tile>([&](const auto &ent, auto &pos, auto &tile) { world.query<Position, Tile>([&](auto &ent[[maybe_unused]], auto &pos, auto &tile) {
if(pos.location.x >= cam_orig.x && pos.location.x <= cam_orig.x + view_x 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) { && 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); Point loc = game_map.map_to_camera(pos.location, cam_orig);

@ -9,7 +9,7 @@ namespace System {
using namespace components; using namespace components;
using namespace lighting; 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 motion(DinkyECS::World &world, Map &game_map);
void collision(DinkyECS::World &world, Player &player); void collision(DinkyECS::World &world, Player &player);
void death(DinkyECS::World &world); void death(DinkyECS::World &world);

@ -66,8 +66,7 @@ TEST_CASE("test out ragel parser", "[gui]") {
std::wstring colors_utf = $converter.from_bytes(colors); std::wstring colors_utf = $converter.from_bytes(colors);
bool good = ansi.parse(colors_utf, bool good = ansi.parse(colors_utf,
[&](sf::Color color, sf::Color bgcolor){ [&](sf::Color color[[maybe_unused]], sf::Color bgcolor[[maybe_unused]]){
// ignore color
}, },
[&](wchar_t ch) { [&](wchar_t ch) {
bool correct_char = ch == '#' || ch == ' ' || ch == '\n' || ch == '\r'; bool correct_char = ch == '#' || ch == ' ' || ch == '\n' || ch == '\r';

@ -119,8 +119,14 @@ TEST_CASE("confirm ECS system works", "[ecs]") {
println("--- After remove test, should only result in test2:"); println("--- After remove test, should only result in test2:");
world.query<Position, Velocity>([&](const auto &ent, auto &pos, auto &vel) { world.query<Position, Velocity>([&](const auto &ent, auto &pos, auto &vel) {
auto &in_position = world.get<Position>(ent);
auto &in_velocity = world.get<Velocity>(ent);
REQUIRE(pos.x >= 0); REQUIRE(pos.x >= 0);
REQUIRE(pos.y >= 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);
}); });
} }

@ -25,7 +25,7 @@ public:
} }
void START(MyEvent ev) { void START(MyEvent ev) {
println("<<< START"); println("<<< START {}", (int)ev);
state(MyState::RUNNING); state(MyState::RUNNING);
} }
@ -40,7 +40,7 @@ public:
} }
void END(MyEvent ev) { void END(MyEvent ev) {
println("<<< STOP"); println("<<< STOP {}", (int)ev);
state(MyState::END); state(MyState::END);
} }
}; };

@ -17,10 +17,10 @@ void test_ansi_parsing(Panel &panel) {
ANSIParser ansi(default_fg, default_bg); ANSIParser ansi(default_fg, default_bg);
bool good = ansi.parse(panel.to_string(), 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 // ignore color
}, },
[&](wchar_t ch) { [&](wchar_t ch[[maybe_unused]]) {
// ignore char // ignore char
}); });

@ -11,12 +11,12 @@
struct TileCell { struct TileCell {
std::string display; std::string display;
uint8_t fg_h; uint8_t fg_h = 0;
uint8_t fg_s; uint8_t fg_s = 0;
uint8_t fg_v; uint8_t fg_v = 0;
uint8_t bg_h; uint8_t bg_h = 0;
uint8_t bg_s; uint8_t bg_s = 0;
uint8_t bg_v; uint8_t bg_v = 0;
}; };
typedef std::vector<TileCell> TileRow; typedef std::vector<TileCell> TileRow;

@ -118,9 +118,9 @@ struct WhatTheColor {
int h; int h;
int s; int s;
int v; int v;
Component h_slider; Component h_slider = nullptr;
Component s_slider; Component s_slider = nullptr;
Component v_slider; Component v_slider = nullptr;
}; };
class GUI { class GUI {

@ -82,13 +82,11 @@ void WorldBuilder::partition_map(Room &cur, int depth) {
// BUG: min room size should be configurable // BUG: min room size should be configurable
if(depth > 0 && left.width > 2 && left.height > 2) { if(depth > 0 && left.width > 2 && left.height > 2) {
left.depth = depth - 1;
partition_map(left, depth-1); partition_map(left, depth-1);
} }
// BUG: min room size should be configurable // BUG: min room size should be configurable
if(depth > 0 && right.width > 2 && right.height > 2) { if(depth > 0 && right.width > 2 && right.height > 2) {
right.depth = depth - 1;
partition_map(right, 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; bool found = false;
Matrix &paths = map.paths(); Matrix &paths = map.paths();
Point out{src.x, src.y}; 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, dbc::check(paths[target.y][target.x] != WALL_PATH_LIMIT,
"target room has path as a wall"); "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); straight_path(holes, src, target);
} }

Loading…
Cancel
Save