AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
GridMap Class Reference

#include "Map.h"

Public Member Functions

 GridMap ()
 
 ~GridMap ()
 
bool loadData (char *filaname)
 
void unloadData ()
 
uint16 getArea (float x, float y) const
 
float getHeight (float x, float y) const
 
float getMinHeight (float x, float y) const
 
float getLiquidLevel (float x, float y) const
 
LiquidData const GetLiquidData (float x, float y, float z, float collisionHeight, uint8 ReqLiquidType) const
 

Private Types

typedef float(GridMap::* GetHeightPtr) (float x, float y) const
 

Private Member Functions

bool loadAreaData (FILE *in, uint32 offset, uint32 size)
 
bool loadHeightData (FILE *in, uint32 offset, uint32 size)
 
bool loadLiquidData (FILE *in, uint32 offset, uint32 size)
 
bool loadHolesData (FILE *in, uint32 offset, uint32 size)
 
bool isHole (int row, int col) const
 
float getHeightFromFloat (float x, float y) const
 
float getHeightFromUint16 (float x, float y) const
 
float getHeightFromUint8 (float x, float y) const
 
float getHeightFromFlat (float x, float y) const
 

Private Attributes

uint32 _flags
 
union {
   float *   m_V9
 
   uint16 *   m_uint16_V9
 
   uint8 *   m_uint8_V9
 
}; 
 
union {
   float *   m_V8
 
   uint16 *   m_uint16_V8
 
   uint8 *   m_uint8_V8
 
}; 
 
int16_maxHeight
 
int16_minHeight
 
float _gridHeight
 
float _gridIntHeightMultiplier
 
uint16_areaMap
 
float _liquidLevel
 
uint16_liquidEntry
 
uint8_liquidFlags
 
float * _liquidMap
 
uint16 _gridArea
 
uint16 _liquidGlobalEntry
 
uint8 _liquidGlobalFlags
 
uint8 _liquidOffX
 
uint8 _liquidOffY
 
uint8 _liquidWidth
 
uint8 _liquidHeight
 
uint16_holes
 
GetHeightPtr _gridGetHeight
 

Detailed Description

Member Typedef Documentation

◆ GetHeightPtr

typedef float(GridMap::* GridMap::GetHeightPtr) (float x, float y) const
private

Constructor & Destructor Documentation

◆ GridMap()

GridMap::GridMap ( )
1325{
1326 _flags = 0;
1327 // Area data
1328 _gridArea = 0;
1329 _areaMap = nullptr;
1330 // Height level data
1334 m_V9 = nullptr;
1335 m_V8 = nullptr;
1336 _maxHeight = nullptr;
1337 _minHeight = nullptr;
1338 // Liquid data
1341 _liquidOffX = 0;
1342 _liquidOffY = 0;
1343 _liquidWidth = 0;
1344 _liquidHeight = 0;
1346 _liquidEntry = nullptr;
1347 _liquidFlags = nullptr;
1348 _liquidMap = nullptr;
1349 _holes = nullptr;
1350}
#define INVALID_HEIGHT
Definition: Map.h:163
int16 * _minHeight
Definition: Map.h:215
float getHeightFromFlat(float x, float y) const
Definition: Map.cpp:1568
float _liquidLevel
Definition: Map.h:224
uint16 * _liquidEntry
Definition: Map.h:225
uint8 _liquidGlobalFlags
Definition: Map.h:230
uint8 _liquidOffY
Definition: Map.h:232
uint16 _liquidGlobalEntry
Definition: Map.h:229
uint8 _liquidOffX
Definition: Map.h:231
float * _liquidMap
Definition: Map.h:227
uint32 _flags
Definition: Map.h:201
uint8 _liquidHeight
Definition: Map.h:234
int16 * _maxHeight
Definition: Map.h:214
uint16 * _areaMap
Definition: Map.h:221
float _gridIntHeightMultiplier
Definition: Map.h:218
uint8 _liquidWidth
Definition: Map.h:233
uint8 * _liquidFlags
Definition: Map.h:226
float * m_V9
Definition: Map.h:204
uint16 _gridArea
Definition: Map.h:228
float _gridHeight
Definition: Map.h:217
GetHeightPtr _gridGetHeight
Definition: Map.h:245
uint16 * _holes
Definition: Map.h:235
float * m_V8
Definition: Map.h:210

References _areaMap, _flags, _gridArea, _gridGetHeight, _gridHeight, _gridIntHeightMultiplier, _holes, _liquidEntry, _liquidFlags, _liquidGlobalEntry, _liquidGlobalFlags, _liquidHeight, _liquidLevel, _liquidMap, _liquidOffX, _liquidOffY, _liquidWidth, _maxHeight, _minHeight, getHeightFromFlat(), INVALID_HEIGHT, m_V8, and m_V9.

◆ ~GridMap()

GridMap::~GridMap ( )
1353{
1354 unloadData();
1355}
void unloadData()
Definition: Map.cpp:1412

References unloadData().

Member Function Documentation

◆ getArea()

