Exemple #1
0
        private static void Update10()
        {
            foreach (TestRemoteTask task in m_tasks)
            {
                switch (task.CurrentStatus)
                {
                case Status.None:
                case Status.Started:
                    break;

                default:
                    Logger.DebugLog("Completed: " + task + ", Result: " + task.Result);
                    m_tasks.Remove(task);
                    break;
                }
            }

            m_tasks.ApplyRemovals();

            if (m_tasks.Count < 10)
            {
                TestRemoteTask task = new TestRemoteTask();
                task.Parameter = "Par";
                m_tasks.Add(task);
                StartTask(task);
            }

            m_tasks.ApplyAdditions();
        }
Exemple #2
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);
        }
        /// <summary>
        /// Marks cells to load or keep loaded inside the bounds
        /// </summary>
        /// <param name="bounds">Spherical bounds</param>
        public void MarkToLoadCellsInBounds(BoundingSphereD bounds)
        {
            BoundingBoxD box    = BoundingBoxD.CreateFromSphere(bounds);
            Vector3I     cellId = Vector3I.Floor(box.Min / m_cellSize);

            for (var it = GetCellsIterator(box); it.IsValid(); it.GetNext(out cellId))
            {
                if (m_toLoadCells.Contains(cellId))
                {
                    continue;
                }

                BoundingBoxD cellBounds = new BoundingBoxD(cellId * m_cellSize, (cellId + 1) * m_cellSize);
                if (bounds.Contains(cellBounds) == ContainmentType.Disjoint)
                {
                    continue;
                }

                m_toLoadCells.Add(cellId);
            }

            m_toLoadCells.ApplyAdditions();
        }
        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();
        }