载入中...
搜索中...
未找到
PlacementMove.cpp
浏览该文件的文档.
2
4#include "building/Ghost.h"
8#include "common/Diagnostic.h"
10
11#include <algorithm>
12#include <cmath>
13#include <limits>
14#include <unordered_set>
15
16namespace eve::building {
17
18using namespace placement_detail;
19
21 int cellY, float rotationDeg) {
22 if (!world || instanceId <= 0) {
24 eve::DiagnosticCode::InvalidArgument, "move requires a world and positive instance id",
25 std::to_string(instanceId), {}, "building.edit"));
26 }
27 auto it = world->buildings().find(instanceId);
28 if (it == world->buildings().end()) {
30 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "move source instance was not found",
31 std::to_string(instanceId), {}, "building.edit"));
32 }
33
34 PlacedBuilding &pb = it->second;
35 if (hasStructuralDependents(*world, instanceId)) {
37 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "move would invalidate structural dependents",
38 "support_in_use", {}, "building.structure"));
39 }
40 if (pb.placementKind != "cell") {
42 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "cell move cannot target a non-cell instance",
43 std::to_string(instanceId), {}, "building.edit"));
44 }
45 const float rot = (rotationDeg < 0.f) ? pb.rotationDeg : normalizeRotation(pb.buildingId, rotationDeg);
46 std::string reason;
47 if (!canPlaceElev(world, pb.buildingId, cellX, cellY, pb.elevation, rot, instanceId, &reason, pb.level)) {
49 eve::DiagnosticCode::Conflict, "move preflight rejected without mutation", reason, {}, "building.edit"));
50 }
51
53 if (!def) {
55 eve::DiagnosticCode::NotFound, "move definition was not found", pb.buildingId, {}, "building.edit"));
56 }
58 receipt.before = pb;
59
61 ev.action = "move";
62 ev.worldId = world->getId();
63 ev.buildingId = pb.buildingId;
65 ev.otherCellX = pb.originCellX;
66 ev.otherCellY = pb.originCellY;
67 ev.cellX = cellX;
68 ev.cellY = cellY;
69 ev.rotationDeg = rot;
70 float px = 0.f, py = 0.f;
71 world->cellToWorldPlane(cellX, cellY, px, py);
72 ev.worldX = px;
73 ev.worldY = py;
74 ev.elevation = pb.elevation;
75 ev.channel = pb.channel;
76
77 clearOccupancy(*world, instanceId);
78 pb.originCellX = cellX;
79 pb.originCellY = cellY;
80 world->cellToWorldPlane(cellX, cellY, pb.worldX, pb.worldY);
81 pb.rotationDeg = rot;
82 PlacementQuery supportQuery;
83 supportQuery.cellX = pb.originCellX;
84 supportQuery.cellY = pb.originCellY;
85 supportQuery.level = pb.level;
86 supportQuery.rotationDeg = pb.rotationDeg;
87 pb.supportInstanceIds = collectStructuralSupports(*world, *def, supportQuery);
88 writeOccupancy(*world, *def, pb, instanceId);
89 receipt.after = pb;
90 if (world->publishEvents_) emit(std::move(ev));
91 return eve::Result<PlacementEditReceipt>::success(std::move(receipt));
92}
93
95 int cellY, const std::string &direction) {
96 if (!world || instanceId <= 0) {
98 eve::DiagnosticCode::InvalidArgument, "edge move requires a world and positive instance id",
99 std::to_string(instanceId), {}, "building.edit"));
100 }
101 auto it = world->buildings().find(instanceId);
102 if (it == world->buildings().end()) {
104 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "edge move source instance was not found",
105 std::to_string(instanceId), {}, "building.edit"));
106 }
107 PlacedBuilding &pb = it->second;
108 if (pb.placementKind != "edge") {
110 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "edge move requires an edge instance",
111 std::to_string(instanceId), {}, "building.edit"));
112 }
113 if (hasStructuralDependents(*world, instanceId)) {
115 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "edge move would invalidate structural dependents",
116 "support_in_use", {}, "building.structure"));
117 }
118 std::string reason;
119 if (!canPlaceEdge(world, pb.buildingId, cellX, cellY, direction, instanceId, &reason, pb.level)) {
121 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "edge move preflight rejected without mutation",
122 reason, {}, "building.edit"));
123 }
124 auto addressResult = canonicalEdge(cellX, cellY, direction);
125 if (!addressResult.ok()) return eve::Result<PlacementEditReceipt>::failure(addressResult.status());
126 const EdgeAddress target = std::move(addressResult).takeValue();
128 if (!def) {
130 eve::DiagnosticCode::NotFound, "edge move definition was not found", pb.buildingId, {}, "building.edit"));
131 }
132
133 PlacementEditReceipt receipt;
134 receipt.before = pb;
136 event.action = "move";
137 event.worldId = world->getId();
138 event.buildingId = pb.buildingId;
139 event.instanceId = instanceId;
140 event.otherCellX = pb.edge.x;
141 event.otherCellY = pb.edge.y;
142 event.cellX = target.x;
143 event.cellY = target.y;
144 event.channel = pb.channel;
145
146 dissolveEdgeCurveGroup(world, pb.edgeCurveGroupId);
147 clearOccupancy(*world, instanceId);
148 pb.edge = target;
149 pb.originCellX = target.x;
150 pb.originCellY = target.y;
151 float ax = 0.f, ay = 0.f, bx = 0.f, by = 0.f;
152 world->cellToWorldPlane(target.x, target.y, ax, ay);
153 world->cellToWorldPlane(target.x + (target.axis == EdgeAxis::Horizontal ? 1 : 0),
154 target.y + (target.axis == EdgeAxis::Vertical ? 1 : 0), bx, by);
155 pb.worldX = (ax + bx) * 0.5f;
156 pb.worldY = (ay + by) * 0.5f;
157 pb.rotationDeg = target.axis == EdgeAxis::Horizontal ? 0.f : 90.f;
158 auto &channels = world->edgeChannels(target.axis, pb.level);
159 auto &occupancy = channels[def->channel];
160 const size_t required = target.axis == EdgeAxis::Horizontal ? size_t(world->width_) * size_t(world->height_ + 1)
161 : size_t(world->width_ + 1) * size_t(world->height_);
162 if (occupancy.size() != required) occupancy.assign(required, 0);
163 const size_t index = target.axis == EdgeAxis::Horizontal
164 ? size_t(target.y) * size_t(world->width_) + size_t(target.x)
165 : size_t(target.y) * size_t(world->width_ + 1) + size_t(target.x);
166 occupancy[index] = instanceId;
167 event.rotationDeg = pb.rotationDeg;
168 event.worldX = pb.worldX;
169 event.worldY = pb.worldY;
170 event.elevation = pb.elevation;
171 receipt.after = pb;
172 if (world->publishEvents_) emit(std::move(event));
173 return eve::Result<PlacementEditReceipt>::success(std::move(receipt));
174}
175
177 int vertexY) {
178 if (!world || instanceId <= 0) {
180 eve::DiagnosticCode::InvalidArgument, "corner move requires a world and positive instance id",
181 std::to_string(instanceId), {}, "building.edit"));
182 }
183 auto found = world->buildings_.find(instanceId);
184 if (found == world->buildings_.end()) {
186 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "corner move source instance was not found",
187 std::to_string(instanceId), {}, "building.edit"));
188 }
189 PlacedBuilding &placed = found->second;
190 if (placed.placementKind != "corner") {
192 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "corner move requires a corner instance",
193 std::to_string(instanceId), {}, "building.edit"));
194 }
195 if (hasStructuralDependents(*world, instanceId)) {
197 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "corner move would invalidate structural dependents",
198 "support_in_use", {}, "building.structure"));
199 }
200 std::string reason;
201 if (!canPlaceCorner(world, placed.buildingId, vertexX, vertexY, instanceId, &reason, placed.level)) {
203 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "corner move preflight rejected without mutation",
204 reason, {}, "building.edit"));
205 }
206 const BuildingDefinition *definition = BuildingRegistry::find(placed.buildingId);
207 if (!definition) {
209 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "corner move definition was not found",
210 placed.buildingId, {}, "building.edit"));
211 }
212
213 PlacementEditReceipt receipt;
214 receipt.before = placed;
215 clearOccupancy(*world, instanceId);
216 placed.corner = CornerAddress{vertexX, vertexY};
217 placed.originCellX = vertexX;
218 placed.originCellY = vertexY;
219 world->cellToWorldPlane(vertexX, vertexY, placed.worldX, placed.worldY);
220 PlacementQuery query;
221 query.cellX = vertexX;
222 query.cellY = vertexY;
223 query.level = placed.level;
224 placed.supportInstanceIds = collectStructuralSupports(*world, *definition, query);
225 auto &occupancy = world->cornerChannels(placed.level)[definition->channel];
226 const size_t required = size_t(world->width_ + 1) * size_t(world->height_ + 1);
227 if (occupancy.size() != required) occupancy.assign(required, 0);
228 occupancy[size_t(vertexY) * size_t(world->width_ + 1) + size_t(vertexX)] = instanceId;
229 receipt.after = placed;
230
232 event.action = "move";
233 event.worldId = world->getId();
234 event.buildingId = placed.buildingId;
235 event.instanceId = instanceId;
236 event.otherCellX = receipt.before.corner.x;
237 event.otherCellY = receipt.before.corner.y;
238 event.cellX = vertexX;
239 event.cellY = vertexY;
240 event.level = placed.level;
241 event.worldX = placed.worldX;
242 event.worldY = placed.worldY;
243 event.elevation = placed.elevation;
244 event.channel = placed.channel;
245 if (world->publishEvents_) emit(std::move(event));
246 return eve::Result<PlacementEditReceipt>::success(std::move(receipt));
247}
248
250 float worldY, float elevation, float rotationDeg) {
251 if (!world || instanceId <= 0) {
253 eve::DiagnosticCode::InvalidArgument, "free move requires a world and positive instance id",
254 std::to_string(instanceId), {}, "building.edit"));
255 }
256 auto found = world->buildings_.find(instanceId);
257 if (found == world->buildings_.end() || found->second.placementKind != "free") {
259 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "free move source instance was not found",
260 std::to_string(instanceId), {}, "building.edit"));
261 }
262 PlacedBuilding &placed = found->second;
263 std::string reason;
264 if (!canPlaceFree(world, placed.buildingId, worldX, worldY, instanceId, &reason, placed.level, rotationDeg)) {
266 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "free move preflight rejected without mutation",
267 reason, {}, "building.edit"));
268 }
269 PlacementEditReceipt receipt;
270 receipt.before = placed;
271 placed.worldX = worldX;
272 placed.worldY = worldY;
273 placed.elevation = elevation;
274 placed.rotationDeg = normalizeRotation(placed.buildingId, rotationDeg);
275 grid::worldToCell(*world->grid_, worldX, worldY, placed.originCellX, placed.originCellY, world->width_,
276 world->height_);
277 receipt.after = placed;
279 event.action = "move";
280 event.worldId = world->getId();
281 event.buildingId = placed.buildingId;
282 event.instanceId = instanceId;
283 event.cellX = placed.originCellX;
284 event.cellY = placed.originCellY;
285 event.level = placed.level;
286 event.rotationDeg = placed.rotationDeg;
287 event.worldX = placed.worldX;
288 event.worldY = placed.worldY;
289 event.elevation = placed.elevation;
290 event.channel = placed.channel;
291 if (world->publishEvents_) emit(std::move(event));
292 return eve::Result<PlacementEditReceipt>::success(std::move(receipt));
293}
294
296 const SurfacePatch &patch, float rotationDeg) {
297 if (!world || instanceId <= 0) {
299 eve::DiagnosticCode::InvalidArgument, "free surface move requires a world and positive instance id",
300 std::to_string(instanceId), {}, "building.edit"));
301 }
302 auto found = world->buildings_.find(instanceId);
303 if (found == world->buildings_.end() || found->second.placementKind != "free") {
305 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "free surface move source instance was not found",
306 std::to_string(instanceId), {}, "building.edit"));
307 }
308 PlacedBuilding &placed = found->second;
309 const BuildingDefinition *def = BuildingRegistry::find(placed.buildingId);
310 if (!def) {
312 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "free surface move definition was not found",
313 placed.buildingId, {}, "building.edit"));
314 }
315 const float planeX = patch.anchor.worldX;
316 const float planeY = world->getGrid().plane == grid::GridPlane::XZ ? patch.anchor.worldZ : patch.anchor.worldY;
317 const float elevation = world->getGrid().plane == grid::GridPlane::XZ ? patch.anchor.worldY : patch.anchor.worldZ;
318 std::string reason;
319 if (!canPlaceFree(world, placed.buildingId, planeX, planeY, instanceId, &reason, placed.level, rotationDeg) ||
321 (def->maxSurfaceHeightDelta >= 0.f && patch.heightDelta > def->maxSurfaceHeightDelta)) {
322 if (reason.empty())
323 reason = patch.maxSlopeDegrees > def->maxSurfaceSlopeDegrees ? "surface_slope" : "surface_height_delta";
325 eve::DiagnosticCode::Conflict, "free surface move preflight rejected without mutation", reason, {},
326 "building.edit"));
327 }
328
329 PlacementEditReceipt receipt;
330 receipt.before = placed;
331 placed.worldX = planeX;
332 placed.worldY = planeY;
333 placed.elevation = elevation;
334 placed.rotationDeg = normalizeRotation(placed.buildingId, rotationDeg);
335 grid::worldToCell(*world->grid_, planeX, planeY, placed.originCellX, placed.originCellY, world->width_,
336 world->height_);
337 placed.surfaceId = patch.anchor.surfaceId;
338 placed.surfaceRevision = patch.anchor.surfaceRevision;
339 placed.surfaceNormalX = patch.anchor.normalX;
340 placed.surfaceNormalY = patch.anchor.normalY;
341 placed.surfaceNormalZ = patch.anchor.normalZ;
342 placed.surfaceTangentX = patch.anchor.tangentX;
343 placed.surfaceTangentY = patch.anchor.tangentY;
344 placed.surfaceTangentZ = patch.anchor.tangentZ;
345 placed.surfaceSampleCount = static_cast<int>(patch.samples.size());
346 placed.surfaceMaxSlopeDegrees = patch.maxSlopeDegrees;
347 placed.surfaceHeightDelta = patch.heightDelta;
348 receipt.after = placed;
349
351 event.action = "move";
352 event.worldId = world->getId();
353 event.buildingId = placed.buildingId;
354 event.instanceId = instanceId;
355 event.cellX = placed.originCellX;
356 event.cellY = placed.originCellY;
357 event.level = placed.level;
358 event.rotationDeg = placed.rotationDeg;
359 event.worldX = placed.worldX;
360 event.worldY = placed.worldY;
361 event.elevation = placed.elevation;
362 event.channel = placed.channel;
363 if (world->publishEvents_) emit(std::move(event));
364 return eve::Result<PlacementEditReceipt>::success(std::move(receipt));
365}
366
368 const std::string &replacementBuildingId) {
369 if (!world || instanceId <= 0 || replacementBuildingId.empty()) {
372 "replace requires a world, positive instance id and replacement definition",
373 replacementBuildingId, {}, "building.edit"));
374 }
375 auto it = world->buildings().find(instanceId);
376 if (it == world->buildings().end()) {
378 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "replace source instance was not found",
379 std::to_string(instanceId), {}, "building.edit"));
380 }
381 PlacedBuilding &pb = it->second;
382 const BuildingDefinition *replacement = BuildingRegistry::find(replacementBuildingId);
383 if (!replacement) {
385 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "replacement definition was not found",
386 replacementBuildingId, {}, "building.edit"));
387 }
388 const bool sourceEdge = pb.placementKind == "edge";
389 const bool sourceCorner = pb.placementKind == "corner";
390 const bool sourceFree = pb.placementKind == "free";
391 if (pb.placementKind != replacement->placementKind) {
393 eve::DiagnosticCode::InvalidArgument, "replacement must use the same placement domain as the source",
394 replacementBuildingId, {}, "building.edit"));
395 }
396 if (hasStructuralDependents(*world, instanceId) &&
397 !replacementPreservesStructuralDependents(*world, instanceId, *replacement)) {
399 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "replace would invalidate structural dependents",
400 "support_in_use", {}, "building.structure"));
401 }
402
403 std::string reason;
404 if (sourceEdge) {
405 const char *direction = pb.edge.axis == EdgeAxis::Horizontal ? "north" : "west";
406 if (!canPlaceEdge(world, replacementBuildingId, pb.edge.x, pb.edge.y, direction, instanceId, &reason,
407 pb.level)) {
409 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "replace preflight rejected without mutation",
410 reason, {}, "building.edit"));
411 }
412 } else if (sourceCorner) {
413 if (!canPlaceCorner(world, replacementBuildingId, pb.corner.x, pb.corner.y, instanceId, &reason, pb.level)) {
415 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "replace preflight rejected without mutation",
416 reason, {}, "building.edit"));
417 }
418 } else if (sourceFree) {
419 if (!canPlaceFree(world, replacementBuildingId, pb.worldX, pb.worldY, instanceId, &reason, pb.level,
420 pb.rotationDeg)) {
422 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "replace preflight rejected without mutation",
423 reason, {}, "building.edit"));
424 }
425 } else if (!canPlaceElev(world, replacementBuildingId, pb.originCellX, pb.originCellY, pb.elevation, pb.rotationDeg,
426 instanceId, &reason, pb.level)) {
428 eve::DiagnosticCode::Conflict, "replace preflight rejected without mutation", reason, {}, "building.edit"));
429 }
430
431 PlacementEditReceipt receipt;
432 receipt.before = pb;
434 event.action = "replace";
435 event.worldId = world->getId();
436 event.otherBuildingId = pb.buildingId;
437 event.buildingId = replacementBuildingId;
438 event.instanceId = instanceId;
439 event.otherCellX = pb.originCellX;
440 event.otherCellY = pb.originCellY;
441
442 dissolveEdgeCurveGroup(world, pb.edgeCurveGroupId);
443 clearOccupancy(*world, instanceId);
444 pb.buildingId = replacementBuildingId;
445 pb.placementKind = replacement->placementKind;
446 pb.channel = replacement->channel;
447 pb.tags = replacement->tags;
448 if (sourceFree) {
449 applyDefinitionFreeFootprint(pb, *replacement, *world);
450 }
451 pb.rotationDeg = sourceEdge ? pb.rotationDeg : normalizeRotation(replacementBuildingId, pb.rotationDeg);
452 if (sourceEdge) {
453 pb.supportInstanceIds.clear();
454 auto &channels = world->edgeChannels(pb.edge.axis, pb.level);
455 auto &occupancy = channels[replacement->channel];
456 const size_t required = pb.edge.axis == EdgeAxis::Horizontal
457 ? size_t(world->width_) * size_t(world->height_ + 1)
458 : size_t(world->width_ + 1) * size_t(world->height_);
459 if (occupancy.size() != required) occupancy.assign(required, 0);
460 const size_t index = pb.edge.axis == EdgeAxis::Horizontal
461 ? size_t(pb.edge.y) * size_t(world->width_) + size_t(pb.edge.x)
462 : size_t(pb.edge.y) * size_t(world->width_ + 1) + size_t(pb.edge.x);
463 occupancy[index] = instanceId;
464 } else if (sourceCorner) {
465 PlacementQuery supportQuery;
466 supportQuery.cellX = pb.corner.x;
467 supportQuery.cellY = pb.corner.y;
468 supportQuery.level = pb.level;
469 pb.supportInstanceIds = collectStructuralSupports(*world, *replacement, supportQuery);
470 auto &occupancy = world->cornerChannels(pb.level)[replacement->channel];
471 const size_t required = size_t(world->width_ + 1) * size_t(world->height_ + 1);
472 if (occupancy.size() != required) occupancy.assign(required, 0);
473 occupancy[size_t(pb.corner.y) * size_t(world->width_ + 1) + size_t(pb.corner.x)] = instanceId;
474 } else {
475 PlacementQuery supportQuery;
476 supportQuery.cellX = pb.originCellX;
477 supportQuery.cellY = pb.originCellY;
478 supportQuery.level = pb.level;
479 supportQuery.rotationDeg = pb.rotationDeg;
480 pb.supportInstanceIds = collectStructuralSupports(*world, *replacement, supportQuery);
481 writeOccupancy(*world, *replacement, pb, instanceId);
482 }
483 event.cellX = pb.originCellX;
484 event.cellY = pb.originCellY;
485 event.rotationDeg = pb.rotationDeg;
486 event.worldX = pb.worldX;
487 event.worldY = pb.worldY;
488 event.elevation = pb.elevation;
489 event.channel = pb.channel;
490 receipt.after = pb;
491 if (world->publishEvents_) emit(std::move(event));
492 return eve::Result<PlacementEditReceipt>::success(std::move(receipt));
493}
494
496 if (!world) return;
497 // Collect ids first so remove events fire consistently.
498 std::vector<int> ids = world->instanceOrder_;
499 for (int id : ids)
500 if (world->hasBuilding(id)) removeBuildingCascade(world, id);
501 world->buildings().clear();
502 world->edgeCurveGroups_.clear();
503 world->instanceOrder_.clear();
504 for (auto &kv : world->allChannels()) {
505 std::fill(kv.second.begin(), kv.second.end(), 0);
506 }
507 for (auto &kv : world->horizontalEdgeChannels_) std::fill(kv.second.begin(), kv.second.end(), 0);
508 for (auto &kv : world->verticalEdgeChannels_) std::fill(kv.second.begin(), kv.second.end(), 0);
509 world->cellChannelsByLevel_.clear();
510 world->horizontalEdgesByLevel_.clear();
511 world->verticalEdgesByLevel_.clear();
512}
513
514} // namespace eve::building
LogicalId target
std::map< std::string, std::vector< Key >, std::less<> > channels
Stable, structured diagnostics shared by engine modules.
int instanceId
Pure cell/world projection helpers for GridConfig.
float elevation
std::vector< Colorf > px
bool required
RoadLaneDirection direction
bool found
bool placed
uint32_t index
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
static const BuildingDefinition * find(const std::string &id)
Finds .
Definition Building.cpp:557
static eve::Result< PlacementEditReceipt > moveFreeSurfaceResult(PlacementWorld *world, int instanceId, const SurfacePatch &patch, float rotationDeg)
Atomically move a free-domain instance and replace its surface attachment.
static int removeBuildingCascade(PlacementWorld *world, int instanceId)
Compatibility-only count projection; prefer removeBuildingCascadeResult in C++.
static void clearBuildings(PlacementWorld *world)
static eve::Result< PlacementEditReceipt > moveCornerResult(PlacementWorld *world, int instanceId, int vertexX, int vertexY)
Atomically move a corner-domain instance to another grid vertex.
static bool canPlaceFree(PlacementWorld *world, const std::string &buildingId, float worldX, float worldY, int excludeInstanceId=0, std::string *reason=nullptr, int level=std::numeric_limits< int >::min(), float rotationDeg=0.f)
Validate an exact free-domain world-plane anchor and circular or oriented-box footprint.
static float normalizeRotation(const std::string &buildingId, float rotationDeg)
规范化旋转角(cardinal → 0/90/180/270;none → 0)。
static eve::Result< PlacementEditReceipt > moveFreeResult(PlacementWorld *world, int instanceId, float worldX, float worldY, float elevation, float rotationDeg)
Atomically move a free-domain instance to an exact world-plane anchor.
static eve::Result< PlacementEditReceipt > replaceBuildingResult(PlacementWorld *world, int instanceId, const std::string &replacementBuildingId)
Atomically replace an instance definition at its current cell or edge address.
static eve::Result< PlacementEditReceipt > moveEdgeResult(PlacementWorld *world, int instanceId, int cellX, int cellY, const std::string &direction)
Atomically move an edge-domain instance to a canonical grid edge.
static bool canPlaceCorner(PlacementWorld *world, const std::string &buildingId, int vertexX, int vertexY, int excludeInstanceId=0, std::string *reason=nullptr, int level=std::numeric_limits< int >::min())
Validate a corner-domain placement at one canonical grid vertex.
static bool canPlaceElev(PlacementWorld *world, const std::string &buildingId, int cellX, int cellY, float elevation, float rotationDeg=0.f, int excludeInstanceId=0, std::string *reason=nullptr, int level=std::numeric_limits< int >::min())
static eve::Result< PlacementEditReceipt > moveBuildingResult(PlacementWorld *world, int instanceId, int cellX, int cellY, float rotationDeg=-1.f)
Atomically move a cell-domain instance while preserving its identity and state.
static eve::Result< EdgeAddress > canonicalEdge(int cellX, int cellY, const std::string &direction)
Normalize a cell-relative cardinal direction to a unique edge address.
static bool canPlaceEdge(PlacementWorld *world, const std::string &buildingId, int cellX, int cellY, const std::string &direction, int excludeInstanceId=0, std::string *reason=nullptr, int level=std::numeric_limits< int >::min())
Validate an edge-domain placement without mutating the world.
格子型建筑放置世界(脚本可直接操作)。
std::unordered_map< const void *, size_t > ids
Definition Snapshot.cpp:109
void applyDefinitionFreeFootprint(PlacedBuilding &placed, const BuildingDefinition &definition, const PlacementWorld &world)
建筑放置模块入口:定义 / 放置世界 / 鬼影 / 变更事件的脚本绑定点。 设计文档:docs/dev/建筑放置系统设计.md
Definition Building.cpp:10
void worldToCell(const GridConfig &cfg, float px, float py, int &cx, int &cy, int mapW, int mapH)
Maps planar coordinates to the nearest cell. Staggered/hex layouts use a bounded nearest-neighbor sea...
一次成功放置变更的事件(供脚本 poll / C++ hook)。
std::string action
place / remove / move / rotate
建筑模板(进程级注册表中的定义)。
std::string placementKind
Placement domain: cell (default), edge, corner, or free.
std::string channel
占地格子尺寸。
float maxSurfaceHeightDelta
Maximum elevation range across a sampled footprint; negative disables it.
float maxSurfaceSlopeDegrees
Maximum angle between a footprint normal and the grid-plane up axis.
std::vector< std::string > tags
Canonical address of one logical grid vertex used by corner objects.
Canonical address of one grid edge.
已放置的建筑实例。
std::vector< std::string > tags
EdgeAddress edge
Canonical edge address when placementKind is edge.
EdgeCurveGroupId edgeCurveGroupId
Optional link to a world-owned curve group; zero means an ordinary edge.
int level
Authoritative discrete floor coordinate used by occupancy and topology.
std::string placementKind
Placement domain snapshot: cell, edge, corner, or free.
std::vector< int > supportInstanceIds
Derived support links rebuilt from authoritative level/address data.
CornerAddress corner
Canonical grid vertex when placementKind is corner.
Owning before/after receipt produced by one committed placement edit.
校验上下文:传给可插拔规则。
int level
Discrete floor whose occupancy and adjacency are queried.
Surface samples and continuity metrics for one rotated building footprint.
std::vector< SurfacePatchSample > samples