forked from metin-server/m2dev-client-src
Add parallel race/motion loading and thread-safe Pack/Pool managers
This commit is contained in:
@@ -13,7 +13,7 @@ static ZSTD_DCtx* GetThreadLocalZSTDContext()
|
||||
return g_zstdDCtx;
|
||||
}
|
||||
|
||||
bool CPack::Open(const std::string& path, TPackFileMap& entries)
|
||||
bool CPack::Load(const std::string& path)
|
||||
{
|
||||
std::error_code ec;
|
||||
m_file.map(path, ec);
|
||||
@@ -34,13 +34,13 @@ bool CPack::Open(const std::string& path, TPackFileMap& entries)
|
||||
return false;
|
||||
}
|
||||
|
||||
m_index.resize(m_header.entry_num);
|
||||
|
||||
for (size_t i = 0; i < m_header.entry_num; i++) {
|
||||
TPackFileEntry entry;
|
||||
TPackFileEntry& entry = m_index[i];
|
||||
memcpy(&entry, m_file.data() + sizeof(TPackFileHeader) + i * sizeof(TPackFileEntry), sizeof(TPackFileEntry));
|
||||
m_decryption.ProcessData((CryptoPP::byte*)&entry, (CryptoPP::byte*)&entry, sizeof(TPackFileEntry));
|
||||
|
||||
entries[entry.file_name] = std::make_pair(shared_from_this(), entry);
|
||||
|
||||
if (file_size < m_header.data_begin + entry.offset + entry.compressed_size) {
|
||||
return false;
|
||||
}
|
||||
@@ -97,4 +97,4 @@ bool CPack::GetFileWithPool(const TPackFileEntry& entry, TPackFile& result, CBuf
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,16 @@ public:
|
||||
CPack() = default;
|
||||
~CPack() = default;
|
||||
|
||||
bool Open(const std::string& path, TPackFileMap& entries);
|
||||
bool Load(const std::string& path);
|
||||
const std::vector<TPackFileEntry>& GetIndex() const { return m_index; }
|
||||
|
||||
bool GetFile(const TPackFileEntry& entry, TPackFile& result);
|
||||
bool GetFileWithPool(const TPackFileEntry& entry, TPackFile& result, CBufferPool* pPool);
|
||||
|
||||
private:
|
||||
TPackFileHeader m_header;
|
||||
std::vector<TPackFileEntry> m_index;
|
||||
mio::mmap_source m_file;
|
||||
|
||||
CryptoPP::CTR_Mode<CryptoPP::Camellia>::Decryption m_decryption;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -23,8 +23,19 @@ bool CPackManager::AddPack(const std::string& path)
|
||||
{
|
||||
std::shared_ptr<CPack> pack = std::make_shared<CPack>();
|
||||
|
||||
if (!pack->Load(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return pack->Open(path, m_entries);
|
||||
const auto& index = pack->GetIndex();
|
||||
for (const auto& entry : index)
|
||||
{
|
||||
m_entries[entry.file_name] = std::make_pair(pack, entry);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPackManager::GetFile(std::string_view path, TPackFile& result)
|
||||
|
||||
Reference in New Issue
Block a user