|
Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
|
#include <ParticleSystem.hpp>
Public Member Functions | |
| ParticleSystem () | |
| void | reseedFrom (const esengine::RandomSource &source) |
| void | update (ecs::Registry ®istry, f32 dt) |
| void | setGpuAvailable (bool available) |
| bool | gpuAvailable () const |
| bool | peekGpuStep (Entity entity, GpuStep &out) const |
| void | commitGpuStep (Entity entity, const GpuStep &step) |
| The kernel ran this step: the time and births it covered are spent. | |
| const std::vector< ForceFieldInstance > & | forceFields () const |
| const std::vector< SdfColliderInstance > & | sdfColliders () const |
| void | addGpuCollisions (Entity entity, u32 total, const CollisionEvent *events, u32 count) |
| Collisions a kernel reported, a frame or two late since they come back from the GPU; they reach the game as any others do. | |
| const std::vector< CollisionQuery > & | collisionQueries () const |
| const std::vector< CollisionEvent > & | collisionEvents () const |
| const std::vector< CollisionStats > & | collisionStats () const |
| void | setCollisionBudget (u32 queries, u32 events, bool debug=false) |
| void | resolveCollisions (ecs::Registry ®istry, const CollisionReply *replies, u32 count) |
| void | play (Entity entity) |
| void | stop (Entity entity) |
| void | reset (Entity entity) |
| u32 | aliveCount (Entity entity) const |
| u32 | emitAt (ecs::Registry ®istry, Entity entity, u32 count, const glm::vec3 &position, const glm::vec3 &normal, const glm::vec3 &velocity) |
Spawn count of entity's particles at a world point, now: an impact's sparks, a muzzle's flash, without moving the emitter or replaying it. | |
| u32 | totalAliveParticles () const |
| void | setParticleLimit (u32 limit) |
| template<typename Fn> | |
| void | forEachParticle (Entity entity, Fn &&fn) const |
| EmitterState * | getState (Entity entity) |
| const EmitterState * | getState (Entity entity) const |
| void | setColorLut (Entity entity, const f32 *rgba, i32 count) |
| void | setSizeLut (Entity entity, const f32 *values, i32 count) |
| void | setSpeedLut (Entity entity, const f32 *values, i32 count) |
| void | setBursts (Entity entity, const f32 *values, i32 count) |
| const ColorLut * | colorLut (Entity entity) const |
| The over-life curves an entity was given, for the GPU kernel to read; null where none was set. | |
| const SizeLut * | sizeLut (Entity entity) const |
| const SizeLut * | speedLut (Entity entity) const |
Static Public Attributes | |
| static constexpr const char * | kRandomStream = "particles" |
| static constexpr u32 | kGpuMaxCapacity = 2'000'000 |
| static constexpr u32 | kGpuFallbackCapacity = 20'000 |
Definition at line 138 of file ParticleSystem.hpp.
| esengine::particle::ParticleSystem::ParticleSystem | ( | ) |
Definition at line 16 of file ParticleSystem.cpp.
References kRandomStream.
| void esengine::particle::ParticleSystem::addGpuCollisions | ( | Entity | entity, |
| u32 | total, | ||
| const CollisionEvent * | events, | ||
| u32 | count ) |
Collisions a kernel reported, a frame or two late since they come back from the GPU; they reach the game as any others do.
Definition at line 908 of file ParticleSystem.cpp.
References addGpuCollisions().
Referenced by addGpuCollisions().
Definition at line 372 of file ParticleSystem.cpp.
|
inline |
Definition at line 173 of file ParticleSystem.hpp.
|
inline |
Definition at line 172 of file ParticleSystem.hpp.
|
inline |
Definition at line 174 of file ParticleSystem.hpp.
The over-life curves an entity was given, for the GPU kernel to read; null where none was set.
Definition at line 226 of file ParticleSystem.hpp.
The kernel ran this step: the time and births it covered are spent.
Definition at line 401 of file ParticleSystem.cpp.
References esengine::particle::EmitterState::gpuBurst, esengine::particle::EmitterState::gpuDt, esengine::particle::EmitterState::gpuReset, esengine::particle::EmitterState::gpuSmooth, and esengine::particle::EmitterState::gpuSpawned.
| u32 esengine::particle::ParticleSystem::emitAt | ( | ecs::Registry & | registry, |
| Entity | entity, | ||
| u32 | count, | ||
| const glm::vec3 & | position, | ||
| const glm::vec3 & | normal, | ||
| const glm::vec3 & | velocity ) |
Spawn count of entity's particles at a world point, now: an impact's sparks, a muzzle's flash, without moving the emitter or replaying it.
The emitter's own settings make them (shape, speed, size, colour, life). Its shape stands at position, turned so its local +Y — a cone's or a hemisphere's axis — points along normal when one is given, and as the entity is turned otherwise; velocity is added to every particle. A Local-space emitter keeps them in its own frame, as a sub-emitter's burst is kept. CPU-simulated emitters only: a GPU one answers 0.
Definition at line 517 of file ParticleSystem.cpp.
References esengine::particle::ParticlePool::aliveCount(), esengine::ecs::Registry::get(), esengine::particle::EmitterState::gpu, esengine::ecs::Registry::has(), esengine::ecs::Local, esengine::particle::EmitterState::pool, esengine::ecs::Registry::valid(), and esengine::ecs::Transform::worldRotation.
|
inline |
Definition at line 164 of file ParticleSystem.hpp.
|
inline |
Definition at line 202 of file ParticleSystem.hpp.
| EmitterState * esengine::particle::ParticleSystem::getState | ( | Entity | entity | ) |
Definition at line 420 of file ParticleSystem.cpp.
| const EmitterState * esengine::particle::ParticleSystem::getState | ( | Entity | entity | ) | const |
Definition at line 425 of file ParticleSystem.cpp.
|
inline |
Definition at line 154 of file ParticleSystem.hpp.
What a GPU emitter has to do to catch up: the time, the births, where in the ring they go. False when the entity is not simulated on the GPU. Nothing is consumed until commitGpuStep, so a step that was asked for and never run (a collect whose frame did not reach the graph) is asked for again next time rather than lost.
Definition at line 382 of file ParticleSystem.cpp.
References esengine::particle::GpuStep::capacity, esengine::particle::GpuStep::drawCount, esengine::particle::GpuStep::dt, esengine::particle::GpuStep::fed, esengine::particle::GpuStep::firstIndex, esengine::particle::EmitterState::gpuBurst, esengine::particle::EmitterState::gpuCapacity, esengine::particle::EmitterState::gpuDt, esengine::particle::EmitterState::gpuFed, esengine::particle::EmitterState::gpuReset, esengine::particle::EmitterState::gpuSmooth, esengine::particle::EmitterState::gpuSpawned, esengine::particle::EmitterState::noise_time, esengine::particle::GpuStep::noiseTime, esengine::particle::GpuStep::reset, esengine::particle::GpuStep::smoothCount, and esengine::particle::GpuStep::spawnCount.
| void esengine::particle::ParticleSystem::play | ( | Entity | entity | ) |
Definition at line 293 of file ParticleSystem.cpp.
| void esengine::particle::ParticleSystem::reseedFrom | ( | const esengine::RandomSource & | source | ) |
Re-derive this system's generator from the engine's seed. Spawns after this point reproduce; particles already alive keep the values they got.
Definition at line 19 of file ParticleSystem.cpp.
References kRandomStream, and esengine::RandomSource::stream().
| void esengine::particle::ParticleSystem::reset | ( | Entity | entity | ) |
Definition at line 313 of file ParticleSystem.cpp.
| void esengine::particle::ParticleSystem::resolveCollisions | ( | ecs::Registry & | registry, |
| const CollisionReply * | replies, | ||
| u32 | count ) |
Definition at line 943 of file ParticleSystem.cpp.
References esengine::particle::Particle::age, esengine::particle::Particle::alive, esengine::particle::CollisionReply::body, esengine::ecs::ParticleEmitter::collisionEnabled, esengine::ecs::ParticleEmitter::collisionFallback, esengine::particle::ParticlePool::deallocateByIndex(), esengine::ecs::ParticleEmitter::enabled, esengine::Entity::fromRaw(), esengine::particle::Particle::generation, esengine::ecs::Registry::get(), esengine::ecs::Registry::has(), esengine::particle::kMaxTrailPoints, esengine::particle::Particle::lifetime, esengine::particle::CollisionReply::nx, esengine::particle::CollisionReply::ny, esengine::particle::CollisionReply::nz, esengine::particle::ParticlePool::particles(), esengine::particle::EmitterState::pool, esengine::particle::Particle::position, resolveCollisions(), esengine::particle::CollisionReply::status, esengine::ecs::ParticleEmitter::subEmitter, esengine::ecs::ParticleEmitter::subEmitterChance, esengine::ecs::ParticleEmitter::subEmitterInheritVelocity, esengine::particle::EmitterState::trail_count, esengine::particle::EmitterState::trail_pos, esengine::ecs::Registry::valid(), esengine::particle::CollisionReply::x, esengine::particle::CollisionReply::y, and esengine::particle::CollisionReply::z.
Referenced by resolveCollisions().
|
inline |
Definition at line 165 of file ParticleSystem.hpp.
Set/clear an entity's burst schedule: count pairs of (seconds, particles) in values. Each fires once per pass of the emitter's clock over its time, and a looping emitter passes every duration.
Definition at line 360 of file ParticleSystem.cpp.
|
inline |
Definition at line 175 of file ParticleSystem.hpp.
Set (count == kColorLutSize) or clear (count == 0) an entity's color-over-life LUT. When set, particle color is sampled from it instead of start/end+easing.
Definition at line 331 of file ParticleSystem.cpp.
References esengine::particle::kColorLutSize.
|
inline |
Whether emitters that ask for GPU simulation get it. Set by the renderer, which knows the device; false means they run on the CPU, capped at kGpuFallbackCapacity.
Definition at line 153 of file ParticleSystem.hpp.
|
inline |
Definition at line 199 of file ParticleSystem.hpp.
| void esengine::particle::ParticleSystem::setSizeLut | ( | Entity | entity, |
| const f32 * | values, | ||
| i32 | count ) |
Set/clear an entity's size-over-life multiplier LUT (× the particle's start size).
Definition at line 342 of file ParticleSystem.cpp.
References esengine::particle::kColorLutSize.
| void esengine::particle::ParticleSystem::setSpeedLut | ( | Entity | entity, |
| const f32 * | values, | ||
| i32 | count ) |
Set/clear an entity's speed-over-life multiplier LUT. It scales how fast a particle travels along the trajectory it already has — it is not a force, and gravity, damping and noise still accumulate into velocity as before.
Definition at line 351 of file ParticleSystem.cpp.
References esengine::particle::kColorLutSize.
Definition at line 227 of file ParticleSystem.hpp.
Definition at line 228 of file ParticleSystem.hpp.
| void esengine::particle::ParticleSystem::stop | ( | Entity | entity | ) |
Definition at line 305 of file ParticleSystem.cpp.
| u32 esengine::particle::ParticleSystem::totalAliveParticles | ( | ) | const |
Definition at line 412 of file ParticleSystem.cpp.
| void esengine::particle::ParticleSystem::update | ( | ecs::Registry & | registry, |
| f32 | dt ) |
Definition at line 23 of file ParticleSystem.cpp.
References esengine::ecs::Registry::activeView(), esengine::particle::ParticlePool::aliveCount(), esengine::ecs::Box, esengine::particle::EmitterState::burst_clock, esengine::particle::EmitterState::burst_timer, esengine::particle::burstsDue(), esengine::particle::ForceFieldInstance::direction, esengine::particle::EmitterState::elapsed_time, esengine::particle::EmitterState::emission_accumulator, esengine::particle::CollisionStats::emitter, esengine::ecs::Transform::ensureDecomposed(), esengine::particle::CollisionStats::eventDropped, esengine::particle::CollisionStats::events, esengine::particle::SdfColliderInstance::ext, esengine::particle::ForceFieldInstance::falloff, esengine::particle::EmitterState::first_update, esengine::Entity::fromRaw(), esengine::particle::EmitterState::gpu, esengine::particle::EmitterState::gpuBurst, esengine::particle::EmitterState::gpuCapacity, esengine::particle::CollisionStats::hits, esengine::particle::SdfColliderInstance::inverted, esengine::ecs::Camera::isActive, kGpuFallbackCapacity, kGpuMaxCapacity, esengine::particle::kMaxTrailPoints, esengine::particle::SdfColliderInstance::mask, esengine::particle::CollisionStats::mode, esengine::particle::EmitterState::noise_time, esengine::ecs::Registry::onDestroy(), esengine::particle::EmitterState::playing, esengine::particle::EmitterState::pool, esengine::particle::ForceFieldInstance::position, esengine::particle::SdfColliderInstance::position, esengine::particle::ForceFieldInstance::radius, esengine::particle::ForceFieldInstance::radiusSq, esengine::particle::SdfColliderInstance::rotation, esengine::particle::SdfColliderInstance::shape, esengine::particle::ForceFieldInstance::strength, esengine::particle::ForceFieldInstance::type, and esengine::ecs::World.
|
staticconstexpr |
Definition at line 156 of file ParticleSystem.hpp.
Referenced by update().
|
staticconstexpr |
Definition at line 155 of file ParticleSystem.hpp.
Referenced by update().
|
staticconstexpr |
The engine stream this system draws from — see core/RandomSource.hpp.
Definition at line 141 of file ParticleSystem.hpp.
Referenced by ParticleSystem(), and reseedFrom().