5#ifndef PARTICLE_SYSTEM_H
6#define PARTICLE_SYSTEM_H
11#include "src/system/ext/random8.h"
20using LampTy = hardware::LampTy;
36 isOccupiedSpaces.
reset();
46 particuleCount = std::min<uint16_t>(ParticleSystem::maxParticuleCount, _particleCount);
54 void init_particules(
const std::function<int16_t(
size_t)>& positionGeneratorFunction)
56 isOccupiedSpaces.
reset();
58 for (
size_t i = 0; i < particuleCount; ++i)
70 const std::function<int16_t(
size_t)>& positionGeneratorFunction)
72 for (
size_t i = 0; i < particuleCount and maxParticlesToPop > 0; ++i)
83 return maxParticlesToPop > 0;
93 const float deltaTime_s,
94 const bool shouldContrain =
true)
96 for (
size_t i = 0; i < particuleCount; ++i)
99 if (not isAllocated[i])
115 const float deltaTime_s,
116 const bool shouldContrain =
true)
118 for (
size_t i = 0; i < particuleCount; ++i)
121 if (not isAllocated[i])
132 if (newLedIndex != ledIndex)
137 isOccupiedSpaces[ledIndex] =
false;
138 isOccupiedSpaces[newLedIndex] =
true;
163 uint16_t particleCount = 0;
164 for (
size_t i = 0; i < particuleCount; ++i)
167 if (not isAllocated[i])
170 auto& parti = particules[i];
171 if (shouldDepopFunction(parti))
173 isAllocated[i] =
false;
174 isOccupiedSpaces[parti._savedLampIndex] =
false;
181 return particleCount;
191 uint16_t particleCount = 0;
192 for (
size_t i = 0; i < particuleCount; ++i)
195 if (not isAllocated[i])
197 const auto& particle = particules[i];
204 return particleCount;
210 uint16_t particleCount = 0;
211 for (
size_t i = 0; i < particuleCount; ++i)
214 if (not isAllocated[i])
218 return particleCount;
230 void spawn_particule(
const size_t index,
const std::function<int16_t(
size_t)>& positionGeneratorFunction)
232 int16_t pos = positionGeneratorFunction(index);
236 pos = positionGeneratorFunction(index);
241 particules[index] =
Particle(
utils::vec3d {helixCoordinates.
x, helixCoordinates.y, helixCoordinates.z});
242 isAllocated[index] =
true;
243 isOccupiedSpaces[pos] =
true;
247 static constexpr uint16_t maxParticuleCount = 512;
248 Particle particules[maxParticuleCount];
253 uint16_t particuleCount;
Define a compact bitset class for compile-time sized bit arrays.
A compact, zero-allocation bitset for compile-time sized bit arrays.
Definition: bitset.h:23
void reset() noexcept
Set all bits to 0.
Definition: bitset.h:74
Define a particle system ALL PARTICLE SYSTEM SHARE THE SAME PÄRTICLE SUBSET.
Definition: particle_system.hpp:27
void spawn_particule(const size_t index, const std::function< int16_t(size_t)> &positionGeneratorFunction)
Spawn a particle.
Definition: particle_system.hpp:230
uint16_t get_number_of_active() const
Return the number of active particles.
Definition: particle_system.hpp:208
bool init_deferred_particules(uint8_t maxParticlesToPop, const std::function< int16_t(size_t)> &positionGeneratorFunction)
Init the particles from a initialization function, in a timed defered way.
Definition: particle_system.hpp:69
uint16_t show(const std::function< uint32_t(int16_t, const Particle &)> sample_color, LampTy &lamp)
Display this particle system.
Definition: particle_system.hpp:189
bool is_position_taken(const int16_t pos) const
Return True if the position is already occupied.
Definition: particle_system.hpp:223
void iterate_no_collisions(const utils::vec3d &accelerationCartesian, const float deltaTime_s, const bool shouldContrain=true)
Advance the particle simulation, ignoring collisions.
Definition: particle_system.hpp:92
void set_max_particle_count(const uint16_t _particleCount)
Call when you want to change the particle count of the simulation Can be called once when starting th...
Definition: particle_system.hpp:44
uint16_t depop_particules(const std::function< bool(const Particle &)> &shouldDepopFunction)
Filter particles depending on condition.
Definition: particle_system.hpp:161
void init_particules(const std::function< int16_t(size_t)> &positionGeneratorFunction)
Init the particles from a initialization function.
Definition: particle_system.hpp:54
void reset()
reset system to zero count
Definition: particle_system.hpp:34
void iterate_with_collisions(const utils::vec3d &accelerationCartesian, const float deltaTime_s, const bool shouldContrain=true)
Advance the particle simulation, taking collisions in account.
Definition: particle_system.hpp:114
Define the main led strip interaction object.
Contains basic interface types to implement custom user modes.
Definition: control_fixed_modes.hpp:12
hardware::LampTy LampTy
Define a particle in cylindrical space, and movement equations on the cylinder surface.
Definition: particle.hpp:22
static constexpr bool is_led_index_valid(const int16_t ledIndex)
True if the given strip index is a valid one.
Definition: lamp_type.hpp:1193
static constexpr HelixXYZTy strip_to_helix_unconstraint(const int16_t n)
convert strip index to 3D coordinates, without checks on led index. This allows to use 3D coordinates...
Definition: lamp_type.hpp:1182
Define a single particle for a particle system.
Define a particle in 3D space. it has a position and speed.
Definition: particle.hpp:37
void apply_acceleration(const utils::vec3d &accelerationCartesian_m, const float deltaTime_s, const bool shouldContrain=true)
apply a cartesian acceleration to this particulate
Definition: particle.hpp:94
int16_t _savedLampIndex
optimization
Definition: particle.hpp:207
Particle simulate_after_acceleration(const utils::vec3d &accelerationCartesian_m, const float deltaTime_s, const bool shouldContrain=true) const
Simulate this particle movement as a new particle.
Definition: particle.hpp:136
float thetaSpeed_radS
angular speed, in radian/seconds
Definition: particle.hpp:200
float zSpeed_mS
linear speed, in meter/seconds
Definition: particle.hpp:201
Main interface between the user and the hardware of the lamp.
Definition: lamp_type.hpp:118
void LMBD_INLINE setPixelColor(uint16_t n, uint32_t color)
(indexable) Set the n-th LED color
Definition: lamp_type.hpp:878
float x
x coordinate in 2D
Definition: vector_math.h:16
3d vector in any space
Definition: vector_math.h:54