[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>
|
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user