载入中...
搜索中...
未找到
ActionGameEventSink.cpp
浏览该文件的文档.
2
3#include "common/Capability.h"
4
5#include <utility>
6
8 // namespace
9
11 : log_(&log), resolver_(std::move(resolver)) {}
12
13ActionGameEventSink::~ActionGameEventSink() { cap::removeListener<IActionGameplayEventSink>(this); }
14
16 for (std::size_t index = 0; index < cap::listenerCount<IActionGameplayEventSink>(); ++index)
17 if (cap::listenerAt<IActionGameplayEventSink>(index) == this) return true;
18 return false;
19}
20
22 const bool current = enabled();
23 if (value && !current)
24 cap::addListener<IActionGameplayEventSink>(this);
25 else if (!value && current)
26 cap::removeListener<IActionGameplayEventSink>(this);
27}
28
31 if (!log_) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "game event log is unavailable", "log"));
32 if (!resolver_) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "action subject resolver is unavailable", "resolver"));
33
34 std::optional<SubjectRef> source;
35 if (context.source) {
36 auto resolved = resolver_(*context.source);
37 if (!resolved) return Result<void>::failure(resolved.status());
38 source = resolved.value();
39 }
41 if (binding.targetIndex) {
42 if (*binding.targetIndex >= context.targets.size())
43 return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "gameplay event target index is unavailable", "targetIndex"));
44 auto resolved = resolver_(context.targets[*binding.targetIndex]);
45 if (!resolved) return Result<void>::failure(resolved.status());
46 subject = resolved.value();
47 } else if (source) {
48 subject = *source;
49 } else {
50 return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "gameplay event has no source or target subject", "subject"));
51 }
52
53 auto payload = binding.data.toJson();
54 if (!payload) return Result<void>::failure(payload.status());
55 auto schema = LogicalId::parse("action:gameplay-event-v1");
56 if (!schema) return Result<void>::failure(Diagnostic::error(DiagnosticCode::Failed, "built-in gameplay event schema is invalid", "schemaId"));
57
59 envelope.type = binding.tag;
60 envelope.source = source ? source->format() : std::string{};
61 envelope.subject = subject.format();
62 envelope.schemaId = *schema;
63 envelope.schemaVersion = SchemaVersion(1);
64 envelope.tick = context.tick;
65 envelope.payload = std::move(payload).takeValue();
66 auto appended = log_->append(std::move(envelope));
67 if (!appended) return Result<void>::failure(appended.status());
68 lastSequence_ = appended.value();
70}
71
72std::optional<eve::game_event::EventSequence> ActionGameEventSink::lastSequence() const noexcept {
73 return lastSequence_;
74}
75
76} // namespace eve::action::game_event_adapter
Persistent GameEventLog adapter for action events.
double value
Value::Object payload
int subject
Definition AnimSmr.cpp:163
eve::action::ActionVfxBinding binding
double current
uint32_t index
const UnitySourceAsset & source
const VegetationPresetContext & context
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
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
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
Strong, domain-neutral reference to a runtime subject.
Definition SubjectRef.h:26
static SubjectRef nil() noexcept
Return the invalid nil reference.
Definition SubjectRef.h:35
void setEnabled(bool enabled)
Opt this adapter into or out of gameplay-event dispatch.
bool enabled() const
Return whether this exact adapter is registered.
ActionGameEventSink(eve::game_event::GameEventLog &log, ActionSubjectResolver resolver)
Construct from borrowed event authority and an owning resolver callback.
Result< void > emit(const ActionGameplayEventBinding &binding, const ActionNotifyContext &context) override
Emit one validated event or return a structured domain failure.
std::optional< eve::game_event::EventSequence > lastSequence() const noexcept
Return the last successfully appended stream-local sequence.
Deterministic in-memory stream of topic-neutral event envelopes.
Definition GameEvent.h:261
eve::Result< EventSequence > append(GameEvent envelope)
Appends a typed-metadata envelope and assigns stream-local order.
std::function< Result< SubjectRef >(ecs::EntityHandle)> ActionSubjectResolver
Resolves a stable gameplay subject for a generation-qualified ECS handle.
detail::StrongUint64< detail::SchemaVersionTag > SchemaVersion
Persistent data-format version; not a runtime replacement generation.
Owning validated event request authored on an action timeline.
Context linking a routed event to its action execution.
Envelope metadata shared by event domains.
Definition GameEvent.h:183
std::string source
Stable source reference, owned by this envelope.
Definition GameEvent.h:191
std::string type
Compatibility event name and diagnostic topic.
Definition GameEvent.h:189
std::string payload
Canonical serialized payload at the stream persistence boundary.
Definition GameEvent.h:207
SchemaVersion schemaVersion
Version of the payload schema, not a stream or runtime generation.
Definition GameEvent.h:201
SchemaId schemaId
Logical schema identifier for the typed payload codec.
Definition GameEvent.h:199
SimulationTick tick
Deterministic simulation time at which the event was emitted.
Definition GameEvent.h:203
std::string subject
Stable subject reference, owned by this envelope.
Definition GameEvent.h:193