mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-26 06:27:45 +00:00
Fixing code for consistency, const correctness, include tree and style.
This commit is contained in:
parent
f1580813d3
commit
e54d546b56
6 changed files with 487 additions and 474 deletions
|
@ -20,6 +20,7 @@
|
||||||
#include "Network/PacketWrappers/UpdateHpMpTpPacket.h"
|
#include "Network/PacketWrappers/UpdateHpMpTpPacket.h"
|
||||||
#include "Network/PacketWrappers/NpcSpawnPacket.h"
|
#include "Network/PacketWrappers/NpcSpawnPacket.h"
|
||||||
#include "Network/PacketWrappers/MoveActorPacket.h"
|
#include "Network/PacketWrappers/MoveActorPacket.h"
|
||||||
|
#include "Navi/NaviProvider.h"
|
||||||
|
|
||||||
#include "StatusEffect/StatusEffect.h"
|
#include "StatusEffect/StatusEffect.h"
|
||||||
#include "Action/ActionCollision.h"
|
#include "Action/ActionCollision.h"
|
||||||
|
|
|
@ -35,6 +35,11 @@ namespace World
|
||||||
TYPE_FORWARD( Session );
|
TYPE_FORWARD( Session );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace World::Navi
|
||||||
|
{
|
||||||
|
TYPE_FORWARD( NaviProvider );
|
||||||
|
}
|
||||||
|
|
||||||
namespace World::Territory::Housing
|
namespace World::Territory::Housing
|
||||||
{
|
{
|
||||||
TYPE_FORWARD( HousingInteriorTerritory );
|
TYPE_FORWARD( HousingInteriorTerritory );
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "NaviMgr.h"
|
#include "NaviMgr.h"
|
||||||
|
#include "Navi/NaviProvider.h"
|
||||||
#include <Logging/Logger.h>
|
#include <Logging/Logger.h>
|
||||||
|
|
||||||
Sapphire::World::Manager::NaviMgr::NaviMgr( FrameworkPtr pFw ) :
|
Sapphire::World::Manager::NaviMgr::NaviMgr( FrameworkPtr pFw ) :
|
||||||
|
@ -7,9 +8,9 @@ Sapphire::World::Manager::NaviMgr::NaviMgr( FrameworkPtr pFw ) :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sapphire::World::Manager::NaviMgr::setupTerritory( std::string internalName )
|
bool Sapphire::World::Manager::NaviMgr::setupTerritory( const std::string& internalName )
|
||||||
{
|
{
|
||||||
auto provider = new NaviProvider( internalName );
|
auto provider = Navi::make_NaviProvider( internalName );
|
||||||
|
|
||||||
if( provider->init() )
|
if( provider->init() )
|
||||||
{
|
{
|
||||||
|
@ -20,7 +21,7 @@ bool Sapphire::World::Manager::NaviMgr::setupTerritory( std::string internalName
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sapphire::NaviProvider* Sapphire::World::Manager::NaviMgr::getNaviProvider( std::string internalName )
|
Sapphire::World::Navi::NaviProviderPtr Sapphire::World::Manager::NaviMgr::getNaviProvider( const std::string& internalName )
|
||||||
{
|
{
|
||||||
if( m_naviProviderTerritoryMap.find( internalName ) != m_naviProviderTerritoryMap.end() )
|
if( m_naviProviderTerritoryMap.find( internalName ) != m_naviProviderTerritoryMap.end() )
|
||||||
return m_naviProviderTerritoryMap[ internalName ];
|
return m_naviProviderTerritoryMap[ internalName ];
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#ifndef SAPPHIRE_NAVIMGR_H
|
#ifndef SAPPHIRE_NAVIMGR_H
|
||||||
#define SAPPHIRE_NAVIMGR_H
|
#define SAPPHIRE_NAVIMGR_H
|
||||||
|
|
||||||
#include "Forwards.h"
|
#include "ForwardsZone.h"
|
||||||
#include "BaseManager.h"
|
#include "BaseManager.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <Navi/NaviProvider.h>
|
|
||||||
|
|
||||||
namespace Sapphire::World::Manager
|
namespace Sapphire::World::Manager
|
||||||
{
|
{
|
||||||
|
@ -17,13 +16,13 @@ namespace Sapphire::World::Manager
|
||||||
NaviMgr( FrameworkPtr pFw );
|
NaviMgr( FrameworkPtr pFw );
|
||||||
virtual ~NaviMgr() = default;
|
virtual ~NaviMgr() = default;
|
||||||
|
|
||||||
bool setupTerritory( std::string internalName );
|
bool setupTerritory( const std::string& internalName );
|
||||||
NaviProvider* getNaviProvider( std::string internalName );
|
Navi::NaviProviderPtr getNaviProvider( const std::string& internalName );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FrameworkPtr m_pFw;
|
FrameworkPtr m_pFw;
|
||||||
|
|
||||||
std::unordered_map<std::string, NaviProvider*> m_naviProviderTerritoryMap;
|
std::unordered_map< std::string, Navi::NaviProviderPtr > m_naviProviderTerritoryMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <experimental/filesystem>
|
#include <experimental/filesystem>
|
||||||
|
|
||||||
|
|
||||||
Sapphire::NaviProvider::NaviProvider( std::string internalName ) :
|
Sapphire::World::Navi::NaviProvider::NaviProvider( const std::string& internalName ) :
|
||||||
m_naviMesh( nullptr ),
|
m_naviMesh( nullptr ),
|
||||||
m_naviMeshQuery( nullptr ),
|
m_naviMeshQuery( nullptr ),
|
||||||
m_internalName( internalName )
|
m_internalName( internalName )
|
||||||
|
@ -23,7 +23,7 @@ Sapphire::NaviProvider::NaviProvider( std::string internalName ) :
|
||||||
m_polyFindRange[2] = 10;
|
m_polyFindRange[2] = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sapphire::NaviProvider::init()
|
bool Sapphire::World::Navi::NaviProvider::init()
|
||||||
{
|
{
|
||||||
auto meshesFolder = std::experimental::filesystem::path( "navi" );
|
auto meshesFolder = std::experimental::filesystem::path( "navi" );
|
||||||
auto meshFolder = meshesFolder / std::experimental::filesystem::path( m_internalName );
|
auto meshFolder = meshesFolder / std::experimental::filesystem::path( m_internalName );
|
||||||
|
@ -42,33 +42,33 @@ bool Sapphire::NaviProvider::init()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sapphire::NaviProvider::hasNaviMesh() const
|
bool Sapphire::World::Navi::NaviProvider::hasNaviMesh() const
|
||||||
{
|
{
|
||||||
return m_naviMesh != nullptr;
|
return m_naviMesh != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sapphire::NaviProvider::initQuery()
|
void Sapphire::World::Navi::NaviProvider::initQuery()
|
||||||
{
|
{
|
||||||
if( m_naviMeshQuery != nullptr )
|
if( m_naviMeshQuery )
|
||||||
dtFreeNavMeshQuery( m_naviMeshQuery );
|
dtFreeNavMeshQuery( m_naviMeshQuery );
|
||||||
|
|
||||||
m_naviMeshQuery = dtAllocNavMeshQuery();
|
m_naviMeshQuery = dtAllocNavMeshQuery();
|
||||||
m_naviMeshQuery->init( m_naviMesh, 2048 );
|
m_naviMeshQuery->init( m_naviMesh, 2048 );
|
||||||
}
|
}
|
||||||
|
|
||||||
int Sapphire::NaviProvider::fixupCorridor( dtPolyRef* path, const int npath, const int maxPath,
|
int32_t Sapphire::World::Navi::NaviProvider::fixupCorridor( dtPolyRef* path, const int32_t npath, const int32_t maxPath,
|
||||||
const dtPolyRef* visited, const int nvisited )
|
const dtPolyRef* visited, const int32_t nvisited )
|
||||||
{
|
{
|
||||||
int furthestPath = -1;
|
int32_t furthestPath = -1;
|
||||||
int furthestVisited = -1;
|
int32_t furthestVisited = -1;
|
||||||
|
|
||||||
// Find furthest common polygon.
|
// Find furthest common polygon.
|
||||||
for( int i = npath - 1; i >= 0; --i )
|
for( int32_t i = npath - 1; i >= 0; --i )
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for( int j = nvisited - 1; j >= 0; --j )
|
for( int32_t j = nvisited - 1; j >= 0; --j )
|
||||||
{
|
{
|
||||||
if( path[i] == visited[j] )
|
if( path[ i ] == visited[ j ] )
|
||||||
{
|
{
|
||||||
furthestPath = i;
|
furthestPath = i;
|
||||||
furthestVisited = j;
|
furthestVisited = j;
|
||||||
|
@ -86,54 +86,56 @@ int Sapphire::NaviProvider::fixupCorridor( dtPolyRef* path, const int npath, con
|
||||||
// Concatenate paths.
|
// Concatenate paths.
|
||||||
|
|
||||||
// Adjust beginning of the buffer to include the visited.
|
// Adjust beginning of the buffer to include the visited.
|
||||||
const int req = nvisited - furthestVisited;
|
const int32_t req = nvisited - furthestVisited;
|
||||||
const int orig = rcMin( furthestPath + 1, npath );
|
const int32_t orig = rcMin( furthestPath + 1, npath );
|
||||||
int size = rcMax( 0, npath - orig );
|
int32_t size = rcMax( 0, npath - orig );
|
||||||
if( req + size > maxPath )
|
if( req + size > maxPath )
|
||||||
size = maxPath - req;
|
size = maxPath - req;
|
||||||
if( size )
|
if( size )
|
||||||
memmove( path + req, path + orig, size * sizeof( dtPolyRef ) );
|
memmove( path + req, path + orig, size * sizeof( dtPolyRef ) );
|
||||||
|
|
||||||
// Store visited
|
// Store visited
|
||||||
for( int i = 0; i < req; ++i )
|
for( int32_t i = 0; i < req; ++i )
|
||||||
path[i] = visited[( nvisited - 1 ) - i];
|
path[i] = visited[( nvisited - 1 ) - i];
|
||||||
|
|
||||||
return req + size;
|
return req + size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Sapphire::NaviProvider::fixupShortcuts( dtPolyRef* path, int npath, dtNavMeshQuery* navQuery )
|
int32_t Sapphire::World::Navi::NaviProvider::fixupShortcuts( dtPolyRef* path, int32_t npath, dtNavMeshQuery* navQuery )
|
||||||
{
|
{
|
||||||
if( npath < 3 )
|
if( npath < 3 )
|
||||||
return npath;
|
return npath;
|
||||||
|
|
||||||
// Get connected polygons
|
// Get connected polygons
|
||||||
static const int maxNeis = 16;
|
static const int32_t maxNeis = 16;
|
||||||
dtPolyRef neis[maxNeis];
|
dtPolyRef neis[ maxNeis ];
|
||||||
int nneis = 0;
|
int32_t nneis = 0;
|
||||||
|
|
||||||
const dtMeshTile* tile = 0;
|
const dtMeshTile* tile = 0;
|
||||||
const dtPoly* poly = 0;
|
const dtPoly* poly = 0;
|
||||||
if( dtStatusFailed( navQuery->getAttachedNavMesh()->getTileAndPolyByRef( path[0], &tile, &poly ) ) )
|
if( dtStatusFailed( navQuery->getAttachedNavMesh()->getTileAndPolyByRef( path[ 0 ], &tile, &poly ) ) )
|
||||||
return npath;
|
return npath;
|
||||||
|
|
||||||
for( unsigned int k = poly->firstLink; k != DT_NULL_LINK; k = tile->links[k].next )
|
for( uint32_t k = poly->firstLink; k != DT_NULL_LINK; k = tile->links[ k ].next )
|
||||||
{
|
{
|
||||||
const dtLink* link = &tile->links[k];
|
const dtLink* link = &tile->links[ k ];
|
||||||
if( link->ref != 0 )
|
if( link->ref != 0 )
|
||||||
{
|
{
|
||||||
if( nneis < maxNeis )
|
if( nneis < maxNeis )
|
||||||
neis[nneis++] = link->ref;
|
neis[ nneis++ ] = link->ref;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If any of the neighbour polygons is within the next few polygons
|
// If any of the neighbour polygons is within the next few polygons
|
||||||
// in the path, short cut to that polygon directly.
|
// in the path, short cut to that polygon directly.
|
||||||
static const int maxLookAhead = 6;
|
static const int32_t maxLookAhead = 6;
|
||||||
int cut = 0;
|
int32_t cut = 0;
|
||||||
for( int i = dtMin( maxLookAhead, npath ) - 1; i > 1 && cut == 0; i-- ) {
|
for( int32_t i = dtMin( maxLookAhead, npath ) - 1; i > 1 && cut == 0; i-- )
|
||||||
for( int j = 0; j < nneis; j++ )
|
{
|
||||||
|
for( int32_t j = 0; j < nneis; j++ )
|
||||||
{
|
{
|
||||||
if( path[i] == neis[j] ) {
|
if( path[ i ] == neis[ j ] )
|
||||||
|
{
|
||||||
cut = i;
|
cut = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -141,35 +143,34 @@ int Sapphire::NaviProvider::fixupShortcuts( dtPolyRef* path, int npath, dtNavMes
|
||||||
}
|
}
|
||||||
if( cut > 1 )
|
if( cut > 1 )
|
||||||
{
|
{
|
||||||
int offset = cut - 1;
|
int32_t offset = cut - 1;
|
||||||
npath -= offset;
|
npath -= offset;
|
||||||
for( int i = 1; i < npath; i++ )
|
for( int32_t i = 1; i < npath; i++ )
|
||||||
path[i] = path[i + offset];
|
path[ i ] = path[ i + offset ];
|
||||||
}
|
}
|
||||||
|
|
||||||
return npath;
|
return npath;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sapphire::NaviProvider::inRange( const float* v1, const float* v2, const float r, const float h )
|
bool Sapphire::World::Navi::NaviProvider::inRange( const float* v1, const float* v2, const float r, const float h )
|
||||||
{
|
{
|
||||||
const float dx = v2[0] - v1[0];
|
const float dx = v2[ 0 ] - v1[ 0 ];
|
||||||
const float dy = v2[1] - v1[1];
|
const float dy = v2[ 1 ] - v1[ 1 ];
|
||||||
const float dz = v2[2] - v1[2];
|
const float dz = v2[ 2 ] - v1[ 2 ];
|
||||||
return ( dx*dx + dz * dz ) < r*r && fabsf( dy ) < h;
|
return ( dx * dx + dz * dz ) < r * r && fabsf( dy ) < h;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sapphire::NaviProvider::getSteerTarget( dtNavMeshQuery* navQuery, const float* startPos, const float* endPos,
|
bool Sapphire::World::Navi::NaviProvider::getSteerTarget( dtNavMeshQuery* navQuery, const float* startPos, const float* endPos,
|
||||||
const float minTargetDist,
|
const float minTargetDist, const dtPolyRef* path, const int32_t pathSize,
|
||||||
const dtPolyRef* path, const int pathSize,
|
float* steerPos, unsigned char& steerPosFlag, dtPolyRef& steerPosRef,
|
||||||
float* steerPos, unsigned char& steerPosFlag, dtPolyRef& steerPosRef,
|
float* outPoints, int32_t* outPointCount )
|
||||||
float* outPoints, int* outPointCount )
|
|
||||||
{
|
{
|
||||||
// Find steer target.
|
// Find steer target.
|
||||||
static const int MAX_STEER_POINTS = 3;
|
static const int32_t MAX_STEER_POINTS = 3;
|
||||||
float steerPath[MAX_STEER_POINTS * 3];
|
float steerPath[ MAX_STEER_POINTS * 3 ];
|
||||||
unsigned char steerPathFlags[MAX_STEER_POINTS];
|
uint8_t steerPathFlags[ MAX_STEER_POINTS ];
|
||||||
dtPolyRef steerPathPolys[MAX_STEER_POINTS];
|
dtPolyRef steerPathPolys[ MAX_STEER_POINTS ];
|
||||||
int nsteerPath = 0;
|
int32_t nsteerPath = 0;
|
||||||
navQuery->findStraightPath( startPos, endPos, path, pathSize,
|
navQuery->findStraightPath( startPos, endPos, path, pathSize,
|
||||||
steerPath, steerPathFlags, steerPathPolys, &nsteerPath, MAX_STEER_POINTS );
|
steerPath, steerPathFlags, steerPathPolys, &nsteerPath, MAX_STEER_POINTS );
|
||||||
if( !nsteerPath )
|
if( !nsteerPath )
|
||||||
|
@ -178,18 +179,17 @@ bool Sapphire::NaviProvider::getSteerTarget( dtNavMeshQuery* navQuery, const flo
|
||||||
if( outPoints && outPointCount )
|
if( outPoints && outPointCount )
|
||||||
{
|
{
|
||||||
*outPointCount = nsteerPath;
|
*outPointCount = nsteerPath;
|
||||||
for( int i = 0; i < nsteerPath; ++i )
|
for( int32_t i = 0; i < nsteerPath; ++i )
|
||||||
dtVcopy( &outPoints[i * 3], &steerPath[i * 3] );
|
dtVcopy( &outPoints[ i * 3 ], &steerPath[ i * 3 ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Find vertex far enough to steer to.
|
// Find vertex far enough to steer to.
|
||||||
int ns = 0;
|
int32_t ns = 0;
|
||||||
while( ns < nsteerPath )
|
while( ns < nsteerPath )
|
||||||
{
|
{
|
||||||
// Stop at Off-Mesh link or when point is further than slop away.
|
// Stop at Off-Mesh link or when point is further than slop away.
|
||||||
if( ( steerPathFlags[ns] & DT_STRAIGHTPATH_OFFMESH_CONNECTION ) ||
|
if( ( steerPathFlags[ ns ] & DT_STRAIGHTPATH_OFFMESH_CONNECTION ) ||
|
||||||
!inRange( &steerPath[ns * 3], startPos, minTargetDist, 1000.0f ) )
|
!inRange( &steerPath[ ns * 3 ], startPos, minTargetDist, 1000.0f ) )
|
||||||
break;
|
break;
|
||||||
ns++;
|
ns++;
|
||||||
}
|
}
|
||||||
|
@ -197,15 +197,17 @@ bool Sapphire::NaviProvider::getSteerTarget( dtNavMeshQuery* navQuery, const flo
|
||||||
if( ns >= nsteerPath )
|
if( ns >= nsteerPath )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
dtVcopy( steerPos, &steerPath[ns * 3] );
|
dtVcopy( steerPos, &steerPath[ ns * 3 ] );
|
||||||
steerPos[1] = startPos[1];
|
steerPos[ 1 ] = startPos[ 1 ];
|
||||||
steerPosFlag = steerPathFlags[ns];
|
steerPosFlag = steerPathFlags[ ns ];
|
||||||
steerPosRef = steerPathPolys[ns];
|
steerPosRef = steerPathPolys[ ns ];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::findFollowPath( Common::FFXIVARR_POSITION3 startPos, Common::FFXIVARR_POSITION3 endPos )
|
std::vector< Sapphire::Common::FFXIVARR_POSITION3 >
|
||||||
|
Sapphire::World::Navi::NaviProvider::findFollowPath( const Common::FFXIVARR_POSITION3& startPos,
|
||||||
|
const Common::FFXIVARR_POSITION3& endPos )
|
||||||
{
|
{
|
||||||
if( !m_naviMesh || !m_naviMeshQuery )
|
if( !m_naviMesh || !m_naviMeshQuery )
|
||||||
throw std::runtime_error( "No navimesh loaded" );
|
throw std::runtime_error( "No navimesh loaded" );
|
||||||
|
@ -214,8 +216,8 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::find
|
||||||
|
|
||||||
dtPolyRef startRef, endRef = 0;
|
dtPolyRef startRef, endRef = 0;
|
||||||
|
|
||||||
float spos[3] = {startPos.x, startPos.y, startPos.z};
|
float spos[ 3 ] = { startPos.x, startPos.y, startPos.z };
|
||||||
float epos[3] = {endPos.x, endPos.y, endPos.z};
|
float epos[ 3 ] = { endPos.x, endPos.y, endPos.z };
|
||||||
|
|
||||||
dtQueryFilter filter;
|
dtQueryFilter filter;
|
||||||
filter.setIncludeFlags( 0xffff );
|
filter.setIncludeFlags( 0xffff );
|
||||||
|
@ -228,8 +230,8 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::find
|
||||||
if( !startRef || !endRef )
|
if( !startRef || !endRef )
|
||||||
return resultCoords;
|
return resultCoords;
|
||||||
|
|
||||||
dtPolyRef polys[MAX_POLYS];
|
dtPolyRef polys[ MAX_POLYS ];
|
||||||
int numPolys = 0;
|
int32_t numPolys = 0;
|
||||||
|
|
||||||
m_naviMeshQuery->findPath( startRef, endRef, spos, epos, &filter, polys, &numPolys, MAX_POLYS );
|
m_naviMeshQuery->findPath( startRef, endRef, spos, epos, &filter, polys, &numPolys, MAX_POLYS );
|
||||||
|
|
||||||
|
@ -238,21 +240,23 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::find
|
||||||
{
|
{
|
||||||
// Iterate over the path to find smooth path on the detail mesh surface.
|
// Iterate over the path to find smooth path on the detail mesh surface.
|
||||||
memcpy( polys, polys, sizeof( dtPolyRef )*numPolys );
|
memcpy( polys, polys, sizeof( dtPolyRef )*numPolys );
|
||||||
int npolys = numPolys;
|
int32_t npolys = numPolys;
|
||||||
|
|
||||||
float iterPos[3], targetPos[3];
|
float iterPos[3], targetPos[3];
|
||||||
m_naviMeshQuery->closestPointOnPoly( startRef, spos, iterPos, 0 );
|
m_naviMeshQuery->closestPointOnPoly( startRef, spos, iterPos, 0 );
|
||||||
m_naviMeshQuery->closestPointOnPoly( polys[npolys - 1], epos, targetPos, 0 );
|
m_naviMeshQuery->closestPointOnPoly( polys[ npolys - 1 ], epos, targetPos, 0 );
|
||||||
|
|
||||||
Logger::debug("IterPos: {0} {1} {2}; TargetPos: {3} {4} {5}", iterPos[0], iterPos[1], iterPos[2], targetPos[0], targetPos[1], targetPos[2]);
|
Logger::debug( "IterPos: {0} {1} {2}; TargetPos: {3} {4} {5}",
|
||||||
|
iterPos[ 0 ], iterPos[ 1 ], iterPos[ 2 ],
|
||||||
|
targetPos[ 0 ], targetPos[ 1 ], targetPos[ 2 ] );
|
||||||
|
|
||||||
static const float STEP_SIZE = 1.2f;
|
static const float STEP_SIZE = 1.2f;
|
||||||
static const float SLOP = 0.15f;
|
static const float SLOP = 0.15f;
|
||||||
|
|
||||||
int numSmoothPath = 0;
|
int32_t numSmoothPath = 0;
|
||||||
float smoothPath[MAX_SMOOTH * 3];
|
float smoothPath[ MAX_SMOOTH * 3 ];
|
||||||
|
|
||||||
dtVcopy( &smoothPath[numSmoothPath * 3], iterPos );
|
dtVcopy( &smoothPath[ numSmoothPath * 3 ], iterPos );
|
||||||
numSmoothPath++;
|
numSmoothPath++;
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -260,8 +264,8 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::find
|
||||||
while( npolys && numSmoothPath < MAX_SMOOTH )
|
while( npolys && numSmoothPath < MAX_SMOOTH )
|
||||||
{
|
{
|
||||||
// Find location to steer towards.
|
// Find location to steer towards.
|
||||||
float steerPos[3];
|
float steerPos[ 3 ];
|
||||||
unsigned char steerPosFlag;
|
uint8_t steerPosFlag;
|
||||||
dtPolyRef steerPosRef;
|
dtPolyRef steerPosRef;
|
||||||
|
|
||||||
if( !getSteerTarget( m_naviMeshQuery, iterPos, targetPos, SLOP,
|
if( !getSteerTarget( m_naviMeshQuery, iterPos, targetPos, SLOP,
|
||||||
|
@ -272,7 +276,7 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::find
|
||||||
bool offMeshConnection = ( steerPosFlag & DT_STRAIGHTPATH_OFFMESH_CONNECTION ) ? true : false;
|
bool offMeshConnection = ( steerPosFlag & DT_STRAIGHTPATH_OFFMESH_CONNECTION ) ? true : false;
|
||||||
|
|
||||||
// Find movement delta.
|
// Find movement delta.
|
||||||
float delta[3], len;
|
float delta[ 3 ], len;
|
||||||
dtVsub( delta, steerPos, iterPos );
|
dtVsub( delta, steerPos, iterPos );
|
||||||
len = dtMathSqrtf( dtVdot( delta, delta ) );
|
len = dtMathSqrtf( dtVdot( delta, delta ) );
|
||||||
// If the steer target is end of path or off-mesh link, do not move past the location.
|
// If the steer target is end of path or off-mesh link, do not move past the location.
|
||||||
|
@ -280,14 +284,14 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::find
|
||||||
len = 1;
|
len = 1;
|
||||||
else
|
else
|
||||||
len = STEP_SIZE / len;
|
len = STEP_SIZE / len;
|
||||||
float moveTgt[3];
|
float moveTgt[ 3 ];
|
||||||
dtVmad( moveTgt, iterPos, delta, len );
|
dtVmad( moveTgt, iterPos, delta, len );
|
||||||
|
|
||||||
// Move
|
// Move
|
||||||
float result[3];
|
float result[ 3 ];
|
||||||
dtPolyRef visited[16];
|
dtPolyRef visited[ 16 ];
|
||||||
int nvisited = 0;
|
int32_t nvisited = 0;
|
||||||
m_naviMeshQuery->moveAlongSurface( polys[0], iterPos, moveTgt, &filter,
|
m_naviMeshQuery->moveAlongSurface( polys[ 0 ], iterPos, moveTgt, &filter,
|
||||||
result, visited, &nvisited, 16 );
|
result, visited, &nvisited, 16 );
|
||||||
|
|
||||||
npolys = fixupCorridor( polys, npolys, MAX_POLYS, visited, nvisited );
|
npolys = fixupCorridor( polys, npolys, MAX_POLYS, visited, nvisited );
|
||||||
|
@ -295,7 +299,7 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::find
|
||||||
|
|
||||||
float h = 0;
|
float h = 0;
|
||||||
m_naviMeshQuery->getPolyHeight( polys[0], result, &h );
|
m_naviMeshQuery->getPolyHeight( polys[0], result, &h );
|
||||||
result[1] = h;
|
result[ 1 ] = h;
|
||||||
dtVcopy( iterPos, result );
|
dtVcopy( iterPos, result );
|
||||||
|
|
||||||
// Handle end of path and off-mesh links when close enough.
|
// Handle end of path and off-mesh links when close enough.
|
||||||
|
@ -305,7 +309,7 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::find
|
||||||
dtVcopy( iterPos, targetPos );
|
dtVcopy( iterPos, targetPos );
|
||||||
if( numSmoothPath < MAX_SMOOTH )
|
if( numSmoothPath < MAX_SMOOTH )
|
||||||
{
|
{
|
||||||
dtVcopy( &smoothPath[numSmoothPath * 3], iterPos );
|
dtVcopy( &smoothPath[ numSmoothPath * 3 ], iterPos );
|
||||||
numSmoothPath++;
|
numSmoothPath++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -313,19 +317,19 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::find
|
||||||
else if( offMeshConnection && inRange( iterPos, steerPos, SLOP, 1.0f ) )
|
else if( offMeshConnection && inRange( iterPos, steerPos, SLOP, 1.0f ) )
|
||||||
{
|
{
|
||||||
// Reached off-mesh connection.
|
// Reached off-mesh connection.
|
||||||
float startPos[3], endPos[3];
|
float startPos[ 3 ], endPos[ 3 ];
|
||||||
|
|
||||||
// Advance the path up to and over the off-mesh connection.
|
// Advance the path up to and over the off-mesh connection.
|
||||||
dtPolyRef prevRef = 0, polyRef = polys[0];
|
dtPolyRef prevRef = 0, polyRef = polys[ 0 ];
|
||||||
int npos = 0;
|
int32_t npos = 0;
|
||||||
while( npos < npolys && polyRef != steerPosRef )
|
while( npos < npolys && polyRef != steerPosRef )
|
||||||
{
|
{
|
||||||
prevRef = polyRef;
|
prevRef = polyRef;
|
||||||
polyRef = polys[npos];
|
polyRef = polys[ npos ];
|
||||||
npos++;
|
npos++;
|
||||||
}
|
}
|
||||||
for( int i = npos; i < npolys; ++i )
|
for( int32_t i = npos; i < npolys; ++i )
|
||||||
polys[i - npos] = polys[i];
|
polys[ i - npos ] = polys[ i ];
|
||||||
npolys -= npos;
|
npolys -= npos;
|
||||||
|
|
||||||
// Handle the connection.
|
// Handle the connection.
|
||||||
|
@ -334,41 +338,41 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::find
|
||||||
{
|
{
|
||||||
if( numSmoothPath < MAX_SMOOTH )
|
if( numSmoothPath < MAX_SMOOTH )
|
||||||
{
|
{
|
||||||
dtVcopy( &smoothPath[numSmoothPath * 3], startPos );
|
dtVcopy( &smoothPath[ numSmoothPath * 3 ], startPos );
|
||||||
numSmoothPath++;
|
numSmoothPath++;
|
||||||
// Hack to make the dotted path not visible during off-mesh connection.
|
// Hack to make the dotted path not visible during off-mesh connection.
|
||||||
if( numSmoothPath & 1 )
|
if( numSmoothPath & 1 )
|
||||||
{
|
{
|
||||||
dtVcopy( &smoothPath[numSmoothPath * 3], startPos );
|
dtVcopy( &smoothPath[ numSmoothPath * 3 ], startPos );
|
||||||
numSmoothPath++;
|
numSmoothPath++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Move position at the other side of the off-mesh link.
|
// Move position at the other side of the off-mesh link.
|
||||||
dtVcopy( iterPos, endPos );
|
dtVcopy( iterPos, endPos );
|
||||||
float eh = 0.0f;
|
float eh = 0.0f;
|
||||||
m_naviMeshQuery->getPolyHeight( polys[0], iterPos, &eh );
|
m_naviMeshQuery->getPolyHeight( polys[ 0 ], iterPos, &eh );
|
||||||
iterPos[1] = eh;
|
iterPos[ 1 ] = eh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store results.
|
// Store results.
|
||||||
if( numSmoothPath < MAX_SMOOTH )
|
if( numSmoothPath < MAX_SMOOTH )
|
||||||
{
|
{
|
||||||
dtVcopy( &smoothPath[numSmoothPath * 3], iterPos );
|
dtVcopy( &smoothPath[ numSmoothPath * 3 ], iterPos );
|
||||||
numSmoothPath++;
|
numSmoothPath++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int i = 0; i < numSmoothPath; i += 3 )
|
for( int32_t i = 0; i < numSmoothPath; i += 3 )
|
||||||
{
|
{
|
||||||
resultCoords.push_back( Common::FFXIVARR_POSITION3{ smoothPath[i], smoothPath[i + 1], smoothPath[i + 2] } );
|
resultCoords.push_back( Common::FFXIVARR_POSITION3{ smoothPath[ i ], smoothPath[ i + 1 ], smoothPath[ i + 2 ] } );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultCoords;
|
return resultCoords;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sapphire::NaviProvider::loadMesh( std::string path )
|
void Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path )
|
||||||
{
|
{
|
||||||
FILE* fp = fopen( path.c_str(), "rb" );
|
FILE* fp = fopen( path.c_str(), "rb" );
|
||||||
if( !fp )
|
if( !fp )
|
||||||
|
@ -414,7 +418,7 @@ void Sapphire::NaviProvider::loadMesh( std::string path )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read tiles.
|
// Read tiles.
|
||||||
for( int i = 0; i < header.numTiles; ++i )
|
for( int32_t i = 0; i < header.numTiles; ++i )
|
||||||
{
|
{
|
||||||
NavMeshTileHeader tileHeader;
|
NavMeshTileHeader tileHeader;
|
||||||
readLen = fread( &tileHeader, sizeof( tileHeader ), 1, fp );
|
readLen = fread( &tileHeader, sizeof( tileHeader ), 1, fp );
|
||||||
|
@ -427,8 +431,9 @@ void Sapphire::NaviProvider::loadMesh( std::string path )
|
||||||
if( !tileHeader.tileRef || !tileHeader.dataSize )
|
if( !tileHeader.tileRef || !tileHeader.dataSize )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
unsigned char* data = (unsigned char*)dtAlloc( tileHeader.dataSize, DT_ALLOC_PERM );
|
uint8_t* data = reinterpret_cast< uint8_t* >( dtAlloc( tileHeader.dataSize, DT_ALLOC_PERM ) );
|
||||||
if( !data ) break;
|
if( !data )
|
||||||
|
break;
|
||||||
memset( data, 0, tileHeader.dataSize );
|
memset( data, 0, tileHeader.dataSize );
|
||||||
readLen = fread( data, tileHeader.dataSize, 1, fp );
|
readLen = fread( data, tileHeader.dataSize, 1, fp );
|
||||||
if( readLen != 1 )
|
if( readLen != 1 )
|
||||||
|
|
|
@ -6,43 +6,43 @@
|
||||||
#include <recastnavigation/Detour/Include/DetourNavMesh.h>
|
#include <recastnavigation/Detour/Include/DetourNavMesh.h>
|
||||||
#include <recastnavigation/Detour/Include/DetourNavMeshQuery.h>
|
#include <recastnavigation/Detour/Include/DetourNavMeshQuery.h>
|
||||||
|
|
||||||
namespace Sapphire
|
namespace Sapphire::World::Navi
|
||||||
{
|
{
|
||||||
|
|
||||||
class NaviProvider
|
class NaviProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
static const int NAVMESHSET_MAGIC = 'M' << 24 | 'S' << 16 | 'E' << 8 | 'T'; //'MSET';
|
static const int32_t NAVMESHSET_MAGIC = 'M' << 24 | 'S' << 16 | 'E' << 8 | 'T'; //'MSET'
|
||||||
static const int NAVMESHSET_VERSION = 1;
|
static const int32_t NAVMESHSET_VERSION = 1;
|
||||||
|
|
||||||
struct NavMeshSetHeader
|
struct NavMeshSetHeader
|
||||||
{
|
{
|
||||||
int magic;
|
int32_t magic;
|
||||||
int version;
|
int32_t version;
|
||||||
int numTiles;
|
int32_t numTiles;
|
||||||
dtNavMeshParams params;
|
dtNavMeshParams params;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NavMeshTileHeader
|
struct NavMeshTileHeader
|
||||||
{
|
{
|
||||||
dtTileRef tileRef;
|
dtTileRef tileRef;
|
||||||
int dataSize;
|
int32_t dataSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int MAX_POLYS = 256;
|
static const int32_t MAX_POLYS = 256;
|
||||||
static const int MAX_SMOOTH = 2048;
|
static const int32_t MAX_SMOOTH = 2048;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NaviProvider( const std::string internalName );
|
NaviProvider( const std::string& internalName );
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
void loadMesh( std::string path );
|
void loadMesh( const std::string& path );
|
||||||
void initQuery();
|
void initQuery();
|
||||||
|
|
||||||
void toDetourPos(const Common::FFXIVARR_POSITION3 position, float* out);
|
void toDetourPos( const Common::FFXIVARR_POSITION3& position, float* out );
|
||||||
Sapphire::Common::FFXIVARR_POSITION3 toGamePos( float* pos );
|
Common::FFXIVARR_POSITION3 toGamePos( float* pos );
|
||||||
|
|
||||||
std::vector< Sapphire::Common::FFXIVARR_POSITION3 > findFollowPath(Common::FFXIVARR_POSITION3 startPos, Common::FFXIVARR_POSITION3 endPos);
|
std::vector< Common::FFXIVARR_POSITION3 > findFollowPath( const Common::FFXIVARR_POSITION3& startPos, const Common::FFXIVARR_POSITION3& endPos );
|
||||||
|
|
||||||
bool hasNaviMesh() const;
|
bool hasNaviMesh() const;
|
||||||
|
|
||||||
|
@ -52,13 +52,15 @@ namespace Sapphire
|
||||||
dtNavMesh* m_naviMesh;
|
dtNavMesh* m_naviMesh;
|
||||||
dtNavMeshQuery* m_naviMeshQuery;
|
dtNavMeshQuery* m_naviMeshQuery;
|
||||||
|
|
||||||
float m_polyFindRange[3];
|
float m_polyFindRange[ 3 ];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int fixupCorridor( dtPolyRef* path, const int npath, const int maxPath, const dtPolyRef* visited, const int nvisited );
|
static int32_t fixupCorridor( dtPolyRef* path, int32_t npath, int32_t maxPath, const dtPolyRef* visited, int32_t nvisited );
|
||||||
static int fixupShortcuts( dtPolyRef* path, int npath, dtNavMeshQuery* navQuery );
|
static int32_t fixupShortcuts( dtPolyRef* path, int32_t npath, dtNavMeshQuery* navQuery );
|
||||||
inline static bool inRange( const float* v1, const float* v2, const float r, const float h );
|
inline static bool inRange( const float* v1, const float* v2, const float r, const float h );
|
||||||
static bool getSteerTarget( dtNavMeshQuery* navQuery, const float* startPos, const float* endPos, const float minTargetDist, const dtPolyRef* path, const int pathSize, float* steerPos, unsigned char& steerPosFlag, dtPolyRef& steerPosRef, float* outPoints = 0, int* outPointCount = 0 );
|
static bool getSteerTarget( dtNavMeshQuery* navQuery, const float* startPos, const float* endPos, const float minTargetDist,
|
||||||
|
const dtPolyRef* path, const int32_t pathSize, float* steerPos, uint8_t& steerPosFlag,
|
||||||
|
dtPolyRef& steerPosRef, float* outPoints = 0, int32_t* outPointCount = 0 );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue