Exemple #1
0
        /// <summary>
        /// Get all the blocks on the target grid that are damaged
        /// </summary>
        private void GetDamagedBlocks()
        {
            m_damagedBlocks.Clear();
            m_projectedBlocks.Clear();

            // get physical blocks

            foreach (IMySlimBlock slim in Attached.AttachedGrid.AttachedSlimBlocks((IMyCubeGrid)m_currentGrid.Entity, Attached.AttachedGrid.AttachmentKind.Permanent, true))
            {
                if (slim.CurrentDamage > 0f || slim.BuildLevelRatio < 1f)
                {
                    m_damagedBlocks.Add(slim);
                }
            }

            // get projections

            HashSet <IMyEntity> projections = null;

            foreach (IMyCubeGrid grid in Attached.AttachedGrid.AttachedGrids((IMyCubeGrid)m_currentGrid.Entity, Attached.AttachedGrid.AttachmentKind.Permanent, true))
            {
                if (CubeGridCache.GetFor(grid).CountByType(typeof(MyObjectBuilder_Projector)) == 0)
                {
                    continue;
                }

                using (MainLock.AcquireSharedUsing())
                {
                    if (projections == null)
                    {
                        projections = new HashSet <IMyEntity>();
                        MyAPIGateway.Entities.GetEntities(projections, entity => entity is MyCubeGrid && ((MyCubeGrid)entity).Projector != null);

                        if (projections.Count == 0)
                        {
                            break;
                        }
                    }

                    foreach (MyCubeGrid proj in projections)
                    {
                        if (proj.Projector.CubeGrid == grid)
                        {
                            foreach (IMySlimBlock block in proj.CubeBlocks)
                            {
                                m_projectedBlocks.Add(block);
                            }
                        }
                    }
                }

                continue;
            }

            m_projectedBlocks.ApplyAdditions();

            Log.DebugLog("damaged blocks: " + m_damagedBlocks.Count + ", projected blocks: " + m_projectedBlocks.Count);
        }
Exemple #2
0
 public void CleanUp()
 {
     Shields.Clear();
     RefreshSlot           = 0;
     CreationTick          = 0;
     IntegrityShield       = null;
     NotBlockingShield     = null;
     NotBlockingAttackerId = -1;
     IgnoreAttackerId      = -1;
     OriginBlock           = null;
     OriginHit             = Vector3D.Zero;
 }
        public void ProcessDirtyCells(Dictionary <MyEntity, MyEntityTracker> trackedEntities)
        {
            m_dirtyCells.ApplyAdditions();

            if (m_dirtyCells.Count == 0)
            {
                return;
            }
            ProfilerShort.Begin("Find false possitive dirty cells");
            foreach (var cell in m_dirtyCells)
            {
                foreach (var tracker in trackedEntities.Values)
                {
                    var scaledBoundingVolume = tracker.BoundingVolume;
                    scaledBoundingVolume.Radius *= SCALE;
                    if (scaledBoundingVolume.Contains(cell.BoundingVolume) != ContainmentType.Disjoint)
                    {
                        m_dirtyCells.Remove(cell);
                        break;
                    }
                }
            }
            m_dirtyCells.ApplyRemovals();

            ProfilerShort.BeginNextBlock("Remove stuff");
            foreach (var cell in m_dirtyCells)
            {
                cell.GetAll(m_tempObjectSeedList);

                foreach (var objectSeed in m_tempObjectSeedList)
                {
                    if (objectSeed.Generated)
                    {
                        CloseObjectSeed(objectSeed);
                    }
                }
                m_tempObjectSeedList.Clear();
            }

            ProfilerShort.BeginNextBlock("Remove dirty cells");
            foreach (var cell in m_dirtyCells)
            {
                m_cells.Remove(cell.CellId);
                m_cellsTree.RemoveProxy(cell.proxyId);
            }
            m_dirtyCells.Clear();
            ProfilerShort.End();
        }
        /// <summary>
        /// Unloads all cells that have been marked to be unloaded. It will remove all objects inside the sphere from
        /// the world. It will not unload cells that are still in the tracking volume of a tracked entity.
        /// </summary>
        /// <param name="trackedEntities">List of tracked entities</param>
        public void UnloadCells(Dictionary <MyEntity, MyEntityTracker> trackedEntities)
        {
            m_toUnloadCells.ApplyAdditions();
            if (m_toUnloadCells.Count == 0)
            {
                return;
            }

            List <MyObjectSeed> cellObjects = new List <MyObjectSeed>();

            foreach (MyProceduralCell cell in m_toUnloadCells)
            {
                foreach (MyEntityTracker tracker in trackedEntities.Values)
                {
                    BoundingSphereD boundingVolume = tracker.BoundingVolume;
                    if (boundingVolume.Contains(cell.BoundingVolume) != ContainmentType.Disjoint)
                    {
                        m_toUnloadCells.Remove(cell);
                        break;
                    }
                }
            }
            m_toUnloadCells.ApplyRemovals();
            foreach (var cell in m_toUnloadCells)
            {
                cell.GetAll(cellObjects);

                foreach (MyObjectSeed obj in cellObjects)
                {
                    if (obj.Params.Generated)
                    {
                        CloseObject(obj);
                    }
                }
                cellObjects.Clear();
            }
            foreach (MyProceduralCell cell in m_toUnloadCells)
            {
                m_cells.Remove(cell.CellId);
                m_cellsTree.RemoveProxy(cell.proxyId);
            }
            m_toUnloadCells.Clear();
        }
        /// <summary>
        /// Generates all marked to be loaded cells seeds
        /// </summary>
        public void LoadCells()
        {
            m_toLoadCells.ApplyAdditions();

            foreach (var cellId in m_toLoadCells)
            {
                if (m_loadedCells.ContainsKey(cellId))
                {
                    continue;
                }

                MyProceduralCell cell = GenerateCellSeeds(cellId);
                if (cell != null)
                {
                    m_loadedCells.Add(cellId, cell);

                    BoundingBoxD aabb = cell.BoundingVolume;
                    cell.proxyId = m_cellsTree.AddProxy(ref aabb, cell, 0u);
                }
            }

            m_toLoadCells.Clear();
        }