Create new Vec2i RefId for ESM3 exterior cells.

Applies the necessary changes to use !2708 for the new Id type
This commit is contained in:
florent.teppe 2023-03-22 14:01:52 +01:00
parent 1e0c3bfdec
commit 4c15064a83
11 changed files with 159 additions and 32 deletions

View file

@ -14,6 +14,7 @@
#include "generatedrefid.hpp"
#include "indexrefid.hpp"
#include "stringrefid.hpp"
#include "vec2irefid.hpp"
namespace ESM
{
@ -38,6 +39,7 @@ namespace ESM
FormId = 3,
Generated = 4,
Index = 5,
Vec2i = 6,
};
// RefId is used to represent an Id that identifies an ESM record. These Ids can then be used in
@ -70,6 +72,8 @@ namespace ESM
// identified by index (i.e. ESM3 SKIL).
static RefId index(RecNameInts recordType, std::uint32_t value) { return RefId(IndexRefId(recordType, value)); }
static RefId vec2i(std::pair<int32_t, int32_t> value) { return RefId(Vec2iRefId(value)); }
constexpr RefId() = default;
constexpr RefId(EmptyRefId value) noexcept
@ -97,6 +101,11 @@ namespace ESM
{
}
constexpr RefId(Vec2iRefId value) noexcept
: mValue(value)
{
}
// Returns a reference to the value of StringRefId if it's the underlying value or throws an exception.
const std::string& getRefIdString() const;

View file

@ -0,0 +1,26 @@
#include "vec2irefid.hpp"
#include <ostream>
#include <sstream>
namespace ESM
{
std::string Vec2iRefId::toString() const
{
std::ostringstream stream;
stream << "# " << mValue.first << ", " << mValue.second;
return stream.str();
}
std::string Vec2iRefId::toDebugString() const
{
std::ostringstream stream;
stream << *this;
return stream.str();
}
std::ostream& operator<<(std::ostream& stream, Vec2iRefId value)
{
return stream << "Vec2i{" << value.mValue.first << "," << value.mValue.second << '}';
}
}

View file

@ -0,0 +1,52 @@
#ifndef OPENMW_COMPONENTS_ESM_VEC2IREFID_HPP
#define OPENMW_COMPONENTS_ESM_VEC2IREFID_HPP
#include <functional>
#include <iosfwd>
#include <utility>
namespace ESM
{
class Vec2iRefId
{
public:
constexpr Vec2iRefId() = default;
constexpr explicit Vec2iRefId(std::pair<int32_t, int32_t> value) noexcept
: mValue(value)
{
}
std::pair<int32_t, int32_t> getValue() const { return mValue; }
std::string toString() const;
std::string toDebugString() const;
constexpr bool operator==(Vec2iRefId rhs) const noexcept { return mValue == rhs.mValue; }
constexpr bool operator<(Vec2iRefId rhs) const noexcept { return mValue < rhs.mValue; }
friend std::ostream& operator<<(std::ostream& stream, Vec2iRefId value);
friend struct std::hash<Vec2iRefId>;
private:
std::pair<int32_t, int32_t> mValue = std::pair<int32_t, int32_t>(0, 0);
};
}
namespace std
{
template <>
struct hash<ESM::Vec2iRefId>
{
std::size_t operator()(ESM::Vec2iRefId value) const noexcept
{
return (53 + std::hash<int32_t>{}(value.mValue.first)) * 53 + std::hash<int32_t>{}(value.mValue.second);
}
};
}
#endif