载入中...
搜索中...
未找到
WeaponDefinitionRuntime.cpp
浏览该文件的文档.
51 if (integer == nullptr || *integer < std::numeric_limits<int>::min() || *integer > std::numeric_limits<int>::max())
118 return eve::Result<WeaponDefinition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
127 eve::DiagnosticCode::InvalidArgument, "weapon definition id does not match its logical reference", "id", {},
133 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon kind and logic must be strings",
138 if (!readNumber(*object, "damage", result.damage) || !readNumber(*object, "penetration", result.penetration) ||
146 !readNumber(*object, "spreadMin", result.spreadMin) || !readNumber(*object, "spreadMax", result.spreadMax) ||
152 !readNumber(*object, "zoomFov", result.zoomFov) || !readNumber(*object, "cooldown", result.cooldown) ||
155 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon numeric fields must be finite numbers",
163 eve::DiagnosticCode::InvalidArgument, "weapon damage falloff fields are outside valid ranges", "definition",
166 if (!readText(*object, "damageType", result.damageType) || !readText(*object, "element", result.element) ||
175 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon target policy fields are invalid",
179 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon must target ground, air, or both",
186 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "fireModes must be an array", "fireModes",
199 return eve::Result<WeaponDefinition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
208 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "resource must be an object", "resource",
211 if (!readText(*nested, "kind", resourceName) || !readNumber(*nested, "max", result.resource.max) ||
216 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon resource fields are invalid",
225 return eve::Result<WeaponDefinition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
233 return eve::Result<WeaponDefinition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
240 !readInteger(*nested, "reserve", result.reserveSize) || !readNumber(*nested, "reload", result.reloadTime))
241 return eve::Result<WeaponDefinition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
262 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "effects fields are invalid", "effects",
269eve::Result<eve::definition::DefinitionHandle> currentHandle(eve::definitions::DefinitionRegistry& registry,
351 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon runtime state must be an object",
353 static const std::set<std::string> fields = {"aiming", "burstRemaining", "burstTimer", "cooldown",
360 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "unknown weapon runtime state field",
366 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon runtime state is missing a field",
379 !readStateNumber(*object, "recoilYaw", result.recoilYaw) || !readText(*object, "selector", selector) ||
380 !readText(*object, "stage", stage) || !readStateNumber(*object, "stageTimer", result.stageTimer))
382 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon runtime scalar field is invalid",
389 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon runtime resource is invalid",
392 if (!readText(*resourceValue, "kind", kind) || !readStateNumber(*resourceValue, "value", result.resource.value) ||
401 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon runtime resource fields are invalid",
409eve::Result<WeaponDefinition> parseWeaponDefinition(const eve::definitions::Definition& source) {
412 return eve::Result<WeaponDefinition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
424eve::Result<WeaponDefinitionRuntime> WeaponDefinitionRuntime::create(eve::definitions::DefinitionRegistry& registry,
430 eve::DiagnosticCode::InvalidArgument, "weapon definition reference must use weapon namespace", "definition",
443eve::Result<WeaponDefinitionRuntime> WeaponDefinitionRuntime::create(eve::definitions::DefinitionRegistry& registry,
450 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon id is not a valid logical name",
457eve::Result<WeaponDefinitionRuntime> WeaponDefinitionRuntime::create(Weapon& module, std::string_view definitionId,
467const WeaponRuntimeState& WeaponDefinitionRuntime::state() const noexcept { return runtime_.state(); }
478 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon definition registry is not bound",
530eve::Result<eve::definition::ReloadOutcome> WeaponDefinitionRuntime::reload(eve::definition::ReloadPolicy policy) {
533 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "weapon definition registry is not bound",
541 auto rebuild = [defaults, maxSpread](const WeaponRuntimeState& oldState, const eve::definition::InstanceIdentity&,
569 eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider& hashProvider) const {
570 const eve::definition::RuntimeStateEncoder<WeaponRuntimeState> encoder = [](const WeaponRuntimeState& value) {
573 return eve::definition::snapshotRuntimeInstance(runtime_, "weapon.runtime", runtimeSchema(), eve::SchemaVersion(1),
595 eve::DiagnosticCode::StaleHandle, "weapon snapshot cannot restore against a replaced definition",
598 return eve::definition::restoreRuntimeInstance(runtime_, snapshotValue, "weapon.runtime", runtimeSchema(),
Owning, renderer-independent dynamic values.
Strongly typed Weapon definition/runtime adapter.
static Result< DefinitionRef > fromId(LogicalId id)
Build a definition reference from a valid LogicalId.
Definition ResourceRef.cpp:50
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
Human-readable, scoped identifier in the form namespace:name.
Definition Identity.h:411
static std::optional< LogicalId > fromParts(std::string_view namespaceName, std::string_view name)
Builds a logical ID from separate namespace and name components.
Definition Identity.cpp:48
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 Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:57
static eve::Result< RuntimeInstance > create(eve::PersistentId instanceId, eve::DefinitionRef definition, eve::Generation definitionGeneration, State state, bool active=true)
Construct a runtime instance after validating its identity.
Definition DefinitionRuntime.h:321
Deterministic registry of topic-neutral, versioned JSON definitions.
Definition Definitions.h:58
eve::ResultRef< const Definition > resolveHandle(const DefinitionHandle &handle) const
Resolves a generation-qualified handle and reports stale identities.
Definition Definitions.cpp:319
eve::Result< DefinitionHandle > handle(const std::string &type, const std::string &id) const
Returns the current generation-qualified handle through Result.
Definition Definitions.cpp:325
Binds a typed WeaponDefinition to one mutable runtime instance.
Definition WeaponDefinitionRuntime.h:69
eve::Result< void > applyTo(WeaponEntity *entity) const
Atomically project this runtime into a borrowed WeaponEntity.
Definition WeaponDefinitionRuntime.cpp:487
const WeaponRuntimeState & state() const noexcept
Borrow mutable typed firing/resource state.
Definition WeaponDefinitionRuntime.cpp:467
eve::Result< eve::definition::ReloadOutcome > reload(eve::definition::ReloadPolicy policy)
Reload the registry's current generation using a typed policy.
Definition WeaponDefinitionRuntime.cpp:530
eve::Result< eve::SnapshotEnvelope > snapshot(eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider) const
Capture stable typed runtime state in the common SnapshotEnvelope.
Definition WeaponDefinitionRuntime.cpp:568
eve::Result< std::string > snapshotJson(eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider) const
Serialize snapshot() as canonical deterministic JSON.
Definition WeaponDefinitionRuntime.cpp:577
eve::Result< void > restore(const eve::SnapshotEnvelope &snapshot, const eve::SnapshotHashProvider &hashProvider)
Verify and restore a same-generation snapshot transactionally.
Definition WeaponDefinitionRuntime.cpp:585
eve::Result< WeaponDefinition > definition() const
Resolve the current strongly typed WeaponDefinition projection.
Definition WeaponDefinitionRuntime.cpp:475
void setActive(bool active) noexcept
Set the active guard used by RejectWhileActive.
Definition WeaponDefinitionRuntime.cpp:483
static eve::Result< WeaponDefinitionRuntime > create(eve::definitions::DefinitionRegistry ®istry, eve::DefinitionRef definition, eve::PersistentId instanceId, eve::definition::ReloadPolicy policy=eve::definition::ReloadPolicy::RebuildInstance)
Create from a common weapon:<name> definition reference.
Definition WeaponDefinitionRuntime.cpp:424
eve::definition::DefinitionHandle definitionHandle() const noexcept
Return the exact generation-qualified definition handle.
Definition WeaponDefinitionRuntime.cpp:471
bool isActive() const noexcept
Return whether the instance is active.
Definition WeaponDefinitionRuntime.cpp:485
const eve::definition::InstanceIdentity & identity() const noexcept
Borrow the common instance identity and exact definition generation.
Definition WeaponDefinitionRuntime.cpp:463
eve::definitions::DefinitionRegistry & definitionRegistry() noexcept
Return the common registry backing legacy weapon definitions.
Definition Weapon.h:54
eve::Result< eve::SnapshotEnvelope > snapshotRuntimeInstance(const RuntimeInstance< State > &runtime, std::string type, eve::LogicalId schema, eve::SchemaVersion schemaVersion, eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider, const RuntimeStateEncoder< State > &encode)
Capture a typed runtime instance in the common snapshot envelope.
Definition RuntimeSnapshot.h:96
eve::Result< void > restoreRuntimeInstance(RuntimeInstance< State > &runtime, const eve::SnapshotEnvelope &snapshot, std::string_view expectedType, const eve::LogicalId &expectedSchema, eve::SchemaVersion expectedVersion, const eve::SnapshotHashProvider &hashProvider, const RuntimeStateDecoder< State > &decode)
Verify and atomically restore a typed runtime instance.
Definition RuntimeSnapshot.h:135
std::function< eve::Result< State >(const eve::Value &)> RuntimeStateDecoder
Decodes one domain-owned runtime state from an owning Value.
Definition RuntimeSnapshot.h:31
std::function< eve::Result< eve::Value >(const State &)> RuntimeStateEncoder
Converts one domain-owned runtime state into an owning Value.
Definition RuntimeSnapshot.h:27
@ Resource
const EditorValue * field(const EditorValue &value, const char *name)
Definition RoadNetworkEditTarget.cpp:15
bool readNumber(const EditorValue &value, const char *name, float &output)
Definition RoadNetworkEditTarget.cpp:30
载具模块入口(eve.Vehicle):定义注册 / 实体工厂 / RTS 命令 / 帧调度。 设计文档:docs/dev/通用载具系统设计.md
Definition RTSArchetype.h:10
@ Ranged
const char * weaponKindName(WeaponKind kind)
武器形态的字符串名("melee" | "ranged" | "magic" | "missile" | "custom")。
Definition Weapon.cpp:86
eve::Result< WeaponDefinition > parseWeaponDefinition(const eve::definitions::Definition &source)
Parse one canonical registry definition into an owning typed snapshot.
Definition WeaponDefinitionRuntime.cpp:409
WeaponKind weaponKindFromName(const std::string &name)
从字符串解析武器形态;未知名字回退 Ranged。
Definition Weapon.cpp:97
@ Windup
@ Active
@ Recover
const char * fireModeName(FireMode mode)
开火模式的字符串名("single" | "burst" | "auto")。
Definition Weapon.cpp:71
const char * attackStageName(AttackStage stage)
攻击阶段的字符串名("idle" | "windup" | "active" | "recover")。
Definition Weapon.cpp:105
@ Charges
@ Stamina
@ InvalidArgument
@ Failed
@ StaleHandle
Result< std::string > serializeSnapshotEnvelope(const SnapshotEnvelope &snapshot)
Serialize an envelope as deterministic compact JSON.
Definition Snapshot.cpp:184
std::function< Result< ContentId >(std::string_view canonicalInput)> SnapshotHashProvider
Injected content-digest implementation used by snapshots.
Definition Snapshot.h:36
Stable outer format shared by persistence and cross-process snapshots.
Definition Snapshot.h:46
A generation-qualified reference to one definition incarnation.
Definition DefinitionRuntime.h:69
Canonical identity carried by every typed runtime instance.
Definition DefinitionRuntime.h:87
One immutable view of a registered versioned JSON definition.
Definition Definitions.h:31
Mutable state owned by one typed weapon runtime instance.
Definition WeaponDefinitionRuntime.h:45
float currentSpread
Definition WeaponDefinitionRuntime.h:53