uint16 GridMap::getArea ( float  x,
float  y 
) const
1557{
1558 if (!_areaMap)
1559 return _gridArea;
1560
1561 x = 16 * (32 - x / SIZE_OF_GRIDS);
1562 y = 16 * (32 - y / SIZE_OF_GRIDS);
1563 int lx = (int)x & 15;
1564 int ly = (int)y & 15;
1565 return _areaMap[lx * 16 + ly];
1566}
#define SIZE_OF_GRIDS
Definition: MapDefines.h:25

References _areaMap, _gridArea, and SIZE_OF_GRIDS.

Referenced by Map::GetFullTerrainStatusForPosition(), and GetLiquidData().

◆ getHeight()

float GridMap::getHeight ( float  x,
float  y 
) const
inline
258{return (this->*_gridGetHeight)(x, y);}

Referenced by Map::GetFullTerrainStatusForPosition(), and GetLiquidData().

◆ getHeightFromFlat()

float GridMap::getHeightFromFlat ( float  x,
float  y 
) const
private
1569{
1570 return _gridHeight;
1571}

References _gridHeight.

Referenced by GridMap(), loadHeightData(), and unloadData().

◆ getHeightFromFloat()

float GridMap::getHeightFromFloat ( float  x,
float  y 
) const
private
1574{
1575 if (!m_V8 || !m_V9)
1576 return _gridHeight;
1577
1578 x = MAP_RESOLUTION * (32 - x / SIZE_OF_GRIDS);
1579 y = MAP_RESOLUTION * (32 - y / SIZE_OF_GRIDS);
1580
1581 int x_int = (int)x;
1582 int y_int = (int)y;
1583 x -= x_int;
1584 y -= y_int;
1585 x_int &= (MAP_RESOLUTION - 1);
1586 y_int &= (MAP_RESOLUTION - 1);
1587
1588 if (isHole(x_int, y_int))
1589 return INVALID_HEIGHT;
1590
1591 // Height stored as: h5 - its v8 grid, h1-h4 - its v9 grid
1592 // +--------------> X
1593 // | h1-------h2 Coordinates is:
1594 // | | \ 1 / | h1 0, 0
1595 // | | \ / | h2 0, 1
1596 // | | 2 h5 3 | h3 1, 0
1597 // | | / \ | h4 1, 1
1598 // | | / 4 \ | h5 1/2, 1/2
1599 // | h3-------h4
1600 // V Y
1601 // For find height need
1602 // 1 - detect triangle
1603 // 2 - solve linear equation from triangle points
1604 // Calculate coefficients for solve h = a*x + b*y + c
1605
1606 float a, b, c;
1607 // Select triangle:
1608 if (x + y < 1)
1609 {
1610 if (x > y)
1611 {
1612 // 1 triangle (h1, h2, h5 points)
1613 float h1 = m_V9[(x_int) * 129 + y_int];
1614 float h2 = m_V9[(x_int + 1) * 129 + y_int];
1615 float h5 = 2 * m_V8[x_int * 128 + y_int];
1616 a = h2 - h1;
1617 b = h5 - h1 - h2;
1618 c = h1;
1619 }
1620 else
1621 {
1622 // 2 triangle (h1, h3, h5 points)
1623 float h1 = m_V9[x_int * 129 + y_int ];
1624 float h3 = m_V9[x_int * 129 + y_int + 1];
1625 float h5 = 2 * m_V8[x_int * 128 + y_int];
1626 a = h5 - h1 - h3;
1627 b = h3 - h1;
1628 c = h1;
1629 }
1630 }
1631 else
1632 {
1633 if (x > y)
1634 {
1635 // 3 triangle (h2, h4, h5 points)
1636 float h2 = m_V9[(x_int + 1) * 129 + y_int ];
1637 float h4 = m_V9[(x_int + 1) * 129 + y_int + 1];
1638 float h5 = 2 * m_V8[x_int * 128 + y_int];
1639 a = h2 + h4 - h5;
1640 b = h4 - h2;
1641 c = h5 - h4;
1642 }
1643 else
1644 {
1645 // 4 triangle (h3, h4, h5 points)
1646 float h3 = m_V9[(x_int) * 129 + y_int + 1];
1647 float h4 = m_V9[(x_int + 1) * 129 + y_int + 1];
1648 float h5 = 2 * m_V8[x_int * 128 + y_int];
1649 a = h4 - h3;
1650 b = h3 + h4 - h5;
1651 c = h5 - h4;
1652 }
1653 }
1654 // Calculate height
1655 return a * x + b * y + c;
1656}
#define MAP_RESOLUTION
Definition: GridDefines.h:50
bool isHole(int row, int col) const
Definition: Map.cpp:1798

References _gridHeight, INVALID_HEIGHT, isHole(), m_V8, m_V9, MAP_RESOLUTION, and SIZE_OF_GRIDS.

Referenced by loadHeightData().

◆ getHeightFromUint16()

float GridMap::getHeightFromUint16 ( float  x,
float  y 
) const
private
1729{
1730 if (!m_uint16_V8 || !m_uint16_V9)
1731 return _gridHeight;
1732
1733 x = MAP_RESOLUTION * (32 - x / SIZE_OF_GRIDS);
1734 y = MAP_RESOLUTION * (32 - y / SIZE_OF_GRIDS);
1735
1736 int x_int = (int)x;
1737 int y_int = (int)y;
1738 x -= x_int;
1739 y -= y_int;
1740 x_int &= (MAP_RESOLUTION - 1);
1741 y_int &= (MAP_RESOLUTION - 1);
1742
1743 if (isHole(x_int, y_int))
1744 return INVALID_HEIGHT;
1745
1746 int32 a, b, c;
1747 uint16* V9_h1_ptr = &m_uint16_V9[x_int * 128 + x_int + y_int];
1748 if (x + y < 1)
1749 {
1750 if (x > y)
1751 {
1752 // 1 triangle (h1, h2, h5 points)
1753 int32 h1 = V9_h1_ptr[ 0];
1754 int32 h2 = V9_h1_ptr[129];
1755 int32 h5 = 2 * m_uint16_V8[x_int * 128 + y_int];
1756 a = h2 - h1;
1757 b = h5 - h1 - h2;
1758 c = h1;
1759 }
1760 else
1761 {
1762 // 2 triangle (h1, h3, h5 points)
1763 int32 h1 = V9_h1_ptr[0];
1764 int32 h3 = V9_h1_ptr[1];
1765 int32 h5 = 2 * m_uint16_V8[x_int * 128 + y_int];
1766 a = h5 - h1 - h3;
1767 b = h3 - h1;
1768 c = h1;
1769 }
1770 }
1771 else
1772 {
1773 if (x > y)
1774 {
1775 // 3 triangle (h2, h4, h5 points)
1776 int32 h2 = V9_h1_ptr[129];
1777 int32 h4 = V9_h1_ptr[130];
1778 int32 h5 = 2 * m_uint16_V8[x_int * 128 + y_int];
1779 a = h2 + h4 - h5;
1780 b = h4 - h2;
1781 c = h5 - h4;
1782 }
1783 else
1784 {
1785 // 4 triangle (h3, h4, h5 points)
1786 int32 h3 = V9_h1_ptr[ 1];
1787 int32 h4 = V9_h1_ptr[130];
1788 int32 h5 = 2 * m_uint16_V8[x_int * 128 + y_int];
1789 a = h4 - h3;
1790 b = h3 + h4 - h5;
1791 c = h5 - h4;
1792 }
1793 }
1794 // Calculate height
1795 return (float)((a * x) + (b * y) + c) * _gridIntHeightMultiplier + _gridHeight;
1796}
std::int32_t int32
Definition: Define.h:103
std::uint16_t uint16
Definition: Define.h:108
uint16 * m_uint16_V8
Definition: Map.h:211
uint16 * m_uint16_V9
Definition: Map.h:205

References _gridHeight, _gridIntHeightMultiplier, INVALID_HEIGHT, isHole(), m_uint16_V8, m_uint16_V9, MAP_RESOLUTION, and SIZE_OF_GRIDS.

Referenced by loadHeightData().

◆ getHeightFromUint8()

float GridMap::getHeightFromUint8 ( float  x,
float  y 
) const
private
1659{
1660 if (!m_uint8_V8 || !m_uint8_V9)
1661 return _gridHeight;
1662
1663 x = MAP_RESOLUTION * (32 - x / SIZE_OF_GRIDS);
1664 y = MAP_RESOLUTION * (32 - y / SIZE_OF_GRIDS);
1665
1666 int x_int = (int)x;
1667 int y_int = (int)y;
1668 x -= x_int;
1669 y -= y_int;
1670 x_int &= (MAP_RESOLUTION - 1);
1671 y_int &= (MAP_RESOLUTION - 1);
1672
1673 if (isHole(x_int, y_int))
1674 return INVALID_HEIGHT;
1675
1676 int32 a, b, c;
1677 uint8* V9_h1_ptr = &m_uint8_V9[x_int * 128 + x_int + y_int];
1678 if (x + y < 1)
1679 {
1680 if (x > y)
1681 {
1682 // 1 triangle (h1, h2, h5 points)
1683 int32 h1 = V9_h1_ptr[ 0];
1684 int32 h2 = V9_h1_ptr[129];
1685 int32 h5 = 2 * m_uint8_V8[x_int * 128 + y_int];
1686 a = h2 - h1;
1687 b = h5 - h1 - h2;
1688 c = h1;
1689 }
1690 else
1691 {
1692 // 2 triangle (h1, h3, h5 points)
1693 int32 h1 = V9_h1_ptr[0];
1694 int32 h3 = V9_h1_ptr[1];
1695 int32 h5 = 2 * m_uint8_V8[x_int * 128 + y_int];
1696 a = h5 - h1 - h3;
1697 b = h3 - h1;
1698 c = h1;
1699 }
1700 }
1701 else
1702 {
1703 if (x > y)
1704 {
1705 // 3 triangle (h2, h4, h5 points)
1706 int32 h2 = V9_h1_ptr[129];
1707 int32 h4 = V9_h1_ptr[130];
1708 int32 h5 = 2 * m_uint8_V8[x_int * 128 + y_int];
1709 a = h2 + h4 - h5;
1710 b = h4 - h2;
1711 c = h5 - h4;
1712 }
1713 else
1714 {
1715 // 4 triangle (h3, h4, h5 points)
1716 int32 h3 = V9_h1_ptr[ 1];
1717 int32 h4 = V9_h1_ptr[130];
1718 int32 h5 = 2 * m_uint8_V8[x_int * 128 + y_int];
1719 a = h4 - h3;
1720 b = h3 + h4 - h5;
1721 c = h5 - h4;
1722 }
1723 }
1724 // Calculate height
1725 return (float)((a * x) + (b * y) + c) * _gridIntHeightMultiplier + _gridHeight;
1726}
std::uint8_t uint8
Definition: Define.h:109
uint8 * m_uint8_V8
Definition: Map.h:212
uint8 * m_uint8_V9
Definition: Map.h:206

