[keel] Add valid and repair functions for AssetManager
This commit is contained in:
parent
fd4619bc25
commit
a2cec10cb6
@ -21,6 +21,17 @@ class AssetManager;
|
||||
template<typename T>
|
||||
class AssetRef;
|
||||
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool valid(auto const&) noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool repair(auto const&) noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef OX_BARE_METAL
|
||||
template<typename T>
|
||||
class AssetContainer {
|
||||
@ -215,6 +226,9 @@ class AssetManager {
|
||||
ox::Result<AssetRef<T>> loadAsset(ox::StringView const assetId) noexcept {
|
||||
auto &p = m_cache[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) {
|
||||
p = ox::make_unique<AssetContainer<T>>(std::move(obj));
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user