libeuropa/io: Remove usage of *_map from PakReader
I'm not sure how I want to handle this yet, but for now, using a vector<pair<...>> is the easiest way currently to retain insertion order. Using a hash table IS probably a better idea, and I'm looking to maybe importing Boost multimaps to allow that, but for now, /shrug.
This commit is contained in:
parent
d9e30b8466
commit
6cd6d45a71
2 changed files with 15 additions and 6 deletions
|
@ -13,13 +13,14 @@
|
|||
#include <europa/structs/Pak.hpp>
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
namespace europa::io {
|
||||
|
||||
/// Reader for Europa package files (.pak).
|
||||
struct PakReader {
|
||||
using MapType = std::unordered_map<std::string, PakFile>;
|
||||
using FlatType = std::pair<std::string, PakFile>;
|
||||
using MapType = std::vector<FlatType>;
|
||||
|
||||
/// Constructor. Takes in a input stream to read pak data from.
|
||||
/// This stream should only be used by the PakReader, nothing else.
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <europa/io/PakReader.hpp>
|
||||
|
@ -38,18 +39,21 @@ namespace europa::io {
|
|||
//
|
||||
// Read this in first.
|
||||
auto filename = impl::ReadPString(stream);
|
||||
auto file = PakFile {};
|
||||
if constexpr(std::is_same_v<T, structs::PakHeader_V5>) {
|
||||
// Version 5 supports sector aligned packages which have an additional field in them
|
||||
// so we need to handle it here
|
||||
// (not feeling quite as hot about all the crazy template magic here anymore)
|
||||
if(header_type.sectorAlignedFlag) {
|
||||
files[filename].InitWithExistingTocEntry(impl::ReadStreamType<typename T::TocEntry_SectorAligned>(stream));
|
||||
file.InitWithExistingTocEntry(impl::ReadStreamType<typename T::TocEntry_SectorAligned>(stream));
|
||||
} else {
|
||||
files[filename].InitWithExistingTocEntry(impl::ReadStreamType<typename T::TocEntry>(stream));
|
||||
file.InitWithExistingTocEntry(impl::ReadStreamType<typename T::TocEntry>(stream));
|
||||
}
|
||||
} else {
|
||||
files[filename].InitWithExistingTocEntry(impl::ReadStreamType<typename T::TocEntry>(stream));
|
||||
file.InitWithExistingTocEntry(impl::ReadStreamType<typename T::TocEntry>(stream));
|
||||
}
|
||||
|
||||
files.emplace_back(filename, std::move(file));
|
||||
}
|
||||
|
||||
header = header_type;
|
||||
|
@ -80,7 +84,11 @@ namespace europa::io {
|
|||
}
|
||||
|
||||
void PakReader::ReadFile(const std::string& file) {
|
||||
auto& fileObject = files[file];
|
||||
auto it = std::find_if(files.begin(), files.end(), [&file](PakReader::FlatType& fl) { return fl.first == file; });
|
||||
if(it == files.end())
|
||||
return;
|
||||
|
||||
auto& fileObject = it->second;
|
||||
std::vector<std::uint8_t> buffer;
|
||||
|
||||
buffer.resize(fileObject.GetSize());
|
||||
|
|
Loading…
Reference in a new issue