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 <limits>
|
||||||
#include <cstdlib> //For abort()
|
#include <cstdlib> //For abort()
|
||||||
#include <cstring> //For memcpy
|
#include <cstring> //For memcpy
|
||||||
|
#include <unordered_map>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -284,24 +285,8 @@ namespace PolyVox
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct BlockPositionCompare
|
typedef std::unordered_map<Vector3DInt32, std::shared_ptr< UncompressedBlock<VoxelType> > > SharedPtrBlockMap;
|
||||||
{
|
typedef std::unordered_map<Vector3DInt32, std::weak_ptr< UncompressedBlock<VoxelType> > > WeakPtrBlockMap;
|
||||||
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;
|
|
||||||
|
|
||||||
void initialise();
|
void initialise();
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
@ -228,6 +229,19 @@ namespace PolyVox
|
|||||||
|
|
||||||
}//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"
|
#include "PolyVoxCore/Vector.inl"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user