diff --git a/src/nostalgia/core/clipboard.hpp b/src/nostalgia/core/clipboard.hpp index af32d7dd..96fd8eba 100644 --- a/src/nostalgia/core/clipboard.hpp +++ b/src/nostalgia/core/clipboard.hpp @@ -14,7 +14,7 @@ namespace nostalgia::core { ox::String getClipboardText(class Context *ctx) noexcept; -void setClipboardText(class Context *ctx, const ox::String &text) noexcept; +void setClipboardText(class Context *ctx, ox::CRStringView text) noexcept; template void setClipboardObject([[maybe_unused]] class Context *ctx, [[maybe_unused]] ox::UniquePtr obj) noexcept { diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index cbb37309..b8acb028 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -63,7 +63,7 @@ class Context { const ox::FileAddress &palettePath) noexcept; friend ox::Error run(Context *ctx) noexcept; friend void shutdown(Context *ctx) noexcept; - friend ox::Result> init(ox::UniquePtr fs, const char *appName) noexcept; + friend ox::Result> init(ox::UniquePtr fs, ox::CRStringView appName) noexcept; friend ox::String getClipboardText(Context *ctx) noexcept; friend uint64_t ticksMs(Context *ctx) noexcept; friend uint8_t bgStatus(Context *ctx) noexcept; @@ -73,17 +73,15 @@ class Context { friend void setBgCbb(Context *ctx, unsigned bgIdx, unsigned cbb) noexcept; friend void setBgStatus(Context *ctx, uint32_t status) noexcept; friend void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept; - friend void setClipboardText(Context *ctx, const ox::String &text) noexcept; friend void setUpdateHandler(Context *ctx, UpdateHandler h) noexcept; friend constexpr void setKeyEventHandler(Context *ctx, KeyEventHandler h) noexcept; friend constexpr KeyEventHandler keyEventHandler(Context *ctx) noexcept; friend void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept; - friend void setWindowTitle(Context *ctx, const char *title) noexcept; public: ox::UniquePtr rom; ox::Vector drawers; - const char *appName = "Nostalgia"; + ox::StringView appName = "Nostalgia"; #ifndef OX_BARE_METAL AssetManager assetManager; diff --git a/src/nostalgia/core/core.hpp b/src/nostalgia/core/core.hpp index baa1f849..628d05f9 100644 --- a/src/nostalgia/core/core.hpp +++ b/src/nostalgia/core/core.hpp @@ -17,7 +17,7 @@ namespace nostalgia::core { -ox::Result> init(ox::UniquePtr fs, const char *appName = "Nostalgia") noexcept; +ox::Result> init(ox::UniquePtr fs, ox::CRStringView appName = "Nostalgia") noexcept; ox::Error run(Context *ctx) noexcept; diff --git a/src/nostalgia/core/gba/core.cpp b/src/nostalgia/core/gba/core.cpp index 06226e36..bcbb443b 100644 --- a/src/nostalgia/core/gba/core.cpp +++ b/src/nostalgia/core/gba/core.cpp @@ -54,7 +54,7 @@ static ox::Result findPreloadSection() noexcept { return OxError(1); } -ox::Result> init(ox::UniquePtr fs, const char *appName) noexcept { +ox::Result> init(ox::UniquePtr fs, ox::CRStringView appName) noexcept { auto ctx = ox::make_unique(); ctx->rom = std::move(fs); ctx->appName = appName; diff --git a/src/nostalgia/core/gba/gfx.cpp b/src/nostalgia/core/gba/gfx.cpp index 78e1351c..54ad80e7 100644 --- a/src/nostalgia/core/gba/gfx.cpp +++ b/src/nostalgia/core/gba/gfx.cpp @@ -85,7 +85,7 @@ ox::Error shutdownGfx(Context*) noexcept { return {}; } -void setWindowTitle(Context*, const char*) noexcept { +void setWindowTitle(Context*, ox::CRStringView) noexcept { } void focusWindow(Context*) noexcept { @@ -210,10 +210,11 @@ ox::Error loadSpritePalette(Context *ctx, unsigned cbb, const ox::FileAddress &p } // Do NOT use Context in the GBA version of this function. -void puts(Context *ctx, int column, int row, const char *str) noexcept { - for (int i = 0; str[i]; i++) { +void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept { + const auto col = static_cast(column); + for (auto i = 0u; i < str.bytes(); i++) { const auto c = charMap[static_cast(str[i])]; - setTile(ctx, 0, column + i, row, static_cast(c)); + setTile(ctx, 0, static_cast(col + i), row, static_cast(c)); } } diff --git a/src/nostalgia/core/gba/media.cpp b/src/nostalgia/core/gba/media.cpp index 4fd0a14d..4fecd0a5 100644 --- a/src/nostalgia/core/gba/media.cpp +++ b/src/nostalgia/core/gba/media.cpp @@ -11,7 +11,7 @@ namespace nostalgia::core { -ox::Result loadRom(const char*) noexcept { +ox::Result loadRom(ox::CRStringView) noexcept { // put the header in the wrong order to prevent mistaking this code for the // media section constexpr auto headerP2 = "HEADER__________"; diff --git a/src/nostalgia/core/gba/panic.cpp b/src/nostalgia/core/gba/panic.cpp index c21cf5d2..60938753 100644 --- a/src/nostalgia/core/gba/panic.cpp +++ b/src/nostalgia/core/gba/panic.cpp @@ -27,7 +27,7 @@ void panic(const char*, int, const char *msg, const ox::Error &err) noexcept { puts(nullptr, 32 + 1, 4, "UNEXPECTED STATE:"); puts(nullptr, 32 + 2, 6, msg); if (err) { - puts(nullptr, 32 + 2, 8, serr.c_str()); + puts(nullptr, 32 + 2, 8, serr); } puts(nullptr, 32 + 1, 15, "PLEASE RESTART THE SYSTEM"); // disable all interrupt handling and IntrWait on no interrupts diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index 3fd36e35..59a22b8d 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -93,11 +93,11 @@ struct TileSheet { other.columns = 0; other.rows = 0; } - constexpr SubSheet(const char *pName, int pColumns, int pRows, int bpp) noexcept: + constexpr SubSheet(ox::CRStringView pName, int pColumns, int pRows, int bpp) noexcept: name(pName), columns(pColumns), rows(pRows), pixels(static_cast(columns * rows * PixelsPerTile) / (bpp == 4 ? 2u : 1u)) { } - constexpr SubSheet(const char *pName, int pColumns, int pRows, ox::Vector pPixels) noexcept: + constexpr SubSheet(ox::CRStringView pName, int pColumns, int pRows, ox::Vector pPixels) noexcept: name(pName), columns(pColumns), rows(pRows), pixels(std::move(pPixels)) { } @@ -375,7 +375,7 @@ struct TileSheet { constexpr ox::Error addSubSheet(const SubSheetIdx &idx) noexcept { auto &parent = getSubSheet(idx); if (parent.subsheets.size() < 2) { - parent.subsheets.emplace_back(ox::sfmt("Subsheet {}", parent.subsheets.size()).c_str(), 1, 1, bpp); + parent.subsheets.emplace_back(ox::sfmt("Subsheet {}", parent.subsheets.size()), 1, 1, bpp); } else { parent.subsheets.emplace_back("Subsheet 0", parent.columns, parent.rows, bpp); parent.subsheets.emplace_back("Subsheet 1", 1, 1, bpp); @@ -482,7 +482,7 @@ void addCustomDrawer(Context *ctx, Drawer *cd) noexcept; void removeCustomDrawer(Context *ctx, Drawer *cd) noexcept; -void setWindowTitle(Context *ctx, const char *title) noexcept; +void setWindowTitle(Context *ctx, ox::CRStringView title) noexcept; void focusWindow(Context *ctx) noexcept; @@ -518,7 +518,7 @@ ox::Error loadSpriteTileSheet(Context *ctx, const ox::FileAddress &tilesheetAddr, const ox::FileAddress &paletteAddr) noexcept; -void puts(Context *ctx, int column, int row, const char *str) noexcept; +void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept; void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept; diff --git a/src/nostalgia/core/glfw/clipboard.cpp b/src/nostalgia/core/glfw/clipboard.cpp index ddde7792..259d7907 100644 --- a/src/nostalgia/core/glfw/clipboard.cpp +++ b/src/nostalgia/core/glfw/clipboard.cpp @@ -17,9 +17,11 @@ ox::String getClipboardText(Context *ctx) noexcept { return glfwGetClipboardString(id->window); } -void setClipboardText(Context *ctx, const ox::String &text) noexcept { +void setClipboardText(Context *ctx, ox::CRStringView text) noexcept { const auto id = ctx->windowerData(); - glfwSetClipboardString(id->window, text.c_str()); + auto cstr = ox_malloca(text.bytes() + 1, char); + ox_strncpy(cstr.get(), text.data(), text.bytes()); + glfwSetClipboardString(id->window, cstr); } } diff --git a/src/nostalgia/core/glfw/core.cpp b/src/nostalgia/core/glfw/core.cpp index ccfa8ddc..69c7ddd2 100644 --- a/src/nostalgia/core/glfw/core.cpp +++ b/src/nostalgia/core/glfw/core.cpp @@ -13,7 +13,7 @@ namespace nostalgia::core { -ox::Result> init(ox::UniquePtr fs, const char *appName) noexcept { +ox::Result> init(ox::UniquePtr fs, ox::CRStringView appName) noexcept { auto ctx = ox::make_unique(); ctx->rom = std::move(fs); ctx->appName = appName; diff --git a/src/nostalgia/core/glfw/gfx.cpp b/src/nostalgia/core/glfw/gfx.cpp index 1215beb8..37787741 100644 --- a/src/nostalgia/core/glfw/gfx.cpp +++ b/src/nostalgia/core/glfw/gfx.cpp @@ -192,7 +192,9 @@ ox::Error initGfx(Context *ctx) noexcept { glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); } glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); - id->window = glfwCreateWindow(240 * Scale, 160 * Scale, ctx->appName, nullptr, nullptr); + auto cstr = ox_malloca(ctx->appName.bytes() + 1, char); + ox_strncpy(cstr.get(), ctx->appName.data(), ctx->appName.bytes()); + id->window = glfwCreateWindow(240 * Scale, 160 * Scale, cstr, nullptr, nullptr); if (id->window == nullptr) { return OxError(1, "Could not open GLFW window"); } @@ -220,9 +222,11 @@ ox::Error initGfx(Context *ctx) noexcept { return OxError(0); } -void setWindowTitle(Context *ctx, const char *title) noexcept { +void setWindowTitle(Context *ctx, ox::CRStringView title) noexcept { const auto id = ctx->windowerData(); - glfwSetWindowTitle(id->window, title); + auto cstr = ox_malloca(title.bytes() + 1, char); + ox_strncpy(cstr.get(), title.data(), title.bytes()); + glfwSetWindowTitle(id->window, cstr); } void focusWindow(Context *ctx) noexcept { diff --git a/src/nostalgia/core/headless/core.cpp b/src/nostalgia/core/headless/core.cpp index 9d324474..00791393 100644 --- a/src/nostalgia/core/headless/core.cpp +++ b/src/nostalgia/core/headless/core.cpp @@ -7,7 +7,7 @@ namespace nostalgia::core { -ox::Result> init(ox::UniquePtr, const char*) noexcept { +ox::Result> init(ox::UniquePtr, ox::CRStringView) noexcept { return OxError(1); } diff --git a/src/nostalgia/core/headless/gfx.cpp b/src/nostalgia/core/headless/gfx.cpp index 66ec931b..3adb76e6 100644 --- a/src/nostalgia/core/headless/gfx.cpp +++ b/src/nostalgia/core/headless/gfx.cpp @@ -15,7 +15,7 @@ ox::Error shutdownGfx(Context*) noexcept { return OxError(0); } -void setWindowTitle(Context*, const char*) noexcept { +void setWindowTitle(Context*, ox::CRStringView) noexcept { } void focusWindow(Context*) noexcept { @@ -75,7 +75,7 @@ ox::Error loadSpritePalette(Context*, int, const ox::FileAddress&) noexcept { } // Do NOT use Context in the GBA version of this function. -void puts(Context*, int, int, const char*) noexcept { +void puts(Context*, int, int, ox::CRStringView) noexcept { } void setTile(Context*, int, int, int, uint8_t) noexcept { diff --git a/src/nostalgia/core/headless/media.cpp b/src/nostalgia/core/headless/media.cpp index 9edf68c1..dcfeaac8 100644 --- a/src/nostalgia/core/headless/media.cpp +++ b/src/nostalgia/core/headless/media.cpp @@ -8,7 +8,7 @@ namespace nostalgia::core { -ox::Result loadRom(const char*) noexcept { +ox::Result loadRom(ox::CRStringView) noexcept { return OxError(1); } diff --git a/src/nostalgia/core/media.cpp b/src/nostalgia/core/media.cpp index dfe6bd3f..ebcbe4c5 100644 --- a/src/nostalgia/core/media.cpp +++ b/src/nostalgia/core/media.cpp @@ -6,9 +6,9 @@ namespace nostalgia::core { -ox::Result> loadRomFs(const char *path) noexcept { +ox::Result> loadRomFs(ox::CRStringView path) noexcept { const auto lastDot = ox_lastIndexOf(path, '.'); - const auto fsExt = lastDot != -1 ? path + lastDot : ""; + const auto fsExt = lastDot != -1 ? path.substr(static_cast(lastDot)) : ""; if (ox_strcmp(fsExt, ".oxfs") == 0) { oxRequire(rom, core::loadRom(path)); return {ox::make_unique(rom, 32 * ox::units::MB, unloadRom)}; diff --git a/src/nostalgia/core/media.hpp b/src/nostalgia/core/media.hpp index 523e6bfa..1bff8b41 100644 --- a/src/nostalgia/core/media.hpp +++ b/src/nostalgia/core/media.hpp @@ -89,9 +89,9 @@ ox::Error writeObj(Context *ctx, const ox::FileAddress &file, const T &obj, return ctx->rom->write(file, objBuff.data(), objBuff.size()); } -ox::Result> loadRomFs(const char *path) noexcept; +ox::Result> loadRomFs(ox::CRStringView path) noexcept; -ox::Result loadRom(const char *path = "") noexcept; +ox::Result loadRom(ox::CRStringView path = "") noexcept; void unloadRom(char*) noexcept; diff --git a/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp b/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp index dd9bc4be..8b684af2 100644 --- a/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp @@ -416,7 +416,7 @@ void TileSheetEditorImGui::SubSheetEditor::draw() noexcept { if (ImGui::Button("OK")) { ImGui::CloseCurrentPopup(); m_show = false; - inputSubmitted.emit(m_name.c_str(), m_cols, m_rows); + inputSubmitted.emit(m_name, m_cols, m_rows); } ImGui::SameLine(); if (ImGui::Button("Cancel")) { diff --git a/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp b/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp index 66767ede..d770e7d6 100644 --- a/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp @@ -32,7 +32,7 @@ class TileSheetEditorImGui: public studio::BaseEditor { int m_rows = 0; bool m_show = false; public: - ox::Signal inputSubmitted; + ox::Signal inputSubmitted; constexpr void show(const ox::String &name, int cols, int rows) noexcept { m_show = true; m_name = name.c_str(); diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.cpp b/src/nostalgia/core/studio/tilesheeteditormodel.cpp index 11a37a88..43fb6221 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.cpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.cpp @@ -256,7 +256,7 @@ class AddSubSheetCommand: public TileSheetCommand { auto &parent = m_img->getSubSheet(m_parentIdx); if (m_addedSheets.size() < 2) { auto i = parent.subsheets.size(); - parent.subsheets.emplace_back(ox::sfmt("Subsheet {}", i).c_str(), 1, 1, m_img->bpp); + parent.subsheets.emplace_back(ox::sfmt("Subsheet {}", i), 1, 1, m_img->bpp); } else { parent.subsheets.emplace_back("Subsheet 0", parent.columns, parent.rows, std::move(parent.pixels)); parent.rows = 0; diff --git a/src/nostalgia/core/typeconv.cpp b/src/nostalgia/core/typeconv.cpp index 1e7cc24a..11e1eb49 100644 --- a/src/nostalgia/core/typeconv.cpp +++ b/src/nostalgia/core/typeconv.cpp @@ -49,8 +49,8 @@ static const auto converters = [] { }(); [[nodiscard]] -static auto findConverter(const char *srcTypeName, int srcTypeVersion, - const char *dstTypeName, int dstTypeVersion) noexcept -> ox::Result { +static auto findConverter(ox::CRStringView srcTypeName, int srcTypeVersion, + ox::CRStringView dstTypeName, int dstTypeVersion) noexcept -> ox::Result { for (auto &c : converters) { if (c->matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) { return c.get(); @@ -60,8 +60,8 @@ static auto findConverter(const char *srcTypeName, int srcTypeVersion, }; static ox::Result> convert(const ox::Buffer &srcBuffer, - const char *srcTypeName, int srcTypeVersion, - const char *dstTypeName, int dstTypeVersion) noexcept { + ox::CRStringView srcTypeName, int srcTypeVersion, + ox::CRStringView dstTypeName, int dstTypeVersion) noexcept { // look for direct converter auto [c, err] = findConverter(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion); if (!err) { @@ -82,9 +82,9 @@ static ox::Result> convert(const ox::Buffer &srcBuffer, return OxError(1, "Could not convert between types"); } -ox::Result> convert(const ox::Buffer &srcBuffer, const char *dstTypeName, int dstTypeVersion) noexcept { +ox::Result> convert(const ox::Buffer &srcBuffer, ox::CRStringView dstTypeName, int dstTypeVersion) noexcept { oxRequire(hdr, ox::readClawHeader(srcBuffer)); - return convert(srcBuffer, hdr.typeName.c_str(), hdr.typeVersion, dstTypeName, dstTypeVersion); + return convert(srcBuffer, hdr.typeName, hdr.typeVersion, dstTypeName, dstTypeVersion); } #endif diff --git a/src/nostalgia/core/typeconv.hpp b/src/nostalgia/core/typeconv.hpp index 1de6a38c..f54dd587 100644 --- a/src/nostalgia/core/typeconv.hpp +++ b/src/nostalgia/core/typeconv.hpp @@ -51,24 +51,24 @@ struct BaseConverter { virtual ~BaseConverter() noexcept = default; [[nodiscard]] - virtual const char *srcTypeName() noexcept = 0; + virtual ox::StringView srcTypeName() noexcept = 0; [[nodiscard]] virtual int srcTypeVersion() noexcept = 0; [[nodiscard]] - virtual bool srcMatches(const char *srcTypeName, int srcTypeVersion) const noexcept = 0; + virtual bool srcMatches(ox::CRStringView srcTypeName, int srcTypeVersion) const noexcept = 0; [[nodiscard]] - virtual bool dstMatches(const char *dstTypeName, int dstTypeVersion) const noexcept = 0; + virtual bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept = 0; virtual ox::Result> convertPtrToPtr(Wrap *src) noexcept = 0; virtual ox::Result> convertBuffToPtr(const ox::Buffer &srcBuff) noexcept = 0; [[nodiscard]] - inline bool matches(const char *srcTypeName, int srcTypeVersion, - const char *dstTypeName, int dstTypeVersion) const noexcept { + inline bool matches(ox::CRStringView srcTypeName, int srcTypeVersion, + ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept { return srcMatches(srcTypeName, srcTypeVersion) && dstMatches(dstTypeName, dstTypeVersion); } @@ -81,7 +81,7 @@ struct Converter: public BaseConverter { virtual ox::Error convert(SrcType*, DstType*) noexcept = 0; [[nodiscard]] - const char *srcTypeName() noexcept final { + ox::StringView srcTypeName() noexcept final { return ox::requireModelTypeName(); } @@ -91,7 +91,7 @@ struct Converter: public BaseConverter { } [[nodiscard]] - bool srcMatches(const char *srcTypeName, int srcTypeVersion) const noexcept final { + bool srcMatches(ox::CRStringView srcTypeName, int srcTypeVersion) const noexcept final { static constexpr auto SrcTypeName = ox::requireModelTypeName(); static constexpr auto SrcTypeVersion = ox::requireModelTypeVersion(); return ox_strcmp(srcTypeName, SrcTypeName) == 0 @@ -99,7 +99,7 @@ struct Converter: public BaseConverter { } [[nodiscard]] - bool dstMatches(const char *dstTypeName, int dstTypeVersion) const noexcept final { + bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept final { static constexpr auto DstTypeName = ox::requireModelTypeName(); static constexpr auto DstTypeVersion = ox::requireModelTypeVersion(); return ox_strcmp(dstTypeName, DstTypeName) == 0 @@ -122,7 +122,7 @@ struct Converter: public BaseConverter { }; ox::Result> convert(const ox::Buffer &srcBuffer, - const char *dstTypeName, int dstTypeVersion) noexcept; + ox::CRStringView dstTypeName, int dstTypeVersion) noexcept; template ox::Result convert(const ox::Buffer &srcBuffer) noexcept { diff --git a/src/nostalgia/core/userland/gfx.cpp b/src/nostalgia/core/userland/gfx.cpp index ed715a0a..cccecafd 100644 --- a/src/nostalgia/core/userland/gfx.cpp +++ b/src/nostalgia/core/userland/gfx.cpp @@ -52,9 +52,10 @@ ox::Error loadSpriteTileSheet(Context*, return OxError(0); } -void puts(Context *ctx, int column, int row, const char *str) noexcept { - for (int i = 0; str[i]; ++i) { - setTile(ctx, 0, column + i, row, static_cast(charMap[static_cast(str[i])])); +void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept { + const auto col = static_cast(column); + for (auto i = 0u; i < str.bytes(); ++i) { + setTile(ctx, 0, static_cast(col + i), row, static_cast(charMap[static_cast(str[i])])); } } diff --git a/src/nostalgia/core/userland/media.cpp b/src/nostalgia/core/userland/media.cpp index b27c2af0..92ebe48b 100644 --- a/src/nostalgia/core/userland/media.cpp +++ b/src/nostalgia/core/userland/media.cpp @@ -10,8 +10,8 @@ namespace nostalgia::core { -ox::Result loadRom(const char *path) noexcept { - std::ifstream file(path, std::ios::binary | std::ios::ate); +ox::Result loadRom(ox::CRStringView path) noexcept { + std::ifstream file(toStdStringView(path), std::ios::binary | std::ios::ate); if (!file.good()) { oxErrorf("Could not find ROM file: {}", path); return OxError(1, "Could not find ROM file"); diff --git a/src/nostalgia/glutils/glutils.cpp b/src/nostalgia/glutils/glutils.cpp index b17e4dad..211823fc 100644 --- a/src/nostalgia/glutils/glutils.cpp +++ b/src/nostalgia/glutils/glutils.cpp @@ -47,7 +47,7 @@ template struct GLObject; template struct GLObject; [[nodiscard]] -static ox::Result buildShader(GLuint shaderType, const GLchar *src, const char *shaderName) noexcept { +static ox::Result buildShader(GLuint shaderType, const GLchar *src, ox::CRStringView shaderName) noexcept { GLShader shader(glCreateShader(shaderType)); glShaderSource(shader, 1, &src, nullptr); glCompileShader(shader); diff --git a/src/nostalgia/studio/lib/configio.hpp b/src/nostalgia/studio/lib/configio.hpp index 3b2675fc..e836c30d 100644 --- a/src/nostalgia/studio/lib/configio.hpp +++ b/src/nostalgia/studio/lib/configio.hpp @@ -38,7 +38,7 @@ constexpr auto ConfigDir = [] { }(); template -ox::Result readConfig(core::Context *ctx, const char *name) noexcept { +ox::Result readConfig(core::Context *ctx, ox::CRStringView name) noexcept { oxAssert(ox_strcmp(name, ""), "Config type has no TypeName"); const auto homeDir = std::getenv(ox::defines::OS == ox::OS::Windows ? "USERPROFILE" : "HOME"); const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName).toStdString(); @@ -70,16 +70,16 @@ template ox::Error writeConfig(core::Context *ctx, const auto &name, T *data) noexcept { oxAssert(ox_strcmp(name, ""), "Config type has no TypeName"); const auto homeDir = std::getenv(ox::defines::OS == ox::OS::Windows ? "USERPROFILE" : "HOME"); - const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName).toStdString(); - const auto path = ox::sfmt("{}.json", name).toStdString(); - ox::PassThroughFS fs(configPath.c_str()); + const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName); + const auto path = ox::sfmt("{}.json", name); + ox::PassThroughFS fs(configPath); if (auto err = fs.mkdir("/", true)) { oxErrf("Could not create config directory: {}\n", toStr(err)); return err; } oxRequireM(buff, ox::writeOC(data)); buff.back().value = '\n'; - if (auto err = fs.write(path.c_str(), buff.data(), buff.size())) { + if (auto err = fs.write(path, buff.data(), buff.size())) { oxErrf("Could not read config file: {}\n", toStr(err)); return OxError(2, "Could not read config file"); } diff --git a/src/nostalgia/studio/lib/itemmaker.hpp b/src/nostalgia/studio/lib/itemmaker.hpp index 05af6cdb..847c095d 100644 --- a/src/nostalgia/studio/lib/itemmaker.hpp +++ b/src/nostalgia/studio/lib/itemmaker.hpp @@ -21,7 +21,7 @@ class ItemMaker { fileExt(std::move(pFileExt)) { } virtual ~ItemMaker() noexcept = default; - virtual ox::Error write(core::Context *ctx, const char *pName) const noexcept = 0; + virtual ox::Error write(core::Context *ctx, ox::CRStringView pName) const noexcept = 0; }; template @@ -44,7 +44,7 @@ class ItemMakerT: public ItemMaker { item(std::forward(pItem)), fmt(pFmt) { } - ox::Error write(core::Context *ctx, const char *pName) const noexcept override { + ox::Error write(core::Context *ctx, ox::CRStringView pName) const noexcept override { const auto path = ox::sfmt("{}/{}.{}", parentDir, pName, fileExt); auto sctx = core::applicationData(ctx); return sctx->project->writeObj(path, &item, fmt); diff --git a/src/nostalgia/studio/newmenu.cpp b/src/nostalgia/studio/newmenu.cpp index 4c4d9f2e..c7b140e0 100644 --- a/src/nostalgia/studio/newmenu.cpp +++ b/src/nostalgia/studio/newmenu.cpp @@ -108,7 +108,7 @@ void NewMenu::drawLastPageButtons(core::Context *ctx) noexcept { } void NewMenu::finish(core::Context *ctx) noexcept { - const auto err = m_types[static_cast(m_selectedType)]->write(ctx, m_itemName.c_str()); + const auto err = m_types[static_cast(m_selectedType)]->write(ctx, m_itemName); if (err) { oxLogError(err); return; diff --git a/src/nostalgia/studio/studioapp.cpp b/src/nostalgia/studio/studioapp.cpp index bfdc7dab..ba64310d 100644 --- a/src/nostalgia/studio/studioapp.cpp +++ b/src/nostalgia/studio/studioapp.cpp @@ -283,10 +283,10 @@ void StudioUI::save() noexcept { } } -ox::Error StudioUI::openProject(const ox::String &path) noexcept { - oxRequireM(fs, core::loadRomFs(path.c_str())); +ox::Error StudioUI::openProject(ox::CRStringView path) noexcept { + oxRequireM(fs, core::loadRomFs(path)); m_ctx->rom = std::move(fs); - core::setWindowTitle(m_ctx, ox::sfmt("Nostalgia Studio - {}", path).c_str()); + core::setWindowTitle(m_ctx, ox::sfmt("Nostalgia Studio - {}", path)); m_project = ox::make_unique(m_ctx->rom.get(), path); auto sctx = applicationData(m_ctx); sctx->project = m_project.get(); diff --git a/src/nostalgia/studio/studioapp.hpp b/src/nostalgia/studio/studioapp.hpp index a7529cb1..b5c79f7d 100644 --- a/src/nostalgia/studio/studioapp.hpp +++ b/src/nostalgia/studio/studioapp.hpp @@ -77,7 +77,7 @@ class StudioUI: public ox::SignalHandler { void save() noexcept; - ox::Error openProject(const ox::String &path) noexcept; + ox::Error openProject(ox::CRStringView path) noexcept; ox::Error openFile(ox::CRStringView path) noexcept; diff --git a/src/nostalgia/tools/pack.cpp b/src/nostalgia/tools/pack.cpp index 423608c2..f792aed0 100644 --- a/src/nostalgia/tools/pack.cpp +++ b/src/nostalgia/tools/pack.cpp @@ -13,9 +13,9 @@ using namespace nostalgia; -static ox::Error writeFileBuff(ox::CRString path, const ox::Buffer &buff) noexcept { +static ox::Error writeFileBuff(ox::CRStringView path, const ox::Buffer &buff) noexcept { try { - std::ofstream f(path.c_str(), std::ios::binary); + std::ofstream f(toStdStringView(path), std::ios::binary); f.write(buff.data(), static_cast(buff.size())); } catch (const std::fstream::failure&) { return OxError(2, "failed to write file"); @@ -23,8 +23,8 @@ static ox::Error writeFileBuff(ox::CRString path, const ox::Buffer &buff) noexce return {}; } -static ox::Result readFileBuff(const char *path) noexcept { - std::ifstream file(path, std::ios::binary | std::ios::ate); +static ox::Result readFileBuff(ox::CRStringView path) noexcept { + std::ifstream file(toStdStringView(path), std::ios::binary | std::ios::ate); if (!file.good()) { oxErrorf("Could not find OxFS file: {}", path); return OxError(1, "Could not find OxFS file"); @@ -55,7 +55,7 @@ static ox::Error run(const ox::ClArgs &args) noexcept { } ox::Buffer dstBuff(32 * ox::units::MB); oxReturnError(ox::FileSystem32::format(dstBuff.data(), dstBuff.size())); - ox::PassThroughFS src(argSrc.c_str()); + ox::PassThroughFS src(argSrc); ox::FileSystem32 dst(ox::FileStore32(dstBuff.data(), dstBuff.size())); core::TypeStore ts(&src); oxReturnError(pack(&ts, &src, &dst)); @@ -66,7 +66,7 @@ static ox::Error run(const ox::ClArgs &args) noexcept { oxRequire(dstSize, dst.size()); dstBuff.resize(dstSize); - oxRequireM(romBuff, readFileBuff(argRomBin.c_str())); + oxRequireM(romBuff, readFileBuff(argRomBin)); oxReturnError(appendBinary(&romBuff, &dstBuff, pl.get())); oxOutf("Dest FS size: {} bytes\n", dstSize); diff --git a/src/nostalgia/tools/pack/pack.cpp b/src/nostalgia/tools/pack/pack.cpp index 2533b9b0..c82258a5 100644 --- a/src/nostalgia/tools/pack/pack.cpp +++ b/src/nostalgia/tools/pack/pack.cpp @@ -123,7 +123,7 @@ static ox::Error copy(ox::FileSystem *src, ox::FileSystem *dest, ox::CRStringVie oxOutf("reading {}\n", currentFile); oxRequire(stat, src->stat(ox::StringView(currentFile))); if (stat.fileType == ox::FileType::Directory) { - oxReturnError(dest->mkdir(currentFile.c_str(), true)); + oxReturnError(dest->mkdir(currentFile, true)); oxReturnError(copy(src, dest, currentFile + '/')); } else { // load file