Started working on a random flood function for paths to do things like fill rooms with stuff.

main
Zed A. Shaw 1 week ago
parent e863bfa2fe
commit ee1e2e5bc5
  1. 17
      pathing.cpp
  2. 3
      pathing.hpp
  3. 16
      status.txt
  4. 2
      systems.cpp
  5. 18
      tests/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<void(Point at, int dnum)> 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;

@ -1,6 +1,8 @@
#pragma once
#include "point.hpp"
#include "matrix.hpp"
#include <functional>
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<void(Point at, int dnum)> cb);
bool INVARIANT();
};

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

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

@ -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);
});
}

Loading…
Cancel
Save