Recast: move poly flags and area enums to Detour NavMesh header

Also needs to be used in building and query code, moved to Detour NavMesh header.
This commit is contained in:
Kawe Mazidjatari 2024-09-19 00:02:37 +02:00
parent d5fa52499c
commit 30570981e1
12 changed files with 109 additions and 112 deletions

View File

@ -118,11 +118,11 @@ void ConvexVolumeTool::handleMenu()
if (ImGui::Checkbox("Clip", &isEnabled))
m_areaType = RC_NULL_AREA;
isEnabled = m_areaType == EDITOR_POLYAREA_TRIGGER;
isEnabled = m_areaType == DT_POLYAREA_TRIGGER;
if (ImGui::Checkbox("Trigger", &isEnabled))
m_areaType = EDITOR_POLYAREA_TRIGGER; // todo(amos): also allow setting flags and store this in .gset.
m_areaType = DT_POLYAREA_TRIGGER; // todo(amos): also allow setting flags and store this in .gset.
if (m_areaType == EDITOR_POLYAREA_TRIGGER)
if (m_areaType == DT_POLYAREA_TRIGGER)
{
ImGui::Text("Poly Flags");
ImGui::Indent();
@ -132,7 +132,7 @@ void ConvexVolumeTool::handleMenu()
for (int i = 0; i < numPolyFlags; i++)
{
const char* flagName = g_navMeshPolyFlagNames[i];
ImGui::CheckboxFlags(flagName, &m_polyFlags, i == (numPolyFlags-1) ? EDITOR_POLYFLAGS_ALL : 1<<i);
ImGui::CheckboxFlags(flagName, &m_polyFlags, i == (numPolyFlags-1) ? DT_POLYFLAGS_ALL : 1<<i);
}
ImGui::Unindent();

View File

@ -142,7 +142,7 @@ void CrowdToolState::init(class Editor* editor)
crowd->init(MAX_AGENTS, m_editor->getAgentRadius(), nav);
// Make polygons with 'disabled' flag invalid.
crowd->getEditableFilter(0)->setExcludeFlags(EDITOR_POLYFLAGS_DISABLED);
crowd->getEditableFilter(0)->setExcludeFlags(DT_POLYFLAGS_DISABLED);
// Setup local avoidance params to different qualities.
dtObstacleAvoidanceParams params;
@ -1085,7 +1085,7 @@ void CrowdTool::handleClick(const float* s, const float* p, bool shift)
unsigned short flags = 0;
if (dtStatusSucceed(nav->getPolyFlags(ref, &flags)))
{
flags ^= EDITOR_POLYFLAGS_DISABLED;
flags ^= DT_POLYFLAGS_DISABLED;
nav->setPolyFlags(ref, flags);
}
}

View File

@ -38,11 +38,11 @@ unsigned int EditorDebugDraw::areaToCol(unsigned int area)
switch(area)
{
// Ground : light blue
case EDITOR_POLYAREA_GROUND: return duRGBA(0, 192, 215, 255);
case DT_POLYAREA_GROUND: return duRGBA(0, 192, 215, 255);
// Jump : blue
case EDITOR_POLYAREA_JUMP: return duRGBA(0, 0, 255, 255);
case DT_POLYAREA_JUMP: return duRGBA(0, 0, 255, 255);
// Trigger : light green
case EDITOR_POLYAREA_TRIGGER: return duRGBA(20, 245, 0, 255);
case DT_POLYAREA_TRIGGER: return duRGBA(20, 245, 0, 255);
// Unexpected : white
default: return duRGBA(255, 255, 255, 255);
}

View File

