OregonCore  revision be9e804-git
Your Favourite TBC server
GridMap Class Reference

#include <Map.h>

Public Member Functions

 GridMap ()
 
 ~GridMap ()
 
bool loadData (const char *filename)
 
void unloadData ()
 
uint16 getArea (float x, float y)
 
float getHeight (float x, float y)
 
float getLiquidLevel (float x, float y)
 
uint8 getTerrainType (float x, float y)
 
ZLiquidStatus getLiquidStatus (float x, float y, float z, uint8 ReqLiquidType, LiquidData *data=0)
 

Private Types

typedef float(GridMap::* pGetHeightPtr) (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 m_flags
 
uint16 m_gridArea
 
uint16m_area_map
 
float m_gridHeight
 
float m_gridIntHeightMultiplier
 
union {
   float *   m_V9
 
   uint16 *   m_uint16_V9
 
   uint8 *   m_uint8_V9
 
}; 
 
union {
   float *   m_V8
 
   uint16 *   m_uint16_V8
 
   uint8 *   m_uint8_V8
 
}; 
 
uint16 m_liquidType
 
uint8 m_liquid_offX
 
uint8 m_liquid_offY
 
uint8 m_liquid_width
 
uint8 m_liquid_height
 
float m_liquidLevel
 
uint16_liquidEntry
 
uint8_liquidFlags
 
float * _liquidMap
 
pGetHeightPtr m_gridGetHeight
 

Detailed Description

Definition at line 155 of file Map.h.

Member Typedef Documentation

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

Definition at line 192 of file Map.h.

Constructor & Destructor Documentation

GridMap::GridMap ( )

Definition at line 1011 of file Map.cpp.

References getHeightFromFlat(), and INVALID_HEIGHT.

1012 {
1013  m_flags = 0;
1014  // Area data
1015  m_gridArea = 0;
1016  m_area_map = NULL;
1017  // Height level data
1020  m_V9 = NULL;
1021  m_V8 = NULL;
1022  // Liquid data
1023  m_liquidType = 0;
1024  m_liquid_offX = 0;
1025  m_liquid_offY = 0;
1026  m_liquid_width = 0;
1027  m_liquid_height = 0;
1029  _liquidEntry = NULL;
1030  _liquidFlags = NULL;
1031  _liquidMap = NULL;
1032 }
float * m_V9
Definition: Map.h:166
uint8 m_liquid_offY
Definition: Map.h:179
uint32 m_flags
Definition: Map.h:157
pGetHeightPtr m_gridGetHeight
Definition: Map.h:193
float * m_V8
Definition: Map.h:172
float getHeightFromFlat(float x, float y) const
Definition: Map.cpp:1214
float m_liquidLevel
Definition: Map.h:182
uint16 * m_area_map
Definition: Map.h:160
uint8 m_liquid_offX
Definition: Map.h:178
uint16 m_liquidType
Definition: Map.h:177
uint16 m_gridArea
Definition: Map.h:159
float m_gridHeight
Definition: Map.h:162
#define INVALID_HEIGHT
Definition: Map.h:259
uint8 m_liquid_width
Definition: Map.h:180
uint8 m_liquid_height
Definition: Map.h:181
uint8 * _liquidFlags
Definition: Map.h:184
uint16 * _liquidEntry
Definition: Map.h:183
float * _liquidMap
Definition: Map.h:185
GridMap::~GridMap ( )

Definition at line 1034 of file Map.cpp.

1035 {
1036  unloadData();
1037 }
void unloadData()
Definition: Map.cpp:1087

Member Function Documentation

uint16 GridMap::getArea ( float  x,
float  y 
)

Definition at line 1202 of file Map.cpp.

References CENTER_GRID_ID, and SIZE_OF_GRIDS.

1203 {
1204  if (!m_area_map)
1205  return m_gridArea;
1206 
1207  x = 16 * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
1208  y = 16 * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
1209  int lx = (int)x & 15;
1210  int ly = (int)y & 15;
1211  return m_area_map[lx * 16 + ly];
1212 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:35
#define CENTER_GRID_ID
Definition: GridDefines.h:36
uint16 * m_area_map
Definition: Map.h:160
uint16 m_gridArea
Definition: Map.h:159
float GridMap::getHeight ( float  x,
float  y 
)
inline

Definition at line 206 of file Map.h.

207  {
208  return (this->*m_gridGetHeight)(x, y);
209  }
pGetHeightPtr m_gridGetHeight
Definition: Map.h:193
float GridMap::getHeightFromFlat ( float  x,
float  y 
) const
private

Definition at line 1214 of file Map.cpp.

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

1215 {
1216  return m_gridHeight;
1217 }
float m_gridHeight
Definition: Map.h:162
float GridMap::getHeightFromFloat ( float  x,
float  y 
) const
private

Definition at line 1219 of file Map.cpp.

References CENTER_GRID_ID, MAP_RESOLUTION, and SIZE_OF_GRIDS.

Referenced by loadHeightData().

1220 {
1221  if (!m_V8 || !m_V9)
1222  return m_gridHeight;
1223 
1226 
1227  int x_int = (int)x;
1228  int y_int = (int)y;
1229  x -= x_int;
1230  y -= y_int;
1231  x_int &= (MAP_RESOLUTION - 1);
1232  y_int &= (MAP_RESOLUTION - 1);
1233 
1234  // Height stored as: h5 - its v8 grid, h1-h4 - its v9 grid
1235  // +--------------> X
1236  // | h1-------h2 Coordinates is:
1237  // | | \ 1 / | h1 0,0
1238  // | | \ / | h2 0,1
1239  // | | 2 h5 3 | h3 1,0
1240  // | | / \ | h4 1,1
1241  // | | / 4 \ | h5 1/2,1/2
1242  // | h3-------h4
1243  // V Y
1244  // For find height need
1245  // 1 - detect triangle
1246  // 2 - solve linear equation from triangle points
1247  // Calculate coefficients for solve h = a*x + b*y + c
1248 
1249  float a, b, c;
1250  // Select triangle:
1251  if (x + y < 1)
1252  {
1253  if (x > y)
1254  {
1255  // 1 triangle (h1, h2, h5 points)
1256  float h1 = m_V9[(x_int) * 129 + y_int];
1257  float h2 = m_V9[(x_int + 1) * 129 + y_int];
1258  float h5 = 2 * m_V8[x_int * 128 + y_int];
1259  a = h2 - h1;
1260  b = h5 - h1 - h2;
1261  c = h1;
1262  }
1263  else
1264  {
1265  // 2 triangle (h1, h3, h5 points)
1266  float h1 = m_V9[x_int * 129 + y_int ];
1267  float h3 = m_V9[x_int * 129 + y_int + 1];
1268  float h5 = 2 * m_V8[x_int * 128 + y_int];
1269  a = h5 - h1 - h3;
1270  b = h3 - h1;
1271  c = h1;
1272  }
1273  }
1274  else
1275  {
1276  if (x > y)
1277  {
1278  // 3 triangle (h2, h4, h5 points)
1279  float h2 = m_V9[(x_int + 1) * 129 + y_int ];
1280  float h4 = m_V9[(x_int + 1) * 129 + y_int + 1];
1281  float h5 = 2 * m_V8[x_int * 128 + y_int];
1282  a = h2 + h4 - h5;
1283  b = h4 - h2;
1284  c = h5 - h4;
1285  }
1286  else
1287  {
1288  // 4 triangle (h3, h4, h5 points)
1289  float h3 = m_V9[(x_int) * 129 + y_int + 1];
1290  float h4 = m_V9[(x_int + 1) * 129 + y_int + 1];
1291  float h5 = 2 * m_V8[x_int * 128 + y_int];
1292  a = h4 - h3;
1293  b = h3 + h4 - h5;
1294  c = h5 - h4;
1295  }
1296  }
1297  // Calculate height
1298  return a * x + b * y + c;
1299 }
float * m_V9
Definition: Map.h:166
#define SIZE_OF_GRIDS
Definition: GridDefines.h:35
#define CENTER_GRID_ID
Definition: GridDefines.h:36
float * m_V8
Definition: Map.h:172
#define MAP_RESOLUTION
Definition: GridDefines.h:51
float m_gridHeight
Definition: Map.h:162
float GridMap::getHeightFromUint16 ( float  x,
float  y 
) const
private

Definition at line 1368 of file Map.cpp.

References CENTER_GRID_ID, MAP_RESOLUTION, and SIZE_OF_GRIDS.

Referenced by loadHeightData().

1369 {
1370  if (!m_uint16_V8 || !m_uint16_V9)
1371  return m_gridHeight;
1372 
1375 
1376  int x_int = (int)x;
1377  int y_int = (int)y;
1378  x -= x_int;
1379  y -= y_int;
1380  x_int &= (MAP_RESOLUTION - 1);
1381  y_int &= (MAP_RESOLUTION - 1);
1382 
1383  int32 a, b, c;
1384  uint16* V9_h1_ptr = &m_uint16_V9[x_int * 128 + x_int + y_int];
1385  if (x + y < 1)
1386  {
1387  if (x > y)
1388  {
1389  // 1 triangle (h1, h2, h5 points)
1390  int32 h1 = V9_h1_ptr[ 0];
1391  int32 h2 = V9_h1_ptr[129];
1392  int32 h5 = 2 * m_uint16_V8[x_int * 128 + y_int];
1393  a = h2 - h1;
1394  b = h5 - h1 - h2;
1395  c = h1;
1396  }
1397  else
1398  {
1399  // 2 triangle (h1, h3, h5 points)
1400  int32 h1 = V9_h1_ptr[0];
1401  int32 h3 = V9_h1_ptr[1];
1402  int32 h5 = 2 * m_uint16_V8[x_int * 128 + y_int];
1403  a = h5 - h1 - h3;
1404  b = h3 - h1;
1405  c = h1;
1406  }
1407  }
1408  else
1409  {
1410  if (x > y)
1411  {
1412  // 3 triangle (h2, h4, h5 points)
1413  int32 h2 = V9_h1_ptr[129];
1414  int32 h4 = V9_h1_ptr[130];
1415  int32 h5 = 2 * m_uint16_V8[x_int * 128 + y_int];
1416  a = h2 + h4 - h5;
1417  b = h4 - h2;
1418  c = h5 - h4;
1419  }
1420  else
1421  {
1422  // 4 triangle (h3, h4, h5 points)
1423  int32 h3 = V9_h1_ptr[ 1];
1424  int32 h4 = V9_h1_ptr[130];
1425  int32 h5 = 2 * m_uint16_V8[x_int * 128 + y_int];
1426  a = h4 - h3;
1427  b = h3 + h4 - h5;
1428  c = h5 - h4;
1429  }
1430  }
1431  // Calculate height
1432  return (float)((a * x) + (b * y) + c) * m_gridIntHeightMultiplier + m_gridHeight;
1433 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:35
#define CENTER_GRID_ID
Definition: GridDefines.h:36
ACE_INT32 int32
Definition: Define.h:67
#define MAP_RESOLUTION
Definition: GridDefines.h:51
float m_gridIntHeightMultiplier
Definition: Map.h:163
uint16 * m_uint16_V8
Definition: Map.h:173
uint16 * m_uint16_V9
Definition: Map.h:167
float m_gridHeight
Definition: Map.h:162
ACE_UINT16 uint16
Definition: Define.h:72
float GridMap::getHeightFromUint8 ( float  x,
float  y 
) const
private

Definition at line 1301 of file Map.cpp.

References CENTER_GRID_ID, MAP_RESOLUTION, and SIZE_OF_GRIDS.

Referenced by loadHeightData().

1302 {
1303  if (!m_uint8_V8 || !m_uint8_V9)
1304  return m_gridHeight;
1305 
1308 
1309  int x_int = (int)x;
1310  int y_int = (int)y;
1311  x -= x_int;
1312  y -= y_int;
1313  x_int &= (MAP_RESOLUTION - 1);
1314  y_int &= (MAP_RESOLUTION - 1);
1315 
1316  int32 a, b, c;
1317  uint8* V9_h1_ptr = &m_uint8_V9[x_int * 128 + x_int + y_int];
1318  if (x + y < 1)
1319  {
1320  if (x > y)
1321  {
1322  // 1 triangle (h1, h2, h5 points)
1323  int32 h1 = V9_h1_ptr[ 0];
1324  int32 h2 = V9_h1_ptr[129];
1325  int32 h5 = 2 * m_uint8_V8[x_int * 128 + y_int];
1326  a = h2 - h1;
1327  b = h5 - h1 - h2;
1328  c = h1;
1329  }
1330  else
1331  {
1332  // 2 triangle (h1, h3, h5 points)
1333  int32 h1 = V9_h1_ptr[0];
1334  int32 h3 = V9_h1_ptr[1];
1335  int32 h5 = 2 * m_uint8_V8[x_int * 128 + y_int];
1336  a = h5 - h1 - h3;
1337  b = h3 - h1;
1338  c = h1;
1339  }
1340  }
1341  else
1342  {
1343  if (x > y)
1344  {
1345  // 3 triangle (h2, h4, h5 points)
1346  int32 h2 = V9_h1_ptr[129];
1347  int32 h4 = V9_h1_ptr[130];
1348  int32 h5 = 2 * m_uint8_V8[x_int * 128 + y_int];
1349  a = h2 + h4 - h5;
1350  b = h4 - h2;
1351  c = h5 - h4;
1352  }
1353  else
1354  {
1355  // 4 triangle (h3, h4, h5 points)
1356  int32 h3 = V9_h1_ptr[ 1];
1357  int32 h4 = V9_h1_ptr[130];
1358  int32 h5 = 2 * m_uint8_V8[x_int * 128 + y_int];
1359  a = h4 - h3;
1360  b = h3 + h4 - h5;
1361  c = h5 - h4;
1362  }
1363  }
1364  // Calculate height
1365  return (float)((a * x) + (b * y) + c) * m_gridIntHeightMultiplier + m_gridHeight;
1366 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:35
#define CENTER_GRID_ID
Definition: GridDefines.h:36
ACE_INT32 int32
Definition: Define.h:67
uint8 * m_uint8_V8
Definition: Map.h:174
ACE_UINT8 uint8
Definition: Define.h:73
uint8 * m_uint8_V9
Definition: Map.h:168
#define MAP_RESOLUTION
Definition: GridDefines.h:51
float m_gridIntHeightMultiplier
Definition: Map.h:163
float m_gridHeight
Definition: Map.h:162
float GridMap::getLiquidLevel ( float  x,
float  y 
)

Definition at line 1435 of file Map.cpp.

References CENTER_GRID_ID, INVALID_HEIGHT, MAP_RESOLUTION, and SIZE_OF_GRIDS.

1436 {
1437  if (!_liquidMap)
1438  return m_liquidLevel;
1439 
1442 
1443  int cx_int = ((int)x & (MAP_RESOLUTION - 1)) - m_liquid_offY;
1444  int cy_int = ((int)y & (MAP_RESOLUTION - 1)) - m_liquid_offX;
1445 
1446  if (cx_int < 0 || cx_int >= m_liquid_height)
1447  return INVALID_HEIGHT;
1448  if (cy_int < 0 || cy_int >= m_liquid_width)
1449  return INVALID_HEIGHT;
1450 
1451  return _liquidMap[cx_int * m_liquid_width + cy_int];
1452 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:35
uint8 m_liquid_offY
Definition: Map.h:179
#define CENTER_GRID_ID
Definition: GridDefines.h:36
#define MAP_RESOLUTION
Definition: GridDefines.h:51
float m_liquidLevel
Definition: Map.h:182
uint8 m_liquid_offX
Definition: Map.h:178
#define INVALID_HEIGHT
Definition: Map.h:259
uint8 m_liquid_width
Definition: Map.h:180
uint8 m_liquid_height
Definition: Map.h:181
float * _liquidMap
Definition: Map.h:185
ZLiquidStatus GridMap::getLiquidStatus ( float  x,
float  y,
float  z,
uint8  ReqLiquidType,
LiquidData data = 0 
)
inline

Definition at line 1467 of file Map.cpp.

References CENTER_GRID_ID, LiquidData::depth_level, LiquidData::entry, GetAreaEntryByAreaFlagAndMap(), GetAreaEntryByAreaID(), LiquidData::level, LIQUID_MAP_ABOVE_WATER, LIQUID_MAP_IN_WATER, LIQUID_MAP_NO_WATER, LIQUID_MAP_UNDER_WATER, LIQUID_MAP_WATER_WALK, MAP_LIQUID_TYPE_DARK_WATER, MAP_LIQUID_TYPE_WATER, MAP_RESOLUTION, MAPID_INVALID, SIZE_OF_GRIDS, sLiquidTypeStore, and LiquidData::type_flags.

1468 {
1469  // Check water type (if no water return)
1470  if (!m_liquidType && !_liquidFlags)
1471  return LIQUID_MAP_NO_WATER;
1472 
1473  // Get cell
1474  float cx = MAP_RESOLUTION * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
1475  float cy = MAP_RESOLUTION * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
1476 
1477  int x_int = (int)cx & (MAP_RESOLUTION - 1);
1478  int y_int = (int)cy & (MAP_RESOLUTION - 1);
1479 
1480  // Check water type in cell
1481  int idx=(x_int>>3)*16 + (y_int>>3);
1482  uint8 type = _liquidFlags ? _liquidFlags[idx] : 1 << m_liquidType;
1483  uint32 entry = 0;
1484  if (_liquidEntry)
1485  {
1486  if (LiquidTypeEntry const* liquidEntry = sLiquidTypeStore.LookupEntry(_liquidEntry[idx]))
1487  {
1488  entry = liquidEntry->Id;
1489  uint32 liqTypeIdx = liquidEntry->Type;
1490  if ((entry < 21) && (type & MAP_LIQUID_TYPE_WATER))
1491  {
1492  // only basic liquid stored in maps actualy so in some case we need to override type depend on area
1493  // actualy only Hyjal Mount and Coilfang raid be overrided here
1495  {
1496  uint32 overrideLiquid = area->LiquidTypeOverride;
1497  if (!overrideLiquid && area->zone)
1498  if (area = GetAreaEntryByAreaID(area->zone))
1499  overrideLiquid = area->LiquidTypeOverride;
1500 
1501  if (LiquidTypeEntry const* liq = sLiquidTypeStore.LookupEntry(overrideLiquid))
1502  {
1503  entry = overrideLiquid;
1504  liqTypeIdx = liq->Type;
1505  }
1506  }
1507  }
1508 
1509  type |= (1 << liqTypeIdx) | (type & MAP_LIQUID_TYPE_DARK_WATER);
1510  }
1511  }
1512 
1513  if (type == 0)
1514  return LIQUID_MAP_NO_WATER;
1515 
1516  // Check req liquid type mask
1517  if (ReqLiquidType && !(ReqLiquidType & type))
1518  return LIQUID_MAP_NO_WATER;
1519 
1520  // Check water level:
1521  // Check water height map
1522  int lx_int = x_int - m_liquid_offY;
1523  int ly_int = y_int - m_liquid_offX;
1524  if (lx_int < 0 || lx_int >= m_liquid_height)
1525  return LIQUID_MAP_NO_WATER;
1526  if (ly_int < 0 || ly_int >= m_liquid_width)
1527  return LIQUID_MAP_NO_WATER;
1528 
1529  // Get water level
1530  float liquid_level = _liquidMap ? _liquidMap[lx_int * m_liquid_width + ly_int] : m_liquidLevel;
1531  // Get ground level (sub 0.2 for fix some errors)
1532  float ground_level = getHeight(x, y);
1533 
1534  // Check water level and ground level
1535  if (liquid_level < ground_level || z < ground_level - 2)
1536  return LIQUID_MAP_NO_WATER;
1537 
1538  // All ok in water -> store data
1539  if (data)
1540  {
1541  data->entry = entry;
1542  data->type_flags = type;
1543  data->level = liquid_level;
1544  data->depth_level = ground_level;
1545  }
1546 
1547  // For speed check as int values
1548  float delta = liquid_level - z;
1549 
1550  // Get position delta
1551  if (delta > 2.0f) // Under water
1552  return LIQUID_MAP_UNDER_WATER;
1553  if (delta > 0.0f) // In water
1554  return LIQUID_MAP_IN_WATER;
1555  if (delta > -0.1f) // Walk on water
1556  return LIQUID_MAP_WATER_WALK;
1557  // Above water
1558  return LIQUID_MAP_ABOVE_WATER;
1559 }
AreaTableEntry const * GetAreaEntryByAreaID(uint32 area_id)
Definition: DBCStores.cpp:623
DBCStorage< LiquidTypeEntry > sLiquidTypeStore(LiquidTypefmt)
float depth_level
Definition: Map.h:152
#define SIZE_OF_GRIDS
Definition: GridDefines.h:35
#define MAPID_INVALID
Definition: Object.h:547
uint8 m_liquid_offY
Definition: Map.h:179
#define CENTER_GRID_ID
Definition: GridDefines.h:36
AreaTableEntry const * GetAreaEntryByAreaFlagAndMap(uint32 area_flag, uint32 map_id)
Definition: DBCStores.cpp:632
#define MAP_LIQUID_TYPE_DARK_WATER
Definition: Map.h:144
float getHeight(float x, float y)
Definition: Map.h:206
ACE_UINT8 uint8
Definition: Define.h:73
#define MAP_RESOLUTION
Definition: GridDefines.h:51
float level
Definition: Map.h:151
float m_liquidLevel
Definition: Map.h:182
uint32 type_flags
Definition: Map.h:149
#define MAP_LIQUID_TYPE_WATER
Definition: Map.h:140
uint8 m_liquid_offX
Definition: Map.h:178
uint32 entry
Definition: Map.h:150
uint16 getArea(float x, float y)
Definition: Map.cpp:1202
uint16 m_liquidType
Definition: Map.h:177
ACE_UINT32 uint32
Definition: Define.h:71
uint8 m_liquid_width
Definition: Map.h:180
uint8 m_liquid_height
Definition: Map.h:181
uint8 * _liquidFlags
Definition: Map.h:184
uint16 * _liquidEntry
Definition: Map.h:183
float * _liquidMap
Definition: Map.h:185
uint8 GridMap::getTerrainType ( float  x,
float  y 
)

Definition at line 1454 of file Map.cpp.

References CENTER_GRID_ID, and SIZE_OF_GRIDS.

1455 {
1456  if (!_liquidFlags)
1457  return 0;
1458 
1459  x = 16 * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
1460  y = 16 * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
1461  int lx = (int)x & 15;
1462  int ly = (int)y & 15;
1463  return _liquidFlags[lx * 16 + ly];
1464 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:35
#define CENTER_GRID_ID
Definition: GridDefines.h:36
uint8 * _liquidFlags
Definition: Map.h:184
bool GridMap::loadAreaData ( FILE *  in,
uint32  offset,
uint32  size 
)
private

Definition at line 1104 of file Map.cpp.

References map_areaHeader::flags, map_areaHeader::fourcc, map_areaHeader::gridArea, and MAP_AREA_NO_AREA.

1105 {
1106  map_areaHeader header;
1107  fseek(in, offset, SEEK_SET);
1108 
1109  if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != uint32(MAP_AREA_MAGIC))
1110  return false;
1111 
1112  m_gridArea = header.gridArea;
1113  if (!(header.flags & MAP_AREA_NO_AREA))
1114  {
1115  m_area_map = new uint16 [16 * 16];
1116  if (fread(m_area_map, sizeof(uint16), 16 * 16, in) != 16 * 16)
1117  return false;
1118  }
1119  return true;
1120 }
uint16 gridArea
Definition: Map.h:96
uint16 * m_area_map
Definition: Map.h:160
uint16 flags
Definition: Map.h:95
uint16 m_gridArea
Definition: Map.h:159
uint32 fourcc
Definition: Map.h:94
ACE_UINT16 uint16
Definition: Define.h:72
#define MAP_AREA_NO_AREA
Definition: Map.h:90
ACE_UINT32 uint32
Definition: Define.h:71
bool GridMap::loadData ( const char *  filename)

Definition at line 1039 of file Map.cpp.

References map_fileheader::areaMapOffset, map_fileheader::areaMapSize, map_fileheader::heightMapOffset, map_fileheader::heightMapSize, map_fileheader::liquidMapOffset, map_fileheader::liquidMapSize, map_fileheader::mapMagic, sLog, and map_fileheader::versionMagic.

1040 {
1041  // Unload old data if exist
1042  unloadData();
1043 
1044  map_fileheader header;
1045  // Not return error if file not found
1046  FILE* in = fopen(filename, "rb");
1047  if (!in)
1048  return true;
1049 
1050  if (fread(&header, sizeof(header), 1, in) != 1)
1051  {
1052  fclose(in);
1053  return false;
1054  }
1055 
1056  if (header.mapMagic == uint32(MAP_MAGIC) && header.versionMagic == uint32(MAP_VERSION_MAGIC))
1057  {
1058  // loadup area data
1059  if (header.areaMapOffset && !loadAreaData(in, header.areaMapOffset, header.areaMapSize))
1060  {
1061  sLog.outError("Error loading map area data\n");
1062  fclose(in);
1063  return false;
1064  }
1065  // loadup height data
1066  if (header.heightMapOffset && !loadHeightData(in, header.heightMapOffset, header.heightMapSize))
1067  {
1068  sLog.outError("Error loading map height data\n");
1069  fclose(in);
1070  return false;
1071  }
1072  // loadup liquid data
1073  if (header.liquidMapOffset && !loadLiquidData(in, header.liquidMapOffset, header.liquidMapSize))
1074  {
1075  sLog.outError("Error loading map liquids data\n");
1076  fclose(in);
1077  return false;
1078  }
1079  fclose(in);
1080  return true;
1081  }
1082  sLog.outError("Map file '%s' is from an incompatible clientversion. Please recreate using the mapextractor.", filename);
1083  fclose(in);
1084  return false;
1085 }
uint32 areaMapSize
Definition: Map.h:81
void unloadData()
Definition: Map.cpp:1087
#define sLog
Log class singleton.
Definition: Log.h:187
uint32 areaMapOffset
Definition: Map.h:80
uint32 heightMapOffset
Definition: Map.h:82
bool loadLiquidData(FILE *in, uint32 offset, uint32 size)
Definition: Map.cpp:1168
uint32 liquidMapOffset
Definition: Map.h:84
uint32 liquidMapSize
Definition: Map.h:85
uint32 heightMapSize
Definition: Map.h:83
bool loadAreaData(FILE *in, uint32 offset, uint32 size)
Definition: Map.cpp:1104
uint32 mapMagic
Definition: Map.h:77
ACE_UINT32 uint32
Definition: Define.h:71
uint32 versionMagic
Definition: Map.h:78
bool loadHeightData(FILE *in, uint32 offset, uint32 size)
Definition: Map.cpp:1122
bool GridMap::loadHeightData ( FILE *  in,
uint32  offset,
uint32  size 
)
private

Definition at line 1122 of file Map.cpp.

References map_heightHeader::flags, map_heightHeader::fourcc, getHeightFromFlat(), getHeightFromFloat(), getHeightFromUint16(), getHeightFromUint8(), map_heightHeader::gridHeight, map_heightHeader::gridMaxHeight, MAP_HEIGHT_AS_INT16, MAP_HEIGHT_AS_INT8, and MAP_HEIGHT_NO_HEIGHT.

1123 {
1124  map_heightHeader header;
1125  fseek(in, offset, SEEK_SET);
1126 
1127  if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != uint32(MAP_HEIGHT_MAGIC))
1128  return false;
1129 
1130  m_gridHeight = header.gridHeight;
1131  if (!(header.flags & MAP_HEIGHT_NO_HEIGHT))
1132  {
1133  if ((header.flags & MAP_HEIGHT_AS_INT16))
1134  {
1135  m_uint16_V9 = new uint16 [129 * 129];
1136  m_uint16_V8 = new uint16 [128 * 128];
1137  if (fread(m_uint16_V9, sizeof(uint16), 129 * 129, in) != 129 * 129 ||
1138  fread(m_uint16_V8, sizeof(uint16), 128 * 128, in) != 128 * 128)
1139  return false;
1140  m_gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 65535;
1142  }
1143  else if ((header.flags & MAP_HEIGHT_AS_INT8))
1144  {
1145  m_uint8_V9 = new uint8 [129 * 129];
1146  m_uint8_V8 = new uint8 [128 * 128];
1147  if (fread(m_uint8_V9, sizeof(uint8), 129 * 129, in) != 129 * 129 ||
1148  fread(m_uint8_V8, sizeof(uint8), 128 * 128, in) != 128 * 128)
1149  return false;
1150  m_gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 255;
1152  }
1153  else
1154  {
1155  m_V9 = new float [129 * 129];
1156  m_V8 = new float [128 * 128];
1157  if (fread(m_V9, sizeof(float), 129 * 129, in) != 129 * 129 ||
1158  fread(m_V8, sizeof(float), 128 * 128, in) != 128 * 128)
1159  return false;
1161  }
1162  }
1163  else
1165  return true;
1166 }
float * m_V9
Definition: Map.h:166
float getHeightFromUint8(float x, float y) const
Definition: Map.cpp:1301
uint32 fourcc
Definition: Map.h:105
#define MAP_HEIGHT_NO_HEIGHT
Definition: Map.h:99
float gridMaxHeight
Definition: Map.h:108
uint32 flags
Definition: Map.h:106
pGetHeightPtr m_gridGetHeight
Definition: Map.h:193
uint8 * m_uint8_V8
Definition: Map.h:174
float * m_V8
Definition: Map.h:172
float getHeightFromUint16(float x, float y) const
Definition: Map.cpp:1368
ACE_UINT8 uint8
Definition: Define.h:73
uint8 * m_uint8_V9
Definition: Map.h:168
float getHeightFromFlat(float x, float y) const
Definition: Map.cpp:1214
float m_gridIntHeightMultiplier
Definition: Map.h:163
float getHeightFromFloat(float x, float y) const
Definition: Map.cpp:1219
uint16 * m_uint16_V8
Definition: Map.h:173
float gridHeight
Definition: Map.h:107
uint16 * m_uint16_V9
Definition: Map.h:167
float m_gridHeight
Definition: Map.h:162
ACE_UINT16 uint16
Definition: Define.h:72
#define MAP_HEIGHT_AS_INT8
Definition: Map.h:101
ACE_UINT32 uint32
Definition: Define.h:71
#define MAP_HEIGHT_AS_INT16
Definition: Map.h:100
bool GridMap::loadLiquidData ( FILE *  in,
uint32  offset,
uint32  size 
)
private

Definition at line 1168 of file Map.cpp.

References map_liquidHeader::flags, map_liquidHeader::fourcc, map_liquidHeader::height, map_liquidHeader::liquidLevel, map_liquidHeader::liquidType, MAP_LIQUID_NO_HEIGHT, MAP_LIQUID_NO_TYPE, map_liquidHeader::offsetX, map_liquidHeader::offsetY, and map_liquidHeader::width.

1169 {
1170  map_liquidHeader header;
1171  fseek(in, offset, SEEK_SET);
1172 
1173  if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != uint32(MAP_LIQUID_MAGIC))
1174  return false;
1175 
1176  m_liquidType = header.liquidType;
1177  m_liquid_offX = header.offsetX;
1178  m_liquid_offY = header.offsetY;
1179  m_liquid_width = header.width;
1180  m_liquid_height = header.height;
1181  m_liquidLevel = header.liquidLevel;
1182 
1183  if (!(header.flags & MAP_LIQUID_NO_TYPE))
1184  {
1185  _liquidEntry = new uint16[16*16];
1186  if (fread(_liquidEntry, sizeof(uint16), 16*16, in) != 16*16)
1187  return false;
1188 
1189  _liquidFlags = new uint8[16*16];
1190  if (fread(_liquidFlags, sizeof(uint8), 16*16, in) != 16*16)
1191  return false;
1192  }
1193  if (!(header.flags & MAP_LIQUID_NO_HEIGHT))
1194  {
1195  _liquidMap = new float[m_liquid_width * m_liquid_height];
1196  if (fread(_liquidMap, sizeof(float), m_liquid_width * m_liquid_height, in) != m_liquid_width * m_liquid_height)
1197  return false;
1198  }
1199  return true;
1200 }
#define MAP_LIQUID_NO_TYPE
Definition: Map.h:111
uint8 offsetY
Definition: Map.h:120
uint8 height
Definition: Map.h:122
uint16 flags
Definition: Map.h:117
uint8 m_liquid_offY
Definition: Map.h:179
uint8 offsetX
Definition: Map.h:119
#define MAP_LIQUID_NO_HEIGHT
Definition: Map.h:112
uint32 fourcc
Definition: Map.h:116
uint16 liquidType
Definition: Map.h:118
uint8 width
Definition: Map.h:121
float liquidLevel
Definition: Map.h:123
ACE_UINT8 uint8
Definition: Define.h:73
float m_liquidLevel
Definition: Map.h:182
uint8 m_liquid_offX
Definition: Map.h:178
uint16 m_liquidType
Definition: Map.h:177
ACE_UINT16 uint16
Definition: Define.h:72
ACE_UINT32 uint32
Definition: Define.h:71
uint8 m_liquid_width
Definition: Map.h:180
uint8 m_liquid_height
Definition: Map.h:181
uint8 * _liquidFlags
Definition: Map.h:184
uint16 * _liquidEntry
Definition: Map.h:183
float * _liquidMap
Definition: Map.h:185
void GridMap::unloadData ( )

Definition at line 1087 of file Map.cpp.

References getHeightFromFlat().

Referenced by Map::UnloadGrid().

1088 {
1089  delete[] m_area_map;
1090  delete[] m_V9;
1091  delete[] m_V8;
1092  delete[] _liquidEntry;
1093  delete[] _liquidFlags;
1094  delete[] _liquidMap;
1095  m_area_map = NULL;
1096  m_V9 = NULL;
1097  m_V8 = NULL;
1098  _liquidEntry = NULL;
1099  _liquidFlags = NULL;
1100  _liquidMap = NULL;
1102 }
float * m_V9
Definition: Map.h:166
pGetHeightPtr m_gridGetHeight
Definition: Map.h:193
float * m_V8
Definition: Map.h:172
float getHeightFromFlat(float x, float y) const
Definition: Map.cpp:1214
uint16 * m_area_map
Definition: Map.h:160
uint8 * _liquidFlags
Definition: Map.h:184
uint16 * _liquidEntry
Definition: Map.h:183
float * _liquidMap
Definition: Map.h:185

Member Data Documentation

union { ... }
union { ... }
uint16* GridMap::_liquidEntry
private

Definition at line 183 of file Map.h.

uint8* GridMap::_liquidFlags
private

Definition at line 184 of file Map.h.

float* GridMap::_liquidMap
private

Definition at line 185 of file Map.h.

uint16* GridMap::m_area_map
private

Definition at line 160 of file Map.h.

uint32 GridMap::m_flags
private

Definition at line 157 of file Map.h.

uint16 GridMap::m_gridArea
private

Definition at line 159 of file Map.h.

pGetHeightPtr GridMap::m_gridGetHeight
private

Definition at line 193 of file Map.h.

float GridMap::m_gridHeight
private

Definition at line 162 of file Map.h.

float GridMap::m_gridIntHeightMultiplier
private

Definition at line 163 of file Map.h.

uint8 GridMap::m_liquid_height
private

Definition at line 181 of file Map.h.

uint8 GridMap::m_liquid_offX
private

Definition at line 178 of file Map.h.

uint8 GridMap::m_liquid_offY
private

Definition at line 179 of file Map.h.

uint8 GridMap::m_liquid_width
private

Definition at line 180 of file Map.h.

float GridMap::m_liquidLevel
private

Definition at line 182 of file Map.h.

uint16 GridMap::m_liquidType
private

Definition at line 177 of file Map.h.

uint16* GridMap::m_uint16_V8

Definition at line 173 of file Map.h.

uint16* GridMap::m_uint16_V9

Definition at line 167 of file Map.h.

uint8* GridMap::m_uint8_V8

Definition at line 174 of file Map.h.

uint8* GridMap::m_uint8_V9

Definition at line 168 of file Map.h.

float* GridMap::m_V8

Definition at line 172 of file Map.h.

float* GridMap::m_V9

Definition at line 166 of file Map.h.


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