Removed use of template template parameters from AStarPathfinder.

This commit is contained in:
unknown 2012-06-05 16:33:29 +02:00
parent 8c02098088
commit c9e83f41f1
3 changed files with 28 additions and 28 deletions

View File

@ -45,8 +45,8 @@ namespace PolyVox
/// This function provides the default method for checking whether a given voxel /// This function provides the default method for checking whether a given voxel
/// is valid for the path computed by the AStarPathfinder. /// is valid for the path computed by the AStarPathfinder.
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
bool aStarDefaultVoxelValidator(const VolumeType<VoxelType>* volData, const Vector3DInt32& v3dPos); bool aStarDefaultVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos);
/// Provides a configuration for the AStarPathfinder. /// Provides a configuration for the AStarPathfinder.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -59,20 +59,20 @@ namespace PolyVox
/// ///
/// \sa AStarPathfinder /// \sa AStarPathfinder
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
struct AStarPathfinderParams struct AStarPathfinderParams
{ {
public: public:
AStarPathfinderParams AStarPathfinderParams
( (
VolumeType<VoxelType>* volData, VolumeType* volData,
const Vector3DInt32& v3dStart, const Vector3DInt32& v3dStart,
const Vector3DInt32& v3dEnd, const Vector3DInt32& v3dEnd,
std::list<Vector3DInt32>* listResult, std::list<Vector3DInt32>* listResult,
float fHBias = 1.0, float fHBias = 1.0,
uint32_t uMaxNoOfNodes = 10000, uint32_t uMaxNoOfNodes = 10000,
Connectivity connectivity = TwentySixConnected, Connectivity connectivity = TwentySixConnected,
polyvox_function<bool (const VolumeType<VoxelType>*, const Vector3DInt32&)> funcIsVoxelValidForPath = &aStarDefaultVoxelValidator, polyvox_function<bool (const VolumeType*, const Vector3DInt32&)> funcIsVoxelValidForPath = &aStarDefaultVoxelValidator,
polyvox_function<void (float)> funcProgressCallback = 0 polyvox_function<void (float)> funcProgressCallback = 0
) )
:volume(volData) :volume(volData)
@ -88,7 +88,7 @@ namespace PolyVox
} }
/// This is the volume through which the AStarPathfinder must find a path. /// This is the volume through which the AStarPathfinder must find a path.
VolumeType<VoxelType>* volume; VolumeType* volume;
/// The start point for the pathfinding algorithm. /// The start point for the pathfinding algorithm.
Vector3DInt32 start; 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. /// you could check to ensure that the voxel above is empty and the voxel below is solid.
/// ///
/// \sa aStarDefaultVoxelValidator /// \sa aStarDefaultVoxelValidator
polyvox_function<bool (const VolumeType<VoxelType>*, const Vector3DInt32&)> isVoxelValidForPath; polyvox_function<bool (const VolumeType*, const Vector3DInt32&)> isVoxelValidForPath;
/// This function is called by the AStarPathfinder to report on its progress in getting to /// 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 /// the goal. The progress is reported by computing the distance from the closest node found
@ -161,11 +161,11 @@ namespace PolyVox
/// ///
/// \sa AStarPathfinderParams /// \sa AStarPathfinderParams
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
class AStarPathfinder class AStarPathfinder
{ {
public: public:
AStarPathfinder(const AStarPathfinderParams<VolumeType, VoxelType>& params); AStarPathfinder(const AStarPathfinderParams<VolumeType>& params);
void execute(); void execute();
@ -187,7 +187,7 @@ namespace PolyVox
float m_fProgress; float m_fProgress;
AStarPathfinderParams<VolumeType, VoxelType> m_params; AStarPathfinderParams<VolumeType> m_params;
}; };
} }

View File

