Exemplo n.º 1
0
        public static void RemoveParticleEffect(MyParticleEffect effect, bool fromBackground = false)
        {
            //System.Diagnostics.Debug.Assert(m_updateCompleted == true);

            //Because XNA can call Update() more times per frame
            if (!fromBackground)
            {
                WaitUntilUpdateCompleted();
            }

            bool remove = true;

            if (!effect.UserDraw /*&& effect.Enabled*/)
            {
                lock (m_particleEffectsForUpdate)
                {
                    //System.Diagnostics.Debug.Assert(m_particleEffectsForUpdate.Contains(effect));
                    remove = m_particleEffectsForUpdate.Contains(effect);
                    if (remove)
                    {
                        m_particleEffectsForUpdate.Remove(effect);
                    }
                }
            }

            m_particleEffectsAll.Remove(effect);
            if (remove)
            {
                MyParticlesLibrary.RemoveParticleEffectInstance(effect);
            }
        }
Exemplo n.º 2
0
        public MyParticleEffect CreateInstance()
        {
            MyParticleEffect effect = MyParticlesManager.EffectsPool.Allocate(true);

            if (effect != null)
            {
                effect.Start(m_particleID);

                effect.Name    = Name;
                effect.Enabled = Enabled;
                effect.SetLength(GetLength());
                effect.SetPreload(GetPreload());
                effect.LowRes = LowRes;

                foreach (MyParticleGeneration generation in m_generations)
                {
                    MyParticleGeneration gen = generation.CreateInstance(effect);
                    if (gen != null)
                    {
                        effect.AddGeneration(gen);
                    }
                }

                if (m_instances == null)
                {
                    m_instances = new List <MyParticleEffect>();
                }

                m_instances.Add(effect);
            }

            return(effect);
        }
Exemplo n.º 3
0
 void m_entity_OnClose(MyEntity obj)
 {
     if (m_shotSmoke != null)
     {
         MyParticlesManager.RemoveParticleEffect(m_shotSmoke);
         m_shotSmoke = null;
     }
 }
Exemplo n.º 4
0
 public void RemoveInstance(MyParticleEffect effect)
 {
     if (m_instances != null)
     {
         if (m_instances.Contains(effect))
         {
             m_instances.Remove(effect);
         }
     }
 }
		public override void OnBeforeRemovedFromContainer()
		{
			base.OnBeforeRemovedFromContainer();

			if(m_landingEffect != null)
			{
				m_landingEffect.Stop();
				m_landingEffect = null;
				--m_landingEffectCount;
			}
		}
Exemplo n.º 6
0
        public static bool TryCreateParticleEffect(int id, out MyParticleEffect effect, bool userDraw = false)
        {
            if (!MyParticlesLibrary.EffectExists(id))
            {
                effect = null;
                return(false);
            }

            effect = CreateParticleEffect(id, userDraw);
            return(effect != null);
        }
        public void Close()
        {
            Clear();

            for (int i = 0; i < m_properties.Length; i++)
            {
                m_properties[i] = null;
            }

            m_emitter.Close();

            m_effect = null;
        }
Exemplo n.º 8
0
 static public void RemoveParticleEffectInstance(MyParticleEffect effect)
 {
     effect.Close(false);
     //if (effect.Enabled)
     {
         if (m_libraryEffects[effect.GetID()].GetInstances().Contains(effect))
         {
             MyParticlesManager.EffectsPool.Deallocate(effect);
             m_libraryEffects[effect.GetID()].RemoveInstance(effect);
         }
         else
         {
             System.Diagnostics.Debug.Assert(false, "Effect deleted twice!");
         }
     }
 }
        public void Start(MyParticleEffect effect)
        {
            System.Diagnostics.Debug.Assert(m_effect == null);
            System.Diagnostics.Debug.Assert(m_particles.Count == 0);
            System.Diagnostics.Debug.Assert(Birth == null);

            m_effect = effect;
            m_name   = "ParticleGeneration";

            m_emitter.Start();

            m_lastEffectPosition = null;
            IsInherited          = false;
            m_birthRate          = 0.0f;
            m_particlesToCreate  = 0.0f;
            m_AABB = BoundingBoxD.CreateInvalid();
        }
