mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 12:58:00 +03:00
Apply clang-format to code base
This commit is contained in:
parent
f37d0be806
commit
ddb0522bbf
2199 changed files with 118692 additions and 114392 deletions
|
@ -27,15 +27,15 @@ namespace EsmLoader
|
|||
template <class F>
|
||||
auto returnAs(F&& f)
|
||||
{
|
||||
using Result = decltype(std::forward<F>(f)(ESM::Static {}));
|
||||
using Result = decltype(std::forward<F>(f)(ESM::Static{}));
|
||||
if constexpr (!std::is_same_v<Result, void>)
|
||||
return Result {};
|
||||
return Result{};
|
||||
}
|
||||
|
||||
template <class T, class F>
|
||||
auto withStatic(std::string_view refId, const std::vector<T>& values, F&& f)
|
||||
{
|
||||
const auto it = std::lower_bound(values.begin(), values.end(), refId, LessById {});
|
||||
const auto it = std::lower_bound(values.begin(), values.end(), refId, LessById{});
|
||||
|
||||
if (it == values.end() || it->mId != refId)
|
||||
return returnAs(std::forward<F>(f));
|
||||
|
@ -48,11 +48,16 @@ namespace EsmLoader
|
|||
{
|
||||
switch (type)
|
||||
{
|
||||
case ESM::REC_ACTI: return withStatic(refId, content.mActivators, std::forward<F>(f));
|
||||
case ESM::REC_CONT: return withStatic(refId, content.mContainers, std::forward<F>(f));
|
||||
case ESM::REC_DOOR: return withStatic(refId, content.mDoors, std::forward<F>(f));
|
||||
case ESM::REC_STAT: return withStatic(refId, content.mStatics, std::forward<F>(f));
|
||||
default: break;
|
||||
case ESM::REC_ACTI:
|
||||
return withStatic(refId, content.mActivators, std::forward<F>(f));
|
||||
case ESM::REC_CONT:
|
||||
return withStatic(refId, content.mContainers, std::forward<F>(f));
|
||||
case ESM::REC_DOOR:
|
||||
return withStatic(refId, content.mDoors, std::forward<F>(f));
|
||||
case ESM::REC_STAT:
|
||||
return withStatic(refId, content.mStatics, std::forward<F>(f));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return returnAs(std::forward<F>(f));
|
||||
|
@ -63,13 +68,13 @@ namespace EsmLoader
|
|||
|
||||
std::string_view getModel(const EsmData& content, std::string_view refId, ESM::RecNameInts type)
|
||||
{
|
||||
return withStatic(refId, type, content, [] (const auto& v) { return std::string_view(v.mModel); });
|
||||
return withStatic(refId, type, content, [](const auto& v) { return std::string_view(v.mModel); });
|
||||
}
|
||||
|
||||
ESM::Variant getGameSetting(const std::vector<ESM::GameSetting>& records, std::string_view id)
|
||||
{
|
||||
const std::string lower = Misc::StringUtils::lowerCase(id);
|
||||
auto it = std::lower_bound(records.begin(), records.end(), lower, LessById {});
|
||||
auto it = std::lower_bound(records.begin(), records.end(), lower, LessById{});
|
||||
if (it == records.end() || it->mId != lower)
|
||||
throw std::runtime_error("Game settings \"" + std::string(id) + "\" is not found");
|
||||
return it->mValue;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
#include "record.hpp"
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
#include <components/esm3/cellref.hpp>
|
||||
#include <components/esm/defs.hpp>
|
||||
#include <components/esm3/cellref.hpp>
|
||||
#include <components/esm3/esmreader.hpp>
|
||||
#include <components/esm3/loadacti.hpp>
|
||||
#include <components/esm3/loadcell.hpp>
|
||||
|
@ -14,25 +14,25 @@
|
|||
#include <components/esm3/loadgmst.hpp>
|
||||
#include <components/esm3/loadland.hpp>
|
||||
#include <components/esm3/loadstat.hpp>
|
||||
#include <components/esm3/readerscache.hpp>
|
||||
#include <components/files/collections.hpp>
|
||||
#include <components/files/conversion.hpp>
|
||||
#include <components/files/multidircollection.hpp>
|
||||
#include <components/loadinglistener/loadinglistener.hpp>
|
||||
#include <components/misc/resourcehelpers.hpp>
|
||||
#include <components/misc/strings/lower.hpp>
|
||||
#include <components/esm3/readerscache.hpp>
|
||||
#include <components/loadinglistener/loadinglistener.hpp>
|
||||
#include <components/files/conversion.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <cstddef>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
namespace EsmLoader
|
||||
{
|
||||
|
@ -46,15 +46,9 @@ namespace EsmLoader
|
|||
return (v.mId);
|
||||
}
|
||||
|
||||
const ESM::CellId& operator()(const ESM::Cell& v) const
|
||||
{
|
||||
return v.mCellId;
|
||||
}
|
||||
const ESM::CellId& operator()(const ESM::Cell& v) const { return v.mCellId; }
|
||||
|
||||
std::pair<int, int> operator()(const ESM::Land& v) const
|
||||
{
|
||||
return std::pair(v.mX, v.mY);
|
||||
}
|
||||
std::pair<int, int> operator()(const ESM::Land& v) const { return std::pair(v.mX, v.mY); }
|
||||
|
||||
template <class T>
|
||||
decltype(auto) operator()(const Record<T>& v) const
|
||||
|
@ -71,17 +65,20 @@ namespace EsmLoader
|
|||
};
|
||||
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasId : std::false_type {};
|
||||
struct HasId : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct HasId<T, std::void_t<decltype(T::mId)>> : std::true_type {};
|
||||
struct HasId<T, std::void_t<decltype(T::mId)>> : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
constexpr bool hasId = HasId<T>::value;
|
||||
|
||||
template <class T>
|
||||
auto loadRecord(ESM::ESMReader& reader, Records<T>& records)
|
||||
-> std::enable_if_t<hasId<T>>
|
||||
auto loadRecord(ESM::ESMReader& reader, Records<T>& records) -> std::enable_if_t<hasId<T>>
|
||||
{
|
||||
T record;
|
||||
bool deleted = false;
|
||||
|
@ -93,8 +90,7 @@ namespace EsmLoader
|
|||
}
|
||||
|
||||
template <class T>
|
||||
auto loadRecord(ESM::ESMReader& reader, Records<T>& records)
|
||||
-> std::enable_if_t<!hasId<T>>
|
||||
auto loadRecord(ESM::ESMReader& reader, Records<T>& records) -> std::enable_if_t<!hasId<T>>
|
||||
{
|
||||
T record;
|
||||
bool deleted = false;
|
||||
|
@ -213,12 +209,12 @@ namespace EsmLoader
|
|||
}
|
||||
|
||||
ShallowContent shallowLoad(const Query& query, const std::vector<std::string>& contentFiles,
|
||||
const Files::Collections& fileCollections, ESM::ReadersCache& readers,
|
||||
ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener)
|
||||
const Files::Collections& fileCollections, ESM::ReadersCache& readers, ToUTF8::Utf8Encoder* encoder,
|
||||
Loading::Listener* listener)
|
||||
{
|
||||
ShallowContent result;
|
||||
|
||||
const std::set<std::string> supportedFormats {
|
||||
const std::set<std::string> supportedFormats{
|
||||
".esm",
|
||||
".esp",
|
||||
".omwgame",
|
||||
|
@ -228,8 +224,9 @@ namespace EsmLoader
|
|||
|
||||
for (std::size_t i = 0; i < contentFiles.size(); ++i)
|
||||
{
|
||||
const std::string &file = contentFiles[i];
|
||||
const std::string extension = Misc::StringUtils::lowerCase(Files::pathToUnicodeString(std::filesystem::path(file).extension()));
|
||||
const std::string& file = contentFiles[i];
|
||||
const std::string extension
|
||||
= Misc::StringUtils::lowerCase(Files::pathToUnicodeString(std::filesystem::path(file).extension()));
|
||||
|
||||
if (supportedFormats.find(extension) == supportedFormats.end())
|
||||
{
|
||||
|
@ -263,31 +260,30 @@ namespace EsmLoader
|
|||
ESM::RecNameInts mType;
|
||||
|
||||
template <class T>
|
||||
RefIdWithType operator()(const T& v) const { return {v.mId, mType}; }
|
||||
RefIdWithType operator()(const T& v) const
|
||||
{
|
||||
return { v.mId, mType };
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void addRefIdsTypes(const std::vector<T>& values, std::vector<RefIdWithType>& refIdsTypes)
|
||||
{
|
||||
std::transform(values.begin(), values.end(), std::back_inserter(refIdsTypes),
|
||||
WithType {static_cast<ESM::RecNameInts>(T::sRecordId)});
|
||||
WithType{ static_cast<ESM::RecNameInts>(T::sRecordId) });
|
||||
}
|
||||
|
||||
void addRefIdsTypes(EsmData& content)
|
||||
{
|
||||
content.mRefIdTypes.reserve(
|
||||
content.mActivators.size()
|
||||
+ content.mContainers.size()
|
||||
+ content.mDoors.size()
|
||||
+ content.mStatics.size()
|
||||
);
|
||||
content.mRefIdTypes.reserve(content.mActivators.size() + content.mContainers.size() + content.mDoors.size()
|
||||
+ content.mStatics.size());
|
||||
|
||||
addRefIdsTypes(content.mActivators, content.mRefIdTypes);
|
||||
addRefIdsTypes(content.mContainers, content.mRefIdTypes);
|
||||
addRefIdsTypes(content.mDoors, content.mRefIdTypes);
|
||||
addRefIdsTypes(content.mStatics, content.mRefIdTypes);
|
||||
|
||||
std::sort(content.mRefIdTypes.begin(), content.mRefIdTypes.end(), LessById {});
|
||||
std::sort(content.mRefIdTypes.begin(), content.mRefIdTypes.end(), LessById{});
|
||||
}
|
||||
|
||||
std::vector<ESM::Cell> prepareCellRecords(Records<ESM::Cell>& records)
|
||||
|
@ -330,19 +326,19 @@ namespace EsmLoader
|
|||
EsmData result;
|
||||
|
||||
if (query.mLoadActivators)
|
||||
result.mActivators = prepareRecords(content.mActivators, GetKey {});
|
||||
result.mActivators = prepareRecords(content.mActivators, GetKey{});
|
||||
if (query.mLoadCells)
|
||||
result.mCells = prepareCellRecords(content.mCells.mValues);
|
||||
if (query.mLoadContainers)
|
||||
result.mContainers = prepareRecords(content.mContainers, GetKey {});
|
||||
result.mContainers = prepareRecords(content.mContainers, GetKey{});
|
||||
if (query.mLoadDoors)
|
||||
result.mDoors = prepareRecords(content.mDoors, GetKey {});
|
||||
result.mDoors = prepareRecords(content.mDoors, GetKey{});
|
||||
if (query.mLoadGameSettings)
|
||||
result.mGameSettings = prepareRecords(content.mGameSettings, GetKey {});
|
||||
result.mGameSettings = prepareRecords(content.mGameSettings, GetKey{});
|
||||
if (query.mLoadLands)
|
||||
result.mLands = prepareRecords(content.mLands, GetKey {});
|
||||
result.mLands = prepareRecords(content.mLands, GetKey{});
|
||||
if (query.mLoadStatics)
|
||||
result.mStatics = prepareRecords(content.mStatics, GetKey {});
|
||||
result.mStatics = prepareRecords(content.mStatics, GetKey{});
|
||||
|
||||
addRefIdsTypes(result);
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ namespace EsmLoader
|
|||
};
|
||||
|
||||
EsmData loadEsmData(const Query& query, const std::vector<std::string>& contentFiles,
|
||||
const Files::Collections& fileCollections, ESM::ReadersCache& readers,
|
||||
ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener = nullptr);
|
||||
const Files::Collections& fileCollections, ESM::ReadersCache& readers, ToUTF8::Utf8Encoder* encoder,
|
||||
Loading::Listener* listener = nullptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,11 +16,12 @@ namespace EsmLoader
|
|||
bool mDeleted;
|
||||
T mValue;
|
||||
|
||||
template <class ... Args>
|
||||
explicit Record(bool deleted, Args&& ... args)
|
||||
template <class... Args>
|
||||
explicit Record(bool deleted, Args&&... args)
|
||||
: mDeleted(deleted)
|
||||
, mValue(std::forward<Args>(args) ...)
|
||||
{}
|
||||
, mValue(std::forward<Args>(args)...)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
|
@ -29,12 +30,11 @@ namespace EsmLoader
|
|||
template <class T, class GetKey>
|
||||
inline std::vector<T> prepareRecords(Records<T>& records, const GetKey& getKey)
|
||||
{
|
||||
const auto greaterByKey = [&] (const auto& l, const auto& r) { return getKey(r) < getKey(l); };
|
||||
const auto equalByKey = [&] (const auto& l, const auto& r) { return getKey(l) == getKey(r); };
|
||||
const auto greaterByKey = [&](const auto& l, const auto& r) { return getKey(r) < getKey(l); };
|
||||
const auto equalByKey = [&](const auto& l, const auto& r) { return getKey(l) == getKey(r); };
|
||||
std::stable_sort(records.begin(), records.end(), greaterByKey);
|
||||
std::vector<T> result;
|
||||
Misc::forEachUnique(records.rbegin(), records.rend(), equalByKey, [&] (const auto& v)
|
||||
{
|
||||
Misc::forEachUnique(records.rbegin(), records.rend(), equalByKey, [&](const auto& v) {
|
||||
if (!v.mDeleted)
|
||||
result.emplace_back(std::move(v.mValue));
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue