mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Merge branch 'esm_ref_id_refactor' into 'master'
Simplify ESM::RefId See merge request OpenMW/openmw!2563
This commit is contained in:
commit
e6064645db
@ -22,6 +22,7 @@
|
||||
#include "esmstore.hpp"
|
||||
#include "player.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace MWWorld
|
||||
@ -932,7 +933,7 @@ namespace MWWorld
|
||||
ESM::WeatherState state;
|
||||
state.load(reader);
|
||||
|
||||
mCurrentRegion.swap(state.mCurrentRegion);
|
||||
std::swap(mCurrentRegion, state.mCurrentRegion);
|
||||
mTimePassed = state.mTimePassed;
|
||||
mFastForward = state.mFastForward;
|
||||
mWeatherUpdateTime = state.mWeatherUpdateTime;
|
||||
|
@ -16,11 +16,6 @@ namespace ESM
|
||||
return Misc::StringUtils::ciLess(mId, rhs.mId);
|
||||
}
|
||||
|
||||
bool RefId::operator>(const RefId& rhs) const
|
||||
{
|
||||
return Misc::StringUtils::ciGreater(mId, rhs.mId);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const RefId& refId)
|
||||
{
|
||||
os << refId.getRefIdString();
|
||||
|
@ -1,6 +1,6 @@
|
||||
#ifndef OPENMW_COMPONENTS_ESM_REFID_HPP
|
||||
#define OPENMW_COMPONENTS_ESM_REFID_HPP
|
||||
#include <compare>
|
||||
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
@ -8,17 +8,18 @@
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
// RefId is used to represent an Id that identifies an ESM record. These Ids can then be used in
|
||||
// ESM::Stores to find the actual record. These Ids can be serialized/de-serialized, stored on disk and remain
|
||||
// valid. They are used by ESM files, by records to reference other ESM records.
|
||||
struct RefId
|
||||
{
|
||||
// This structure is used to represent an Id that identifies an ESM record. These Ids can then be used in
|
||||
// ESM::Stores to find the actual record. These Ids can be serialized/de-serialized, stored on disk and remain
|
||||
// valid. They are used by ESM files, by records to reference other ESM records.
|
||||
const static RefId sEmpty;
|
||||
|
||||
bool empty() const { return mId.empty(); }
|
||||
void swap(RefId& rhs) { mId.swap(rhs.mId); }
|
||||
|
||||
bool operator==(const RefId& rhs) const;
|
||||
|
||||
bool operator<(const RefId& rhs) const;
|
||||
bool operator>(const RefId& rhs) const;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const RefId& dt);
|
||||
|
||||
|
@ -2,8 +2,10 @@
|
||||
#define COMPONENTS_ESM_MAGICEFFECTS_H
|
||||
|
||||
#include <components/esm/refid.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
@ -29,30 +31,25 @@ namespace ESM
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const SummonKey& other) const
|
||||
{
|
||||
return mEffectId == other.mEffectId && mSourceId == other.mSourceId && mEffectIndex == other.mEffectIndex;
|
||||
}
|
||||
|
||||
bool operator<(const SummonKey& other) const
|
||||
{
|
||||
if (mEffectId < other.mEffectId)
|
||||
return true;
|
||||
if (mEffectId > other.mEffectId)
|
||||
return false;
|
||||
|
||||
if (mSourceId < other.mSourceId)
|
||||
return true;
|
||||
if (mSourceId > other.mSourceId)
|
||||
return false;
|
||||
|
||||
return mEffectIndex < other.mEffectIndex;
|
||||
}
|
||||
|
||||
int mEffectId;
|
||||
ESM::RefId mSourceId;
|
||||
int mEffectIndex;
|
||||
};
|
||||
|
||||
inline auto makeTupleRef(const SummonKey& value) noexcept
|
||||
{
|
||||
return std::tie(value.mEffectId, value.mSourceId, value.mEffectIndex);
|
||||
}
|
||||
|
||||
inline bool operator==(const SummonKey& l, const SummonKey& r) noexcept
|
||||
{
|
||||
return makeTupleRef(l) == makeTupleRef(r);
|
||||
}
|
||||
|
||||
inline bool operator<(const SummonKey& l, const SummonKey& r) noexcept
|
||||
{
|
||||
return makeTupleRef(l) < makeTupleRef(r);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -20,16 +20,6 @@ namespace Misc::StringUtils
|
||||
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharLess());
|
||||
}
|
||||
|
||||
struct CiCharGreater
|
||||
{
|
||||
bool operator()(char x, char y) const { return toLower(x) > toLower(y); }
|
||||
};
|
||||
|
||||
inline bool ciGreater(std::string_view x, std::string_view y)
|
||||
{
|
||||
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharGreater());
|
||||
}
|
||||
|
||||
inline bool ciEqual(std::string_view x, std::string_view y)
|
||||
{
|
||||
if (std::size(x) != std::size(y))
|
||||
|
Loading…
x
Reference in New Issue
Block a user