mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-09 03:57:51 +03:00
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:
parent
1e0c3bfdec
commit
4c15064a83
11 changed files with 159 additions and 32 deletions
|
@ -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;
|
||||
|
||||
|
|
26
components/esm/vec2irefid.cpp
Normal file
26
components/esm/vec2irefid.cpp
Normal 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 << '}';
|
||||
}
|
||||
}
|
52
components/esm/vec2irefid.hpp
Normal file
52
components/esm/vec2irefid.hpp
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue