27#include <toast/events/listener.hpp>
28#include <unordered_map>
29#include <unordered_set>
41 std::filesystem::path artworks;
42 std::filesystem::path cache;
43 std::filesystem::path saved;
44 std::filesystem::path core;
70 ~AssetManager() =
default;
72 static auto get()
noexcept -> AssetManager&;
75 static auto isInitialized()
noexcept ->
bool {
76 return instance !=
nullptr;
93 auto load(std::string_view uri) ->
Asset*;
107 auto save(std::string_view uri) -> bool;
116 auto saveBytes(std::string_view uri,
const std::vector<uint8_t>& data) -> bool;
124 auto loadBytes(std::string_view uri) -> std::optional<std::vector<uint8_t>>;
129 auto tryLoadBytes(std::string_view uri) -> std::optional<std::vector<uint8_t>>;
154 static void registerDatabase(std::string_view name, std::filesystem::path root);
165 static auto projectRoot() ->
const std::filesystem::path&;
172 static auto resolveURI(std::string_view uri) -> std::optional<toast::UID>;
186 auto search(std::string_view query) -> std::vector<Handle<Asset>>;
188 auto listByType(std::string_view type) -> std::vector<toast::UID>;
199 bool replaced =
false;
200 std::shared_ptr<const Prefab> prefab;
209 auto hasPendingReloads() const ->
bool;
217 auto getCachePath() const -> const std::filesystem::path&;
236 static
void mountPack(std::string_view scheme, const std::filesystem::path& pak_path);
239 static inline AssetManager* instance =
nullptr;
243 static inline std::unordered_map<std::
string, std::unique_ptr<
PackArchive>> mounts;
245 event::Listener listener;
246 mutable std::mutex mutex;
247 std::unordered_map<uint64_t,
AssetInfo> manifest;
248 std::unordered_map<uint64_t, std::unique_ptr<
Asset>> cache;
249 std::unordered_map<uint64_t, std::filesystem::file_time_type> asset_mtimes;
250 std::unordered_set<uint64_t> pending_reloads;
251 std::vector<std::unique_ptr<
Asset>> retired_assets;
254 auto createAsset(const
AssetInfo& info, std::vector<uint8_t>& raw_data) -> std::unique_ptr<
Asset>;
256 static inline std::unordered_map<std::
string, std::filesystem::path> roots;
258 auto resolveVirtualPath(std::string_view virtual_path) -> std::optional<std::filesystem::path>;
259 auto readVirtualPath(std::string_view virtual_path) -> std::optional<std::vector<uint8_t>>;
260 auto openFile(const std::filesystem::path& path) -> std::optional<std::vector<uint8_t>>;
261 auto saveFile(const std::filesystem::path& path, const std::vector<uint8_t>& data) ->
bool;
Public API for the asset management system.
auto save(toast::UID uid) -> bool
Serializes the cached asset at the given UID back to its backing file.
Definition asset_manager.cpp:231
static void mountPack(std::string_view scheme, const std::filesystem::path &pak_path)
Mounts a .pak archive at a URI scheme.
Definition asset_manager.cpp:50
auto tryLoadBytes(std::string_view uri) -> std::optional< std::vector< uint8_t > >
Like loadBytes() but silent on misses.
Definition asset_manager.cpp:303
static auto typeOf(toast::UID uid) -> std::string
Looks up an asset's type string in the manifest without loading it.
Definition asset_manager.cpp:576
static auto getURI(toast::UID uid) -> std::string
Definition asset_manager.cpp:524
static auto projectRoot() -> const std::filesystem::path &
Returns the project root path (project:// root).
Definition asset_manager.cpp:423
void reloadManifest()
Re-reads the project manifest from disk.
Definition asset_manager.cpp:324
static void clearDatabases()
Removes all content database schemes (non-fixed), leaving only special roots intact.
Definition asset_manager.cpp:415
auto search(std::string_view query) -> std::vector< Handle< Asset > >
Searches the manifest for entries whose path contains the given query string.
Definition asset_manager.cpp:535
auto applyPendingReloads() -> std::vector< ReloadedAsset >
Reloads the assets pollModifiedAssets() changed.
Definition asset_manager.cpp:654
void clearUnusedAssets()
Evicts all assets whose ref count is zero from the cache.
Definition asset_manager.cpp:389
auto saveBytes(std::string_view uri, const std::vector< uint8_t > &data) -> bool
Writes raw bytes to the path resolved by a virtual URI, bypassing the manifest.
Definition asset_manager.cpp:282
void pollModifiedAssets()
Searches what assets have been modified.
Definition asset_manager.cpp:617
static void registerDatabase(std::string_view name, std::filesystem::path root)
Registers a content database scheme.
Definition asset_manager.cpp:411
static auto resolveURI(std::string_view uri) -> std::optional< toast::UID >
Maps a virtual URI to its manifest UID.
Definition asset_manager.cpp:515
static auto getLoadMode() -> SaveMode
Definition asset_manager.cpp:46
static void setLoadMode(SaveMode mode)
Selects the asset load mode.
Definition asset_manager.cpp:41
static void setPaths(Paths &&paths)
Configures the five fixed special URI roots; must be called before Engine::init().
Definition asset_manager.cpp:403
auto load(toast::UID uid) -> Asset *
Loads an asset by UID, returning the cached copy if already resident.
Definition asset_manager.cpp:170
auto loadBytes(std::string_view uri) -> std::optional< std::vector< uint8_t > >
Reads raw bytes from the URI, bypassing the manifest.
Definition asset_manager.cpp:292
Base class for all engine assets.
Definition core_types.hpp:45
SaveMode
Definition core_types.hpp:25
Definition App.axaml.cs:9
Read-side parser for the PACK v2 archive format produced by tools/asset_packer.
Definition asset_manager.hpp:34
Definition asset_manager.hpp:196
Definition asset_manager.hpp:39
std::filesystem::path project
project root folder; special databases are derived from here
Definition asset_manager.hpp:40
Concrete asset types for the Toast engine.