[nostalgia] Replace C strings with StringViews
This commit is contained in:
@@ -26,9 +26,10 @@ oxModelBegin(PreloadPtr)
|
||||
oxModelEnd()
|
||||
|
||||
ox::Result<std::size_t> getPreloadAddr(Context *ctx, const ox::FileAddress &file) noexcept;
|
||||
ox::Result<std::size_t> getPreloadAddr(Context *ctx, ox::CRStringView file) noexcept;
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> readObj(Context *ctx, const ox::FileAddress &file,
|
||||
ox::Result<AssetRef<T>> readObj([[maybe_unused]] Context *ctx, [[maybe_unused]] ox::CRStringView path,
|
||||
[[maybe_unused]] bool forceLoad = false) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
constexpr auto readConvert = [](const ox::Buffer &buff) -> ox::Result<T> {
|
||||
@@ -41,21 +42,36 @@ ox::Result<AssetRef<T>> readObj(Context *ctx, const ox::FileAddress &file,
|
||||
}
|
||||
return std::move(obj);
|
||||
};
|
||||
oxRequire(path, file.getPath());
|
||||
if (forceLoad) {
|
||||
oxRequire(buff, ctx->rom->read(file));
|
||||
oxRequire(buff, ctx->rom->read(path));
|
||||
oxRequire(obj, readConvert(buff));
|
||||
oxRequire(cached, ctx->assetManager.setAsset(path, obj));
|
||||
return std::move(cached);
|
||||
} else {
|
||||
auto [cached, err] = ctx->assetManager.getAsset<T>(path);
|
||||
if (err) {
|
||||
oxRequire(buff, ctx->rom->read(file));
|
||||
oxRequire(buff, ctx->rom->read(path));
|
||||
oxRequire(obj, readConvert(buff));
|
||||
oxReturnError(ctx->assetManager.setAsset(path, obj).moveTo(&cached));
|
||||
}
|
||||
return std::move(cached);
|
||||
}
|
||||
#else
|
||||
if constexpr(ox::preloadable<T>::value) {
|
||||
oxRequire(addr, getPreloadAddr(ctx, path));
|
||||
return AssetRef<T>(reinterpret_cast<const T*>(addr));
|
||||
} else {
|
||||
return OxError(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> readObj(Context *ctx, const ox::FileAddress &file,
|
||||
[[maybe_unused]] bool forceLoad = false) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequire(path, file.getPath());
|
||||
return readObj<T>(ctx, ox::StringView(path), forceLoad);
|
||||
#else
|
||||
if constexpr(ox::preloadable<T>::value) {
|
||||
oxRequire(addr, getPreloadAddr(ctx, file));
|
||||
|
||||
Reference in New Issue
Block a user