summaryrefslogtreecommitdiffstats
path: root/src/model/Position.hpp
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-09-26 00:58:27 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-09-26 00:58:27 +0200
commitc3e32345e53650a1c231f4e1a41d40c97955b893 (patch)
tree93b22aedbe355173510a04eafec9f14d7c4c3e0f /src/model/Position.hpp
parent8b4ca336ce68cc17573115dd07eb1bfc6521b298 (diff)
downloadrpgedit-c3e32345e53650a1c231f4e1a41d40c97955b893.tar
rpgedit-c3e32345e53650a1c231f4e1a41d40c97955b893.zip
Collision rework
Diffstat (limited to 'src/model/Position.hpp')
-rw-r--r--src/model/Position.hpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/model/Position.hpp b/src/model/Position.hpp
index a88c151..c8fc477 100644
--- a/src/model/Position.hpp
+++ b/src/model/Position.hpp
@@ -28,6 +28,8 @@
#include "Direction.hpp"
+#include <functional>
+
namespace RPGEdit {
@@ -41,19 +43,19 @@ struct Position {
Position p = *this;
switch (dir) {
- case NORTH:
+ case Direction::NORTH:
p.y -= amount;
break;
- case EAST:
+ case Direction::EAST:
p.x += amount;
break;
- case SOUTH:
+ case Direction::SOUTH:
p.y += amount;
break;
- case WEST:
+ case Direction::WEST:
p.x -= amount;
}
@@ -64,6 +66,10 @@ struct Position {
return translate(dir, 1);
}
+ bool operator==(const Position<T> &p) const {
+ return (x == p.x) && (y == p.y);
+ }
+
template<typename T2>
explicit operator Position<T2>() const {
return Position<T2>{T2(x), T2(y)};
@@ -73,3 +79,20 @@ struct Position {
}
}
+
+namespace std {
+template<typename T> struct hash<RPGEdit::Model::Position<T>> {
+ typedef size_t result_type;
+ typedef RPGEdit::Model::Position<T> argument_type;
+
+ size_t operator()(const RPGEdit::Model::Position<T> &pos) const noexcept {
+ const int shift = 4*sizeof(size_t); // half the bit count of size_t
+
+ std::hash<T> hash;
+ size_t hash1 = hash(pos.x), hash2 = hash(pos.y);
+
+ return hash1 ^ ((hash2 << shift) | (hash2 >> shift));
+ }
+};
+
+}