///======================================================================== /// Method : Resize /// /// <summary> /// Resize the FlatChunk /// </summary> /// <param name="xiNewHasMetaData"></param> /// <param name="xiNewWidth"></param> /// <param name="xiNewHeight"></param> /// <param name="xiOptions"></param> /// <returns> /// The increase in file size, in bytes /// </returns> ///======================================================================== public int Resize(bool xiNewHasMetaData, short xiNewWidth, short xiNewHeight, eResizeOptions xiOptions) { int lExtraSquares = (xiNewWidth * xiNewHeight) - (Width * Height); int lExtraMeta = (xiNewHasMetaData ? (xiNewWidth * xiNewHeight) : 0) - (HasMetaData ? (Width * Height) : 0); int lExtraWidth = xiNewWidth - Width; int lExtraHeight = xiNewHeight - Height; bool lKeepRight = (xiOptions & eResizeOptions.KeepRight) == eResizeOptions.KeepRight; bool lKeepBottom = (xiOptions & eResizeOptions.KeepBottom) == eResizeOptions.KeepBottom; short[][] lOldTextureIds = TextureIds; short[][] lOldTerrainHeight = TerrainHeight; Byte[][][] lOldTexMetaData = TexMetaData; if (lOldTerrainHeight.Length != lOldTextureIds.Length) { throw new Exception("Error: TerrainHeight and TextureIds arrays were of different length!"); } if (HasMetaData && lOldTexMetaData.Length != lOldTextureIds.Length) { throw new Exception("Error: TexMetaData and TextureIds arrays were of different length!"); } Width = xiNewWidth; Height = xiNewHeight; TextureIds = new short[Width][]; TerrainHeight = new short[Width][]; TexMetaData = xiNewHasMetaData ? new Byte[Width][][] : null; for (int x = 0; x < Width; x++) { TextureIds[x] = new short[Height]; TerrainHeight[x] = new short[Height]; if (xiNewHasMetaData) TexMetaData[x] = new Byte[Height][]; int lCopyX = lKeepRight ? x - lExtraWidth : x; if (lCopyX >= lOldTextureIds.Length || lCopyX < 0) { lCopyX = lKeepRight ? lOldTextureIds.Length - 1 : 0; } if (lOldTerrainHeight[lCopyX].Length != lOldTextureIds[lCopyX].Length) { throw new Exception("Error: TerrainHeight and TextureIds arrays were of different length!"); } if (HasMetaData && lOldTexMetaData[lCopyX].Length != lOldTextureIds[lCopyX].Length) { throw new Exception("Error: TexMetaData and TextureIds arrays were of different length!"); } for (int y = 0; y < Height; y++) { int lCopyY = lKeepBottom ? y - lExtraHeight : y; if (lCopyY >= lOldTextureIds[lCopyX].Length || lCopyY < 0) { lCopyY = lKeepBottom ? lOldTextureIds[lCopyX].Length - 1 : 0; } TextureIds[x][y] = lOldTextureIds[lCopyX][lCopyY]; TerrainHeight[x][y] = lOldTerrainHeight[lCopyX][lCopyY]; if (xiNewHasMetaData && HasMetaData) { TexMetaData[x][y] = lOldTexMetaData[lCopyX][lCopyY]; } else if (xiNewHasMetaData) { TexMetaData[x][y] = new Byte[8]; // Initialise to all zero since we've got nothing better to do } } } HasMetaData = xiNewHasMetaData; return lExtraSquares * 4 + lExtraMeta * 8; }
///======================================================================== /// Method : Resize /// /// <summary> /// Resize the FlatChunk /// </summary> /// <param name="xiNewHasMetaData"></param> /// <param name="xiNewWidth"></param> /// <param name="xiNewHeight"></param> /// <param name="xiOptions"></param> /// <returns> /// The increase in file size, in bytes /// </returns> ///======================================================================== public int Resize(bool xiNewHasMetaData, short xiNewWidth, short xiNewHeight, eResizeOptions xiOptions) { int lExtraSquares = (xiNewWidth * xiNewHeight) - (Width * Height); int lExtraMeta = (xiNewHasMetaData ? (xiNewWidth * xiNewHeight) : 0) - (HasMetaData ? (Width * Height) : 0); int lExtraWidth = xiNewWidth - Width; int lExtraHeight = xiNewHeight - Height; bool lKeepRight = (xiOptions & eResizeOptions.KeepRight) == eResizeOptions.KeepRight; bool lKeepBottom = (xiOptions & eResizeOptions.KeepBottom) == eResizeOptions.KeepBottom; short[][] lOldTextureIds = TextureIds; short[][] lOldTerrainHeight = TerrainHeight; Byte[][][] lOldTexMetaData = TexMetaData; if (lOldTerrainHeight.Length != lOldTextureIds.Length) { throw new Exception("Error: TerrainHeight and TextureIds arrays were of different length!"); } if (HasMetaData && lOldTexMetaData.Length != lOldTextureIds.Length) { throw new Exception("Error: TexMetaData and TextureIds arrays were of different length!"); } Width = xiNewWidth; Height = xiNewHeight; TextureIds = new short[Width][]; TerrainHeight = new short[Width][]; TexMetaData = xiNewHasMetaData ? new Byte[Width][][] : null; for (int x = 0; x < Width; x++) { TextureIds[x] = new short[Height]; TerrainHeight[x] = new short[Height]; if (xiNewHasMetaData) { TexMetaData[x] = new Byte[Height][]; } int lCopyX = lKeepRight ? x - lExtraWidth : x; if (lCopyX >= lOldTextureIds.Length || lCopyX < 0) { lCopyX = lKeepRight ? lOldTextureIds.Length - 1 : 0; } if (lOldTerrainHeight[lCopyX].Length != lOldTextureIds[lCopyX].Length) { throw new Exception("Error: TerrainHeight and TextureIds arrays were of different length!"); } if (HasMetaData && lOldTexMetaData[lCopyX].Length != lOldTextureIds[lCopyX].Length) { throw new Exception("Error: TexMetaData and TextureIds arrays were of different length!"); } for (int y = 0; y < Height; y++) { int lCopyY = lKeepBottom ? y - lExtraHeight : y; if (lCopyY >= lOldTextureIds[lCopyX].Length || lCopyY < 0) { lCopyY = lKeepBottom ? lOldTextureIds[lCopyX].Length - 1 : 0; } TextureIds[x][y] = lOldTextureIds[lCopyX][lCopyY]; TerrainHeight[x][y] = lOldTerrainHeight[lCopyX][lCopyY]; if (xiNewHasMetaData && HasMetaData) { TexMetaData[x][y] = lOldTexMetaData[lCopyX][lCopyY]; } else if (xiNewHasMetaData) { TexMetaData[x][y] = new Byte[8]; // Initialise to all zero since we've got nothing better to do } } } HasMetaData = xiNewHasMetaData; return(lExtraSquares * 4 + lExtraMeta * 8); }