References _gridHeight, _gridIntHeightMultiplier, INVALID_HEIGHT, isHole(), m_uint8_V8, m_uint8_V9, MAP_RESOLUTION, and SIZE_OF_GRIDS.

Referenced by loadHeightData().

◆ GetLiquidData()

LiquidData const GridMap::GetLiquidData ( float  x,
float  y,
float  z,
float  collisionHeight,
uint8  ReqLiquidType 
) const
inline
1894{
1895 LiquidData liquidData;
1896
1897 // Check water type (if no water return)
1899 {
1900 // Get cell
1901 float cx = MAP_RESOLUTION * (32 - x / SIZE_OF_GRIDS);
1902 float cy = MAP_RESOLUTION * (32 - y / SIZE_OF_GRIDS);
1903
1904 int x_int = (int) cx & (MAP_RESOLUTION - 1);
1905 int y_int = (int) cy & (MAP_RESOLUTION - 1);
1906
1907 // Check water type in cell
1908 int idx=(x_int>>3)*16 + (y_int>>3);
1911 if (LiquidTypeEntry const* liquidEntry = sLiquidTypeStore.LookupEntry(entry))
1912 {
1914 uint32 liqTypeIdx = liquidEntry->Type;
1915 if (entry < 21)
1916 {
1917 if (AreaTableEntry const* area = sAreaTableStore.LookupEntry(getArea(x, y)))
1918 {
1919 uint32 overrideLiquid = area->LiquidTypeOverride[liquidEntry->Type];
1920 if (!overrideLiquid && area->zone)
1921 {
1922 area = sAreaTableStore.LookupEntry(area->zone);
1923 if (area)
1924 overrideLiquid = area->LiquidTypeOverride[liquidEntry->Type];
1925 }
1926
1927 if (LiquidTypeEntry const* liq = sLiquidTypeStore.LookupEntry(overrideLiquid))
1928 {
1929 entry = overrideLiquid;
1930 liqTypeIdx = liq->Type;
1931 }
1932 }
1933 }
1934
1935 type |= 1 << liqTypeIdx;
1936 }
1937
1938 // Check req liquid type mask
1939 if (type != 0 && (!ReqLiquidType || (ReqLiquidType & type) != 0))
1940 {
1941 // Check water level:
1942 // Check water height map
1943 int lx_int = x_int - _liquidOffY;
1944 int ly_int = y_int - _liquidOffX;
1945 if (lx_int >= 0 && lx_int < _liquidHeight && ly_int >= 0 && ly_int < _liquidWidth)
1946 {
1947 // Get water level
1948 float liquid_level = _liquidMap ? _liquidMap[lx_int * _liquidWidth + ly_int] : _liquidLevel;
1949 // Get ground level
1950 float ground_level = getHeight(x, y);
1951
1952 // Check water level and ground level (sub 0.2 for fix some errors)
1953 if (liquid_level >= ground_level && z >= ground_level - 0.2f)
1954 {
1955 // All ok in water -> store data
1956 liquidData.Entry = entry;
1957 liquidData.Flags = type;
1958 liquidData.Level = liquid_level;
1959 liquidData.DepthLevel = ground_level;
1960
1961 // For speed check as int values
1962 float delta = liquid_level - z;
1963
1964 if (delta > collisionHeight)
1965 liquidData.Status = LIQUID_MAP_UNDER_WATER;
1966 else if (delta > 0.0f)
1967 liquidData.Status = LIQUID_MAP_IN_WATER;
1968 else if (delta > -0.1f)
1969 liquidData.Status = LIQUID_MAP_WATER_WALK;
1970 else
1971 liquidData.Status = LIQUID_MAP_ABOVE_WATER;
1972 }
1973 }
1974 }
1975 }
1976
1977 return liquidData;
1978}
std::uint32_t uint32
Definition: Define.h:107
@ LIQUID_MAP_UNDER_WATER
Definition: Map.h:146
@ LIQUID_MAP_IN_WATER
Definition: Map.h:145
@ LIQUID_MAP_ABOVE_WATER
Definition: Map.h:143
@ LIQUID_MAP_WATER_WALK
Definition: Map.h:144
#define MAP_LIQUID_TYPE_DARK_WATER
Definition: Map.h:160
DBCStorage< AreaTableEntry > sAreaTableStore(AreaTableEntryfmt)
DBCStorage< LiquidTypeEntry > sLiquidTypeStore(LiquidTypefmt)
Definition: Map.h:169
float Level
Definition: Map.h:174
uint32 Flags
Definition: Map.h:173
uint32 Entry
Definition: Map.h:172
LiquidStatus Status
Definition: Map.h:176
float DepthLevel
Definition: Map.h:175
uint16 getArea(float x, float y) const
Definition: Map.cpp:1556
float getHeight(float x, float y) const
Definition: Map.h:258
Definition: DBCStructure.h:518
Definition: DBCStructure.h:1282