Exemplo n.º 10
0
        public MyParticleGeneration Duplicate(MyParticleEffect effect)
        {
            MyParticleGeneration generation = MyParticlesManager.GenerationsPool.Allocate();

            generation.Start(effect);

            generation.Name = Name;

            for (int i = 0; i < m_properties.Length; i++)
            {
                generation.m_properties[i] = m_properties[i].Duplicate();
            }

            m_emitter.Duplicate(generation.m_emitter);

            return(generation);
        }
Exemplo n.º 11
0
        public MyParticleEffect Duplicate()
        {
            MyParticleEffect effect = MyParticlesManager.EffectsPool.Allocate();

            effect.Start(0);

            effect.Name      = Name;
            effect.m_preload = m_preload;
            effect.m_length  = m_length;

            foreach (MyParticleGeneration generation in m_generations)
            {
                MyParticleGeneration duplicatedGeneration = generation.Duplicate(effect);
                effect.AddGeneration(duplicatedGeneration);
            }

            return(effect);
        }
Exemplo n.º 12
0
        public MyParticleGeneration CreateInstance(MyParticleEffect effect)
        {
            MyParticleGeneration generation = MyParticlesManager.GenerationsPool.Allocate(true);

            if (generation == null)
            {
                return(null);
            }

            generation.Start(effect);

            generation.Name = Name;

            for (int i = 0; i < m_properties.Length; i++)
            {
                generation.m_properties[i] = m_properties[i];
            }

            generation.m_emitter.CreateInstance(m_emitter);

            return(generation);
        }
Exemplo n.º 13
0
        static public void Deserialize(XmlReader reader)
        {
            Close();
            RedundancyDetected = 0;

            reader.ReadStartElement(); //VRageParticleLibrary

            int version = reader.ReadElementContentAsInt();

            reader.ReadStartElement(); //ParticleEffects

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                MyParticleEffect effect = MyParticlesManager.EffectsPool.Allocate();
                effect.Deserialize(reader);
                AddParticleEffect(effect);
            }

            reader.ReadEndElement(); //ParticleEffects

            reader.ReadEndElement(); //root
        }
Exemplo n.º 14
0
        static MyParticleEffect CreateParticleEffect(int id, bool userDraw = false)
        {
            //Because we can call Update() more times per frame
            WaitUntilUpdateCompleted();

            MyParticleEffect effect = MyParticlesLibrary.CreateParticleEffect(id);

            // This could more likely be caused by empty generation pool (which is allowed) then error in xml
            //System.Diagnostics.Debug.Assert(effect.GetGenerations().Count > 0);


            //Not in parallel
            userDraw = false;

            if (effect != null)
            {
                System.Diagnostics.Debug.Assert(m_updaterTask.IsComplete == true);

                if (!userDraw)
                {
                    lock (m_particleEffectsForUpdate)
                    {
                        m_particleEffectsForUpdate.Add(effect);
                    }
                }
                else
                {
                    effect.AutoDelete = false;
                }

                effect.UserDraw = userDraw;

                m_particleEffectsAll.Add(effect);
            }

            return(effect);
        }
