载入中...
搜索中...
未找到
PcgMeshLodBackup.cpp
浏览该文件的文档.
2
4
5#include <optional>
6#include <utility>
7
8namespace eve::procgen {
9
11 std::optional<graphics::Renderable3D::MeshRenderer> renderer;
12 std::uint32_t entityId = 0;
13 std::uint32_t entityGeneration = 0;
14};
15
16PcgMeshLodBackup::PcgMeshLodBackup() : impl_(std::make_unique<Impl>()) {}
19PcgMeshLodBackup& PcgMeshLodBackup::operator=(PcgMeshLodBackup&&) noexcept = default;
20
21Result<void> PcgMeshLodBackup::capture(graphics::Renderable3D& renderable) {
22 Impl candidate;
23 candidate.renderer = *renderable.meshRenderer();
24 candidate.entityId = renderable.getEntityId();
25 candidate.entityGeneration = renderable.getEntityGeneration();
26 *impl_ = std::move(candidate);
27 return Result<void>::success();
28}
29
31 if (!impl_->renderer)
33 DiagnosticCode::NotFound, "Pcg mesh LOD backup is empty", "procgen.pcgMeshLodBackup"));
34 if (renderable.getEntityId() != impl_->entityId ||
35 renderable.getEntityGeneration() != impl_->entityGeneration)
37 DiagnosticCode::Conflict, "Pcg mesh LOD backup belongs to another entity generation",
38 "procgen.pcgMeshLodBackup"));
39 auto restored = *impl_->renderer;
40 *renderable.meshRenderer() = std::move(restored);
41 discard();
42 return Result<void>::success();
43}
44
46 impl_->renderer.reset();
47 impl_->entityId = 0;
48 impl_->entityGeneration = 0;
49}
50
51bool PcgMeshLodBackup::isCaptured() const noexcept { return impl_->renderer.has_value(); }
52std::uint32_t PcgMeshLodBackup::getEntityId() const noexcept { return impl_->entityId; }
53std::uint32_t PcgMeshLodBackup::getEntityGeneration() const noexcept { return impl_->entityGeneration; }
54
55} // namespace eve::procgen
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
EVENGINE_API_BACKENDS public API.
uint32_t getEntityId() const
Return the table-local entity id used with getEntityGeneration().
uint32_t getEntityGeneration() const
Return the generation required to reject stale entity ids.
Caller-owned transactional backup of one Renderable3D renderer before Pcg LOD replacement.
PcgMeshLodBackup()
Pcg mesh lod backup.
void discard() noexcept
Forget the snapshot without changing its entity.
~PcgMeshLodBackup()
Pcg mesh lod backup.
Result< void > restore(graphics::Renderable3D &renderable)
Restore and consume the backup after exact entity-generation validation.
bool isCaptured() const noexcept
Return whether a restorable snapshot is present.
std::uint32_t getEntityGeneration() const noexcept
Return the captured ECS generation, or zero when empty.
std::uint32_t getEntityId() const noexcept
Return the captured table-local entity id, or zero when empty.
std::optional< graphics::Renderable3D::MeshRenderer > renderer