Vector hasher is now a separate class
This commit is contained in:
parent
ed6c37febc
commit
f44d123ba8
@ -145,7 +145,7 @@ private:
|
||||
|
||||
/* Pathfinding fields */
|
||||
std::priority_queue<cPathCell *, std::vector<cPathCell *>, compareHeuristics> m_OpenList;
|
||||
std::unordered_map<Vector3i, cPathCell, Vector3i> m_Map;
|
||||
std::unordered_map<Vector3i, cPathCell, VectorHasher<int>> m_Map;
|
||||
Vector3i m_Destination;
|
||||
Vector3i m_Source;
|
||||
int m_BoundingBoxWidth;
|
||||
|
@ -76,19 +76,21 @@ private:
|
||||
{
|
||||
public:
|
||||
/// Per-chunk data for the simulator, specified individual chunks to simulate
|
||||
std::unordered_map<Vector3i, std::pair<BLOCKTYPE, bool>, Vector3i> m_ChunkData;
|
||||
|
||||
/** test */
|
||||
std::unordered_map<Vector3i, std::pair<BLOCKTYPE, bool>, VectorHasher<int>> m_ChunkData;
|
||||
std::vector<sPoweredBlocks> m_PoweredBlocks;
|
||||
std::vector<sLinkedPoweredBlocks> m_LinkedBlocks;
|
||||
std::unordered_map<Vector3i, bool, Vector3i> m_SimulatedPlayerToggleableBlocks;
|
||||
std::unordered_map<Vector3i, sRepeatersDelayList, Vector3i> m_RepeatersDelayList;
|
||||
std::unordered_map<Vector3i, bool, VectorHasher<int>> m_SimulatedPlayerToggleableBlocks;
|
||||
std::unordered_map<Vector3i, sRepeatersDelayList, VectorHasher<int>> m_RepeatersDelayList;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
typedef std::vector <sPoweredBlocks> PoweredBlocksList;
|
||||
typedef std::vector <sLinkedPoweredBlocks> LinkedBlocksList;
|
||||
typedef std::unordered_map<Vector3i, bool, Vector3i> SimulatedPlayerToggleableList;
|
||||
typedef std::unordered_map<Vector3i, sRepeatersDelayList, Vector3i> RepeatersDelayList;
|
||||
typedef std::unordered_map<Vector3i, bool, VectorHasher<int>> SimulatedPlayerToggleableList;
|
||||
typedef std::unordered_map<Vector3i, sRepeatersDelayList, VectorHasher<int>> RepeatersDelayList;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -235,12 +235,6 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Provides a hash of a vector's contents */
|
||||
size_t operator()(const Vector3<T> & a_Vector) const
|
||||
{
|
||||
return ((std::hash<T>()(a_Vector.x) ^ (std::hash<T>()(a_Vector.y) << 1)) ^ std::hash<T>()(a_Vector.z));
|
||||
}
|
||||
|
||||
// tolua_begin
|
||||
|
||||
inline Vector3<T> operator + (const Vector3<T>& a_Rhs) const
|
||||
@ -390,6 +384,28 @@ template <> inline Vector3<int> Vector3<int>::Floor(void) const
|
||||
|
||||
|
||||
|
||||
template <typename What>
|
||||
class VectorHasher
|
||||
{
|
||||
public:
|
||||
/** Provides a hash of a vector's contents */
|
||||
size_t operator()(const Vector3<What> & a_Vector) const
|
||||
{
|
||||
// Guaranteed to have no hash collisions for any 128x128x128 area
|
||||
size_t Hash = 0;
|
||||
Hash ^= static_cast<size_t>(a_Vector.x);
|
||||
Hash <<= 8;
|
||||
Hash ^= static_cast<size_t>(a_Vector.y);
|
||||
Hash <<= 8;
|
||||
Hash ^= static_cast<size_t>(a_Vector.z);
|
||||
return Hash;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
const double Vector3<T>::EPS = 0.000001;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user