Exemplo n.º 15
0
 public static void AddParticleEffect(MyParticleEffect effect)
 {
     m_libraryEffects.Add(effect.GetID(), effect);
 }
        public override void Draw()
        {
            base.Draw();            

            var worldToLocal = MatrixD.Invert(Container.Entity.PositionComp.WorldMatrix);

			if (m_thrust.CanDraw())
			{
				m_thrust.UpdateThrustFlame();
				m_thrust.UpdateThrustColor();

				foreach (var flame in m_thrust.Flames)
				{
					if (m_thrust.CubeGrid.Physics == null)
						continue;

					var flameDirection = Vector3D.TransformNormal(flame.Direction, Container.Entity.PositionComp.WorldMatrix);
					var flamePosition = Vector3D.Transform(flame.Position, Container.Entity.PositionComp.WorldMatrix);

					float radius = m_thrust.ThrustRadiusRand * flame.Radius;
					float length = m_thrust.ThrustLengthRand * flame.Radius;
					float thickness = m_thrust.ThrustThicknessRand * flame.Radius;

					Vector3D velocityAtNewCOM = Vector3D.Cross(m_thrust.CubeGrid.Physics.AngularVelocity, flamePosition - m_thrust.CubeGrid.Physics.CenterOfMassWorld);
					var velocity = m_thrust.CubeGrid.Physics.LinearVelocity + velocityAtNewCOM;

					if (m_thrust.CurrentStrength > 0 && length > 0)
					{
						float angle = 1 - Math.Abs(Vector3.Dot(MyUtils.Normalize(MySector.MainCamera.Position - flamePosition), flameDirection));
						float alphaCone = (1 - (float)Math.Pow(1 - angle, 30)) * 0.5f;
						//  We move polyline particle backward, because we are stretching ball texture and it doesn't look good if stretched. This will hide it.
						MyTransparentGeometry.AddLineBillboard(m_thrust.FlameLengthMaterial, m_thrust.ThrustColor * alphaCone, flamePosition - flameDirection * length * 0.25f,
							GetRenderObjectID(), ref worldToLocal, flameDirection, length, thickness);

					}

					if (radius > 0)
						MyTransparentGeometry.AddPointBillboard(m_thrust.FlamePointMaterial, m_thrust.ThrustColor, flamePosition, GetRenderObjectID(), ref worldToLocal, radius, 0);

					if (m_landingEffectUpdateCounter-- <= 0)
					{
						m_landingEffectUpdateCounter = (int)Math.Round(m_landingEffectUpdateInterval * (0.8f + MyRandom.Instance.NextFloat() * 0.4f));

						m_lastHitInfo = MyPhysics.CastRay(flamePosition,
							flamePosition + flameDirection * m_thrust.ThrustLengthRand * (m_thrust.CubeGrid.GridSizeEnum == MyCubeSize.Large ? 5.0f : 3.0f) * flame.Radius,
							MyPhysics.ObjectDetectionCollisionLayer);
					}

					if (m_landingEffect != null)
					{
						m_landingEffect.Stop(true);
						m_landingEffect = null;
						--m_landingEffectCount;
					}
					continue;

					if (m_landingEffect == null && m_landingEffectCount < m_maxNumberLandingEffects && MyParticlesManager.TryCreateParticleEffect(54, out m_landingEffect))
					{
						++m_landingEffectCount;
					}

					if (m_landingEffect == null)
						continue;

					m_landingEffect.UserScale = m_thrust.CubeGrid.GridSize;
					m_landingEffect.WorldMatrix = MatrixD.CreateFromTransformScale(Quaternion.CreateFromForwardUp(-m_lastHitInfo.Value.HkHitInfo.Normal, Vector3.CalculatePerpendicularVector(m_lastHitInfo.Value.HkHitInfo.Normal)), m_lastHitInfo.Value.Position, Vector3D.One);
				}
			}
			else if(m_landingEffect != null)
			{
				m_landingEffect.Stop(true);
				m_landingEffect = null;
				--m_landingEffectCount;
			}

            if (m_thrust.Light != null)
            {
                m_thrust.UpdateLight();
            }

            
        }            
Exemplo n.º 17
0
        public static void CustomDraw(MyParticleEffect effect)
        {
            System.Diagnostics.Debug.Assert(effect != null);

            m_effectsForCustomDraw.Add(effect);
        }
Exemplo n.º 18
0
 public void AddParticleToLibrary(MyParticleEffect effect)
 {
     MyParticlesLibrary.AddParticleEffect(effect);
 }
