载入中...
搜索中...
未找到
ContainerAdapters.cpp
浏览该文件的文档.
69 eve::container::MembershipId(std::string(kOccupantPrefix) + std::to_string(payload->occupantId));
76 if (lhs.id != rhs.id || lhs.revision != rhs.revision || lhs.entries.size() != rhs.entries.size()) return false;
82 left.membership.generation != right->membership.generation || left.object.id != right->object.id ||
105 event.payload = "{\"containerId\":" + quote(container.value()) + ",\"objectId\":" + quote(object.value()) +
113void notify(const eve::container::GameEventSink& sink, const eve::container::ContainerId& container,
115 eve::container::SlotIndex slot, eve::Revision revision, std::uint64_t serial, eve::SimulationTick tick,
131 eve::DiagnosticCode::CallbackFailure, "container membership committed but an event observer threw"));
140class VehicleSeatContainerAdapter::PreparedState final : public eve::container::IContainer::PreparedState {
142 PreparedState(VehicleSeatContainerAdapter& owner, std::vector<std::optional<int>> staged, eve::Revision revision)
197eve::container::ContainerObject VehicleSeatContainerAdapter::describe(int occupantId, std::string driver) {
214 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "vehicle seat adapter is stale or unbound"));
221 if (seat.occupant <= 0 || index > static_cast<std::size_t>(std::numeric_limits<std::int32_t>::max()))
227 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "vehicle occupant appears in multiple seats"));
228 result.entries.push_back({{id, eve::container::SlotIndex(static_cast<std::int32_t>(index)), eve::Generation(1)},
235 const eve::container::ContainerObject& object, std::optional<eve::container::SlotIndex> destination,
241 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "vehicle seat adapter is stale or unbound"));
244 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle seat object facts are invalid"));
248 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "vehicle occupant identity is stale"));
260 if (!destination->isValid() || static_cast<std::size_t>(destination->value()) >= seats->list.size())
262 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle seat slot is out of range"));
279eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>> VehicleSeatContainerAdapter::prepare(
280 const eve::container::ContainerSnapshot& expected, const eve::container::ContainerSnapshot& candidate) {
285 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "vehicle seat adapter is stale or unbound"));
287 return eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>>::failure(eve::Diagnostic::error(
291 return eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>>::failure(current.status());
294 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "vehicle seat expected snapshot is stale"));
297 return eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>>::failure(eve::Diagnostic::error(
298 eve::DiagnosticCode::InvariantViolation, "vehicle seat candidate revision is not the next revision"));
301 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "vehicle seat candidate exceeds capacity"));
317 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "vehicle seat candidate payload is stale"));
327 return eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>>::success(std::move(prepared));
330eve::Result<eve::container::MembershipId> VehicleSeatContainerAdapter::enter(eve::container::SlotIndex seatIndex,
341 notify(sink, descriptor_.id, objectIdValue, eve::container::ContainerEventKind::Rejected, seatIndex, revision(),
351 notify(sink, descriptor_.id, object.id, eve::container::ContainerEventKind::Rejected, seatIndex,
352 current.value().revision, serial, tick, diagnostic == nullptr ? "rejected" : diagnostic->message(),
360 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "vehicle seat revision exhausted"));
362 notify(sink, descriptor_.id, object.id, eve::container::ContainerEventKind::Rejected, seatIndex,
373 notify(sink, descriptor_.id, objectIdValue, eve::container::ContainerEventKind::Rejected, seatIndex,
374 current.value().revision, serial, tick, diagnostic == nullptr ? "prepare_failed" : diagnostic->message(),
381 notify(sink, descriptor_.id, objectIdValue, eve::container::ContainerEventKind::Accepted, seatIndex, *next, serial,
383 notify(sink, descriptor_.id, objectIdValue, eve::container::ContainerEventKind::Enter, seatIndex, *next, serial,
385 return eve::Result<eve::container::MembershipId>::success(objectIdValue, appliedStatus(callbackFailed));
388eve::Result<eve::container::MembershipId> VehicleSeatContainerAdapter::exit(eve::container::SlotIndex seatIndex,
399 const auto status = current ? eve::Status::failure(eve::Diagnostic::error(eve::DiagnosticCode::NotFound,
404 notify(sink, descriptor_.id, objectIdValue, eve::container::ContainerEventKind::Rejected, seatIndex, revision(),
415 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "vehicle seat revision exhausted"));
417 notify(sink, descriptor_.id, objectIdValue, eve::container::ContainerEventKind::Rejected, seatIndex,
427 notify(sink, descriptor_.id, objectIdValue, eve::container::ContainerEventKind::Rejected, seatIndex,
428 current.value().revision, serial, tick, diagnostic == nullptr ? "prepare_failed" : diagnostic->message(),
435 notify(sink, descriptor_.id, objectIdValue, eve::container::ContainerEventKind::Accepted, seatIndex, *next, serial,
437 notify(sink, descriptor_.id, objectIdValue, eve::container::ContainerEventKind::Exit, seatIndex, *next, serial,
439 return eve::Result<eve::container::MembershipId>::success(objectIdValue, appliedStatus(callbackFailed));
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
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
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
void commit() noexcept override
Publish the staged state; the operation is non-throwing.
Definition ContainerAdapters.cpp:145
void rollback() noexcept override
Abandon an unpublished stage; the operation is non-throwing.
Definition ContainerAdapters.cpp:159
PreparedState(VehicleSeatContainerAdapter &owner, std::vector< std::optional< int > > staged, eve::Revision revision)
Definition ContainerAdapters.cpp:142
Transactional adapter over one VehicleEntity::Seats component.
Definition ContainerAdapters.h:42
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:279
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:234
eve::Result< eve::container::ContainerSnapshot > snapshot() const override
Snapshot.
Definition ContainerAdapters.cpp:209
eve::Result< eve::container::MembershipId > exit(eve::container::SlotIndex seatIndex, eve::container::GameEventSink sink={}, eve::SimulationTick tick=eve::SimulationTick::zero())
Stage and publish the occupant leaving a seat.
Definition ContainerAdapters.cpp:388
eve::Result< eve::container::MembershipId > enter(eve::container::SlotIndex seatIndex, int occupantId, eve::container::GameEventSink sink={}, eve::SimulationTick tick=eve::SimulationTick::zero())
Stage and publish an occupant entering a seat.
Definition ContainerAdapters.cpp:330
eve::Revision revision() const noexcept
Return the live seat-component revision, or zero when stale.
Definition ContainerAdapters.cpp:182
VehicleSeatContainerAdapter(eve::container::ContainerId id, VehicleEntity *vehicle, eve::container::AcceptedCondition accepted={})
Binds an adapter to a live ECS vehicle.
Definition ContainerAdapters.cpp:170
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
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
EventId eventId
Stable event identity; nil is allowed only for legacy transient events.
Definition GameEvent.h:185
std::string payload
Canonical serialized payload at the stream persistence boundary.
Definition GameEvent.h:207
Owning snapshot payload for a vehicle occupant membership.
Definition ContainerAdapters.h:24
Vehicle adapters for the common Container/Zone/Transfer protocol.