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
/// is valid for the path computed by the AStarPathfinder.
template< template<typename> class VolumeType, typename VoxelType>
bool aStarDefaultVoxelValidator(const VolumeType<VoxelType>* volData, const Vector3DInt32& v3dPos);
template<typename VolumeType>
bool aStarDefaultVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos);
/// Provides a configuration for the AStarPathfinder.
////////////////////////////////////////////////////////////////////////////////
@ -59,20 +59,20 @@ namespace PolyVox
///
/// \sa AStarPathfinder
////////////////////////////////////////////////////////////////////////////////
template< template<typename> class VolumeType, typename VoxelType>
template<typename VolumeType>
struct AStarPathfinderParams
{
public:
AStarPathfinderParams
(
VolumeType<VoxelType>* volData,
VolumeType* volData,
const Vector3DInt32& v3dStart,
const Vector3DInt32& v3dEnd,
std::list<Vector3DInt32>* listResult,
float fHBias = 1.0,
uint32_t uMaxNoOfNodes = 10000,
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
)
:volume(volData)
@ -88,7 +88,7 @@ namespace PolyVox
}
/// This is the volume through which the AStarPathfinder must find a path.
VolumeType<VoxelType>* 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<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
/// 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<typename> class VolumeType, typename VoxelType>
template<typename VolumeType>
class AStarPathfinder
{
public:
AStarPathfinder(const AStarPathfinderParams<VolumeType, VoxelType>& params);
AStarPathfinder(const AStarPathfinderParams<VolumeType>& params);
void execute();
@ -187,7 +187,7 @@ namespace PolyVox
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.
/// \return true is the voxel is valid for the path
////////////////////////////////////////////////////////////////////////////////
template< template<typename> class VolumeType, typename VoxelType>
bool aStarDefaultVoxelValidator(const VolumeType<VoxelType>* volData, const Vector3DInt32& v3dPos)
template<typename VolumeType>
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<typename> class VolumeType, typename VoxelType>
AStarPathfinder<VolumeType, VoxelType>::AStarPathfinder(const AStarPathfinderParams<VolumeType, VoxelType>& params)
template<typename VolumeType>
AStarPathfinder<VolumeType>::AStarPathfinder(const AStarPathfinderParams<VolumeType>& params)
:m_params(params)
{
}
template< template<typename> class VolumeType, typename VoxelType>
void AStarPathfinder<VolumeType, VoxelType>::execute()
template<typename VolumeType>
void AStarPathfinder<VolumeType>::execute()
{
//Clear any existing nodes
allNodes.clear();
@ -182,8 +182,8 @@ namespace PolyVox
}
}
template< template<typename> class VolumeType, typename VoxelType>
void AStarPathfinder<VolumeType, VoxelType>::processNeighbour(const Vector3DInt32& neighbourPos, float neighbourGVal)
template<typename VolumeType>
void AStarPathfinder<VolumeType>::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<typename> class VolumeType, typename VoxelType>
float AStarPathfinder<VolumeType, VoxelType>::SixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
template<typename VolumeType>
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.
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<typename> class VolumeType, typename VoxelType>
float AStarPathfinder<VolumeType, VoxelType>::EighteenConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
template<typename VolumeType>
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
//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<typename> class VolumeType, typename VoxelType>
float AStarPathfinder<VolumeType, VoxelType>::TwentySixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
template<typename VolumeType>
float AStarPathfinder<VolumeType>::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<typename> class VolumeType, typename VoxelType>
float AStarPathfinder<VolumeType, VoxelType>::computeH(const Vector3DInt32& a, const Vector3DInt32& b)
template<typename VolumeType>
float AStarPathfinder<VolumeType>::computeH(const Vector3DInt32& a, const Vector3DInt32& b)
{
float hVal;

View File

@ -150,8 +150,8 @@ void TestAStarPathfinder::testExecute()
std::list<Vector3DInt32> result;
//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>);
AStarPathfinder<RawVolume, uint8_t> pathfinder(params);
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);
//Execute the pathfinder.
pathfinder.execute();