10#include <DTL/Base/RogueLike.hpp>
11#include <DTL/Random/RandomEngine.hpp>
12#include <DTL/Shape/CellularAutomatonIsland.hpp>
13#include <DTL/Shape/MazeDig.hpp>
14#include <DTL/Shape/PerlinIsland.hpp>
15#include <DTL/Shape/SimpleRogueLike.hpp>
25 DTL_RANDOM_ENGINE.seed(
seed);
26 DTL_RANDOM_ENGINE.clear();
30 std::uint_fast8_t fill = 0) {
31 return std::vector<std::vector<std::uint_fast8_t>>(
32 size_t(
height), std::vector<std::uint_fast8_t>(
size_t(
width), fill));
37 const std::function<uint32_t(std::uint_fast8_t)> &mapValue) {
38 const int h = int(matrix.size());
39 const int w =
h > 0 ? int(matrix[0].size()) : 0;
41 for (
int y = 0;
y <
h; ++
y) {
42 for (
int x = 0;
x <
w; ++
x) {
43 grid.
setCell(
x,
y, mapValue(matrix[
size_t(
y)][
size_t(
x)]));
50 std::vector<std::pair<int, int>> walkable;
54 const uint32_t
c = uint32_t(grid.
getCell(
x,
y));
57 walkable.emplace_back(
x,
y);
61 if (walkable.empty())
return;
63 auto pick = [&](uint32_t salt) -> std::pair<int, int> {
64 const uint32_t
idx = (
seed * 1664525u + salt * 1013904223u) % uint32_t(walkable.size());
69 if (
a ==
b && walkable.size() > 1)
b = walkable[(size_t(
seed) + 1) % walkable.size()];
72 grid.
addObjectAt(
"spawn",
"spawn",
float(
a.first), float(
a.second));
73 grid.
addObjectAt(
"stairs",
"stairs",
float(
b.first), float(
b.second));
Intermediate 2D generation result. cells store semantic ids (see Semantic.h), not tile GIDs — convert...
void resize(int width, int height)
void setCell(int x, int y, int semantic)
int getCell(int x, int y) const
void addObjectAt(const std::string &name, const std::string &type, float x, float y)
Script-friendly: name/type + tile coords.
constexpr uint32_t Corridor
void copyMatrixToGrid(const std::vector< std::vector< std::uint_fast8_t > > &matrix, Grid2D &grid, const std::function< uint32_t(std::uint_fast8_t)> &mapValue)
void placeSpawnAndStairs(Grid2D &grid, uint32_t seed)
Place spawn + stairs on walkable cells (floor/corridor/grass/dirt/sand).
void seedEngine(uint32_t seed)
std::vector< std::vector< std::uint_fast8_t > > makeMatrix(int width, int height, std::uint_fast8_t fill=0)