Added recast navmesh.

This commit is contained in:
Justin Marshall
2026-05-22 21:59:30 -07:00
parent d24553b366
commit b0788b922e
31 changed files with 11241 additions and 20 deletions
+57 -1
View File
@@ -29,6 +29,7 @@ If you have questions concerning this license or the applicable additional terms
#include "precompiled.h"
#pragma hdrstop
#include "../Game_local.h"
#include "AAS_local.h"
/*
@@ -72,6 +73,28 @@ idAASLocal::Init
============
*/
bool idAASLocal::Init( const idStr &mapName, unsigned int mapFileCRC ) {
const idStr navName = idRecastNavMesh::NavFileNameForAASName( mapName );
if ( recastNavMesh.IsLoaded() && mapName.Icmp( name ) == 0 ) {
common->Printf( "Keeping %s\n", navName.c_str() );
recastNavMesh.RemoveAllObstacles();
return true;
}
if ( recastNavMesh.Load( mapName, navName, mapFileCRC ) ) {
if ( file ) {
for ( int i = 0; i < obstacleList.Num(); i++ ) {
delete obstacleList[i];
}
obstacleList.Clear();
ShutdownRouting();
AASFileManager->FreeAAS( file );
file = NULL;
}
name = mapName;
common->Printf( "Loaded Recast navmesh: %s\n", navName.c_str() );
return true;
}
if ( file && mapName.Icmp( file->GetName() ) == 0 && mapFileCRC == file->GetCRC() ) {
common->Printf( "Keeping %s\n", file->GetName() );
RemoveAllObstacles();
@@ -95,6 +118,7 @@ idAASLocal::Shutdown
============
*/
void idAASLocal::Shutdown( void ) {
recastNavMesh.Shutdown();
if ( file ) {
ShutdownRouting();
RemoveAllObstacles();
@@ -109,6 +133,10 @@ idAASLocal::Stats
============
*/
void idAASLocal::Stats( void ) const {
if ( recastNavMesh.IsLoaded() ) {
recastNavMesh.Stats();
return;
}
if ( !file ) {
return;
}
@@ -123,6 +151,9 @@ idAASLocal::GetSettings
============
*/
const idAASSettings *idAASLocal::GetSettings( void ) const {
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.GetSettings();
}
if ( !file ) {
return NULL;
}
@@ -135,6 +166,9 @@ idAASLocal::PointAreaNum
============
*/
int idAASLocal::PointAreaNum( const idVec3 &origin ) const {
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.PointAreaNum( origin );
}
if ( !file ) {
return 0;
}
@@ -147,6 +181,9 @@ idAASLocal::PointReachableAreaNum
============
*/
int idAASLocal::PointReachableAreaNum( const idVec3 &origin, const idBounds &searchBounds, const int areaFlags ) const {
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.PointReachableAreaNum( origin, searchBounds, areaFlags );
}
if ( !file ) {
return 0;
}
@@ -160,6 +197,9 @@ idAASLocal::BoundsReachableAreaNum
============
*/
int idAASLocal::BoundsReachableAreaNum( const idBounds &bounds, const int areaFlags ) const {
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.BoundsReachableAreaNum( bounds, areaFlags );
}
if ( !file ) {
return 0;
}
@@ -173,6 +213,10 @@ idAASLocal::PushPointIntoAreaNum
============
*/
void idAASLocal::PushPointIntoAreaNum( int areaNum, idVec3 &origin ) const {
if ( recastNavMesh.IsLoaded() ) {
recastNavMesh.PushPointIntoAreaNum( areaNum, origin );
return;
}
if ( !file ) {
return;
}
@@ -185,6 +229,9 @@ idAASLocal::AreaCenter
============
*/
idVec3 idAASLocal::AreaCenter( int areaNum ) const {
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.AreaCenter( areaNum );
}
if ( !file ) {
return vec3_origin;
}
@@ -197,6 +244,9 @@ idAASLocal::AreaFlags
============
*/
int idAASLocal::AreaFlags( int areaNum ) const {
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.AreaFlags( areaNum );
}
if ( !file ) {
return 0;
}
@@ -209,6 +259,9 @@ idAASLocal::AreaTravelFlags
============
*/
int idAASLocal::AreaTravelFlags( int areaNum ) const {
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.AreaTravelFlags( areaNum );
}
if ( !file ) {
return 0;
}
@@ -221,6 +274,9 @@ idAASLocal::Trace
============
*/
bool idAASLocal::Trace( aasTrace_t &trace, const idVec3 &start, const idVec3 &end ) const {
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.Trace( trace, start, end );
}
if ( !file ) {
trace.fraction = 0.0f;
trace.lastAreaNum = 0;
@@ -285,4 +341,4 @@ int idAASLocal::AdjustPositionAndGetArea(idVec3& origin)
int area = PointReachableAreaNum(origin, DefaultSearchBounds(), AREA_REACHABLE_WALK);
PushPointIntoAreaNum(area, origin);
return area;
}
}
+31
View File
@@ -175,6 +175,9 @@ idAASLocal::DefaultSearchBounds
============
*/
const idBounds &idAASLocal::DefaultSearchBounds( void ) const {
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.GetSettings()->boundingBoxes[0];
}
return file->GetSettings().boundingBoxes[0];
}
@@ -184,6 +187,10 @@ idAASLocal::ShowArea
============
*/
void idAASLocal::ShowArea( const idVec3 &origin ) const {
if ( recastNavMesh.IsLoaded() ) {
recastNavMesh.ShowArea( origin );
return;
}
static int lastAreaNum;
int areaNum;
const aasArea_t *area;
@@ -242,6 +249,10 @@ idAASLocal::ShowWalkPath
============
*/
void idAASLocal::ShowWalkPath( const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin ) const {
if ( recastNavMesh.IsLoaded() ) {
recastNavMesh.ShowPath( origin, goalAreaNum, goalOrigin );
return;
}
int i, areaNum, curAreaNum, travelTime;
idReachability *reach;
idVec3 org, areaCenter;
@@ -288,6 +299,10 @@ idAASLocal::ShowFlyPath
============
*/
void idAASLocal::ShowFlyPath( const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin ) const {
if ( recastNavMesh.IsLoaded() ) {
recastNavMesh.ShowPath( origin, goalAreaNum, goalOrigin );
return;
}
int i, areaNum, curAreaNum, travelTime;
idReachability *reach;
idVec3 org, areaCenter;
@@ -476,6 +491,22 @@ idAASLocal::Test
*/
void idAASLocal::Test( const idVec3 &origin ) {
if ( recastNavMesh.IsLoaded() ) {
if ( aas_showRecastNavMesh.GetInteger() > 0 ) {
recastNavMesh.DebugDraw( aas_showRecastNavMesh.GetInteger() );
}
if ( aas_showAreas.GetBool() ) {
ShowArea( origin );
}
if ( aas_showPath.GetInteger() > 0 ) {
ShowWalkPath( origin, aas_showPath.GetInteger(), AreaCenter( aas_showPath.GetInteger() ) );
}
if ( aas_showFlyPath.GetInteger() > 0 ) {
ShowFlyPath( origin, aas_showFlyPath.GetInteger(), AreaCenter( aas_showFlyPath.GetInteger() ) );
}
return;
}
if ( !file ) {
return;
}
+2
View File
@@ -31,6 +31,7 @@ If you have questions concerning this license or the applicable additional terms
#include "AAS.h"
#include "../Pvs.h"
#include "RecastNavMesh.h"
class idRoutingCache {
@@ -125,6 +126,7 @@ public:
private:
idAASFile * file;
idStr name;
idRecastNavMesh recastNavMesh;
private: // routing data
idRoutingCache *** areaCacheIndex; // for each area in each cluster the travel times to all other areas in the cluster
+16
View File
@@ -143,6 +143,10 @@ bool idAASLocal::WalkPathValid( int areaNum, const idVec3 &origin, int goalAreaN
const aasArea_t *area;
idVec3 p, dir;
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.PathValid( areaNum, origin, goalAreaNum, goalOrigin, travelFlags, endPos, endAreaNum );
}
if ( file == NULL ) {
endPos = goalOrigin;
endAreaNum = 0;
@@ -283,6 +287,10 @@ bool idAASLocal::WalkPathToGoal( aasPath_t &path, int areaNum, const idVec3 &ori
idReachability *reach;
idVec3 endPos;
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.PathToGoal( path, areaNum, origin, goalAreaNum, goalOrigin, travelFlags );
}
path.type = PATHTYPE_WALK;
path.moveGoal = origin;
path.moveAreaNum = areaNum;
@@ -402,6 +410,10 @@ idAASLocal::FlyPathValid
bool idAASLocal::FlyPathValid( int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags, idVec3 &endPos, int &endAreaNum ) const {
aasTrace_t trace;
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.PathValid( areaNum, origin, goalAreaNum, goalOrigin, travelFlags, endPos, endAreaNum );
}
if ( file == NULL ) {
endPos = goalOrigin;
endAreaNum = 0;
@@ -459,6 +471,10 @@ bool idAASLocal::FlyPathToGoal( aasPath_t &path, int areaNum, const idVec3 &orig
idReachability *reach;
idVec3 endPos;
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.PathToGoal( path, areaNum, origin, goalAreaNum, goalOrigin, travelFlags );
}
path.type = PATHTYPE_WALK;
path.moveGoal = origin;
path.moveAreaNum = areaNum;
+29
View File
@@ -435,6 +435,10 @@ idAASLocal::SetAreaState
bool idAASLocal::SetAreaState( const idBounds &bounds, const int areaContents, bool disabled ) {
idBounds expBounds;
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.SetAreaState( bounds, areaContents, disabled );
}
if ( !file ) {
return false;
}
@@ -537,6 +541,10 @@ idAASLocal::AddObstacle
aasHandle_t idAASLocal::AddObstacle( const idBounds &bounds ) {
idRoutingObstacle *obstacle;
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.AddObstacle( bounds );
}
if ( !file ) {
return -1;
}
@@ -557,6 +565,10 @@ idAASLocal::RemoveObstacle
============
*/
void idAASLocal::RemoveObstacle( const aasHandle_t handle ) {
if ( recastNavMesh.IsLoaded() ) {
recastNavMesh.RemoveObstacle( handle );
return;
}
if ( !file ) {
return;
}
@@ -576,6 +588,11 @@ idAASLocal::RemoveAllObstacles
void idAASLocal::RemoveAllObstacles( void ) {
int i;
if ( recastNavMesh.IsLoaded() ) {
recastNavMesh.RemoveAllObstacles();
return;
}
if ( !file ) {
return;
}
@@ -1002,6 +1019,10 @@ bool idAASLocal::RouteToGoalArea( int areaNum, const idVec3 origin, int goalArea
travelTime = 0;
*reach = NULL;
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.RouteToGoalArea( areaNum, origin, goalAreaNum, travelFlags, travelTime, reach );
}
if ( !file ) {
return false;
}
@@ -1151,6 +1172,10 @@ int idAASLocal::TravelTimeToGoalArea( int areaNum, const idVec3 &origin, int goa
int travelTime;
idReachability *reach;
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.TravelTimeToGoalArea( areaNum, origin, goalAreaNum, travelFlags );
}
if ( !file ) {
return 0;
}
@@ -1175,6 +1200,10 @@ bool idAASLocal::FindNearestGoal( aasGoal_t &goal, int areaNum, const idVec3 ori
idVec3 v1, v2, p;
float targetDist, dist;
if ( recastNavMesh.IsLoaded() ) {
return recastNavMesh.FindNearestGoal( this, goal, areaNum, origin, target, travelFlags, obstacles, numObstacles, callback );
}
if ( file == NULL || areaNum <= 0 ) {
goal.areaNum = areaNum;
goal.origin = origin;