コード例 #1
0
        private void AddGridToMap()
        {
            MyCubeGrid grid;

            while (NewGrids.TryDequeue(out grid))
            {
                var allFat = ConcurrentListPool.Get();

                var gridFat = grid.GetFatBlocks();
                for (int i = 0; i < gridFat.Count; i++)
                {
                    allFat.Add(gridFat[i]);
                }
                allFat.ApplyAdditions();

                var gridMap = GridMapPool.Get();

                if (grid.Components.TryGet(out gridMap.Targeting))
                {
                    gridMap.Targeting.AllowScanning = false;
                }
                gridMap.Trash = true;

                gridMap.MyCubeBocks = allFat;
                GridToInfoMap.TryAdd(grid, gridMap);
                grid.OnFatBlockAdded   += ToGridMap;
                grid.OnFatBlockRemoved += FromGridMap;
                grid.OnClose           += RemoveGridFromMap;
                DirtyGridInfos.Add(grid);
            }
        }
コード例 #2
0
 private void FromGridMap(MyCubeBlock myCubeBlock)
 {
     try
     {
         GridToInfoMap[myCubeBlock.CubeGrid].MyCubeBocks.Remove(myCubeBlock, true);
         DirtyGridInfos.Add(myCubeBlock.CubeGrid);
     }
     catch (Exception ex) { Log.Line($"Exception in FromGridMap: {ex} - marked:{myCubeBlock.MarkedForClose}"); }
 }
コード例 #3
0
 private void ToGridMap(MyCubeBlock myCubeBlock)
 {
     try
     {
         GridToInfoMap[myCubeBlock.CubeGrid].MyCubeBocks.Add(myCubeBlock);
         GridToInfoMap[myCubeBlock.CubeGrid].MyCubeBocks.ApplyAdditions();
         DirtyGridInfos.Add(myCubeBlock.CubeGrid);
     }
     catch (Exception ex) { Log.Line($"Exception in ToGridMap: {ex} - marked:{myCubeBlock.MarkedForClose}"); }
 }
コード例 #4
0
        private void RemoveGridFromMap(MyEntity myEntity)
        {
            var     grid = (MyCubeGrid)myEntity;
            GridMap gridMap;

            if (GridToInfoMap.TryRemove(grid, out gridMap))
            {
                ConcurrentListPool.Return(gridMap.MyCubeBocks);

                gridMap.Trash = true;
                GridMapPool.Return(gridMap);

                grid.OnFatBlockAdded   -= ToGridMap;
                grid.OnFatBlockRemoved -= FromGridMap;
                grid.OnClose           -= RemoveGridFromMap;
                grid.AddedToScene      -= GridAddedToScene;
                DirtyGridInfos.Add(grid);
            }
            else
            {
                Log.Line($"grid not removed and list not cleaned: marked:{grid.MarkedForClose}({grid.Closed}) - inScene:{grid.InScene}");
            }
        }