Exemplo n.º 19
0
 private void DestroyMeteor()
 {
     MyParticleEffect impactParticle;
     if (InParticleVisibleRange && MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.MeteorAsteroidCollision, out impactParticle))
     {
         impactParticle.WorldMatrix = Entity.WorldMatrix;
         impactParticle.UserScale = MyUtils.GetRandomFloat(1.5f, 2);
     }
     if (m_dustEffect != null)
     {
         m_dustEffect.Stop();
         if (m_particleEffectId == (int)MyParticleEffectsIDEnum.MeteorParticle)
         {
             m_dustEffect.Close(false);
             if (InParticleVisibleRange && m_particleVectorUp != Vector3.Zero && MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.MeteorParticleAfterHit, out m_dustEffect))
             {
                 MatrixD m = MatrixD.CreateWorld(Entity.WorldMatrix.Translation, m_particleVectorForward, m_particleVectorUp);
                 m_dustEffect.WorldMatrix = m;
             }
         }
         m_dustEffect = null;
     }
     PlayExplosionSound();
 }
		private void DrawAtmosphericEntryEffect()
		{
			var naturalGravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(m_grid.PositionComp.GetPosition());
			var naturalGravityMagnitude = naturalGravity.Length();

            bool noPhysics = m_grid.Physics == null;
            bool recentlyHitVoxel = MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastVoxelContactTime < m_atmosphericEffectVoxelContactDelay;
            bool tooLowSpeed = !noPhysics && (m_grid.Physics.LinearVelocity.Length() < m_atmosphericEffectMinSpeed);
			if (noPhysics || recentlyHitVoxel || tooLowSpeed)
			{
				if (m_atmosphericEffect != null)
				{
					MyParticlesManager.RemoveParticleEffect(m_atmosphericEffect);
					m_atmosphericEffect = null;
				}

				return;
			}
			var currentVelocity = m_grid.Physics.LinearVelocity;
			var currentVelocityDirection = Vector3.Normalize(currentVelocity);
			var currentSpeed = currentVelocity.Length();

			if (m_atmosphericEffect == null)
			{
				if(!MyParticlesManager.TryCreateParticleEffect(52, out m_atmosphericEffect))
					return;
			}

			BoundingBox worldAABB = (BoundingBox)m_grid.PositionComp.WorldAABB;
			var aabbCenter = worldAABB.Center;
			var directionFaceCenter = new Vector3();
			Debug.Assert(m_tmpCornerList.Count == 0);
			foreach (var corner in worldAABB.GetCorners())
			{
				var centerToCorner = corner - aabbCenter;
				if (centerToCorner.Dot(currentVelocityDirection) > 0.01f)
				{
					m_tmpCornerList.Add(corner);
					directionFaceCenter += corner;
					if (m_tmpCornerList.Count == 4)
						break;
				}
			}
			if(m_tmpCornerList.Count > 0)
				directionFaceCenter /= m_tmpCornerList.Count;

			Plane plane = new Plane(directionFaceCenter, -currentVelocityDirection);

			m_tmpCornerList.Clear();
			var startPosition = m_grid.Physics.CenterOfMassWorld;
			float? intersectDistance = new Ray(startPosition, currentVelocityDirection).Intersects(plane);
			m_lastWorkingIntersectDistance = intersectDistance ?? m_lastWorkingIntersectDistance;
			var intersectPoint = startPosition + 0.875f * currentVelocityDirection * m_lastWorkingIntersectDistance;
	
			Matrix worldMatrix = Matrix.Identity;
			worldMatrix.Translation = intersectPoint;
			worldMatrix.Forward = currentVelocityDirection;
			var forwardPerpendicular = Vector3.Transform(currentVelocityDirection, Quaternion.CreateFromAxisAngle(m_grid.PositionComp.WorldMatrix.Left, (float)Math.PI / 2.0f));
			worldMatrix.Up = Vector3.Normalize(Vector3.Reject(m_grid.PositionComp.WorldMatrix.Left, forwardPerpendicular));
			worldMatrix.Left = worldMatrix.Up.Cross(worldMatrix.Forward);

			var atmosphericDensityMultiplier = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(m_grid.PositionComp.GetPosition());

			m_atmosphericEffect.UserScale = (float)worldAABB.ProjectedArea(currentVelocityDirection) / (float)Math.Pow(38.0 * m_grid.GridSize, 2.0);
			m_atmosphericEffect.UserAxisScale = Vector3.Normalize(new Vector3(1.0f, 1.0f, 1.0f + 1.5f*(m_grid.Physics.LinearVelocity.Length() - m_atmosphericEffectMinSpeed) / (MyGridPhysics.ShipMaxLinearVelocity() - m_atmosphericEffectMinSpeed)));
			m_atmosphericEffect.WorldMatrix = worldMatrix;
			m_atmosphericEffect.UserColorMultiplier = new Vector4(MathHelper.Clamp((currentSpeed - m_atmosphericEffectMinSpeed) / (m_atmosphericEffectMinSpeed * 0.5f) * (float)Math.Pow(atmosphericDensityMultiplier, 1.5), 0.0f, m_atmosphericEffectMinFade));
		}
