diff --git a/src/keel/assetmanager.hpp b/src/keel/assetmanager.hpp index 9683861c..d2088bc2 100644 --- a/src/keel/assetmanager.hpp +++ b/src/keel/assetmanager.hpp @@ -194,13 +194,13 @@ class AssetManager { ox::HashMap>> m_cache; public: - ox::Result> getAsset(const ox::String &assetId) const noexcept { + ox::Result> getAsset(const ox::StringView &assetId) const noexcept { auto out = m_cache.at(assetId); oxReturnError(out); return AssetRef(out.value->get()); } - ox::Result> setAsset(const ox::String &assetId, const T &obj) noexcept { + ox::Result> setAsset(const ox::StringView &assetId, const T &obj) noexcept { auto &p = m_cache[assetId]; if (!p) { p = ox::make_unique>(obj); @@ -211,7 +211,7 @@ class AssetManager { return AssetRef(p.get()); } - ox::Result> setAsset(const ox::String &assetId, T &&obj) noexcept { + ox::Result> setAsset(const ox::StringView &assetId, T &&obj) noexcept { auto &p = m_cache[assetId]; if (!p) { p = ox::make_unique>(obj); @@ -247,13 +247,13 @@ class AssetManager { public: template - ox::Result> getAsset(const ox::String &assetId) noexcept { + ox::Result> getAsset(ox::CRStringView assetId) noexcept { auto m = getTypeManager(); return m->getAsset(assetId); } template - ox::Result> setAsset(const ox::String &assetId, const T &obj) noexcept { + ox::Result> setAsset(ox::CRStringView assetId, const T &obj) noexcept { auto m = getTypeManager(); return m->setAsset(assetId, obj); } diff --git a/src/keel/media.cpp b/src/keel/media.cpp index e5671bb7..def57fb6 100644 --- a/src/keel/media.cpp +++ b/src/keel/media.cpp @@ -25,8 +25,11 @@ ox::Result 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 fs) noexcept { ox::Result> loadRomFs(ox::CRStringView path) noexcept { const auto lastDot = ox_lastIndexOf(path, '.'); - const auto fsExt = lastDot != -1 ? path.substr(static_cast(lastDot)) : ""; + const auto fsExt = lastDot != -1 ? substr(path, static_cast(lastDot)) : ""; if (ox_strcmp(fsExt, ".oxfs") == 0) { oxRequire(rom, loadRom(path)); return {ox::make_unique(rom, 32 * ox::units::MB, unloadRom)}; diff --git a/src/keel/media.hpp b/src/keel/media.hpp index 9ca3afec..8d5ef1dd 100644 --- a/src/keel/media.hpp +++ b/src/keel/media.hpp @@ -52,28 +52,24 @@ ox::Result> 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(ox::String(assetId)); + auto [cached, err] = ctx->assetManager.getAsset(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> 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 diff --git a/src/keel/pack.cpp b/src/keel/pack.cpp index 22e3a206..402f1916 100644 --- a/src/keel/pack.cpp +++ b/src/keel/pack.cpp @@ -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"); diff --git a/src/nostalgia/modules/core/src/studio/studiomodule.cpp b/src/nostalgia/modules/core/src/studio/studiomodule.cpp index 7659db75..d4fd7e91 100644 --- a/src/nostalgia/modules/core/src/studio/studiomodule.cpp +++ b/src/nostalgia/modules/core/src/studio/studiomodule.cpp @@ -29,10 +29,10 @@ class StudioModule: public studio::Module { }; } - ox::Vector> itemMakers(turbine::Context*) const noexcept final { + ox::Vector> itemMakers(turbine::Context*) const noexcept final { ox::Vector> out; - out.emplace_back(ox::make>("Tile Sheet", "TileSheets", "ng")); - out.emplace_back(ox::make>("Palette", "Palettes", "npal")); + out.emplace_back(ox::make>("Tile Sheet", "TileSheets", FileExt_ng)); + out.emplace_back(ox::make>("Palette", "Palettes", FileExt_npal)); return out; } }; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp index 45c41d8c..51ebf04d 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp @@ -632,7 +632,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept { } constexpr ox::StringView uuidPrefix = "uuid://"; if (ox::beginsWith(path, uuidPrefix)) { - auto uuid = ox::StringView(path + uuidPrefix.bytes(), ox_strlen(path) - uuidPrefix.bytes()); + auto uuid = ox::StringView(path.data() + uuidPrefix.bytes(), path.bytes() - uuidPrefix.bytes()); auto out = m_ctx->keelCtx.uuidToPath.at(uuid); if (out.error) { return {}; diff --git a/src/nostalgia/player/main.cpp b/src/nostalgia/player/main.cpp index 4e34b03b..985f1341 100644 --- a/src/nostalgia/player/main.cpp +++ b/src/nostalgia/player/main.cpp @@ -35,17 +35,7 @@ int main(int argc, const char **argv) { #endif OX_INIT_DEBUG_LOGGER(loggerConn, "Nostalgia Player") ox::Error err; -#ifdef __cpp_exceptions - try { - err = run(argc, argv); - } catch (ox::Exception const&ex) { - err = ex.toError(); - } catch (...) { - err = OxError(1, "Non-Ox exception"); - } -#else err = run(argc, argv); -#endif oxAssert(err, "Something went wrong..."); return static_cast(err); } diff --git a/src/studio/modlib/include/studio/project.hpp b/src/studio/modlib/include/studio/project.hpp index 554e1d2b..397478a7 100644 --- a/src/studio/modlib/include/studio/project.hpp +++ b/src/studio/modlib/include/studio/project.hpp @@ -33,7 +33,7 @@ constexpr ox::Result fileExt(ox::CRStringView path) noexcept { if (!extStart) { return OxError(1, "Cannot open a file without valid extension."); } - return path.substr(extStart + 1); + return substr(path, extStart + 1); } class Project { diff --git a/src/studio/modlib/src/editor.cpp b/src/studio/modlib/src/editor.cpp index 8fadb13b..dd3d0375 100644 --- a/src/studio/modlib/src/editor.cpp +++ b/src/studio/modlib/src/editor.cpp @@ -104,7 +104,7 @@ ox::Error BaseEditor::saveItem() noexcept { ox::StringView BaseEditor::pathToItemName(ox::CRStringView path) noexcept { const auto lastSlash = std::find(path.rbegin(), path.rend(), '/').offset(); - return path.substr(lastSlash + 1); + return substr(path, lastSlash + 1); } void BaseEditor::setRequiresConstantRefresh(bool value) noexcept { diff --git a/src/studio/modlib/src/project.cpp b/src/studio/modlib/src/project.cpp index 3197b425..d9230b60 100644 --- a/src/studio/modlib/src/project.cpp +++ b/src/studio/modlib/src/project.cpp @@ -23,7 +23,7 @@ static void generateTypes(ox::TypeStore *ts) noexcept { Project::Project(keel::Context *ctx, ox::String path, ox::CRStringView projectDataDir) noexcept: m_ctx(ctx), - m_path(path), + m_path(std::move(path)), m_projectDataDir(projectDataDir), m_typeStore(ctx->rom.get(), ox::sfmt("/.{}/type_descriptors", projectDataDir)), m_fs(ctx->rom.get()) { @@ -57,8 +57,7 @@ bool Project::exists(ox::CRStringView path) const noexcept { } const ox::Vector &Project::fileList(ox::CRStringView ext) noexcept { - // Warning: StringView to String - return m_fileExtFileMap[ox::String(ext)]; + return m_fileExtFileMap[ext]; } void Project::buildFileIndex() noexcept { @@ -81,8 +80,7 @@ void Project::indexFile(ox::CRStringView path) noexcept { if (err) { return; } - // Warning: StringView to String - m_fileExtFileMap[ox::String(ext)].emplace_back(path); + m_fileExtFileMap[ext].emplace_back(path); } ox::Error Project::writeBuff(const ox::StringView &path, const ox::Buffer &buff) noexcept { @@ -90,8 +88,7 @@ ox::Error Project::writeBuff(const ox::StringView &path, const ox::Buffer &buff) ox::Buffer outBuff; outBuff.reserve(buff.size() + HdrSz); ox::BufferWriter writer(&outBuff); - // Warning: StringView to String - const auto [uuid, err] = m_ctx->pathToUuid.at(ox::String(path)); + const auto [uuid, err] = m_ctx->pathToUuid.at(path); if (!err) { oxReturnError(keel::writeUuidHeader(writer, *uuid)); }