34 using ChannelMap = std::unordered_map<std::string, std::vector<int>>;
47 std::string
getId()
const {
return id_; }
49 void setId(
const std::string &
id) { id_ =
id; }
56 float getCellSize()
const;
58 void setCellSize(
float s);
61 float getOriginX()
const;
63 float getOriginY()
const;
65 void setOrigin(
float x,
float y);
70 void setFloorHeight(
float height);
79 void setSnapMode(
const std::string &mode) { snapMode_ = mode; }
86 void setExtra(
const std::string &
key,
const std::string &
value);
88 std::string getExtra(
const std::string &
key,
const std::string &fallback = {})
const;
96 void setGridLayout(
const std::string &
layout);
98 std::string getGridLayoutName()
const;
100 void setGridPlane(
const std::string &plane);
102 std::string getGridPlaneName()
const;
104 void setCellGap(
float gapX,
float gapY);
106 void setHexSideLength(
float s);
108 void setStagger(
const std::string &axis,
const std::string &
index);
119 int worldToCellX(
float worldX)
const;
122 int worldToCellY(
float worldY)
const;
124 float cellToWorldX(
int cellX)
const;
126 float cellToWorldY(
int cellY)
const;
129 void cellToWorldPlane(
int cellX,
int cellY,
float &
px,
float &
py)
const;
132 void cellToWorld3D(
int cellX,
int cellY,
float elevation,
float &worldX,
float &worldY,
133 float &worldZ)
const;
135 float cellToWorld3DX(
int cellX,
int cellY,
float elevation)
const;
137 float cellToWorld3DY(
int cellX,
int cellY,
float elevation)
const;
139 float cellToWorld3DZ(
int cellX,
int cellY,
float elevation)
const;
142 void worldToCell3D(
float worldX,
float worldY,
float worldZ,
int &cellX,
int &cellY)
const;
144 int worldToCell3DX(
float worldX,
float worldY,
float worldZ)
const;
146 int worldToCell3DY(
float worldX,
float worldY,
float worldZ)
const;
151 void setTerrain(
int cellX,
int cellY,
int semantic);
154 int getTerrain(
int cellX,
int cellY)
const;
156 bool inBounds(
int cellX,
int cellY)
const;
164 void clearTileLayer();
166 void setTerrainGidMapJson(
const std::string &json);
168 void setTerrainGid(
int gid,
int semantic);
170 void clearTerrainGidMap();
176 int getOccupant(
int cellX,
int cellY)
const;
178 int getOccupantInChannel(
const std::string &channel,
int cellX,
int cellY)
const;
180 int getOccupantAtLevel(
const std::string &channel,
int cellX,
int cellY,
int level)
const;
183 int getAnyOccupant(
int cellX,
int cellY)
const;
185 int getAnyOccupantAtLevel(
int cellX,
int cellY,
int level)
const;
187 bool isCellEmpty(
int cellX,
int cellY)
const;
189 bool isCellEmptyInChannel(
const std::string &channel,
int cellX,
int cellY)
const;
191 int getEdgeOccupant(
const std::string &channel,
int cellX,
int cellY,
194 int getEdgeOccupantAtLevel(
const std::string &channel,
int cellX,
int cellY,
197 bool isEdgeEmpty(
const std::string &channel,
int cellX,
int cellY,
200 int getCornerOccupant(
const std::string &channel,
int vertexX,
int vertexY)
const;
202 int getCornerOccupantAtLevel(
const std::string &channel,
int vertexX,
int vertexY,
205 int getAnyCornerOccupantAtLevel(
int vertexX,
int vertexY,
int level)
const;
207 bool isCornerEmpty(
const std::string &channel,
int vertexX,
int vertexY)
const;
209 int getFreeOccupant(
const std::string &channel,
float worldX,
float worldY)
const;
211 int getFreeOccupantAtLevel(
const std::string &channel,
float worldX,
float worldY,
214 int getEdgeConnectionMask(
int instanceId)
const;
216 std::string getEdgeVariant(
int instanceId)
const;
218 int getBuildingCount()
const;
220 bool hasBuilding(
int instanceId)
const;
222 std::string getBuildingId(
int instanceId)
const;
224 int getBuildingCellX(
int instanceId)
const;
226 int getBuildingCellY(
int instanceId)
const;
228 float getBuildingWorldX(
int instanceId)
const;
230 float getBuildingWorldY(
int instanceId)
const;
233 float getBuildingWorldZ(
int instanceId)
const;
236 float getBuildingElevation(
int instanceId)
const;
238 int getBuildingLevel(
int instanceId)
const;
240 int getBuildingSupportCount(
int instanceId)
const;
242 int getBuildingSupportAt(
int instanceId,
int index)
const;
244 int getBuildingDependentCount(
int instanceId)
const;
246 std::string getBuildingSurfaceId(
int instanceId)
const;
248 int64_t getBuildingSurfaceRevision(
int instanceId)
const;
250 float getBuildingSurfaceNormalX(
int instanceId)
const;
252 float getBuildingSurfaceNormalY(
int instanceId)
const;
254 float getBuildingSurfaceNormalZ(
int instanceId)
const;
256 std::string getBuildingChannel(
int instanceId)
const;
258 float getBuildingRotation(
int instanceId)
const;
260 std::string getBuildingProp(
int instanceId,
const std::string &
key,
261 const std::string &fallback = {})
const;
263 void setBuildingProp(
int instanceId,
const std::string &
key,
const std::string &
value);
265 bool buildingHasTag(
int instanceId,
const std::string &
tag)
const;
267 int getBuildingInstanceAt(
int index)
const;
273 std::vector<EdgeCurveGroupId> edgeCurveGroupIds()
const;
284 bool canPlace(
const std::string &buildingId,
int cellX,
int cellY,
float rotationDeg = 0.f);
286 std::string canPlaceReason(
const std::string &buildingId,
int cellX,
int cellY,
287 float rotationDeg = 0.f);
289 int placeAt(
const std::string &buildingId,
int cellX,
int cellY,
float rotationDeg = 0.f);
291 int placeAtWorld(
const std::string &buildingId,
float worldX,
float worldY,
292 float rotationDeg = 0.f);
294 int placeAtWorld3D(
const std::string &buildingId,
float worldX,
float worldY,
float worldZ,
295 float rotationDeg = 0.f);
297 int placeGhost(
Ghost *ghost);
299 int placeEdge(
const std::string &buildingId,
int cellX,
int cellY,
302 bool canPlaceEdge(
const std::string &buildingId,
int cellX,
int cellY,
305 std::string canPlaceEdgeReason(
const std::string &buildingId,
int cellX,
int cellY,
308 int placeCorner(
const std::string &buildingId,
int vertexX,
int vertexY);
310 bool canPlaceCorner(
const std::string &buildingId,
int vertexX,
int vertexY);
312 std::string canPlaceCornerReason(
const std::string &buildingId,
int vertexX,
int vertexY);
314 int placeFree(
const std::string &buildingId,
float worldX,
float worldY,
315 float elevation = 0.f,
float rotationDeg = 0.f);
317 bool canPlaceFree(
const std::string &buildingId,
float worldX,
float worldY);
319 std::string canPlaceFreeReason(
const std::string &buildingId,
float worldX,
float worldY);
321 bool removeBuilding(
int instanceId);
323 std::string canRemoveBuildingReason(
int instanceId)
const;
328 int removeBuildingCascade(
int instanceId);
330 bool moveBuilding(
int instanceId,
int cellX,
int cellY,
float rotationDeg = -1.f);
332 void clearBuildings();
335 [[nodiscard]] std::unique_ptr<PlacementWorld> cloneState()
const;
341 const std::vector<int> &
occupancy()
const {
return occupancy_; }
345 const std::vector<int> &
terrain()
const {
return terrain_; }
347 std::vector<int> &
terrain() {
return terrain_; }
348 const std::unordered_map<std::string, std::vector<int>> &
allChannels()
const {
351 std::unordered_map<std::string, std::vector<int>> &
allChannels() {
return allChannels_; }
354 std::vector<int> &channelOccupancy(
const std::string &channel);
356 std::vector<int> &channelOccupancy(
const std::string &channel,
int level);
357 const std::unordered_map<int, PlacedBuilding> &
buildings()
const {
return buildings_; }
358 std::unordered_map<int, PlacedBuilding> &
buildings() {
return buildings_; }
363 int terrainFromGid(
int cellX,
int cellY)
const;
382 float floorHeight_ = 3.f;
383 int activeLevel_ = 0;
384 std::unique_ptr<grid::GridConfig> grid_;
385 std::string snapMode_ =
"grid";
386 std::string validateRule_ =
"default";
387 std::vector<int> occupancy_;
388 std::vector<int> terrain_;
389 std::vector<uint8_t> terrainOverrides_;
390 std::unordered_map<std::string, std::vector<int>> allChannels_;
391 std::unordered_map<std::string, std::vector<int>> horizontalEdgeChannels_;
392 std::unordered_map<std::string, std::vector<int>> verticalEdgeChannels_;
393 std::unordered_map<std::string, std::vector<int>> cornerChannels_;
394 std::unordered_map<int, ChannelMap> cellChannelsByLevel_;
395 std::unordered_map<int, ChannelMap> horizontalEdgesByLevel_;
396 std::unordered_map<int, ChannelMap> verticalEdgesByLevel_;
397 std::unordered_map<int, ChannelMap> cornersByLevel_;
398 std::unordered_map<int, PlacedBuilding> buildings_;
399 std::unordered_map<uint64_t, EdgeCurveGroup> edgeCurveGroups_;
400 uint64_t nextEdgeCurveGroupId_ = 1;
401 bool publishEvents_ =
true;
402 std::unordered_map<std::string, std::string> extra_;
403 std::vector<int> instanceOrder_;
407 bool terrainBound_ =
false;
408 std::unordered_map<int, int> terrainGidMap_;