载入中...
搜索中...
未找到
HouseGenerationConfigure.cpp
浏览该文件的文档.
2
4std::vector<uint8_t> State::makeMask(int ins) const {
7}
8
9
11 if (r.width < 3 || r.depth < 3 || r.floors < 1 || r.maxAttempts < 1) {
13 eve::DiagnosticCode::InvalidArgument, "house needs a 3x3 plot, at least one floor and one attempt", {}, {},
14 "housegen.generate"));
15 }
16 if (!std::isfinite(r.moduleSize) || r.moduleSize <= 0.f || !std::isfinite(r.floorHeight) || r.floorHeight <= 0.f)
18 eve::DiagnosticCode::InvalidArgument, "moduleSize and floorHeight must be finite and positive", {}, {},
19 "housegen.generate"));
20 if (!isOneOf(r.footprint, {"auto", "rectangle", "l_shape", "t_shape", "polygon"}) ||
21 !isOneOf(r.roof, {"auto", "gable", "flat", "shed"}) ||
22 !isOneOf(r.entrance, {"auto", "north", "east", "south", "west"})) {
24 "unsupported footprint, roof or entrance mode", {}, {},
25 "housegen.generate"));
26 }
27 if (r.footprint == "polygon" && r.perimeter.size() < 3) {
29 "polygon footprint needs at least 3 perimeter points",
30 {}, {}, "housegen.generate"));
31 }
32 const auto foundation = library_.byCategory("foundation", r.style);
33 const auto floor = library_.byCategory("floor", r.style);
34 const auto wall = library_.byCategory("wall", r.style);
35 const auto door = library_.byCategory("door", r.style);
36 const auto roof = library_.byCategory("roof", r.style);
37 if (!has(foundation) || !has(floor) || !has(wall) || !has(door) || !has(roof)) {
39 eve::DiagnosticCode::NotFound, "library needs foundation, floor, wall, door and roof categories", {}, {},
40 "housegen.generate"));
41 }
42 // A named style must be a complete pack; otherwise per-category selection would
43 // silently mix it with unstyled components into a broken house.
44 if (!r.style.empty() && !library_.hasCompletePack(r.style)) {
47 "style pack '" + r.style + "' is incomplete (needs foundation, floor, wall, door and roof)", {}, {},
48 "housegen.generate"));
49 }
50 // Interior partition and stairwell categories are optional: interior walls/doors are used
51 // only for an explicit multi-room request, stairs only for multi-floor houses.
52 const auto stairs = library_.byCategory("stairs", r.style);
53 const auto innerWall = library_.byCategory("interior_wall", r.style);
54 const auto innerDoor = library_.byCategory("interior_door", r.style);
55 const bool partitionsInteriors = r.requiredRooms.size() > 1;
56 if (partitionsInteriors && (!has(innerWall) || !has(innerDoor)))
58 eve::DiagnosticCode::NotFound, "multi-room generation needs interior_wall and interior_door categories",
59 "requiredRooms", {}, "housegen.generate"));
60
61 rng.seed(r.seed);
65 static constexpr const char *shapes[] = {"rectangle", "l_shape", "t_shape"};
66 static constexpr const char *roofs[] = {"gable", "flat", "shed"};
69 generated.footprintStyle = r.footprint == "auto" ? shapes[rng() % 3]
70 : r.footprint == "polygon" ? "polygon"
71 : r.footprint;
72 generated.roofStyle = r.roof == "auto" ? roofs[rng() % 3] : r.roof;
73 const SocketDirection entranceDirection = r.entrance == "auto" ? sides[rng() % 4] : directionFromName(r.entrance);
74 generated.entranceSide = directionName(entranceDirection);
75
76 // A multi-floor house needs a vertical stair column through an interior cell.
77 isPolygon = generated.footprintStyle == "polygon";
78 baseMask = makeMask(0);
82
83 if (r.floors > 1 && has(stairs)) {
85 if (!stairwell)
87 eve::DiagnosticCode::Unsupported, "multi-floor house needs an interior cell for a stairwell", {}, {},
88 "housegen.generate"));
89 }
90
92}
93} // namespace eve::housegen::house_detail
int sides
Definition TreeMesh.cpp:459
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
std::vector< std::reference_wrapper< const HouseComponent > > byCategory(std::string_view category, std::string_view style={}) const
按分类(可选风格)查询组件。
bool hasCompletePack(std::string_view style) const
报告一个风格是否构成完整组件包。
std::string footprintStyle
布局风格结果。
Definition HouseLayout.h:30
std::vector< uint8_t > footprintMask
Definition HouseLayout.h:36
float moduleSize
生成参数回显。
Definition HouseLayout.h:27
int footprintWidth
Canonical base-floor occupancy mask owned by this layout.
Definition HouseLayout.h:34
std::string directionName(SocketDirection direction)
std::vector< uint8_t > polygonMask(const std::vector< HousePolygonPoint > &poly, int width, int depth, int inset)
Rasterize an arbitrary closed polygon onto the cell grid (cell centers inside).
bool isOneOf(const std::string &value, std::initializer_list< const char * > options)
SocketDirection directionFromName(const std::string &name)
std::optional< std::pair< int, int > > findInteriorCell(const std::vector< uint8_t > &mask, int width, int depth)
First active cell that is interior (all four orthogonal neighbours active).
bool has(const std::vector< std::reference_wrapper< const HouseComponent > > &values)
std::vector< uint8_t > footprintMask(const std::string &shape, int width, int depth, int inset)
Internal footprintMask stage helper. @cost Linear in plot cells; reuse for one floor emission.
SocketDirection
组件连接点方向(上下 + 四向)。
std::vector< HousePolygonPoint > perimeter
自由轮廓占地顶点(footprint="polygon" 时必填,至少 3 个,角坐标)。
std::vector< std::string > requiredRooms
int maxAttempts
生成重试上限。
std::string footprint
auto | rectangle | l_shape | t_shape | polygon。
std::string roof
auto | gable | flat | shed。
std::string entrance
auto | north | east | south | west。
int width
占地尺寸(格)与层数。
float moduleSize
模块尺寸 / 层高(世界单位)。
std::optional< std::pair< int, int > > stairwell
eve::Result< void > floor(const procgen::Grid2D &grid, const std::vector< std::string > &rooms)
std::vector< uint8_t > makeMask(int ins) const
Internal makeMask stage helper. @cost Linear in plot cells times polygon vertices for polygon footpri...