References _liquidEntry, _liquidFlags, _liquidGlobalEntry, _liquidGlobalFlags, _liquidLevel, _liquidMap, _liquidOffX, _liquidOffY, _liquidWidth, LiquidData::DepthLevel, LiquidData::Entry, LiquidData::Flags, getArea(), getHeight(), LiquidData::Level, LIQUID_MAP_ABOVE_WATER, LIQUID_MAP_IN_WATER, LIQUID_MAP_UNDER_WATER, LIQUID_MAP_WATER_WALK, MAP_LIQUID_TYPE_DARK_WATER, MAP_RESOLUTION, sAreaTableStore, SIZE_OF_GRIDS, sLiquidTypeStore, and LiquidData::Status.

Referenced by Map::GetFullTerrainStatusForPosition().

◆ getLiquidLevel()

float GridMap::getLiquidLevel ( float  x,
float  y 
) const
1874{
1875 if (!_liquidMap)
1876 return _liquidLevel;
1877
1878 x = MAP_RESOLUTION * (32 - x / SIZE_OF_GRIDS);
1879 y = MAP_RESOLUTION * (32 - y / SIZE_OF_GRIDS);
1880
1881 int cx_int = ((int)x & (MAP_RESOLUTION - 1)) - _liquidOffY;
1882 int cy_int = ((int)y & (MAP_RESOLUTION - 1)) - _liquidOffX;
1883
1884 if (cx_int < 0 || cx_int >= _liquidHeight)
1885 return INVALID_HEIGHT;
1886 if (cy_int < 0 || cy_int >= _liquidWidth)
1887 return INVALID_HEIGHT;
1888
1889 return _liquidMap[cx_int * _liquidWidth + cy_int];
1890}

References _liquidHeight, _liquidLevel, _liquidMap, _liquidOffX, _liquidOffY, _liquidWidth, INVALID_HEIGHT, MAP_RESOLUTION, and SIZE_OF_GRIDS.

◆ getMinHeight()

