public MyGeneratedBlockLocation(MySlimBlock refBlock, MyCubeBlockDefinition blockDefinition, Vector3I position, Vector3I forward, Vector3I up, ushort?blockIdInCompound = null, MyGridInfo gridInfo = null) { RefBlock = refBlock; BlockDefinition = blockDefinition; Position = position; Orientation = new MyBlockOrientation(Base6Directions.GetDirection(ref forward), Base6Directions.GetDirection(ref up)); BlockIdInCompound = blockIdInCompound; GridInfo = gridInfo; GeneratedBlockType = MyStringId.NullOrEmpty; }
public MyGeneratedBlockLocation(MySlimBlock refBlock, MyCubeBlockDefinition blockDefinition, Vector3I position, Vector3I forward, Vector3I up, ushort? blockIdInCompound = null, MyGridInfo gridInfo = null) { RefBlock = refBlock; BlockDefinition = blockDefinition; Position = position; Orientation = new MyBlockOrientation(Base6Directions.GetDirection(ref forward), Base6Directions.GetDirection(ref up)); BlockIdInCompound = blockIdInCompound; GridInfo = gridInfo; GeneratedBlockType = MyStringId.NullOrEmpty; }
public MyGeneratedBlockLocation(MySlimBlock refBlock, MyCubeBlockDefinition blockDefinition, Vector3I position, MyBlockOrientation orientation, ushort?blockIdInCompound = null, MyGridInfo gridInfo = null) { RefBlock = refBlock; BlockDefinition = blockDefinition; Position = position; Orientation = orientation; BlockIdInCompound = blockIdInCompound; GridInfo = gridInfo; GeneratedBlockType = MyStringId.NullOrEmpty; }
public MyGeneratedBlockLocation(MySlimBlock refBlock, MyCubeBlockDefinition blockDefinition, Vector3I position, MyBlockOrientation orientation, ushort? blockIdInCompound = null, MyGridInfo gridInfo = null) { RefBlock = refBlock; BlockDefinition = blockDefinition; Position = position; Orientation = orientation; BlockIdInCompound = blockIdInCompound; GridInfo = gridInfo; GeneratedBlockType = MyStringId.NullOrEmpty; }
private void ProcessChangedGrid(MyCubeGrid newGrid) { Vector3I gridOffset = Vector3I.Round((m_grid.PositionComp.GetPosition() - newGrid.PositionComp.GetPosition()) / m_grid.GridSize); Vector3 fw = (Vector3)Vector3D.TransformNormal(m_grid.WorldMatrix.Forward, newGrid.PositionComp.WorldMatrixNormalizedInv); Vector3 up = (Vector3)Vector3D.TransformNormal(m_grid.WorldMatrix.Up, newGrid.PositionComp.WorldMatrixNormalizedInv); Base6Directions.Direction fwDir = Base6Directions.GetClosestDirection(fw); Base6Directions.Direction upDir = Base6Directions.GetClosestDirection(up); if (upDir == fwDir) { upDir = Base6Directions.GetPerpendicular(fwDir); } MatrixI transform = new MatrixI(ref gridOffset, fwDir, upDir); MyGridInfo gridInfo = new MyGridInfo(); gridInfo.Grid = newGrid; gridInfo.Transform = transform; m_splitGridInfos.Add(gridInfo); // Remove from split grid if (m_removeLocationsForGridSplits.Count > 0) { List <int> indexesToRemove = new List <int>(); for (int i = 0; i < m_removeLocationsForGridSplits.Count; ++i) { MyGeneratedBlockLocation location = m_removeLocationsForGridSplits[i]; Debug.Assert(location.GeneratedBlockType != MyStringId.NullOrEmpty); RemoveBlock(location, gridInfo, location.GeneratedBlockType); } } // Add to split grid List <MySlimBlock> newGridBlocks = new List <MySlimBlock>(); m_addLocations.RemoveWhere(delegate(MyGeneratedBlockLocation loc) { if (loc.RefBlock != null && loc.RefBlock.CubeGrid == newGrid) { newGridBlocks.Add(loc.RefBlock); return(true); } return(false); }); foreach (var newGridBlock in newGridBlocks) { Debug.Assert(newGrid == newGridBlock.CubeGrid); newGridBlock.CubeGrid.AdditionalModelGenerators.ForEach(g => g.UpdateAfterGridSpawn(newGridBlock)); } }
private void ProcessChangedGrid(MyCubeGrid newGrid) { Vector3I position = Vector3I.Round((this.m_grid.PositionComp.GetPosition() - newGrid.PositionComp.GetPosition()) / ((double)this.m_grid.GridSize)); Vector3 vec = (Vector3)Vector3D.TransformNormal(this.m_grid.WorldMatrix.Forward, newGrid.PositionComp.WorldMatrixNormalizedInv); Base6Directions.Direction closestDirection = Base6Directions.GetClosestDirection(vec); Base6Directions.Direction up = Base6Directions.GetClosestDirection((Vector3)Vector3D.TransformNormal(this.m_grid.WorldMatrix.Up, newGrid.PositionComp.WorldMatrixNormalizedInv)); if (up == closestDirection) { up = Base6Directions.GetPerpendicular(closestDirection); } MyGridInfo item = new MyGridInfo { Grid = newGrid, Transform = new MatrixI(ref position, closestDirection, up) }; this.m_splitGridInfos.Add(item); if (this.m_removeLocationsForGridSplits.Count > 0) { List <int> list1 = new List <int>(); for (int i = 0; i < this.m_removeLocationsForGridSplits.Count; i++) { MyGeneratedBlockLocation location = this.m_removeLocationsForGridSplits[i]; this.RemoveBlock(location, item, location.GeneratedBlockType); } } List <MySlimBlock> newGridBlocks = new List <MySlimBlock>(); this.m_addLocations.RemoveWhere(delegate(MyGeneratedBlockLocation loc) { if ((loc.RefBlock == null) || !ReferenceEquals(loc.RefBlock.CubeGrid, newGrid)) { return(false); } newGridBlocks.Add(loc.RefBlock); return(true); }); using (List <MySlimBlock> .Enumerator enumerator = newGridBlocks.GetEnumerator()) { while (enumerator.MoveNext()) { MySlimBlock newGridBlock; newGridBlock.CubeGrid.AdditionalModelGenerators.ForEach(g => g.UpdateAfterGridSpawn(newGridBlock)); } } }
private bool RemoveBlock(MyGeneratedBlockLocation location, MyGridInfo gridInfo, MyStringId generatedBlockType) { MySlimBlock slimBlock = null; if (gridInfo != null) { Vector3I position = Vector3I.Transform(location.Position, gridInfo.Transform); slimBlock = gridInfo.Grid.GetCubeBlock(position); } else { slimBlock = m_grid.GetCubeBlock(location.Position); } if (slimBlock != null) { if (slimBlock.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = slimBlock.FatBlock as MyCompoundCubeBlock; var compoundBlocks = compoundBlock.GetBlocks(); for (int i = 0; i < compoundBlocks.Count; ++i) { MySlimBlock block = compoundBlocks[i]; Debug.Assert(block != null); if (block.BlockDefinition.IsGeneratedBlock && block.BlockDefinition.GeneratedBlockType == generatedBlockType && block.Orientation == location.Orientation) { ushort?id = compoundBlock.GetBlockId(block); m_removeLocations.Add(new MyGeneratedBlockLocation(null, block.BlockDefinition, block.Position, block.Orientation, blockIdInCompound: id, gridInfo: gridInfo)); return(true); } } } else if (slimBlock.BlockDefinition.IsGeneratedBlock && slimBlock.BlockDefinition.GeneratedBlockType == generatedBlockType && slimBlock.Orientation == location.Orientation) { m_removeLocations.Add(new MyGeneratedBlockLocation(null, slimBlock.BlockDefinition, slimBlock.Position, slimBlock.Orientation, gridInfo: gridInfo)); return(true); } } return(false); }
private bool RemoveBlock(MyGeneratedBlockLocation location, MyGridInfo gridInfo, MyStringId generatedBlockType) { MySlimBlock cubeBlock = null; if (gridInfo == null) { cubeBlock = this.m_grid.GetCubeBlock(location.Position); } else { Vector3I pos = Vector3I.Transform(location.Position, gridInfo.Transform); cubeBlock = gridInfo.Grid.GetCubeBlock(pos); } if (cubeBlock != null) { if (!(cubeBlock.FatBlock is MyCompoundCubeBlock)) { if ((cubeBlock.BlockDefinition.IsGeneratedBlock && (cubeBlock.BlockDefinition.GeneratedBlockType == generatedBlockType)) && (cubeBlock.Orientation == location.Orientation)) { ushort?blockIdInCompound = null; this.m_removeLocations.Add(new MyGeneratedBlockLocation(null, cubeBlock.BlockDefinition, cubeBlock.Position, cubeBlock.Orientation, blockIdInCompound, gridInfo)); return(true); } } else { MyCompoundCubeBlock fatBlock = cubeBlock.FatBlock as MyCompoundCubeBlock; ListReader <MySlimBlock> blocks = fatBlock.GetBlocks(); for (int i = 0; i < blocks.Count; i++) { MySlimBlock block3 = blocks[i]; if ((block3.BlockDefinition.IsGeneratedBlock && (block3.BlockDefinition.GeneratedBlockType == generatedBlockType)) && (block3.Orientation == location.Orientation)) { ushort?blockId = fatBlock.GetBlockId(block3); this.m_removeLocations.Add(new MyGeneratedBlockLocation(null, block3.BlockDefinition, block3.Position, block3.Orientation, blockId, gridInfo)); return(true); } } } } return(false); }
private bool RemoveBlock(MyGeneratedBlockLocation location, MyGridInfo gridInfo, MyStringId generatedBlockType) { MySlimBlock slimBlock = null; if (gridInfo != null) { Vector3I position = Vector3I.Transform(location.Position, gridInfo.Transform); slimBlock = gridInfo.Grid.GetCubeBlock(position); } else { slimBlock = m_grid.GetCubeBlock(location.Position); } if (slimBlock != null) { if (slimBlock.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = slimBlock.FatBlock as MyCompoundCubeBlock; var compoundBlocks = compoundBlock.GetBlocks(); for (int i = 0; i < compoundBlocks.Count; ++i) { MySlimBlock block = compoundBlocks[i]; Debug.Assert(block != null); if (block.BlockDefinition.IsGeneratedBlock && block.BlockDefinition.GeneratedBlockType == generatedBlockType && block.Orientation == location.Orientation) { ushort? id = compoundBlock.GetBlockId(block); m_removeLocations.Add(new MyGeneratedBlockLocation(null, block.BlockDefinition, block.Position, block.Orientation, blockIdInCompound: id, gridInfo: gridInfo)); return true; } } } else if (slimBlock.BlockDefinition.IsGeneratedBlock && slimBlock.BlockDefinition.GeneratedBlockType == generatedBlockType && slimBlock.Orientation == location.Orientation) { m_removeLocations.Add(new MyGeneratedBlockLocation(null, slimBlock.BlockDefinition, slimBlock.Position, slimBlock.Orientation, gridInfo: gridInfo)); return true; } } return false; }
private void ProcessChangedGrid(MyCubeGrid newGrid) { Vector3I gridOffset = Vector3I.Round((m_grid.PositionComp.GetPosition() - newGrid.PositionComp.GetPosition()) / m_grid.GridSize); Vector3 fw = (Vector3)Vector3D.TransformNormal(m_grid.WorldMatrix.Forward, newGrid.PositionComp.WorldMatrixNormalizedInv); Vector3 up = (Vector3)Vector3D.TransformNormal(m_grid.WorldMatrix.Up, newGrid.PositionComp.WorldMatrixNormalizedInv); Base6Directions.Direction fwDir = Base6Directions.GetClosestDirection(fw); Base6Directions.Direction upDir = Base6Directions.GetClosestDirection(up); if (upDir == fwDir) upDir = Base6Directions.GetPerpendicular(fwDir); MatrixI transform = new MatrixI(ref gridOffset, fwDir, upDir); MyGridInfo gridInfo = new MyGridInfo(); gridInfo.Grid = newGrid; gridInfo.Transform = transform; m_splitGridInfos.Add(gridInfo); // Remove from split grid if (m_removeLocationsForGridSplits.Count > 0) { List<int> indexesToRemove = new List<int>(); for (int i = 0; i < m_removeLocationsForGridSplits.Count; ++i) { MyGeneratedBlockLocation location = m_removeLocationsForGridSplits[i]; Debug.Assert(location.GeneratedBlockType != MyStringId.NullOrEmpty); RemoveBlock(location, gridInfo, location.GeneratedBlockType); } } // Add to split grid List<MySlimBlock> newGridBlocks = new List<MySlimBlock>(); m_addLocations.RemoveWhere(delegate(MyGeneratedBlockLocation loc) { if (loc.RefBlock != null && loc.RefBlock.CubeGrid == newGrid) { newGridBlocks.Add(loc.RefBlock); return true; } return false; }); foreach (var newGridBlock in newGridBlocks) { Debug.Assert(newGrid == newGridBlock.CubeGrid); newGridBlock.CubeGrid.AdditionalModelGenerators.ForEach(g => g.UpdateAfterGridSpawn(newGridBlock)); } }