2022-04-20 03:05:34 +02:00
|
|
|
#ifndef FAST_WFC_PROPAGATOR_HPP_
|
|
|
|
#define FAST_WFC_PROPAGATOR_HPP_
|
|
|
|
|
|
|
|
#include "array_3d.h"
|
2022-04-20 03:24:50 +02:00
|
|
|
#include "direction.h"
|
2022-04-20 03:05:34 +02:00
|
|
|
#include <array>
|
|
|
|
#include <tuple>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class Wave;
|
|
|
|
|
|
|
|
class Propagator {
|
|
|
|
public:
|
|
|
|
using PropagatorState = std::vector<std::array<std::vector<unsigned>, 4>>;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::size_t patterns_size;
|
|
|
|
|
|
|
|
PropagatorState propagator_state;
|
|
|
|
|
|
|
|
const unsigned wave_width;
|
|
|
|
const unsigned wave_height;
|
|
|
|
|
|
|
|
const bool periodic_output;
|
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
// All the tuples (y, x, pattern) that should be propagated.
|
|
|
|
// The tuple should be propagated when wave.get(y, x, pattern) is set to
|
|
|
|
// false.
|
2022-04-20 03:05:34 +02:00
|
|
|
std::vector<std::tuple<unsigned, unsigned, unsigned>> propagating;
|
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
// compatible.get(y, x, pattern)[direction] contains the number of patterns
|
|
|
|
// present in the wave that can be placed in the cell next to (y,x) in the
|
|
|
|
// opposite direction of direction without being in contradiction with pattern
|
|
|
|
// placed in (y,x). If wave.get(y, x, pattern) is set to false, then
|
|
|
|
// compatible.get(y, x, pattern) has every element negative or null
|
2022-04-20 03:05:34 +02:00
|
|
|
Array3D<std::array<int, 4>> compatible;
|
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
void init_compatible();
|
2022-04-20 03:05:34 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
Propagator(unsigned wave_height, unsigned wave_width, bool periodic_output,
|
2022-04-20 03:24:50 +02:00
|
|
|
PropagatorState propagator_state) :
|
2022-04-20 03:05:34 +02:00
|
|
|
patterns_size(propagator_state.size()),
|
|
|
|
propagator_state(propagator_state),
|
|
|
|
wave_width(wave_width),
|
|
|
|
wave_height(wave_height),
|
|
|
|
periodic_output(periodic_output),
|
|
|
|
compatible(wave_height, wave_width, patterns_size) {
|
|
|
|
init_compatible();
|
|
|
|
}
|
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
void add_to_propagator(unsigned y, unsigned x, unsigned pattern) {
|
2022-04-20 03:05:34 +02:00
|
|
|
// All the direction are set to 0, since the pattern cannot be set in (y,x).
|
|
|
|
std::array<int, 4> temp = {};
|
|
|
|
compatible.get(y, x, pattern) = temp;
|
|
|
|
propagating.emplace_back(y, x, pattern);
|
|
|
|
}
|
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
void propagate(Wave &wave);
|
2022-04-20 03:05:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FAST_WFC_PROPAGATOR_HPP_
|