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 ( )
1322{
1323 _flags = 0;
1324 // Area data
1325 _gridArea = 0;
1326 _areaMap = nullptr;
1327 // Height level data
1331 m_V9 = nullptr;
1332 m_V8 = nullptr;
1333 _maxHeight = nullptr;
1334 _minHeight = nullptr;
1335 // Liquid data
1338 _liquidOffX = 0;
1339 _liquidOffY = 0;
1340 _liquidWidth = 0;
1341 _liquidHeight = 0;
1343 _liquidEntry = nullptr;
1344 _liquidFlags = nullptr;
1345 _liquidMap = nullptr;
1346 _holes = nullptr;
1347}
#define INVALID_HEIGHT
Definition: Map.h:165
int16 * _minHeight
Definition: Map.h:217
float getHeightFromFlat(float x, float y) const
Definition: Map.cpp:1565
float _liquidLevel
Definition: Map.h:226
uint16 * _liquidEntry
Definition: Map.h:227
uint8 _liquidGlobalFlags
Definition: Map.h:232
uint8 _liquidOffY
Definition: Map.h:234
uint16 _liquidGlobalEntry
Definition: Map.h:231
uint8 _liquidOffX
Definition: Map.h:233
float * _liquidMap
Definition: Map.h:229
uint32 _flags
Definition: Map.h:203
uint8 _liquidHeight
Definition: Map.h:236
int16 * _maxHeight
Definition: Map.h:216
uint16 * _areaMap
Definition: Map.h:223
float _gridIntHeightMultiplier
Definition: Map.h:220
uint8 _liquidWidth
Definition: Map.h:235
uint8 * _liquidFlags
Definition: Map.h:228
float * m_V9
Definition: Map.h:206
uint16 _gridArea
Definition: Map.h:230
float _gridHeight
Definition: Map.h:219
GetHeightPtr _gridGetHeight
Definition: Map.h:247
uint16 * _holes
Definition: Map.h:237
float * m_V8
Definition: Map.h:212

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 ( )
1350{
1351 unloadData();
1352}
void unloadData()
Definition: Map.cpp:1409

References unloadData().

Member Function Documentation

◆ getArea()

uint16 GridMap::getArea ( float  x,
float  y 
) const
1554{
1555 if (!_areaMap)
1556 return _gridArea;
1557
1558 x = 16 * (32 - x / SIZE_OF_GRIDS);
1559 y = 16 * (32 - y / SIZE_OF_GRIDS);
1560 int lx = (int)x & 15;
1561 int ly = (int)y & 15;
1562 return _areaMap[lx * 16 + ly];
1563}
#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
260{return (this->*_gridGetHeight)(x, y);}

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

◆ getHeightFromFlat()

float GridMap::getHeightFromFlat ( float  x,
float  y 
) const
private
1566{
1567 return _gridHeight;
1568}

References _gridHeight.

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

◆ getHeightFromFloat()

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

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

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

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

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
1871{
1872 if (!_liquidMap)
1873 return _liquidLevel;
1874
1875 x = MAP_RESOLUTION * (32 - x / SIZE_OF_GRIDS);
1876 y = MAP_RESOLUTION * (32 - y / SIZE_OF_GRIDS);
1877
1878 int cx_int = ((int)x & (MAP_RESOLUTION - 1)) - _liquidOffY;
1879 int cy_int = ((int)y & (MAP_RESOLUTION - 1)) - _liquidOffX;
1880
1881 if (cx_int < 0 || cx_int >= _liquidHeight)
1882 return INVALID_HEIGHT;
1883 if (cy_int < 0 || cy_int >= _liquidWidth)
1884 return INVALID_HEIGHT;
1885
1886 return _liquidMap[cx_int * _liquidWidth + cy_int];
1887}

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

◆ getMinHeight()

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

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
1796{
1797 if (!_holes)
1798 return false;
1799
1800 int cellRow = row / 8; // 8 squares per cell
1801 int cellCol = col / 8;
1802 int holeRow = row % 8 / 2;
1803 int holeCol = (col - (cellCol * 8)) / 2;
1804
1805 uint16 hole = _holes[cellRow * 16 + cellCol];
1806
1807 return (hole & holetab_h[holeCol] & holetab_v[holeRow]) != 0;
1808}
static uint16 const holetab_h[4]
Definition: Map.cpp:56
static uint16 const holetab_v[4]
Definition: Map.cpp:57