@ -307,7 +307,7 @@ void Editor_StaticTileMeshCommon::renderTileMeshData()
if (m_tileMeshDrawFlags & TM_DRAWFLAGS_NAVMESH)
{
duDebugDrawNavMeshWithClosedList(&m_dd, *m_navMesh, *m_navQuery, detourDrawOffset, m_navMeshDrawFlags, m_traverseLinkDrawParams);
duDebugDrawNavMeshPolysWithFlags(&m_dd, *m_navMesh, EDITOR_POLYFLAGS_DISABLED, detourDrawOffset, detourDrawFlags, duRGBA(0, 0, 0, 128));
duDebugDrawNavMeshPolysWithFlags(&m_dd, *m_navMesh, DT_POLYFLAGS_DISABLED, detourDrawOffset, detourDrawFlags, duRGBA(0, 0, 0, 128));
}
}
@ -572,7 +572,7 @@ void Editor_DynamicTileMeshCommon::renderTileMeshData()
if (recastDrawFlags & TM_DRAWFLAGS_NAVMESH)
{
duDebugDrawNavMeshWithClosedList(&m_dd, *m_navMesh, *m_navQuery, detourDrawOffset, detourDrawFlags, m_traverseLinkDrawParams);
duDebugDrawNavMeshPolysWithFlags(&m_dd, *m_navMesh, EDITOR_POLYFLAGS_DISABLED, detourDrawOffset, detourDrawFlags, duRGBA(0, 0, 0, 128));
duDebugDrawNavMeshPolysWithFlags(&m_dd, *m_navMesh, DT_POLYFLAGS_DISABLED, detourDrawOffset, detourDrawFlags, duRGBA(0, 0, 0, 128));
}
}

View File

