37 using ChannelMap = std::unordered_map<std::string, std::vector<int>>;
50 std::string
getId()
const {
return id_; }
52 void setId(
const std::string &
id) { id_ =
id; }
59 float getCellSize()
const;
61 void setCellSize(
float s);
64 float getOriginX()
const;
66 float getOriginY()
const;
68 void setOrigin(
float x,
float y);
73 void setFloorHeight(
float height);
82 void setSnapMode(
const std::string &mode) { snapMode_ = mode; }
89 void setExtra(
const std::string &
key,
const std::string &
value);
91 std::string getExtra(
const std::string &
key,
const std::string &fallback = {})
const;
99 void setGridLayout(
const std::string &
layout);
101 std::string getGridLayoutName()
const;
103 void setGridPlane(
const std::string &plane);
105 std::string getGridPlaneName()
const;
107 void setCellGap(
float gapX,
float gapY);
109 void setHexSideLength(
float s);
111 void setStagger(
const std::string &
axis,
const std::string &
index);
122 int worldToCellX(
float worldX)
const;
125 int worldToCellY(
float worldY)
const;
127 float cellToWorldX(
int cellX)
const;
129 float cellToWorldY(
int cellY)
const;
132 void cellToWorldPlane(
int cellX,
int cellY,
float &
px,
float &
py)
const;
135 void cellToWorld3D(
int cellX,
int cellY,
float elevation,
float &worldX,
float &worldY,
136 float &worldZ)
const;
138 float cellToWorld3DX(
int cellX,
int cellY,
float elevation)
const;
140 float cellToWorld3DY(
int cellX,
int cellY,
float elevation)
const;
142 float cellToWorld3DZ(
int cellX,
int cellY,
float elevation)
const;
145 void worldToCell3D(
float worldX,
float worldY,
float worldZ,
int &cellX,
int &cellY)
const;
147 int worldToCell3DX(
float worldX,
float worldY,
float worldZ)
const;
149 int worldToCell3DY(
float worldX,
float worldY,
float worldZ)
const;
154 void setTerrain(
int cellX,
int cellY,
int semantic);
157 int getTerrain(
int cellX,
int cellY)
const;
159 bool inBounds(
int cellX,
int cellY)
const;
167 void clearTileLayer();
169 void setTerrainGidMapJson(
const std::string &json);
171 void setTerrainGid(
int gid,
int semantic);
173 void clearTerrainGidMap();
179 int getOccupant(
int cellX,
int cellY)
const;
181 int getOccupantInChannel(
const std::string &channel,
int cellX,
int cellY)
const;
183 int getOccupantAtLevel(
const std::string &channel,
int cellX,
int cellY,
int level)
const;
186 int getAnyOccupant(
int cellX,
int cellY)
const;
188 int getAnyOccupantAtLevel(
int cellX,
int cellY,
int level)
const;
190 bool isCellEmpty(
int cellX,
int cellY)
const;
192 bool isCellEmptyInChannel(
const std::string &channel,
int cellX,
int cellY)
const;
194 int getEdgeOccupant(
const std::string &channel,
int cellX,
int cellY,
197 int getEdgeOccupantAtLevel(
const std::string &channel,
int cellX,
int cellY,
200 bool isEdgeEmpty(
const std::string &channel,
int cellX,
int cellY,
203 int getCornerOccupant(
const std::string &channel,
int vertexX,
int vertexY)
const;
205 int getCornerOccupantAtLevel(
const std::string &channel,
int vertexX,
int vertexY,
208 int getAnyCornerOccupantAtLevel(
int vertexX,
int vertexY,
int level)
const;
210 bool isCornerEmpty(
const std::string &channel,
int vertexX,
int vertexY)
const;
212 int getFreeOccupant(
const std::string &channel,
float worldX,
float worldY)
const;
214 int getFreeOccupantAtLevel(
const std::string &channel,
float worldX,
float worldY,
217 int getEdgeConnectionMask(
int instanceId)
const;
219 std::string getEdgeVariant(
int instanceId)
const;
221 int getBuildingCount()
const;
225 std::string getBuildingId(
int instanceId)
const;
231 float getBuildingWorldX(
int instanceId)
const;
233 float getBuildingWorldY(
int instanceId)
const;
236 float getBuildingWorldZ(
int instanceId)
const;
239 float getBuildingElevation(
int instanceId)
const;
243 int getBuildingSupportCount(
int instanceId)
const;
247 int getBuildingDependentCount(
int instanceId)
const;
249 std::string getBuildingSurfaceId(
int instanceId)
const;
251 int64_t getBuildingSurfaceRevision(
int instanceId)
const;
253 float getBuildingSurfaceNormalX(
int instanceId)
const;
255 float getBuildingSurfaceNormalY(
int instanceId)
const;
257 float getBuildingSurfaceNormalZ(
int instanceId)
const;
259 std::string getBuildingChannel(
int instanceId)
const;
261 float getBuildingRotation(
int instanceId)
const;
263 std::string getBuildingProp(
int instanceId,
const std::string &
key,
264 const std::string &fallback = {})
const;
266 void setBuildingProp(
int instanceId,
const std::string &
key,
const std::string &
value);
268 bool buildingHasTag(
int instanceId,
const std::string &
tag)
const;
270 int getBuildingInstanceAt(
int index)
const;
276 std::vector<EdgeCurveGroupId> edgeCurveGroupIds()
const;
287 bool canPlace(
const std::string &buildingId,
int cellX,
int cellY,
float rotationDeg = 0.f);
289 std::string canPlaceReason(
const std::string &buildingId,
int cellX,
int cellY,
290 float rotationDeg = 0.f);
292 int placeAt(
const std::string &buildingId,
int cellX,
int cellY,
float rotationDeg = 0.f);
294 int placeAtWorld(
const std::string &buildingId,
float worldX,
float worldY,
295 float rotationDeg = 0.f);
297 int placeAtWorld3D(
const std::string &buildingId,
float worldX,
float worldY,
float worldZ,
298 float rotationDeg = 0.f);
300 int placeGhost(
Ghost *ghost);
302 int placeEdge(
const std::string &buildingId,
int cellX,
int cellY,
305 bool canPlaceEdge(
const std::string &buildingId,
int cellX,
int cellY,
308 std::string canPlaceEdgeReason(
const std::string &buildingId,
int cellX,
int cellY,
311 int placeCorner(
const std::string &buildingId,
int vertexX,
int vertexY);
313 bool canPlaceCorner(
const std::string &buildingId,
int vertexX,
int vertexY);
315 std::string canPlaceCornerReason(
const std::string &buildingId,
int vertexX,
int vertexY);
317 int placeFree(
const std::string &buildingId,
float worldX,
float worldY,
318 float elevation = 0.f,
float rotationDeg = 0.f);
320 bool canPlaceFree(
const std::string &buildingId,
float worldX,
float worldY);
322 std::string canPlaceFreeReason(
const std::string &buildingId,
float worldX,
float worldY);
326 std::string canRemoveBuildingReason(
int instanceId)
const;
333 bool moveBuilding(
int instanceId,
int cellX,
int cellY,
float rotationDeg = -1.f);
335 void clearBuildings();
338 [[nodiscard]] std::unique_ptr<PlacementWorld> cloneState()
const;
344 const std::vector<int> &
occupancy()
const {
return occupancy_; }
348 const std::vector<int> &
terrain()
const {
return terrain_; }
350 std::vector<int> &
terrain() {
return terrain_; }
351 const std::unordered_map<std::string, std::vector<int>> &
allChannels()
const {
354 std::unordered_map<std::string, std::vector<int>> &
allChannels() {
return allChannels_; }
357 std::vector<int> &channelOccupancy(
const std::string &channel);
359 std::vector<int> &channelOccupancy(
const std::string &channel,
int level);
360 const std::unordered_map<int, PlacedBuilding> &
buildings()
const {
return buildings_; }
361 std::unordered_map<int, PlacedBuilding> &
buildings() {
return buildings_; }
367 std::unique_ptr<AssemblyState> assemblyState_;
368 int instanceCounter_ = 0;
370 int terrainFromGid(
int cellX,
int cellY)
const;
389 float floorHeight_ = 3.f;
390 int activeLevel_ = 0;
391 std::unique_ptr<grid::GridConfig> grid_;
392 std::string snapMode_ =
"grid";
393 std::string validateRule_ =
"default";
394 std::vector<int> occupancy_;
395 std::vector<int> terrain_;
396 std::vector<uint8_t> terrainOverrides_;
397 std::unordered_map<std::string, std::vector<int>> allChannels_;
398 std::unordered_map<std::string, std::vector<int>> horizontalEdgeChannels_;
399 std::unordered_map<std::string, std::vector<int>> verticalEdgeChannels_;
400 std::unordered_map<std::string, std::vector<int>> cornerChannels_;
401 std::unordered_map<int, ChannelMap> cellChannelsByLevel_;
402 std::unordered_map<int, ChannelMap> horizontalEdgesByLevel_;
403 std::unordered_map<int, ChannelMap> verticalEdgesByLevel_;
404 std::unordered_map<int, ChannelMap> cornersByLevel_;
405 std::unordered_map<int, PlacedBuilding> buildings_;
406 std::unordered_map<uint64_t, EdgeCurveGroup> edgeCurveGroups_;
407 uint64_t nextEdgeCurveGroupId_ = 1;
408 bool publishEvents_ =
true;
409 std::unordered_map<std::string, std::string> extra_;
410 std::vector<int> instanceOrder_;
414 bool terrainBound_ =
false;
415 std::unordered_map<int, int> terrainGidMap_;