Exemplo n.º 21
0
        public static VRageRender.MyBillboard AddBillboardEffect(MyParticleEffect effect)
        {
            //VRageRender.MyBillboard billboard = m_preallocatedParticleBillboards.Allocate();
            //VRageRender.MyBillboard billboard = new VRageRender.MyBillboard();
            VRageRender.MyBillboard billboard = VRageRender.MyRenderProxy.BillboardsPoolWrite.Allocate();
            if (billboard != null)
            {
                billboard.ContainedBillboards.Clear();

                MyTransparentGeometry.StartParticleProfilingBlock("AddBillboardEffect");

                billboard.DistanceSquared = (float)Vector3D.DistanceSquared(MyTransparentGeometry.Camera.Translation, effect.WorldMatrix.Translation);

                billboard.Lowres = effect.LowRes || VRageRender.MyRenderConstants.RenderQualityProfile.LowResParticles;
                billboard.Near = effect.Near;
                billboard.CustomViewProjection = -1;

                MyTransparentGeometry.EndParticleProfilingBlock();
            }
            return billboard;
        }
Exemplo n.º 22
0
            public override void UpdateBeforeSimulation100()
            {
                base.UpdateBeforeSimulation100();
                if (m_particleVectorUp == Vector3.Zero)
                {
                    if (Entity.Physics.LinearVelocity != Vector3.Zero)
                        m_particleVectorUp = -Vector3.Normalize(Entity.Physics.LinearVelocity);
                    else
                        m_particleVectorUp = Vector3.Up;
                    m_particleVectorUp.CalculatePerpendicularVector(out m_particleVectorForward);
                }

                if (m_dustEffect != null && !InParticleVisibleRange)
                {
                    m_dustEffect.Stop();
                    m_dustEffect = null;
                }

                if (m_dustEffect == null && Entity.PositionComp.Scale > 1.5 && InParticleVisibleRange)
                {
                    if (MyParticlesManager.TryCreateParticleEffect(m_particleEffectId, out m_dustEffect))
                    {
                        UpdateParticlePosition();
                        m_dustEffect.UserScale = Entity.PositionComp.Scale.Value / 5;
                    }
                }

                m_soundEmitter.Update();

                if (MySandboxGame.TotalGamePlayTimeInMilliseconds - m_timeCreated > Math.Min(MAX_TRAJECTORY_LENGTH / MIN_SPEED, MAX_TRAJECTORY_LENGTH / Entity.Physics.LinearVelocity.Length()) * 1000)
                {
                    CloseMeteorInternal();
                }
            }
Exemplo n.º 23
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            if (m_producedSinceLastUpdate)
            {
                if (m_effect == null)
                {
                    CreateEffect();
                }
            }
            else
            {
                if (m_effect != null)
                {
                    m_effect.Stop();
                    m_effect = null;
                }
            }

            if (MyFakes.ENABLE_OXYGEN_SOUNDS)
            {
                UpdateSound();
            }

            m_isProducing = m_producedSinceLastUpdate;
            m_producedSinceLastUpdate = false;

            UdpateTexts();
        }
Exemplo n.º 24
0
 public static void RemoveParticleEffect(MyParticleEffect effect)
 {
     RemoveParticleEffect(effect.GetID());
 }
 public static void AddParticleEffect(MyParticleEffect effect)
 {
     m_libraryEffects.Add(effect.GetID(), effect);
 }
Exemplo n.º 26
0
 public void RemoveInstance(MyParticleEffect effect)
 {
     if (m_instances != null)
     {
         if (m_instances.Contains(effect))
             m_instances.Remove(effect);
     }
 }
Exemplo n.º 27
0
        private void CreateEffect()
        {
            if (m_effect != null)
            {
                m_effect.Stop();
                m_effect = null;
            }

            if (MyParticlesManager.TryCreateParticleEffect(48, out m_effect))
            {
                Matrix mat;
                Orientation.GetMatrix(out mat);

                var orientation = mat;

                if (IsDepressurizing)
                {
                    orientation.Left = mat.Right;
                    orientation.Up = mat.Down;
                    orientation.Forward = mat.Backward;
                }

                orientation = Matrix.Multiply(orientation, CubeGrid.PositionComp.WorldMatrix.GetOrientation());
                orientation.Translation = CubeGrid.GridIntegerToWorld(Position + mat.Forward / 4f);

                m_effect.WorldMatrix = orientation;
                m_effect.AutoDelete = false;

                m_effect.UserScale = 3f;
            }
        }