float GridMap::getMinHeight ( float  x,
float  y 
) const
1814{
1815 if (!_minHeight)
1816 return -500.0f;
1817
1818 static uint32 const indices[] =
1819 {
1820 3, 0, 4,
1821 0, 1, 4,
1822 1, 2, 4,
1823 2, 5, 4,
1824 5, 8, 4,
1825 8, 7, 4,
1826 7, 6, 4,
1827 6, 3, 4
1828 };
1829
1830 static float const boundGridCoords[] =
1831 {
1832 0.0f, 0.0f,
1833 0.0f, -266.66666f,
1834 0.0f, -533.33331f,
1835 -266.66666f, 0.0f,
1836 -266.66666f, -266.66666f,
1837 -266.66666f, -533.33331f,
1838 -533.33331f, 0.0f,
1839 -533.33331f, -266.66666f,
1840 -533.33331f, -533.33331f
1841 };
1842
1843 Cell cell(x, y);
1844 float gx = x - (int32(cell.GridX()) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS;
1845 float gy = y - (int32(cell.GridY()) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS;
1846
1847 uint32 quarterIndex = 0;
1848 if (cell.CellY() < MAX_NUMBER_OF_CELLS / 2)
1849 {
1850 if (cell.CellX() < MAX_NUMBER_OF_CELLS / 2)
1851 {
1852 quarterIndex = 4 + (gy > gx);
1853 }
1854 else
1855 quarterIndex = 2 + ((-SIZE_OF_GRIDS - gx) > gy);
1856 }
1857 else if (cell.CellX() < MAX_NUMBER_OF_CELLS / 2)
1858 {
1859 quarterIndex = 6 + ((-SIZE_OF_GRIDS - gx) <= gy);
1860 }
1861 else
1862 quarterIndex = gx > gy;
1863
1864 quarterIndex *= 3;
1865
1866 return G3D::Plane(
1867 G3D::Vector3(boundGridCoords[indices[quarterIndex + 0] * 2 + 0], boundGridCoords[indices[quarterIndex + 0] * 2 + 1], _minHeight[indices[quarterIndex + 0]]),
1868 G3D::Vector3(boundGridCoords[indices[quarterIndex + 1] * 2 + 0], boundGridCoords[indices[quarterIndex + 1] * 2 + 1], _minHeight[indices[quarterIndex + 1]]),
1869 G3D::Vector3(boundGridCoords[indices[quarterIndex + 2] * 2 + 0], boundGridCoords[indices[quarterIndex + 2] * 2 + 1], _minHeight[indices[quarterIndex + 2]])
1870 ).distance(G3D::Vector3(gx, gy, 0.0f));
1871}
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:34
#define CENTER_GRID_ID
Definition: GridDefines.h:36
Definition: Cell.h:45

References _minHeight, Cell::CellX(), Cell::CellY(), CENTER_GRID_ID, Cell::GridX(), Cell::GridY(), MAX_NUMBER_OF_CELLS, and SIZE_OF_GRIDS.

◆ isHole()

bool GridMap::isHole ( int  row,
int  col 
) const
private
1799{
1800 if (!_holes)
1801 return false;
1802
1803 int cellRow = row / 8; // 8 squares per cell
1804 int cellCol = col / 8;
1805 int holeRow = row % 8 / 2;
1806 int holeCol = (col - (cellCol * 8)) / 2;
1807
1808 uint16 hole = _holes[cellRow * 16 + cellCol];
1809
1810 return (hole & holetab_h[holeCol] & holetab_v[holeRow]) != 0;
1811}
static uint16 const holetab_h[4]
Definition: Map.cpp:59
static uint16 const holetab_v[4]
Definition: Map.cpp:60

References _holes, holetab_h, and holetab_v.

Referenced by getHeightFromFloat(), getHeightFromUint16(), and getHeightFromUint8().

◆ loadAreaData()

bool GridMap::loadAreaData ( FILE *  in,
uint32  offset,
uint32  size 
)
private
1436{
1437 map_areaHeader header;
1438 fseek(in, offset, SEEK_SET);
1439
1440 if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != MapAreaMagic.asUInt)
1441 return false;
1442
1443 _gridArea = header.gridArea;
1444 if (!(header.flags & MAP_AREA_NO_AREA))
1445 {
1446 _areaMap = new uint16 [16 * 16];
1447 if (fread(_areaMap, sizeof(uint16), 16 * 16, in) != 16 * 16)
1448 return false;
1449 }
1450 return true;
1451}
#define MAP_AREA_NO_AREA
Definition: Map.h:102
u_map_magic MapAreaMagic
Definition: Map.cpp:55
uint32 asUInt
Definition: Map.cpp:50
Definition: Map.h:105
uint32 fourcc
Definition: Map.h:106
uint16 gridArea
Definition: Map.h:108
uint16 flags
Definition: Map.h:107

References _areaMap, _gridArea, u_map_magic::asUInt, map_areaHeader::flags, map_areaHeader::fourcc, map_areaHeader::gridArea, MAP_AREA_NO_AREA, and MapAreaMagic.

Referenced by loadData().

◆ loadData()

bool GridMap::loadData ( char *  filaname)
1358{
1359 // Unload old data if exist
1360 unloadData();
1361
1362 map_fileheader header;
1363 // Not return error if file not found
1364 FILE* in = fopen(filename, "rb");
1365 if (!in)
1366 return true;
1367
1368 if (fread(&header, sizeof(header), 1, in) != 1)
1369 {
1370 fclose(in);
1371 return false;
1372 }
1373
1374 if (header.mapMagic == MapMagic.asUInt && header.versionMagic == MapVersionMagic)
1375 {
1376 // loadup area data
1377 if (header.areaMapOffset && !loadAreaData(in, header.areaMapOffset, header.areaMapSize))
1378 {
1379 LOG_ERROR("maps", "Error loading map area data\n");
1380 fclose(in);
1381 return false;
1382 }
1383 // loadup height data
1384 if (header.heightMapOffset && !loadHeightData(in, header.heightMapOffset, header.heightMapSize))
1385 {
1386 LOG_ERROR("maps", "Error loading map height data\n");
1387 fclose(in);
1388 return false;
1389 }
1390 // loadup liquid data
1391 if (header.liquidMapOffset && !loadLiquidData(in, header.liquidMapOffset, header.liquidMapSize))
1392 {
1393 LOG_ERROR("maps", "Error loading map liquids data\n");
1394 fclose(in);
1395 return false;
1396 }
1397 // loadup holes data (if any. check header.holesOffset)
1398 if (header.holesSize && !loadHolesData(in, header.holesOffset, header.holesSize))
1399 {
1400 LOG_ERROR("maps", "Error loading map holes data\n");
1401 fclose(in);
1402 return false;
1403 }
1404 fclose(in);
1405 return true;
1406 }
1407 LOG_ERROR("maps", "Map file '{}' is from an incompatible clientversion. Please recreate using the mapextractor.", filename);
1408 fclose(in);
1409 return false;
1410}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
uint32 MapVersionMagic
Definition: Map.cpp:54
u_map_magic MapMagic
Definition: Map.cpp:53
Definition: Map.h:88
uint32 mapMagic
Definition: Map.h:89
uint32 holesSize
Definition: Map.h:99
uint32 liquidMapSize
Definition: Map.h:97
uint32 areaMapOffset
Definition: Map.h:92
uint32 heightMapSize
Definition: Map.h:95
uint32 heightMapOffset
Definition: Map.h:94
uint32 holesOffset
Definition: Map.h:98
uint32 versionMagic
Definition: Map.h:90
uint32 liquidMapOffset
Definition: Map.h:96
uint32 areaMapSize
Definition: Map.h:93
bool loadAreaData(FILE *in, uint32 offset, uint32 size)
Definition: Map.cpp:1435
bool loadHolesData(FILE *in, uint32 offset, uint32 size)
Definition: Map.cpp:1544
bool loadHeightData(FILE *in, uint32 offset, uint32 size)
Definition: Map.cpp:1453
bool loadLiquidData(FILE *in, uint32 offset, uint32 size)
Definition: Map.cpp:1509

References map_fileheader::areaMapOffset, map_fileheader::areaMapSize, u_map_magic::asUInt, map_fileheader::heightMapOffset, map_fileheader::heightMapSize, map_fileheader::holesOffset, map_fileheader::holesSize, map_fileheader::liquidMapOffset, map_fileheader::liquidMapSize, loadAreaData(), loadHeightData(), loadHolesData(), loadLiquidData(), LOG_ERROR, MapMagic, map_fileheader::mapMagic, MapVersionMagic, unloadData(), and map_fileheader::versionMagic.

◆ loadHeightData()

bool GridMap::loadHeightData ( FILE *  in,
uint32  offset,
uint32  size 
)
private
1454{
1455 map_heightHeader header;
1456 fseek(in, offset, SEEK_SET);
1457
1458 if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != MapHeightMagic.asUInt)
1459 return false;
1460
1461 _gridHeight = header.gridHeight;
1462 if (!(header.flags & MAP_HEIGHT_NO_HEIGHT))
1463 {
1464 if ((header.flags & MAP_HEIGHT_AS_INT16))
1465 {
1466 m_uint16_V9 = new uint16 [129 * 129];
1467 m_uint16_V8 = new uint16 [128 * 128];
1468 if (fread(m_uint16_V9, sizeof(uint16), 129 * 129, in) != 129 * 129 ||
1469 fread(m_uint16_V8, sizeof(uint16), 128 * 128, in) != 128 * 128)
1470 return false;
1471 _gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 65535;
1473 }
1474 else if ((header.flags & MAP_HEIGHT_AS_INT8))
1475 {
1476 m_uint8_V9 = new uint8 [129 * 129];
1477 m_uint8_V8 = new uint8 [128 * 128];
1478 if (fread(m_uint8_V9, sizeof(uint8), 129 * 129, in) != 129 * 129 ||
1479 fread(m_uint8_V8, sizeof(uint8), 128 * 128, in) != 128 * 128)
1480 return false;
1481 _gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 255;
1483 }
1484 else
1485 {
1486 m_V9 = new float [129 * 129];
1487 m_V8 = new float [128 * 128];
1488 if (fread(m_V9, sizeof(float), 129 * 129, in) != 129 * 129 ||
1489 fread(m_V8, sizeof(float), 128 * 128, in) != 128 * 128)
1490 return false;
1492 }
1493 }
1494 else
1496
1498 {
1499 _maxHeight = new int16[3 * 3];
1500 _minHeight = new int16[3 * 3];
1501 if (fread(_maxHeight, sizeof(int16), 3 * 3, in) != 3 * 3 ||
1502 fread(_minHeight, sizeof(int16), 3 * 3, in) != 3 * 3)
1503 return false;
1504 }
1505
1506 return true;
1507}
std::int16_t int16
Definition: Define.h:104
#define MAP_HEIGHT_HAS_FLIGHT_BOUNDS
Definition: Map.h:114
#define MAP_HEIGHT_AS_INT8
Definition: Map.h:113
#define MAP_HEIGHT_NO_HEIGHT
Definition: Map.h:111
#define MAP_HEIGHT_AS_INT16
Definition: Map.h:112
u_map_magic MapHeightMagic
Definition: Map.cpp:56
Definition: Map.h:117
float gridMaxHeight
Definition: Map.h:121
uint32 flags
Definition: Map.h:119
float gridHeight
Definition: Map.h:120
uint32 fourcc
Definition: Map.h:118
float getHeightFromFloat(float x, float y) const
Definition: Map.cpp:1573
float getHeightFromUint16(float x, float y) const
Definition: Map.cpp:1728
float getHeightFromUint8(float x, float y) const
Definition: Map.cpp:1658

