diff options
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/game/Maps/Map.cpp | 108 | ||||
| -rw-r--r-- | src/server/game/Maps/Map.h | 4 | 
2 files changed, 56 insertions, 56 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index af90ff94255..eb866afb28e 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -1788,8 +1788,7 @@ GridMap::GridMap()      _gridIntHeightMultiplier = 0;      m_V9 = nullptr;      m_V8 = nullptr; -    _maxHeight = nullptr; -    _minHeight = nullptr; +    _minHeightPlanes = nullptr;      // Liquid data      _liquidGlobalEntry = 0;      _liquidGlobalFlags = 0; @@ -1871,8 +1870,7 @@ void GridMap::unloadData()      delete[] _areaMap;      delete[] m_V9;      delete[] m_V8; -    delete[] _maxHeight; -    delete[] _minHeight; +    delete[] _minHeightPlanes;      delete[] _liquidEntry;      delete[] _liquidFlags;      delete[] _liquidMap; @@ -1880,8 +1878,7 @@ void GridMap::unloadData()      _areaMap = nullptr;      m_V9 = nullptr;      m_V8 = nullptr; -    _maxHeight = nullptr; -    _minHeight = nullptr; +    _minHeightPlanes = nullptr;      _liquidEntry = nullptr;      _liquidFlags = nullptr;      _liquidMap  = nullptr; @@ -1953,11 +1950,44 @@ bool GridMap::loadHeightData(FILE* in, uint32 offset, uint32 /*size*/)      if (header.flags & MAP_HEIGHT_HAS_FLIGHT_BOUNDS)      { -        _maxHeight = new int16[3 * 3]; -        _minHeight = new int16[3 * 3]; -        if (fread(_maxHeight, sizeof(int16), 3 * 3, in) != 3 * 3 || -            fread(_minHeight, sizeof(int16), 3 * 3, in) != 3 * 3) +        std::array<int16, 9> maxHeights; +        std::array<int16, 9> minHeights; +        if (fread(maxHeights.data(), sizeof(int16), maxHeights.size(), in) != maxHeights.size() || +            fread(minHeights.data(), sizeof(int16), minHeights.size(), in) != minHeights.size())              return false; + +        static uint32 constexpr indices[8][3] = +        { +            { 3, 0, 4 }, +            { 0, 1, 4 }, +            { 1, 2, 4 }, +            { 2, 5, 4 }, +            { 5, 8, 4 }, +            { 8, 7, 4 }, +            { 7, 6, 4 }, +            { 6, 3, 4 } +        }; + +        static float constexpr boundGridCoords[9][2] = +        { +            { 0.0f, 0.0f }, +            { 0.0f, -266.66666f }, +            { 0.0f, -533.33331f }, +            { -266.66666f, 0.0f }, +            { -266.66666f, -266.66666f }, +            { -266.66666f, -533.33331f }, +            { -533.33331f, 0.0f }, +            { -533.33331f, -266.66666f }, +            { -533.33331f, -533.33331f } +        }; + +        _minHeightPlanes = new G3D::Plane[8]; +        for (uint32 quarterIndex = 0; quarterIndex < 8; ++quarterIndex) +            _minHeightPlanes[quarterIndex] = G3D::Plane( +                G3D::Vector3(boundGridCoords[indices[quarterIndex][0]][0], boundGridCoords[indices[quarterIndex][0]][1], minHeights[indices[quarterIndex][0]]), +                G3D::Vector3(boundGridCoords[indices[quarterIndex][1]][0], boundGridCoords[indices[quarterIndex][1]][1], minHeights[indices[quarterIndex][1]]), +                G3D::Vector3(boundGridCoords[indices[quarterIndex][2]][0], boundGridCoords[indices[quarterIndex][2]][1], minHeights[indices[quarterIndex][2]]) +            );      }      return true; @@ -2269,62 +2299,32 @@ bool GridMap::isHole(int row, int col) const  float GridMap::getMinHeight(float x, float y) const  { -    if (!_minHeight) +    if (!_minHeightPlanes)          return -500.0f; -    static uint32 const indices[] = -    { -        3, 0, 4, -        0, 1, 4, -        1, 2, 4, -        2, 5, 4, -        5, 8, 4, -        8, 7, 4, -        7, 6, 4, -        6, 3, 4 -    }; - -    static float const boundGridCoords[] = -    { -        0.0f, 0.0f, -        0.0f, -266.66666f, -        0.0f, -533.33331f, -        -266.66666f, 0.0f, -        -266.66666f, -266.66666f, -        -266.66666f, -533.33331f, -        -533.33331f, 0.0f, -        -533.33331f, -266.66666f, -        -533.33331f, -533.33331f -    }; - -    Cell cell(x, y); -    float gx = x - (int32(cell.GridX()) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS; -    float gy = y - (int32(cell.GridY()) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS; +    GridCoord gridCoord = Trinity::ComputeGridCoord(x, y); + +    int32 doubleGridX = int32(std::floor(-(x - MAP_HALFSIZE) / CENTER_GRID_OFFSET)); +    int32 doubleGridY = int32(std::floor(-(y - MAP_HALFSIZE) / CENTER_GRID_OFFSET)); + +    float gx = x - (int32(gridCoord.x_coord) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS; +    float gy = y - (int32(gridCoord.y_coord) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS;      uint32 quarterIndex = 0; -    if (cell.CellY() < MAX_NUMBER_OF_CELLS / 2) +    if (doubleGridY & 1)      { -        if (cell.CellX() < MAX_NUMBER_OF_CELLS / 2) -        { -            quarterIndex = 4 + (gy > gx); -        } +        if (doubleGridX & 1) +            quarterIndex = 4 + (gx <= gy);          else              quarterIndex = 2 + ((-SIZE_OF_GRIDS - gx) > gy);      } -    else if (cell.CellX() < MAX_NUMBER_OF_CELLS / 2) -    { +    else if (doubleGridX & 1)          quarterIndex = 6 + ((-SIZE_OF_GRIDS - gx) <= gy); -    }      else          quarterIndex = gx > gy; -    quarterIndex *= 3; - -    return G3D::Plane( -        G3D::Vector3(boundGridCoords[indices[quarterIndex + 0] * 2 + 0], boundGridCoords[indices[quarterIndex + 0] * 2 + 1], _minHeight[indices[quarterIndex + 0]]), -        G3D::Vector3(boundGridCoords[indices[quarterIndex + 1] * 2 + 0], boundGridCoords[indices[quarterIndex + 1] * 2 + 1], _minHeight[indices[quarterIndex + 1]]), -        G3D::Vector3(boundGridCoords[indices[quarterIndex + 2] * 2 + 0], boundGridCoords[indices[quarterIndex + 2] * 2 + 1], _minHeight[indices[quarterIndex + 2]]) -    ).distance(G3D::Vector3(gx, gy, 0.0f)); +    G3D::Ray ray = G3D::Ray::fromOriginAndDirection(G3D::Vector3(gx, gy, 0.0f), G3D::Vector3::unitZ()); +    return ray.intersection(_minHeightPlanes[quarterIndex]).z;  }  float GridMap::getLiquidLevel(float x, float y) const diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 21160087247..032ed6cf40d 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -66,6 +66,7 @@ enum WeatherState : uint32;  namespace Trinity { struct ObjectUpdater; }  namespace VMAP { enum class ModelIgnoreFlags : uint32; } +namespace G3D { class Plane; }  struct ScriptAction  { @@ -201,8 +202,7 @@ class TC_GAME_API GridMap          uint16* m_uint16_V8;          uint8* m_uint8_V8;      }; -    int16* _maxHeight; -    int16* _minHeight; +    G3D::Plane* _minHeightPlanes;      // Height level data      float _gridHeight;      float _gridIntHeightMultiplier;  | 
