| 57 | */ |
| 58 | |
| 59 | void ParticleEmitter::Emit(ParticleGroup& system, float elapsedTime) const |
| 60 | { |
| 61 | if (m_emissionRate > 0.f) |
| 62 | { |
| 63 | // We accumulate the real part (to avoid that a high emission rate prevents particles to form) |
| 64 | m_emissionAccumulator += elapsedTime * m_emissionRate; |
| 65 | |
| 66 | float emissionCount = std::floor(m_emissionAccumulator); // The number of emissions in this update |
| 67 | m_emissionAccumulator -= emissionCount; // We get rid off the integer part |
| 68 | |
| 69 | if (emissionCount >= 1.f) |
| 70 | { |
| 71 | // We compute the maximum number of particles which can be emitted |
| 72 | std::size_t emissionCountInt = static_cast<std::size_t>(emissionCount); |
| 73 | std::size_t maxParticleCount = emissionCountInt * m_emissionCount; |
| 74 | |
| 75 | // We get the number of particles that we are able to create (depending on the free space) |
| 76 | std::size_t particleCount = std::min(maxParticleCount, system.GetMaxParticleCount() - system.GetParticleCount()); |
| 77 | if (particleCount == 0) |
| 78 | return; |
| 79 | |
| 80 | // And we emit our particles |
| 81 | void* particles = system.GenerateParticles(particleCount); |
| 82 | ParticleMapper mapper(particles, system.GetDeclaration()); |
| 83 | |
| 84 | SetupParticles(mapper, particleCount); |
| 85 | |
| 86 | if (m_lagCompensationEnabled) |
| 87 | { |
| 88 | // We will now apply our controllers |
| 89 | float invEmissionRate = 1.f / m_emissionRate; |
| 90 | for (unsigned int i = 1; i <= emissionCountInt; ++i) |
| 91 | system.ApplyControllers(mapper, std::min(m_emissionCount * i, particleCount), invEmissionRate); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /*! |
| 98 | * \brief Enables the lag compensation |
no test coverage detected