Beispiel #1
0
 internal void UnmarkReplicable(MyProceduralLogicalSector sector)
 {
     Debug.Assert(sector.Replicable);
     m_sectorsForReplication.Remove(sector);
     QueueDestroyLogicalSector(sector);
     sector.Replicable = false;
 }
Beispiel #2
0
        private static void ReregisterHierarchy(MyEntity entity, bool top = true)
        {
            if (entity.Hierarchy == null)
            {
                return;
            }

            RemovedGrids.Remove(entity.EntityId);

            foreach (var child in entity.Hierarchy.Children)
            {
                MyEntity childEntity = (MyEntity)child.Container.Entity;
                ReregisterHierarchy(childEntity, false);
                MyEntities.RegisterForUpdate(childEntity);
                //childEntity.AddToGamePruningStructure();

                //child.Container.Entity.InScene = true;
            }
            if (!top)
            {
                return;
            }

            MyEntities.RegisterForUpdate(entity);
            entity.AddToGamePruningStructure();

            /*
             * if ( !PluginSettings.Instance.DynamicConcealPhysics )
             *  return;
             *
             * if ( entity.Physics != null )
             *  entity.Physics.Enabled = true;
             */
            //UnregisteredEntities.Remove( entity );
        }
Beispiel #3
0
        public T Dequeue()
        {
            T item;

            _queue.TryDequeue(out item);
            _hashSet.Remove(item);
            return(item);
        }
        public void OnStopPlaying(MySourceVoice voice)
        {
#if DEBUG
            //Debug.Assert(m_debugPlayingList.Contains(voice), string.Format("Debug only. Stopping not playing voice {0}", voice));
            m_debugPlayingList.Remove(voice);
#endif
            m_currentCount--;
            m_availableVoices.Enqueue(voice);
        }
