summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Mobs/Path.h2
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator.h12
-rw-r--r--src/Vector3.h28
3 files changed, 30 insertions, 12 deletions
diff --git a/src/Mobs/Path.h b/src/Mobs/Path.h
index 491165795..d4ad066e3 100644
--- a/src/Mobs/Path.h
+++ b/src/Mobs/Path.h
@@ -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;
diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h
index b0d3ad7af..9fbefae73 100644
--- a/src/Simulator/IncrementalRedstoneSimulator.h
+++ b/src/Simulator/IncrementalRedstoneSimulator.h
@@ -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:
diff --git a/src/Vector3.h b/src/Vector3.h
index 279fe5cd7..168071469 100644
--- a/src/Vector3.h
+++ b/src/Vector3.h
@@ -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;