private void UpdateParticlesCreation() { if (!Enabled.GetValue <bool>()) { return; } //particles to create in this update if (!m_effect.IsStopped) { float lodBirth = 1.0f; if (GetEffect().EnableLods) { LODBirth.GetInterpolatedValue <float>(GetEffect().Distance, out lodBirth); } Birth.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out m_birthRate); m_birthRate *= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * (EnableCustomBirth ? m_effect.UserBirthMultiplier : 1.0f) * MyParticlesManager.BirthMultiplierOverall * lodBirth; m_particlesToCreate += m_birthRate; } //If speed of effect is too high, there would be created bunches //of particles each frame. By interpolating position, we create //seamless particle creation. Vector3 positionDelta = Vector3.Zero; if (!m_lastEffectPosition.HasValue) { m_lastEffectPosition = EffectMatrix.Translation; } //Position delta interpolates particle position at fast flying objects, dont do that while motion inheritance if (m_particlesToCreate > 1.0f && !m_effect.CalculateDeltaMatrix) { positionDelta = (EffectMatrix.Translation - m_lastEffectPosition.Value) / (int)m_particlesToCreate; } //VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("CreateParticle"); using (ParticlesLock.AcquireExclusiveUsing()) { int maxParticles = 40; while (m_particlesToCreate >= 1.0f && maxParticles-- > 0) { if (m_effect.CalculateDeltaMatrix) { CreateParticle(EffectMatrix.Translation); } else { CreateParticle(m_lastEffectPosition.Value + positionDelta * (int)m_particlesToCreate); } m_particlesToCreate -= 1.0f; } } // VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("OnLife"); if (OnLife.GetValue <int>() != -1) { MyParticleGeneration inheritedGeneration = GetInheritedGeneration(OnLife.GetValue <int>()); if (inheritedGeneration == null) { OnLife.SetValue(-1); } else { inheritedGeneration.IsInherited = true; float particlesToCreate = inheritedGeneration.m_particlesToCreate; using (ParticlesLock.AcquireSharedUsing()) { foreach (MyAnimatedParticle particle in m_particles) { inheritedGeneration.m_particlesToCreate = particlesToCreate; inheritedGeneration.EffectMatrix = MatrixD.CreateWorld(particle.ActualPosition, (Vector3D)particle.Velocity, Vector3D.Cross(Vector3D.Left, particle.Velocity)); inheritedGeneration.UpdateParticlesCreation(); } } } } // VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); m_lastEffectPosition = EffectMatrix.Translation; }