From ee1e2e5bc5cdde8984da558ebcbd4d44756ad242 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Thu, 12 Dec 2024 11:38:38 -0500 Subject: [PATCH] Started working on a random flood function for paths to do things like fill rooms with stuff. --- pathing.cpp | 17 +++++++++++++++++ pathing.hpp | 3 +++ status.txt | 16 +++++++--------- systems.cpp | 2 +- tests/pathing.cpp | 18 ++++++++++++++++++ 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/pathing.cpp b/pathing.cpp index 9aae6b3..6de97b8 100644 --- a/pathing.cpp +++ b/pathing.cpp @@ -76,6 +76,23 @@ void Pathing::clear_target(const Point &at) { $input[at.y][at.x] = 1; } +void Pathing::random_flood(const Point from, std::function cb) { + int from_x = from.x; + int from_y = from.y; + int dnum = $paths[from.y][from.x]; + cb(from, dnum); + + for(int y = from_y - 1; y <= from_y + 1; y++) { + if(y < 0 || y >= int($height)) continue; + for(int x = from_x - 1; x <= from_x + 1; x++) { + if(x >= 0 && x <= int($width)) { + dnum = $paths[y][x]; + cb({size_t(x), size_t(y)}, dnum); + } + } + } +} + bool Pathing::INVARIANT() { using dbc::check; diff --git a/pathing.hpp b/pathing.hpp index 18c2110..45162f3 100644 --- a/pathing.hpp +++ b/pathing.hpp @@ -1,6 +1,8 @@ #pragma once #include "point.hpp" #include "matrix.hpp" +#include + class Pathing { public: @@ -22,6 +24,7 @@ public: Matrix &paths() { return $paths; } Matrix &input() { return $input; } int distance(Point to) { return $paths[to.y][to.x];} + void random_flood(const Point from, std::function cb); bool INVARIANT(); }; diff --git a/status.txt b/status.txt index 2b42a2a..616708e 100644 --- a/status.txt +++ b/status.txt @@ -1,24 +1,22 @@ TODAY'S GOAL: +* Light should flood using the dijkstra map rather than use a box. + -1. Learn std::initializer_list by using it. 0. \ua3fd causes the character immediately after to vanish. Make a test and solve it. 1. Why do Sliders only have to be kept around forever and can't go in containers like everything else? -2. Why are sliders not selected when I click on them? Is it a hover? -3. Why do fonts render blank? Also when I scroll they slowly disappear until there's a column. -* \u2738 is missing on the row when in grid but works when clicked. - -* A designer tool to help find characters for foreground, background, and figure out their colors. +* Make a for-loop generator thing, and figure out whatever this magic matrix-processing-without-for-loops tech is (that probably doesn't exist). -* renderer's mouse coordinates are totally wrong. Need to put glyph bounds into the panel and then you can ask if a mouse click is on a panel, and what the _panel's_ coordinates are. - -* Use a vector of strings with 1 char each again. +"you could make an iterator type that you create with the Matrix & a box - then it iterates though each row/column and updates its x/y values. More code over all but loops like you're doing now could be simpler" TODO: +* Hot key for debug view. + * Refine the event handling to pass most of them to the gui panels and then I can intercept them. -* Resolve fmt::format vs std::format. +* Resolve fmt::format vs std::format from hirdrac when using clang or gcc latest. * Fix " room should always be found" diff --git a/systems.cpp b/systems.cpp index 2203ef9..a8611be 100644 --- a/systems.cpp +++ b/systems.cpp @@ -10,7 +10,7 @@ #include "dbc.hpp" #include "lights.hpp" -const bool DEBUG_MAP=false; +const bool DEBUG_MAP=true; using std::string; using namespace fmt; diff --git a/tests/pathing.cpp b/tests/pathing.cpp index c4df3a4..62989be 100644 --- a/tests/pathing.cpp +++ b/tests/pathing.cpp @@ -35,3 +35,21 @@ TEST_CASE("dijkstra algo test", "[pathing]") { REQUIRE(pathing.$paths == expected); } } + +TEST_CASE("random flood", "[pathing]") { + json data = load_test_pathing("./tests/dijkstra.json"); + auto test = data[0]; + + Matrix expected = test["expected"]; + Matrix walls = test["walls"]; + + Pathing pathing(walls[0].size(), walls.size()); + pathing.$input = test["input"]; + + REQUIRE(pathing.INVARIANT()); + pathing.compute_paths(walls); + + pathing.random_flood({1, 2}, [&](Point at, int dnum) { + println("FLOOD: at={},{}, dnum={}", at.x, at.y, dnum); + }); +}