public void Close(bool done) { if (!done && OnDelete != null) { OnDelete(this, null); } Clear(); m_name = "ParticleEffect"; foreach (MyParticleGeneration generation in m_generations) { if (done) { generation.Done(); } else { generation.Close(); } MyParticlesManager.GenerationsPool.Deallocate(generation); } m_generations.Clear(); foreach (MyParticleLight particleLight in m_particleLights) { if (done) { particleLight.Done(); } else { particleLight.Close(); } MyParticlesManager.LightsPool.Deallocate(particleLight); } m_particleLights.Clear(); if (m_instances != null) { while (m_instances.Count > 0) { MyParticlesManager.RemoveParticleEffect(m_instances[0]); } } OnDelete = null; OnUpdate = null; Tag = null; }
public bool Update() { if (!Enabled) { return(m_isStopped); //efect is not enabled at all and must be deleted } if (WorldMatrix == MatrixD.Zero) { return(true); } System.Diagnostics.Debug.Assert(WorldMatrix != MatrixD.Zero, "Effect world matrix was not set!"); if (MyParticlesManager.CalculateGravityInPoint != null && m_updateCounter == 0) { Gravity = MyParticlesManager.CalculateGravityInPoint(WorldMatrix.Translation); } m_updateCounter++; if (m_updateCounter > GRAVITY_UPDATE_DELAY) { m_updateCounter = 0; } VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("ParticleEffect-UpdateGen"); //m_distance = MySector.MainCamera.GetDistanceWithFOV(WorldMatrix.Translation) / (100.0f); //precalculate for LODs m_distance = (float)Vector3D.Distance(MyTransparentGeometry.Camera.Translation, WorldMatrix.Translation) / (100.0f); //precalculate for LODs m_particlesCount = 0; m_birthRate = 0; m_AABB = BoundingBoxD.CreateInvalid(); if (Velocity != Vector3.Zero) { var position = m_worldMatrix.Translation; position.X += Velocity.X * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; position.Y += Velocity.Y * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; position.Z += Velocity.Z * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; m_worldMatrix = MatrixD.CreateWorld(position, Vector3D.Normalize(Velocity), m_worldMatrix.Up); } for (int i = 0; i < m_generations.Count; i++) { if (m_showOnlyThisGeneration >= 0 && i != m_showOnlyThisGeneration) { continue; } m_generations[i].EffectMatrix = WorldMatrix; m_generations[i].Update(); m_particlesCount += m_generations[i].GetParticlesCount(); m_birthRate += m_generations[i].GetBirthRate(); m_generations[i].MergeAABB(ref m_AABB); } foreach (var particleLight in m_particleLights) { particleLight.Update(); } foreach (var particleSound in m_particleSounds) { particleSound.Update(); } m_elapsedTime += MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; if (m_loop && m_elapsedTime >= m_durationActual) { m_elapsedTime = 0; SetRandomDuration(); } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); m_lastWorldMatrix = m_worldMatrix; if (OnUpdate != null) { OnUpdate(this, null); } if (m_isStopped) { // if the effect is stopped, kill it after all particles will die off return(m_particlesCount == 0); } else { // remove particles after set duration time (duration 0 means infinite duration - has to be stopped from code) return(m_durationActual > 0 && m_elapsedTime > m_durationActual); } }
public bool Update() { if (!Enabled) { return(AutoDelete); //efect is not enabled at all and must be deleted } if (WorldMatrix == MatrixD.Zero) { return(true); } System.Diagnostics.Debug.Assert(WorldMatrix != MatrixD.Zero, "Effect world matrix was not set!"); if (!m_isPreloading && !m_wasPreloaded && m_preload > 0) { m_isPreloading = true; // TODO: Optimize (preload causes lags, depending on preload size, it's from 0 ms to 85 ms) while (m_elapsedTime < m_preload) { Update(); } m_isPreloading = false; m_wasPreloaded = true; } if (MyParticlesManager.CalculateGravityInPoint != null && m_updateCounter == 0) { Gravity = MyParticlesManager.CalculateGravityInPoint(WorldMatrix.Translation); } m_updateCounter++; if (m_updateCounter > GRAVITY_UPDATE_DELAY) { m_updateCounter = 0; } VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("ParticleEffect-Update"); if (!m_isPreloading) { MyPerformanceCounter.PerCameraDrawWrite.ParticleEffectsDrawn++; } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("ParticleEffect-UpdateGen"); m_elapsedTime += VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; //m_distance = MySector.MainCamera.GetDistanceWithFOV(WorldMatrix.Translation) / (100.0f); //precalculate for LODs m_distance = (float)Vector3D.Distance(MyTransparentGeometry.Camera.Translation, WorldMatrix.Translation) / (100.0f); //precalculate for LODs m_particlesCount = 0; m_birthRate = 0; m_AABB = BoundingBoxD.CreateInvalid(); if (Velocity != Vector3.Zero) { var position = m_worldMatrix.Translation; position.X += Velocity.X * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; position.Y += Velocity.Y * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; position.Z += Velocity.Z * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; m_worldMatrix = MatrixD.CreateWorld(position, Vector3D.Normalize(Velocity), m_worldMatrix.Up); } foreach (IMyParticleGeneration generation in m_generations) { generation.EffectMatrix = WorldMatrix; generation.Update(); m_particlesCount += generation.GetParticlesCount(); m_birthRate += generation.GetBirthRate(); generation.MergeAABB(ref m_AABB); } if (m_particlesCount > 0) { m_hasShownSomething = true; } foreach (var particleLight in m_particleLights) { particleLight.Update(); } foreach (var particleSound in m_particleSounds) { particleSound.Update(); } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); m_lastWorldMatrix = m_worldMatrix; if (((m_particlesCount == 0 && HasShownSomething()) || (m_particlesCount == 0 && m_birthRate == 0.0f)) && AutoDelete && !m_isPreloading) { //Effect was played and has to be deleted return(true); } if (!m_isPreloading && OnUpdate != null) { OnUpdate(this, null); } m_positionDirty = false; return(false); }