载入中...
搜索中...
未找到
HouseGenRuntime.cpp
浏览该文件的文档.
2
6
7#include <set>
8#include <utility>
9
11
14
16 const auto diagnostics = document.validate();
17 for (const auto& diagnostic : diagnostics)
18 if (diagnostic.severity() == DiagnosticSeverity::Error)
19 return Result<void>::failure(eve::Status(EditorStatus::Rejected, diagnostics));
20 auto library = std::make_unique<housegen::HouseComponentLibrary>();
21 std::set<std::string> categories;
22 for (const auto& component : document.components()) {
23 auto registered = library->registerComponent(component.component);
24 if (!registered.ok()) return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.housegen.runtime-component"), "House runtime rejected an authored component");
25 categories.insert(component.component.category);
26 }
27 for (const char* required : {"foundation","floor","wall","door","roof"})
28 if (!categories.contains(required))
29 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.housegen.runtime-category"), "House kit is missing required category: "+std::string(required));
30 auto layout = std::make_unique<housegen::HouseLayout>();
32 auto generated = generator.generate(document.request(), *layout);
33 if (!generated.ok()) return eve::editing::failed<void>(EditorStatus::Failed, RuleId("editor.housegen.generate"), "House generator rejected the candidate kit or request");
34 library_=std::move(library); layout_=std::move(layout); revision_=document.revision();
35 return eve::editing::applied<void>(diagnostics);
36}
37
39 if (expectedRevision!=revision_) return eve::editing::failed<EditorGizmoSnapshot>(EditorStatus::Conflict, RuleId("editor.housegen.stale"), "House preview generation is stale");
40 if (!layout_||!library_) return eve::editing::failed<EditorGizmoSnapshot>(EditorStatus::NotFound, RuleId("editor.housegen.preview"), "House preview has no generated layout");
41 EditorGizmoSnapshot snapshot;snapshot.status=EditorStatus::Applied;snapshot.target="housegen-preview";snapshot.targetRevision=revision_;
42 if (layout_->instances.size()>200000) return eve::editing::failed<EditorGizmoSnapshot>(EditorStatus::Rejected, RuleId("editor.housegen.preview-budget"), "House layout exceeds 200000 preview instances");
43 for (std::size_t index=0;index<layout_->instances.size();++index){const auto& instance=layout_->instances[index];const auto component=library_->find(instance.componentId);if(!component)continue;const auto& c=component->get();const bool quarter=((instance.rotationDeg/90)&1)!=0;EditorGizmoPrimitive p;p.id="component:"+std::to_string(index);p.kind="box";p.position={(instance.x+(quarter?c.depth:c.width)*.5)*layout_->moduleSize,(instance.z*c.height+.5*c.height)*layout_->floorHeight,(instance.y+(quarter?c.width:c.depth)*.5)*layout_->moduleSize};p.size={(quarter?c.depth:c.width)*layout_->moduleSize,c.height*layout_->floorHeight,(quarter?c.width:c.depth)*layout_->moduleSize};if(c.category=="door")p.color={.2,1,.4,.8};else if(c.category=="roof")p.color={1,.5,.2,.65};else if(c.category=="foundation")p.color={.5,.5,.5,.6};else p.color={.2,.7,1,.5};snapshot.primitives.push_back(std::move(p));}
44 for(std::size_t index=0;index<layout_->rooms.size();++index){const auto& room=layout_->rooms[index];EditorGizmoPrimitive p;p.id="room:"+std::to_string(index);p.kind="area";p.position={(room.x+room.width*.5)*layout_->moduleSize,.02,(room.y+room.depth*.5)*layout_->moduleSize};p.size={room.width*layout_->moduleSize,.01,room.depth*layout_->moduleSize};p.color={.8,.2,1,.25};snapshot.primitives.push_back(std::move(p));}
45 return eve::editing::applied<EditorGizmoSnapshot>(std::move(snapshot));
46}
47
48} // namespace eve::housegen_editing
glm::vec4 p[6]
std::int32_t c
bool required
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Structured status and zero or more diagnostics for an operation.
Definition Status.h:68
std::uint64_t revision() const override
Return the current revision.
eve::Result< void > registerComponent(const HouseComponent &component)
注册单个组件(id 重复会报错)。
布局生成器:把 HouseRequest 解析为 HouseLayout(组件库驱动)。
eve::Result< void > generate(const HouseRequest &request, HouseLayout &out) const
生成布局;失败时不修改输出布局并返回结构化诊断。
Revisioned component-kit and deterministic generation-request asset.
const housegen::HouseRequest & request() const
Request.
const std::vector< HouseKitComponentValue > & components() const
Components.
std::vector< EditorDiagnostic > validate() const
Validate kit fields, generator-required categories and request budgets.
Result< void > publish(const HouseGenDocumentTarget &document)
Generate entirely in temporary state before replacing the active preview.
HouseGenPreviewRuntime()
House gen preview runtime.
Result< EditorGizmoSnapshot > gizmo(Revision expectedRevision) const
Build grid cells, component bounds and room overlays for the active generation.
const housegen::HouseLayout * layout() const
Access the published layout.
~HouseGenPreviewRuntime()
House gen preview runtime.
const housegen::HouseComponentLibrary * library() const
Access the published component library.
editing::RuleId RuleId
editing::Revision Revision
Renderer-neutral wire primitive for authoring viewport overlays.
Immutable revision-tagged overlay snapshot consumed by any viewport renderer.
std::vector< GizmoPrimitive > primitives