@ -447,23 +447,23 @@ bool Editor_SoloMesh::handleBuild()
for (int i = 0; i < m_pmesh->npolys; ++i)
{
if (m_pmesh->areas[i] == RC_WALKABLE_AREA)
m_pmesh->areas[i] = EDITOR_POLYAREA_GROUND;
m_pmesh->areas[i] = DT_POLYAREA_GROUND;
if (m_pmesh->areas[i] == EDITOR_POLYAREA_GROUND
if (m_pmesh->areas[i] == DT_POLYAREA_GROUND
//||
//m_pmesh->areas[i] == EDITOR_POLYAREA_GRASS ||
//m_pmesh->areas[i] == EDITOR_POLYAREA_ROAD
)
{
m_pmesh->flags[i] = EDITOR_POLYFLAGS_WALK;
m_pmesh->flags[i] = DT_POLYFLAGS_WALK;
}
//else if (m_pmesh->areas[i] == EDITOR_POLYAREA_WATER)
//{
// m_pmesh->flags[i] = EDITOR_POLYFLAGS_SWIM;
//}
else if (m_pmesh->areas[i] == EDITOR_POLYAREA_TRIGGER)
else if (m_pmesh->areas[i] == DT_POLYAREA_TRIGGER)
{
m_pmesh->flags[i] = EDITOR_POLYFLAGS_WALK /*| EDITOR_POLYFLAGS_DOOR*/;
m_pmesh->flags[i] = DT_POLYFLAGS_WALK /*| EDITOR_POLYFLAGS_DOOR*/;
}
}

View File

@ -175,23 +175,23 @@ struct MeshProcess : public dtTileCacheMeshProcess
for (int i = 0; i < params->polyCount; ++i)
{
if (polyAreas[i] == DT_TILECACHE_WALKABLE_AREA)
polyAreas[i] = EDITOR_POLYAREA_GROUND;
polyAreas[i] = DT_POLYAREA_GROUND;
if (polyAreas[i] == EDITOR_POLYAREA_GROUND
if (polyAreas[i] == DT_POLYAREA_GROUND
//||
//polyAreas[i] == EDITOR_POLYAREA_GRASS ||
//polyAreas[i] == EDITOR_POLYAREA_ROAD
)
{
polyFlags[i] = EDITOR_POLYFLAGS_WALK;
polyFlags[i] = DT_POLYFLAGS_WALK;
}
//else if (polyAreas[i] == EDITOR_POLYAREA_WATER)
//{
// polyFlags[i] = EDITOR_POLYFLAGS_SWIM;
//}
else if (polyAreas[i] == EDITOR_POLYAREA_TRIGGER)
else if (polyAreas[i] == DT_POLYAREA_TRIGGER)
{
polyFlags[i] = EDITOR_POLYFLAGS_WALK /*| EDITOR_POLYFLAGS_DOOR*/;
polyFlags[i] = DT_POLYFLAGS_WALK /*| EDITOR_POLYFLAGS_DOOR*/;
}
}

View File

@ -1242,27 +1242,14 @@ unsigned char* Editor_TileMesh::buildTileMesh(const int tx, const int ty, const
for (int i = 0; i < m_pmesh->npolys; ++i)
{
if (m_pmesh->areas[i] == RC_WALKABLE_AREA)
m_pmesh->areas[i] = EDITOR_POLYAREA_GROUND;
if (m_pmesh->areas[i] == EDITOR_POLYAREA_GROUND
//||
//m_pmesh->areas[i] == EDITOR_POLYAREA_GRASS ||
//m_pmesh->areas[i] == EDITOR_POLYAREA_ROAD
)
{
m_pmesh->flags[i] |= EDITOR_POLYFLAGS_WALK;
}
//else if (m_pmesh->areas[i] == EDITOR_POLYAREA_WATER)
//{
// m_pmesh->flags[i] = EDITOR_POLYFLAGS_SWIM;
//}
else if (m_pmesh->areas[i] == EDITOR_POLYAREA_TRIGGER)
{
m_pmesh->flags[i] |= EDITOR_POLYFLAGS_WALK /*| EDITOR_POLYFLAGS_DOOR*/;
}
m_pmesh->areas[i] = DT_POLYAREA_GROUND;
if (m_pmesh->areas[i] == DT_POLYAREA_GROUND ||
m_pmesh->areas[i] == DT_POLYAREA_TRIGGER)
m_pmesh->flags[i] |= DT_POLYFLAGS_WALK;
if (m_pmesh->surfa[i] <= NAVMESH_SMALL_POLYGON_THRESHOLD)
m_pmesh->flags[i] |= EDITOR_POLYFLAGS_TOO_SMALL;
if (m_pmesh->surfa[i] <= RC_POLY_SURFAREA_TOO_SMALL_THRESHOLD)
m_pmesh->flags[i] |= DT_POLYFLAGS_TOO_SMALL;
const int nvp = m_pmesh->nvp;
const unsigned short* p = &m_pmesh->polys[i*nvp*2];
@ -1277,7 +1264,7 @@ unsigned char* Editor_TileMesh::buildTileMesh(const int tx, const int ty, const
if ((p[nvp+j] & 0xf) == 0xf)
continue;
m_pmesh->flags[i] |= EDITOR_POLYFLAGS_HAS_NEIGHBOUR;
m_pmesh->flags[i] |= DT_POLYFLAGS_HAS_NEIGHBOUR;
}
}
@ -1330,7 +1317,7 @@ unsigned char* Editor_TileMesh::buildTileMesh(const int tx, const int ty, const
// without restoring this, the renderer will draw it as NULL area
// even though it's walkable. The other values will get color ID'd
// by the renderer so we don't need to check on those.
if (m_pmesh->areas[i] == EDITOR_POLYAREA_GROUND)
if (m_pmesh->areas[i] == DT_POLYAREA_GROUND)
m_pmesh->areas[i] = RC_WALKABLE_AREA;
}

View File

@ -181,7 +181,7 @@ static void disableUnvisitedPolys(dtNavMesh* nav, NavmeshFlags* flags)
targetPoly->groupId = DT_UNLINKED_POLY_GROUP;
targetPoly->firstLink = DT_NULL_LINK;
targetPoly->flags = EDITOR_POLYFLAGS_DISABLED;
targetPoly->flags = DT_POLYFLAGS_DISABLED;
numUnlinkedPolys++;
}

View File

@ -176,7 +176,7 @@ NavMeshTesterTool::NavMeshTesterTool() :
m_pathIterPolyCount(0),
m_steerPointCount(0)
{
m_filter.setIncludeFlags(EDITOR_POLYFLAGS_ALL ^ EDITOR_POLYFLAGS_DISABLED);
m_filter.setIncludeFlags(DT_POLYFLAGS_ALL ^ DT_POLYFLAGS_DISABLED);
m_filter.setExcludeFlags(0);
m_polyPickExt[0] = 2;
@ -197,10 +197,10 @@ void NavMeshTesterTool::init(Editor* editor)
if (m_navQuery)
{
// Change costs.
m_filter.setAreaCost(EDITOR_POLYAREA_GROUND, 1.0f);
m_filter.setAreaCost(EDITOR_POLYAREA_JUMP, 1.5f);
m_filter.setAreaCost(DT_POLYAREA_GROUND, 1.0f);
m_filter.setAreaCost(DT_POLYAREA_JUMP, 1.5f);
//m_filter.setAreaCost(EDITOR_POLYAREA_ROAD, 1.0f);
m_filter.setAreaCost(EDITOR_POLYAREA_TRIGGER, 1.0f);
m_filter.setAreaCost(DT_POLYAREA_TRIGGER, 1.0f);
//m_filter.setAreaCost(EDITOR_POLYAREA_GRASS, 2.0f);
//m_filter.setAreaCost(EDITOR_POLYAREA_WATER, 10.0f);
}
@ -387,19 +387,19 @@ void NavMeshTesterTool::handleMenu()
ImGui::Indent();
isEnabled = (m_filter.getIncludeFlags() & EDITOR_POLYFLAGS_WALK) != 0;
isEnabled = (m_filter.getIncludeFlags() & DT_POLYFLAGS_WALK) != 0;
if (ImGui::Checkbox("Walk##IncludeFlags", &isEnabled))
{
m_filter.setIncludeFlags(m_filter.getIncludeFlags() ^ EDITOR_POLYFLAGS_WALK);
m_filter.setIncludeFlags(m_filter.getIncludeFlags() ^ DT_POLYFLAGS_WALK);
recalc();
}
isEnabled = (m_filter.getIncludeFlags() & EDITOR_POLYFLAGS_TOO_SMALL) != 0;
isEnabled = (m_filter.getIncludeFlags() & DT_POLYFLAGS_TOO_SMALL) != 0;
if (ImGui::Checkbox("Skip##IncludeFlags", &isEnabled))
{
m_filter.setIncludeFlags(m_filter.getIncludeFlags() ^ EDITOR_POLYFLAGS_TOO_SMALL);
m_filter.setIncludeFlags(m_filter.getIncludeFlags() ^ DT_POLYFLAGS_TOO_SMALL);
recalc();
}
@ -410,19 +410,19 @@ void NavMeshTesterTool::handleMenu()
ImGui::Indent();
isEnabled = (m_filter.getExcludeFlags() & EDITOR_POLYFLAGS_WALK) != 0;
isEnabled = (m_filter.getExcludeFlags() & DT_POLYFLAGS_WALK) != 0;
if (ImGui::Checkbox("Walk##ExcludeFlags", &isEnabled))
{
m_filter.setExcludeFlags(m_filter.getExcludeFlags() ^ EDITOR_POLYFLAGS_WALK);
m_filter.setExcludeFlags(m_filter.getExcludeFlags() ^ DT_POLYFLAGS_WALK);
recalc();
}
isEnabled = (m_filter.getExcludeFlags() & EDITOR_POLYFLAGS_TOO_SMALL) != 0;
isEnabled = (m_filter.getExcludeFlags() & DT_POLYFLAGS_TOO_SMALL) != 0;
if (ImGui::Checkbox("Skip##ExcludeFlags", &isEnabled))
{
m_filter.setExcludeFlags(m_filter.getExcludeFlags() ^ EDITOR_POLYFLAGS_TOO_SMALL);
m_filter.setExcludeFlags(m_filter.getExcludeFlags() ^ DT_POLYFLAGS_TOO_SMALL);
recalc();
}

View File

@ -133,31 +133,6 @@ enum EditorToolType
// EDITOR_POLYAREA_WATER,
//};
#if DT_NAVMESH_SET_VERSION >= 9
enum EditorPolyAreas
{
EDITOR_POLYAREA_JUMP,
EDITOR_POLYAREA_GROUND,
EDITOR_POLYAREA_RESERVED,
EDITOR_POLYAREA_TRIGGER,
};
#else
enum EditorPolyAreas
{
EDITOR_POLYAREA_GROUND,
EDITOR_POLYAREA_JUMP,
// NOTE: not sure if anything beyond EDITOR_POLYAREA_JUMP belongs to MSET5,
// this needs to be confirmed, for now its been kept in for MSET5.
EDITOR_POLYAREA_JUMP_REVERSE,
EDITOR_POLYAREA_TRIGGER,
EDITOR_POLYAREA_WALLJUMP_LEFT,
EDITOR_POLYAREA_WALLJUMP_RIGHT,
EDITOR_POLYAREA_WALLJUMP_LEFT_REVERSE,
EDITOR_POLYAREA_WALLJUMP_RIGHT_REVERSE,
};
#endif
//enum EditorPolyFlags // note: original poly flags for reference.
//{
// // Most common polygon flags.
@ -169,37 +144,6 @@ enum EditorPolyAreas
// EDITOR_POLYFLAGS_ALL = 0xffff // All abilities.
//};
// Polygon surface area's that aren't larger than this amount will be flagged
// as 'EDITOR_POLYFLAGS_TOO_SMALL'.
static const unsigned short NAVMESH_SMALL_POLYGON_THRESHOLD = 120;
enum EditorPolyFlags
{
// Most common polygon flags.
EDITOR_POLYFLAGS_WALK = 1<<0, // Ability to walk (ground, grass, road).
EDITOR_POLYFLAGS_TOO_SMALL = 1<<1, // This polygon's surface area is too small; it will be ignored during AIN script nodes generation, NavMesh_RandomPositions, dtNavMeshQuery::findLocalNeighbourhood, etc.
EDITOR_POLYFLAGS_HAS_NEIGHBOUR = 1<<2, // This polygon is connected to a polygon on a neighbouring tile.
// Off-mesh connection flags
EDITOR_POLYFLAGS_JUMP = 1<<3, // Ability to jump (exclusively used on off-mesh connection polygons).
EDITOR_POLYFLAGS_JUMP_LINKED = 1<<4, // Off-mesh connections who's start and end verts link to other polygons need this flag.
EDITOR_POLYFLAGS_UNK2 = 1<<5, // Unknown, no use cases found yet.
// Only used along with poly area 'EDITOR_POLYAREA_TRIGGER'.
EDITOR_POLYFLAGS_OBSTACLE = 1<<6, // Unknown, used for small road blocks and other small but easily climbable obstacles.
EDITOR_POLYFLAGS_UNK4 = 1<<7, // Unknown, no use cases found yet.
EDITOR_POLYFLAGS_DISABLED = 1<<8, // Used for ToggleNPCPathsForEntity. Also, see [r5apex_ds + 0xC96EA8]. Used for toggling poly's when a door closes during runtime.
// Also used to disable poly's in the navmesh file itself when we do happen to build navmesh on lava or other very hazardous areas.
EDITOR_POLYFLAGS_HAZARD = 1<<9, // see [r5apex_ds + 0xC96ED0], used for hostile objects such as electric fences.
EDITOR_POLYFLAGS_DOOR = 1<<10, // See [r5apex_ds + 0xECBAE0], used for large bunker style doors (vertical and horizontal opening ones), perhaps also shooting cover hint?.
EDITOR_POLYFLAGS_UNK8 = 1<<11, // Unknown, no use cases found yet.
EDITOR_POLYFLAGS_UNK9 = 1<<12, // Unknown, no use cases found yet.
EDITOR_POLYFLAGS_DOOR_BREACHABLE = 1<<13, // Used for doors that need to be breached, such as the Explosive Holds doors.
EDITOR_POLYFLAGS_ALL = 0xffff // All abilities.
};
inline static const char* const g_navMeshPolyFlagNames[] =
{
"walk",

View File

@ -214,6 +214,69 @@ enum dtPolyTypes
DT_POLYTYPE_OFFMESH_CONNECTION = 1,
};
enum dtPolyAreas
{
#if DT_NAVMESH_SET_VERSION >= 9
DT_POLYAREA_JUMP,
DT_POLYAREA_GROUND,
#else
DT_POLYAREA_GROUND,
DT_POLYAREA_JUMP,
#endif
// NOTE: not sure if anything beyond DT_POLYAREA_JUMP belongs to MSET5,
// this needs to be confirmed, for now its been kept in for MSET5.
DT_POLYAREA_JUMP_REVERSE,
DT_POLYAREA_TRIGGER,
DT_POLYAREA_WALLJUMP_LEFT,
DT_POLYAREA_WALLJUMP_RIGHT,
DT_POLYAREA_WALLJUMP_LEFT_REVERSE,
DT_POLYAREA_WALLJUMP_RIGHT_REVERSE,
};
enum dtPolyFlags
{
/// Most common polygon flags.
/// Ability to walk (ground, grass, road).
DT_POLYFLAGS_WALK = 1<<0,
/// This polygon's surface area is too small; it will be ignored during AIN script nodes generation, NavMesh_RandomPositions, dtNavMeshQuery::findLocalNeighbourhood, etc.
DT_POLYFLAGS_TOO_SMALL = 1<<1,
/// This polygon is connected to a polygon on a neighbouring tile.
DT_POLYFLAGS_HAS_NEIGHBOUR = 1<<2,
/// Off-mesh connection flags
/// Ability to jump (exclusively used on off-mesh connection polygons).
DT_POLYFLAGS_JUMP = 1<<3,
/// Off-mesh connections who's start and end verts link to other polygons need this flag.
DT_POLYFLAGS_JUMP_LINKED = 1<<4,
/// Unknown, no use cases found yet.
DT_POLYFLAGS_UNK2 = 1<<5,
/// Only used along with poly area 'DT_POLYAREA_TRIGGER'.
/// Unknown, used for small road blocks and other small but easily climbable obstacles.
DT_POLYFLAGS_OBSTACLE = 1<<6,
/// Unknown, no use cases found yet.
DT_POLYFLAGS_UNK4 = 1<<7,
/// Used for ToggleNPCPathsForEntity. Also, see [r5apex_ds + 0xC96EA8]. Used for toggling poly's when a door closes during runtime.
/// Also used to disable poly's in the navmesh file itself when we do happen to build navmesh on lava or other very hazardous areas.
DT_POLYFLAGS_DISABLED = 1<<8,
/// see [r5apex_ds + 0xC96ED0], used for hostile objects such as electric fences.
DT_POLYFLAGS_HAZARD = 1<<9,
/// See [r5apex_ds + 0xECBAE0], used for large bunker style doors (vertical and horizontal opening ones), perhaps also shooting cover hint?.
DT_POLYFLAGS_DOOR = 1<<10,
/// Unknown, no use cases found yet.
DT_POLYFLAGS_UNK8 = 1<<11,
/// Unknown, no use cases found yet.
DT_POLYFLAGS_UNK9 = 1<<12,
/// Used for doors that need to be breached, such as the Explosive Holds doors.
DT_POLYFLAGS_DOOR_BREACHABLE = 1<<13,
/// All abilities.
DT_POLYFLAGS_ALL = 0xffff
};
/// Defines a polygon within a dtMeshTile object.
/// @ingroup detour

View File

@ -635,6 +635,9 @@ static const unsigned char RC_WALKABLE_AREA = 63;
/// @see rcPolyMesh::surfa
static const float RC_POLY_SURFAREA_QUANT_FACTOR = 0.01f;
// Polygons with surface areas not larger than this amount should be flagged.
static const unsigned short RC_POLY_SURFAREA_TOO_SMALL_THRESHOLD = 120;
/// The value returned by #rcGetCon if the specified direction is not connected
/// to another span. (Has no neighbor.)
static const int RC_NOT_CONNECTED = 0x3f;