mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-23 20:36:53 +01:00
Got rid of std::touples in the wfc module.
This commit is contained in:
parent
bb723e3c44
commit
2680c89948
@ -7,7 +7,6 @@ void Propagator::init_compatible() {
|
||||
for (uint32_t y = 0; y < wave_height; y++) {
|
||||
for (uint32_t x = 0; x < wave_width; x++) {
|
||||
for (uint32_t pattern = 0; pattern < patterns_size; pattern++) {
|
||||
|
||||
for (int direction = 0; direction < 4; direction++) {
|
||||
value.direction[direction] = static_cast<uint32_t>(propagator_state[pattern].directions[get_opposite_direction(direction)].size());
|
||||
}
|
||||
@ -22,8 +21,13 @@ void Propagator::propagate(Wave &wave) {
|
||||
// We propagate every element while there is element to propagate.
|
||||
while (propagating.size() != 0) {
|
||||
// The cell and pattern that has been set to false.
|
||||
uint32_t y1, x1, pattern;
|
||||
std::tie(y1, x1, pattern) = propagating[propagating.size() - 1];
|
||||
|
||||
const PropagatingEntry &e = propagating[propagating.size() - 1];
|
||||
|
||||
uint32_t y1 = e.data[0];
|
||||
uint32_t x1 = e.data[1];
|
||||
uint32_t pattern = e.data[2];
|
||||
|
||||
propagating.resize(propagating.size() - 1);
|
||||
|
||||
// We propagate the information in all 4 directions.
|
||||
@ -38,9 +42,11 @@ void Propagator::propagate(Wave &wave) {
|
||||
} else {
|
||||
x2 = x1 + dx;
|
||||
y2 = y1 + dy;
|
||||
|
||||
if (x2 < 0 || x2 >= (int)wave.width) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (y2 < 0 || y2 >= (int)wave.height) {
|
||||
continue;
|
||||
}
|
||||
@ -54,19 +60,19 @@ void Propagator::propagate(Wave &wave) {
|
||||
// contradiction with pattern1
|
||||
int size = patterns.size();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
uint32_t pattern = patterns[i];
|
||||
|
||||
uint32_t pattern_entry = patterns[i];
|
||||
|
||||
// We decrease the number of compatible patterns in the opposite
|
||||
// direction If the pattern was discarded from the wave, the element
|
||||
// is still negative, which is not a problem
|
||||
CompatibilityEntry &value = compatible.get(y2, x2, pattern);
|
||||
CompatibilityEntry &value = compatible.get(y2, x2, pattern_entry);
|
||||
value.direction[direction]--;
|
||||
|
||||
// If the element was set to 0 with this operation, we need to remove
|
||||
// the pattern from the wave, and propagate the information
|
||||
if (value.direction[direction] == 0) {
|
||||
add_to_propagator(y2, x2, pattern);
|
||||
wave.set(i2, pattern, false);
|
||||
add_to_propagator(y2, x2, pattern_entry);
|
||||
wave.set(i2, pattern_entry, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "array_3d.h"
|
||||
#include "core/vector.h"
|
||||
#include "direction.h"
|
||||
#include <tuple>
|
||||
|
||||
class Wave;
|
||||
|
||||
@ -26,10 +25,26 @@ private:
|
||||
|
||||
const bool periodic_output;
|
||||
|
||||
struct PropagatingEntry {
|
||||
uint32_t data[3];
|
||||
|
||||
PropagatingEntry() {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
data[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
PropagatingEntry(uint32_t x, uint32_t y, uint32_t z) {
|
||||
data[0] = x;
|
||||
data[1] = y;
|
||||
data[2] = z;
|
||||
}
|
||||
};
|
||||
|
||||
// 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.
|
||||
Vector<std::tuple<uint32_t, uint32_t, uint32_t>> propagating;
|
||||
Vector<PropagatingEntry> propagating;
|
||||
|
||||
struct CompatibilityEntry {
|
||||
int direction[4];
|
||||
@ -67,7 +82,7 @@ public:
|
||||
CompatibilityEntry temp;
|
||||
compatible.get(y, x, pattern) = temp;
|
||||
|
||||
propagating.push_back(std::tuple<uint32_t, uint32_t, uint32_t>(y, x, pattern));
|
||||
propagating.push_back(PropagatingEntry(y, x, pattern));
|
||||
}
|
||||
|
||||
void propagate(Wave &wave);
|
||||
|
@ -212,11 +212,10 @@ private:
|
||||
|
||||
// Generate the propagator which will be used in the wfc algorithm.
|
||||
static Vector<PropagatorEntry> generate_propagator(
|
||||
const Vector<std::tuple<uint32_t, uint32_t, uint32_t, uint32_t>> &neighbors,
|
||||
const Vector<NeighbourData> &neighbors,
|
||||
Vector<Tile<T>> tiles,
|
||||
Vector<std::pair<uint32_t, uint32_t>> id_to_oriented_tile,
|
||||
Vector<Vector<uint32_t>> oriented_tile_ids) {
|
||||
|
||||
size_t nb_oriented_tiles = id_to_oriented_tile.size();
|
||||
Vector<DensePropagatorHelper> dense_propagator(nb_oriented_tiles, { Vector<bool>(nb_oriented_tiles, false), Vector<bool>(nb_oriented_tiles, false), Vector<bool>(nb_oriented_tiles, false), Vector<bool>(nb_oriented_tiles, false) });
|
||||
dense_propagator.resize(nb_oriented_tiles);
|
||||
@ -311,11 +310,20 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
struct NeighbourData {
|
||||
uint32_t data[4];
|
||||
|
||||
NeighbourData() {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
direction[i] = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Construct the TilingWFC class to generate a tiled image.
|
||||
TilingWFC(
|
||||
const Vector<Tile<T>> &tiles,
|
||||
const Vector<std::tuple<uint32_t, uint32_t, uint32_t, uint32_t>>
|
||||
&neighbors,
|
||||
const Vector<NeighbourData> &neighbors,
|
||||
const uint32_t height, const uint32_t width,
|
||||
const TilingWFCOptions &options, int seed) :
|
||||
tiles(tiles),
|
||||
|
Loading…
Reference in New Issue
Block a user