载入中...
搜索中...
未找到
VehicleDefinitionRuntime.cpp
浏览该文件的文档.
26eve::Result<eve::definition::DefinitionHandle> currentHandle(eve::definitions::DefinitionRegistry& registry,
37bool readString(const eve::Value::Object& object, std::string_view name, std::string& result, bool required = false) {
46bool readNumber(const eve::Value::Object& object, std::string_view name, float& result, float fallback) {
59 if (!std::isfinite(number) || number < 0.0 || number > std::numeric_limits<float>::max()) return false;
64bool readSignedNumber(const eve::Value::Object& object, std::string_view name, float& result, float fallback) {
84bool readBool(const eve::Value::Object& object, std::string_view name, bool& result, bool fallback) {
98eve::Result<VehicleDefinition> parseVehicleDefinition(const eve::definitions::Definition& source) {
104 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle definition must be an object", "json",
109 if (!readString(*object, "category", result.category) || !readString(*object, "mobility", result.mobility))
111 eve::DiagnosticCode::InvalidArgument, "vehicle category and mobility must be strings", "definition", {},
117 !readNumber(*object, "maxHealth", result.maxHealth, result.maxHealth) || result.radius <= 0.f ||
120 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle numeric definition field is invalid",
127 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle physics must be an object",
134 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle physics numeric field is invalid",
163 return eve::Result<VehicleDefinition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
170 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "mount must be an object", "mounts",
183 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "mount definition field is invalid",
189 eve::DiagnosticCode::InvalidArgument, "mount limits must contain four numbers", "mounts.limits",
216 if (!readNumber(*value, "maxTravel", result.suspension.maxTravel, result.suspension.maxTravel) ||
217 !readNumber(*value, "driveForce", result.suspension.driveForce, result.suspension.driveForce) ||
218 !readNumber(*value, "lateralGrip", result.suspension.lateralGrip, result.suspension.lateralGrip))
220 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "suspension numeric field is invalid",
226 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "suspension wheels must be an array",
255 return eve::Result<VehicleDefinition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
262 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "seat must be an object", "seats", {},
269 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "seat definition field is invalid",
287 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle tags must be an array", "tags",
293 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle tag is invalid", "tags", {},
319 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle runtime state must be an object",
321 static const std::set<std::string> fields = {"destroyed", "faction", "heading", "health", "speed", "x", "y"};
326 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "unknown vehicle runtime state field",
332 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle runtime state is missing a field",
349 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle runtime state field is invalid",
358eve::Result<VehicleDefinitionRuntime> VehicleDefinitionRuntime::create(eve::definitions::DefinitionRegistry& registry,
364 eve::DiagnosticCode::InvalidArgument, "vehicle definition reference must use vehicle namespace",
374 auto runtime = eve::definition::RuntimeInstance<VehicleRuntimeState>::create(instanceId, std::move(definition),
381eve::Result<VehicleDefinitionRuntime> VehicleDefinitionRuntime::create(eve::definitions::DefinitionRegistry& registry,
388 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle id is not a valid logical name",
395eve::Result<VehicleDefinitionRuntime> VehicleDefinitionRuntime::create(Vehicle& module, std::string_view definitionId,
405const VehicleRuntimeState& VehicleDefinitionRuntime::state() const noexcept { return runtime_.state(); }
416 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle definition registry is not bound",
430 eve::DiagnosticCode::InvalidArgument, "vehicle runtime cannot project to a null VehicleEntity", "entity",
474eve::Result<eve::definition::ReloadOutcome> VehicleDefinitionRuntime::reload(eve::definition::ReloadPolicy policy) {
477 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "vehicle definition registry is not bound",
488 auto rebuild = [maxHealth](const VehicleRuntimeState& oldState, const eve::definition::InstanceIdentity&,
500 eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider& hashProvider) const {
501 const eve::definition::RuntimeStateEncoder<VehicleRuntimeState> encoder = [](const VehicleRuntimeState& value) {
504 return eve::definition::snapshotRuntimeInstance(runtime_, "vehicle.runtime", vehicleSchema(), eve::SchemaVersion(1),
526 eve::DiagnosticCode::StaleHandle, "vehicle snapshot cannot restore against a replaced definition",
529 return eve::definition::restoreRuntimeInstance(runtime_, snapshotValue, "vehicle.runtime", vehicleSchema(),
Owning, renderer-independent dynamic values.
Strongly typed Vehicle definition/entity runtime adapter.
static Result< DefinitionRef > fromId(LogicalId id)
Build a definition reference from a valid LogicalId.
Definition ResourceRef.cpp:50
const LogicalId & id() const noexcept
Return the stable logical definition identity.
Definition ResourceRef.h:97
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
std::string_view name() const noexcept
Returns the name component as a view into this object.
Definition Identity.cpp:63
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
std::string format() const
Formats the ID in lower-case canonical UUID text.
Definition Identity.h:173
Binds a VehicleDefinition to a VehicleEntity without a new root type.
Definition VehicleDefinitionRuntime.h:56
eve::Result< std::string > snapshotJson(eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider) const
Serialize snapshot() as canonical deterministic JSON.
Definition VehicleDefinitionRuntime.cpp:508
eve::Result< void > restore(const eve::SnapshotEnvelope &snapshot, const eve::SnapshotHashProvider &hashProvider)
Verify and restore a same-generation vehicle snapshot atomically.
Definition VehicleDefinitionRuntime.cpp:516
bool isActive() const noexcept
Return the active guard state.
Definition VehicleDefinitionRuntime.cpp:425
void setActive(bool active) noexcept
Set the active guard used by RejectWhileActive.
Definition VehicleDefinitionRuntime.cpp:423
eve::Result< eve::SnapshotEnvelope > snapshot(eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider) const
Capture mutable entity state in a common SnapshotEnvelope.
Definition VehicleDefinitionRuntime.cpp:499
eve::definition::DefinitionHandle definitionHandle() const noexcept
Return the generation-qualified definition handle.
Definition VehicleDefinitionRuntime.cpp:409
const eve::definition::InstanceIdentity & identity() const noexcept
Borrow common instance identity and exact definition generation.
Definition VehicleDefinitionRuntime.cpp:401
static eve::Result< VehicleDefinitionRuntime > create(eve::definitions::DefinitionRegistry ®istry, eve::DefinitionRef definition, eve::PersistentId instanceId, eve::definition::ReloadPolicy policy=eve::definition::ReloadPolicy::RebuildInstance)
Create from a common vehicle:<name> definition.
Definition VehicleDefinitionRuntime.cpp:358
const VehicleRuntimeState & state() const noexcept
Borrow mutable vehicle entity state.
Definition VehicleDefinitionRuntime.cpp:405
eve::Result< void > applyTo(VehicleEntity *entity) const
Project typed state and identity into a borrowed VehicleEntity.
Definition VehicleDefinitionRuntime.cpp:427
eve::Result< VehicleDefinition > definition() const
Resolve and parse the current strongly typed VehicleDefinition.
Definition VehicleDefinitionRuntime.cpp:413
eve::Result< eve::definition::ReloadOutcome > reload(eve::definition::ReloadPolicy policy)
Reload the registry's current generation using a typed policy.
Definition VehicleDefinitionRuntime.cpp:474
eve::definitions::DefinitionRegistry & definitionRegistry() noexcept
Return the canonical common registry for vehicle definitions.
Definition Vehicle.h:59
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
bool readString(const eve::Value::Object &object, const char *name, std::string &output)
Definition ArtifactProvider.cpp:20
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::Result< VehicleDefinition > parseVehicleDefinition(const eve::definitions::Definition &source)
Parse one canonical registry definition into a short-lived typed projection.
Definition VehicleDefinitionRuntime.cpp:98
@ 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
eve::DefinitionRef definition
Definition DefinitionRuntime.h:89
eve::PersistentId instanceId
Definition DefinitionRuntime.h:88
One immutable view of a registered versioned JSON definition.
Definition Definitions.h:31
std::vector< SuspensionWheel > wheels
Definition VehicleTypes.h:123
载具模板(registerVehiclesFromJson 注册,进程级注册表)。
Definition VehicleTypes.h:135
std::vector< ArmorZone > armorZones
Definition VehicleTypes.h:145
Mutable state owned by one typed vehicle runtime instance.
Definition VehicleDefinitionRuntime.h:38