Exemplo n.º 28
0
        protected void CreateParticles(Vector3D position, bool createDust, bool createSparks, bool createStones)
        {
            if (!m_particleEffectsEnabled)
                return;

            if (m_dustParticles != null && m_dustParticles.IsStopped)
                m_dustParticles = null;

            if (createDust)
            {
                if (m_dustParticles == null)
                {
                    ProfilerShort.Begin(string.Format("Create dust: stones = {0}", createStones));
                    //MyParticleEffectsIDEnum.Smoke_Construction
                    MyParticlesManager.TryCreateParticleEffect(createStones ? (int)m_dustEffectStonesId : (int)m_dustEffectId, out m_dustParticles);
                    ProfilerShort.End();
                }

                if (m_dustParticles != null)
                {
                    m_dustParticles.AutoDelete = false;
                    m_dustParticles.Near = m_drillEntity.Render.NearFlag;
                    m_dustParticles.WorldMatrix = MatrixD.CreateTranslation(position);
                }
            }

            if (createSparks)
            {
                ProfilerShort.Begin("Create sparks");
                MyParticleEffect sparks;
                if (MyParticlesManager.TryCreateParticleEffect((int)m_sparksEffectId, out sparks))
                {
                    sparks.WorldMatrix = Matrix.CreateTranslation(position);
                    sparks.Near = m_drillEntity.Render.NearFlag;
                }
                ProfilerShort.End();
            }
        }
Exemplo n.º 29
0
        public static void RemoveParticleEffect(MyParticleEffect effect, bool fromBackground = false)
        {
            //System.Diagnostics.Debug.Assert(m_updateCompleted == true);

            //Because XNA can call Update() more times per frame
            if (!fromBackground)
                WaitUntilUpdateCompleted();

            bool remove = true;

            if (!effect.UserDraw /*&& effect.Enabled*/)
            {
                lock (m_particleEffectsForUpdate)
                {
                    //System.Diagnostics.Debug.Assert(m_particleEffectsForUpdate.Contains(effect));
                    remove = m_particleEffectsForUpdate.Contains(effect);
                    if (remove)
                        m_particleEffectsForUpdate.Remove(effect);
                }
            }

            m_particleEffectsAll.Remove(effect);
            //if (remove)
            MyParticlesLibrary.RemoveParticleEffectInstance(effect);
        }
Exemplo n.º 30
0
 private void StopParticles()
 {
     if (m_dustParticles != null)
     {
         m_dustParticles.Stop();
         m_dustParticles = null;
     }
 }
Exemplo n.º 31
0
        public static void CustomDraw(MyParticleEffect effect)
        {
            System.Diagnostics.Debug.Assert(effect != null);

            m_effectsForCustomDraw.Add(effect);
        }
Exemplo n.º 32
0
 public override void Close()
 {
     if (m_dustEffect != null)
     {
         m_dustEffect.Stop();
         m_dustEffect = null;
     }
     base.Close();
 }
Exemplo n.º 33
0
        public static bool TryCreateParticleEffect(int id, out MyParticleEffect effect, bool userDraw = false)
        {
            if (!MyParticlesLibrary.EffectExists(id))
            {
                effect = null;
                return false;
            }

            effect = CreateParticleEffect(id, userDraw);
            return effect != null;
        }
Exemplo n.º 34
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            if (m_producedSinceLastUpdate)
            {
                if (m_effect == null)
                {
                    CreateEffect();
                }
            }
            else
            {
                if (m_effect != null)
                {
                    m_effect.Stop();
                    m_effect = null;
                }
            }

            if (MyFakes.ENABLE_OXYGEN_SOUNDS)
                UpdateSound();

            m_isProducing = m_producedSinceLastUpdate;
            m_producedSinceLastUpdate = false;
            var block = GetOxygenBlock();

            int sourceUpdateFrames = (m_updateCounter - m_lastOutputUpdateTime);
            int sinkUpdateFrames = (m_updateCounter - m_lastInputUpdateTime);

            float gasInput = GasInputPerUpdate * sinkUpdateFrames;
            float gasOutput = GasOutputPerUpdate * sourceUpdateFrames;
            float totalTransfer = gasInput - gasOutput + m_nextGasTransfer;
            Transfer(totalTransfer);

            SourceComp.SetRemainingCapacityByType(m_oxygenGasId, (float)(block.Room != null ? block.Room.OxygenAmount : 0));

            m_updateCounter = 0;
            m_lastOutputUpdateTime = m_updateCounter;
            m_lastInputUpdateTime = m_updateCounter;
            ResourceSink.Update();

            UdpateTexts();
        }
