Replace MPQ runtime with loose file asset system

Extract assets from MPQ archives into organized loose files indexed by
manifest.json, enabling fully parallel reads without StormLib serialization.
Add asset_extract and blp_convert tools, PNG texture override support.
This commit is contained in:
Kelsi 2026-02-12 20:32:14 -08:00
parent 5fda1a3157
commit aa16a687c2
16 changed files with 1427 additions and 101 deletions

View file

@ -1,8 +1,9 @@
#pragma once
#include "pipeline/mpq_manager.hpp"
#include "pipeline/blp_loader.hpp"
#include "pipeline/dbc_loader.hpp"
#include "pipeline/asset_manifest.hpp"
#include "pipeline/loose_file_reader.hpp"
#include <memory>
#include <string>
#include <map>
@ -14,7 +15,9 @@ namespace pipeline {
/**
* AssetManager - Unified interface for loading WoW assets
*
* Coordinates MPQ archives, texture loading, and database files
* Reads pre-extracted loose files indexed by manifest.json.
* Use the asset_extract tool to extract MPQ archives first.
* All reads are fully parallel (no serialization mutex needed).
*/
class AssetManager {
public:
@ -23,7 +26,7 @@ public:
/**
* Initialize asset manager
* @param dataPath Path to WoW Data directory
* @param dataPath Path to directory containing manifest.json and extracted assets
* @return true if initialization succeeded
*/
bool initialize(const std::string& dataPath);
@ -60,33 +63,27 @@ public:
std::shared_ptr<DBCFile> getDBC(const std::string& name) const;
/**
* Check if a file exists in MPQ archives
* Check if a file exists
* @param path Virtual file path
* @return true if file exists
*/
bool fileExists(const std::string& path) const;
/**
* Read raw file data from MPQ archives
* Read raw file data
* @param path Virtual file path
* @return File contents (empty if not found)
*/
std::vector<uint8_t> readFile(const std::string& path) const;
/**
* Read optional file data from MPQ archives without warning spam.
* Read optional file data without warning spam.
* Intended for probe-style lookups (e.g. external .anim variants).
* @param path Virtual file path
* @return File contents (empty if not found)
*/
std::vector<uint8_t> readFileOptional(const std::string& path) const;
/**
* Get MPQ manager for direct access
*/
MPQManager& getMPQManager() { return mpqManager; }
const MPQManager& getMPQManager() const { return mpqManager; }
/**
* Get loaded DBC count
*/
@ -108,12 +105,14 @@ private:
bool initialized = false;
std::string dataPath;
MPQManager mpqManager;
mutable std::mutex readMutex;
// Loose file backend
AssetManifest manifest_;
LooseFileReader looseReader_;
mutable std::mutex cacheMutex;
std::map<std::string, std::shared_ptr<DBCFile>> dbcCache;
// Decompressed file cache (LRU, dynamic budget based on system RAM)
// File cache (LRU, dynamic budget based on system RAM)
struct CachedFile {
std::vector<uint8_t> data;
uint64_t lastAccessTime;
@ -125,6 +124,14 @@ private:
mutable size_t fileCacheMisses = 0;
mutable size_t fileCacheBudget = 1024 * 1024 * 1024; // Dynamic, starts at 1GB
void setupFileCacheBudget();
/**
* Try to load a PNG override for a BLP path.
* Returns valid BLPImage if PNG found, invalid otherwise.
*/
BLPImage tryLoadPngOverride(const std::string& normalizedPath) const;
/**
* Normalize path for case-insensitive lookup
*/

View file

@ -0,0 +1,74 @@
#pragma once
#include <string>
#include <vector>
#include <cstdint>
#include <unordered_map>
namespace wowee {
namespace pipeline {
/**
* AssetManifest - Maps WoW virtual paths to filesystem paths
*
* Loaded once at startup from manifest.json. Read-only after init,
* so concurrent reads are safe without a mutex.
*/
class AssetManifest {
public:
struct Entry {
std::string filesystemPath; // Relative path from basePath (forward slashes)
uint64_t size; // File size in bytes
uint32_t crc32; // CRC32 for integrity verification
};
AssetManifest() = default;
/**
* Load manifest from JSON file
* @param manifestPath Full path to manifest.json
* @return true if loaded successfully
*/
bool load(const std::string& manifestPath);
/**
* Lookup an entry by normalized WoW path (lowercase, backslash)
* @return Pointer to entry or nullptr if not found
*/
const Entry* lookup(const std::string& normalizedWowPath) const;
/**
* Resolve full filesystem path for a WoW virtual path
* @return Full filesystem path or empty string if not found
*/
std::string resolveFilesystemPath(const std::string& normalizedWowPath) const;
/**
* Check if an entry exists
*/
bool hasEntry(const std::string& normalizedWowPath) const;
/**
* Get base path (directory containing extracted assets)
*/
const std::string& getBasePath() const { return basePath_; }
/**
* Get total number of entries
*/
size_t getEntryCount() const { return entries_.size(); }
/**
* Check if manifest is loaded
*/
bool isLoaded() const { return loaded_; }
private:
bool loaded_ = false;
std::string basePath_; // Root directory for extracted assets
std::string manifestDir_; // Directory containing manifest.json
std::unordered_map<std::string, Entry> entries_;
};
} // namespace pipeline
} // namespace wowee

View file

@ -0,0 +1,40 @@
#pragma once
#include <string>
#include <vector>
#include <cstdint>
namespace wowee {
namespace pipeline {
/**
* LooseFileReader - Thread-safe filesystem file reader
*
* Each read opens its own file descriptor, so no mutex is needed.
* This replaces the serialized MPQ read path.
*/
class LooseFileReader {
public:
LooseFileReader() = default;
/**
* Read entire file into memory
* @param filesystemPath Full path to file on disk
* @return File contents (empty if not found or error)
*/
static std::vector<uint8_t> readFile(const std::string& filesystemPath);
/**
* Check if a file exists on disk
*/
static bool fileExists(const std::string& filesystemPath);
/**
* Get file size without reading
* @return Size in bytes, or 0 if not found
*/
static uint64_t getFileSize(const std::string& filesystemPath);
};
} // namespace pipeline
} // namespace wowee