[keel] Add valid and repair functions for AssetManager

This commit is contained in:
Gary Talent 2024-06-01 13:54:45 -05:00
parent fd4619bc25
commit a2cec10cb6

View File

@ -21,6 +21,17 @@ class AssetManager;
template<typename T> template<typename T>
class AssetRef; class AssetRef;
[[nodiscard]]
constexpr bool valid(auto const&) noexcept {
return true;
}
[[nodiscard]]
constexpr bool repair(auto const&) noexcept {
return false;
}
#ifndef OX_BARE_METAL #ifndef OX_BARE_METAL
template<typename T> template<typename T>
class AssetContainer { class AssetContainer {
@ -215,6 +226,9 @@ class AssetManager {
ox::Result<AssetRef<T>> loadAsset(ox::StringView const assetId) noexcept { ox::Result<AssetRef<T>> loadAsset(ox::StringView const assetId) noexcept {
auto &p = m_cache[assetId]; auto &p = m_cache[assetId];
oxRequireM(obj, m_loader(assetId)); oxRequireM(obj, m_loader(assetId));
if (!valid(obj) && !repair(obj)) {
return OxError(1, "asset is invalid state and could not be repaired");
}
if (!p) { if (!p) {
p = ox::make_unique<AssetContainer<T>>(std::move(obj)); p = ox::make_unique<AssetContainer<T>>(std::move(obj));
} else { } else {