Blocks now stored in an unordered_map (hash based) rather than a map.
This commit is contained in:
parent
2602b00103
commit
3a08487dc2
@ -33,6 +33,7 @@ freely, subject to the following restrictions:
|
||||
#include <limits>
|
||||
#include <cstdlib> //For abort()
|
||||
#include <cstring> //For memcpy
|
||||
#include <unordered_map>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@ -284,24 +285,8 @@ namespace PolyVox
|
||||
|
||||
private:
|
||||
|
||||
struct BlockPositionCompare
|
||||
{
|
||||
bool operator() (const PolyVox::Vector3DInt32& a, const PolyVox::Vector3DInt32& b) const
|
||||
{
|
||||
const uint32_t size = 3;
|
||||
for(uint32_t ct = 0; ct < size; ++ct)
|
||||
{
|
||||
if (a.getElement(ct) < b.getElement(ct))
|
||||
return true;
|
||||
if (b.getElement(ct) < a.getElement(ct))
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<Vector3DInt32, std::shared_ptr< UncompressedBlock<VoxelType> >, BlockPositionCompare> SharedPtrBlockMap;
|
||||
typedef std::map<Vector3DInt32, std::weak_ptr< UncompressedBlock<VoxelType> >, BlockPositionCompare> WeakPtrBlockMap;
|
||||
typedef std::unordered_map<Vector3DInt32, std::shared_ptr< UncompressedBlock<VoxelType> > > SharedPtrBlockMap;
|
||||
typedef std::unordered_map<Vector3DInt32, std::weak_ptr< UncompressedBlock<VoxelType> > > WeakPtrBlockMap;
|
||||
|
||||
void initialise();
|
||||
|
||||
|
@ -31,6 +31,7 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
namespace PolyVox
|
||||
@ -228,6 +229,19 @@ namespace PolyVox
|
||||
|
||||
}//namespace PolyVox
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<PolyVox::Vector3DInt32>
|
||||
{
|
||||
std::size_t operator()(const PolyVox::Vector3DInt32& vec) const
|
||||
{
|
||||
return ((vec.getX() & 0xFF)) | ((vec.getY() & 0xFF) << 8) | ((vec.getZ() & 0xFF) << 16);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#include "PolyVoxCore/Vector.inl"
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user