mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-02 14:57:59 +03:00
Fix loading order in EsmLoader
Need to load the last present record from a sequence of loaded records. That means reverse should be called before unique or unique should be applied for a reversed range. Since unique keeps only the first element from a sub sequence of equal elements. Use forEachUnique with reversed range to avoid redundant container modifications.
This commit is contained in:
parent
d3d9abede4
commit
194c11f214
3 changed files with 110 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
|||
#define OPENMW_COMPONENTS_ESMLOADER_RECORD_H
|
||||
|
||||
#include <components/esm3/loadcell.hpp>
|
||||
#include <components/misc/algorithm.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
@ -31,12 +32,12 @@ namespace EsmLoader
|
|||
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);
|
||||
records.erase(std::unique(records.begin(), records.end(), equalByKey), records.end());
|
||||
std::reverse(records.begin(), records.end());
|
||||
std::vector<T> result;
|
||||
for (Record<T>& v : records)
|
||||
Misc::forEachUnique(records.rbegin(), records.rend(), equalByKey, [&] (const auto& v)
|
||||
{
|
||||
if (!v.mDeleted)
|
||||
result.emplace_back(std::move(v.mValue));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue