TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GridMap Class Reference

#include <Map.h>

Public Member Functions

 GridMap ()
 
 ~GridMap ()
 
bool loadData (const char *filename)
 
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
 
uint8 getTerrainType (float x, float y) const
 
ZLiquidStatus getLiquidStatus (float x, float y, float z, uint8 ReqLiquidType, LiquidData *data=0)
 

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)
 
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 _liquidType
 
uint8 _liquidOffX
 
uint8 _liquidOffY
 
uint8 _liquidWidth
 
uint8 _liquidHeight
 
GetHeightPtr _gridGetHeight
 

Member Typedef Documentation

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

Constructor & Destructor Documentation

GridMap::GridMap ( )
1654 {
1655  _flags = 0;
1656  // Area data
1657  _gridArea = 0;
1658  _areaMap = nullptr;
1659  // Height level data
1663  m_V9 = nullptr;
1664  m_V8 = nullptr;
1665  _maxHeight = nullptr;
1666  _minHeight = nullptr;
1667  // Liquid data
1668  _liquidType = 0;
1669  _liquidOffX = 0;
1670  _liquidOffY = 0;
1671  _liquidWidth = 0;
1672  _liquidHeight = 0;
1674  _liquidEntry = nullptr;
1675  _liquidFlags = nullptr;
1676  _liquidMap = nullptr;
1677 }
float * m_V9
Definition: Map.h:163
float _gridIntHeightMultiplier
Definition: Map.h:176
uint8 _liquidHeight
Definition: Map.h:191
uint8 _liquidOffX
Definition: Map.h:188
int16 * _minHeight
Definition: Map.h:173
uint16 _gridArea
Definition: Map.h:186
GetHeightPtr _gridGetHeight
Definition: Map.h:200
uint16 * _areaMap
Definition: Map.h:179
float * m_V8
Definition: Map.h:168
uint16 _liquidType
Definition: Map.h:187
float getHeightFromFlat(float x, float y) const
Definition: Map.cpp:1875
uint8 _liquidOffY
Definition: Map.h:189
float _gridHeight
Definition: Map.h:175
uint32 _flags
Definition: Map.h:161
float _liquidLevel
Definition: Map.h:182
#define INVALID_HEIGHT
Definition: Map.h:248
uint8 _liquidWidth
Definition: Map.h:190
uint8 * _liquidFlags
Definition: Map.h:184
uint16 * _liquidEntry
Definition: Map.h:183
float * _liquidMap
Definition: Map.h:185
int16 * _maxHeight
Definition: Map.h:172

+ Here is the call graph for this function:

GridMap::~GridMap ( )
1680 {
1681  unloadData();
1682 }
void unloadData()
Definition: Map.cpp:1734

+ Here is the call graph for this function:

Member Function Documentation

