载入中...
搜索中...
未找到
ParticleEffect.cpp
浏览该文件的文档.
48 return (std::filesystem::path(sourcePath).parent_path() / reference).lexically_normal().generic_string();
53 for (const auto& key : parameters.keys()) emitter->setFloatParameter(key, parameters.getFloat(key.c_str(), 0.f));
62 return action == "start" || action == "stop" || action == "pause" || action == "reset" || action == "emit" ||
72 Diagnostic::error(DiagnosticCode::InvalidArgument, "effect eventRoutes must be an array", "eventRoutes"));
77 Diagnostic::error(DiagnosticCode::InvalidArgument, "event route must be an object", "eventRoutes"));
82 route.inheritVelocity = routeObject.has("inheritVelocity") ? routeObject.getFloat("inheritVelocity", 0.f) : 0.f;
85 DiagnosticCode::InvalidArgument, "event route requires from and to emitter names", "eventRoutes"));
104 Diagnostic::error(DiagnosticCode::InvalidArgument, "effect timeline must be an object", "timeline"));
115 Diagnostic::error(DiagnosticCode::InvalidArgument, "timeline.cues must be an array", "timeline.cues"));
120 Diagnostic::error(DiagnosticCode::InvalidArgument, "timeline cue must be an object", "timeline.cues"));
139 DiagnosticCode::InvalidArgument, "timeline emit cue requires a positive count", "timeline.cues.count"));
144 if ((cue.action == "start" || cue.action == "stop" || cue.action == "pause" || cue.action == "reset" ||
154 [](const ParticleEffectTimelineCue& a, const ParticleEffectTimelineCue& b) { return a.time < b.time; });
160Result<ParticleEffect*> ParticleEffect::parse(const std::string& json, const std::string& sourcePath) {
171 Diagnostic::error(DiagnosticCode::InvalidArgument, "effect type must be eve.particle-effect", "type"));
173 if (version < ParticleEffect::kMinSupportedVersion || version > ParticleEffect::kMaxSupportedVersion)
175 DiagnosticCode::Unsupported, "unsupported particle effect version: " + std::to_string(version), "version"));
213 const std::string name = layerObject.has("name") ? layerObject.getString("name") : std::string();
220 Diagnostic::error(DiagnosticCode::Conflict, "duplicate emitter layer name: " + name, "emitters.name"));
230 const std::string configPath = layerObject.has("config") ? layerObject.getString("config") : std::string();
237 DiagnosticCode::InvalidArgument, "emitter layer " + name + " requires emitter or config", "emitters"));
249 configError = (diag && !diag->message().empty()) ? diag->message() : "config root must be object";
257 Diagnostic::error(DiagnosticCode::Failed, "emitter layer " + name + ": " + configError, "emitters"));
276 const float localRotation = layerObject.has("rotation") ? layerObject.getFloat("rotation", 0.f) : 0.f;
288 DiagnosticCode::NotFound, "event route references unknown emitter: " + route.from + " -> " + route.to,
294 Diagnostic::error(DiagnosticCode::NotFound, "timeline cue references unknown emitter: " + cue.emitter,
313ParticleEffect* ParticleEffect::fromText(const std::string& json, const std::string& sourcePath, std::string* error) {
345Result<ParticleEffect*> ParticleEffect::tryFromText(const std::string& json, const std::string& sourcePath) {
365 return tryFromText(std::string(static_cast<const char*>(data->getData()), data->getSize()), path);
400 DiagnosticCode::InvalidArgument, "Particle effect contains invalid lifetime data", "emitters"));
404 DiagnosticCode::Unsupported, "Particle effect contains an unbounded looping emitter", "emitters"));
415 Diagnostic::error(DiagnosticCode::NotFound, "Particle effect has no enabled emitters", "emitters"));
472 if (!timelinePlaying_ || timelinePaused_) return Result<void>::success(Status::success(StatusCode::NoOp));
475 DiagnosticCode::InvalidArgument, "timeline step duration must be finite and non-negative", "step.delta"));
536 return Result<void>::success(Status::success(changed ? StatusCode::Applied : StatusCode::NoOp));
596 return Result<void>::success(Status::success(changed ? StatusCode::Applied : StatusCode::NoOp));
607 Diagnostic::error(DiagnosticCode::NotFound, "timeline cue emitter is missing: " + cue.emitter, "emitter"));
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 Result< Duration > fromSeconds(double seconds)
Convert finite seconds to the nearest nanosecond.
Definition Time.cpp:16
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:537
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
static Document parse(const std::string &text, std::string *error=nullptr)
Parse.
Definition Json.cpp:581
Runtime instance of a versioned, multi-emitter particle effect asset.
Definition ParticleEffect.h:68
static Result< ParticleEffect * > tryFromFile(const std::string &path)
Load an effect asset file and return a structured Result.
Definition ParticleEffect.cpp:349
static Result< ParticleEffect * > tryFromText(const std::string &json, const std::string &sourcePath={})
Parse an effect asset and return a structured Result.
Definition ParticleEffect.cpp:345
bool hasFloatParameter(const std::string &name) const
Return true when the asset declares the parameter.
Definition ParticleEffect.cpp:700
ParticleEmitter * getEmitter(int index) const
Return an emitter layer by index, or null.
Definition ParticleEffect.cpp:375
Result< void > reloadFromText(const std::string &json)
Atomically replace this instance from JSON text.
Definition ParticleEffect.cpp:423
Result< Duration > naturalDuration() const
Calculate when every enabled finite emitter and its particles have ended.
Definition ParticleEffect.cpp:389
void setPosition(float x, float y)
Set the group transform origin in world space.
Definition ParticleEffect.cpp:625
void reset()
Reset every emitter timeline, clear particles, and rewind cues.
Definition ParticleEffect.cpp:674
static ParticleEffect * fromFile(const std::string &path, std::string *error=nullptr)
Read, parse, and instantiate an effect asset.
Definition ParticleEffect.cpp:329
const ParticleEffectTimeline & timeline() const
Return authored timeline controls.
Definition ParticleEffect.h:115
ParticleEffect(const ParticleEffect &)=delete
Result< void > reloadFromFile(const std::string &path={})
Atomically reload from sourcePath, or an explicit path override.
Definition ParticleEffect.cpp:431
void setVisible(bool visible)
Set visibility for every emitter layer.
Definition ParticleEffect.cpp:646
static Result< void > advanceRegisteredTimelines(const SimulationStep &step)
Advance registered timelines from an injected scheduler step.
Definition ParticleEffect.cpp:525
Result< void > advanceTimeline(const SimulationStep &step)
Advance the effect-local timeline and fire due cues.
Definition ParticleEffect.cpp:471
ParticleEmitter * getEmitterByName(const std::string &name) const
Return an emitter layer by name, or null.
Definition ParticleEffect.cpp:380
void setLayer(int layer)
Offset all emitter render layers while preserving asset-local ordering.
Definition ParticleEffect.cpp:641
static ParticleEffect * fromText(const std::string &json, const std::string &sourcePath, std::string *error=nullptr)
Parse and instantiate an effect asset from JSON text.
Definition ParticleEffect.cpp:313
void start()
Start every enabled emitter and the effect timeline clock.
Definition ParticleEffect.cpp:651
std::span< const ParticleEffectEventRoute > eventRoutes() const
Return authored event routes (borrowed snapshot of asset data).
Definition ParticleEffect.cpp:385
void setFloatParameter(const std::string &name, float value)
Set one gameplay parameter on every layer that declares or binds it.
Definition ParticleEffect.cpp:689
int getEmitterCount() const
Return the number of named emitter layers.
Definition ParticleEffect.cpp:368
float getFloatParameter(const std::string &name) const
Return an effect parameter value, or zero when unknown.
Definition ParticleEffect.cpp:695
std::string getEmitterName(int index) const
Return a stable layer name by index, or empty text.
Definition ParticleEffect.cpp:370
static constexpr int kMaxSupportedVersion
Highest schema version accepted by this build.
Definition ParticleEffect.h:71
static void tickRegisteredTimelines(float dt)
Advance every effect that auto-registered a playing timeline.
Definition ParticleEffect.cpp:518
void setRotation(float radians)
Rotate local offsets and emitter directions in radians.
Definition ParticleEffect.cpp:631
bool emit(const std::string &emitterName, int count)
Emit a manual burst from one named layer.
Definition ParticleEffect.cpp:682
void updateTimeline(float dt)
Legacy seconds facade for timeline cues; consumes Result internally.
Definition ParticleEffect.cpp:506
ECS emitter entity. Script configures components; ParticleSimSystem / ParticleRenderSystem drive per-...
Definition ParticleEmitter.h:71
static ParticleEmitter * createEmitter(int bufferSize=1000)
Definition ParticleEmitter.cpp:712
Result< T > applied(T value, std::vector< Diagnostic > diagnostics={})
Construct an Applied result with an owning payload and optional diagnostics.
Definition EditingResult.h:43
Definition ParticleGraph.h:53
bool loadConfigFile(ParticleEmitter *emitter, const std::string &path, std::string *error)
Read path via Filesystem, apply, and bind Resource.path + modtime for hot reload. Returns false if fi...
Definition ParticleConfig.cpp:475
eve::Result< void > applyConfigDocument(ParticleEmitter *emitter, eve::json::Value root)
Apply particle JSON config onto an emitter, including material texture resources. Does not change buf...
Definition ParticleConfig.cpp:117
@ InvalidArgument
@ NotFound
@ Unsupported
@ Failed
@ Conflict
@ NoOp
@ Applied