2022-04-22 01:15:40 +02:00
|
|
|
#ifndef TILING_WAVE_FORM_COLLAPSE_H
|
|
|
|
#define TILING_WAVE_FORM_COLLAPSE_H
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-22 01:15:40 +02:00
|
|
|
#include "array_2d.h"
|
2022-04-21 16:31:03 +02:00
|
|
|
#include "core/vector.h"
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-22 01:15:40 +02:00
|
|
|
#include "wave_form_collapse.h"
|
2022-04-20 03:05:34 +02:00
|
|
|
|
|
|
|
struct Tile {
|
2022-04-22 01:15:40 +02:00
|
|
|
enum Symmetry {
|
2022-04-22 01:55:53 +02:00
|
|
|
SYMMETRY_X = 0,
|
2022-04-22 01:15:40 +02:00
|
|
|
SYMMETRY_T,
|
|
|
|
SYMMETRY_I,
|
|
|
|
SYMMETRY_L,
|
|
|
|
SYMMETRY_BACKSLASH,
|
|
|
|
SYMMETRY_P
|
|
|
|
};
|
|
|
|
|
2022-04-22 01:55:53 +02:00
|
|
|
struct ActionMap {
|
|
|
|
Vector<uint32_t> map[8];
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-22 01:55:53 +02:00
|
|
|
void set_size(int size) {
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
map[i].resize(size);
|
2022-04-20 03:05:34 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-22 01:55:53 +02:00
|
|
|
};
|
2022-04-22 01:15:40 +02:00
|
|
|
|
2022-04-22 01:55:53 +02:00
|
|
|
static const uint8_t rotation_map[6][9];
|
|
|
|
static const uint8_t reflection_map[6][9];
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-22 01:55:53 +02:00
|
|
|
Vector<Array2D<uint32_t>> data;
|
|
|
|
Symmetry symmetry;
|
|
|
|
double weight;
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-22 01:55:53 +02:00
|
|
|
static ActionMap generate_action_map(const Symmetry &symmetry);
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-22 01:55:53 +02:00
|
|
|
static Vector<Array2D<uint32_t>> generate_oriented(Array2D<uint32_t> data, Symmetry symmetry);
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-22 01:55:53 +02:00
|
|
|
Tile(const Vector<Array2D<uint32_t>> &p_data, Symmetry p_symmetry, double p_weight);
|
|
|
|
Tile(const Array2D<uint32_t> &p_data, Symmetry p_symmetry, double p_weight);
|
2022-04-20 03:05:34 +02:00
|
|
|
};
|
|
|
|
|
2022-04-22 18:54:59 +02:00
|
|
|
class TilingWaveFormCollapse : public WaveFormCollapse {
|
2022-04-22 01:55:53 +02:00
|
|
|
GDCLASS(TilingWaveFormCollapse, WaveFormCollapse);
|
|
|
|
|
|
|
|
public:
|
2022-04-22 01:15:40 +02:00
|
|
|
struct NeighbourData {
|
|
|
|
uint32_t data[4];
|
|
|
|
|
|
|
|
NeighbourData() {
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
2022-04-22 01:55:53 +02:00
|
|
|
data[i] = 0;
|
2022-04-22 01:15:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-04-21 17:05:26 +02:00
|
|
|
struct DensePropagatorHelper {
|
|
|
|
Vector<bool> directions[4];
|
|
|
|
|
|
|
|
void resize(const int size) {
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
directions[i].resize(size);
|
|
|
|
directions[i].fill(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-04-22 02:35:38 +02:00
|
|
|
struct IdToTilePair {
|
|
|
|
uint32_t id;
|
|
|
|
uint32_t oriented_tile;
|
|
|
|
|
|
|
|
IdToTilePair() {
|
|
|
|
id = 0;
|
|
|
|
oriented_tile = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
IdToTilePair(uint32_t p_id, uint32_t p_oriented_tile) {
|
|
|
|
id = p_id;
|
|
|
|
oriented_tile = p_oriented_tile;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_tiles(const Vector<Tile> &p_tiles);
|
|
|
|
void set_neighbours(const Vector<NeighbourData> &p_neighbors);
|
|
|
|
|
|
|
|
void generate_oriented_tile_ids();
|
|
|
|
|
|
|
|
void generate_propagator();
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-22 01:55:53 +02:00
|
|
|
static Vector<double> get_tiles_weights(const Vector<Tile> &tiles);
|
2022-04-21 16:31:03 +02:00
|
|
|
|
2022-04-22 02:35:38 +02:00
|
|
|
void set_tile(uint32_t tile_id, uint32_t i, uint32_t j);
|
|
|
|
bool set_tile(uint32_t tile_id, uint32_t orientation, uint32_t i, uint32_t j);
|
|
|
|
|
|
|
|
Array2D<uint32_t> do_run();
|
|
|
|
|
2022-04-22 01:55:53 +02:00
|
|
|
Array2D<uint32_t> id_to_tiling(Array2D<uint32_t> ids);
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-22 02:35:38 +02:00
|
|
|
void initialize();
|
|
|
|
|
|
|
|
TilingWaveFormCollapse();
|
|
|
|
~TilingWaveFormCollapse();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void generate_propagator_add_helper(Tile::ActionMap *action_map1, Tile::ActionMap *action_map2,
|
|
|
|
Vector<DensePropagatorHelper> *dense_propagator,
|
|
|
|
const NeighbourData &neighbour,
|
|
|
|
uint32_t action, uint32_t direction);
|
|
|
|
|
2022-04-22 01:55:53 +02:00
|
|
|
Vector<Tile> tiles;
|
2022-04-22 02:35:38 +02:00
|
|
|
Vector<NeighbourData> neighbors;
|
2022-04-21 14:28:04 +02:00
|
|
|
|
2022-04-22 02:35:38 +02:00
|
|
|
Vector<IdToTilePair> id_to_oriented_tile;
|
|
|
|
Vector<Vector<uint32_t>> oriented_tile_ids;
|
2022-04-20 03:05:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FAST_WFC_TILING_WFC_HPP_
|