载入中...
搜索中...
未找到
CarrierRecipeCodec.cpp
浏览该文件的文档.
52Result<std::optional<double>> optionalDouble(const Value::Object& object, const char* name, std::string_view path) {
56Result<std::optional<int>> optionalInt(const Value::Object& object, const char* name, std::string_view path) {
60Result<void> assignOptionalDouble(const Value::Object& object, const char* name, double& dest, std::string_view path) {
67Result<void> assignOptionalInt(const Value::Object& object, const char* name, int& dest, std::string_view path) {
74Result<Duration> readSeconds(const Value::Object& object, const char* name, std::string_view path) {
78 return Result<Duration>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Expected positive seconds"), std::string(path), {},
85Result<LogicalId> readLogicalId(const Value::Object& object, const char* name, std::string_view path) {
88 return Result<LogicalId>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Expected non-empty logical id"), std::string(path), {},
92 return Result<LogicalId>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Logical id must be namespace:name"), std::string(path), {},
98 if (text == "linear" || text == "IntegrateLinear") return Result<CarrierMotionOpKind>::success(CarrierMotionOpKind::IntegrateLinear);
99 if (text == "gravity" || text == "ApplyGravity") return Result<CarrierMotionOpKind>::success(CarrierMotionOpKind::ApplyGravity);
100 if (text == "homing" || text == "SteerHoming") return Result<CarrierMotionOpKind>::success(CarrierMotionOpKind::SteerHoming);
101 if (text == "accelerate" || text == "Accelerate") return Result<CarrierMotionOpKind>::success(CarrierMotionOpKind::Accelerate);
102 if (text == "sway" || text == "CurveSway") return Result<CarrierMotionOpKind>::success(CarrierMotionOpKind::CurveSway);
103 if (text == "helix" || text == "CurveHelix") return Result<CarrierMotionOpKind>::success(CarrierMotionOpKind::CurveHelix);
104 if (text == "avoidBody" || text == "SteerAvoidBody") return Result<CarrierMotionOpKind>::success(CarrierMotionOpKind::SteerAvoidBody);
117 return Result<CarrierMotionOpKind>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Unknown motion kind"), std::string(path), {},
122 if (text == "onExpire" || text == "OnExpire") return Result<CarrierTriggerKind>::success(CarrierTriggerKind::OnExpire);
123 if (text == "onFuse" || text == "OnFuse") return Result<CarrierTriggerKind>::success(CarrierTriggerKind::OnFuse);
124 if (text == "onInterval" || text == "OnInterval") return Result<CarrierTriggerKind>::success(CarrierTriggerKind::OnInterval);
125 if (text == "onHit" || text == "OnHit") return Result<CarrierTriggerKind>::success(CarrierTriggerKind::OnHit);
126 if (text == "onProximity" || text == "OnProximity") return Result<CarrierTriggerKind>::success(CarrierTriggerKind::OnProximity);
131 if (text == "onApex" || text == "OnApex") return Result<CarrierTriggerKind>::success(CarrierTriggerKind::OnApex);
132 return Result<CarrierTriggerKind>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Unknown trigger kind"), std::string(path), {},
139 if (text == "emitHit" || text == "hit" || text == "EmitHit") return Result<CarrierImpactKind>::success(CarrierImpactKind::EmitHit);
140 if (text == "splash" || text == "Splash") return Result<CarrierImpactKind>::success(CarrierImpactKind::Splash);
141 if (text == "pierce" || text == "Pierce") return Result<CarrierImpactKind>::success(CarrierImpactKind::Pierce);
142 if (text == "bounce" || text == "Bounce") return Result<CarrierImpactKind>::success(CarrierImpactKind::Bounce);
143 if (text == "release" || text == "Release") return Result<CarrierImpactKind>::success(CarrierImpactKind::Release);
144 if (text == "spawnChild" || text == "SpawnChild") return Result<CarrierImpactKind>::success(CarrierImpactKind::SpawnChild);
145 return Result<CarrierImpactKind>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Unknown impact kind"), std::string(path), {},
204 if (!object) return Result<CarrierMotionOp>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Motion op must be string or object"), std::string(path), {},
208 return Result<CarrierMotionOp>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Motion op requires kind"), std::string(path + ".kind"), {},
213 if (auto assigned = assignOptionalDouble(*object, "gravity", op.gravity, path + ".gravity"); !assigned)
216 assignOptionalDouble(*object, "maxTurnRateDegrees", op.maxTurnRateDegrees, path + ".maxTurnRateDegrees");
220 if (auto assigned = assignOptionalDouble(*object, "turnRate", op.maxTurnRateDegrees, path + ".turnRate");
224 if (auto assigned = assignOptionalDouble(*object, "acceleration", op.acceleration, path + ".acceleration");
227 if (auto assigned = assignOptionalDouble(*object, "avoidLookAhead", op.avoidLookAhead, path + ".avoidLookAhead");
230 if (auto assigned = assignOptionalDouble(*object, "avoidStrength", op.avoidStrength, path + ".avoidStrength");
234 assignOptionalDouble(*object, "avoidRadiusPadding", op.avoidRadiusPadding, path + ".avoidRadiusPadding");
237 if (auto assigned = assignOptionalDouble(*object, "curveAmplitude", op.curveAmplitude, path + ".curveAmplitude");
241 if (auto assigned = assignOptionalDouble(*object, "amplitude", op.curveAmplitude, path + ".amplitude");
246 assignOptionalDouble(*object, "curveFrequencyHz", op.curveFrequencyHz, path + ".curveFrequencyHz");
250 if (auto assigned = assignOptionalDouble(*object, "frequency", op.curveFrequencyHz, path + ".frequency");
255 assignOptionalDouble(*object, "angularRateDegrees", op.angularRateDegrees, path + ".angularRateDegrees");
258 if (auto assigned = assignOptionalDouble(*object, "orbitRadius", op.orbitRadius, path + ".orbitRadius"); !assigned)
262 if (auto assigned = assignOptionalDouble(*object, "axisX", op.axis.x, path + ".axisX"); !assigned)
264 if (auto assigned = assignOptionalDouble(*object, "axisY", op.axis.y, path + ".axisY"); !assigned)
266 if (auto assigned = assignOptionalDouble(*object, "axisZ", op.axis.z, path + ".axisZ"); !assigned)
268 if (auto assigned = assignOptionalInt(*object, "randomSeed", op.randomSeed, path + ".randomSeed"); !assigned)
271 assignOptionalDouble(*object, "predictionSeconds", op.predictionSeconds, path + ".predictionSeconds");
286 if (!object) return Result<CarrierTrigger>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Trigger must be string or object"), std::string(path), {},
290 return Result<CarrierTrigger>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Trigger requires kind"), std::string(path + ".kind"), {},
300 const auto fuseSeconds = fuseField.value().has_value() ? fuseField.value() : secondsField.value();
316 assignOptionalDouble(*object, "proximityRadius", trigger.proximityRadius, path + ".proximityRadius");
320 if (auto assigned = assignOptionalDouble(*object, "radius", trigger.proximityRadius, path + ".radius");
324 if (auto assigned = assignOptionalDouble(*object, "threshold", trigger.threshold, path + ".threshold"); !assigned)
331 if (!object) return Result<CarrierImpact>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Impact must be an object"), std::string(path), {},
336 return Result<CarrierImpact>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Impact requires kind"), std::string(path + ".kind"), {},
347 if (auto assigned = assignOptionalDouble(*object, "damage", impact.damage, path + ".damage"); !assigned)
349 if (auto assigned = assignOptionalDouble(*object, "splashRadius", impact.splashRadius, path + ".splashRadius");
353 if (auto assigned = assignOptionalDouble(*object, "radius", impact.splashRadius, path + ".radius"); !assigned)
356 if (auto assigned = assignOptionalInt(*object, "pierceCount", impact.pierceCount, path + ".pierceCount"); !assigned)
359 if (auto assigned = assignOptionalInt(*object, "count", impact.pierceCount, path + ".count"); !assigned)
362 if (auto assigned = assignOptionalInt(*object, "bounceCount", impact.bounceCount, path + ".bounceCount"); !assigned)
364 if (auto assigned = assignOptionalDouble(*object, "restitution", impact.restitution, path + ".restitution");
368 assignOptionalDouble(*object, "bounceFriction", impact.bounceFriction, path + ".bounceFriction");
371 if (auto assigned = assignOptionalDouble(*object, "bounceSpreadDegrees", impact.bounceSpreadDegrees,
375 if (auto assigned = assignOptionalInt(*object, "randomSeed", impact.randomSeed, path + ".randomSeed"); !assigned)
383 return Result<CarrierImpact>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Invalid childRecipeId"), std::string(path + ".childRecipeId"), {},
387 return Result<CarrierImpact>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("childRecipeId must be a string"), std::string(path + ".childRecipeId"), {},
409 return Result<CarrierRecipe>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Preset requires positive speed"), std::string("speed"), {},
429 if (auto assigned = assignOptionalDouble(object, "maxTurnRateDegrees", homing, "maxTurnRateDegrees"); !assigned)
432 if (auto assigned = assignOptionalDouble(object, "accelerate", accelerate, "accelerate"); !assigned)
552 return Result<CarrierRecipe>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Recipe requires positive speed"), std::string("speed"), {},
559 return Result<CarrierRecipe>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Full recipe requires motion array"), std::string("motion"), {},
569 return Result<CarrierRecipe>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Full recipe requires triggers array"), std::string("triggers"), {},
579 return Result<CarrierRecipe>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Full recipe requires impacts array"), std::string("impacts"), {},
596 if (!object) return Result<CarrierRecipe>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, std::string("Carrier recipe must be an object"), std::string(""), {},
603 if (field(*object, "motionOps") || (field(*object, "motion") && field(*object, "motion")->isArray()))
628 if (op.maxTurnRateDegrees != 0.0) entry.emplace("maxTurnRateDegrees", Value(op.maxTurnRateDegrees));
632 if (op.avoidRadiusPadding != 0.0) entry.emplace("avoidRadiusPadding", Value(op.avoidRadiusPadding));
652 if (trigger.interval > Duration::zero()) entry.emplace("interval", Value(trigger.interval.seconds()));
653 if (trigger.proximityRadius > 0.0) entry.emplace("proximityRadius", Value(trigger.proximityRadius));
666 if (impact.pierceCount != 0) entry.emplace("pierceCount", Value(static_cast<std::int64_t>(impact.pierceCount)));
667 if (impact.bounceCount != 0) entry.emplace("bounceCount", Value(static_cast<std::int64_t>(impact.bounceCount)));
671 if (impact.childRecipeId.isValid()) entry.emplace("childRecipeId", Value(impact.childRecipeId.format()));
672 if (impact.bounceFriction != 0.0) entry.emplace("bounceFriction", Value(impact.bounceFriction));
673 if (impact.bounceSpreadDegrees != 0.0) entry.emplace("bounceSpreadDegrees", Value(impact.bounceSpreadDegrees));
674 if (impact.randomSeed != 0) entry.emplace("randomSeed", Value(static_cast<std::int64_t>(impact.randomSeed)));
Decode/encode CombatCarrier recipes from canonical eve::Value trees.
Stable, structured diagnostics shared by engine modules.
Common time values and an injectable deterministic simulation clock.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result< Duration > fromSeconds(double seconds)
Convert finite seconds to the nearest nanosecond.
Definition Time.cpp:17
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:37
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
Definition BuildingSnapshot.cpp:96
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:27
bool readString(const eve::Value::Object &object, const char *name, std::string &output)
Definition ArtifactProvider.cpp:21
ShapeState * child(const JPH::Body &body, const JPH::SubShapeID &id)
Resolves a native child record for a synchronous callback or query. @ownership Borrowed from the worl...
Definition JoltInternal.h:138
Result< std::optional< double > > readOptionalDouble(const Value::Object &object, std::string_view name, std::string_view path, std::string_view source)
Decode an optional finite number for the weapon codecs.
Definition NumericRead.h:24
Result< std::optional< int > > readOptionalInt(const Value::Object &object, std::string_view name, std::string_view path, std::string_view source)
Decode an optional native int, also accepting integral finite Doubles, for the weapon codecs.
Definition NumericRead.h:49
载具模块入口(eve.Vehicle):定义注册 / 实体工厂 / RTS 命令 / 帧调度。 设计文档:docs/dev/通用载具系统设计.md
Definition RTSArchetype.h:10
@ SpawnChild
@ EmitTrigger
CarrierMotionOpKind
Ordered ballistic operators applied each simulation step.
Definition CombatCarrier.h:32
@ ApplyGravity
@ SteerHoming
@ SteerWander
@ CurveHelix
@ SteerOrbit
@ RotateVelocity
@ IntegrateLinear
@ CurveSway
@ Accelerate
@ SpeedOscillate
@ SteerAvoidBody
@ ApplyDrag
@ SteerPredictive
Result< Value > encodeCarrierRecipe(const CarrierRecipe &recipe)
Encode one CarrierRecipe into an owning Value object (full form).
Definition CarrierRecipeCodec.cpp:612
Result< CarrierRecipe > decodeCarrierRecipe(const Value &value)
Decode one CarrierRecipe from an owning Value object.
Definition CarrierRecipeCodec.cpp:594
@ OnProximity
@ OnInterval
@ OnSpeedBelow
@ OnDistance
@ InvalidArgument
Result< std::string > readStringMember(const Value::Object &object, std::string_view name)
Read a required string field, including an empty string, as an owning value.
Definition Value.cpp:25
Data-driven composition recipe for one carrier family.
Definition CombatCarrier.h:144