Exemplo n.º 35
0
        //  Kills this missile. Must be called at her end (after explosion or timeout)
        //  This method must be called when this object dies or is removed
        //  E.g. it removes lights, sounds, etc
        protected override void Closing()
        {
            base.Closing();

            if (this.Physics != null)
            {
                MyMissiles.Remove(this);
            }

            if (m_collidedEntity != null)
            {
                m_collidedEntity.OnClose -= m_collidedEntity_OnClose;
                m_collidedEntity = null;
            }

            if (m_smokeEffect != null)
            {
                m_smokeEffect.Stop();
                m_smokeEffect = null;
            }

            //  Free the light
            if (m_light != null)
            {
                MyLights.RemoveLight(m_light);
                m_light = null;
            }

            //  Stop cue (needed because sound is looping)
            m_soundEmitter.StopSound(true);
        }      
		public override void OnBeforeRemovedFromContainer()
		{
			base.OnBeforeRemovedFromContainer();

			if(m_atmosphericEffect != null)
			{
				MyParticlesManager.RemoveParticleEffect(m_atmosphericEffect);
				m_atmosphericEffect = null;
			}
		}
Exemplo n.º 37
0
        //  Generate explosion particles. These will be smoke, explosion and some polyline particles.
        void GenerateExplosionParticles(MyParticleEffectsIDEnum newParticlesType, BoundingSphere explosionSphere, float particleScale)
        {
            if (MyParticlesManager.TryCreateParticleEffect((int)newParticlesType, out m_explosionEffect))
            {
                m_explosionEffect.OnDelete += delegate
                {
                    m_explosionInfo.LifespanMiliseconds = 0;
                    m_explosionEffect = null;
                };
                m_explosionEffect.WorldMatrix = CalculateEffectMatrix(explosionSphere);
                //explosionEffect.UserRadiusMultiplier = tempExplosionSphere.Radius;
                m_explosionEffect.UserScale = particleScale;
            }

           // m_lifespanInMiliseconds = Math.Max(m_lifespanInMiliseconds, (int)(m_explosionEffect.GetLength() * 1000));
        }
Exemplo n.º 38
0
        static public void RemoveParticleEffectInstance(MyParticleEffect effect)
        {
            effect.Close(false);
            //if (effect.Enabled)
            if (m_libraryEffects.ContainsKey(effect.GetID()))
            {
                var instances = m_libraryEffects[effect.GetID()].GetInstances();
                if (instances != null)
                {
                    if (instances.Contains(effect))
                    {
                        MyParticlesManager.EffectsPool.Deallocate(effect);
                        m_libraryEffects[effect.GetID()].RemoveInstance(effect);
                    }
                    else
                    {
                        System.Diagnostics.Debug.Assert(false, "Effect deleted twice!");

                    }
                }
            }
        }
Exemplo n.º 39
0
 public void RemoveParticle(MyParticleEffect effect)
 {
     effect.Clear();
     MyParticlesLibrary.RemoveParticleEffectInstance(effect);
 }
Exemplo n.º 40
0
 public static void AddParticleEffect(MyParticleEffect effect)
 {
     m_libraryEffects.Add(effect.GetID(), effect);
     m_libraryEffectsString[effect.Name] = effect;
 }
Exemplo n.º 41
0
 public static void AddParticleEffect(MyParticleEffect effect)
 {
     m_libraryEffects.Add(effect.GetID(), effect);
     m_libraryEffectsString[effect.Name] = effect;
 }
Exemplo n.º 42
0
 protected override void StopEffects()
 {
     if (m_particleEffect1 != null)
     {
         m_particleEffect1.Stop();
         m_particleEffect1 = null;
     }
     if (m_particleEffect2 != null)
     {
         m_particleEffect2.Stop();
         m_particleEffect2 = null;
     }
     if (m_effectLight != null)
     {
         MyLights.RemoveLight(m_effectLight);
         m_effectLight = null;
     }
 }
Exemplo n.º 43
0
 public static void RemoveParticleEffect(MyParticleEffect effect)
 {
     RemoveParticleEffect(effect.GetID());
 }