[nostalgia/core] Add AssetManager

This commit is contained in:
2021-10-30 17:03:24 -05:00
parent a3dd2b59cc
commit e29f65f351
5 changed files with 217 additions and 15 deletions
+20 -3
View File
@@ -16,9 +16,26 @@
namespace nostalgia::core {
template<typename T>
ox::Result<T> readObj(Context *ctx, const ox::FileAddress &file) noexcept {
oxRequire(buff, ctx->rom->read(file));
return ox::readClaw<T>(buff);
ox::Result<AssetRef<T>> readObj(Context *ctx, const ox::FileAddress &file, bool forceLoad = false) noexcept {
#ifndef OX_BARE_METAL
oxRequire(path, file.getPath());
if (forceLoad) {
oxRequire(buff, ctx->rom->read(file));
oxRequire(obj, ox::readClaw<T>(buff));
oxRequire(cached, ctx->assetManager.template setAsset(path, obj));
return cached;
} else {
auto [cached, err] = ctx->assetManager.template getAsset<T>(path);
if (err) {
oxRequire(buff, ctx->rom->read(file));
oxRequire(obj, ox::readClaw<T>(buff));
oxReturnError(ctx->assetManager.template setAsset(path, obj).moveTo(&cached));
}
return cached;
}
#else
return OxError(1);
#endif
}
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(const char *path) noexcept;