References _gridGetHeight, _gridHeight, _gridIntHeightMultiplier, _maxHeight, _minHeight, u_map_magic::asUInt, map_heightHeader::flags, map_heightHeader::fourcc, getHeightFromFlat(), getHeightFromFloat(), getHeightFromUint16(), getHeightFromUint8(), map_heightHeader::gridHeight, map_heightHeader::gridMaxHeight, m_uint16_V8, m_uint16_V9, m_uint8_V8, m_uint8_V9, m_V8, m_V9, MAP_HEIGHT_AS_INT16, MAP_HEIGHT_AS_INT8, MAP_HEIGHT_HAS_FLIGHT_BOUNDS, MAP_HEIGHT_NO_HEIGHT, and MapHeightMagic.

Referenced by loadData().

◆ loadHolesData()

bool GridMap::loadHolesData ( FILE *  in,
uint32  offset,
uint32  size 
)
private
1545{
1546 if (fseek(in, offset, SEEK_SET) != 0)
1547 return false;
1548
1549 _holes = new uint16[16 * 16];
1550 if (fread(_holes, sizeof(uint16), 16 * 16, in) != 16 * 16)
1551 return false;
1552
1553 return true;
1554}

References _holes.

Referenced by loadData().

◆ loadLiquidData()

bool GridMap::loadLiquidData ( FILE *  in,
uint32  offset,
uint32  size 
)
private
1510{
1511 map_liquidHeader header;
1512 fseek(in, offset, SEEK_SET);
1513
1514 if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != MapLiquidMagic.asUInt)
1515 return false;
1516
1519 _liquidOffX = header.offsetX;
1520 _liquidOffY = header.offsetY;
1521 _liquidWidth = header.width;
1522 _liquidHeight = header.height;
1523 _liquidLevel = header.liquidLevel;
1524
1525 if (!(header.flags & MAP_LIQUID_NO_TYPE))
1526 {
1527 _liquidEntry = new uint16[16 * 16];
1528 if (fread(_liquidEntry, sizeof(uint16), 16 * 16, in) != 16 * 16)
1529 return false;
1530
1531 _liquidFlags = new uint8[16 * 16];
1532 if (fread(_liquidFlags, sizeof(uint8), 16 * 16, in) != 16 * 16)
1533 return false;
1534 }
1535 if (!(header.flags & MAP_LIQUID_NO_HEIGHT))
1536 {
1538 if (fread(_liquidMap, sizeof(float), _liquidWidth * _liquidHeight, in) != (uint32(_liquidWidth) * uint32(_liquidHeight)))
1539 return false;
1540 }
1541 return true;
1542}
#define MAP_LIQUID_NO_TYPE
Definition: Map.h:124
#define MAP_LIQUID_NO_HEIGHT
Definition: Map.h:125
u_map_magic MapLiquidMagic
Definition: Map.cpp:57
Definition: Map.h:128
uint8 offsetX
Definition: Map.h:133
uint32 fourcc
Definition: Map.h:129
uint8 liquidFlags
Definition: Map.h:131
uint8 width
Definition: Map.h:135
uint8 height
Definition: Map.h:136
uint8 flags
Definition: Map.h:130
uint16 liquidType
Definition: Map.h:132
uint8 offsetY
Definition: Map.h:134
float liquidLevel
Definition: Map.h:137

