载入中...
搜索中...
未找到
RoguelikeGenerator.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <cmath>
4#include <cstdint>
5#include <limits>
6#include <random>
7#include <sstream>
8#include <string>
9#include <unordered_set>
10#include <vector>
12#include "procgen/Grid2D.h"
13#include "procgen/Params.h"
14#include "procgen/Semantic.h"
15
16// RoguelikeGenerator.cpp
17// RoguelikeGenerator �?a configurable, seed-driven room-and-corridor level
18// generator ("RoguelikeGenerator Pro" style). Unlike dungeon.bsp it layers
19// extra data on top of the wall/floor grid:
20// * `detail` (Grid2D) stores per-cell wall-autotile direction masks, floor
21// pattern variants and scattered decor tiles (see k* constants below).
22// * `objects` carry placed props (pillars / chests / grass tufts) and the
23// spawn / stairs markers.
24// Everything is driven by Params so scripts can re-roll with a different seed
25// or tweak generation rules without touching code. Generated cells use the
26// standard Semantic ids, so the result still applies to a TileLayer through
27// the usual palette pipeline.
28//
29// Register id: "level.roguelike"
30
31
32namespace eve::procgen {
33namespace {
34
35// ---- detail-layer encoding (documented; the script example consumes these) ----
36// Wall cells: detail = 8-bit neighbour mask (which directions are walkable).
37// Floor cells: detail = floor-pattern variant (1..kFloorMaxVariant), or
38// >= kDecorBase to mark a scattered decor tile.
39constexpr int kDecorBase = 100; // floor detail >= this => decor tile
40constexpr int kFloorMaxVariant = 32; // floor pattern variant cap
41
42// Neighbour direction bits used by the wall mask.
43constexpr int kE = 1 << 0; // +x
44constexpr int kS = 1 << 1; // +y
45constexpr int kW = 1 << 2; // -x
46constexpr int kN = 1 << 3; // -y
47constexpr int kSE = 1 << 4;
48constexpr int kSW = 1 << 5;
49constexpr int kNW = 1 << 6;
50constexpr int kNE = 1 << 7;
51
52bool isWalkable(uint32_t c) { return c == Semantic::Floor || c == Semantic::Corridor; }
53
54struct Rect {
55 int x = 0;
56 int y = 0;
57 int w = 0;
58 int h = 0;
59};
60
61int clampInt(int v, int lo, int hi) { return std::max(lo, std::min(hi, v)); }
62
63std::vector<std::string> assetPool(const Params &params, const std::string &role, const std::string &fallback) {
64 std::vector<std::string> result;
65 std::stringstream input(params.getString("assets." + role, fallback));
66 std::string item;
67 while (std::getline(input, item, ',')) {
68 const auto first = item.find_first_not_of(" \t");
69 const auto last = item.find_last_not_of(" \t");
70 if (first != std::string::npos) result.push_back(item.substr(first, last - first + 1));
71 }
72 return result;
73}
74
75std::string pickAsset(const std::vector<std::string> &pool, std::mt19937 &rng) {
76 if (pool.empty()) return {};
77 return pool[size_t(rng()) % pool.size()];
78}
79
81void autotileWalls(Grid2D &out) {
82 const int w = out.getWidth();
83 const int h = out.getHeight();
84 for (int y = 0; y < h; ++y) {
85 for (int x = 0; x < w; ++x) {
86 if (uint32_t(out.getCell(x, y)) != Semantic::Wall) continue;
87 int mask = 0;
88 if (x + 1 < w && isWalkable(uint32_t(out.getCell(x + 1, y)))) mask |= kE;
89 if (y + 1 < h && isWalkable(uint32_t(out.getCell(x, y + 1)))) mask |= kS;
90 if (x - 1 >= 0 && isWalkable(uint32_t(out.getCell(x - 1, y)))) mask |= kW;
91 if (y - 1 >= 0 && isWalkable(uint32_t(out.getCell(x, y - 1)))) mask |= kN;
92 if (x + 1 < w && y + 1 < h && isWalkable(uint32_t(out.getCell(x + 1, y + 1)))) mask |= kSE;
93 if (x - 1 >= 0 && y + 1 < h && isWalkable(uint32_t(out.getCell(x - 1, y + 1)))) mask |= kSW;
94 if (x - 1 >= 0 && y - 1 >= 0 && isWalkable(uint32_t(out.getCell(x - 1, y - 1)))) mask |= kNW;
95 if (x + 1 < w && y - 1 >= 0 && isWalkable(uint32_t(out.getCell(x + 1, y - 1)))) mask |= kNE;
96 out.setDetail(x, y, mask);
97 }
98 }
99}
100
102int floorVariant(int x, int y, const std::string &pattern, int variants, uint32_t salt) {
103 const int v = std::max(1, variants);
104 switch (pattern[0]) {
105 case 'c': // checker
106 return 1 + ((x + y) % v);
107 case 'p': // plank
108 return 1 + (y % v);
109 default: // brick / plain / cobble -> pseudo-random but stable per seed
110 return 1 + (int((x * 73856093u + y * 19349663u + salt) & 0x7FFFFFFFu) % v);
111 }
112}
113
114void carveRect(Grid2D &out, const Rect &r, uint32_t semantic) {
115 for (int y = r.y; y < r.y + r.h; ++y)
116 for (int x = r.x; x < r.x + r.w; ++x) out.setCell(x, y, int(semantic));
117}
118
119bool rectsOverlap(const Rect &a, const Rect &b, int pad) {
120 return a.x < b.x + b.w + pad && b.x < a.x + a.w + pad && a.y < b.y + b.h + pad && b.y < a.y + a.h + pad;
121}
122
123void carveCorridor(Grid2D &out, int ax, int ay, int bx, int by, int width, const std::string &style,
124 std::mt19937 &rng) {
125 auto carve = [&](int x, int y) {
126 if (uint32_t(out.getCell(x, y)) == Semantic::Wall) out.setCell(x, y, int(Semantic::Corridor));
127 };
128 if (style == "diagonal") {
129 int x = ax;
130 int y = ay;
131 while (x != bx || y != by) {
132 for (int oy = 0; oy < width; ++oy)
133 for (int ox = 0; ox < width; ++ox) carve(x + ox, y + oy);
134 if (x != bx && y != by && (rng() & 1u)) {
135 x += (bx > x) ? 1 : -1;
136 } else if (x != bx) {
137 x += (bx > x) ? 1 : -1;
138 } else {
139 y += (by > y) ? 1 : -1;
140 }
141 }
142 for (int oy = 0; oy < width; ++oy)
143 for (int ox = 0; ox < width; ++ox) carve(x + ox, y + oy);
144 return;
145 }
146
147 // L-shaped: horizontal then vertical (random bend for variety on "l").
148 int cornerX = bx;
149 int cornerY = ay;
150 if (style == "straight") {
151 // Force a straight line when aligned, otherwise keep the L.
152 } else if (rng() & 1u) {
153 cornerX = ax;
154 cornerY = by;
155 }
156
157 const int x0 = std::min(ax, bx);
158 const int x1 = std::max(ax, bx);
159 for (int x = x0; x <= x1; ++x)
160 for (int oy = 0; oy < width; ++oy) carve(x, cornerY + oy);
161
162 const int y0 = std::min(ay, by);
163 const int y1 = std::max(ay, by);
164 for (int y = y0; y <= y1; ++y)
165 for (int ox = 0; ox < width; ++ox) carve(cornerX + ox, y);
166}
167
168bool genRoguelike(const Params &params, Grid2D &out, std::string &error) {
169 const int w = params.getWidth();
170 const int h = params.getHeight();
171 if (w < 9 || h < 9) {
172 error = "level.roguelike: size must be at least 9x9";
173 return false;
174 }
175
176 const uint32_t seed = params.getSeed();
177 const int roomCount = clampInt(params.getInt("roomCount", 9), 1, 256);
178 const int roomMin = clampInt(params.getInt("roomMin", 4), 2, w);
179 const int roomMax = clampInt(params.getInt("roomMax", 8), roomMin, w);
180 const int padding = clampInt(params.getInt("padding", 1), 0, 4);
181 const int spacing = clampInt(params.getInt("spacing", 2), 0, 8);
182 const int clusterGapMin = clampInt(params.getInt("clusterGapMin", spacing + 1), 1, 8);
183 const int clusterGapMax = clampInt(params.getInt("clusterGapMax", spacing + 3), clusterGapMin, 12);
184 const int clusterBranchBias = clampInt(params.getInt("clusterBranchBias", 0), 0, 4);
185 const int corridorW = clampInt(params.getInt("corridorWidth", 1), 1, 3);
186 const int stairCount = clampInt(params.getInt("stairCount", 1), 0, 4);
187 const int stairSideMask = clampInt(params.getInt("stairSideMask", 15), 1, 15);
188 const std::string layout = params.getString("layoutStyle", "grid");
189 const std::string style = params.getString("corridorStyle", "l");
190 const std::string connections = params.getString("connectionStyle", "sequential");
191 const std::string pattern = params.getString("floorPattern", "brick");
192 const int variants = clampInt(params.getInt("floorVariants", 4), 1, kFloorMaxVariant);
193 const float decorDensity = std::clamp(params.getFloat("decorDensity", 0.05f), 0.f, 1.f);
194 const std::string decorSet = params.getString("decorSet", "mixed");
195 const bool doAutotile = params.getInt("autotile", 1) != 0;
196
197 out.resize(w, h);
198 out.fill(Semantic::Wall);
199
200 std::mt19937 rng(seed);
201
202 // 1) Place rooms on a coarse grid partition so they stay spread out, but
203 // allow jitter within each slot. Reject a slot if its room would overlap
204 // an earlier one (with spacing) or push outside the map.
205 const int cols = std::max(1, int(std::sqrt(double(roomCount))));
206 const int rows = std::max(1, (roomCount + cols - 1) / cols);
207 std::vector<Rect> rooms;
208 std::vector<size_t> roomParents;
209 std::uniform_int_distribution<int> dim(roomMin, roomMax);
210 std::uniform_int_distribution<int> jx(0, 0), jy(0, 0);
211
212 if (layout == "clustered") {
213 const int firstW = std::min(dim(rng), w - padding * 2);
214 const int firstH = std::min(dim(rng), h - padding * 2);
215 rooms.push_back({(w - firstW) / 2, (h - firstH) / 2, firstW, firstH});
216 roomParents.push_back(0);
217 std::uniform_int_distribution<int> jitter(-1, 1);
218 std::uniform_int_distribution<int> clusterGap(clusterGapMin, clusterGapMax);
219 const int maxAttempts = roomCount * 160;
220 for (int attempt = 0; attempt < maxAttempts && int(rooms.size()) < roomCount; ++attempt) {
221 size_t parentIndex = size_t(rng()) % rooms.size();
222 // Sampling additional candidates and keeping the oldest biases
223 // growth toward established hubs without prescribing a layout.
224 // Zero preserves uniform parent selection.
225 for (int sample = 0; sample < clusterBranchBias; ++sample)
226 parentIndex = std::min(parentIndex, size_t(rng()) % rooms.size());
227 const Rect &parent = rooms[parentIndex];
228 const int rw = std::min(dim(rng), w - padding * 2);
229 const int rh = std::min(dim(rng), h - padding * 2);
230 const int gap = clusterGap(rng);
231 Rect cand{0, 0, rw, rh};
232 switch (rng() % 4u) {
233 case 0: // east
234 cand.x = parent.x + parent.w + gap;
235 cand.y = parent.y + parent.h / 2 - rh / 2 + jitter(rng);
236 break;
237 case 1: // west
238 cand.x = parent.x - rw - gap;
239 cand.y = parent.y + parent.h / 2 - rh / 2 + jitter(rng);
240 break;
241 case 2: // south
242 cand.x = parent.x + parent.w / 2 - rw / 2 + jitter(rng);
243 cand.y = parent.y + parent.h + gap;
244 break;
245 default: // north
246 cand.x = parent.x + parent.w / 2 - rw / 2 + jitter(rng);
247 cand.y = parent.y - rh - gap;
248 break;
249 }
250 if (cand.x < padding || cand.y < padding || cand.x + cand.w > w - padding || cand.y + cand.h > h - padding)
251 continue;
252 bool ok = true;
253 for (const Rect &other : rooms) {
254 if (rectsOverlap(cand, other, spacing)) {
255 ok = false;
256 break;
257 }
258 }
259 if (ok) {
260 rooms.push_back(cand);
261 roomParents.push_back(parentIndex);
262 }
263 }
264 } else {
265 for (int r = 0; r < rows; ++r) {
266 for (int c = 0; c < cols; ++c) {
267 if (int(rooms.size()) >= roomCount) break;
268 const int sx = padding + int((long(c) * (w - 2 * padding)) / cols);
269 const int ex = padding + int((long(c + 1) * (w - 2 * padding)) / cols);
270 const int sy = padding + int((long(r) * (h - 2 * padding)) / rows);
271 const int ey = padding + int((long(r + 1) * (h - 2 * padding)) / rows);
272 const int slotW = std::max(roomMin, ex - sx);
273 const int slotH = std::max(roomMin, ey - sy);
274 if (slotW < roomMin || slotH < roomMin) continue;
275 for (int attempt = 0; attempt < 24; ++attempt) {
276 const int rw = std::min(dim(rng), slotW);
277 const int rh = std::min(dim(rng), slotH);
278 std::uniform_int_distribution<int> ox(sx, sx + slotW - rw);
279 std::uniform_int_distribution<int> oy(sy, sy + slotH - rh);
280 const Rect cand{ox(rng), oy(rng), rw, rh};
281 bool ok = true;
282 for (const Rect &other : rooms) {
283 if (rectsOverlap(cand, other, spacing)) {
284 ok = false;
285 break;
286 }
287 }
288 if (ok) {
289 roomParents.push_back(rooms.empty() ? 0 : rooms.size() - 1);
290 rooms.push_back(cand);
291 break;
292 }
293 }
294 }
295 }
296 }
297 if (rooms.empty()) {
298 // Last resort: one central room.
299 const int rw = std::max(roomMin, w / 3);
300 const int rh = std::max(roomMin, h / 3);
301 rooms.push_back({(w - rw) / 2, (h - rh) / 2, rw, rh});
302 roomParents.push_back(0);
303 }
304
305 // 2) Carve room floors.
306 for (const Rect &r : rooms) carveRect(out, r, Semantic::Floor);
307
308 // 3) Connect rooms. Nearest-parent mode produces a compact branching tree
309 // instead of long row-wrap corridors while preserving deterministic output.
310 for (size_t i = 1; i < rooms.size(); ++i) {
311 size_t parent = i - 1;
312 if (connections == "growth" && i < roomParents.size()) {
313 parent = roomParents[i];
314 } else if (connections == "nearest") {
315 int bestDistance = w + h + 1;
316 const int bx = rooms[i].x + rooms[i].w / 2;
317 const int by = rooms[i].y + rooms[i].h / 2;
318 for (size_t candidate = 0; candidate < i; ++candidate) {
319 const int ax = rooms[candidate].x + rooms[candidate].w / 2;
320 const int ay = rooms[candidate].y + rooms[candidate].h / 2;
321 const int distance = std::abs(ax - bx) + std::abs(ay - by);
322 if (distance < bestDistance) {
323 bestDistance = distance;
324 parent = candidate;
325 }
326 }
327 }
328 const int ax = rooms[parent].x + rooms[parent].w / 2;
329 const int ay = rooms[parent].y + rooms[parent].h / 2;
330 const int bx = rooms[i].x + rooms[i].w / 2;
331 const int by = rooms[i].y + rooms[i].h / 2;
332 carveCorridor(out, ax, ay, bx, by, corridorW, style, rng);
333 }
334
335 // 4) Wall autotile direction masks.
336 if (doAutotile) autotileWalls(out);
337
338 // 5) Floor pattern variants.
339 const uint32_t salt = seed * 2654435761u;
340 for (int y = 0; y < h; ++y) {
341 for (int x = 0; x < w; ++x) {
342 const uint32_t c = uint32_t(out.getCell(x, y));
343 if (c == Semantic::Floor || c == Semantic::Corridor) {
344 out.setDetail(x, y, floorVariant(x, y, pattern, variants, salt));
345 }
346 }
347 }
348
349 // 6) Scatter non-blocking ground detail, avoiding narrow doorways.
350 // through doorways (cells with a wall on two opposite sides) and the
351 // outer border so spawn/stairs stay reachable.
352 std::vector<std::pair<int, int>> floorCells;
353 floorCells.reserve(size_t(w * h));
354 for (int y = 1; y < h - 1; ++y)
355 for (int x = 1; x < w - 1; ++x)
356 if (isWalkable(uint32_t(out.getCell(x, y)))) floorCells.emplace_back(x, y);
357
358 std::vector<std::pair<int, int>> decorTiles;
359 if (!floorCells.empty() && decorDensity > 0.f) {
360 const size_t count = size_t(float(floorCells.size()) * decorDensity);
361 std::uniform_int_distribution<size_t> pick(0, floorCells.size() - 1);
362 std::uniform_int_distribution<int> kind(0, 2);
363 for (size_t i = 0; i < count; ++i) {
364 const auto [dx, dy] = floorCells[pick(rng)];
365 if (out.getDetail(dx, dy) >= kDecorBase) continue;
366 // Keep a clear 1-tile ring around spawn/stairs for reachability.
367 bool nearMarker = false;
368 for (int k = 0; k < out.getObjectCount(); ++k) {
369 if (int(out.getObjectX(k)) == dx && int(out.getObjectY(k)) == dy) {
370 nearMarker = true;
371 break;
372 }
373 }
374 if (nearMarker) continue;
375 out.setDetail(dx, dy, kDecorBase + kind(rng));
376 decorTiles.emplace_back(dx, dy);
377 }
378 }
379
380 // 7) Semantic asset dressing. Pools are comma-separated asset ids supplied
381 // by the caller. Generic fallbacks deliberately contain no KayKit names.
382 // Renderers resolve `getObjectAsset()` however they like (GLTF, prefab, sprite…).
383 const auto containers = assetPool(params, "container", "container");
384 const auto treasure = assetPool(params, "treasure", "treasure");
385 const auto columns = assetPool(params, "column", "column");
386 const auto tables = assetPool(params, "table", "table");
387 const auto seating = assetPool(params, "seating", "seat");
388 const auto beds = assetPool(params, "bed", "bed");
389 const auto shelves = assetPool(params, "shelf", "shelf");
390 const auto lights = assetPool(params, "light", "light");
391 const auto wallLights = assetPool(params, "wallLight", params.getString("assets.light", "light"));
392 const auto wallShelves = assetPool(params, "wallShelf", params.getString("assets.shelf", "shelf"));
393 const auto banners = assetPool(params, "banner", "banner");
394 const auto weapons = assetPool(params, "weapon", "weapon_display");
395 const auto traps = assetPool(params, "trap", "trap");
396 const auto food = assetPool(params, "food", "food");
397 const auto tavern = assetPool(params, "tavern", "tavern_prop");
398 const auto clutter = assetPool(params, "clutter", "clutter");
399 const auto stairsAssets = assetPool(params, "stairs", "stairs");
400 const float propDensity = std::clamp(params.getFloat("propDensity", 0.16f), 0.f, 1.f);
401 const float corridorLightDensity = std::clamp(params.getFloat("corridorLightDensity", 0.035f), 0.f, 0.25f);
402 std::unordered_set<int> occupied;
403 int objectSerial = 0;
404 int minimumRoomProps = std::numeric_limits<int>::max();
405 auto cellKey = [w](int x, int y) { return y * w + x; };
406 auto place = [&](const std::string &role, const std::vector<std::string> &pool, double x, double y, float rotation,
407 int flags, float ow = 1.f, float oh = 1.f) {
408 const int cellX = clampInt(int(std::round(x)), 0, w - 1);
409 const int cellY = clampInt(int(std::round(y)), 0, h - 1);
410 if (pool.empty() || !isWalkable(uint32_t(out.getCell(cellX, cellY)))) return false;
411 if ((flags & 1) && occupied.count(cellKey(cellX, cellY))) return false;
412 out.addAssetObject(role + std::to_string(objectSerial++), role, pickAsset(pool, rng), static_cast<float>(x),
413 static_cast<float>(y), ow, oh, rotation, flags);
414 if (flags & 1) occupied.insert(cellKey(cellX, cellY));
415 return true;
416 };
417
418 if (decorSet != "none") {
419 for (size_t roomIndex = 0; roomIndex < rooms.size(); ++roomIndex) {
420 const Rect &r = rooms[roomIndex];
421 if (r.w < 3 || r.h < 3) continue;
422 const int left = r.x, right = r.x + r.w - 1;
423 const int top = r.y, bottom = r.y + r.h - 1;
424 const int cx = r.x + r.w / 2, cy = r.y + r.h / 2;
425 // The clustered layout grows from room zero, making it the visual
426 // hub. Give that hub a dense dining composition instead of a quiet
427 // edge-oriented theme; remaining rooms still cycle deterministically.
428 const int theme = roomIndex == 0 ? 2 : int((roomIndex + seed) % 7);
429 static constexpr const char *kThemeNames[] = {"storage", "quarters", "dining", "armory",
430 "treasury", "shrine", "tavern"};
431 out.addAssetObject("room" + std::to_string(roomIndex), "room", kThemeNames[theme], float(r.x), float(r.y),
432 float(r.w), float(r.h), 0.f, 32);
433 const int propsBeforeRoom = objectSerial;
434
435 // Every furnished room receives wall-mounted light and occasional banner.
436 place("light", wallLights, left, cy, 90.f, 2 | 4);
437 if (r.w >= 6) place("light", wallLights, right, cy, 270.f, 2 | 4);
438 if ((rng() % 3u) != 0) place("banner", banners, left, cy - 1, 90.f, 2);
439 if (propDensity >= 0.45f && r.w >= 5 && (roomIndex % 2) == 0)
440 place("banner", banners, cx + (r.w >= 7 ? 1 : 0), bottom, 0.f, 2);
441 if (propDensity >= 0.6f && r.w >= 6 && (roomIndex % 2) != 0)
442 place("light", wallLights, cx, bottom, 0.f, 2 | 4);
443
444 if (decorSet == "pillars") {
445 place("column", columns, left + 1, top + 1, 0.f, 1);
446 place("column", columns, right - 1, bottom - 1, 0.f, 1);
447 continue;
448 }
449 if (decorSet == "treasure" || theme == 4) {
450 place("container", containers, right, cy, 270.f, 1);
451 place("treasure", treasure, right - 1, cy, 0.f, 16);
452 place("treasure", treasure, right - 1.35f, cy + 0.45f, 35.f, 16);
453 place("treasure", treasure, right - 0.65f, cy - 0.45f, 320.f, 16);
454 place("column", columns, left + 1, top + 1, 0.f, 1);
455 place("column", columns, left + 1, bottom - 1, 0.f, 1);
456 } else if (theme == 0) {
457 place("container", containers, right, top + 1, 270.f, 1);
458 place("container", containers, right, bottom - 1, 270.f, 1);
459 place("container", containers, right - 0.75f, top + 1.35f, 245.f, 16);
460 place("container", containers, right - 0.55f, bottom - 1.25f, 300.f, 16);
461 place("shelf", wallShelves, cx, bottom, 0.f, 1 | 2);
462 if (r.h >= 6) place("shelf", wallShelves, left, cy + 1, 90.f, 1 | 2);
463 if (r.w >= 6) place("container", containers, left + 2, bottom, 0.f, 1);
464 place("clutter", clutter, left + 1, bottom, 0.f, 16);
465 } else if (theme == 1) {
466 place("bed", beds, right, cy, 270.f, 1, 1.f, 2.f);
467 if (r.h >= 6) place("bed", beds, right, cy - 2, 270.f, 1, 1.f, 2.f);
468 place("container", containers, right - 1, top, 180.f, 1);
469 place("light", lights, right - 1, cy, 0.f, 4);
470 place("seating", seating, left + 1, bottom - 1, 45.f, 1);
471 } else if (theme == 2) {
472 place("table", tables, cx, cy, (rng() & 1u) ? 0.f : 90.f, 1, 2.f, 1.f);
473 place("seating", seating, cx - 1, cy, 270.f, 1);
474 place("seating", seating, cx + 1, cy, 90.f, 1);
475 place("seating", seating, cx, cy - 1, 0.f, 1);
476 place("seating", seating, cx, cy + 1, 180.f, 1);
477 place("food", food, cx, cy, 0.f, 16);
478 place("food", food, cx - 0.38f, cy + 0.18f, 25.f, 16);
479 place("food", food, cx + 0.38f, cy - 0.18f, 205.f, 16);
480 if (r.w >= 6) {
481 place("table", tables, cx - 2, cy, 0.f, 1, 2.f, 1.f);
482 place("seating", seating, cx - 2, cy - 1, 0.f, 1);
483 place("seating", seating, cx - 2, cy + 1, 180.f, 1);
484 place("food", food, cx - 2, cy, 70.f, 16);
485 }
486 } else if (theme == 3) {
487 place("weapon", weapons, left, cy, 90.f, 2);
488 place("weapon", weapons, cx, bottom, 0.f, 2);
489 place("column", columns, cx, cy, 0.f, 1);
490 if (r.w >= 6) place("column", columns, left + 1, bottom - 1, 0.f, 1);
491 place("container", containers, right, top + 1, 270.f, 1);
492 if ((rng() & 1u) != 0) place("trap", traps, cx - 1, cy, 0.f, 8);
493 } else if (theme == 5) {
494 place("table", tables, cx, cy, 0.f, 1, 2.f, 1.f);
495 place("light", lights, cx - 0.45f, cy, 0.f, 4);
496 place("light", lights, cx + 0.45f, cy, 0.f, 4);
497 place("food", food, cx, cy, 0.f, 16);
498 place("seating", seating, cx, bottom - 1, 180.f, 1);
499 if (r.w >= 6) {
500 place("seating", seating, cx - 2, bottom - 1, 180.f, 1);
501 place("seating", seating, cx + 2, bottom - 1, 180.f, 1);
502 }
503 } else {
504 place("tavern", tavern, right, cy, 270.f, 1);
505 place("table", tables, cx, cy, 0.f, 1, 2.f, 1.f);
506 place("seating", seating, cx - 1, cy, 270.f, 1);
507 place("seating", seating, cx + 1, cy, 90.f, 1);
508 place("seating", seating, cx, cy + 1, 180.f, 1);
509 place("food", food, cx, cy, 0.f, 16);
510 place("food", food, cx - 0.4f, cy, 20.f, 16);
511 place("food", food, cx + 0.4f, cy, 340.f, 16);
512 place("container", containers, right, bottom - 1, 270.f, 1);
513 place("tavern", tavern, right - 0.7f, bottom - 1.2f, 250.f, 16);
514 }
515
516 // High-density presets add a secondary wall-side storage vignette.
517 // This is intentionally shared across themes: barrels, trunks, and
518 // crates are the visual glue that makes modular rooms feel occupied.
519 if (propDensity >= 0.45f && theme != 0 && theme != 4 && theme != 6) {
520 place("container", containers, right, bottom - 1, 270.f, 1);
521 place("container", containers, right - 0.65f, bottom - 1.3f, 245.f, 16);
522 if (r.w >= 6 && theme != 2) place("seating", seating, left + 1, top + 1, 45.f, 1);
523 }
524
525 // Sparse edge clutter gives the dense, lived-in reference look without
526 // turning room centres and corridors into an obstacle field.
527 const int clutterAttempts = clampInt(int(std::ceil(propDensity * 1.5f)), 0, 2);
528 const std::pair<int, int> clutterSpots[] = {
529 {left, top + 1}, {right, bottom - 1}, {left + 1, bottom}, {right - 1, top}};
530 for (int i = 0; i < clutterAttempts; ++i) {
531 const auto &spot = clutterSpots[(size_t(i) + roomIndex) % 4];
532 place("clutter", clutter, spot.first, spot.second, float((i + int(roomIndex)) % 4) * 90.f, 16);
533 }
534
535 // Enforce a visible minimum for dense showcase presets. Failed
536 // blocking placements simply advance to another interior edge;
537 // non-blocking clutter remains cosmetic and navigation-safe.
538 if (propDensity >= 0.35f) {
539 // Scale the visual budget with room area. A fixed count makes
540 // large chambers look abandoned even at high density.
541 const int roomArea = r.w * r.h;
542 const int targetProps = clampInt(4 + int(std::ceil(propDensity * float(roomArea) * 0.28f)), 4, 16);
543 const std::pair<int, int> fillerSpots[] = {{left + 1, top + 1}, {right - 1, top + 1},
544 {left + 1, bottom - 1}, {right - 1, bottom - 1},
545 {cx - 1, bottom - 1}, {cx + 1, top + 1}};
546 for (int attempt = 0; attempt < 24 && objectSerial - propsBeforeRoom < targetProps; ++attempt) {
547 const auto &spot = fillerSpots[(size_t(attempt) + roomIndex) % 6];
548 if ((attempt & 1) == 0)
549 place("container", containers, spot.first, spot.second,
550 float((attempt + int(roomIndex)) % 4) * 90.f, 1);
551 else
552 place("container", containers, float(spot.first) + 0.35f, float(spot.second) - 0.25f,
553 float((attempt * 37) % 360), 16);
554 }
555 }
556 minimumRoomProps = std::min(minimumRoomProps, objectSerial - propsBeforeRoom);
557 }
558
559 // Long connectors in the reference are punctuated by sparse sconces.
560 // Keep this semantic and density-driven so packs can substitute any
561 // wall-mounted light prefab without changing the generator.
562 const uint32_t lightThreshold = uint32_t(corridorLightDensity * 1000.f);
563 for (int y = 1; y < h - 1; ++y) {
564 for (int x = 1; x < w - 1; ++x) {
565 if (uint32_t(out.getCell(x, y)) != Semantic::Corridor) continue;
566 const uint32_t hash = uint32_t(x) * 73856093u ^ uint32_t(y) * 19349663u ^ seed;
567 if ((hash % 1000u) >= lightThreshold) continue;
568 if (uint32_t(out.getCell(x - 1, y)) == Semantic::Wall)
569 place("light", wallLights, float(x), float(y), 90.f, 2 | 4);
570 else if (uint32_t(out.getCell(x + 1, y)) == Semantic::Wall)
571 place("light", wallLights, float(x), float(y), 270.f, 2 | 4);
572 else if (uint32_t(out.getCell(x, y - 1)) == Semantic::Wall)
573 place("light", wallLights, float(x), float(y), 180.f, 2 | 4);
574 else if (uint32_t(out.getCell(x, y + 1)) == Semantic::Wall)
575 place("light", wallLights, float(x), float(y), 0.f, 2 | 4);
576 }
577 }
578 }
579
580 // 8) Spawn + an outward-facing perimeter stair. Stairs are architecture,
581 // not arbitrary floor clutter: orientation identifies the wall opening the
582 // renderer should replace (0 north, 180 south, 90 west, 270 east).
583 struct StairCandidate {
584 int x, y;
585 float rotation;
586 int side;
587 };
588 std::vector<StairCandidate> stairCandidates;
589 for (const Rect &r : rooms) {
590 for (int x = r.x + 1; x < r.x + r.w - 1; ++x) {
591 if ((stairSideMask & 1) && uint32_t(out.getCell(x, r.y - 1)) == Semantic::Wall)
592 stairCandidates.push_back({x, r.y, 180.f, 1});
593 if ((stairSideMask & 2) && uint32_t(out.getCell(x, r.y + r.h)) == Semantic::Wall)
594 stairCandidates.push_back({x, r.y + r.h - 1, 0.f, 2});
595 }
596 for (int y = r.y + 1; y < r.y + r.h - 1; ++y) {
597 if ((stairSideMask & 4) && uint32_t(out.getCell(r.x - 1, y)) == Semantic::Wall)
598 stairCandidates.push_back({r.x, y, 270.f, 4});
599 if ((stairSideMask & 8) && uint32_t(out.getCell(r.x + r.w, y)) == Semantic::Wall)
600 stairCandidates.push_back({r.x + r.w - 1, y, 90.f, 8});
601 }
602 }
603 std::vector<size_t> selectedStairs;
604 for (int entrance = 0; entrance < stairCount && selectedStairs.size() < stairCandidates.size(); ++entrance) {
605 size_t best = size_t(seed) % stairCandidates.size();
606 int bestDistance = -1;
607 if (!selectedStairs.empty()) {
608 for (size_t candidate = 0; candidate < stairCandidates.size(); ++candidate) {
609 bool duplicate = false;
610 int nearest = w + h;
611 for (size_t chosen : selectedStairs) {
612 if (stairCandidates[candidate].x == stairCandidates[chosen].x &&
613 stairCandidates[candidate].y == stairCandidates[chosen].y) {
614 duplicate = true;
615 break;
616 }
617 nearest = std::min(nearest, std::abs(stairCandidates[candidate].x - stairCandidates[chosen].x) +
618 std::abs(stairCandidates[candidate].y - stairCandidates[chosen].y));
619 }
620 if (!duplicate && nearest > bestDistance) {
621 bestDistance = nearest;
622 best = candidate;
623 }
624 }
625 if (bestDistance < 0) break;
626 }
627 selectedStairs.push_back(best);
628 const StairCandidate &stairs = stairCandidates[best];
629 out.addAssetObject("stairs" + std::to_string(entrance), "stairs", pickAsset(stairsAssets, rng), float(stairs.x),
630 float(stairs.y), 1.f, 1.f, stairs.rotation, 64);
631 occupied.insert(cellKey(stairs.x, stairs.y));
632 }
633
634 std::vector<std::pair<int, int>> walkable;
635 for (int y = 0; y < h; ++y)
636 for (int x = 0; x < w; ++x)
637 if (isWalkable(uint32_t(out.getCell(x, y))) && !occupied.count(cellKey(x, y))) walkable.emplace_back(x, y);
638 if (!walkable.empty()) {
639 auto pick = [&](uint32_t s) { return walkable[(seed * 1664525u + s * 1013904223u) % walkable.size()]; };
640 auto a = pick(1);
641 out.addObjectAt("spawn", "spawn", float(a.first), float(a.second));
642 }
643
644 // 9) Metadata.
645 out.setMeta("algorithm", "level.roguelike");
646 out.setMeta("seed", std::to_string(seed));
647 out.setMeta("rooms", std::to_string(rooms.size()));
648 out.setMeta("floorPattern", pattern);
649 out.setMeta("decorTiles", std::to_string(decorTiles.size()));
650 out.setMeta("corridorStyle", style);
651 out.setMeta("layoutStyle", layout);
652 out.setMeta("connectionStyle", connections);
653 out.setMeta("assetPack", params.getString("assetPack", "semantic-default"));
654 out.setMeta("placedProps", std::to_string(objectSerial));
655 out.setMeta("minimumRoomProps",
656 std::to_string(minimumRoomProps == std::numeric_limits<int>::max() ? 0 : minimumRoomProps));
657 out.setMeta("stairs", std::to_string(selectedStairs.size()));
658 // Tile renderers use these semantic pools to resolve every architecture cell.
659 // Copying them into metadata keeps the generated artifact self-describing.
660 static const char *architectureRoles[] = {
661 "wall", "wallCorner", "wallJunction", "wallDoor", "wallWindow", "wallHalf", "wallBroken",
662 "wallScaffold", "floor", "floorBroken", "floorDirt", "floorWood", "floorGrate", "floorFoundation",
663 "ceiling", "stairs", "stairsRail", "door", "barrier"};
664 for (const char *role : architectureRoles) {
665 const std::string key = std::string("assets.") + role;
666 if (params.has(key)) out.setMeta(key, params.getString(key, ""));
667 }
668 return true;
669}
670
671} // namespace
672
674 auto descriptor = GeneratorDescriptor::grid("level.roguelike", "Roguelike Level", "Dungeon", 9, 9);
675 descriptor.params.push_back(ParamDescriptor::integer("roomCount", "Room Count", 9, 1, 256));
676 descriptor.params.push_back(ParamDescriptor::integer("roomMin", "Minimum Room Size", 4, 2, 128));
677 descriptor.params.push_back(ParamDescriptor::integer("roomMax", "Maximum Room Size", 8, 2, 256));
678 descriptor.params.push_back(ParamDescriptor::integer("padding", "Room Padding", 1, 0, 4));
679 descriptor.params.push_back(ParamDescriptor::integer("spacing", "Room Spacing", 2, 0, 8));
680 descriptor.params.push_back(ParamDescriptor::integer("clusterGapMin", "Cluster Minimum Gap", 2, 1, 8));
681 descriptor.params.push_back(ParamDescriptor::integer("clusterGapMax", "Cluster Maximum Gap", 4, 1, 12));
682 descriptor.params.push_back(ParamDescriptor::integer("clusterBranchBias", "Cluster Branch Bias", 0, 0, 4));
683 descriptor.params.push_back(ParamDescriptor::integer("corridorWidth", "Corridor Width", 1, 1, 3));
684 descriptor.params.push_back(ParamDescriptor::integer("stairCount", "Stair Count", 1, 0, 4));
685 descriptor.params.push_back(ParamDescriptor::integer("stairSideMask", "Stair Side Mask", 15, 1, 15));
686 descriptor.params.push_back(ParamDescriptor::choice("layoutStyle", "Room Layout", "grid", {"grid", "clustered"}));
687 descriptor.params.push_back(ParamDescriptor::choice("connectionStyle", "Room Connections", "sequential",
688 {"sequential", "nearest", "growth"}));
689 descriptor.params.push_back(
690 ParamDescriptor::choice("corridorStyle", "Corridor Style", "l", {"l", "straight", "diagonal"}));
691 descriptor.params.push_back(ParamDescriptor::choice("floorPattern", "Floor Pattern", "brick",
692 {"brick", "checker", "plank", "plain", "cobble"}));
693 descriptor.params.push_back(ParamDescriptor::integer("floorVariants", "Floor Variants", 4, 1, 15));
694 descriptor.params.push_back(
695 ParamDescriptor::floating("decorDensity", "Decoration Density", 0.05f, 0.f, 1.f, 0.01f));
696 descriptor.params.push_back(
697 ParamDescriptor::choice("decorSet", "Decoration Set", "mixed", {"mixed", "pillars", "treasure", "none"}));
698 descriptor.params.push_back(ParamDescriptor::floating("propDensity", "Prop Density", 0.16f, 0.f, 1.f, 0.01f));
699 descriptor.params.push_back(
700 ParamDescriptor::floating("corridorLightDensity", "Corridor Light Density", 0.035f, 0.f, 0.25f, 0.005f));
701 descriptor.params.push_back(ParamDescriptor::boolean("autotile", "Autotile", true));
702 registry.registerAlgorithm(std::move(descriptor), genRoguelike);
703}
704
706 autotileWalls(grid);
707 return grid.getWidth() > 0 && grid.getHeight() > 0;
708}
709
711 if (grid.getWidth() <= 0 || grid.getHeight() <= 0)
713 "autotile grid dimensions must be positive", {}, {},
714 "procgen.gridGraph"));
715 constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
716 constexpr int dy[] = {-1, 0, 1, 0, -1, 1, 1, -1};
717 for (int y = 0; y < grid.getHeight(); ++y) {
718 for (int x = 0; x < grid.getWidth(); ++x) {
719 int mask = 0;
720 if (uint32_t(grid.getCell(x, y)) != Semantic::Empty)
721 for (int direction = 0; direction < 8; ++direction)
722 if (uint32_t(grid.getCell(x + dx[direction], y + dy[direction])) != Semantic::Empty)
723 mask |= 1 << direction;
724 grid.setDetail(x, y, mask);
725 }
726 }
728}
729
730uint32_t randomSeedValue() {
731 std::random_device rd;
732 const uint32_t v = rd();
733 return v == 0 ? 1u : v;
734}
735
736} // namespace eve::procgen
737
738// WfcSimple.cpp
739namespace eve::procgen {
740namespace {
741
742struct WfcTile {
744 // Orthogonal adjacency: bit i set ⇒ may neighbor tile i (N/E/S/W all share same rule).
745 uint64_t compat = 0;
746};
747
748struct WfcPreset {
749 const char *name;
750 std::vector<WfcTile> tiles;
751};
752
753WfcPreset makeDungeonPreset() {
754 // 0 Wall, 1 Floor, 2 Corridor, 3 Door
755 WfcPreset p;
756 p.name = "dungeon";
757 p.tiles = {
758 {Semantic::Wall, 0},
759 {Semantic::Floor, 0},
761 {Semantic::Door, 0},
762 };
763 auto allow = [&](int a, int b) {
764 p.tiles[size_t(a)].compat |= (1ull << b);
765 p.tiles[size_t(b)].compat |= (1ull << a);
766 };
767 allow(0, 0); // wall-wall
768 allow(0, 1); // wall-floor
769 allow(0, 2); // wall-corridor
770 allow(0, 3); // wall-door
771 allow(1, 1); // floor-floor
772 allow(1, 2); // floor-corridor
773 allow(1, 3); // floor-door
774 allow(2, 2); // corridor-corridor
775 // door-door disallowed (keeps doors sparse)
776 return p;
777}
778
779WfcPreset makeCavePreset() {
780 WfcPreset p;
781 p.name = "cave";
782 p.tiles = {
783 {Semantic::Wall, 0},
784 {Semantic::Floor, 0},
785 };
786 auto allow = [&](int a, int b) {
787 p.tiles[size_t(a)].compat |= (1ull << b);
788 p.tiles[size_t(b)].compat |= (1ull << a);
789 };
790 allow(0, 0);
791 allow(0, 1);
792 allow(1, 1);
793 return p;
794}
795
796WfcPreset makeTerrainPreset() {
797 // Adjacent biomes only (ordered elevation band).
798 // 0 Water 1 Sand 2 Grass 3 Dirt 4 Stone 5 Snow
799 WfcPreset p;
800 p.name = "terrain";
801 p.tiles = {
804 };
805 auto allow = [&](int a, int b) {
806 p.tiles[size_t(a)].compat |= (1ull << b);
807 p.tiles[size_t(b)].compat |= (1ull << a);
808 };
809 for (int i = 0; i < 6; ++i) {
810 allow(i, i);
811 if (i + 1 < 6) allow(i, i + 1);
812 }
813 return p;
814}
815
816const WfcPreset &presetByName(const std::string &name) {
817 static const WfcPreset dungeon = makeDungeonPreset();
818 static const WfcPreset cave = makeCavePreset();
819 static const WfcPreset terrain = makeTerrainPreset();
820 if (name == "cave") return cave;
821 if (name == "terrain") return terrain;
822 return dungeon;
823}
824
825bool genWfcSimple(const Params &params, Grid2D &out, std::string &error) {
826 const int w = params.getWidth();
827 const int h = params.getHeight();
828 if (w < 4 || h < 4) {
829 error = "wfc.simple: size must be at least 4x4";
830 return false;
831 }
832 if (w > 256 || h > 256) {
833 error = "wfc.simple: size capped at 256x256";
834 return false;
835 }
836
837 const std::string presetName = params.getString("preset", "dungeon");
838 if (presetName != "dungeon" && presetName != "cave" && presetName != "terrain") {
839 error = "wfc.simple: unknown preset '" + presetName + "' (use dungeon|cave|terrain)";
840 return false;
841 }
842 const WfcPreset &preset = presetByName(presetName);
843 const int tileCount = int(preset.tiles.size());
844 if (tileCount <= 0 || tileCount > 63) {
845 error = "wfc.simple: invalid tile set";
846 return false;
847 }
848
849 const int maxAttempts = std::max(1, params.getInt("maxAttempts", 32));
850 const uint64_t fullMask = (tileCount >= 63) ? ~0ull : ((1ull << tileCount) - 1ull);
851
852 std::mt19937 rng(params.getSeed());
853
854 auto trySolve = [&](Grid2D &grid) -> bool {
855 std::vector<uint64_t> wave(size_t(w * h), fullMask);
856 auto idx = [&](int x, int y) { return size_t(y * w + x); };
857 auto countBits = [](uint64_t m) {
858 int c = 0;
859 while (m) {
860 m &= m - 1;
861 ++c;
862 }
863 return c;
864 };
865
866 auto pickTile = [&](uint64_t mask) -> int {
867 int options[64];
868 int n = 0;
869 for (int t = 0; t < tileCount; ++t) {
870 if (mask & (1ull << t)) options[n++] = t;
871 }
872 if (n <= 0) return -1;
873 std::uniform_int_distribution<int> dist(0, n - 1);
874 return options[dist(rng)];
875 };
876
877 // Border: force walls for dungeon/cave (keeps maps enclosed).
878 if (presetName != "terrain") {
879 for (int x = 0; x < w; ++x) {
880 wave[idx(x, 0)] = 1ull << 0;
881 wave[idx(x, h - 1)] = 1ull << 0;
882 }
883 for (int y = 0; y < h; ++y) {
884 wave[idx(0, y)] = 1ull << 0;
885 wave[idx(w - 1, y)] = 1ull << 0;
886 }
887 }
888
889 auto propagate = [&](int sx, int sy) -> bool {
890 std::vector<std::pair<int, int>> stack;
891 stack.emplace_back(sx, sy);
892 while (!stack.empty()) {
893 const auto [cx, cy] = stack.back();
894 stack.pop_back();
895 const uint64_t self = wave[idx(cx, cy)];
896 if (self == 0) return false;
897
898 uint64_t allowedNeighbor = 0;
899 for (int t = 0; t < tileCount; ++t) {
900 if (self & (1ull << t)) allowedNeighbor |= preset.tiles[size_t(t)].compat;
901 }
902
903 const int dirs[4][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
904 for (const auto &d : dirs) {
905 const int nx = cx + d[0];
906 const int ny = cy + d[1];
907 if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
908 uint64_t &nb = wave[idx(nx, ny)];
909 const uint64_t before = nb;
910 nb &= allowedNeighbor;
911 if (nb == 0) return false;
912 if (nb != before) stack.emplace_back(nx, ny);
913 }
914 }
915 return true;
916 };
917
918 // Seed propagate from border constraints.
919 if (presetName != "terrain") {
920 for (int x = 0; x < w; ++x) {
921 if (!propagate(x, 0) || !propagate(x, h - 1)) return false;
922 }
923 for (int y = 0; y < h; ++y) {
924 if (!propagate(0, y) || !propagate(w - 1, y)) return false;
925 }
926 }
927
928 for (;;) {
929 int bestX = -1, bestY = -1;
930 int bestEntropy = std::numeric_limits<int>::max();
931 bool anyUncollapsed = false;
932 for (int y = 0; y < h; ++y) {
933 for (int x = 0; x < w; ++x) {
934 const int e = countBits(wave[idx(x, y)]);
935 if (e == 0) return false;
936 if (e == 1) continue;
937 anyUncollapsed = true;
938 // Prefer lower entropy; break ties randomly via salt.
939 const int salted = e * 1000 + int(rng() % 1000u);
940 if (salted < bestEntropy) {
941 bestEntropy = salted;
942 bestX = x;
943 bestY = y;
944 }
945 }
946 }
947 if (!anyUncollapsed) break;
948 if (bestX < 0) return false;
949
950 const int chosen = pickTile(wave[idx(bestX, bestY)]);
951 if (chosen < 0) return false;
952 wave[idx(bestX, bestY)] = 1ull << chosen;
953 if (!propagate(bestX, bestY)) return false;
954 }
955
956 grid.resize(w, h);
957 for (int y = 0; y < h; ++y) {
958 for (int x = 0; x < w; ++x) {
959 const uint64_t m = wave[idx(x, y)];
960 int tile = 0;
961 for (int t = 0; t < tileCount; ++t) {
962 if (m & (1ull << t)) {
963 tile = t;
964 break;
965 }
966 }
967 grid.setCell(x, y, int(preset.tiles[size_t(tile)].semantic));
968 }
969 }
970 return true;
971 };
972
973 bool ok = false;
974 for (int attempt = 0; attempt < maxAttempts; ++attempt) {
975 // Advance RNG between attempts for a different collapse order.
976 if (attempt > 0) (void)rng();
977 Grid2D candidate;
978 if (trySolve(candidate)) {
979 out = std::move(candidate);
980 ok = true;
981 break;
982 }
983 }
984 if (!ok) {
985 error = "wfc.simple: failed to collapse (try different seed/preset or raise maxAttempts)";
986 return false;
987 }
988
989 out.setMeta("algorithm", "wfc.simple");
990 out.setMeta("preset", presetName);
991
992 // Spawn/stairs on walkable cells when present.
993 std::vector<std::pair<int, int>> walkable;
994 for (int y = 0; y < h; ++y) {
995 for (int x = 0; x < w; ++x) {
996 const uint32_t c = uint32_t(out.getCell(x, y));
998 c == Semantic::Sand) {
999 walkable.emplace_back(x, y);
1000 }
1001 }
1002 }
1003 if (!walkable.empty()) {
1004 std::uniform_int_distribution<size_t> pick(0, walkable.size() - 1);
1005 auto a = walkable[pick(rng)];
1006 auto b = walkable[pick(rng)];
1007 if (a == b && walkable.size() > 1) b = walkable[(pick(rng) + 1) % walkable.size()];
1008 out.clearObjects();
1009 out.addObjectAt("spawn", "spawn", float(a.first), float(a.second));
1010 out.addObjectAt("stairs", "stairs", float(b.first), float(b.second));
1011 }
1012 return true;
1013}
1014
1015} // namespace
1016
1018 auto descriptor = GeneratorDescriptor::grid("wfc.simple", "Simple WFC", "Wave Function Collapse", 4, 4, 256, 256);
1019 descriptor.params.push_back(ParamDescriptor::choice("preset", "Preset", "dungeon", {"dungeon", "cave", "terrain"}));
1020 descriptor.params.push_back(ParamDescriptor::integer("maxAttempts", "Maximum Attempts", 32, 1, 512));
1021 registry.registerAlgorithm(std::move(descriptor), genWfcSimple);
1022}
1023
1024} // namespace eve::procgen
double y
double m[16]
double x
float w
Definition AnimClip.cpp:738
std::string descriptor
std::string terrain
const std::string & s
int mask
float gap
float cx
Definition CardTypes.cpp:36
float cy
Definition CardTypes.cpp:37
glm::vec4 p[6]
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
EvpackChunkInput input
Definition Evpack.cpp:170
int rows
int cols
std::string pattern
std::string layout
std::vector< eve::ProcgenProbeDesc > lights
glm::vec3 n
Definition Grass.cpp:63
double r
float v
HexVec3 left
HexVec3 right
std::int32_t c
std::int32_t first
int h
std::uint32_t width
const ColourScope * parent
std::array< float, 4 > rotation
Poco::JSON::Object::Ptr result
std::vector< RecipeParam > params
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
float distance
glm::dvec3 dx
std::string error
Definition Package.cpp:174
int idx
const eve::script::BindingContractRegistry & registry
std::string hash
float d
float t
RoadLaneDirection direction
std::vector< WfcTile > tiles
uint64_t compat
uint32_t semantic
ScriptStructure out
std::string kind
float dy
Definition Shadow.cpp:151
bool occupied
Definition Shadow.cpp:155
const SquirrelValueOptions & options
int count
std::map< Cell, int > best
int spacing
int columns
uint32_t seed
Definition TreeMesh.cpp:276
float size
Definition TreeMesh.cpp:158
double oy
double ox
uint32_t flags
float bottom
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Registry for executable generators and their reflection metadata.
Intermediate 2D generation result. cells store semantic ids (see Semantic.h), not tile GIDs — convert...
Definition Grid2D.h:37
SQInteger top
Definition Snapshot.cpp:115
const HouseComponent * pick(const std::vector< std::reference_wrapper< const HouseComponent > > &choices, std::mt19937 &rng)
Borrow a weighted component from library-backed choices. @ownership Borrowed; the session's library o...
constexpr uint32_t Floor
Definition Semantic.h:14
constexpr uint32_t Grass
Definition Semantic.h:18
constexpr uint32_t Stone
Definition Semantic.h:20
constexpr uint32_t Wall
Definition Semantic.h:13
constexpr uint32_t Sand
Definition Semantic.h:17
constexpr uint32_t Dirt
Definition Semantic.h:19
constexpr uint32_t Corridor
Definition Semantic.h:15
constexpr uint32_t Empty
Definition Semantic.h:12
constexpr uint32_t Door
Definition Semantic.h:22
constexpr uint32_t Water
Definition Semantic.h:16
constexpr uint32_t Snow
Definition Semantic.h:21
double sample(const Heightmap &map, double u, double v)
Sample.
void registerWfcSimple(GeneratorRegistry &registry)
void registerRoguelikeGenerator(GeneratorRegistry &registry)
Register the "level.roguelike" algorithm (idempotent).
eve::Result< void > autotileOccupiedGridInPlace(Grid2D &grid)
Write an eight-neighbour occupancy mask into every non-empty cell's detail value.
bool autotileGridInPlace(Grid2D &grid)
Post-process any generated Grid2D: fill each wall cell's detail with an 8-bit neighbour mask describi...
uint32_t randomSeedValue()
Produce a fresh seed suitable for regenerating a level (never 0).
std::string presetName(UiThemeBasePreset preset)
Preset name.
WidgetDesc grid(int columns, std::vector< WidgetDesc > children, std::string id)
Fixed-column grid; children are placed in source order.
Definition Widget.cpp:878
static ParamDescriptor choice(std::string key, std::string label, std::string defaultValue, std::vector< std::string > choices)
Construct a finite-choice string descriptor.
static ParamDescriptor integer(std::string key, std::string label, int defaultValue, int minimum, int maximum, int step=1)
Construct a bounded integer descriptor.
static RecipeDescriptor grid(std::string id, std::string displayName, std::string category, int minimumWidth, int minimumHeight, int maximumWidth=4096, int maximumHeight=4096)
Create a schema with common seed, width and height parameters.
Object::Ptr theme
uint32_t pad[2]