Beispiel #5
0
        /// <summary>
        ///     Invokes actions on the game thread, and blocks until completion
        /// </summary>
        /// <param name="action"></param>
        public static void InvokeBlocking(Action action)
        {
            var threadLock = new FastResourceLock();

            if (!SessionClosing)
            {
                ThreadLocks.Add(threadLock);
            }

            threadLock.AcquireExclusive();
            try
            {
                MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                {
                    try
                    {
                        var invokeBlock = Profiler.Start(FullName, nameof(InvokeBlocking));
                        action();
                        invokeBlock.End();
                    }
                    catch (Exception ex)
                    {
                        Logging.Instance.WriteLine("Exception on blocking game thread invocation: " + ex);

                        if (!SessionClosing && ShipyardCore.Debug)
                        {
                            throw;
                        }
                    }
                    finally
                    {
                        threadLock.ReleaseExclusive();
                    }
                });
            }
            catch (Exception ex)
            {
                Logging.Instance.WriteLine("Exception in Utilities.InvokeBlocking: " + ex);
                threadLock.ReleaseExclusive();

                if (!SessionClosing && ShipyardCore.Debug)
                {
                    throw;
                }
            }

            threadLock.AcquireExclusive();
            threadLock.ReleaseExclusive();

            if (!SessionClosing)
            {
                ThreadLocks.Remove(threadLock);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Adds newly added grids to cache and update count to meet change
        /// </summary>
        /// <param name="entity"></param>
        private void MyEntitiesOnOnEntityAdd(MyEntity entity)
        {
            if (!BlockLimiterConfig.Instance.EnableLimits)
            {
                return;
            }

            if (!(entity is MyCubeGrid grid))
            {
                return;
            }

            if (grid.Projector != null || grid.IsPreview)
            {
                return;
            }
            // Do Not Add to grid cache at this point to allow MyCubeGridsOnBlockBuild to add and prevent double counts
            var blocks = grid.CubeBlocks;

            GridCache.AddGrid(grid);
            foreach (var block in blocks)
            {
                if (_justAdded.Contains(block))
                {
                    _justAdded.Remove(block);
                    continue;
                }
                _justAdded.Add(block);
                Block.IncreaseCount(block.BlockDefinition,
                                    block.BuiltBy == block.OwnerId
                        ? new List <long> {
                    block.BuiltBy
                }
                        : new List <long> {
                    block.BuiltBy, block.OwnerId
                }, 1, grid.EntityId);
            }
        }
        public void Update()
        {
            if (m_owner == null || m_audioEngine == null)
            {
                return;
            }
            int i;

            if (m_owner.DisablePooling)
            {
                MySourceVoice voice;
                for (i = 0; i < m_voiceBuffer2.Count; i++)
                {
                    m_voiceBuffer2[i].Dispose();
                }
                m_voiceBuffer2 = m_voiceBuffer;
                m_voiceBuffer.Clear();
                for (i = 0; i < m_availableVoices.Count; i++)
                {
                    if (m_availableVoices.TryDequeue(out voice))
                    {
                        voice.DestroyVoice();
                        m_voiceBuffer.Add(voice);
                    }
                }
            }
            int id = 0;

            //fading out
            while (id < m_fadingOutVoices.Count)
            {
                MySourceVoice voice = m_fadingOutVoices[id];
                if (!voice.IsValid)
                {
                    m_fadingOutVoices.RemoveAt(id);
                    //m_fadingOutVoices.Insert(id, m_owner.GetVoice(voice.CueEnum));
                    //voice = m_fadingOutVoices[id];
                }
                else
                {
                    if (voice.Voice.Volume < 0.01f)
                    {
                        voice.Voice.Stop();
                        voice.Voice.FlushSourceBuffers(); // triggers voice's BufferEnd event
                        m_fadingOutVoices.RemoveAt(id);
                        continue;
                    }
                    else
                    {
                        voice.Voice.SetVolume(0.65f * voice.Voice.Volume);
                    }
                }

                ++id;
            }

            //check for invalid voices
            m_voicesToRemove.Clear();
            foreach (MySourceVoice voice in m_allVoices)
            {
                if (voice.IsValid == false)
                {
                    m_voicesToRemove.Add(voice);
                }
            }

            //remove invalid voices
            while (m_voicesToRemove.Count > 0)
            {
                m_allVoices.Remove(m_voicesToRemove[0]);
                m_voicesToRemove.RemoveAt(0);
            }

            //silent sounds playing in large number (sameSoundLimiterCount)
            if (UseSameSoundLimiter)
            {
                //add remaining voices to distance and sort them
                m_distancedVoices.Clear();
                foreach (MySourceVoice voice in m_allVoices)
                {
                    m_distancedVoices.Add(voice);
                }
                m_distancedVoices.Sort(delegate(MySourceVoice x, MySourceVoice y)
                {
                    return(x.distanceToListener.CompareTo(y.distanceToListener));
                });

                //silent or un-silent voices
                MyCueId     currentCueId;
                int         j, limit;
                MySoundData cueDefinition;
                while (m_distancedVoices.Count > 0)
                {
                    currentCueId  = m_distancedVoices[0].CueEnum;
                    i             = 0;
                    cueDefinition = MyAudio.Static.GetCue(currentCueId);
                    limit         = cueDefinition.SoundLimit;
                    for (j = 0; j < m_distancedVoices.Count; j++)
                    {
                        if (m_distancedVoices[j].CueEnum.Equals(currentCueId))
                        {
                            i++;
                            if (limit > 0 && i > limit)
                            {
                                m_distancedVoices[j].Silent = true;
                            }
                            else
                            {
                                m_distancedVoices[j].Silent = false;
                            }
                            m_distancedVoices.RemoveAt(j);
                            j--;
                        }
                    }
                }
            }
        }
        public override void Handle()
        {
            Logging.Instance.WriteDebug("ProcessLocalYards Start");
            var removeYards = new HashSet <ShipyardItem>();

            foreach (ShipyardItem item in LocalYards)
            {
                //see if the shipyard has been deleted
                if (item.YardEntity.Closed || item.YardEntity.Physics == null || item.YardType == ShipyardType.Invalid ||
                    (item.StaticYard && !item.YardEntity.Physics.IsStatic))
                {
                    //the client shouldn't tell the server the yard is invalid
                    //item.Disable();
                    removeYards.Add(item);
                    continue;
                }

                if (item.StaticYard)
                {
                    UpdateBoxLines(item);
                }

                //don't draw boxes inside active yards, it's distracting
                if (item.YardType != ShipyardType.Disabled)
                {
                    continue;
                }

                var corners = new Vector3D[8];
                item.ShipyardBox.GetCorners(corners, 0);
                double dist = Vector3D.DistanceSquared(corners[0], item.ShipyardBox.Center);

                var sphere = new BoundingSphereD(item.ShipyardBox.Center, dist);

                //Utilities.InvokeBlocking(()=> entities = MyAPIGateway.Entities.GetTopMostEntitiesInSphere(ref sphere));
                List <IMyEntity> entities = MyAPIGateway.Entities.GetTopMostEntitiesInSphere(ref sphere);

                if (entities.Count == 0)
                {
                    Logging.Instance.WriteDebug("Couldn't get entities in ProcessLocalYards");
                    continue;
                }
                var removeGrids = new HashSet <IMyCubeGrid>();
                foreach (IMyEntity entity in entities)
                {
                    var grid = entity as IMyCubeGrid;
                    if (grid == null)
                    {
                        continue;
                    }

                    if (grid.EntityId == item.EntityId)
                    {
                        continue;
                    }

                    //workaround to not blind people with digi's helmet mod
                    if (grid.Physics == null && grid.Projector() == null)
                    {
                        continue;
                    }

                    if (grid.Closed || grid.MarkedForClose)
                    {
                        removeGrids.Add(grid);
                        continue;
                    }

                    if (LocalYards.Any(x => x.EntityId == grid.EntityId))
                    {
                        continue;
                    }

                    //create a bounding box around the ship
                    MyOrientedBoundingBoxD gridBox = MathUtility.CreateOrientedBoundingBox(grid);

                    //check if the ship bounding box is completely inside the yard box
                    ContainmentType result = item.ShipyardBox.Contains(ref gridBox);

                    if (result == ContainmentType.Contains)
                    {
                        item.ContainsGrids.Add(grid);
                        item.IntersectsGrids.Remove(grid);
                    }
                    else if (result == ContainmentType.Intersects)
                    {
                        item.IntersectsGrids.Add(grid);
                        item.ContainsGrids.Remove(grid);
                    }
                    else
                    {
                        removeGrids.Add(grid);
                    }
                }

                foreach (IMyCubeGrid containGrid in item.ContainsGrids)
                {
                    if (!entities.Contains(containGrid))
                    {
                        removeGrids.Add(containGrid);
                    }
                }

                foreach (IMyCubeGrid intersectGrid in item.IntersectsGrids)
                {
                    if (!entities.Contains(intersectGrid))
                    {
                        removeGrids.Add(intersectGrid);
                    }
                }

                foreach (IMyCubeGrid removeGrid in removeGrids)
                {
                    ShipyardCore.BoxDict.Remove(removeGrid.EntityId);
                    item.ContainsGrids.Remove(removeGrid);
                    item.IntersectsGrids.Remove(removeGrid);
                }
            }

            foreach (ShipyardItem removeItem in removeYards)
            {
                foreach (IMyCubeGrid grid in removeItem.ContainsGrids)
                {
                    ShipyardCore.BoxDict.Remove(grid.EntityId);
                }
                foreach (IMyCubeGrid grid in removeItem.IntersectsGrids)
                {
                    ShipyardCore.BoxDict.Remove(grid.EntityId);
                }

                LocalYards.Remove(removeItem);
            }
        }
 public void Remove(MyStorageBase storage)
 {
     // this works because magic
     m_storagesWithCache.Remove(new StorageData(storage));
 }