17#include <unordered_map>
18#include <unordered_set>
66f32 sdfDistance(
const SdfColliderInstance& c,
const glm::vec3& point);
164 const std::vector<ForceFieldInstance>&
forceFields()
const {
return force_fields_; }
165 const std::vector<SdfColliderInstance>&
sdfColliders()
const {
return sdf_colliders_; }
173 const std::vector<CollisionEvent>&
collisionEvents()
const {
return collision_events_; }
174 const std::vector<CollisionStats>&
collisionStats()
const {
return collision_stats_; }
176 collision_debug_ = debug;
177 query_budget_ = std::min(queries, 65536u); event_budget_ = std::min(events, 16384u);
197 const glm::vec3& normal,
const glm::vec3& velocity);
201 template<
typename Fn>
203 auto it = states_.find(entity);
204 if (it != states_.end()) it->second.pool.forEachAlive(fn);
242 glm::vec3 velocityBias,
u32 count,
bool allowBirthTrigger,
u32 depth = 0,
247 f32 inheritVelocity,
f32 chance);
260 u32 collisionQuota(
Entity emitter)
const;
266 struct SubEmitRequest { glm::vec3 position; glm::vec3 velocity;
u32 depth = 0; };
267 std::vector<SubEmitRequest> subemit_requests_;
269 struct PendingCollision {
Entity emitter;
u32 generation; EmitterFrame frame;
bool world; std::size_t stats; };
270 std::vector<CollisionQuery> collision_queries_;
271 std::vector<PendingCollision> collision_pending_;
272 std::vector<CollisionEvent> collision_events_;
273 std::vector<CollisionStats> collision_stats_;
274 std::vector<glm::vec3> collision_cameras_;
275 Entity collision_emitter_{};
276 std::size_t collision_stats_index_ = 0;
277 u32 query_budget_ = 4096, event_budget_ = 1024, event_attempts_ = 0;
278 u32 collision_child_bursts_ = 0;
279 u32 collision_frame_ = 0;
280 bool collision_debug_ =
false;
281 std::unordered_map<Entity, u32> collision_quotas_;
282 std::vector<Entity> scene_emitters_;
283 std::vector<SubEmitRequest> drain_scratch_;
284 std::unordered_map<Entity, EmitterState> states_;
287 std::unordered_set<Entity> pending_play_;
288 std::unordered_map<Entity, ColorLut> colorLuts_;
289 std::unordered_map<Entity, SizeLut> sizeLuts_;
290 std::unordered_map<Entity, SizeLut> speedLuts_;
291 std::unordered_map<Entity, std::vector<ScheduledBurst>> burstSchedules_;
293 bool gpu_available_ =
false;
294 u32 particle_limit_ = 0xffffffffu;
295 std::vector<u32> dead_particle_indices_;
298 std::vector<ForceFieldInstance> force_fields_;
299 std::vector<SdfColliderInstance> sdf_colliders_;
300 struct GpuCollisions { Entity entity;
u32 total; std::vector<CollisionEvent> events; };
301 std::vector<GpuCollisions> gpu_collisions_;
304 Connection destroyConn_;
Math utilities and GLM configuration for ESEngine.
A shape particles bounce off without any physics: a signed distance a compute kernel can answer per p...
A scene-placed force zone that pushes every world-space particle near it.
Where a particle is born and which way it leaves — a pure function of the emitter's own configuration...
Reflection and metadata system for automatic binding generation.
#define ES_CONST(...)
Mark a constant that CROSSES the boundary, so EHT emits its TS twin.
Central ECS registry for entity and component management.
Core type definitions and utilities for ESEngine.
Central container for all entities and components.
bool gpuAvailable() const
const SizeLut * speedLut(Entity entity) const
void setSizeLut(Entity entity, const f32 *values, i32 count)
EmitterState * getState(Entity entity)
void setParticleLimit(u32 limit)
void forEachParticle(Entity entity, Fn &&fn) const
void reset(Entity entity)
void update(ecs::Registry ®istry, f32 dt)
const std::vector< ForceFieldInstance > & forceFields() const
const std::vector< SdfColliderInstance > & sdfColliders() const
const std::vector< CollisionStats > & collisionStats() const
u32 totalAliveParticles() const
void setBursts(Entity entity, const f32 *values, i32 count)
const std::vector< CollisionQuery > & collisionQueries() const
static constexpr u32 kGpuMaxCapacity
static constexpr u32 kGpuFallbackCapacity
void reseedFrom(const esengine::RandomSource &source)
const SizeLut * sizeLut(Entity entity) const
u32 aliveCount(Entity entity) 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 g...
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,...
void resolveCollisions(ecs::Registry ®istry, const CollisionReply *replies, u32 count)
void setGpuAvailable(bool available)
void commitGpuStep(Entity entity, const GpuStep &step)
The kernel ran this step: the time and births it covered are spent.
const std::vector< CollisionEvent > & collisionEvents() const
static constexpr const char * kRandomStream
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.
bool peekGpuStep(Entity entity, GpuStep &out) const
void setCollisionBudget(u32 queries, u32 events, bool debug=false)
void setSpeedLut(Entity entity, const f32 *values, i32 count)
void setColorLut(Entity entity, const f32 *rgba, i32 count)
constexpr int kColorLutSize
f32 sdfDistance(const SdfColliderInstance &c, const glm::vec3 &point)
How far a world point is outside a collider, negative inside; what the kernel's sdfOne answers.
std::array< f32, kColorLutSize > SizeLut
constexpr int kMaxTrailPoints
std::array< glm::vec4, kColorLutSize > ColorLut
std::int32_t i32
Signed 32-bit integer.
std::uint32_t u32
Unsigned 32-bit integer.
float f32
32-bit floating point
Entity identifier with packed index + generation.
EmitterState(u32 capacity)
std::vector< glm::vec3 > trail_pos
f32 burst_clock
Where the scheduled bursts last looked: the emitting clock of the previous step, below zero before th...
std::vector< u8 > trail_count
What one frame asks of a GPU-simulated emitter: how long to advance, how many to spawn and where in t...
bool fed
A GPU parent's events spawn into it, so any slot may be live whatever was scheduled.
u32 firstIndex
Absolute index of the first particle born this step (slot = index % capacity).
u32 spawnCount
Born this step: smoothCount spread across dt, then the rest as one burst.
bool reset
Kill everything first (a reset() since the last step).
u32 drawCount
Slots that may hold a live particle once this step has run.