Made EntityWrapper hashable
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#define EntityWrapper_h__
|
#define EntityWrapper_h__
|
||||||
|
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
#include <boost/functional/hash.hpp>
|
||||||
#include "ComponentWrapper.h"
|
#include "ComponentWrapper.h"
|
||||||
|
|
||||||
class World;
|
class World;
|
||||||
@@ -26,9 +27,23 @@ struct EntityWrapper
|
|||||||
bool Valid();
|
bool Valid();
|
||||||
|
|
||||||
ComponentWrapper operator[](const char* componentName);
|
ComponentWrapper operator[](const char* componentName);
|
||||||
bool operator==(const EntityWrapper& e);
|
bool operator==(const EntityWrapper& e) const;
|
||||||
explicit operator EntityID() const;
|
explicit operator EntityID() const;
|
||||||
operator bool();
|
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
|
#endif
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
const EntityWrapper EntityWrapper::Invalid = EntityWrapper(nullptr, EntityID_Invalid);
|
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);
|
return (this->World == e.World) && (this->ID == e.ID);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user