void LoadHeightData(BinaryReader reader, uint offset) { reader.BaseStream.Seek(offset, SeekOrigin.Begin); map_HeightHeader mapHeader = reader.ReadStruct <map_HeightHeader>(); _gridHeight = mapHeader.gridHeight; _flags = (uint)mapHeader.flags; if (!mapHeader.flags.HasAnyFlag(HeightHeaderFlags.NoHeight)) { if (mapHeader.flags.HasAnyFlag(HeightHeaderFlags.HeightAsInt16)) { m_uint16_V9 = new ushort[129 * 129]; for (var i = 0; i < m_uint16_V9.Length; ++i) { m_uint16_V9[i] = reader.ReadUInt16(); } m_uint16_V8 = new ushort[128 * 128]; for (var i = 0; i < m_uint16_V8.Length; ++i) { m_uint16_V8[i] = reader.ReadUInt16(); } _gridIntHeightMultiplier = (mapHeader.gridMaxHeight - mapHeader.gridHeight) / 65535; _gridGetHeight = getHeightFromUint16; } else if (mapHeader.flags.HasAnyFlag(HeightHeaderFlags.HeightAsInt8)) { m_ubyte_V9 = reader.ReadBytes(129 * 129); m_ubyte_V8 = reader.ReadBytes(128 * 128); _gridIntHeightMultiplier = (mapHeader.gridMaxHeight - mapHeader.gridHeight) / 255; _gridGetHeight = getHeightFromUint8; } else { m_V9 = new float[129 * 129]; for (var i = 0; i < m_V9.Length; ++i) { m_V9[i] = reader.ReadSingle(); } m_V8 = new float[128 * 128]; for (var i = 0; i < m_V8.Length; ++i) { m_V8[i] = reader.ReadSingle(); } _gridGetHeight = getHeightFromFloat; } } else { _gridGetHeight = getHeightFromFlat; } if (mapHeader.flags.HasAnyFlag(HeightHeaderFlags.HeightHasFlightBounds)) { _maxHeight = new short[3 * 3]; for (var i = 0; i < _maxHeight.Length; ++i) { _maxHeight[i] = reader.ReadInt16(); } _minHeight = new short[3 * 3]; for (var i = 0; i < _minHeight.Length; ++i) { _minHeight[i] = reader.ReadInt16(); } } }
bool LoadHeightData(BinaryReader reader, uint offset) { reader.BaseStream.Seek(offset, SeekOrigin.Begin); map_HeightHeader mapHeader = reader.Read <map_HeightHeader>(); if (mapHeader.fourcc != MapConst.MapHeightMagic) { return(false); } _gridHeight = mapHeader.gridHeight; _flags = (uint)mapHeader.flags; if (!mapHeader.flags.HasAnyFlag(HeightHeaderFlags.NoHeight)) { if (mapHeader.flags.HasAnyFlag(HeightHeaderFlags.HeightAsInt16)) { m_uint16_V9 = reader.ReadArray <ushort>(129 * 129); m_uint16_V8 = reader.ReadArray <ushort>(128 * 128); _gridIntHeightMultiplier = (mapHeader.gridMaxHeight - mapHeader.gridHeight) / 65535; _gridGetHeight = getHeightFromUint16; } else if (mapHeader.flags.HasAnyFlag(HeightHeaderFlags.HeightAsInt8)) { m_ubyte_V9 = reader.ReadBytes(129 * 129); m_ubyte_V8 = reader.ReadBytes(128 * 128); _gridIntHeightMultiplier = (mapHeader.gridMaxHeight - mapHeader.gridHeight) / 255; _gridGetHeight = getHeightFromUint8; } else { m_V9 = reader.ReadArray <float>(129 * 129); m_V8 = reader.ReadArray <float>(128 * 128); _gridGetHeight = getHeightFromFloat; } } else { _gridGetHeight = getHeightFromFlat; } if (mapHeader.flags.HasAnyFlag(HeightHeaderFlags.HeightHasFlightBounds)) { short[] maxHeights = reader.ReadArray <short>(3 * 3); short[] minHeights = reader.ReadArray <short>(3 * 3); uint[][] indices = { new uint[] { 3, 0, 4 }, new uint[] { 0, 1, 4 }, new uint[] { 1, 2, 4 }, new uint[] { 2, 5, 4 }, new uint[] { 5, 8, 4 }, new uint[] { 8, 7, 4 }, new uint[] { 7, 6, 4 }, new uint[] { 6, 3, 4 } }; float[][] boundGridCoords = { new [] { 0.0f, 0.0f }, new [] { 0.0f, -266.66666f }, new [] { 0.0f, -533.33331f }, new [] { -266.66666f, 0.0f }, new [] { -266.66666f, -266.66666f }, new [] { -266.66666f, -533.33331f }, new [] { -533.33331f, 0.0f }, new [] { -533.33331f, -266.66666f }, new [] { -533.33331f, -533.33331f } }; _minHeightPlanes = new Plane[8]; for (uint quarterIndex = 0; quarterIndex < 8; ++quarterIndex) { _minHeightPlanes[quarterIndex] = new Plane( new Vector3(boundGridCoords[indices[quarterIndex][0]][0], boundGridCoords[indices[quarterIndex][0]][1], minHeights[indices[quarterIndex][0]]), new Vector3(boundGridCoords[indices[quarterIndex][1]][0], boundGridCoords[indices[quarterIndex][1]][1], minHeights[indices[quarterIndex][1]]), new Vector3(boundGridCoords[indices[quarterIndex][2]][0], boundGridCoords[indices[quarterIndex][2]][1], minHeights[indices[quarterIndex][2]]) ); } } return(true); }