1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 21:42:13 +00:00
OpenMW/components/esm/exteriorcelllocation.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.6 KiB
C++
Raw Normal View History

2024-05-02 01:09:13 +00:00
#ifndef OPENMW_COMPONENTS_ESM_EXTERIORCELLLOCATION_H
#define OPENMW_COMPONENTS_ESM_EXTERIORCELLLOCATION_H
#include "refid.hpp"
#include <components/esm3/loadcell.hpp>
2024-05-01 23:55:36 +00:00
#include <ostream>
2024-05-02 01:09:13 +00:00
#include <tuple>
namespace ESM
{
struct ExteriorCellLocation
{
int mX = 0;
int mY = 0;
ESM::RefId mWorldspace = ESM::Cell::sDefaultWorldspaceId;
ExteriorCellLocation() = default;
ExteriorCellLocation(int x, int y, ESM::RefId worldspace)
: mX(x)
, mY(y)
, mWorldspace(worldspace)
{
}
friend bool operator==(const ExteriorCellLocation& lhs, const ExteriorCellLocation& rhs) = default;
friend inline bool operator<(const ExteriorCellLocation& lhs, const ExteriorCellLocation& rhs)
{
return std::make_tuple(lhs.mX, lhs.mY, lhs.mWorldspace) < std::make_tuple(rhs.mX, rhs.mY, rhs.mWorldspace);
}
2024-05-01 23:55:36 +00:00
friend inline std::ostream& operator<<(std::ostream& stream, const ExteriorCellLocation& value)
{
return stream << "{" << value.mX << ", " << value.mY << ", " << value.mWorldspace << "}";
}
2024-05-02 01:09:13 +00:00
};
}
namespace std
{
template <>
struct hash<ESM::ExteriorCellLocation>
{
std::size_t operator()(const ESM::ExteriorCellLocation& toHash) const
{
// Compute individual hash values for first,
// second and third and combine them using XOR
// and bit shifting:
return ((hash<int>()(toHash.mX) ^ (hash<int>()(toHash.mY) << 1)) >> 1)
^ (hash<ESM::RefId>()(toHash.mWorldspace) << 1);
}
};
}
#endif