载入中...
搜索中...
未找到
ParticleBakeCapture.cpp
浏览该文件的文档.
2#include <cmath>
3#include <map>
4#include <set>
7namespace eve::particles {
12namespace {
14 std::span<const particles::ParticleRecordEvent> events) {
15 auto fail = [](const char* text) {
18 };
19 if (session.isNil() || !std::isfinite(duration) || duration < 0 || events.size() > 2000000)
20 return fail("invalid session, duration or event budget");
21 struct Birth {
22 ParticleTrajectory trajectory;
23 double lastTime = 0;
24 bool dead = false;
25 };
26 std::map<std::uint64_t, Birth> births;
27 double previous = 0;
28 for (const auto& event : events) {
29 if (!std::isfinite(event.seconds) || event.seconds < previous || event.seconds > duration ||
30 !event.birthSerial ||
33 return fail("invalid or out-of-order particle event");
34 previous = event.seconds;
35 const auto& p = event.appearance;
36 for (float v :
37 {p.x, p.y, p.w, p.h, p.rotation, p.color.r, p.color.g, p.color.b, p.color.a, p.u0, p.v0, p.u1, p.v1})
38 if (!std::isfinite(v)) return fail("nonfinite recorded appearance");
39 auto found = births.find(event.birthSerial);
40 if (found == births.end()) {
41 if (event.kind != particles::ParticleRecordEventKind::Snapshot || births.size() == 65536)
42 return fail("death without birth or birth budget exceeded");
43 found =
44 births.emplace(event.birthSerial, Birth{{session, event.birthSerial, {}}, event.seconds, false}).first;
45 }
46 auto& birth = found->second;
47 if (birth.dead) return fail("event after terminal death or reused birth identity");
48 const float time = static_cast<float>(event.seconds);
49 if (!birth.trajectory.keys.empty() && event.seconds != birth.lastTime &&
50 time <= birth.trajectory.keys.back().seconds)
51 return fail("particle times cannot be represented distinctly in asset precision");
53 time, {p.x, p.y, p.w, p.h, p.rotation, p.color.r, p.color.g, p.color.b, p.color.a, p.u0, p.v0, p.u1, p.v1}};
54 if (!birth.trajectory.keys.empty() && event.seconds == birth.lastTime)
55 birth.trajectory.keys.back() = key;
56 else
57 birth.trajectory.keys.push_back(key);
58 birth.lastTime = event.seconds;
59 birth.dead = event.kind == particles::ParticleRecordEventKind::Death;
60 }
61 std::vector<ParticleTrajectory> tracks;
62 tracks.reserve(births.size());
63 for (auto& [identity, birth] : births) {
64 (void)identity;
65 if (!birth.dead) return fail("recording ended with an unclosed birth");
66 if (birth.trajectory.keys.size() > 1) tracks.push_back(std::move(birth.trajectory));
67 }
68 return Result<std::vector<ParticleTrajectory>>::success(std::move(tracks));
69}
70} // namespace
71Result<ParticleTrack> buildParticleTrack(float duration, std::span<const ParticleRecordingSource> sources,
72 const BakeRecipe& recipe) {
73 if (sources.size() > 65536)
74 return Result<ParticleTrack>::failure(Diagnostic::error(
75 DiagnosticCode::InvalidArgument, "particle session budget exceeded", "particleBakeCapture"));
76 std::set<PersistentId> identities;
77 std::size_t events = 0;
78 for (const auto& source : sources) {
79 if (source.emitterSession.isNil() || !identities.insert(source.emitterSession).second ||
80 source.events.size() > 2000000 - events)
81 return Result<ParticleTrack>::failure(Diagnostic::error(
82 DiagnosticCode::InvalidArgument, "invalid or duplicate particle session, or event budget exceeded",
83 "particleBakeCapture"));
84 events += source.events.size();
85 }
86 std::vector<ParticleTrajectory> tracks;
87 for (const auto& source : sources) {
88 auto converted = convertEvents(source.emitterSession, duration, source.events);
89 if (!converted) return Result<ParticleTrack>::failure(converted.status());
90 auto values = std::move(converted).takeValue();
91 if (values.size() > 65536 - tracks.size())
92 return Result<ParticleTrack>::failure(Diagnostic::error(
93 DiagnosticCode::InvalidArgument, "combined particle birth budget exceeded", "particleBakeCapture"));
94 for (auto& value : values) tracks.push_back(std::move(value));
95 }
96 return ParticleTrack::prepare(duration, std::move(tracks), recipe);
97}
99 std::span<const particles::ParticleRecordEvent> events,
100 const BakeRecipe& recipe) {
102 return buildParticleTrack(duration, std::span<const ParticleRecordingSource>(&source, 1), recipe);
103}
104} // namespace eve::particles
float duration
glm::vec4 p[6]
SQObjectPtr key
Definition ECS.cpp:155
float v
std::int32_t first
std::vector< Track > tracks
std::vector< std::pair< std::uint64_t, OceanBoatReceipt > > sources
std::shared_ptr< const OceanSprayFrame > previous
std::vector< particles::ParticleRecordEvent > events
BakeRecipe recipe
std::set< std::string > values
std::set< std::string > identities
Object::Ptr value
bool found
std::string text
std::string_view source
std::optional< InteractionSession > session
Definition Tactics.cpp:39
uint64_t identity
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Id128 public API.
Definition Identity.h:111
Bounded provenance builder for explicit-coordinate baked recordings. @ownership Owns names and conten...
Definition BakeRecipe.h:21
Immutable particle trajectories independent of live simulation, ECS and graphics resources....
Result< ParticleTrack > buildParticleTrack(float duration, std::span< const ParticleRecordingSource > sources, const BakeRecipe &recipe)
Combine complete emitter journals into one immutable particle clip with a common recording recipe....
Borrowed complete journal for one uniquely identified emitter recording session. @ownership Events ar...
Explicit event/sample time and owning presentation value.
One birth's complete trajectory, including keys exactly at birth and death.