From 3bc7dceca5dbd5d3e97262b006e3f655b8a0189b Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 18 Jan 2016 14:55:49 +0100 Subject: [PATCH] Made EntityWrapper hashable --- include/Engine/Core/EntityWrapper.h | 17 ++++++++++++++++- src/Engine/Core/EntityWrapper.cpp | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/Engine/Core/EntityWrapper.h b/include/Engine/Core/EntityWrapper.h index e4be8d78..79f90f33 100644 --- a/include/Engine/Core/EntityWrapper.h +++ b/include/Engine/Core/EntityWrapper.h @@ -2,6 +2,7 @@ #define EntityWrapper_h__ #include +#include #include "ComponentWrapper.h" class World; @@ -26,9 +27,23 @@ struct EntityWrapper bool Valid(); ComponentWrapper operator[](const char* componentName); - bool operator==(const EntityWrapper& e); + bool operator==(const EntityWrapper& e) const; explicit operator EntityID() const; operator bool(); }; +namespace std +{ + template<> struct hash + { + std::size_t operator()(const EntityWrapper& e) const + { + std::size_t seed = 0; + boost::hash_combine(seed, e.World); + boost::hash_combine(seed, e.ID); + return seed; + } + }; +} + #endif diff --git a/src/Engine/Core/EntityWrapper.cpp b/src/Engine/Core/EntityWrapper.cpp index c3c5cf27..8c1ab10d 100644 --- a/src/Engine/Core/EntityWrapper.cpp +++ b/src/Engine/Core/EntityWrapper.cpp @@ -3,7 +3,7 @@ const EntityWrapper EntityWrapper::Invalid = EntityWrapper(nullptr, EntityID_Invalid); -bool EntityWrapper::operator==(const EntityWrapper& e) +bool EntityWrapper::operator==(const EntityWrapper& e) const { return (this->World == e.World) && (this->ID == e.ID); }