diff --git a/Sparky-core/SparkyCore-TODO.txt b/Sparky-core/SparkyCore-TODO.txt index e1c878eb..64ce2066 100644 --- a/Sparky-core/SparkyCore-TODO.txt +++ b/Sparky-core/SparkyCore-TODO.txt @@ -14,5 +14,4 @@ - Better logging. Seriously. - Check for memory leaks. Likely. - Some kind of Asset Server. This needs to support things like memory mapping and virtual file systems. -- Hash functions for maths classes - Raw Input instead of Win32 stuff diff --git a/Sparky-core/src/sp/maths/AABB.h b/Sparky-core/src/sp/maths/AABB.h index bd62eb81..cbf12cee 100644 --- a/Sparky-core/src/sp/maths/AABB.h +++ b/Sparky-core/src/sp/maths/AABB.h @@ -34,4 +34,15 @@ namespace sp { namespace maths { friend std::ostream& operator<<(std::ostream& stream, const AABB& aabb); }; -} } \ No newline at end of file +} } + +namespace std { + template<> + struct hash + { + size_t operator()(const sp::maths::AABB& value) const + { + return std::hash()(value.min) ^ std::hash()(value.max); + } + }; +} \ No newline at end of file diff --git a/Sparky-core/src/sp/maths/Quaternion.h b/Sparky-core/src/sp/maths/Quaternion.h index c941a0ac..f89e950f 100644 --- a/Sparky-core/src/sp/maths/Quaternion.h +++ b/Sparky-core/src/sp/maths/Quaternion.h @@ -98,4 +98,16 @@ namespace sp { namespace maths { }; -} } \ No newline at end of file +} } + +namespace std { + template<> + struct hash + { + size_t operator()(const sp::maths::Quaternion& value) const + { + return std::hash()(value.x) ^ std::hash()(value.y) + ^ std::hash()(value.z) ^ std::hash()(value.w); + } + }; +} \ No newline at end of file diff --git a/Sparky-core/src/sp/maths/Rectangle.h b/Sparky-core/src/sp/maths/Rectangle.h index 4b8ada30..631e70b9 100644 --- a/Sparky-core/src/sp/maths/Rectangle.h +++ b/Sparky-core/src/sp/maths/Rectangle.h @@ -48,4 +48,16 @@ namespace sp { namespace maths { friend std::ostream& operator<<(std::ostream& stream, const Rectangle& Rectangle); }; -} } \ No newline at end of file +} } + +namespace std { + template<> + struct hash + { + size_t operator()(const sp::maths::Rectangle& value) const + { + return std::hash()(value.x) ^ std::hash()(value.y) + ^ std::hash()(value.width) ^ std::hash()(value.height); + } + }; +} \ No newline at end of file diff --git a/Sparky-core/src/sp/maths/mat4.h b/Sparky-core/src/sp/maths/mat4.h index fe68b05e..c6125916 100644 --- a/Sparky-core/src/sp/maths/mat4.h +++ b/Sparky-core/src/sp/maths/mat4.h @@ -56,4 +56,16 @@ namespace sp { namespace maths { String ToString() const; }; -} } \ No newline at end of file +} } + +namespace std { + template<> + struct hash + { + size_t operator()(const sp::maths::mat4& value) const + { + return std::hash()(value.rows[0]) ^ std::hash()(value.rows[1]) + ^ std::hash()(value.rows[2]) ^ std::hash()(value.rows[3]); + } + }; +} \ No newline at end of file diff --git a/Sparky-core/src/sp/maths/vec2.h b/Sparky-core/src/sp/maths/vec2.h index ebeed5ec..87f33bd3 100644 --- a/Sparky-core/src/sp/maths/vec2.h +++ b/Sparky-core/src/sp/maths/vec2.h @@ -65,4 +65,15 @@ namespace sp { namespace maths { friend std::ostream& operator<<(std::ostream& stream, const vec2& vector); }; -} } \ No newline at end of file +} } + +namespace std { + template<> + struct hash + { + size_t operator()(const sp::maths::vec2& value) const + { + return std::hash()(value.x) ^ std::hash()(value.y); + } + }; +} \ No newline at end of file diff --git a/Sparky-core/src/sp/maths/vec3.h b/Sparky-core/src/sp/maths/vec3.h index 7a876373..d32999bb 100644 --- a/Sparky-core/src/sp/maths/vec3.h +++ b/Sparky-core/src/sp/maths/vec3.h @@ -82,4 +82,15 @@ namespace sp { namespace maths { friend std::ostream& operator<<(std::ostream& stream, const vec3& vector); }; -} } \ No newline at end of file +} } + +namespace std { + template<> + struct hash + { + size_t operator()(const sp::maths::vec3& value) const + { + return std::hash()(value.x) ^ std::hash()(value.y) ^ std::hash()(value.z); + } + }; +} \ No newline at end of file diff --git a/Sparky-core/src/sp/maths/vec4.cpp b/Sparky-core/src/sp/maths/vec4.cpp index b7c921fe..63e68e72 100644 --- a/Sparky-core/src/sp/maths/vec4.cpp +++ b/Sparky-core/src/sp/maths/vec4.cpp @@ -110,12 +110,12 @@ namespace sp { namespace maths { return Divide(other); } - bool vec4::operator==(const vec4& other) + bool vec4::operator==(const vec4& other) const { return x == other.x && y == other.y && z == other.z && w == other.w; } - bool vec4::operator!=(const vec4& other) + bool vec4::operator!=(const vec4& other) const { return !(*this == other); } diff --git a/Sparky-core/src/sp/maths/vec4.h b/Sparky-core/src/sp/maths/vec4.h index f7c40845..63be80b0 100644 --- a/Sparky-core/src/sp/maths/vec4.h +++ b/Sparky-core/src/sp/maths/vec4.h @@ -30,8 +30,8 @@ namespace sp { namespace maths { friend vec4 operator*(vec4 left, const vec4& right); friend vec4 operator/(vec4 left, const vec4& right); - bool operator==(const vec4& other); - bool operator!=(const vec4& other); + bool operator==(const vec4& other) const; + bool operator!=(const vec4& other) const; vec4& operator+=(const vec4& other); vec4& operator-=(const vec4& other); @@ -43,4 +43,16 @@ namespace sp { namespace maths { friend std::ostream& operator<<(std::ostream& stream, const vec4& vector); }; -} } \ No newline at end of file +} } + +namespace std { + template<> + struct hash + { + size_t operator()(const sp::maths::vec4& value) const + { + return std::hash()(value.x) ^ std::hash()(value.y) + ^ std::hash()(value.z) ^ std::hash()(value.w); + } + }; +} \ No newline at end of file