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

#include "GridTerrainData.h"

Public Member Functions

 GridTerrainData ()
 
 ~GridTerrainData ()
 
TerrainMapDataReadResult Load (std::string const &mapFileName)
 
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(GridTerrainData::* GetHeightPtr) (float x, float y) const
 

Private Member Functions

bool LoadAreaData (std::ifstream &fileStream, uint32 const offset)
 
bool LoadHeightData (std::ifstream &fileStream, uint32 const offset)
 
bool LoadLiquidData (std::ifstream &fileStream, uint32 const offset)
 
bool LoadHolesData (std::ifstream &fileStream, uint32 const offset)
 
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

std::unique_ptr< LoadedAreaData_loadedAreaData
 
std::unique_ptr< LoadedHeightData_loadedHeightData
 
std::unique_ptr< LoadedLiquidData_loadedLiquidData
 
std::unique_ptr< LoadedHoleData_loadedHoleData
 
GetHeightPtr _gridGetHeight
 

Detailed Description

Member Typedef Documentation

◆ GetHeightPtr

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

Constructor & Destructor Documentation

◆ GridTerrainData()

GridTerrainData::GridTerrainData ( )
13{
15}
GetHeightPtr _gridGetHeight
Definition GridTerrainData.h:237
float getHeightFromFlat(float x, float y) const
Definition GridTerrainData.cpp:229

References _gridGetHeight, and getHeightFromFlat().

◆ ~GridTerrainData()

GridTerrainData::~GridTerrainData ( )
inline
245{ };

Member Function Documentation

◆ getArea()

uint16 GridTerrainData::getArea ( float  x,
float  y 
) const
215{
216 if (!_loadedAreaData)
217 return 0;
218
219 if (!_loadedAreaData->areaMap)
220 return _loadedAreaData->gridArea;
221
222 x = 16 * (32 - x / SIZE_OF_GRIDS);
223 y = 16 * (32 - y / SIZE_OF_GRIDS);
224 int lx = (int)x & 15;
225 int ly = (int)y & 15;
226 return _loadedAreaData->areaMap->at(lx * 16 + ly);
227}
#define SIZE_OF_GRIDS
Definition MapDefines.h:26
std::unique_ptr< LoadedAreaData > _loadedAreaData
Definition GridTerrainData.h:228

References _loadedAreaData, and SIZE_OF_GRIDS.

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

◆ getHeight()

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

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

◆ getHeightFromFlat()

float GridTerrainData::getHeightFromFlat ( float  x,
float  y 
) const
private
230{
232 return INVALID_HEIGHT;
233
234 return _loadedHeightData->gridHeight;
235}
#define INVALID_HEIGHT
Definition GridTerrainData.h:27
std::unique_ptr< LoadedHeightData > _loadedHeightData
Definition GridTerrainData.h:229

References _loadedHeightData, and INVALID_HEIGHT.

Referenced by GridTerrainData(), and LoadHeightData().

◆ getHeightFromFloat()

float GridTerrainData::getHeightFromFloat ( float  x,
float  y 
) const
private
238{
239 if (!_loadedHeightData || !_loadedHeightData->floatHeightData)
240 return INVALID_HEIGHT;
241
242 x = MAP_RESOLUTION * (32 - x / SIZE_OF_GRIDS);
243 y = MAP_RESOLUTION * (32 - y / SIZE_OF_GRIDS);
244
245 int x_int = (int)x;
246 int y_int = (int)y;
247 x -= x_int;
248 y -= y_int;
249 x_int &= (MAP_RESOLUTION - 1);
250 y_int &= (MAP_RESOLUTION - 1);
251
252 if (isHole(x_int, y_int))
253 return INVALID_HEIGHT;
254
255 // Height stored as: h5 - its v8 grid, h1-h4 - its v9 grid
256 // +--------------> X
257 // | h1-------h2 Coordinates is:
258 // | | \ 1 / | h1 0, 0
259 // | | \ / | h2 0, 1
260 // | | 2 h5 3 | h3 1, 0
261 // | | / \ | h4 1, 1
262 // | | / 4 \ | h5 1/2, 1/2
263 // | h3-------h4
264 // V Y
265 // For find height need
266 // 1 - detect triangle
267 // 2 - solve linear equation from triangle points
268 // Calculate coefficients for solve h = a*x + b*y + c
269
270 float a, b, c;
271 // Select triangle:
272 if (x + y < 1)
273 {
274 if (x > y)
275 {
276 // 1 triangle (h1, h2, h5 points)
277 float h1 = _loadedHeightData->floatHeightData->v9[(x_int) * 129 + y_int];
278 float h2 = _loadedHeightData->floatHeightData->v9[(x_int + 1) * 129 + y_int];
279 float h5 = 2 * _loadedHeightData->floatHeightData->v8[x_int * 128 + y_int];
280 a = h2 - h1;
281 b = h5 - h1 - h2;
282 c = h1;
283 }
284 else
285 {
286 // 2 triangle (h1, h3, h5 points)
287 float h1 = _loadedHeightData->floatHeightData->v9[x_int * 129 + y_int];
288 float h3 = _loadedHeightData->floatHeightData->v9[x_int * 129 + y_int + 1];
289 float h5 = 2 * _loadedHeightData->floatHeightData->v8[x_int * 128 + y_int];
290 a = h5 - h1 - h3;
291 b = h3 - h1;
292 c = h1;
293 }
294 }
295 else
296 {
297 if (x > y)
298 {
299 // 3 triangle (h2, h4, h5 points)
300 float h2 = _loadedHeightData->floatHeightData->v9[(x_int + 1) * 129 + y_int];
301 float h4 = _loadedHeightData->floatHeightData->v9[(x_int + 1) * 129 + y_int + 1];
302 float h5 = 2 * _loadedHeightData->floatHeightData->v8[x_int * 128 + y_int];
303 a = h2 + h4 - h5;
304 b = h4 - h2;
305 c = h5 - h4;
306 }
307 else
308 {
309 // 4 triangle (h3, h4, h5 points)
310 float h3 = _loadedHeightData->floatHeightData->v9[(x_int) * 129 + y_int + 1];
311 float h4 = _loadedHeightData->floatHeightData->v9[(x_int + 1) * 129 + y_int + 1];
312 float h5 = 2 * _loadedHeightData->floatHeightData->v8[x_int * 128 + y_int];
313 a = h4 - h3;
314 b = h3 + h4 - h5;
315 c = h5 - h4;
316 }
317 }
318 // Calculate height
319 return a * x + b * y + c;
320}
#define MAP_RESOLUTION
Definition GridDefines.h:49
bool isHole(int row, int col) const
Definition GridTerrainData.cpp:462

References _loadedHeightData, INVALID_HEIGHT, isHole(), MAP_RESOLUTION, and SIZE_OF_GRIDS.

Referenced by LoadHeightData().

◆ getHeightFromUint16()

float GridTerrainData::getHeightFromUint16 ( float  x,
float  y 
) const
private
393{
394 if (!_loadedHeightData || !_loadedHeightData->uint16HeightData)
395 return INVALID_HEIGHT;
396
397 x = MAP_RESOLUTION * (32 - x / SIZE_OF_GRIDS);
398 y = MAP_RESOLUTION * (32 - y / SIZE_OF_GRIDS);
399
400 int x_int = (int)x;
401 int y_int = (int)y;
402 x -= x_int;
403 y -= y_int;
404 x_int &= (MAP_RESOLUTION - 1);
405 y_int &= (MAP_RESOLUTION - 1);
406
407 if (isHole(x_int, y_int))
408 return INVALID_HEIGHT;
409
410 int32 a, b, c;
411 uint16* V9_h1_ptr = &_loadedHeightData->uint16HeightData->v9[x_int * 128 + x_int + y_int];
412 if (x + y < 1)
413 {
414 if (x > y)
415 {
416 // 1 triangle (h1, h2, h5 points)
417 int32 h1 = V9_h1_ptr[0];
418 int32 h2 = V9_h1_ptr[129];
419 int32 h5 = 2 * _loadedHeightData->uint16HeightData->v8[x_int * 128 + y_int];
420 a = h2 - h1;
421 b = h5 - h1 - h2;
422 c = h1;
423 }
424 else
425 {
426 // 2 triangle (h1, h3, h5 points)
427 int32 h1 = V9_h1_ptr[0];
428 int32 h3 = V9_h1_ptr[1];
429 int32 h5 = 2 * _loadedHeightData->uint16HeightData->v8[x_int * 128 + y_int];
430 a = h5 - h1 - h3;
431 b = h3 - h1;
432 c = h1;
433 }
434 }
435 else
436 {
437 if (x > y)
438 {
439 // 3 triangle (h2, h4, h5 points)
440 int32 h2 = V9_h1_ptr[129];
441 int32 h4 = V9_h1_ptr[130];
442 int32 h5 = 2 * _loadedHeightData->uint16HeightData->v8[x_int * 128 + y_int];
443 a = h2 + h4 - h5;
444 b = h4 - h2;
445 c = h5 - h4;
446 }
447 else
448 {
449 // 4 triangle (h3, h4, h5 points)
450 int32 h3 = V9_h1_ptr[1];
451 int32 h4 = V9_h1_ptr[130];
452 int32 h5 = 2 * _loadedHeightData->uint16HeightData->v8[x_int * 128 + y_int];
453 a = h4 - h3;
454 b = h3 + h4 - h5;
455 c = h5 - h4;
456 }
457 }
458 // Calculate height
459 return (float)((a * x) + (b * y) + c) * _loadedHeightData->uint16HeightData->gridIntHeightMultiplier + _loadedHeightData->gridHeight;
460}
std::int32_t int32
Definition Define.h:103
std::uint16_t uint16
Definition Define.h:108

References _loadedHeightData, INVALID_HEIGHT, isHole(), MAP_RESOLUTION, and SIZE_OF_GRIDS.

Referenced by LoadHeightData().

◆ getHeightFromUint8()

float GridTerrainData::getHeightFromUint8 ( float  x,
float  y 
) const
private
323{
324 if (!_loadedHeightData || !_loadedHeightData->uint8HeightData)
325 return INVALID_HEIGHT;
326
327 x = MAP_RESOLUTION * (32 - x / SIZE_OF_GRIDS);
328 y = MAP_RESOLUTION * (32 - y / SIZE_OF_GRIDS);
329
330 int x_int = (int)x;
331 int y_int = (int)y;
332 x -= x_int;
333 y -= y_int;
334 x_int &= (MAP_RESOLUTION - 1);
335 y_int &= (MAP_RESOLUTION - 1);
336
337 if (isHole(x_int, y_int))
338 return INVALID_HEIGHT;
339
340 int32 a, b, c;
341 uint8* V9_h1_ptr = &_loadedHeightData->uint8HeightData->v9[x_int * 128 + x_int + y_int];
342 if (x + y < 1)
343 {
344 if (x > y)
345 {
346 // 1 triangle (h1, h2, h5 points)
347 int32 h1 = V9_h1_ptr[0];
348 int32 h2 = V9_h1_ptr[129];
349 int32 h5 = 2 * _loadedHeightData->uint8HeightData->v8[x_int * 128 + y_int];
350 a = h2 - h1;
351 b = h5 - h1 - h2;
352 c = h1;
353 }
354 else
355 {
356 // 2 triangle (h1, h3, h5 points)
357 int32 h1 = V9_h1_ptr[0];
358 int32 h3 = V9_h1_ptr[1];
359 int32 h5 = 2 * _loadedHeightData->uint8HeightData->v8[x_int * 128 + y_int];
360 a = h5 - h1 - h3;
361 b = h3 - h1;
362 c = h1;
363 }
364 }
365 else
366 {
367 if (x > y)
368 {
369 // 3 triangle (h2, h4, h5 points)
370 int32 h2 = V9_h1_ptr[129];
371 int32 h4 = V9_h1_ptr[130];
372 int32 h5 = 2 * _loadedHeightData->uint8HeightData->v8[x_int * 128 + y_int];
373 a = h2 + h4 - h5;
374 b = h4 - h2;
375 c = h5 - h4;
376 }
377 else
378 {
379 // 4 triangle (h3, h4, h5 points)
380 int32 h3 = V9_h1_ptr[1];
381 int32 h4 = V9_h1_ptr[130];
382 int32 h5 = 2 * _loadedHeightData->uint8HeightData->v8[x_int * 128 + y_int];
383 a = h4 - h3;
384 b = h3 + h4 - h5;
385 c = h5 - h4;
386 }
387 }
388 // Calculate height
389 return (float)((a * x) + (b * y) + c) * _loadedHeightData->uint8HeightData->gridIntHeightMultiplier + _loadedHeightData->gridHeight;
390}
std::uint8_t uint8
Definition Define.h:109

References _loadedHeightData, INVALID_HEIGHT, isHole(), MAP_RESOLUTION, and SIZE_OF_GRIDS.

Referenced by LoadHeightData().

◆ GetLiquidData()

LiquidData const GridTerrainData::GetLiquidData ( float  x,
float  y,
float  z,
float  collisionHeight,
uint8  ReqLiquidType 
) const
531{
532 LiquidData liquidData;
534 return liquidData;
535
536 // Check water type (if no water return)
537 if (_loadedLiquidData->liquidGlobalFlags || _loadedLiquidData->liquidFlags)
538 {
539 // Get cell
540 float cx = MAP_RESOLUTION * (32 - x / SIZE_OF_GRIDS);
541 float cy = MAP_RESOLUTION * (32 - y / SIZE_OF_GRIDS);
542
543 int x_int = (int)cx & (MAP_RESOLUTION - 1);
544 int y_int = (int)cy & (MAP_RESOLUTION - 1);
545
546 // Check water type in cell
547 int idx = (x_int >> 3) * 16 + (y_int >> 3);
548 uint8 type = _loadedLiquidData->liquidFlags ? _loadedLiquidData->liquidFlags->at(idx) : _loadedLiquidData->liquidGlobalFlags;
549 uint32 entry = _loadedLiquidData->liquidEntry ? _loadedLiquidData->liquidEntry->at(idx) : _loadedLiquidData->liquidGlobalEntry;
550 if (LiquidTypeEntry const* liquidEntry = sLiquidTypeStore.LookupEntry(entry))
551 {
553 uint32 liqTypeIdx = liquidEntry->Type;
554 if (entry < 21)
555 {
556 if (AreaTableEntry const* area = sAreaTableStore.LookupEntry(getArea(x, y)))
557 {
558 uint32 overrideLiquid = area->LiquidTypeOverride[liquidEntry->Type];
559 if (!overrideLiquid && area->zone)
560 {
561 area = sAreaTableStore.LookupEntry(area->zone);
562 if (area)
563 overrideLiquid = area->LiquidTypeOverride[liquidEntry->Type];
564 }
565
566 if (LiquidTypeEntry const* liq = sLiquidTypeStore.LookupEntry(overrideLiquid))
567 {
568 entry = overrideLiquid;
569 liqTypeIdx = liq->Type;
570 }
571 }
572 }
573
574 type |= 1 << liqTypeIdx;
575 }
576
577 // Check req liquid type mask
578 if (type != 0 && (!ReqLiquidType || (ReqLiquidType & type) != 0))
579 {
580 // Check water level:
581 // Check water height map
582 int lx_int = x_int - _loadedLiquidData->liquidOffY;
583 int ly_int = y_int - _loadedLiquidData->liquidOffX;
584 if (lx_int >= 0 && lx_int < _loadedLiquidData->liquidHeight && ly_int >= 0 && ly_int < _loadedLiquidData->liquidWidth)
585 {
586 // Get water level
587 float liquid_level = _loadedLiquidData->liquidMap ? _loadedLiquidData->liquidMap->at(lx_int * _loadedLiquidData->liquidWidth + ly_int) : _loadedLiquidData->liquidLevel;
588 // Get ground level
589 float ground_level = getHeight(x, y);
590
591 // Check water level and ground level (sub 0.2 for fix some errors)
592 if (liquid_level >= ground_level && z >= ground_level - 0.2f)
593 {
594 // All ok in water -> store data
595 liquidData.Entry = entry;
596 liquidData.Flags = type;
597 liquidData.Level = liquid_level;
598 liquidData.DepthLevel = ground_level;
599
600 // For speed check as int values
601 float delta = liquid_level - z;
602
603 if (delta > collisionHeight)
604 liquidData.Status = LIQUID_MAP_UNDER_WATER;
605 else if (delta > 0.0f)
606 liquidData.Status = LIQUID_MAP_IN_WATER;
607 else if (delta > -0.1f)
608 liquidData.Status = LIQUID_MAP_WATER_WALK;
609 else
610 liquidData.Status = LIQUID_MAP_ABOVE_WATER;
611 }
612 }
613 }
614 }
615
616 return liquidData;
617}
DBCStorage< AreaTableEntry > sAreaTableStore(AreaTableEntryfmt)
DBCStorage< LiquidTypeEntry > sLiquidTypeStore(LiquidTypefmt)
std::uint32_t uint32
Definition Define.h:107
@ LIQUID_MAP_UNDER_WATER
Definition GridTerrainData.h:195
@ LIQUID_MAP_IN_WATER
Definition GridTerrainData.h:194
@ LIQUID_MAP_ABOVE_WATER
Definition GridTerrainData.h:192
@ LIQUID_MAP_WATER_WALK
Definition GridTerrainData.h:193
#define MAP_LIQUID_TYPE_DARK_WATER
Definition GridTerrainData.h:42
float getHeight(float x, float y) const
Definition GridTerrainData.h:249
std::unique_ptr< LoadedLiquidData > _loadedLiquidData
Definition GridTerrainData.h:230
uint16 getArea(float x, float y) const
Definition GridTerrainData.cpp:214
Definition DBCStructure.h:518
Definition GridTerrainData.h:199
float Level
Definition GridTerrainData.h:204
uint32 Flags
Definition GridTerrainData.h:203
uint32 Entry
Definition GridTerrainData.h:202
LiquidStatus Status
Definition GridTerrainData.h:206
float DepthLevel
Definition GridTerrainData.h:205
Definition DBCStructure.h:1282

References _loadedLiquidData, 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 GridTerrainData::getLiquidLevel ( float  x,
float  y 
) const
508{
510 return INVALID_HEIGHT;
511
512 if (!_loadedLiquidData->liquidMap)
513 return _loadedLiquidData->liquidLevel;
514
515 x = MAP_RESOLUTION * (32 - x / SIZE_OF_GRIDS);
516 y = MAP_RESOLUTION * (32 - y / SIZE_OF_GRIDS);
517
518 int cx_int = ((int)x & (MAP_RESOLUTION - 1)) - _loadedLiquidData->liquidOffY;
519 int cy_int = ((int)y & (MAP_RESOLUTION - 1)) - _loadedLiquidData->liquidOffX;
520
521 if (cx_int < 0 || cx_int >= _loadedLiquidData->liquidHeight)
522 return INVALID_HEIGHT;
523 if (cy_int < 0 || cy_int >= _loadedLiquidData->liquidWidth)
524 return INVALID_HEIGHT;
525
526 return _loadedLiquidData->liquidMap->at(cx_int * _loadedLiquidData->liquidWidth + cy_int);
527}

References _loadedLiquidData, INVALID_HEIGHT, MAP_RESOLUTION, and SIZE_OF_GRIDS.

◆ getMinHeight()

float GridTerrainData::getMinHeight ( float  x,
float  y 
) const
478{
479 if (!_loadedHeightData || !_loadedHeightData->minHeightPlanes)
480 return MIN_HEIGHT;
481
483
484 int32 doubleGridX = int32(std::floor(-(x - MAP_HALFSIZE) / CENTER_GRID_OFFSET));
485 int32 doubleGridY = int32(std::floor(-(y - MAP_HALFSIZE) / CENTER_GRID_OFFSET));
486
487 float gx = x - (int32(gridCoord.x_coord) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS;
488 float gy = y - (int32(gridCoord.y_coord) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS;
489
490 uint32 quarterIndex = 0;
491 if (doubleGridY & 1)
492 {
493 if (doubleGridX & 1)
494 quarterIndex = 4 + (gx <= gy);
495 else
496 quarterIndex = 2 + ((-SIZE_OF_GRIDS - gx) > gy);
497 }
498 else if (doubleGridX & 1)
499 quarterIndex = 6 + ((-SIZE_OF_GRIDS - gx) <= gy);
500 else
501 quarterIndex = gx > gy;
502
503 G3D::Ray ray = G3D::Ray::fromOriginAndDirection(G3D::Vector3(gx, gy, 0.0f), G3D::Vector3::unitZ());
504 return ray.intersection(_loadedHeightData->minHeightPlanes->at(quarterIndex)).z;
505}
#define CENTER_GRID_ID
Definition GridDefines.h:35
#define CENTER_GRID_OFFSET
Definition GridDefines.h:37
#define MAP_HALFSIZE
Definition GridDefines.h:52
#define MIN_HEIGHT
Definition GridTerrainData.h:29
GridCoord ComputeGridCoordSimple(float x, float y)
Definition GridDefines.h:186
Definition GridDefines.h:84
uint32 x_coord
Definition GridDefines.h:151
uint32 y_coord
Definition GridDefines.h:152

References _loadedHeightData, CENTER_GRID_ID, CENTER_GRID_OFFSET, Acore::ComputeGridCoordSimple(), MAP_HALFSIZE, MIN_HEIGHT, SIZE_OF_GRIDS, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

◆ isHole()

bool GridTerrainData::isHole ( int  row,
int  col 
) const
private
463{
464 if (!_loadedHoleData)
465 return false;
466
467 int cellRow = row / 8; // 8 squares per cell
468 int cellCol = col / 8;
469 int holeRow = row % 8 / 2;
470 int holeCol = (col - (cellCol * 8)) / 2;
471
472 uint16 hole = _loadedHoleData->holes[cellRow * 16 + cellCol];
473
474 return (hole & holetab_h[holeCol] & holetab_v[holeRow]) != 0;
475}
uint16 const holetab_h[4]
Definition GridTerrainData.cpp:9
uint16 const holetab_v[4]
Definition GridTerrainData.cpp:10
std::unique_ptr< LoadedHoleData > _loadedHoleData
Definition GridTerrainData.h:231

References _loadedHoleData, holetab_h, and holetab_v.

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

◆ Load()

TerrainMapDataReadResult GridTerrainData::Load ( std::string const &  mapFileName)
18{
19 // Check if file exists, we do this first as we need to
20 // differentiate between file existing and any other file errors
21 if (!std::filesystem::exists(mapFileName))
23
24 // Start the input stream and check for any errors
25 std::ifstream fileStream(mapFileName, std::ios::binary);
26 if (fileStream.fail())
28
29 // Read the map header
30 map_fileheader header;
31 if (!fileStream.read(reinterpret_cast<char*>(&header), sizeof(header)))
33
34 // Check for valid map and version magics
35 if (header.mapMagic != MapMagic.asUInt || header.versionMagic != MapVersionMagic)
37
38 // Load area data
39 if (header.areaMapOffset && !LoadAreaData(fileStream, header.areaMapOffset))
41
42 // Load height data
43 if (header.heightMapOffset && !LoadHeightData(fileStream, header.heightMapOffset))
45
46 // Load liquid data
47 if (header.liquidMapOffset && !LoadLiquidData(fileStream, header.liquidMapOffset))
49
50 // Load hole data
51 if (header.holesSize && !LoadHolesData(fileStream, header.holesOffset))
53
55}
const uint32 MapVersionMagic
Definition GridTerrainData.h:54
const u_map_magic MapMagic
Definition GridTerrainData.h:53
bool LoadHolesData(std::ifstream &fileStream, uint32 const offset)
Definition GridTerrainData.cpp:203
bool LoadAreaData(std::ifstream &fileStream, uint32 const offset)
Definition GridTerrainData.cpp:57
bool LoadLiquidData(std::ifstream &fileStream, uint32 const offset)
Definition GridTerrainData.cpp:166
bool LoadHeightData(std::ifstream &fileStream, uint32 const offset)
Definition GridTerrainData.cpp:76
Definition GridTerrainData.h:60
uint32 mapMagic
Definition GridTerrainData.h:61
uint32 holesSize
Definition GridTerrainData.h:71
uint32 areaMapOffset
Definition GridTerrainData.h:64
uint32 heightMapOffset
Definition GridTerrainData.h:66
uint32 holesOffset
Definition GridTerrainData.h:70
uint32 versionMagic
Definition GridTerrainData.h:62
uint32 liquidMapOffset
Definition GridTerrainData.h:68
uint32 asUInt
Definition GridTerrainData.h:50

References map_fileheader::areaMapOffset, u_map_magic::asUInt, map_fileheader::heightMapOffset, map_fileheader::holesOffset, map_fileheader::holesSize, InvalidAreaData, InvalidHeightData, InvalidHoleData, InvalidLiquidData, InvalidMagic, map_fileheader::liquidMapOffset, LoadAreaData(), LoadHeightData(), LoadHolesData(), LoadLiquidData(), MapMagic, map_fileheader::mapMagic, MapVersionMagic, NotFound, ReadError, Success, and map_fileheader::versionMagic.

◆ LoadAreaData()

bool GridTerrainData::LoadAreaData ( std::ifstream &  fileStream,
uint32 const  offset 
)
private
58{
59 fileStream.seekg(offset);
60
61 map_areaHeader header;
62 if (!fileStream.read(reinterpret_cast<char*>(&header), sizeof(header)) || header.fourcc != MapAreaMagic.asUInt)
63 return false;
64
65 _loadedAreaData = std::make_unique<LoadedAreaData>();
66 _loadedAreaData->gridArea = header.gridArea;
67 if (!(header.flags & MAP_AREA_NO_AREA))
68 {
69 _loadedAreaData->areaMap = std::make_unique<LoadedAreaData::AreaMapType>();
70 if (!fileStream.read(reinterpret_cast<char*>(_loadedAreaData->areaMap.get()), sizeof(LoadedAreaData::AreaMapType)))
71 return false;
72 }
73 return true;
74}
const u_map_magic MapAreaMagic
Definition GridTerrainData.h:55
#define MAP_AREA_NO_AREA
Definition GridTerrainData.h:74
std::array< uint16, 16 *16 > AreaMapType
Definition GridTerrainData.h:118
Definition GridTerrainData.h:77
uint32 fourcc
Definition GridTerrainData.h:78
uint16 gridArea
Definition GridTerrainData.h:80
uint16 flags
Definition GridTerrainData.h:79

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

Referenced by Load().

◆ LoadHeightData()

bool GridTerrainData::LoadHeightData ( std::ifstream &  fileStream,
uint32 const  offset 
)
private
77{
78 fileStream.seekg(offset);
79
80 map_heightHeader header;
81 if (!fileStream.read(reinterpret_cast<char*>(&header), sizeof(header)) || header.fourcc != MapHeightMagic.asUInt)
82 return false;
83
84 _loadedHeightData = std::make_unique<LoadedHeightData>();
85 _loadedHeightData->gridHeight = header.gridHeight;
86 if (!(header.flags & MAP_HEIGHT_NO_HEIGHT))
87 {
88 if ((header.flags & MAP_HEIGHT_AS_INT16))
89 {
90 _loadedHeightData->uint16HeightData = std::make_unique<LoadedHeightData::Uint16HeightData>();
91 if (!fileStream.read(reinterpret_cast<char*>(&_loadedHeightData->uint16HeightData->v9), sizeof(_loadedHeightData->uint16HeightData->v9))
92 || !fileStream.read(reinterpret_cast<char*>(&_loadedHeightData->uint16HeightData->v8), sizeof(_loadedHeightData->uint16HeightData->v8)))
93 return false;
94
95 _loadedHeightData->uint16HeightData->gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 65535;
97 }
98 else if ((header.flags & MAP_HEIGHT_AS_INT8))
99 {
100 _loadedHeightData->uint8HeightData = std::make_unique<LoadedHeightData::Uint8HeightData>();
101 if (!fileStream.read(reinterpret_cast<char*>(&_loadedHeightData->uint8HeightData->v9), sizeof(_loadedHeightData->uint8HeightData->v9))
102 || !fileStream.read(reinterpret_cast<char*>(&_loadedHeightData->uint8HeightData->v8), sizeof(_loadedHeightData->uint8HeightData->v8)))
103 return false;
104
105 _loadedHeightData->uint8HeightData->gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 255;
107 }
108 else
109 {
110 _loadedHeightData->floatHeightData = std::make_unique<LoadedHeightData::FloatHeightData>();
111 if (!fileStream.read(reinterpret_cast<char*>(&_loadedHeightData->floatHeightData->v9), sizeof(_loadedHeightData->floatHeightData->v9))
112 || !fileStream.read(reinterpret_cast<char*>(&_loadedHeightData->floatHeightData->v8), sizeof(_loadedHeightData->floatHeightData->v8)))
113 return false;
114
116 }
117 }
118 else
120
122 {
123 std::array<int16, 9> maxHeights;
124 std::array<int16, 9> minHeights;
125 if (!fileStream.read(reinterpret_cast<char*>(maxHeights.data()), sizeof(maxHeights)) ||
126 !fileStream.read(reinterpret_cast<char*>(minHeights.data()), sizeof(minHeights)))
127 return false;
128
129 static uint32 constexpr indices[8][3] =
130 {
131 { 3, 0, 4 },
132 { 0, 1, 4 },
133 { 1, 2, 4 },
134 { 2, 5, 4 },
135 { 5, 8, 4 },
136 { 8, 7, 4 },
137 { 7, 6, 4 },
138 { 6, 3, 4 }
139 };
140
141 static float constexpr boundGridCoords[9][2] =
142 {
143 { 0.0f, 0.0f },
144 { 0.0f, -266.66666f },
145 { 0.0f, -533.33331f },
146 { -266.66666f, 0.0f },
147 { -266.66666f, -266.66666f },
148 { -266.66666f, -533.33331f },
149 { -533.33331f, 0.0f },
150 { -533.33331f, -266.66666f },
151 { -533.33331f, -533.33331f }
152 };
153
154 _loadedHeightData->minHeightPlanes = std::make_unique<LoadedHeightData::HeightPlanesType>();
155 for (uint32 quarterIndex = 0; quarterIndex < _loadedHeightData->minHeightPlanes->size(); ++quarterIndex)
156 _loadedHeightData->minHeightPlanes->at(quarterIndex) = G3D::Plane(
157 G3D::Vector3(boundGridCoords[indices[quarterIndex][0]][0], boundGridCoords[indices[quarterIndex][0]][1], minHeights[indices[quarterIndex][0]]),
158 G3D::Vector3(boundGridCoords[indices[quarterIndex][1]][0], boundGridCoords[indices[quarterIndex][1]][1], minHeights[indices[quarterIndex][1]]),
159 G3D::Vector3(boundGridCoords[indices[quarterIndex][2]][0], boundGridCoords[indices[quarterIndex][2]][1], minHeights[indices[quarterIndex][2]])
160 );
161 }
162
163 return true;
164}
#define MAP_HEIGHT_HAS_FLIGHT_BOUNDS
Definition GridTerrainData.h:86
#define MAP_HEIGHT_AS_INT8
Definition GridTerrainData.h:85
const u_map_magic MapHeightMagic
Definition GridTerrainData.h:56
#define MAP_HEIGHT_NO_HEIGHT
Definition GridTerrainData.h:83
#define MAP_HEIGHT_AS_INT16
Definition GridTerrainData.h:84
float getHeightFromFloat(float x, float y) const
Definition GridTerrainData.cpp:237
float getHeightFromUint16(float x, float y) const
Definition GridTerrainData.cpp:392
float getHeightFromUint8(float x, float y) const
Definition GridTerrainData.cpp:322
Definition GridTerrainData.h:89
float gridMaxHeight
Definition GridTerrainData.h:93
uint32 flags
Definition GridTerrainData.h:91
float gridHeight
Definition GridTerrainData.h:92
uint32 fourcc
Definition GridTerrainData.h:90

References _gridGetHeight, _loadedHeightData, u_map_magic::asUInt, map_heightHeader::flags, map_heightHeader::fourcc, getHeightFromFlat(), getHeightFromFloat(), getHeightFromUint16(), getHeightFromUint8(), map_heightHeader::gridHeight, map_heightHeader::gridMaxHeight, MAP_HEIGHT_AS_INT16, MAP_HEIGHT_AS_INT8, MAP_HEIGHT_HAS_FLIGHT_BOUNDS, MAP_HEIGHT_NO_HEIGHT, and MapHeightMagic.

Referenced by Load().

◆ LoadHolesData()

bool GridTerrainData::LoadHolesData ( std::ifstream &  fileStream,
uint32 const  offset 
)
private
204{
205 fileStream.seekg(offset);
206
207 _loadedHoleData = std::make_unique<LoadedHoleData>();
208 if (!fileStream.read(reinterpret_cast<char*>(&_loadedHoleData->holes), sizeof(_loadedHoleData->holes)))
209 return false;
210
211 return true;
212}

References _loadedHoleData.

Referenced by Load().

◆ LoadLiquidData()

bool GridTerrainData::LoadLiquidData ( std::ifstream &  fileStream,
uint32 const  offset 
)
private
167{
168 fileStream.seekg(offset);
169
170 map_liquidHeader header;
171 if (!fileStream.read(reinterpret_cast<char*>(&header), sizeof(header)) || header.fourcc != MapLiquidMagic.asUInt)
172 return false;
173
174 _loadedLiquidData = std::make_unique<LoadedLiquidData>();
175 _loadedLiquidData->liquidGlobalEntry = header.liquidType;
176 _loadedLiquidData->liquidGlobalFlags = header.liquidFlags;
177 _loadedLiquidData->liquidOffX = header.offsetX;
178 _loadedLiquidData->liquidOffY = header.offsetY;
179 _loadedLiquidData->liquidWidth = header.width;
180 _loadedLiquidData->liquidHeight = header.height;
181 _loadedLiquidData->liquidLevel = header.liquidLevel;
182
183 if (!(header.flags & MAP_LIQUID_NO_TYPE))
184 {
185 _loadedLiquidData->liquidEntry = std::make_unique<LoadedLiquidData::LiquidEntryType>();
186 if (!fileStream.read(reinterpret_cast<char*>(_loadedLiquidData->liquidEntry.get()), sizeof(LoadedLiquidData::LiquidEntryType)))
187 return false;
188
189 _loadedLiquidData->liquidFlags = std::make_unique<LoadedLiquidData::LiquidFlagsType>();
190 if (!fileStream.read(reinterpret_cast<char*>(_loadedLiquidData->liquidFlags.get()), sizeof(LoadedLiquidData::LiquidFlagsType)))
191 return false;
192 }
193 if (!(header.flags & MAP_LIQUID_NO_HEIGHT))
194 {
195 _loadedLiquidData->liquidMap = std::make_unique<LoadedLiquidData::LiquidMapType>();
196 _loadedLiquidData->liquidMap->resize(_loadedLiquidData->liquidWidth * _loadedLiquidData->liquidHeight);
197 if (!fileStream.read(reinterpret_cast<char*>(_loadedLiquidData->liquidMap->data()), _loadedLiquidData->liquidMap->size() * sizeof(float)))
198 return false;
199 }
200 return true;
201}
#define MAP_LIQUID_NO_TYPE
Definition GridTerrainData.h:96
#define MAP_LIQUID_NO_HEIGHT
Definition GridTerrainData.h:97
const u_map_magic MapLiquidMagic
Definition GridTerrainData.h:57
std::array< uint16, 16 *16 > LiquidEntryType
Definition GridTerrainData.h:166
std::array< uint8, 16 *16 > LiquidFlagsType
Definition GridTerrainData.h:167
Definition GridTerrainData.h:100
uint8 offsetX
Definition GridTerrainData.h:105
uint32 fourcc
Definition GridTerrainData.h:101
uint8 liquidFlags
Definition GridTerrainData.h:103
uint8 width
Definition GridTerrainData.h:107
uint8 height
Definition GridTerrainData.h:108
uint8 flags
Definition GridTerrainData.h:102
uint16 liquidType
Definition GridTerrainData.h:104
uint8 offsetY
Definition GridTerrainData.h:106
float liquidLevel
Definition GridTerrainData.h:109

References _loadedLiquidData, 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 Load().

Member Data Documentation

◆ _gridGetHeight

GetHeightPtr GridTerrainData::_gridGetHeight
private

Referenced by GridTerrainData(), and LoadHeightData().

◆ _loadedAreaData

std::unique_ptr<LoadedAreaData> GridTerrainData::_loadedAreaData
private

Referenced by getArea(), and LoadAreaData().

◆ _loadedHeightData

std::unique_ptr<LoadedHeightData> GridTerrainData::_loadedHeightData
private

◆ _loadedHoleData

std::unique_ptr<LoadedHoleData> GridTerrainData::_loadedHoleData
private

Referenced by isHole(), and LoadHolesData().

◆ _loadedLiquidData

std::unique_ptr<LoadedLiquidData> GridTerrainData::_loadedLiquidData
private

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