载入中...
搜索中...
未找到
HouseGenerationState.h
浏览该文件的文档.
1#pragma once
4
5#include <algorithm>
6#include <cmath>
7#include <functional>
8#include <optional>
9#include <random>
10#include <tuple>
11#include <unordered_map>
12#include <unordered_set>
13#include <utility>
14
22const HouseComponent* pick(const std::vector<std::reference_wrapper<const HouseComponent>>& choices, std::mt19937& rng);
23bool has(const std::vector<std::reference_wrapper<const HouseComponent>>& values);
24bool isRotationAllowed(const HouseComponent& component, int rotation);
28std::vector<std::reference_wrapper<const HouseComponent>> facadeVariant(
29 const std::vector<std::reference_wrapper<const HouseComponent>>& choices, bool wantWindow);
30bool isOneOf(const std::string& value, std::initializer_list<const char*> options);
31SocketDirection directionFromName(const std::string& name);
37std::vector<uint8_t> footprintMask(const std::string& shape, int width, int depth, int inset);
38bool active(const std::vector<uint8_t>& mask, int width, int depth, int x, int y);
42std::vector<uint8_t> polygonMask(const std::vector<HousePolygonPoint>& poly, int width, int depth, int inset);
46std::vector<std::reference_wrapper<const HouseComponent>> compatibleOnFace(
47 const std::vector<std::reference_wrapper<const HouseComponent>>& choices, SocketDirection face, int rotation);
51std::optional<std::pair<int, int>> findInteriorCell(const std::vector<uint8_t>& mask, int width, int depth);
52void appendRoomRegions(int width, int depth, const std::vector<uint8_t>& mask, const std::string& roomType, int floorZ,
53 std::vector<HouseRoom>& rooms);
54eve::Result<void> partitionFloor(int width, int depth, const std::vector<uint8_t>& mask,
55 const std::vector<std::string>& roomTypes, std::mt19937& rng,
56 const std::vector<std::reference_wrapper<const HouseComponent>>& innerWall,
57 const std::vector<std::reference_wrapper<const HouseComponent>>& innerDoor,
58 std::vector<HouseInstance>& instances, std::vector<HouseRoom>& rooms, int floorZ);
59
60struct State {
64 std::mt19937 rng;
65 bool isPolygon = false;
66 std::vector<uint8_t> baseMask, previousMask;
67 std::optional<std::pair<int, int>> stairwell;
68 std::optional<procgen::Grid2D> planned;
69 int inset = 0, z = 0;
70 [[nodiscard]] eve::Result<void> configure();
71 [[nodiscard]] eve::Result<void> plan();
72 [[nodiscard]] eve::Result<void> floor(const procgen::Grid2D& grid, const std::vector<std::string>& rooms);
73 [[nodiscard]] eve::Result<void> finish();
77 [[nodiscard]] std::vector<uint8_t> makeMask(int ins) const;
78};
79} // namespace eve::housegen::house_detail
double y
double x
bool & active
int mask
std::string name
Definition ECS.cpp:154
ShaderImageInput shape
std::uint32_t width
std::array< float, 4 > rotation
std::set< std::string > choices
std::set< std::string > values
Object::Ptr value
RoadLaneDirection direction
const SquirrelValueOptions & options
std::uint32_t depth
Move-only operation result carrying either a value or Status.
Definition Result.h:176
房屋组件注册表(按 id 索引,支持分类/风格查询)。
一次生成的房屋布局:实例 + 房间 + 元信息,可 JSON 序列化 / 实例化。
Definition HouseLayout.h:23
Intermediate 2D generation result. cells store semantic ids (see Semantic.h), not tile GIDs — convert...
Definition Grid2D.h:37
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).
void appendRoomRegions(int width, int depth, const std::vector< uint8_t > &mask, const std::string &roomType, int floorZ, std::vector< HouseRoom > &rooms)
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).
std::vector< std::reference_wrapper< const HouseComponent > > compatibleOnFace(const std::vector< std::reference_wrapper< const HouseComponent > > &choices, SocketDirection face, int rotation)
Internal compatibleOnFace stage helper. @cost Component choices times sockets; used for one facade pl...
int directionRotation(SocketDirection direction)
eve::Result< void > partitionFloor(int width, int depth, const std::vector< uint8_t > &mask, const std::vector< std::string > &roomTypes, std::mt19937 &rng, const std::vector< std::reference_wrapper< const HouseComponent > > &innerWall, const std::vector< std::reference_wrapper< const HouseComponent > > &innerDoor, std::vector< HouseInstance > &instances, std::vector< HouseRoom > &rooms, int floorZ)
Partition active cells into exact, rectangular rooms and emit mask-safe boundaries.
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.
bool isRotationAllowed(const HouseComponent &component, int rotation)
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...
std::vector< std::reference_wrapper< const HouseComponent > > facadeVariant(const std::vector< std::reference_wrapper< const HouseComponent > > &choices, bool wantWindow)
Internal facadeVariant stage helper. @cost Linear in component choices; amortized across one facade p...
SocketDirection
组件连接点方向(上下 + 四向)。
一次房屋生成请求(参数集)。
std::optional< std::pair< int, int > > stairwell
eve::Result< void > floor(const procgen::Grid2D &grid, const std::vector< std::string > &rooms)
std::optional< procgen::Grid2D > planned
std::vector< uint8_t > makeMask(int ins) const
Internal makeMask stage helper. @cost Linear in plot cells times polygon vertices for polygon footpri...