2026-02-02 12:24:50 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "pipeline/blp_loader.hpp"
|
|
|
|
|
#include "pipeline/dbc_loader.hpp"
|
2026-02-12 20:32:14 -08:00
|
|
|
#include "pipeline/asset_manifest.hpp"
|
|
|
|
|
#include "pipeline/loose_file_reader.hpp"
|
2026-04-06 21:19:37 +03:00
|
|
|
#include <atomic>
|
2026-02-02 12:24:50 -08:00
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
2026-02-12 22:56:36 -08:00
|
|
|
#include <vector>
|
2026-02-02 12:24:50 -08:00
|
|
|
#include <map>
|
2026-03-27 16:33:16 -07:00
|
|
|
#include <unordered_map>
|
2026-02-02 12:24:50 -08:00
|
|
|
#include <mutex>
|
2026-03-27 16:33:16 -07:00
|
|
|
#include <shared_mutex>
|
2026-02-02 12:24:50 -08:00
|
|
|
|
|
|
|
|
namespace wowee {
|
|
|
|
|
namespace pipeline {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* AssetManager - Unified interface for loading WoW assets
|
|
|
|
|
*
|
2026-02-12 20:32:14 -08:00
|
|
|
* Reads pre-extracted loose files indexed by manifest.json.
|
2026-02-15 04:18:34 -08:00
|
|
|
* Supports an override directory (Data/override/) checked before the manifest
|
|
|
|
|
* for HD textures, custom content, or mod overrides.
|
2026-02-12 20:32:14 -08:00
|
|
|
* Use the asset_extract tool to extract MPQ archives first.
|
|
|
|
|
* All reads are fully parallel (no serialization mutex needed).
|
2026-02-02 12:24:50 -08:00
|
|
|
*/
|
|
|
|
|
class AssetManager {
|
|
|
|
|
public:
|
|
|
|
|
AssetManager();
|
|
|
|
|
~AssetManager();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initialize asset manager
|
2026-02-12 20:32:14 -08:00
|
|
|
* @param dataPath Path to directory containing manifest.json and extracted assets
|
2026-02-02 12:24:50 -08:00
|
|
|
* @return true if initialization succeeded
|
|
|
|
|
*/
|
|
|
|
|
bool initialize(const std::string& dataPath);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shutdown and cleanup
|
|
|
|
|
*/
|
|
|
|
|
void shutdown();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if asset manager is initialized
|
|
|
|
|
*/
|
|
|
|
|
bool isInitialized() const { return initialized; }
|
2026-02-20 01:49:43 -08:00
|
|
|
const std::string& getDataPath() const { return dataPath; }
|
feat(editor): add standalone world editor (rough/WIP)
Standalone wowee_editor tool for creating custom WoW zones.
This is a rough initial implementation — many features work but
M2/WMO rendering still has issues (frame sync, texture layout
transitions) and needs further polish.
Terrain:
- Create new blank terrain with 10 biome types (Grassland, Forest,
Jungle, Desert, Barrens, Snow, Swamp, Rocky, Beach, Volcanic)
- Load existing ADT tiles from extracted game data
- Sculpt brushes: Raise, Lower, Smooth, Flatten, Level
- Chunk edge stitching prevents seams between tiles
- Undo/redo (100-deep stack, Ctrl+Z/Ctrl+Shift+Z)
- Save to WoW ADT/WDT format
Texture Painting:
- Paint/Erase/Replace Base modes
- Full tileset texture browser (1285 textures from manifest)
- Per-zone directory filtering and search
- Alpha map editing with 4-layer limit (auto-replaces weakest)
Object Placement:
- M2 and WMO model placement with full manifest browser (11k M2s, 2k WMOs)
- M2Renderer + WMORenderer integrated (loads .skin files for WotLK)
- Ghost preview follows cursor before placing
- Ctrl+click selection, right-click context menu
- Transform gizmo (Move/Rotate/Scale with axis constraints)
- Position/rotation/scale editing in properties panel
NPC/Monster System:
- 631 creature presets scanned from manifest, categorized
(Critters, Beasts, Humanoids, Undead, Demons, etc.)
- Stats editor: level, health, mana, damage, armor, faction
- Behavior: Stationary, Patrol, Wander, Scripted
- Aggro/leash radius, respawn time, flags (hostile/vendor/etc.)
- Save creature spawns to JSON
Water:
- Place water at configurable height per chunk
- Liquid types: Water, Ocean, Magma, Slime
- Rendered as translucent colored quads
- Saved in ADT MH2O format
Infrastructure:
- Free-fly camera (WASD/QE, right-drag look, scroll speed)
- 5-mode toolbar: Sculpt | Paint | Objects | Water | NPCs
- Asset browser indexes full manifest on startup
- Editor water/marker shaders (pos+color vertex format)
- forceNoCull added to M2Renderer for editor use
- AssetManifest::getEntries() and AssetManager::getManifest() exposed
Known issues:
- M2/WMO rendering may not display on first placement (frame index
sync between update/render was misaligned — now fixed but untested
end-to-end)
- Validation layer errors on shutdown (resource cleanup ordering)
- Object placement on steep terrain can miss raycast
- No undo for texture painting or object placement yet
2026-05-05 03:47:03 -07:00
|
|
|
const AssetManifest& getManifest() const { return manifest_; }
|
2026-02-02 12:24:50 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a BLP texture
|
|
|
|
|
* @param path Virtual path to BLP file (e.g., "Textures\\Minimap\\Background.blp")
|
|
|
|
|
* @return BLP image (check isValid())
|
|
|
|
|
*/
|
|
|
|
|
BLPImage loadTexture(const std::string& path);
|
|
|
|
|
|
2026-02-13 00:10:01 -08:00
|
|
|
/**
|
|
|
|
|
* Set expansion-specific data path for CSV DBC lookup.
|
|
|
|
|
* When set, loadDBC() checks expansionDataPath/db/Name.csv before
|
|
|
|
|
* falling back to the manifest (binary DBC from extracted MPQs).
|
|
|
|
|
*/
|
|
|
|
|
void setExpansionDataPath(const std::string& path);
|
|
|
|
|
|
2026-03-10 07:25:04 -07:00
|
|
|
/**
|
|
|
|
|
* Set a base data path to fall back to when the primary manifest
|
|
|
|
|
* does not contain a requested file. Call this when the primary
|
|
|
|
|
* dataPath is an expansion-specific subset (e.g. Data/expansions/vanilla/)
|
|
|
|
|
* that only holds DBC overrides, not the full world asset set.
|
|
|
|
|
* @param basePath Path to the base extraction (Data/) that has a manifest.json
|
|
|
|
|
*/
|
|
|
|
|
void setBaseFallbackPath(const std::string& basePath);
|
|
|
|
|
|
2026-02-02 12:24:50 -08:00
|
|
|
/**
|
|
|
|
|
* Load a DBC file
|
|
|
|
|
* @param name DBC file name (e.g., "Map.dbc")
|
|
|
|
|
* @return Loaded DBC file (check isLoaded())
|
|
|
|
|
*/
|
|
|
|
|
std::shared_ptr<DBCFile> loadDBC(const std::string& name);
|
|
|
|
|
|
2026-03-10 07:00:43 -07:00
|
|
|
/**
|
|
|
|
|
* Load a DBC file that is optional (not all expansions ship it).
|
|
|
|
|
* Returns nullptr quietly (debug-level log only) when the file is absent.
|
|
|
|
|
* @param name DBC file name (e.g., "Item.dbc")
|
|
|
|
|
* @return Loaded DBC file, or nullptr if not available
|
|
|
|
|
*/
|
|
|
|
|
std::shared_ptr<DBCFile> loadDBCOptional(const std::string& name);
|
|
|
|
|
|
2026-02-02 12:24:50 -08:00
|
|
|
/**
|
|
|
|
|
* Get a cached DBC file
|
|
|
|
|
* @param name DBC file name
|
|
|
|
|
* @return Cached DBC or nullptr if not loaded
|
|
|
|
|
*/
|
|
|
|
|
std::shared_ptr<DBCFile> getDBC(const std::string& name) const;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-02-12 20:32:14 -08:00
|
|
|
* Check if a file exists
|
2026-02-02 12:24:50 -08:00
|
|
|
* @param path Virtual file path
|
|
|
|
|
* @return true if file exists
|
|
|
|
|
*/
|
|
|
|
|
bool fileExists(const std::string& path) const;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-02-12 20:32:14 -08:00
|
|
|
* Read raw file data
|
2026-02-02 12:24:50 -08:00
|
|
|
* @param path Virtual file path
|
|
|
|
|
* @return File contents (empty if not found)
|
|
|
|
|
*/
|
|
|
|
|
std::vector<uint8_t> readFile(const std::string& path) const;
|
|
|
|
|
|
2026-02-12 02:27:59 -08:00
|
|
|
/**
|
2026-02-12 20:32:14 -08:00
|
|
|
* Read optional file data without warning spam.
|
2026-02-12 02:27:59 -08:00
|
|
|
* 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;
|
|
|
|
|
|
2026-02-02 12:24:50 -08:00
|
|
|
/**
|
|
|
|
|
* Get loaded DBC count
|
|
|
|
|
*/
|
|
|
|
|
size_t getLoadedDBCCount() const { return dbcCache.size(); }
|
|
|
|
|
|
2026-02-08 22:37:29 -08:00
|
|
|
/**
|
|
|
|
|
* Get file cache stats
|
|
|
|
|
*/
|
|
|
|
|
size_t getFileCacheSize() const { return fileCacheTotalBytes; }
|
|
|
|
|
size_t getFileCacheHits() const { return fileCacheHits; }
|
|
|
|
|
size_t getFileCacheMisses() const { return fileCacheMisses; }
|
|
|
|
|
|
2026-02-02 12:24:50 -08:00
|
|
|
/**
|
|
|
|
|
* Clear all cached resources
|
|
|
|
|
*/
|
|
|
|
|
void clearCache();
|
|
|
|
|
|
2026-02-13 16:53:28 -08:00
|
|
|
/**
|
|
|
|
|
* Clear only DBC cache (forces reload on next loadDBC call)
|
|
|
|
|
*/
|
|
|
|
|
void clearDBCCache();
|
|
|
|
|
|
2026-02-28 09:07:47 -08:00
|
|
|
/**
|
|
|
|
|
* Delete all extracted asset files from the data directory on disk.
|
|
|
|
|
* Removes extracted subdirectories (db, character, creature, terrain, etc.),
|
|
|
|
|
* manifest.json, override dir, and expansion-specific extracted assets.
|
|
|
|
|
* After calling this, initialize() will fail until assets are re-extracted.
|
|
|
|
|
* @return Number of entries removed
|
|
|
|
|
*/
|
|
|
|
|
size_t purgeExtractedAssets();
|
|
|
|
|
|
2026-05-06 10:48:40 -07:00
|
|
|
/**
|
|
|
|
|
* Resolve a normalized WoW path to its on-disk location. Checks the
|
|
|
|
|
* override directory first, then the manifest, then the base-fallback
|
|
|
|
|
* manifest. Public so callers (e.g. terrain_manager probing for
|
|
|
|
|
* sidecar files like .whm/.wot/.woc next to a .adt) can locate the
|
|
|
|
|
* extracted file's directory without reading it.
|
|
|
|
|
* @return absolute or relative fs path, or "" if not found
|
|
|
|
|
*/
|
|
|
|
|
std::string resolveFile(const std::string& normalizedPath) const;
|
|
|
|
|
|
2026-02-02 12:24:50 -08:00
|
|
|
private:
|
|
|
|
|
bool initialized = false;
|
|
|
|
|
std::string dataPath;
|
2026-02-13 00:10:01 -08:00
|
|
|
std::string expansionDataPath_; // e.g. "Data/expansions/wotlk"
|
2026-02-15 04:18:34 -08:00
|
|
|
std::string overridePath_; // e.g. "Data/override"
|
2026-02-02 12:24:50 -08:00
|
|
|
|
2026-02-12 22:56:36 -08:00
|
|
|
// Base manifest (loaded from dataPath/manifest.json)
|
2026-02-12 20:32:14 -08:00
|
|
|
AssetManifest manifest_;
|
|
|
|
|
LooseFileReader looseReader_;
|
|
|
|
|
|
2026-03-10 07:25:04 -07:00
|
|
|
// Optional base-path fallback: used when manifest_ doesn't contain a file.
|
|
|
|
|
// Populated by setBaseFallbackPath(); ignored if baseFallbackDataPath_ is empty.
|
|
|
|
|
std::string baseFallbackDataPath_;
|
|
|
|
|
AssetManifest baseFallbackManifest_;
|
|
|
|
|
|
2026-05-06 10:48:40 -07:00
|
|
|
// (resolveFile moved to public — declaration above.)
|
2026-02-12 22:56:36 -08:00
|
|
|
|
2026-04-06 21:19:37 +03:00
|
|
|
// Guards fileCache, dbcCache, fileCacheTotalBytes, fileCacheAccessCounter, and
|
|
|
|
|
// fileCacheBudget. Shared lock for read-only cache lookups (readFile cache hit,
|
|
|
|
|
// loadDBC cache hit); exclusive lock for inserts and eviction.
|
2026-03-27 16:33:16 -07:00
|
|
|
mutable std::shared_mutex cacheMutex;
|
2026-04-06 21:19:37 +03:00
|
|
|
// THREAD-SAFE: protected by cacheMutex (exclusive lock for writes).
|
2026-03-27 16:33:16 -07:00
|
|
|
std::unordered_map<std::string, std::shared_ptr<DBCFile>> dbcCache;
|
2026-02-02 12:24:50 -08:00
|
|
|
|
2026-02-12 20:32:14 -08:00
|
|
|
// File cache (LRU, dynamic budget based on system RAM)
|
2026-02-08 22:37:29 -08:00
|
|
|
struct CachedFile {
|
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
|
uint64_t lastAccessTime;
|
|
|
|
|
};
|
2026-04-06 21:19:37 +03:00
|
|
|
// THREAD-SAFE: protected by cacheMutex (shared_mutex — shared_lock for reads,
|
|
|
|
|
// exclusive lock_guard for writes/eviction).
|
2026-03-27 16:33:16 -07:00
|
|
|
mutable std::unordered_map<std::string, CachedFile> fileCache;
|
2026-02-08 22:37:29 -08:00
|
|
|
mutable size_t fileCacheTotalBytes = 0;
|
|
|
|
|
mutable uint64_t fileCacheAccessCounter = 0;
|
2026-04-06 21:19:37 +03:00
|
|
|
// THREAD-SAFE: atomic — incremented from any thread after releasing cacheMutex.
|
|
|
|
|
mutable std::atomic<size_t> fileCacheHits{0};
|
|
|
|
|
mutable std::atomic<size_t> fileCacheMisses{0};
|
2026-02-08 23:15:26 -08:00
|
|
|
mutable size_t fileCacheBudget = 1024 * 1024 * 1024; // Dynamic, starts at 1GB
|
2026-02-08 22:37:29 -08:00
|
|
|
|
2026-02-12 20:32:14 -08:00
|
|
|
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;
|
|
|
|
|
|
2026-02-02 12:24:50 -08:00
|
|
|
/**
|
|
|
|
|
* Normalize path for case-insensitive lookup
|
|
|
|
|
*/
|
|
|
|
|
std::string normalizePath(const std::string& path) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace pipeline
|
|
|
|
|
} // namespace wowee
|