@ -28,8 +28,8 @@ namespace PolyVox
/// volume and if its density is below that returned by the voxel's getDensity() function. /// 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 /// \return true is the voxel is valid for the path
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
bool aStarDefaultVoxelValidator(const VolumeType<VoxelType>* volData, const Vector3DInt32& v3dPos) bool aStarDefaultVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos)
{ {
//Voxels are considered valid candidates for the path if they are inside the volume... //Voxels are considered valid candidates for the path if they are inside the volume...
if(volData->getEnclosingRegion().containsPoint(v3dPos) == false) if(volData->getEnclosingRegion().containsPoint(v3dPos) == false)
@ -43,14 +43,14 @@ namespace PolyVox
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// AStarPathfinder Class // AStarPathfinder Class
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
AStarPathfinder<VolumeType, VoxelType>::AStarPathfinder(const AStarPathfinderParams<VolumeType, VoxelType>& params) AStarPathfinder<VolumeType>::AStarPathfinder(const AStarPathfinderParams<VolumeType>& params)
:m_params(params) :m_params(params)
{ {
} }
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
void AStarPathfinder<VolumeType, VoxelType>::execute() void AStarPathfinder<VolumeType>::execute()
{ {
//Clear any existing nodes //Clear any existing nodes
allNodes.clear(); allNodes.clear();
@ -182,8 +182,8 @@ namespace PolyVox
} }
} }
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
void AStarPathfinder<VolumeType, VoxelType>::processNeighbour(const Vector3DInt32& neighbourPos, float neighbourGVal) void AStarPathfinder<VolumeType>::processNeighbour(const Vector3DInt32& neighbourPos, float neighbourGVal)
{ {
bool bIsVoxelValidForPath = m_params.isVoxelValidForPath(m_params.volume, neighbourPos); bool bIsVoxelValidForPath = m_params.isVoxelValidForPath(m_params.volume, neighbourPos);
if(!bIsVoxelValidForPath) if(!bIsVoxelValidForPath)
@ -238,8 +238,8 @@ namespace PolyVox
} }
} }
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
float AStarPathfinder<VolumeType, VoxelType>::SixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b) float AStarPathfinder<VolumeType>::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. //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()); 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; return faceSteps * 1.0f;
} }
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
float AStarPathfinder<VolumeType, VoxelType>::EighteenConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b) float AStarPathfinder<VolumeType>::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 //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 //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); return SixConnectedCost(a,b);
} }
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
float AStarPathfinder<VolumeType, VoxelType>::TwentySixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b) float AStarPathfinder<VolumeType>::TwentySixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
{ {
//Can't say I'm certain about this heuristic - if anyone has //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. //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; return cornerSteps * sqrt_3 + edgeSteps * sqrt_2 + faceSteps * sqrt_1;
} }
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
float AStarPathfinder<VolumeType, VoxelType>::computeH(const Vector3DInt32& a, const Vector3DInt32& b) float AStarPathfinder<VolumeType>::computeH(const Vector3DInt32& a, const Vector3DInt32& b)
{ {
float hVal; float hVal;

View File

@ -150,8 +150,8 @@ void TestAStarPathfinder::testExecute()
std::list<Vector3DInt32> result; std::list<Vector3DInt32> result;
//Create an AStarPathfinder //Create an AStarPathfinder
AStarPathfinderParams<RawVolume, uint8_t> params(&volData, Vector3DInt32(0,0,0), Vector3DInt32(15,15,15), &result, 1.0f, 10000, TwentySixConnected, &testVoxelValidator<RawVolume, uint8_t>); AStarPathfinderParams< RawVolume<uint8_t> > params(&volData, Vector3DInt32(0,0,0), Vector3DInt32(15,15,15), &result, 1.0f, 10000, TwentySixConnected, &testVoxelValidator<RawVolume, uint8_t>);
AStarPathfinder<RawVolume, uint8_t> pathfinder(params); AStarPathfinder< RawVolume<uint8_t> > pathfinder(params);
//Execute the pathfinder. //Execute the pathfinder.
pathfinder.execute(); pathfinder.execute();