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 fatMap = FatMapPool.Get(); if (grid.Components.TryGet(out fatMap.Targeting)) { fatMap.Targeting.AllowScanning = false; } fatMap.Trash = true; fatMap.MyCubeBocks = allFat; GridToFatMap.TryAdd(grid, fatMap); grid.OnFatBlockAdded += ToFatMap; grid.OnFatBlockRemoved += FromFatMap; grid.OnClose += RemoveGridFromMap; DirtyGrids.Add(grid); } }
private void FromFatMap(MyCubeBlock myCubeBlock) { try { GridToFatMap[myCubeBlock.CubeGrid].MyCubeBocks.Remove(myCubeBlock, true); DirtyGrids.Add(myCubeBlock.CubeGrid); } catch (Exception ex) { Log.Line($"Exception in FromFatMap: {ex} - marked:{myCubeBlock.MarkedForClose}"); } }
private void ToFatMap(MyCubeBlock myCubeBlock) { try { GridToFatMap[myCubeBlock.CubeGrid].MyCubeBocks.Add(myCubeBlock); GridToFatMap[myCubeBlock.CubeGrid].MyCubeBocks.ApplyAdditions(); DirtyGrids.Add(myCubeBlock.CubeGrid); } catch (Exception ex) { Log.Line($"Exception in ToFatMap: {ex} - marked:{myCubeBlock.MarkedForClose}"); } }
private void RemoveGridFromMap(MyEntity myEntity) { var grid = (MyCubeGrid)myEntity; FatMap fatMap; if (GridToFatMap.TryRemove(grid, out fatMap)) { ConcurrentListPool.Return(fatMap.MyCubeBocks); fatMap.Trash = true; FatMapPool.Return(fatMap); grid.OnFatBlockAdded -= ToFatMap; grid.OnFatBlockRemoved -= FromFatMap; grid.OnClose -= RemoveGridFromMap; grid.AddedToScene -= GridAddedToScene; DirtyGrids.Add(grid); } else { Log.Line($"grid not removed and list not cleaned: marked:{grid.MarkedForClose}({grid.Closed}) - inScene:{grid.InScene}"); } }