载入中...
搜索中...
未找到
ContainerAdapters.cpp
浏览该文件的文档.
44 const auto* payload = dynamic_cast<const BuildingGarrisonContainerObject*>(object.payload.get());
60 if (lhs.id != rhs.id || lhs.revision != rhs.revision || lhs.entries.size() != rhs.entries.size()) return false;
66 left.membership.generation != right->membership.generation || left.object.id != right->object.id ||
90 event.payload = "{\"containerId\":" + quote(container.value()) + ",\"objectId\":" + quote(object.value()) +
98void notify(const eve::container::GameEventSink& sink, const eve::container::ContainerId& container,
100 eve::container::SlotIndex slot, eve::Revision revision, std::uint64_t serial, eve::SimulationTick tick,
116 eve::DiagnosticCode::CallbackFailure, "container membership committed but an event observer threw"));
125class BuildingGarrisonContainerAdapter::PreparedState final : public eve::container::IContainer::PreparedState {
159BuildingGarrisonContainerAdapter::BuildingGarrisonContainerAdapter(eve::container::ContainerId id,
191eve::container::ContainerObject BuildingGarrisonContainerAdapter::describe(const GarrisonMember& member) {
203eve::Result<eve::container::ContainerSnapshot> BuildingGarrisonContainerAdapter::snapshot() const {
207 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "building garrison adapter is stale or unbound"));
208 if (!descriptor_.capacity.isUnlimited() && value->garrison.size() > descriptor_.capacity.value())
217 eve::DiagnosticCode::InvariantViolation, "building garrison has too many indexed memberships"));
225 {{id, eve::container::SlotIndex(static_cast<std::int32_t>(index)), eve::Generation(1)}, describe(member)});
231 const eve::container::ContainerObject& object, std::optional<eve::container::SlotIndex> destination,
236 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "building garrison adapter is stale or unbound"));
239 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "building garrison object facts are invalid"));
243 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "building garrison payload is stale"));
247 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "building garrison already contains member"));
255 if (destination && (!destination->isValid() || static_cast<std::size_t>(destination->value()) > effectiveSize))
257 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "building garrison slot is out of range"));
266eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>> BuildingGarrisonContainerAdapter::prepare(
267 const eve::container::ContainerSnapshot& expected, const eve::container::ContainerSnapshot& candidate) {
271 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "building garrison adapter is stale or unbound"));
273 return eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>>::failure(eve::Diagnostic::error(
277 return eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>>::failure(current.status());
280 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "building garrison expected snapshot is stale"));
283 return eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>>::failure(eve::Diagnostic::error(
284 eve::DiagnosticCode::InvariantViolation, "building garrison candidate revision is not the next revision"));
285 if (!descriptor_.capacity.isUnlimited() && candidate.entries.size() > descriptor_.capacity.value())
287 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "building garrison candidate exceeds capacity"));
295 entry.membership.slot.value() != static_cast<std::int32_t>(index) || entry.membership.generation.isZero() ||
310 std::make_unique<PreparedState>(*this, std::move(staged), expected.revision, expected.entries.size(), *next);
311 return eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>>::success(std::move(prepared));
314eve::Result<eve::container::MembershipId> BuildingGarrisonContainerAdapter::enter(std::string memberId,
350 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "building garrison revision exhausted"));
353 eve::container::SlotIndex::invalid(), candidate.revision, serial, tick, "revision_exhausted", ignored);
358 {{objectId, eve::container::SlotIndex(static_cast<std::int32_t>(current.value().entries.size())),
375 notify(sink, descriptor_.id, objectId, eve::container::ContainerEventKind::Accepted, slot, *next, serial, tick, {},
377 notify(sink, descriptor_.id, objectId, eve::container::ContainerEventKind::Enter, slot, *next, serial, tick, {},
379 return eve::Result<eve::container::MembershipId>::success(objectId, appliedStatus(callbackFailed));
382eve::Result<eve::container::MembershipId> BuildingGarrisonContainerAdapter::exit(eve::container::MembershipId memberId,
402 notify(sink, descriptor_.id, memberId, eve::container::ContainerEventKind::Rejected, slot, revision(), serial,
411 candidate.entries[index].membership.slot = eve::container::SlotIndex(static_cast<std::int32_t>(index));
415 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "building garrison revision exhausted"));
428 current.value().revision, serial, tick, diagnostic == nullptr ? "prepare_failed" : diagnostic->message(),
435 notify(sink, descriptor_.id, memberId, eve::container::ContainerEventKind::Accepted, slot, *next, serial, tick, {},
437 notify(sink, descriptor_.id, memberId, eve::container::ContainerEventKind::Exit, slot, *next, serial, tick, {},
439 return eve::Result<eve::container::MembershipId>::success(memberId, appliedStatus(callbackFailed));
Building adapters for the common Container/Zone/Transfer protocol.
static Diagnostic warning(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct a warning diagnostic.
Definition Diagnostic.h:134
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
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:36
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Status failure(StatusCode code, Diagnostic diagnostic)
Construct a failed status with one diagnostic.
Definition Status.h:84
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
void rollback() noexcept override
Abandon an unpublished stage; the operation is non-throwing.
Definition ContainerAdapters.cpp:146
void commit() noexcept override
Publish the staged state; the operation is non-throwing.
Definition ContainerAdapters.cpp:135
PreparedState(BuildingGarrisonContainerAdapter &owner, std::vector< GarrisonMember > staged, eve::Revision expectedRevision, std::size_t expectedSize, eve::Revision revision)
Definition ContainerAdapters.cpp:127
Transactional adapter over one placed building's authoritative garrison.
Definition ContainerAdapters.h:36
eve::Result< eve::container::MembershipId > exit(eve::container::MembershipId memberId, eve::container::GameEventSink sink={}, eve::SimulationTick tick=eve::SimulationTick::zero())
Stage and publish removal of one member.
Definition ContainerAdapters.cpp:382
eve::Result< eve::container::ContainerSnapshot > snapshot() const override
Snapshot.
Definition ContainerAdapters.cpp:203
eve::Revision revision() const noexcept
Return the authoritative garrison revision, or zero when stale.
Definition ContainerAdapters.cpp:181
BuildingGarrisonContainerAdapter(eve::container::ContainerId id, PlacementWorld *world, int instanceId, eve::container::Capacity capacity=eve::container::Capacity::unlimited(), eve::container::AcceptedCondition accepted={})
Binds an adapter to a placed building.
Definition ContainerAdapters.cpp:159
eve::Result< std::unique_ptr< eve::container::IContainer::PreparedState > > prepare(const eve::container::ContainerSnapshot &expected, const eve::container::ContainerSnapshot &candidate) override
Prepare an exact replacement from expected to candidate.
Definition ContainerAdapters.cpp:266
eve::Result< void > validateInsert(const eve::container::ContainerObject &object, std::optional< eve::container::SlotIndex > destination, std::optional< eve::container::MembershipId > ignoredObject=std::nullopt) const override
Validate insert.
Definition ContainerAdapters.cpp:230
eve::Result< eve::container::MembershipId > enter(std::string memberId, std::string type="building.garrison.member", std::vector< std::string > tags={}, eve::container::GameEventSink sink={}, eve::SimulationTick tick=eve::SimulationTick::zero())
Stage and publish a new garrison member.
Definition ContainerAdapters.cpp:314
const std::unordered_map< int, PlacedBuilding > & buildings() const
Definition PlacementWorld.h:357
Non-negative capacity measured in membership slots.
Definition Container.h:92
constexpr std::size_t value() const noexcept
Definition Container.h:99
constexpr bool isUnlimited() const noexcept
Definition Container.h:98
Strong identity of one runtime or persistent container.
Definition Container.h:44
bool isValid() const noexcept
Return whether this ID is usable by a transfer request.
Definition Container.h:58
const std::string & value() const noexcept
Return the owned stable spelling.
Definition Container.h:60
Extensible filter result used by container and zone acceptance rules.
Definition Container.h:139
Result< void > evaluate(const struct ContainerObject &object) const
Evaluate the filter; an empty filter accepts every object.
Definition Container.h:149
Detached state prepared for an atomic container replacement.
Definition Container.h:296
Strong identity of an object which can have one container membership.
Definition Container.h:68
static std::optional< MembershipId > from(std::string_view value)
Construct a valid membership ID, rejecting an empty value.
Definition Container.h:76
Explicit slot number; it never implicitly converts to an integer.
Definition Container.h:117
constexpr std::optional< StrongUint64 > incremented() const noexcept
Returns the next value, or empty instead of unsigned wraparound.
Definition StrongUint64.h:30
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
Definition StrongUint64.h:24
建筑放置模块入口:定义 / 放置世界 / 鬼影 / 变更事件的脚本绑定点。 设计文档:docs/dev/建筑放置系统设计.md
Definition Building.cpp:7
constexpr std::string_view containerEventSchemaName
Canonical schema name for container lifecycle envelopes.
Definition Container.h:232
ContainerEventKind
Lifecycle outcome represented by every container-domain event.
Definition Container.h:205
const char * containerEventTypeName(ContainerEventKind kind) noexcept
Stable event type spelling shared by all container adapters.
Definition Container.h:221
std::function< void(const game_event::GameEvent &)> GameEventSink
Callback receiving a canonical game_event envelope.
Definition Container.h:245
EventId deterministicContainerEventId(const ContainerId &container, const MembershipId &object, ContainerEventKind kind, std::uint64_t serial) noexcept
Derives a deterministic event identity for an adapter lifecycle event.
Definition Container.h:257
@ InvalidArgument
@ NotFound
@ CallbackFailure
@ InvariantViolation
@ StaleHandle
@ Conflict
detail::StrongUint64< detail::GenerationTag > Generation
Registry/object replacement generation used to reject stale handles.
Definition Generation.h:13
@ Applied
detail::StrongUint64< detail::SchemaVersionTag > SchemaVersion
Persistent data-format version; not a runtime replacement generation.
Definition SchemaVersion.h:13
Definition Container.h:602
One persistent member of a placed building's logical garrison.
Definition BuildingTypes.h:177
Generic object facts used by filters and transfer diagnostics.
Definition Container.h:168
Lossless snapshot of one container at one revision.
Definition Container.h:190
std::vector< MembershipEntry > entries
Definition Container.h:193