uint16 GridMap::getArea ( float  x,
float  y 
) const
1864 {
1865  if (!_areaMap)
1866  return _gridArea;
1867 
1868  x = 16 * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
1869  y = 16 * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
1870  int lx = (int)x & 15;
1871  int ly = (int)y & 15;
1872  return _areaMap[lx*16 + ly];
1873 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:39
#define CENTER_GRID_ID
Definition: GridDefines.h:40
uint16 _gridArea
Definition: Map.h:186
uint16 * _areaMap
Definition: Map.h:179
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

float GridMap::getHeight ( float  x,
float  y 
) const
inline
213 {return (this->*_gridGetHeight)(x, y);}
GetHeightPtr _gridGetHeight
Definition: Map.h:200
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

float GridMap::getHeightFromFlat ( float  x,
float  y 
) const
private
1876 {
1877  return _gridHeight;
1878 }
float _gridHeight
Definition: Map.h:175

+ Here is the caller graph for this function:

float GridMap::getHeightFromFloat ( float  x,
float  y 
) const
private
1881 {
1882  if (!m_V8 || !m_V9)
1883  return _gridHeight;
1884 
1887 
1888  int x_int = (int)x;
1889  int y_int = (int)y;
1890  x -= x_int;
1891  y -= y_int;
1892  x_int&=(MAP_RESOLUTION - 1);
1893  y_int&=(MAP_RESOLUTION - 1);
1894 
1895  // Height stored as: h5 - its v8 grid, h1-h4 - its v9 grid
1896  // +--------------> X
1897  // | h1-------h2 Coordinates is:
1898  // | | \ 1 / | h1 0, 0
1899  // | | \ / | h2 0, 1
1900  // | | 2 h5 3 | h3 1, 0
1901  // | | / \ | h4 1, 1
1902  // | | / 4 \ | h5 1/2, 1/2
1903  // | h3-------h4
1904  // V Y
1905  // For find height need
1906  // 1 - detect triangle
1907  // 2 - solve linear equation from triangle points
1908  // Calculate coefficients for solve h = a*x + b*y + c
1909 
1910  float a, b, c;
1911  // Select triangle:
1912  if (x+y < 1)
1913  {
1914  if (x > y)
1915  {
1916  // 1 triangle (h1, h2, h5 points)
1917  float h1 = m_V9[(x_int)*129 + y_int];
1918  float h2 = m_V9[(x_int+1)*129 + y_int];
1919  float h5 = 2 * m_V8[x_int*128 + y_int];
1920  a = h2-h1;
1921  b = h5-h1-h2;
1922  c = h1;
1923  }
1924  else
1925  {
1926  // 2 triangle (h1, h3, h5 points)
1927  float h1 = m_V9[x_int*129 + y_int ];
1928  float h3 = m_V9[x_int*129 + y_int+1];
1929  float h5 = 2 * m_V8[x_int*128 + y_int];
1930  a = h5 - h1 - h3;
1931  b = h3 - h1;
1932  c = h1;
1933  }
1934  }
1935  else
1936  {
1937  if (x > y)
1938  {
1939  // 3 triangle (h2, h4, h5 points)
1940  float h2 = m_V9[(x_int+1)*129 + y_int ];
1941  float h4 = m_V9[(x_int+1)*129 + y_int+1];
1942  float h5 = 2 * m_V8[x_int*128 + y_int];
1943  a = h2 + h4 - h5;
1944  b = h4 - h2;
1945  c = h5 - h4;
1946  }
1947  else
1948  {
1949  // 4 triangle (h3, h4, h5 points)
1950  float h3 = m_V9[(x_int)*129 + y_int+1];
1951  float h4 = m_V9[(x_int+1)*129 + y_int+1];
1952  float h5 = 2 * m_V8[x_int*128 + y_int];
1953  a = h4 - h3;
1954  b = h3 + h4 - h5;
1955  c = h5 - h4;
1956  }
1957  }
1958  // Calculate height
1959  return a * x + b * y + c;
1960 }
float * m_V9
Definition: Map.h:163
#define SIZE_OF_GRIDS
Definition: GridDefines.h:39
#define CENTER_GRID_ID
Definition: GridDefines.h:40
float * m_V8
Definition: Map.h:168
#define MAP_RESOLUTION
Definition: GridDefines.h:54
G3D::int16 y
Definition: Vector2int16.h:38
float _gridHeight
Definition: Map.h:175
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

float GridMap::getHeightFromUint16 ( float  x,
float  y 
) const
private
2030 {
2031  if (!m_uint16_V8 || !m_uint16_V9)
2032  return _gridHeight;
2033 
2036 
2037  int x_int = (int)x;
2038  int y_int = (int)y;
2039  x -= x_int;
2040  y -= y_int;
2041  x_int&=(MAP_RESOLUTION - 1);
2042  y_int&=(MAP_RESOLUTION - 1);
2043 
2044  int32 a, b, c;
2045  uint16 *V9_h1_ptr = &m_uint16_V9[x_int*128 + x_int + y_int];
2046  if (x+y < 1)
2047  {
2048  if (x > y)
2049  {
2050  // 1 triangle (h1, h2, h5 points)
2051  int32 h1 = V9_h1_ptr[ 0];
2052  int32 h2 = V9_h1_ptr[129];
2053  int32 h5 = 2 * m_uint16_V8[x_int*128 + y_int];
2054  a = h2-h1;
2055  b = h5-h1-h2;
2056  c = h1;
2057  }
2058  else
2059  {
2060  // 2 triangle (h1, h3, h5 points)
2061  int32 h1 = V9_h1_ptr[0];
2062  int32 h3 = V9_h1_ptr[1];
2063  int32 h5 = 2 * m_uint16_V8[x_int*128 + y_int];
2064  a = h5 - h1 - h3;
2065  b = h3 - h1;
2066  c = h1;
2067  }
2068  }
2069  else
2070  {
2071  if (x > y)
2072  {
2073  // 3 triangle (h2, h4, h5 points)
2074  int32 h2 = V9_h1_ptr[129];
2075  int32 h4 = V9_h1_ptr[130];
2076  int32 h5 = 2 * m_uint16_V8[x_int*128 + y_int];
2077  a = h2 + h4 - h5;
2078  b = h4 - h2;
2079  c = h5 - h4;
2080  }
2081  else
2082  {
2083  // 4 triangle (h3, h4, h5 points)
2084  int32 h3 = V9_h1_ptr[ 1];
2085  int32 h4 = V9_h1_ptr[130];
2086  int32 h5 = 2 * m_uint16_V8[x_int*128 + y_int];
2087  a = h4 - h3;
2088  b = h3 + h4 - h5;
2089  c = h5 - h4;
2090  }
2091  }
2092  // Calculate height
2093  return (float)((a * x) + (b * y) + c)*_gridIntHeightMultiplier + _gridHeight;
2094 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:39
float _gridIntHeightMultiplier
Definition: Map.h:176
#define CENTER_GRID_ID
Definition: GridDefines.h:40
#define MAP_RESOLUTION
Definition: GridDefines.h:54
int32_t int32
Definition: Define.h:146
G3D::int16 y
Definition: Vector2int16.h:38
uint16_t uint16
Definition: Define.h:151
float _gridHeight
Definition: Map.h:175
uint16 * m_uint16_V8
Definition: Map.h:169
uint16 * m_uint16_V9
Definition: Map.h:164
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

float GridMap::getHeightFromUint8 ( float  x,
float  y 
) const
private
1963 {
1964  if (!m_uint8_V8 || !m_uint8_V9)
1965  return _gridHeight;
1966 
1969 
1970  int x_int = (int)x;
1971  int y_int = (int)y;
1972  x -= x_int;
1973  y -= y_int;
1974  x_int&=(MAP_RESOLUTION - 1);
1975  y_int&=(MAP_RESOLUTION - 1);
1976 
1977  int32 a, b, c;
1978  uint8 *V9_h1_ptr = &m_uint8_V9[x_int*128 + x_int + y_int];
1979  if (x+y < 1)
1980  {
1981  if (x > y)
1982  {
1983  // 1 triangle (h1, h2, h5 points)
1984  int32 h1 = V9_h1_ptr[ 0];
1985  int32 h2 = V9_h1_ptr[129];
1986  int32 h5 = 2 * m_uint8_V8[x_int*128 + y_int];
1987  a = h2-h1;
1988  b = h5-h1-h2;
1989  c = h1;
1990  }
1991  else
1992  {
1993  // 2 triangle (h1, h3, h5 points)
1994  int32 h1 = V9_h1_ptr[0];
1995  int32 h3 = V9_h1_ptr[1];
1996  int32 h5 = 2 * m_uint8_V8[x_int*128 + y_int];
1997  a = h5 - h1 - h3;
1998  b = h3 - h1;
1999  c = h1;
2000  }
2001  }
2002  else
2003  {
2004  if (x > y)
2005  {
2006  // 3 triangle (h2, h4, h5 points)
2007  int32 h2 = V9_h1_ptr[129];
2008  int32 h4 = V9_h1_ptr[130];
2009  int32 h5 = 2 * m_uint8_V8[x_int*128 + y_int];
2010  a = h2 + h4 - h5;
2011  b = h4 - h2;
2012  c = h5 - h4;
2013  }
2014  else
2015  {
2016  // 4 triangle (h3, h4, h5 points)
2017  int32 h3 = V9_h1_ptr[ 1];
2018  int32 h4 = V9_h1_ptr[130];
2019  int32 h5 = 2 * m_uint8_V8[x_int*128 + y_int];
2020  a = h4 - h3;
2021  b = h3 + h4 - h5;
2022  c = h5 - h4;
2023  }
2024  }
2025  // Calculate height
2026  return (float)((a * x) + (b * y) + c)*_gridIntHeightMultiplier + _gridHeight;
2027 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:39
float _gridIntHeightMultiplier
Definition: Map.h:176
#define CENTER_GRID_ID
Definition: GridDefines.h:40
uint8 * m_uint8_V8
Definition: Map.h:170
uint8 * m_uint8_V9
Definition: Map.h:165
#define MAP_RESOLUTION
Definition: GridDefines.h:54
int32_t int32
Definition: Define.h:146
G3D::int16 y
Definition: Vector2int16.h:38
float _gridHeight
Definition: Map.h:175
uint8_t uint8
Definition: Define.h:152
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

float GridMap::getLiquidLevel ( float  x,
float  y 
) const
2157 {
2158  if (!_liquidMap)
2159  return _liquidLevel;
2160 
2163 
2164  int cx_int = ((int)x & (MAP_RESOLUTION-1)) - _liquidOffY;
2165  int cy_int = ((int)y & (MAP_RESOLUTION-1)) - _liquidOffX;
2166 
2167  if (cx_int < 0 || cx_int >=_liquidHeight)
2168  return INVALID_HEIGHT;
2169  if (cy_int < 0 || cy_int >=_liquidWidth)
2170  return INVALID_HEIGHT;
2171 
2172  return _liquidMap[cx_int*_liquidWidth + cy_int];
2173 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:39
uint8 _liquidHeight
Definition: Map.h:191
#define CENTER_GRID_ID
Definition: GridDefines.h:40
uint8 _liquidOffX
Definition: Map.h:188
#define MAP_RESOLUTION
Definition: GridDefines.h:54
uint8 _liquidOffY
Definition: Map.h:189
G3D::int16 y
Definition: Vector2int16.h:38
float _liquidLevel
Definition: Map.h:182
G3D::int16 x
Definition: Vector2int16.h:37
#define INVALID_HEIGHT
Definition: Map.h:248
uint8 _liquidWidth
Definition: Map.h:190
float * _liquidMap
Definition: Map.h:185
ZLiquidStatus GridMap::getLiquidStatus ( float  x,
float  y,
float  z,
uint8  ReqLiquidType,
LiquidData data = 0 
)
inline
2190 {
2191  // Check water type (if no water return)
2192  if (!_liquidType && !_liquidFlags)
2193  return LIQUID_MAP_NO_WATER;
2194 
2195  // Get cell
2196  float cx = MAP_RESOLUTION * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
2197  float cy = MAP_RESOLUTION * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
2198 
2199  int x_int = (int)cx & (MAP_RESOLUTION-1);
2200  int y_int = (int)cy & (MAP_RESOLUTION-1);
2201 
2202  // Check water type in cell
2203  int idx=(x_int>>3)*16 + (y_int>>3);
2204  uint8 type = _liquidFlags ? _liquidFlags[idx] : _liquidType;
2205  uint32 entry = 0;
2206  if (_liquidEntry)
2207  {
2208  if (LiquidTypeEntry const* liquidEntry = sLiquidTypeStore.LookupEntry(_liquidEntry[idx]))
2209  {
2210  entry = liquidEntry->ID;
2212  uint32 liqTypeIdx = liquidEntry->Type;
2213  if (entry < 21)
2214  {
2215  if (AreaTableEntry const* area = sAreaTableStore.LookupEntry(getArea(x, y)))
2216  {
2217  uint32 overrideLiquid = area->LiquidTypeID[liquidEntry->Type];
2218  if (!overrideLiquid && area->ParentAreaID)
2219  {
2220  area = sAreaTableStore.LookupEntry(area->ParentAreaID);
2221  if (area)
2222  overrideLiquid = area->LiquidTypeID[liquidEntry->Type];
2223  }
2224 
2225  if (LiquidTypeEntry const* liq = sLiquidTypeStore.LookupEntry(overrideLiquid))
2226  {
2227  entry = overrideLiquid;
2228  liqTypeIdx = liq->Type;
2229  }
2230  }
2231  }
2232 
2233  type |= 1 << liqTypeIdx;
2234  }
2235  }
2236 
2237  if (type == 0)
2238  return LIQUID_MAP_NO_WATER;
2239 
2240  // Check req liquid type mask
2241  if (ReqLiquidType && !(ReqLiquidType&type))
2242  return LIQUID_MAP_NO_WATER;
2243 
2244  // Check water level:
2245  // Check water height map
2246  int lx_int = x_int - _liquidOffY;
2247  int ly_int = y_int - _liquidOffX;
2248  if (lx_int < 0 || lx_int >=_liquidHeight)
2249  return LIQUID_MAP_NO_WATER;
2250  if (ly_int < 0 || ly_int >=_liquidWidth)
2251  return LIQUID_MAP_NO_WATER;
2252 
2253  // Get water level
2254  float liquid_level = _liquidMap ? _liquidMap[lx_int*_liquidWidth + ly_int] : _liquidLevel;
2255  // Get ground level (sub 0.2 for fix some errors)
2256  float ground_level = getHeight(x, y);
2257 
2258  // Check water level and ground level
2259  if (liquid_level < ground_level || z < ground_level - 2)
2260  return LIQUID_MAP_NO_WATER;
2261 
2262  // All ok in water -> store data
2263  if (data)
2264  {
2265  data->entry = entry;
2266  data->type_flags = type;
2267  data->level = liquid_level;
2268  data->depth_level = ground_level;
2269  }
2270 
2271  // For speed check as int values
2272  float delta = liquid_level - z;
2273 
2274  if (delta > 2.0f) // Under water
2275  return LIQUID_MAP_UNDER_WATER;
2276  if (delta > 0.0f) // In water
2277  return LIQUID_MAP_IN_WATER;
2278  if (delta > -0.1f) // Walk on water
2279  return LIQUID_MAP_WATER_WALK;
2280  // Above water
2281  return LIQUID_MAP_ABOVE_WATER;
2282 }
Definition: DBCStructure.h:37
DBCStorage< LiquidTypeEntry > sLiquidTypeStore(LiquidTypefmt)
Definition: Map.h:136
float depth_level
Definition: Map.h:156
#define SIZE_OF_GRIDS
Definition: GridDefines.h:39
uint16 getArea(float x, float y) const
Definition: Map.cpp:1863
uint8 _liquidHeight
Definition: Map.h:191
#define CENTER_GRID_ID
Definition: GridDefines.h:40
uint8 _liquidOffX
Definition: Map.h:188
Definition: Map.h:134
DBCStorage< AreaTableEntry > sAreaTableStore(AreaTablefmt)
#define MAP_RESOLUTION
Definition: GridDefines.h:54
Definition: DBCStructure.h:789
float getHeight(float x, float y) const
Definition: Map.h:213
uint16 _liquidType
Definition: Map.h:187
G3D::int16 z
Definition: Vector3int16.h:46
float level
Definition: Map.h:155
uint8 _liquidOffY
Definition: Map.h:189
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
Definition: Map.h:135
uint32 type_flags
Definition: Map.h:153
uint32 entry
Definition: Map.h:154
#define MAP_LIQUID_TYPE_DARK_WATER
Definition: Map.h:148
uint8_t uint8
Definition: Define.h:152
float _liquidLevel
Definition: Map.h:182
G3D::int16 x
Definition: Vector2int16.h:37
Definition: Map.h:137
uint8 _liquidWidth
Definition: Map.h:190
Definition: Map.h:133
uint8 * _liquidFlags
Definition: Map.h:184
uint16 * _liquidEntry
Definition: Map.h:183
float * _liquidMap
Definition: Map.h:185

+ Here is the call graph for this function:

float GridMap::getMinHeight ( float  x,
float  y 
) const
2097 {
2098  if (!_minHeight)
2099  return -500.0f;
2100 
2101  static uint32 const indices[] =
2102  {
2103  3, 0, 4,
2104  0, 1, 4,
2105  1, 2, 4,
2106  2, 5, 4,
2107  5, 8, 4,
2108  8, 7, 4,
2109  7, 6, 4,
2110  6, 3, 4
2111  };
2112 
2113  static float const boundGridCoords[] =
2114  {
2115  0.0f, 0.0f,
2116  0.0f, -266.66666f,
2117  0.0f, -533.33331f,
2118  -266.66666f, 0.0f,
2119  -266.66666f, -266.66666f,
2120  -266.66666f, -533.33331f,
2121  -533.33331f, 0.0f,
2122  -533.33331f, -266.66666f,
2123  -533.33331f, -533.33331f
2124  };
2125 
2126  Cell cell(x, y);
2127  float gx = x - (int32(cell.GridX()) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS;
2128  float gy = y - (int32(cell.GridY()) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS;
2129 
2130  uint32 quarterIndex = 0;
2131  if (cell.CellY() < MAX_NUMBER_OF_CELLS / 2)
2132  {
2133  if (cell.CellX() < MAX_NUMBER_OF_CELLS / 2)
2134  {
2135  quarterIndex = 4 + (gy > gx);
2136  }
2137  else
2138  quarterIndex = 2 + ((-SIZE_OF_GRIDS - gx) > gy);
2139  }
2140  else if (cell.CellX() < MAX_NUMBER_OF_CELLS / 2)
2141  {
2142  quarterIndex = 6 + ((-SIZE_OF_GRIDS - gx) <= gy);
2143  }
2144  else
2145  quarterIndex = gx > gy;
2146 
2147  quarterIndex *= 3;
2148 
2149  return G3D::Plane(
2150  G3D::Vector3(boundGridCoords[indices[quarterIndex + 0] * 2 + 0], boundGridCoords[indices[quarterIndex + 0] * 2 + 1], _minHeight[indices[quarterIndex + 0]]),
2151  G3D::Vector3(boundGridCoords[indices[quarterIndex + 1] * 2 + 0], boundGridCoords[indices[quarterIndex + 1] * 2 + 1], _minHeight[indices[quarterIndex + 1]]),
2152  G3D::Vector3(boundGridCoords[indices[quarterIndex + 2] * 2 + 0], boundGridCoords[indices[quarterIndex + 2] * 2 + 1], _minHeight[indices[quarterIndex + 2]])
2153  ).distance(G3D::Vector3(gx, gy, 0.0f));
2154 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:39
Definition: Plane.h:25
#define CENTER_GRID_ID
Definition: GridDefines.h:40
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:35
int16 * _minHeight
Definition: Map.h:173
Definition: Vector3.h:58
float distance(const Vector3 &x) const
Definition: Plane.h:131
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
Definition: Cell.h:49
int32_t int32
Definition: g3dmath.h:167
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

uint8 GridMap::getTerrainType ( float  x,
float  y 
) const
2177 {
2178  if (!_liquidFlags)
2179  return 0;
2180 
2181  x = 16 * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
2182  y = 16 * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
2183  int lx = (int)x & 15;
2184  int ly = (int)y & 15;
2185  return _liquidFlags[lx*16 + ly];
2186 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:39
#define CENTER_GRID_ID
Definition: GridDefines.h:40
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
uint8 * _liquidFlags
Definition: Map.h:184
bool GridMap::loadAreaData ( FILE *  in,
uint32  offset,
uint32  size 
)
private
1756 {
1757  map_areaHeader header;
1758  fseek(in, offset, SEEK_SET);
1759 
1760  if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != MapAreaMagic.asUInt)
1761  return false;
1762 
1763  _gridArea = header.gridArea;
1764  if (!(header.flags & MAP_AREA_NO_AREA))
1765  {
1766  _areaMap = new uint16[16 * 16];
1767  if (fread(_areaMap, sizeof(uint16), 16*16, in) != 16*16)
1768  return false;
1769  }
1770  return true;
1771 }
#define MAP_AREA_NO_AREA
Definition: Map.h:94
uint16 _gridArea
Definition: Map.h:186
Definition: Map.h:96
uint16 gridArea
Definition: Map.h:100
uint16 * _areaMap
Definition: Map.h:179
u_map_magic MapAreaMagic
Definition: Map.cpp:44
uint32 asUInt
Non-null terminated string
Definition: Map.h:73
uint16_t uint16
Definition: Define.h:151
uint16 flags
Definition: Map.h:99
#define SEEK_SET
Definition: zconf.h:475
uint32 fourcc
Definition: Map.h:98

+ Here is the caller graph for this function:

bool GridMap::loadData ( const char *  filename)
1685 {
1686  // Unload old data if exist
1687  unloadData();
1688 
1689  map_fileheader header;
1690  // Not return error if file not found
1691  FILE* in = fopen(filename, "rb");
1692  if (!in)
1693  return true;
1694 
1695  if (fread(&header, sizeof(header), 1, in) != 1)
1696  {
1697  fclose(in);
1698  return false;
1699  }
1700 
1702  {
1703  // load up area data
1704  if (header.areaMapOffset && !loadAreaData(in, header.areaMapOffset, header.areaMapSize))
1705  {
1706  TC_LOG_ERROR("maps", "Error loading map area data\n");
1707  fclose(in);
1708  return false;
1709  }
1710  // load up height data
1711  if (header.heightMapOffset && !loadHeightData(in, header.heightMapOffset, header.heightMapSize))
1712  {
1713  TC_LOG_ERROR("maps", "Error loading map height data\n");
1714  fclose(in);
1715  return false;
1716  }
1717  // load up liquid data
1718  if (header.liquidMapOffset && !loadLiquidData(in, header.liquidMapOffset, header.liquidMapSize))
1719  {
1720  TC_LOG_ERROR("maps", "Error loading map liquids data\n");
1721  fclose(in);
1722  return false;
1723  }
1724  fclose(in);
1725  return true;
1726  }
1727 
1728  TC_LOG_ERROR("maps", "Map file '%s' is from an incompatible map version (%.*s %.*s), %.*s %.*s is expected. Please recreate using the mapextractor.",
1729  filename, 4, header.mapMagic.asChar, 4, header.versionMagic.asChar, 4, MapMagic.asChar, 4, MapVersionMagic.asChar);
1730  fclose(in);
1731  return false;
1732 }
uint32 areaMapSize
Definition: Map.h:85
u_map_magic MapMagic
Definition: Map.cpp:42
void unloadData()
Definition: Map.cpp:1734
uint32 areaMapOffset
Definition: Map.h:84
u_map_magic MapVersionMagic
Definition: Map.cpp:43
char asChar[4]
Definition: Map.h:72
uint32 asUInt
Non-null terminated string
Definition: Map.h:73
Definition: Map.h:79
uint32 heightMapOffset
Definition: Map.h:86
bool loadLiquidData(FILE *in, uint32 offset, uint32 size)
Definition: Map.cpp:1829
uint32 liquidMapOffset
Definition: Map.h:88
uint32 liquidMapSize
Definition: Map.h:89
uint32 heightMapSize
Definition: Map.h:87
bool loadAreaData(FILE *in, uint32 offset, uint32 size)
Definition: Map.cpp:1755
u_map_magic mapMagic
Definition: Map.h:81
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
u_map_magic versionMagic
Definition: Map.h:82
bool loadHeightData(FILE *in, uint32 offset, uint32 size)
Definition: Map.cpp:1773

+ Here is the call graph for this function:

bool GridMap::loadHeightData ( FILE *  in,
uint32  offset,
uint32  size 
)
private
1774 {
1775  map_heightHeader header;
1776  fseek(in, offset, SEEK_SET);
1777 
1778  if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != MapHeightMagic.asUInt)
1779  return false;
1780 
1781  _gridHeight = header.gridHeight;
1782  if (!(header.flags & MAP_HEIGHT_NO_HEIGHT))
1783  {
1784  if ((header.flags & MAP_HEIGHT_AS_INT16))
1785  {
1786  m_uint16_V9 = new uint16 [129*129];
1787  m_uint16_V8 = new uint16 [128*128];
1788  if (fread(m_uint16_V9, sizeof(uint16), 129*129, in) != 129*129 ||
1789  fread(m_uint16_V8, sizeof(uint16), 128*128, in) != 128*128)
1790  return false;
1791  _gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 65535;
1793  }
1794  else if ((header.flags & MAP_HEIGHT_AS_INT8))
1795  {
1796  m_uint8_V9 = new uint8 [129*129];
1797  m_uint8_V8 = new uint8 [128*128];
1798  if (fread(m_uint8_V9, sizeof(uint8), 129*129, in) != 129*129 ||
1799  fread(m_uint8_V8, sizeof(uint8), 128*128, in) != 128*128)
1800  return false;
1801  _gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 255;
1803  }
1804  else
1805  {
1806  m_V9 = new float [129*129];
1807  m_V8 = new float [128*128];
1808  if (fread(m_V9, sizeof(float), 129*129, in) != 129*129 ||
1809  fread(m_V8, sizeof(float), 128*128, in) != 128*128)
1810  return false;
1812  }
1813  }
1814  else
1816 
1817  if (header.flags & MAP_HEIGHT_HAS_FLIGHT_BOUNDS)
1818  {
1819  _maxHeight = new int16[3 * 3];
1820  _minHeight = new int16[3 * 3];
1821  if (fread(_maxHeight, sizeof(int16), 3 * 3, in) != 3 * 3 ||
1822  fread(_minHeight, sizeof(int16), 3 * 3, in) != 3 * 3)
1823  return false;
1824  }
1825 
1826  return true;
1827 }
float * m_V9
Definition: Map.h:163
float getHeightFromUint8(float x, float y) const
Definition: Map.cpp:1962
uint32 fourcc
Definition: Map.h:110
#define MAP_HEIGHT_NO_HEIGHT
Definition: Map.h:103
float _gridIntHeightMultiplier
Definition: Map.h:176
float gridMaxHeight
Definition: Map.h:113
int16 * _minHeight
Definition: Map.h:173
uint32 flags
Definition: Map.h:111
#define MAP_HEIGHT_HAS_FLIGHT_BOUNDS
Definition: Map.h:106
GetHeightPtr _gridGetHeight
Definition: Map.h:200
#define MAP_HEIGHT_AS_INT16
Definition: Map.h:104
uint32 asUInt
Non-null terminated string
Definition: Map.h:73
uint8 * m_uint8_V8
Definition: Map.h:170
float * m_V8
Definition: Map.h:168
float getHeightFromUint16(float x, float y) const
Definition: Map.cpp:2029
uint8 * m_uint8_V9
Definition: Map.h:165
float getHeightFromFlat(float x, float y) const
Definition: Map.cpp:1875
float getHeightFromFloat(float x, float y) const
Definition: Map.cpp:1880
u_map_magic MapHeightMagic
Definition: Map.cpp:45
uint16_t uint16
Definition: Define.h:151
float _gridHeight
Definition: Map.h:175
uint16 * m_uint16_V8
Definition: Map.h:169
#define SEEK_SET
Definition: zconf.h:475
#define MAP_HEIGHT_AS_INT8
Definition: Map.h:105
float gridHeight
Definition: Map.h:112
uint16 * m_uint16_V9
Definition: Map.h:164
uint8_t uint8
Definition: Define.h:152
int16_t int16
Definition: Define.h:147
Definition: Map.h:108
int16 * _maxHeight
Definition: Map.h:172

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool GridMap::loadLiquidData ( FILE *  in,
uint32  offset,
uint32  size 
)
private
1830 {
1831  map_liquidHeader header;
1832  fseek(in, offset, SEEK_SET);
1833 
1834  if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != MapLiquidMagic.asUInt)
1835  return false;
1836 
1837  _liquidType = header.liquidType;
1838  _liquidOffX = header.offsetX;
1839  _liquidOffY = header.offsetY;
1840  _liquidWidth = header.width;
1841  _liquidHeight = header.height;
1842  _liquidLevel = header.liquidLevel;
1843 
1844  if (!(header.flags & MAP_LIQUID_NO_TYPE))
1845  {
1846  _liquidEntry = new uint16[16*16];
1847  if (fread(_liquidEntry, sizeof(uint16), 16*16, in) != 16*16)
1848  return false;
1849 
1850  _liquidFlags = new uint8[16*16];
1851  if (fread(_liquidFlags, sizeof(uint8), 16*16, in) != 16*16)
1852  return false;
1853  }
1854  if (!(header.flags & MAP_LIQUID_NO_HEIGHT))
1855  {
1857  if (fread(_liquidMap, sizeof(float), _liquidWidth*_liquidHeight, in) != (uint32(_liquidWidth) * uint32(_liquidHeight)))
1858  return false;
1859  }
1860  return true;
1861 }
uint8 offsetY
Definition: Map.h:125
uint8 height
Definition: Map.h:127
uint16 flags
Definition: Map.h:122
uint8 _liquidHeight
Definition: Map.h:191
#define MAP_LIQUID_NO_TYPE
Definition: Map.h:116
uint8 _liquidOffX
Definition: Map.h:188
uint8 offsetX
Definition: Map.h:124
uint32 fourcc
Definition: Map.h:121
uint16 liquidType
Definition: Map.h:123
uint8 width
Definition: Map.h:126
uint32 asUInt
Non-null terminated string
Definition: Map.h:73
u_map_magic MapLiquidMagic
Definition: Map.cpp:46
float liquidLevel
Definition: Map.h:128
Definition: Map.h:119
uint16 _liquidType
Definition: Map.h:187
uint8 _liquidOffY
Definition: Map.h:189
uint16_t uint16
Definition: Define.h:151
#define SEEK_SET
Definition: zconf.h:475
uint8_t uint8
Definition: Define.h:152
float _liquidLevel
Definition: Map.h:182
uint32_t uint32
Definition: g3dmath.h:168
#define MAP_LIQUID_NO_HEIGHT
Definition: Map.h:117
uint8 _liquidWidth
Definition: Map.h:190
uint8 * _liquidFlags
Definition: Map.h:184
uint16 * _liquidEntry
Definition: Map.h:183
float * _liquidMap
Definition: Map.h:185

+ Here is the caller graph for this function:

void GridMap::unloadData ( )
1735 {
1736  delete[] _areaMap;
1737  delete[] m_V9;
1738  delete[] m_V8;
1739  delete[] _maxHeight;
1740  delete[] _minHeight;
1741  delete[] _liquidEntry;
1742  delete[] _liquidFlags;
1743  delete[] _liquidMap;
1744  _areaMap = nullptr;
1745  m_V9 = nullptr;
1746  m_V8 = nullptr;
1747  _maxHeight = nullptr;
1748  _minHeight = nullptr;
1749  _liquidEntry = nullptr;
1750  _liquidFlags = nullptr;
1751  _liquidMap = nullptr;
1753 }
float * m_V9
Definition: Map.h:163
int16 * _minHeight
Definition: Map.h:173
GetHeightPtr _gridGetHeight
Definition: Map.h:200
uint16 * _areaMap
Definition: Map.h:179
float * m_V8
Definition: Map.h:168
float getHeightFromFlat(float x, float y) const
Definition: Map.cpp:1875
uint8 * _liquidFlags
Definition: Map.h:184
uint16 * _liquidEntry
Definition: Map.h:183
float * _liquidMap
Definition: Map.h:185
int16 * _maxHeight
Definition: Map.h:172

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

union { ... }
union { ... }
uint16* GridMap::_areaMap
private
uint32 GridMap::_flags
private
uint16 GridMap::_gridArea
private
GetHeightPtr GridMap::_gridGetHeight
private
float GridMap::_gridHeight
private
float GridMap::_gridIntHeightMultiplier
private
uint16* GridMap::_liquidEntry
private
uint8* GridMap::_liquidFlags
private
uint8 GridMap::_liquidHeight
private
float GridMap::_liquidLevel
private
float* GridMap::_liquidMap
private
uint8 GridMap::_liquidOffX
private
uint8 GridMap::_liquidOffY
private
uint16 GridMap::_liquidType
private
uint8 GridMap::_liquidWidth
private
int16* GridMap::_maxHeight
private
int16* GridMap::_minHeight
private
uint16* GridMap::m_uint16_V8
uint16* GridMap::m_uint16_V9
uint8* GridMap::m_uint8_V8
uint8* GridMap::m_uint8_V9
float* GridMap::m_V8
float* GridMap::m_V9

The documentation for this class was generated from the following files: