fix(Core/Tools): Revert "Handle different slopes in mmaps and Add so… (#12111)

...me more input parameters to improve"

This reverts commit b544eb420e.
Fixes #12079
This commit is contained in:
UltraNix
2022-06-21 21:07:53 +02:00
committed by GitHub
parent 73bd2b446c
commit 113bdacb5f
10 changed files with 183 additions and 264 deletions

View File

@@ -224,9 +224,6 @@ struct rcConfig
/// The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees]
float walkableSlopeAngle;
/// The maximum slope that is considered walkable but not steep. It should be lower/equal than walkableSlopeAngle. [Limits: 0 <= value < 90] [Units: Degrees]
float walkableSlopeAngleNotSteep;
/// Minimum floor to 'ceiling' height that will still allow the floor area to
/// be considered walkable. [Limit: >= 3] [Units: vx]
int walkableHeight;
@@ -813,7 +810,7 @@ bool rcCreateHeightfield(rcContext* ctx, rcHeightfield& hf, int width, int heigh
/// @param[in] nt The number of triangles.
/// @param[out] areas The triangle area ids. [Length: >= @p nt]
void rcMarkWalkableTriangles(rcContext* ctx, const float walkableSlopeAngle, const float* verts, int nv,
const int* tris, int nt, unsigned char* areas, unsigned char areaType = RC_WALKABLE_AREA);
const int* tris, int nt, unsigned char* areas);
/// Sets the area id of all triangles with a slope greater than or equal to the specified value to #RC_NULL_AREA.
/// @ingroup recast

View File

@@ -334,7 +334,7 @@ static void calcTriNormal(const float* v0, const float* v1, const float* v2, flo
void rcMarkWalkableTriangles(rcContext* ctx, const float walkableSlopeAngle,
const float* verts, int nv,
const int* tris, int nt,
unsigned char* areas, unsigned char areaType)
unsigned char* areas)
{
rcIgnoreUnused(ctx);
rcIgnoreUnused(nv);
@@ -349,7 +349,7 @@ void rcMarkWalkableTriangles(rcContext* ctx, const float walkableSlopeAngle,
calcTriNormal(&verts[tri[0]*3], &verts[tri[1]*3], &verts[tri[2]*3], norm);
// Check if the face is walkable.
if (norm[1] > walkableThr)
areas[i] = areaType;
areas[i] = RC_WALKABLE_AREA;
}
}

View File

@@ -13,7 +13,7 @@
#define SIZE_OF_GRIDS 533.3333f
#define MMAP_MAGIC 0x4d4d4150 // 'MMAP'
#define MMAP_VERSION 14
#define MMAP_VERSION 15
struct MmapTileHeader
{
@@ -36,27 +36,18 @@ static_assert(sizeof(MmapTileHeader) == (sizeof(MmapTileHeader::mmapMagic) +
sizeof(MmapTileHeader::usesLiquids) +
sizeof(MmapTileHeader::padding)), "MmapTileHeader has uninitialized padding fields");
enum NavArea
{
NAV_AREA_EMPTY = 0,
// areas 1-60 will be used for destructible areas (currently skipped in vmaps, WMO with flag 1)
// ground is the highest value to make recast choose ground over water when merging surfaces very close to each other (shallow water would be walkable)
NAV_AREA_GROUND = 11,
NAV_AREA_GROUND_STEEP = 10,
NAV_AREA_WATER = 9,
NAV_AREA_MAGMA_SLIME = 8, // don't need to differentiate between them
NAV_AREA_MAX_VALUE = NAV_AREA_GROUND,
NAV_AREA_MIN_VALUE = NAV_AREA_MAGMA_SLIME,
NAV_AREA_ALL_MASK = 0x3F // max allowed value
};
enum NavTerrainFlag
enum NavTerrain
{
NAV_EMPTY = 0x00,
NAV_GROUND = 1 << (NAV_AREA_MAX_VALUE - NAV_AREA_GROUND),
NAV_GROUND_STEEP = 1 << (NAV_AREA_MAX_VALUE - NAV_AREA_GROUND_STEEP),
NAV_WATER = 1 << (NAV_AREA_MAX_VALUE - NAV_AREA_WATER),
NAV_MAGMA_SLIME = 1 << (NAV_AREA_MAX_VALUE - NAV_AREA_MAGMA_SLIME)
NAV_GROUND = 0x01,
NAV_MAGMA = 0x02,
NAV_SLIME = 0x04,
NAV_WATER = 0x08,
NAV_UNUSED1 = 0x10,
NAV_UNUSED2 = 0x20,
NAV_UNUSED3 = 0x40,
NAV_UNUSED4 = 0x80
// we only have 8 bits
};
#endif /* _MAPDEFINES_H */

View File

@@ -641,12 +641,12 @@ void PathGenerator::CreateFilter()
// creatures don't take environmental damage
if (creature->CanEnterWater())
includeFlags |= (NAV_WATER | NAV_MAGMA_SLIME);
includeFlags |= (NAV_WATER | NAV_MAGMA);
}
else // assume Player
{
// perfect support not possible, just stay 'safe'
includeFlags |= (NAV_GROUND | NAV_WATER | NAV_MAGMA_SLIME);
includeFlags |= (NAV_GROUND | NAV_WATER | NAV_MAGMA);
}
_filter.setIncludeFlags(includeFlags);
@@ -671,17 +671,13 @@ void PathGenerator::UpdateFilter()
_filter.setIncludeFlags(includedFlags);
}
if (Creature const* _sourceCreature = _source->ToCreature())
{
/*if (Creature const* _sourceCreature = _source->ToCreature())
if (_sourceCreature->IsInCombat() || _sourceCreature->IsInEvadeMode())
{
_filter.setIncludeFlags(_filter.getIncludeFlags() | NAV_GROUND_STEEP);
}
}
_filter.setIncludeFlags(_filter.getIncludeFlags() | NAV_GROUND_STEEP);*/
}
}
NavTerrainFlag PathGenerator::GetNavTerrain(float x, float y, float z) const
NavTerrain PathGenerator::GetNavTerrain(float x, float y, float z) const
{
LiquidData data;
LiquidData const& liquidData = _source->GetMap()->GetLiquidData(_source->GetPhaseMask(), x, y, z, _source->GetCollisionHeight(), MAP_ALL_LIQUIDS);
@@ -695,7 +691,7 @@ NavTerrainFlag PathGenerator::GetNavTerrain(float x, float y, float z) const
return NAV_WATER;
case MAP_LIQUID_TYPE_MAGMA:
case MAP_LIQUID_TYPE_SLIME:
return NAV_MAGMA_SLIME;
return NAV_MAGMA;
default:
return NAV_GROUND;
}
@@ -1143,9 +1139,9 @@ bool PathGenerator::IsWaterPath(Movement::PointsArray pathPoints) const
// Check both start and end points, if they're both in water, then we can *safely* let the creature move
for (uint32 i = 0; i < pathPoints.size(); ++i)
{
NavTerrainFlag terrain = GetNavTerrain(pathPoints[i].x, pathPoints[i].y, pathPoints[i].z);
NavTerrain terrain = GetNavTerrain(pathPoints[i].x, pathPoints[i].y, pathPoints[i].z);
// One of the points is not in the water
if (terrain != NAV_MAGMA_SLIME && terrain != NAV_WATER)
if (terrain != NAV_MAGMA && terrain != NAV_WATER)
{
waterPath = false;
break;

View File

@@ -168,7 +168,7 @@ class PathGenerator
void BuildPointPath(float const* startPoint, float const* endPoint);
void BuildShortcut();
[[nodiscard]] NavTerrainFlag GetNavTerrain(float x, float y, float z) const;
[[nodiscard]] NavTerrain GetNavTerrain(float x, float y, float z) const;
void CreateFilter();
void UpdateFilter();

View File

@@ -52,7 +52,7 @@ namespace MMAP
m_workerThread.join();
}
MapBuilder::MapBuilder(Optional<float> maxWalkableAngle, Optional<float> maxWalkableAngleNotSteep, bool skipLiquid,
MapBuilder::MapBuilder(float maxWalkableAngle, bool skipLiquid,
bool skipContinents, bool skipJunkMaps, bool skipBattlegrounds,
bool debugOutput, bool bigBaseUnit, int mapid, const char* offMeshFilePath, unsigned int threads) :
@@ -64,7 +64,6 @@ namespace MMAP
m_skipBattlegrounds (skipBattlegrounds),
m_skipLiquid (skipLiquid),
m_maxWalkableAngle (maxWalkableAngle),
m_maxWalkableAngleNotSteep (maxWalkableAngleNotSteep),
m_bigBaseUnit (bigBaseUnit),
m_mapid (mapid),
m_totalTiles (0u),
@@ -654,16 +653,9 @@ namespace MMAP
// mark all walkable tiles, both liquids and solids
/* we want to have triangles with slope less than walkableSlopeAngleNotSteep (<= 55) to have NAV_AREA_GROUND
* and with slope between walkableSlopeAngleNotSteep and walkableSlopeAngle (55 < .. <= 70) to have NAV_AREA_GROUND_STEEP.
* we achieve this using recast API: memset everything to NAV_AREA_GROUND_STEEP, call rcClearUnwalkableTriangles with 70 so
* any area above that will get RC_NULL_AREA (unwalkable), then call rcMarkWalkableTriangles with 55 to set NAV_AREA_GROUND
* on anything below 55 . Players and idle Creatures can use NAV_AREA_GROUND, while Creatures in combat can use NAV_AREA_GROUND_STEEP.
*/
unsigned char* triFlags = new unsigned char[tTriCount];
memset(triFlags, NAV_AREA_GROUND_STEEP, tTriCount * sizeof(unsigned char));
memset(triFlags, NAV_GROUND, tTriCount * sizeof(unsigned char));
rcClearUnwalkableTriangles(m_rcContext, tileCfg.walkableSlopeAngle, tVerts, tVertCount, tTris, tTriCount, triFlags);
rcMarkWalkableTriangles(m_rcContext, tileCfg.walkableSlopeAngleNotSteep, tVerts, tVertCount, tTris, tTriCount, triFlags, NAV_AREA_GROUND);
rcRasterizeTriangles(m_rcContext, tVerts, tVertCount, tTris, triFlags, tTriCount, *tile.solid, config.walkableClimb);
delete[] triFlags;
@@ -769,15 +761,8 @@ namespace MMAP
// set polygons as walkable
// TODO: special flags for DYNAMIC polygons, ie surfaces that can be turned on and off
for (int i = 0; i < iv.polyMesh->npolys; ++i)
{
if (uint8 area = iv.polyMesh->areas[i] & NAV_AREA_ALL_MASK)
{
if (area >= NAV_AREA_MIN_VALUE)
iv.polyMesh->flags[i] = 1 << (NAV_AREA_MAX_VALUE - area);
else
iv.polyMesh->flags[i] = NAV_GROUND; // TODO: these will be dynamic in future
}
}
if (iv.polyMesh->areas[i] & RC_WALKABLE_AREA)
iv.polyMesh->flags[i] = iv.polyMesh->areas[i];
// setup mesh parameters
dtNavMeshCreateParams params;
@@ -1072,10 +1057,7 @@ namespace MMAP
config.maxVertsPerPoly = DT_VERTS_PER_POLYGON;
config.cs = tileConfig.BASE_UNIT_DIM;
config.ch = tileConfig.BASE_UNIT_DIM;
// Keeping these 2 slope angles the same reduces a lot the number of polys.
// 55 should be the minimum, maybe 70 is ok (keep in mind blink uses mmaps), 85 is too much for players
config.walkableSlopeAngle = m_maxWalkableAngle ? *m_maxWalkableAngle : 55;
config.walkableSlopeAngleNotSteep = m_maxWalkableAngleNotSteep ? *m_maxWalkableAngleNotSteep : 55;
config.walkableSlopeAngle = m_maxWalkableAngle;
config.tileSize = tileConfig.VERTEX_PER_TILE;
config.walkableRadius = m_bigBaseUnit ? 1 : 2;
config.borderSize = config.walkableRadius + 3;

View File

@@ -147,8 +147,7 @@ namespace MMAP
{
friend class TileBuilder;
public:
MapBuilder(Optional<float> maxWalkableAngle,
Optional<float> maxWalkableAngleNotSteep,
MapBuilder(float maxWalkableAngle,
bool skipLiquid,
bool skipContinents,
bool skipJunkMaps,
@@ -204,8 +203,7 @@ namespace MMAP
bool m_skipBattlegrounds;
bool m_skipLiquid;
Optional<float> m_maxWalkableAngle;
Optional<float> m_maxWalkableAngleNotSteep;
float m_maxWalkableAngle;
bool m_bigBaseUnit;
int32 m_mapid;

View File

@@ -105,7 +105,7 @@ namespace MMAP
errno = 0;
if ((dp = readdir(dirp)) != nullptr)
{
if (strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0 && matchWildcardFilter(filter.c_str(), dp->d_name))
if (matchWildcardFilter(filter.c_str(), dp->d_name))
fileList.emplace_back(dp->d_name);
}
else

View File

@@ -17,26 +17,12 @@
#include "MapBuilder.h"
#include "PathCommon.h"
#include "Timer.h"
#include "DBCFileLoader.h"
#include "PathCommon.h"
#include "Util.h"
#include "Timer.h"
#include <boost/filesystem.hpp>
#include <unordered_map>
using namespace MMAP;
namespace
{
std::unordered_map<uint32, uint8> _liquidTypes;
}
uint32 GetLiquidFlags(uint32 liquidId)
{
auto itr = _liquidTypes.find(liquidId);
return itr != _liquidTypes.end() ? (1 << itr->second) : 0;
}
bool checkDirectories(bool debugOutput)
{
std::vector<std::string> dirFiles;
@@ -77,8 +63,7 @@ bool handleArgs(int argc, char** argv,
int& mapnum,
int& tileX,
int& tileY,
Optional<float>& maxAngle,
Optional<float>& maxAngleNotSteep,
float& maxAngle,
bool& skipLiquid,
bool& skipContinents,
bool& skipJunkMaps,
@@ -100,23 +85,11 @@ bool handleArgs(int argc, char** argv,
return false;
float maxangle = atof(param);
if (maxangle <= 90.f && maxangle >= 0.f)
if (maxangle <= 90.f && maxangle >= 45.f)
maxAngle = maxangle;
else
printf("invalid option for '--maxAngle', using default\n");
}
else if (strcmp(argv[i], "--maxAngleNotSteep") == 0)
{
param = argv[++i];
if (!param)
return false;
float maxangle = atof(param);
if (maxangle <= 90.f && maxangle >= 0.f)
maxAngleNotSteep = maxangle;
else
printf("invalid option for '--maxAngleNotSteep', using default\n");
}
else if (strcmp(argv[i], "--threads") == 0)
{
param = argv[++i];
@@ -266,29 +239,12 @@ int finish(const char* message, int returnValue)
return returnValue;
}
std::unordered_map<uint32, uint8> LoadLiquid()
{
DBCFileLoader liquidDbc;
std::unordered_map<uint32, uint8> liquidData;
// format string doesnt matter as long as it has correct length (only used for mapping to structures in worldserver)
if (liquidDbc.Load((boost::filesystem::path("dbc") / "LiquidType.dbc").string().c_str(), "nxxixixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))
{
for (uint32 x = 0; x < liquidDbc.GetNumRows(); ++x)
{
DBCFileLoader::Record record = liquidDbc.getRecord(x);
liquidData[record.getUInt(0)] = record.getUInt(3);
}
}
return liquidData;
}
int main(int argc, char** argv)
{
unsigned int threads = std::thread::hardware_concurrency();
int mapnum = -1;
int tileX = -1, tileY = -1;
Optional<float> maxAngle, maxAngleNotSteep;
float maxAngle = 60.0f;
bool skipLiquid = false,
skipContinents = false,
skipJunkMaps = true,
@@ -300,7 +256,7 @@ int main(int argc, char** argv)
char* file = nullptr;
bool validParam = handleArgs(argc, argv, mapnum,
tileX, tileY, maxAngle, maxAngleNotSteep,
tileX, tileY, maxAngle,
skipLiquid, skipContinents, skipJunkMaps, skipBattlegrounds,
debugOutput, silent, bigBaseUnit, offMeshInputPath, file, threads);
@@ -322,13 +278,7 @@ int main(int argc, char** argv)
if (!checkDirectories(debugOutput))
return silent ? -3 : finish("Press ENTER to close...", -3);
_liquidTypes = LoadLiquid();
if (_liquidTypes.empty())
{
return silent ? -5 : finish("Failed to load LiquidType.dbc", -5);
}
MapBuilder builder(maxAngle, maxAngleNotSteep, skipLiquid, skipContinents, skipJunkMaps,
MapBuilder builder(maxAngle, skipLiquid, skipContinents, skipJunkMaps,
skipBattlegrounds, debugOutput, bigBaseUnit, mapnum, offMeshInputPath, threads);
uint32 start = getMSTime();

View File

@@ -77,8 +77,6 @@ struct map_liquidHeader
#define MAP_LIQUID_TYPE_SLIME 0x08
#define MAP_LIQUID_TYPE_DARK_WATER 0x10
uint32 GetLiquidFlags(uint32 liquidId);
namespace MMAP
{
@@ -414,23 +412,27 @@ namespace MMAP
else
{
liquidType = getLiquidType(i, liquid_flags);
if (liquidType & MAP_LIQUID_TYPE_DARK_WATER)
switch (liquidType)
{
default:
useLiquid = false;
break;
case MAP_LIQUID_TYPE_WATER:
case MAP_LIQUID_TYPE_OCEAN:
// merge different types of water
liquidType = NAV_WATER;
break;
case MAP_LIQUID_TYPE_MAGMA:
liquidType = NAV_MAGMA;
break;
case MAP_LIQUID_TYPE_SLIME:
liquidType = NAV_SLIME;
break;
case MAP_LIQUID_TYPE_DARK_WATER:
// players should not be here, so logically neither should creatures
useTerrain = false;
useLiquid = false;
}
else if ((liquidType & (MAP_LIQUID_TYPE_WATER | MAP_LIQUID_TYPE_OCEAN)) != 0)
{
liquidType = NAV_AREA_WATER;
}
else if ((liquidType & (MAP_LIQUID_TYPE_MAGMA | MAP_LIQUID_TYPE_SLIME)) != 0)
{
liquidType = NAV_AREA_MAGMA_SLIME;
}
else
{
useLiquid = false;
break;
}
}
@@ -733,17 +735,20 @@ namespace MMAP
vertsY = tilesY + 1;
uint8* flags = liquid->GetFlagsStorage();
float* data = liquid->GetHeightStorage();
uint8 type = NAV_AREA_EMPTY;
uint8 type = NAV_EMPTY;
// convert liquid type to NavTerrain
uint32 liquidFlags = GetLiquidFlags(liquid->GetType());
if ((liquidFlags & (MAP_LIQUID_TYPE_WATER | MAP_LIQUID_TYPE_OCEAN)) != 0)
switch (liquid->GetType() & 3)
{
type = NAV_AREA_WATER;
}
else if ((liquidFlags & (MAP_LIQUID_TYPE_MAGMA | MAP_LIQUID_TYPE_SLIME)) != 0)
{
type = NAV_AREA_MAGMA_SLIME;
case 0:
case 1:
type = NAV_WATER;
break;
case 2:
type = NAV_MAGMA;
break;
case 3:
type = NAV_SLIME;
break;
}
// indexing is weird...