Made EntityWrapper hashable

This commit is contained in:
2016-01-18 14:55:49 +01:00
parent 504f301e4d
commit 3bc7dceca5
2 changed files with 17 additions and 2 deletions
+16 -1
View File
@@ -2,6 +2,7 @@
#define EntityWrapper_h__
#include <boost/optional.hpp>
#include <boost/functional/hash.hpp>
#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<EntityWrapper>
{
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
+1 -1
View File
@@ -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);
}