public void MarkCellsDirty(BoundingSphereD toMark, BoundingSphereD?toExclude = null, bool scale = true)
        {
            BoundingSphereD toMarkScaled    = new BoundingSphereD(toMark.Center, toMark.Radius * (scale ? SCALE : 1));
            BoundingSphereD toExcludeScaled = new BoundingSphereD();

            if (toExclude.HasValue)
            {
                toExcludeScaled = toExclude.Value;
                if (scale)
                {
                    toExcludeScaled.Radius *= SCALE;
                }
            }
            ProfilerShort.Begin("Mark dirty cells");
            Vector3I cellId = Vector3I.Floor((toMarkScaled.Center - toMarkScaled.Radius) / CELL_SIZE);

            for (var iter = GetCellsIterator(toMarkScaled); iter.IsValid(); iter.GetNext(out cellId))
            {
                MyProceduralCell cell;
                if (m_cells.TryGetValue(cellId, out cell))
                {
                    if (!toExclude.HasValue || toExcludeScaled.Contains(cell.BoundingVolume) == ContainmentType.Disjoint)
                    {
                        m_dirtyCells.Add(cell);
                    }
                }
            }
            ProfilerShort.End();
        }
예제 #2
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();
        }
예제 #3
0
파일: WeldGrid.cs 프로젝트: zrisher/ARMS
        /// <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);
        }
 public void Register(EquiPlayerAttachmentComponent.Slot slot)
 {
     if (!MyMultiplayerModApi.Static.IsServer)
     {
         return;
     }
     _slots.Add(slot);
     MarkDirty();
 }
        /// <summary>
        /// Marks all cells inside of the toUnload bounding sphere to be unloaded, except all Objects inside toExclude.
        /// </summary>
        /// <param name="toUnload">Unload sphere</param>
        /// <param name="toExclude">Exclude sphere</param>
        public void MarkToUnloadCells(BoundingSphereD toUnload, BoundingSphereD?toExclude = null)
        {
            Vector3I cellId = Vector3I.Floor((toUnload.Center - toUnload.Radius) / CELL_SIZE);

            for (var iter = GetCellsIterator(toUnload); iter.IsValid(); iter.GetNext(out cellId))
            {
                MyProceduralCell cell;
                if (m_cells.TryGetValue(cellId, out cell))
                {
                    if (toExclude == null || !toExclude.HasValue || toExclude.Value.Contains(cell.BoundingVolume) == ContainmentType.Disjoint)
                    {
                        m_toUnloadCells.Add(cell);
                    }
                }
            }
        }
        /// <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 static void GenerateLuckyContent(this MyInventoryBase inventory, MyLootTableDefinition lootTableDefinition,
                                                LootContext context, HashSet <MyStringHash> blacklistedLootTables = null)
        {
            var cachingHashSet = new CachingHashSet <MyLootTableDefinition.Row>();

            foreach (var item in lootTableDefinition.LootTable)
            {
                cachingHashSet.Add(item);
            }
            cachingHashSet.ApplyChanges();
            var num = 0f;

            if (blacklistedLootTables == null)
            {
                blacklistedLootTables = new HashSet <MyStringHash>();
            }
            blacklistedLootTables.Add(lootTableDefinition.Id.SubtypeId);
            foreach (var row in cachingHashSet)
            {
                if (row.AlwaysDrops && row.ItemDefinition != null)
                {
                    if (row.ItemDefinition.Value.TypeId == typeof(MyObjectBuilder_LootTableDefinition))
                    {
                        var nestedTable = MyDefinitionManager.Get <MyLootTableDefinition>(row.ItemDefinition.Value);
                        if (nestedTable != null && !blacklistedLootTables.Contains(nestedTable.Id.SubtypeId))
                        {
                            inventory.GenerateLuckyContent(nestedTable, context, blacklistedLootTables);
                        }
                    }
                    else
                    {
                        AddItemsFuzzy(inventory, row.ItemDefinition.Value, row.Amount);
                    }

                    if (row.IsUnique)
                    {
                        cachingHashSet.Remove(row, false);
                        continue;
                    }
                }

                num += row.Weight;
            }

            var rollLucky = Math.Round(lootTableDefinition.Rolls * context.RollMultiplier + context.RollAdditive);

            for (var j = 0; j < rollLucky; j++)
            {
                var num2 = MyRandom.Instance.NextFloat(0f, num);
                cachingHashSet.ApplyChanges();
                foreach (var row2 in cachingHashSet)
                {
                    num2 -= row2.Weight;
                    if (num2 > 0f || row2.ItemDefinition == null)
                    {
                        continue;
                    }
                    if (row2.ItemDefinition.Value.TypeId == typeof(MyObjectBuilder_LootTableDefinition))
                    {
                        var nestedTable = MyDefinitionManager.Get <MyLootTableDefinition>(row2.ItemDefinition.Value);
                        if (nestedTable != null)
                        {
                            inventory.GenerateLuckyContent(nestedTable, context);
                        }
                    }
                    else
                    {
                        AddItemsFuzzy(inventory, row2.ItemDefinition.Value, row2.Amount);
                    }

                    if (row2.IsUnique)
                    {
                        cachingHashSet.Remove(row2, false);
                        num -= row2.Weight;
                    }

                    break;
                }
            }

            blacklistedLootTables.Remove(lootTableDefinition.Id.SubtypeId);
        }