References _holes, holetab_h, and holetab_v.

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

◆ loadAreaData()

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

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

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
1451{
1452 map_heightHeader header;
1453 fseek(in, offset, SEEK_SET);
1454
1455 if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != MapHeightMagic.asUInt)
1456 return false;
1457
1458 _gridHeight = header.gridHeight;
1459 if (!(header.flags & MAP_HEIGHT_NO_HEIGHT))
1460 {
1461 if ((header.flags & MAP_HEIGHT_AS_INT16))
1462 {
1463 m_uint16_V9 = new uint16 [129 * 129];
1464 m_uint16_V8 = new uint16 [128 * 128];
1465 if (fread(m_uint16_V9, sizeof(uint16), 129 * 129, in) != 129 * 129 ||
1466 fread(m_uint16_V8, sizeof(uint16), 128 * 128, in) != 128 * 128)
1467 return false;
1468 _gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 65535;
1470 }
1471 else if ((header.flags & MAP_HEIGHT_AS_INT8))
1472 {
1473 m_uint8_V9 = new uint8 [129 * 129];
1474 m_uint8_V8 = new uint8 [128 * 128];
1475 if (fread(m_uint8_V9, sizeof(uint8), 129 * 129, in) != 129 * 129 ||
1476 fread(m_uint8_V8, sizeof(uint8), 128 * 128, in) != 128 * 128)
1477 return false;
1478 _gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 255;
1480 }
1481 else
1482 {
1483 m_V9 = new float [129 * 129];
1484 m_V8 = new float [128 * 128];
1485 if (fread(m_V9, sizeof(float), 129 * 129, in) != 129 * 129 ||
1486 fread(m_V8, sizeof(float), 128 * 128, in) != 128 * 128)
1487 return false;
1489 }
1490 }
1491 else
1493
1495 {
1496 _maxHeight = new int16[3 * 3];
1497 _minHeight = new int16[3 * 3];
1498 if (fread(_maxHeight, sizeof(int16), 3 * 3, in) != 3 * 3 ||
1499 fread(_minHeight, sizeof(int16), 3 * 3, in) != 3 * 3)
1500 return false;
1501 }
1502
1503 return true;
1504}
std::int16_t int16
Definition: Define.h:104
#define MAP_HEIGHT_HAS_FLIGHT_BOUNDS
Definition: Map.h:116
#define MAP_HEIGHT_AS_INT8
Definition: Map.h:115
#define MAP_HEIGHT_NO_HEIGHT
Definition: Map.h:113
#define MAP_HEIGHT_AS_INT16
Definition: Map.h:114
u_map_magic MapHeightMagic
Definition: Map.cpp:53
Definition: Map.h:119
float gridMaxHeight
Definition: Map.h:123
uint32 flags
Definition: Map.h:121
float gridHeight
Definition: Map.h:122
uint32 fourcc
Definition: Map.h:120
float getHeightFromFloat(float x, float y) const
Definition: Map.cpp:1570
float getHeightFromUint16(float x, float y) const
Definition: Map.cpp:1725
float getHeightFromUint8(float x, float y) const
Definition: Map.cpp:1655

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
1542{
1543 if (fseek(in, offset, SEEK_SET) != 0)
1544 return false;
1545
1546 _holes = new uint16[16 * 16];
1547 if (fread(_holes, sizeof(uint16), 16 * 16, in) != 16 * 16)
1548 return false;
1549
1550 return true;
1551}

References _holes.

Referenced by loadData().

◆ loadLiquidData()

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

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 ( )
1410{
1411 delete[] _areaMap;
1412 delete[] m_V9;
1413 delete[] m_V8;
1414 delete[] _maxHeight;
1415 delete[] _minHeight;
1416 delete[] _liquidEntry;
1417 delete[] _liquidFlags;
1418 delete[] _liquidMap;
1419 delete[] _holes;
1420 _areaMap = nullptr;
1421 m_V9 = nullptr;
1422 m_V8 = nullptr;
1423 _maxHeight = nullptr;
1424 _minHeight = nullptr;
1425 _liquidEntry = nullptr;
1426 _liquidFlags = nullptr;
1427 _liquidMap = nullptr;
1428 _holes = nullptr;
1430}

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::@292

◆ 

union { ... } GridMap::@294

◆ _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