diff --git a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h index b7e28223..ae74f9a2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h +++ b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h @@ -45,8 +45,8 @@ namespace PolyVox /// This function provides the default method for checking whether a given voxel /// is valid for the path computed by the AStarPathfinder. - template< template class VolumeType, typename VoxelType> - bool aStarDefaultVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos); + template + bool aStarDefaultVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos); /// Provides a configuration for the AStarPathfinder. //////////////////////////////////////////////////////////////////////////////// @@ -59,20 +59,20 @@ namespace PolyVox /// /// \sa AStarPathfinder //////////////////////////////////////////////////////////////////////////////// - template< template class VolumeType, typename VoxelType> + template struct AStarPathfinderParams { public: AStarPathfinderParams ( - VolumeType* volData, + VolumeType* volData, const Vector3DInt32& v3dStart, const Vector3DInt32& v3dEnd, std::list* listResult, float fHBias = 1.0, uint32_t uMaxNoOfNodes = 10000, Connectivity connectivity = TwentySixConnected, - polyvox_function*, const Vector3DInt32&)> funcIsVoxelValidForPath = &aStarDefaultVoxelValidator, + polyvox_function funcIsVoxelValidForPath = &aStarDefaultVoxelValidator, polyvox_function funcProgressCallback = 0 ) :volume(volData) @@ -88,7 +88,7 @@ namespace PolyVox } /// This is the volume through which the AStarPathfinder must find a path. - VolumeType* volume; + VolumeType* volume; /// The start point for the pathfinding algorithm. Vector3DInt32 start; @@ -127,7 +127,7 @@ namespace PolyVox /// you could check to ensure that the voxel above is empty and the voxel below is solid. /// /// \sa aStarDefaultVoxelValidator - polyvox_function*, const Vector3DInt32&)> isVoxelValidForPath; + polyvox_function isVoxelValidForPath; /// This function is called by the AStarPathfinder to report on its progress in getting to /// the goal. The progress is reported by computing the distance from the closest node found @@ -161,11 +161,11 @@ namespace PolyVox /// /// \sa AStarPathfinderParams //////////////////////////////////////////////////////////////////////////////// - template< template class VolumeType, typename VoxelType> + template class AStarPathfinder { public: - AStarPathfinder(const AStarPathfinderParams& params); + AStarPathfinder(const AStarPathfinderParams& params); void execute(); @@ -187,7 +187,7 @@ namespace PolyVox float m_fProgress; - AStarPathfinderParams m_params; + AStarPathfinderParams m_params; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl index 764488f8..03670d02 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl @@ -28,8 +28,8 @@ namespace PolyVox /// volume and if its density is below that returned by the voxel's getDensity() function. /// \return true is the voxel is valid for the path //////////////////////////////////////////////////////////////////////////////// - template< template class VolumeType, typename VoxelType> - bool aStarDefaultVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos) + template + bool aStarDefaultVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos) { //Voxels are considered valid candidates for the path if they are inside the volume... if(volData->getEnclosingRegion().containsPoint(v3dPos) == false) @@ -43,14 +43,14 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// // AStarPathfinder Class //////////////////////////////////////////////////////////////////////////////// - template< template class VolumeType, typename VoxelType> - AStarPathfinder::AStarPathfinder(const AStarPathfinderParams& params) + template + AStarPathfinder::AStarPathfinder(const AStarPathfinderParams& params) :m_params(params) { } - template< template class VolumeType, typename VoxelType> - void AStarPathfinder::execute() + template + void AStarPathfinder::execute() { //Clear any existing nodes allNodes.clear(); @@ -182,8 +182,8 @@ namespace PolyVox } } - template< template class VolumeType, typename VoxelType> - void AStarPathfinder::processNeighbour(const Vector3DInt32& neighbourPos, float neighbourGVal) + template + void AStarPathfinder::processNeighbour(const Vector3DInt32& neighbourPos, float neighbourGVal) { bool bIsVoxelValidForPath = m_params.isVoxelValidForPath(m_params.volume, neighbourPos); if(!bIsVoxelValidForPath) @@ -238,8 +238,8 @@ namespace PolyVox } } - template< template class VolumeType, typename VoxelType> - float AStarPathfinder::SixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b) + template + float AStarPathfinder::SixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b) { //This is the only heuristic I'm sure of - just use the manhatten distance for the 6-connected case. uint32_t faceSteps = std::abs(a.getX()-b.getX()) + std::abs(a.getY()-b.getY()) + std::abs(a.getZ()-b.getZ()); @@ -247,8 +247,8 @@ namespace PolyVox return faceSteps * 1.0f; } - template< template class VolumeType, typename VoxelType> - float AStarPathfinder::EighteenConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b) + template + float AStarPathfinder::EighteenConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b) { //I'm not sure of the correct heuristic for the 18-connected case, so I'm just letting it fall through to the //6-connected case. This means 'h' will be bigger than it should be, resulting in a faster path which may not @@ -257,8 +257,8 @@ namespace PolyVox return SixConnectedCost(a,b); } - template< template class VolumeType, typename VoxelType> - float AStarPathfinder::TwentySixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b) + template + float AStarPathfinder::TwentySixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b) { //Can't say I'm certain about this heuristic - if anyone has //a better idea of what it should be then please let me know. @@ -279,8 +279,8 @@ namespace PolyVox return cornerSteps * sqrt_3 + edgeSteps * sqrt_2 + faceSteps * sqrt_1; } - template< template class VolumeType, typename VoxelType> - float AStarPathfinder::computeH(const Vector3DInt32& a, const Vector3DInt32& b) + template + float AStarPathfinder::computeH(const Vector3DInt32& a, const Vector3DInt32& b) { float hVal; diff --git a/tests/TestAStarPathfinder.cpp b/tests/TestAStarPathfinder.cpp index d1c97dc7..11e92af6 100644 --- a/tests/TestAStarPathfinder.cpp +++ b/tests/TestAStarPathfinder.cpp @@ -150,8 +150,8 @@ void TestAStarPathfinder::testExecute() std::list result; //Create an AStarPathfinder - AStarPathfinderParams params(&volData, Vector3DInt32(0,0,0), Vector3DInt32(15,15,15), &result, 1.0f, 10000, TwentySixConnected, &testVoxelValidator); - AStarPathfinder pathfinder(params); + AStarPathfinderParams< RawVolume > params(&volData, Vector3DInt32(0,0,0), Vector3DInt32(15,15,15), &result, 1.0f, 10000, TwentySixConnected, &testVoxelValidator); + AStarPathfinder< RawVolume > pathfinder(params); //Execute the pathfinder. pathfinder.execute();