Files
ox/src/nostalgia/core/media.hpp
T
2022-01-13 02:04:29 -06:00

44 lines
1.1 KiB
C++

/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/claw/claw.hpp>
#include <ox/fs/fs.hpp>
#include "context.hpp"
namespace nostalgia::core {
template<typename T>
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;
ox::Result<char*> loadRom(const char *path = "") noexcept;
void unloadRom(char*) noexcept;
}