[keel,nostalgia,studio,turbine] Fixes for ox::String explicit change

This commit is contained in:
2023-11-28 23:32:29 -06:00
parent 3a62650d62
commit da98aa864c
10 changed files with 28 additions and 44 deletions

View File

@@ -194,13 +194,13 @@ class AssetManager {
ox::HashMap<ox::String, ox::UniquePtr<AssetContainer<T>>> m_cache;
public:
ox::Result<AssetRef<T>> getAsset(const ox::String &assetId) const noexcept {
ox::Result<AssetRef<T>> getAsset(const ox::StringView &assetId) const noexcept {
auto out = m_cache.at(assetId);
oxReturnError(out);
return AssetRef<T>(out.value->get());
}
ox::Result<AssetRef<T>> setAsset(const ox::String &assetId, const T &obj) noexcept {
ox::Result<AssetRef<T>> setAsset(const ox::StringView &assetId, const T &obj) noexcept {
auto &p = m_cache[assetId];
if (!p) {
p = ox::make_unique<AssetContainer<T>>(obj);
@@ -211,7 +211,7 @@ class AssetManager {
return AssetRef<T>(p.get());
}
ox::Result<AssetRef<T>> setAsset(const ox::String &assetId, T &&obj) noexcept {
ox::Result<AssetRef<T>> setAsset(const ox::StringView &assetId, T &&obj) noexcept {
auto &p = m_cache[assetId];
if (!p) {
p = ox::make_unique<AssetContainer<T>>(obj);
@@ -247,13 +247,13 @@ class AssetManager {
public:
template<typename T>
ox::Result<AssetRef<T>> getAsset(const ox::String &assetId) noexcept {
ox::Result<AssetRef<T>> getAsset(ox::CRStringView assetId) noexcept {
auto m = getTypeManager<T>();
return m->getAsset(assetId);
}
template<typename T>
ox::Result<AssetRef<T>> setAsset(const ox::String &assetId, const T &obj) noexcept {
ox::Result<AssetRef<T>> setAsset(ox::CRStringView assetId, const T &obj) noexcept {
auto m = getTypeManager<T>();
return m->setAsset(assetId, obj);
}

View File

@@ -25,8 +25,11 @@ ox::Result<char*> loadRom(ox::CRStringView path) noexcept {
file.read(buff, size);
return buff;
} catch (const std::ios_base::failure &e) {
oxErrorf("Could not read ROM file: {}", e.what());
oxErrorf("Could not read ROM file due to file IO failure: {}", e.what());
return OxError(2, "Could not read ROM file");
} catch (const std::bad_alloc &e) {
oxErrorf("Could not read ROM file due to new failure: {}", e.what());
return OxError(2, "Could not allocate memory for ROM file");
}
}
@@ -142,7 +145,7 @@ ox::Error setRomFs(Context *ctx, ox::UPtr<ox::FileSystem> fs) noexcept {
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::CRStringView path) noexcept {
const auto lastDot = ox_lastIndexOf(path, '.');
const auto fsExt = lastDot != -1 ? path.substr(static_cast<std::size_t>(lastDot)) : "";
const auto fsExt = lastDot != -1 ? substr(path, static_cast<std::size_t>(lastDot)) : "";
if (ox_strcmp(fsExt, ".oxfs") == 0) {
oxRequire(rom, loadRom(path));
return {ox::make_unique<ox::FileSystem32>(rom, 32 * ox::units::MB, unloadRom)};

View File

@@ -52,28 +52,24 @@ ox::Result<keel::AssetRef<T>> readObjFile(
ox::StringView path;
ox::UUIDStr uuidStr;
if (beginsWith(assetId, "uuid://")) {
assetId = assetId.substr(7);
assetId = substr(assetId, 7);
path = ctx->uuidToPath[assetId];
} else {
path = assetId;
// Warning: StringView to String
uuidStr = ctx->pathToUuid[ox::String(path)].toString();
uuidStr = ctx->pathToUuid[path].toString();
assetId = uuidStr;
}
if (forceLoad) {
oxRequire(buff, ctx->rom->read(path));
oxRequire(obj, readConvert(ctx, buff));
// Warning: StringView to String
oxRequire(cached, ctx->assetManager.setAsset(ox::String(assetId), obj));
oxRequire(cached, ctx->assetManager.setAsset(assetId, obj));
return cached;
} else {
// Warning: StringView to String
auto [cached, err] = ctx->assetManager.getAsset<T>(ox::String(assetId));
auto [cached, err] = ctx->assetManager.getAsset<T>(assetId);
if (err) {
oxRequire(buff, ctx->rom->read(path));
oxRequire(obj, readConvert(ctx, buff));
// Warning: StringView to String
oxReturnError(ctx->assetManager.setAsset(ox::String(assetId), obj).moveTo(&cached));
oxReturnError(ctx->assetManager.setAsset(assetId, obj).moveTo(&cached));
}
return cached;
}
@@ -107,14 +103,12 @@ ox::Result<AssetRef<T>> setAsset(keel::Context *ctx, ox::StringView assetId, T c
}
ox::UUIDStr idStr;
if (assetId[0] == '/') {
// Warning: StringView to String
const auto [id, err] = ctx->pathToUuid.at(ox::String(assetId));
const auto [id, err] = ctx->pathToUuid.at(assetId);
oxReturnError(err);
idStr = id->toString();
assetId = idStr;
}
// Warning: StringView to String
return ctx->assetManager.setAsset(ox::String(assetId), asset);
return ctx->assetManager.setAsset(assetId, asset);
#else
return OxError(1, "Not supported on this platform");
#endif

View File

@@ -31,7 +31,7 @@ static ox::Error pathToInode(
}
if (beginsWith(path, "uuid://")) {
#ifndef OX_BARE_METAL
const auto uuid = ox::StringView(path).substr(7);
const auto uuid = substr(ox::StringView(path), 7);
path = ctx->uuidToPath[uuid];
#else
return OxError(1, "UUID to path conversion not supported on this platform");