-------------------------------------------------------------------------------------- Description: Implements ITr2GenericEmitter interface. Spawns particles. Arguments: arguments - Update arguments position - Position of the "parent" particle (if the emitter owning this generator is "emit during life" or "emit on death" emitter and parent particle has position element); otherwise is nullptr. velo
| 148 | // defined rate value. |
| 149 | // -------------------------------------------------------------------------------------- |
| 150 | void Tr2DynamicEmitter::SpawnParticles( const UpdateArguments& arguments, |
| 151 | const Vector3* position, |
| 152 | const Vector3* velocity, |
| 153 | float rateModifier ) |
| 154 | { |
| 155 | CCP_STATS_ZONE( __FUNCTION__ ); |
| 156 | |
| 157 | if( !m_isValid || m_particleSystem == nullptr ) |
| 158 | { |
| 159 | return; |
| 160 | } |
| 161 | if( m_declarationHash != m_particleSystem->GetElementDeclarationHash() ) |
| 162 | { |
| 163 | m_isValid = false; |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | // spawn rate |
| 168 | if( m_rate <= 0 ) |
| 169 | { |
| 170 | return; |
| 171 | } |
| 172 | m_accumulatedRate += m_rate * rateModifier; |
| 173 | int32_t count = int32_t( m_accumulatedRate ); |
| 174 | m_accumulatedRate -= floor( m_accumulatedRate ); |
| 175 | if( m_maxParticles >= 0 && int32_t( m_emittedParticles ) + count > m_maxParticles ) |
| 176 | { |
| 177 | count = std::max( m_maxParticles - int32_t( m_emittedParticles ), 0 ); |
| 178 | } |
| 179 | m_emittedParticles += count; |
| 180 | |
| 181 | // update position if we have any |
| 182 | Vector3 transformedEmitterPos( 0.f, 0.f, 0.f ); |
| 183 | if( position ) |
| 184 | { |
| 185 | transformedEmitterPos = *position; |
| 186 | } |
| 187 | |
| 188 | float* particle[Tr2ParticleElementData::COUNT]; |
| 189 | for( int32_t i = 0; i < count; ++i ) |
| 190 | { |
| 191 | if( !m_particleSystem->InsertParticle( particle ) ) |
| 192 | { |
| 193 | // Particle system is full |
| 194 | return; |
| 195 | } |
| 196 | |
| 197 | // build an interpolated position "between frames" |
| 198 | XMFLOAT4A interpolatedEmitterPos( transformedEmitterPos.x, transformedEmitterPos.y, transformedEmitterPos.z, 1.f ); |
| 199 | |
| 200 | // let every attached generator have it's way with the new particle |
| 201 | for( auto it = m_generators.begin(); it != m_generators.end(); ++it ) |
| 202 | { |
| 203 | ( *it )->Generate( reinterpret_cast<Vector3*>( &interpolatedEmitterPos ), velocity, particle ); |
| 204 | } |
| 205 | m_particleSystem->DoneInsertingParticle(); |
| 206 | } |
| 207 |
nothing calls this directly
no test coverage detected