Skip to content

Commit

Permalink
switch away from the "support"
Browse files Browse the repository at this point in the history
  • Loading branch information
fl4shk committed Nov 17, 2022
1 parent 95ea37b commit 5a26148
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 64 deletions.
23 changes: 23 additions & 0 deletions dungeon_simple.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

############# #########
#...........# #.......#
#.....................#.......#
#...........# . #.......#
#...........# . #####.###
#...........# . .
####.######## . .
. . .
. . .
. . .
.............. .
. .
. .
. .
. ######.#####
####.###### #..........#
#.........# #..........#
#...............................#
#.........# #..........#
#.........# #..........#
########### ############

23 changes: 23 additions & 0 deletions dungeon_simple_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

################### #########
#.................# #.......#
#.................#...#.......#
#.................# #.......#
#.................# #####.###
#.................# .
####.#########.#### .
. . .
. . .
. . .
........... .
. .
. .
. .
. ######.#####
####.###### #..........#
#.........# #..........#
#...............................#
#.........# #..........#
#.........# #..........#
########### ############

13 changes: 0 additions & 13 deletions dungeon_small.txt

This file was deleted.

11 changes: 11 additions & 0 deletions mountain_range_small.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
......................
......................
......................
.....&&&&&&&&&&&&&&&&.
....&& &&
....& ^^^^^^ &
....& ^^^^^^^ &
....& ^^^ &
....& ^^ &
....&& &&
.....&&&&&&&&&&&&&&&&.
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ int main(int argc, char** argv) {
static constexpr size_t
MIN_OUTPUT_DIM = 1,
MAX_OUTPUT_DIM
//= 32;
= 64;
= 32;
//= 64;

Vec2<size_t> size_2d;
inv_sconcat(ap.at("-w", 0).val, size_2d.x);
Expand Down
113 changes: 71 additions & 42 deletions src/wfc_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,48 +30,68 @@ void PotElem::_set(
Potential& potential, const Vec2<size_t>& pos, size_t ti, bool val
) {
PotElem& self = potential.at(pos.y).at(pos.x);
const bool did_contain = self.contains(ti);
//const bool did_contain = self.contains(ti);
self.domain.at(ti) = val;

const std::vector<Neighbor>& neighbors(calc_neighbors
(Vec2<size_t>(potential.front().size(), potential.size()), pos));
for (const Neighbor& nb: neighbors) {
PotElem& nb_pe = potential.at(nb.pos.y).at(nb.pos.x);
auto
& self_support
= self.support_da2d.at(size_t(nb.d)).at(ti),
& nb_support
= nb_pe.support_da2d.at(size_t(reverse(nb.d))).at(ti);
if (val && !did_contain) {
++self_support;
++nb_support;
} else if (!val && did_contain) {
--self_support;
--nb_support;
}
if (self_support == 0) {
self.domain.at(ti) = false;
} //else {
// self.domain.at(ti) = true;
//}
if (nb_support == 0) {
nb_pe.domain.at(ti) = false;
} //else {
// nb_pe.domain.at(ti) = true;
//}
//if (val && !did_contain) {
// ++self_support;
// //++nb_support;
//} else if (!val && did_contain) {
// --self_support;
// //--nb_support;
//}
//if (did_contain && self_support == 0) {
// self.domain.at(ti) = false;
//} else if (!did_contain && self_support > 0) {
// self.domain.at(ti) = true;
//}
}
//const std::vector<Neighbor>& neighbors(calc_neighbors
// (Vec2<size_t>(potential.front().size(), potential.size()), pos));
//for (const Neighbor& nb: neighbors) {
// PotElem& nb_pe = potential.at(nb.pos.y).at(nb.pos.x);
// auto
// & self_support
// = self.support_da2d.at(size_t(nb.d)).at(ti),
// & nb_support
// = nb_pe.support_da2d.at(size_t(reverse(nb.d))).at(ti);
// if (val && !did_contain) {
// ++self_support;
// ++nb_support;
// } else if (!val && did_contain) {
// --self_support;
// --nb_support;
// //printout("!val && did_contain: ",
// // ti, "; ",
// // pos, " ", nb.pos, "; ",
// // self_support, " ", nb_support,
// // "\n");
// //if (self_support == 0) {
// // //printout("self_support == 0\n");
// // self.domain.at(ti) = false;
// //} //else {
// //// self.domain.at(ti) = true;
// ////}
// //if (nb_support == 0) {
// // //printout("nb_support == 0\n");
// // nb_pe.domain.at(ti) = false;
// //} //else {
// //// nb_pe.domain.at(ti) = true;
// ////}
// }
// if (self_support == 0) {
// //printout("self_support == 0\n");
// self.domain.at(ti) = false;
// } else {
// self.domain.at(ti) = true;
// }
// if (nb_support == 0) {
// //printout("nb_support == 0\n");
// nb_pe.domain.at(ti) = false;
// } else {
// nb_pe.domain.at(ti) = true;
// }

// //if (val && !did_contain) {
// // ++self_support;
// // //++nb_support;
// //} else if (!val && did_contain) {
// // --self_support;
// // //--nb_support;
// //}
// //if (did_contain && self_support == 0) {
// // self.domain.at(ti) = false;
// //} else if (!did_contain && self_support > 0) {
// // self.domain.at(ti) = true;
// //}
//}
}
//--------
Wfc::Wfc() {}
Expand Down Expand Up @@ -585,6 +605,7 @@ void Wfc::gen() {
//printout("failed `_propagate()`: ",
// _baktk_stk.size(),
// "\n");
//_dbg_print(to_push.potential);
//#endif // DEBUG
if (backtrack()) {
//need_pop = true;
Expand Down Expand Up @@ -1189,20 +1210,28 @@ void Wfc::_add_constraint(

//return changed;
}
void Wfc::_dbg_print(const BaktkStkItem& bts_item) const {
void Wfc::_dbg_print(const Potential& potential) const {
Vec2<size_t> pos;
for (pos.y=0; pos.y<size_2d().y; ++pos.y) {
//printout(pos.y, ": ");
for (pos.x=0; pos.x<size_2d().x; ++pos.x) {
//printout(pos, "\n");
//printout(bts_item.potential.size());
//if (bts_item.potential.size() > 0) {
// printout(" ", bts_item.potential.front().size());
//}
//printout("\n");
const PotElem& pot_elem
= bts_item.potential.at(pos.y).at(pos.x);
= potential.at(pos.y).at(pos.x);
//if (pot_elem.size() == 1)
if (pot_elem.num_active() == 1) {
//printout("pot_elem.num_active() == 1\n");
//printout(static_cast<char>
// (mt_darr().at(*pot_elem.begin()).tl_corner()));
printout(static_cast<char>
(mt_darr().at(*pot_elem.first_set()).tl_corner()));
} else {
//printout("pot_elem.num_active() != 1\n");
//printout(pot_elem.size());
if (pot_elem.num_active() <= 9) {
printout(pot_elem.num_active());
Expand Down
14 changes: 7 additions & 7 deletions src/wfc_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace wfc {
// Sea = 'S',
// //Mountain = 'M',
//};
using TileUset = std::unordered_set<size_t>;
//using TileUset = std::unordered_set<size_t>;

class PotElem;

Expand All @@ -36,19 +36,19 @@ std::vector<Neighbor> calc_neighbors(
//--------
class PotElem final {
public: // types
using SupportDa2d = std::vector<std::vector<size_t>>;
using SupportDa2d = std::vector<std::vector<u16>>;
public: // variables
//std::unordered_set<size_t> data;
//std::vector<std::optional<std::string>> data;
std::vector<bool> domain;
SupportDa2d support_da2d;
//SupportDa2d support_da2d;
//std::unordered_map<Dir, std::vector<size_t>> support_umap;
public: // functions
inline PotElem() = default;
inline PotElem(size_t size) {
domain = std::vector<bool>(size, true);
support_da2d = SupportDa2d(size_t(Dir::Lim),
std::vector<size_t>(size, size));
//support_da2d = SupportDa2d(size_t(Dir::Lim),
// std::vector<size_t>(size, size));
}
GEN_CM_BOTH_CONSTRUCTORS_AND_ASSIGN(PotElem);
inline ~PotElem() = default;
Expand Down Expand Up @@ -408,9 +408,9 @@ class Wfc final {
return calc_neighbors(size_2d(), pos);
}
//--------
void _dbg_print(const BaktkStkItem& bts_item) const;
void _dbg_print(const Potential& potential) const;
inline void _dbg_print() const {
_dbg_print(_baktk_stk.top());
_dbg_print(_baktk_stk.top().potential);
}
//--------
};
Expand Down

0 comments on commit 5a26148

Please sign in to comment.