mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-30 16:17:46 +00:00
More pathing
This commit is contained in:
parent
78c0878610
commit
8c6c8bc787
6 changed files with 42 additions and 35 deletions
|
@ -153,7 +153,7 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
|
||||||
// reached destination
|
// reached destination
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
auto path = m_pCurrentZone->GetNaviProvider()->PathFindFollow( m_pos, pos );
|
auto path = m_pCurrentZone->getNaviProvider()->findFollowPath( m_pos, pos );
|
||||||
|
|
||||||
//face( path[0] );
|
//face( path[0] );
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ bool Sapphire::World::Manager::TerritoryMgr::createDefaultTerritories()
|
||||||
territoryInfo->name,
|
territoryInfo->name,
|
||||||
( isPrivateTerritory( territoryTypeId ) ? "PRIVATE" : "PUBLIC" ),
|
( isPrivateTerritory( territoryTypeId ) ? "PRIVATE" : "PUBLIC" ),
|
||||||
pPlaceName->name,
|
pPlaceName->name,
|
||||||
pZone->GetNaviProvider()->HasNaviMesh() ? "NAVI" : "");
|
pZone->getNaviProvider()->hasNaviMesh() ? "NAVI" : "");
|
||||||
|
|
||||||
InstanceIdToZonePtrMap instanceMap;
|
InstanceIdToZonePtrMap instanceMap;
|
||||||
instanceMap[ guid ] = pZone;
|
instanceMap[ guid ] = pZone;
|
||||||
|
|
|
@ -34,7 +34,7 @@ void Sapphire::NaviProvider::init()
|
||||||
{
|
{
|
||||||
auto baseMesh = meshFolder / std::filesystem::path( m_pZone->getInternalName() + ".nav" );
|
auto baseMesh = meshFolder / std::filesystem::path( m_pZone->getInternalName() + ".nav" );
|
||||||
|
|
||||||
LoadMesh( baseMesh.string() );
|
loadMesh( baseMesh.string() );
|
||||||
|
|
||||||
// Load all meshes for testing
|
// Load all meshes for testing
|
||||||
|
|
||||||
|
@ -49,16 +49,16 @@ void Sapphire::NaviProvider::init()
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
InitQuery();
|
initQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sapphire::NaviProvider::HasNaviMesh() const
|
bool Sapphire::NaviProvider::hasNaviMesh() const
|
||||||
{
|
{
|
||||||
return m_naviMesh != nullptr;
|
return m_naviMesh != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sapphire::NaviProvider::InitQuery()
|
void Sapphire::NaviProvider::initQuery()
|
||||||
{
|
{
|
||||||
if( m_naviMeshQuery != nullptr )
|
if( m_naviMeshQuery != nullptr )
|
||||||
dtFreeNavMeshQuery( m_naviMeshQuery );
|
dtFreeNavMeshQuery( m_naviMeshQuery );
|
||||||
|
@ -216,34 +216,45 @@ static bool getSteerTarget( dtNavMeshQuery* navQuery, const float* startPos, con
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::PathFindFollow( Common::FFXIVARR_POSITION3 startPos, Common::FFXIVARR_POSITION3 endPos )
|
void Sapphire::NaviProvider::toDetourPos( const Sapphire::Common::FFXIVARR_POSITION3 pos, float* out ) {
|
||||||
|
float y = pos.y;
|
||||||
|
float z = pos.z;
|
||||||
|
|
||||||
|
out[0] = pos.x;
|
||||||
|
out[1] = y * -1;
|
||||||
|
out[2] = z * -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::findFollowPath( Common::FFXIVARR_POSITION3 startPos, Common::FFXIVARR_POSITION3 endPos )
|
||||||
{
|
{
|
||||||
if( !m_naviMesh || !m_naviMeshQuery )
|
if( !m_naviMesh || !m_naviMeshQuery )
|
||||||
throw std::exception( "No navimesh loaded" );
|
throw std::exception( "No navimesh loaded" );
|
||||||
|
|
||||||
|
auto resultCoords = std::vector< Common::FFXIVARR_POSITION3 >();
|
||||||
|
|
||||||
dtPolyRef startRef, endRef = 0;
|
dtPolyRef startRef, endRef = 0;
|
||||||
|
|
||||||
float start[3] = { startPos.x, startPos.y, startPos.z };
|
float spos[3];
|
||||||
float end[3] = { endPos.x, endPos.y, endPos.z };
|
NaviProvider::toDetourPos( startPos, spos );
|
||||||
|
|
||||||
|
float epos[3];
|
||||||
|
NaviProvider::toDetourPos( endPos, epos );
|
||||||
|
|
||||||
dtQueryFilter filter;
|
dtQueryFilter filter;
|
||||||
filter.setIncludeFlags(0xffff);
|
filter.setIncludeFlags( 0xffff );
|
||||||
filter.setExcludeFlags(0);
|
filter.setExcludeFlags( 0 );
|
||||||
|
|
||||||
m_naviMeshQuery->findNearestPoly( start, m_polyFindRange, &filter, &startRef, 0 );
|
m_naviMeshQuery->findNearestPoly( spos, m_polyFindRange, &filter, &startRef, 0 );
|
||||||
m_naviMeshQuery->findNearestPoly( end, m_polyFindRange, &filter, &endRef, 0 );
|
m_naviMeshQuery->findNearestPoly( epos, m_polyFindRange, &filter, &endRef, 0 );
|
||||||
|
|
||||||
// Couldn't find any close polys to navigate from
|
// Couldn't find any close polys to navigate from
|
||||||
if( !startRef || !endRef )
|
if( !startRef || !endRef )
|
||||||
return {};
|
return resultCoords;
|
||||||
|
|
||||||
auto pathFindStatus = DT_FAILURE;
|
|
||||||
|
|
||||||
auto pathIterNum = 0;
|
|
||||||
dtPolyRef polys[MAX_POLYS];
|
dtPolyRef polys[MAX_POLYS];
|
||||||
int numPolys = 0;
|
int numPolys = 0;
|
||||||
|
|
||||||
m_naviMeshQuery->findPath( startRef, endRef, start, end, &filter, polys, &numPolys, MAX_POLYS );
|
m_naviMeshQuery->findPath( startRef, endRef, spos, epos, &filter, polys, &numPolys, MAX_POLYS );
|
||||||
|
|
||||||
// Check if we got polys back for navigation
|
// Check if we got polys back for navigation
|
||||||
if( numPolys )
|
if( numPolys )
|
||||||
|
@ -254,8 +265,8 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::Path
|
||||||
int npolys = numPolys;
|
int npolys = numPolys;
|
||||||
|
|
||||||
float iterPos[3], targetPos[3];
|
float iterPos[3], targetPos[3];
|
||||||
m_naviMeshQuery->closestPointOnPoly( startRef, start, iterPos, 0 );
|
m_naviMeshQuery->closestPointOnPoly( startRef, spos, iterPos, 0 );
|
||||||
m_naviMeshQuery->closestPointOnPoly( polys[npolys - 1], end, targetPos, 0 );
|
m_naviMeshQuery->closestPointOnPoly( polys[npolys - 1], epos, targetPos, 0 );
|
||||||
|
|
||||||
static const float STEP_SIZE = 0.5f;
|
static const float STEP_SIZE = 0.5f;
|
||||||
static const float SLOP = 0.01f;
|
static const float SLOP = 0.01f;
|
||||||
|
@ -266,8 +277,6 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::Path
|
||||||
dtVcopy( &smoothPath[numSmoothPath * 3], iterPos );
|
dtVcopy( &smoothPath[numSmoothPath * 3], iterPos );
|
||||||
numSmoothPath++;
|
numSmoothPath++;
|
||||||
|
|
||||||
auto resultCoords = std::vector< Common::FFXIVARR_POSITION3 >();
|
|
||||||
|
|
||||||
// Move towards target a small advancement at a time until target reached or
|
// Move towards target a small advancement at a time until target reached or
|
||||||
// when ran out of memory to store the path.
|
// when ran out of memory to store the path.
|
||||||
while( npolys && numSmoothPath < MAX_SMOOTH )
|
while( npolys && numSmoothPath < MAX_SMOOTH )
|
||||||
|
@ -376,16 +385,12 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::Path
|
||||||
{
|
{
|
||||||
resultCoords.push_back( Common::FFXIVARR_POSITION3{ smoothPath[i], smoothPath[i + 2], smoothPath[i + 3] } );
|
resultCoords.push_back( Common::FFXIVARR_POSITION3{ smoothPath[i], smoothPath[i + 2], smoothPath[i + 3] } );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return resultCoords;
|
return resultCoords;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sapphire::NaviProvider::LoadMesh( std::string path )
|
void Sapphire::NaviProvider::loadMesh( std::string path )
|
||||||
{
|
{
|
||||||
FILE* fp = fopen( path.c_str(), "rb" );
|
FILE* fp = fopen( path.c_str(), "rb" );
|
||||||
if( !fp )
|
if( !fp )
|
||||||
|
|
|
@ -36,12 +36,14 @@ namespace Sapphire
|
||||||
NaviProvider( const ZonePtr pZone, Sapphire::FrameworkPtr pFw );
|
NaviProvider( const ZonePtr pZone, Sapphire::FrameworkPtr pFw );
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void LoadMesh( std::string path );
|
void loadMesh( std::string path );
|
||||||
void InitQuery();
|
void initQuery();
|
||||||
|
|
||||||
std::vector< Sapphire::Common::FFXIVARR_POSITION3 > PathFindFollow(Common::FFXIVARR_POSITION3 startPos, Common::FFXIVARR_POSITION3 endPos);
|
void toDetourPos(const Common::FFXIVARR_POSITION3 position, float* out);
|
||||||
|
|
||||||
bool HasNaviMesh() const;
|
std::vector< Sapphire::Common::FFXIVARR_POSITION3 > findFollowPath(Common::FFXIVARR_POSITION3 startPos, Common::FFXIVARR_POSITION3 endPos);
|
||||||
|
|
||||||
|
bool hasNaviMesh() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FrameworkPtr m_pFw;
|
FrameworkPtr m_pFw;
|
||||||
|
|
|
@ -852,7 +852,7 @@ void Sapphire::Zone::updateSpawnPoints()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Sapphire::NaviProvider* Sapphire::Zone::GetNaviProvider() const
|
Sapphire::NaviProvider* Sapphire::Zone::getNaviProvider() const
|
||||||
{
|
{
|
||||||
return m_naviProvider;
|
return m_naviProvider;
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ namespace Sapphire
|
||||||
|
|
||||||
void updateSpawnPoints();
|
void updateSpawnPoints();
|
||||||
|
|
||||||
NaviProvider* GetNaviProvider() const;
|
NaviProvider* getNaviProvider() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue