| 40 | } |
| 41 | |
| 42 | void Particles1d::spawnRandomParticle() { |
| 43 | // First, try to find an inactive particle |
| 44 | for (size_t i = 0; i < mParticles.size(); i++) { |
| 45 | if (!mParticles[i].active) { |
| 46 | mParticles[i].spawn(mNumLeds); |
| 47 | return; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // All slots full - find and reuse the oldest particle |
| 52 | size_t oldestIdx = 0; |
| 53 | u32 oldestTime = mParticles[0].birthTime; |
| 54 | for (size_t i = 1; i < mParticles.size(); i++) { |
| 55 | if (mParticles[i].birthTime < oldestTime) { |
| 56 | oldestTime = mParticles[i].birthTime; |
| 57 | oldestIdx = i; |
| 58 | } |
| 59 | } |
| 60 | mParticles[oldestIdx].spawn(mNumLeds); |
| 61 | } |
| 62 | |
| 63 | void Particles1d::setLifetime(u16 lifetime_ms) { |
| 64 | mLifetimeMs = lifetime_ms; |