@ -27,6 +27,89 @@ namespace DetourNavigator
int mSize ;
} ;
struct RecastMeshData
{
std : : vector < int > mIndices ;
std : : vector < float > mVertices ;
std : : vector < AreaType > mAreaTypes ;
std : : vector < RecastMesh : : Water > mWater ;
} ;
inline bool operator < ( const RecastMeshData & lhs , const RecastMeshData & rhs )
{
return std : : tie ( lhs . mIndices , lhs . mVertices , lhs . mAreaTypes , lhs . mWater )
< std : : tie ( rhs . mIndices , rhs . mVertices , rhs . mAreaTypes , rhs . mWater ) ;
}
inline bool operator < ( const RecastMeshData & lhs , const RecastMesh & rhs )
{
return std : : tie ( lhs . mIndices , lhs . mVertices , lhs . mAreaTypes , lhs . mWater )
< std : : tie ( rhs . getIndices ( ) , rhs . getVertices ( ) , rhs . getAreaTypes ( ) , rhs . getWater ( ) ) ;
}
inline bool operator < ( const RecastMesh & lhs , const RecastMeshData & rhs )
{
return std : : tie ( lhs . getIndices ( ) , lhs . getVertices ( ) , lhs . getAreaTypes ( ) , lhs . getWater ( ) )
< std : : tie ( rhs . mIndices , rhs . mVertices , rhs . mAreaTypes , rhs . mWater ) ;
}
struct NavMeshKey
{
RecastMeshData mRecastMesh ;
std : : vector < OffMeshConnection > mOffMeshConnections ;
} ;
inline bool operator < ( const NavMeshKey & lhs , const NavMeshKey & rhs )
{
return std : : tie ( lhs . mRecastMesh , lhs . mOffMeshConnections )
< std : : tie ( rhs . mRecastMesh , rhs . mOffMeshConnections ) ;
}
struct NavMeshKeyRef
{
std : : reference_wrapper < const NavMeshKey > mRef ;
explicit NavMeshKeyRef ( const NavMeshKey & ref ) : mRef ( ref ) { }
} ;
inline bool operator < ( const NavMeshKeyRef & lhs , const NavMeshKeyRef & rhs )
{
return lhs . mRef . get ( ) < rhs . mRef . get ( ) ;
}
struct NavMeshKeyView
{
std : : reference_wrapper < const RecastMesh > mRecastMesh ;
std : : reference_wrapper < const std : : vector < OffMeshConnection > > mOffMeshConnections ;
NavMeshKeyView ( const RecastMesh & recastMesh , const std : : vector < OffMeshConnection > & offMeshConnections )
: mRecastMesh ( recastMesh ) , mOffMeshConnections ( offMeshConnections ) { }
} ;
inline bool operator < ( const NavMeshKeyView & lhs , const NavMeshKey & rhs )
{
return std : : tie ( lhs . mRecastMesh . get ( ) , lhs . mOffMeshConnections . get ( ) )
< std : : tie ( rhs . mRecastMesh , rhs . mOffMeshConnections ) ;
}
inline bool operator < ( const NavMeshKey & lhs , const NavMeshKeyView & rhs )
{
return std : : tie ( lhs . mRecastMesh , lhs . mOffMeshConnections )
< std : : tie ( rhs . mRecastMesh . get ( ) , rhs . mOffMeshConnections . get ( ) ) ;
}
template < class R >
inline bool operator < ( const NavMeshKeyRef & lhs , const R & rhs )
{
return lhs . mRef . get ( ) < rhs ;
}
template < class L >
inline bool operator < ( const L & lhs , const NavMeshKeyRef & rhs )
{
return lhs < rhs . mRef . get ( ) ;
}
class NavMeshTilesCache
{
public :
@ -35,14 +118,16 @@ namespace DetourNavigator
std : : atomic < std : : int64_t > mUseCount ;
osg : : Vec3f mAgentHalfExtents ;
TilePosition mChangedTile ;
std: : vector < unsigned char > mNavMeshKey ;
NavMeshKey mNavMeshKey ;
NavMeshData mNavMeshData ;
std : : size_t mSize ;
Item ( const osg : : Vec3f & agentHalfExtents , const TilePosition & changedTile , std: : vector < unsigned char > & & navMeshKey )
Item ( const osg : : Vec3f & agentHalfExtents , const TilePosition & changedTile , NavMeshKey& & navMeshKey , std : : size_t size )
: mUseCount ( 0 )
, mAgentHalfExtents ( agentHalfExtents )
, mChangedTile ( changedTile )
, mNavMeshKey ( std : : move ( navMeshKey ) )
, mNavMeshKey ( navMeshKey )
, mSize ( size )
{ }
} ;
@ -115,79 +200,9 @@ namespace DetourNavigator
void reportStats ( unsigned int frameNumber , osg : : Stats & stats ) const ;
private :
class KeyView
{
public :
KeyView ( ) = default ;
virtual ~ KeyView ( ) = default ;
KeyView ( const std : : vector < unsigned char > & value )
: mValue ( & value ) { }
const std : : vector < unsigned char > & getValue ( ) const
{
assert ( mValue ) ;
return * mValue ;
}
virtual int compare ( const std : : vector < unsigned char > & other ) const
{
assert ( mValue ) ;
const auto valueSize = mValue - > size ( ) ;
const auto otherSize = other . size ( ) ;
if ( const auto result = std : : memcmp ( mValue - > data ( ) , other . data ( ) , std : : min ( valueSize , otherSize ) ) )
return result ;
if ( valueSize < otherSize )
return - 1 ;
if ( valueSize > otherSize )
return 1 ;
return 0 ;
}
virtual bool isLess ( const KeyView & other ) const
{
assert ( mValue ) ;
return other . compare ( * mValue ) > 0 ;
}
friend bool operator < ( const KeyView & lhs , const KeyView & rhs )
{
return lhs . isLess ( rhs ) ;
}
private :
const std : : vector < unsigned char > * mValue = nullptr ;
} ;
class RecastMeshKeyView : public KeyView
{
public :
RecastMeshKeyView ( const RecastMesh & recastMesh , const std : : vector < OffMeshConnection > & offMeshConnections )
: mRecastMesh ( recastMesh ) , mOffMeshConnections ( offMeshConnections ) { }
int compare ( const std : : vector < unsigned char > & other ) const override ;
bool isLess ( const KeyView & other ) const override
{
return compare ( other . getValue ( ) ) < 0 ;
}
virtual ~ RecastMeshKeyView ( ) = default ;
private :
std : : reference_wrapper < const RecastMesh > mRecastMesh ;
std : : reference_wrapper < const std : : vector < OffMeshConnection > > mOffMeshConnections ;
} ;
struct TileMap
{
std : : map < KeyView, ItemIterator > mMap ;
std : : map < NavMeshKeyRef , ItemIterator , std : : less < > > mMap ;
} ;
mutable std : : mutex mMutex ;
@ -205,11 +220,6 @@ namespace DetourNavigator
void acquireItemUnsafe ( ItemIterator iterator ) ;
void releaseItem ( ItemIterator iterator ) ;
static std : : size_t getSize ( const Item & item )
{
return static_cast < std : : size_t > ( item . mNavMeshData . mSize ) + item . mNavMeshKey . size ( ) ;
}
} ;
}