[keel] Make AssetManager take StringViewCR for assetId
All checks were successful
Build / build (push) Successful in 3m16s
All checks were successful
Build / build (push) Successful in 3m16s
This commit is contained in:
parent
ede2c8ca37
commit
6837a0556d
@ -196,7 +196,7 @@ class AssetManager {
|
||||
template<typename T>
|
||||
class AssetTypeManager: public AssetTypeManagerBase {
|
||||
public:
|
||||
using Loader = std::function<ox::Result<T>(ox::StringView assetId)>;
|
||||
using Loader = std::function<ox::Result<T>(ox::StringViewCR assetId)>;
|
||||
private:
|
||||
Loader m_loader{};
|
||||
ox::HashMap<ox::String, ox::UPtr<AssetContainer<T>>> m_cache;
|
||||
@ -204,7 +204,7 @@ class AssetManager {
|
||||
public:
|
||||
AssetTypeManager(Loader &&loader) noexcept: m_loader(std::move(loader)) {}
|
||||
|
||||
ox::Result<AssetRef<T>> getAsset(ox::StringView const assetId) const noexcept {
|
||||
ox::Result<AssetRef<T>> getAsset(ox::StringViewCR assetId) const noexcept {
|
||||
OX_REQUIRE(out, m_cache.at(assetId));
|
||||
if (!out || !*out) {
|
||||
return ox::Error(1, "asset is null");
|
||||
@ -212,7 +212,7 @@ class AssetManager {
|
||||
return AssetRef<T>(out->get());
|
||||
}
|
||||
|
||||
ox::Result<AssetRef<T>> loadAsset(ox::StringView const assetId) noexcept {
|
||||
ox::Result<AssetRef<T>> loadAsset(ox::StringViewCR assetId) noexcept {
|
||||
auto &p = m_cache[assetId];
|
||||
OX_REQUIRE_M(obj, m_loader(assetId));
|
||||
if (!p) {
|
||||
@ -224,7 +224,7 @@ class AssetManager {
|
||||
return AssetRef<T>(p.get());
|
||||
}
|
||||
|
||||
ox::Error reloadAsset(ox::StringView const assetId) noexcept {
|
||||
ox::Error reloadAsset(ox::StringViewCR assetId) noexcept {
|
||||
auto &p = m_cache[assetId];
|
||||
OX_REQUIRE_M(obj, m_loader(assetId));
|
||||
if (!p) {
|
||||
@ -247,7 +247,7 @@ class AssetManager {
|
||||
};
|
||||
|
||||
ox::HashMap<ox::String, ox::UPtr<AssetTypeManagerBase>> m_assetTypeManagers;
|
||||
ox::HashMap<ox::String, ox::Signal<ox::Error(ox::StringView assetId)>> m_fileUpdated;
|
||||
ox::HashMap<ox::String, ox::Signal<ox::Error(ox::StringViewCR assetId)>> m_fileUpdated;
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetTypeManager<T>*> getTypeManager() noexcept {
|
||||
@ -273,18 +273,18 @@ class AssetManager {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> getAsset(ox::StringView assetId) noexcept {
|
||||
ox::Result<AssetRef<T>> getAsset(ox::StringViewCR assetId) noexcept {
|
||||
OX_REQUIRE(m, getTypeManager<T>());
|
||||
return m->getAsset(assetId);
|
||||
}
|
||||
|
||||
ox::Error reloadAsset(ox::StringView assetId) noexcept {
|
||||
ox::Error reloadAsset(ox::StringViewCR assetId) noexcept {
|
||||
m_fileUpdated[assetId].emit(assetId);
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> loadAsset(ox::StringView assetId) noexcept {
|
||||
ox::Result<AssetRef<T>> loadAsset(ox::StringViewCR assetId) noexcept {
|
||||
OX_REQUIRE(m, getTypeManager<T>());
|
||||
OX_REQUIRE(out, m->loadAsset(assetId));
|
||||
m_fileUpdated[assetId].connect(m, &AssetTypeManager<T>::reloadAsset);
|
||||
|
Loading…
Reference in New Issue
Block a user