References _liquidEntry, _liquidFlags, _liquidGlobalEntry, _liquidGlobalFlags, _liquidHeight, _liquidLevel, _liquidMap, _liquidOffX, _liquidOffY, _liquidWidth, u_map_magic::asUInt, map_liquidHeader::flags, map_liquidHeader::fourcc, map_liquidHeader::height, map_liquidHeader::liquidFlags, map_liquidHeader::liquidLevel, map_liquidHeader::liquidType, MAP_LIQUID_NO_HEIGHT, MAP_LIQUID_NO_TYPE, MapLiquidMagic, map_liquidHeader::offsetX, map_liquidHeader::offsetY, and map_liquidHeader::width.

Referenced by loadData().

◆ unloadData()

void GridMap::unloadData ( )
1413{
1414 delete[] _areaMap;
1415 delete[] m_V9;
1416 delete[] m_V8;
1417 delete[] _maxHeight;
1418 delete[] _minHeight;
1419 delete[] _liquidEntry;
1420 delete[] _liquidFlags;
1421 delete[] _liquidMap;
1422 delete[] _holes;
1423 _areaMap = nullptr;
1424 m_V9 = nullptr;
1425 m_V8 = nullptr;
1426 _maxHeight = nullptr;
1427 _minHeight = nullptr;
1428 _liquidEntry = nullptr;
1429 _liquidFlags = nullptr;
1430 _liquidMap = nullptr;
1431 _holes = nullptr;
1433}

References _areaMap, _gridGetHeight, _holes, _liquidEntry, _liquidFlags, _liquidMap, _maxHeight, _minHeight, getHeightFromFlat(), m_V8, and m_V9.

Referenced by loadData(), Map::UnloadGrid(), and ~GridMap().

Member Data Documentation

◆ 

union { ... } GridMap::@295

◆ 

union { ... } GridMap::@297

◆ _areaMap

uint16* GridMap::_areaMap
private

◆ _flags

uint32 GridMap::_flags
private

Referenced by GridMap().

◆ _gridArea

uint16 GridMap::_gridArea
private

Referenced by getArea(), GridMap(), and loadAreaData().

◆ _gridGetHeight

GetHeightPtr GridMap::_gridGetHeight
private

Referenced by GridMap(), loadHeightData(), and unloadData().

◆ _gridHeight

◆ _gridIntHeightMultiplier

float GridMap::_gridIntHeightMultiplier
private

◆ _holes

uint16* GridMap::_holes
private

◆ _liquidEntry

uint16* GridMap::_liquidEntry
private

◆ _liquidFlags

uint8* GridMap::_liquidFlags
private

◆ _liquidGlobalEntry

uint16 GridMap::_liquidGlobalEntry
private

◆ _liquidGlobalFlags

uint8 GridMap::_liquidGlobalFlags
private

◆ _liquidHeight

uint8 GridMap::_liquidHeight
private

◆ _liquidLevel

float GridMap::_liquidLevel
private

◆ _liquidMap

float* GridMap::_liquidMap
private

◆ _liquidOffX

uint8 GridMap::_liquidOffX
private

◆ _liquidOffY

uint8 GridMap::_liquidOffY
private

◆ _liquidWidth

uint8 GridMap::_liquidWidth
private

◆ _maxHeight

int16* GridMap::_maxHeight
private

Referenced by GridMap(), loadHeightData(), and unloadData().

◆ _minHeight

int16* GridMap::_minHeight
private

◆ m_uint16_V8

uint16* GridMap::m_uint16_V8

◆ m_uint16_V9

uint16* GridMap::m_uint16_V9

◆ m_uint8_V8

uint8* GridMap::m_uint8_V8

◆ m_uint8_V9

uint8* GridMap::m_uint8_V9

◆ m_V8

float* GridMap::m_V8

◆ m_V9

float* GridMap::m_V9