MCPcopy Create free account
hub / github.com/NazaraEngine/NazaraEngine / Emit

Method Emit

src/Nazara/Graphics/ParticleEmitter.cpp:59–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

UpdateMethod · 0.45

Calls 4

GetMaxParticleCountMethod · 0.80
GetParticleCountMethod · 0.80
GenerateParticlesMethod · 0.80
ApplyControllersMethod · 0.80

Tested by

no test coverage detected