Skip to content

Commit af54318

Browse files
glebmAJenbo
authored andcommitted
MpqArchives: Order by decreasing priority
1 parent e466170 commit af54318

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

Source/engine/assets.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <algorithm>
44
#include <cstdint>
55
#include <cstring>
6+
#include <functional>
67
#include <vector>
78

89
#include "appfat.h"
@@ -24,18 +25,16 @@
2425
namespace devilution {
2526

2627
std::vector<std::string> OverridePaths;
27-
std::map<int, MpqArchiveT> MpqArchives;
28+
std::map<int, MpqArchiveT, std::greater<>> MpqArchives;
2829
bool HasHellfireMpq;
2930

3031
namespace {
3132

3233
#ifdef UNPACKED_MPQS
3334
char *FindUnpackedMpqFile(char *relativePath)
3435
{
35-
// Iterate over archives in reverse order to prefer files from high priority archives
3636
char *path = nullptr;
37-
for (auto rit = MpqArchives.rbegin(); rit != MpqArchives.rend(); ++rit) {
38-
const std::string_view unpackedDir = rit->second;
37+
for (const auto &[_, unpackedDir] : MpqArchives) {
3938
path = relativePath - unpackedDir.size();
4039
std::memcpy(path, unpackedDir.data(), unpackedDir.size());
4140
if (FileExists(path)) break;
@@ -62,10 +61,9 @@ bool FindMpqFile(std::string_view filename, MpqArchive **archive, uint32_t *file
6261
{
6362
const MpqFileHash fileHash = CalculateMpqFileHash(filename);
6463

65-
// Iterate over archives in reverse order to prefer files from high priority archives
66-
for (auto rit = MpqArchives.rbegin(); rit != MpqArchives.rend(); ++rit) {
67-
if (rit->second.GetFileNumber(fileHash, *fileNumber)) {
68-
*archive = &rit->second;
64+
for (auto &[_, mpqArchive] : MpqArchives) {
65+
if (mpqArchive.GetFileNumber(fileHash, *fileNumber)) {
66+
*archive = &mpqArchive;
6967
return true;
7068
}
7169
}

Source/engine/assets.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <cstddef>
44
#include <cstdint>
55
#include <cstdio>
6+
#include <functional>
67
#include <map>
7-
#include <optional>
88
#include <span>
99
#include <string>
1010
#include <string_view>
@@ -285,7 +285,7 @@ using MpqArchiveT = std::string;
285285
using MpqArchiveT = MpqArchive;
286286
#endif
287287

288-
extern DVL_API_FOR_TEST std::map<int, MpqArchiveT> MpqArchives;
288+
extern DVL_API_FOR_TEST std::map<int, MpqArchiveT, std::greater<>> MpqArchives;
289289
constexpr int MainMpqPriority = 1000;
290290
constexpr int DevilutionXMpqPriority = 9000;
291291
constexpr int LangMpqPriority = 9100;

0 commit comments

Comments
 (0)