diff --git a/src/keel/CMakeLists.txt b/src/keel/CMakeLists.txt index 3c51f34b..8f8df73b 100644 --- a/src/keel/CMakeLists.txt +++ b/src/keel/CMakeLists.txt @@ -17,7 +17,6 @@ target_link_libraries( OxFS OxModel OxPreloader - OxStd ) install( @@ -45,4 +44,4 @@ install( if(TURBINE_BUILD_TYPE STREQUAL "Native") add_subdirectory(test) -endif() \ No newline at end of file +endif() diff --git a/src/keel/media.hpp b/src/keel/media.hpp index 94e2012d..9ca3afec 100644 --- a/src/keel/media.hpp +++ b/src/keel/media.hpp @@ -56,20 +56,24 @@ ox::Result> readObjFile( path = ctx->uuidToPath[assetId]; } else { path = assetId; - uuidStr = ctx->pathToUuid[path].toString(); + // Warning: StringView to String + uuidStr = ctx->pathToUuid[ox::String(path)].toString(); assetId = uuidStr; } if (forceLoad) { oxRequire(buff, ctx->rom->read(path)); oxRequire(obj, readConvert(ctx, buff)); - oxRequire(cached, ctx->assetManager.setAsset(assetId, obj)); + // Warning: StringView to String + oxRequire(cached, ctx->assetManager.setAsset(ox::String(assetId), obj)); return cached; } else { - auto [cached, err] = ctx->assetManager.getAsset(assetId); + // Warning: StringView to String + auto [cached, err] = ctx->assetManager.getAsset(ox::String(assetId)); if (err) { oxRequire(buff, ctx->rom->read(path)); oxRequire(obj, readConvert(ctx, buff)); - oxReturnError(ctx->assetManager.setAsset(assetId, obj).moveTo(&cached)); + // Warning: StringView to String + oxReturnError(ctx->assetManager.setAsset(ox::String(assetId), obj).moveTo(&cached)); } return cached; } @@ -103,12 +107,14 @@ ox::Result> setAsset(keel::Context *ctx, ox::StringView assetId, T c } ox::UUIDStr idStr; if (assetId[0] == '/') { - const auto [id, err] = ctx->pathToUuid.at(assetId); + // Warning: StringView to String + const auto [id, err] = ctx->pathToUuid.at(ox::String(assetId)); oxReturnError(err); idStr = id->toString(); assetId = idStr; } - return ctx->assetManager.setAsset(assetId, asset); + // Warning: StringView to String + return ctx->assetManager.setAsset(ox::String(assetId), asset); #else return OxError(1, "Not supported on this platform"); #endif diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.cpp index 72504b2f..39255ba8 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.cpp @@ -15,20 +15,11 @@ namespace nostalgia::core { -ox::Result PaletteEditorImGui::make(turbine::Context *ctx, ox::CRStringView path) noexcept { - ox::UniquePtr out; - try { - out = ox::UniquePtr(new PaletteEditorImGui); - } catch (...) { - return OxError(1); - } - out->m_ctx = ctx; - out->m_itemPath = path; - const auto lastSlash = std::find(out->m_itemPath.rbegin(), out->m_itemPath.rend(), '/').offset(); - out->m_itemName = out->m_itemPath.substr(lastSlash + 1); - oxRequire(pal, keel::readObj(&out->m_ctx->keelCtx, ox::FileAddress(out->m_itemPath.c_str()))); - out->m_pal = *pal; - return out.release(); +PaletteEditorImGui::PaletteEditorImGui(turbine::Context *ctx, ox::String path): + m_ctx(ctx), + m_itemPath(std::move(path)), + m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)), + m_pal(*keel::readObj(&m_ctx->keelCtx, ox::FileAddress(m_itemPath.c_str())).unwrapThrow()) { } const ox::String &PaletteEditorImGui::itemName() const noexcept { @@ -93,21 +84,25 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept { ImGui::TableSetupColumn("Blue", ImGuiTableColumnFlags_WidthFixed, 50); ImGui::TableSetupColumn("Color Preview", ImGuiTableColumnFlags_NoHide); ImGui::TableHeadersRow(); + constexpr auto colVal = [] (unsigned num) { + ox::Array numStr; + ImGui::TableNextColumn(); + ox_itoa(num, numStr.data()); + ImGui::SetCursorPosX( + ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - ImGui::CalcTextSize(numStr.data()).x); + ImGui::Text("%s", numStr.data()); + }; for (auto i = 0u; const auto c : m_pal.colors) { ImGui::PushID(static_cast(i)); ImGui::TableNextRow(); // Color No. - ImGui::TableNextColumn(); - ImGui::Text("%d", i); + colVal(i); // Red - ImGui::TableNextColumn(); - ImGui::Text("%d", red16(c)); + colVal(red16(c)); // Green - ImGui::TableNextColumn(); - ImGui::Text("%d", green16(c)); + colVal(green16(c)); // Blue - ImGui::TableNextColumn(); - ImGui::Text("%d", blue16(c)); + colVal(blue16(c)); // ColorPreview ImGui::TableNextColumn(); const auto ic = ImGui::GetColorU32(ImVec4(redf(c), greenf(c), bluef(c), 1)); diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.hpp b/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.hpp index b015bf64..f93804ad 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.hpp @@ -15,15 +15,15 @@ class PaletteEditorImGui: public studio::Editor { private: turbine::Context *m_ctx = nullptr; - ox::String m_itemName; ox::String m_itemPath; + ox::String m_itemName; Palette m_pal; std::size_t m_selectedRow = 0; PaletteEditorImGui() noexcept = default; public: - static ox::Result make(turbine::Context *ctx, ox::CRStringView path) noexcept; + PaletteEditorImGui(turbine::Context *ctx, ox::String path); /** * Returns the name of item being edited. diff --git a/src/nostalgia/modules/core/src/studio/studiomodule.cpp b/src/nostalgia/modules/core/src/studio/studiomodule.cpp index debcb469..7659db75 100644 --- a/src/nostalgia/modules/core/src/studio/studiomodule.cpp +++ b/src/nostalgia/modules/core/src/studio/studiomodule.cpp @@ -17,13 +17,13 @@ class StudioModule: public studio::Module { { {FileExt_ng}, [ctx](ox::CRStringView path) -> ox::Result { - return ox::makeCatch(ctx, path); + return ox::makeCatch(ctx, ox::String(path)); } }, { {FileExt_npal}, [ctx](ox::CRStringView path) -> ox::Result { - return PaletteEditorImGui::make(ctx, path); + return ox::makeCatch(ctx, ox::String(path)); } } }; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.cpp index 7dbcaf28..aefebf94 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.cpp @@ -38,9 +38,9 @@ ox::Error toPngFile(const ox::String &path, const TileSheet::SubSheet &s, const return OxError(static_cast(lodepng_encode_file(path.c_str(), outData.data(), width, height, fmt, 8))); } -TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context *ctx, ox::CRStringView path): m_tileSheetEditor(ctx, path) { +TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context *ctx, ox::String path): m_tileSheetEditor(ctx, path) { m_ctx = ctx; - m_itemPath = path; + m_itemPath = std::move(path); const auto lastSlash = ox::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset(); m_itemName = m_itemPath.substr(lastSlash + 1); // init palette idx @@ -393,7 +393,7 @@ void TileSheetEditorImGui::drawPaletteSelector() noexcept { } } -ox::Error TileSheetEditorImGui::updateActiveSubsheet(const ox::String &name, int cols, int rows) noexcept { +ox::Error TileSheetEditorImGui::updateActiveSubsheet(const ox::StringView &name, int cols, int rows) noexcept { return model()->updateSubsheet(model()->activeSubSheetIdx(), name, cols, rows); } diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.hpp index 2843ddfd..808712bc 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.hpp @@ -55,7 +55,7 @@ class TileSheetEditorImGui: public studio::BaseEditor { Tool m_tool = Tool::Draw; public: - TileSheetEditorImGui(turbine::Context *ctx, ox::CRStringView path); + TileSheetEditorImGui(turbine::Context *ctx, ox::String path); ~TileSheetEditorImGui() override = default; @@ -116,7 +116,7 @@ class TileSheetEditorImGui: public studio::BaseEditor { void drawPaletteSelector() noexcept; - ox::Error updateActiveSubsheet(const ox::String &name, int cols, int rows) noexcept; + ox::Error updateActiveSubsheet(const ox::StringView &name, int cols, int rows) noexcept; // slots private: diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp index d122b8af..45c41d8c 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp @@ -488,13 +488,13 @@ class UpdateSubSheetCommand: public TileSheetCommand { UpdateSubSheetCommand( TileSheet &img, TileSheet::SubSheetIdx idx, - const ox::String &name, + ox::String name, int cols, int rows) noexcept: m_img(img), m_idx(std::move(idx)) { m_sheet = m_img.getSubSheet(m_idx); - m_newName = name; + m_newName = std::move(name); m_newCols = cols; m_newRows = rows; } @@ -682,8 +682,8 @@ void TileSheetEditorModel::deleteTiles(const TileSheet::SubSheetIdx &idx, std::s pushCommand(ox::make(m_img, idx, tileIdx, tileCnt)); } -ox::Error TileSheetEditorModel::updateSubsheet(const TileSheet::SubSheetIdx &idx, const ox::String &name, int cols, int rows) noexcept { - pushCommand(ox::make(m_img, idx, name, cols, rows)); +ox::Error TileSheetEditorModel::updateSubsheet(const TileSheet::SubSheetIdx &idx, const ox::StringView &name, int cols, int rows) noexcept { + pushCommand(ox::make(m_img, idx, ox::String(name), cols, rows)); return {}; } diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.hpp index 5ead1eae..6acca3f5 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.hpp @@ -72,7 +72,7 @@ class TileSheetEditorModel: public ox::SignalHandler { void deleteTiles(const TileSheet::SubSheetIdx &idx, std::size_t tileIdx, std::size_t tileCnt) noexcept; - ox::Error updateSubsheet(const TileSheet::SubSheetIdx &idx, const ox::String &name, int cols, int rows) noexcept; + ox::Error updateSubsheet(const TileSheet::SubSheetIdx &idx, const ox::StringView &name, int cols, int rows) noexcept; void setActiveSubsheet(const TileSheet::SubSheetIdx&) noexcept; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditorview.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditorview.cpp index f8b721d4..adaa3765 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditorview.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditorview.cpp @@ -11,8 +11,8 @@ namespace nostalgia::core { -TileSheetEditorView::TileSheetEditorView(turbine::Context *ctx, ox::CRStringView path): - m_model(ctx, path), m_pixelsDrawer(&m_model) { +TileSheetEditorView::TileSheetEditorView(turbine::Context *ctx, ox::String path): + m_model(ctx, std::move(path)), m_pixelsDrawer(&m_model) { // build shaders oxThrowError(m_pixelsDrawer.buildShader()); oxThrowError(m_pixelGridDrawer.buildShader()); diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditorview.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditorview.hpp index 80b86d46..b0857826 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditorview.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditorview.hpp @@ -50,7 +50,7 @@ class TileSheetEditorView: public ox::SignalHandler { std::size_t m_palIdx = 0; public: - TileSheetEditorView(turbine::Context *ctx, ox::CRStringView path); + TileSheetEditorView(turbine::Context *ctx, ox::String path); ~TileSheetEditorView() override = default; diff --git a/src/nostalgia/modules/scene/include/nostalgia/scene/scene.hpp b/src/nostalgia/modules/scene/include/nostalgia/scene/scene.hpp index c8b8c6c2..6bbeb6e5 100644 --- a/src/nostalgia/modules/scene/include/nostalgia/scene/scene.hpp +++ b/src/nostalgia/modules/scene/include/nostalgia/scene/scene.hpp @@ -15,7 +15,7 @@ class Scene { public: explicit Scene(const SceneStatic &sceneStatic) noexcept; - ox::Error setupDisplay(core::Context *ctx) const noexcept; + ox::Error setupDisplay(core::Context &ctx) const noexcept; private: void setupLayer(core::Context*, const ox::Vector &layer, unsigned layerNo) const noexcept; diff --git a/src/nostalgia/modules/scene/src/scene.cpp b/src/nostalgia/modules/scene/src/scene.cpp index 25dc7933..8dc8ed6b 100644 --- a/src/nostalgia/modules/scene/src/scene.cpp +++ b/src/nostalgia/modules/scene/src/scene.cpp @@ -12,17 +12,17 @@ Scene::Scene(const SceneStatic &sceneStatic) noexcept: m_sceneStatic(sceneStatic) { } -ox::Error Scene::setupDisplay(core::Context *ctx) const noexcept { +ox::Error Scene::setupDisplay(core::Context &ctx) const noexcept { if (m_sceneStatic.palettes.empty()) { return OxError(1, "Scene has no palettes"); } const auto &palette = m_sceneStatic.palettes[0]; oxReturnError(core::loadBgTileSheet( - ctx, 0, m_sceneStatic.tilesheet, palette)); + &ctx, 0, m_sceneStatic.tilesheet, palette)); // disable all backgrounds - core::setBgStatus(ctx, 0); + core::setBgStatus(&ctx, 0); for (auto layerNo = 0u; const auto &layer : m_sceneStatic.tileMapIdx) { - setupLayer(ctx, layer, layerNo); + setupLayer(&ctx, layer, layerNo); ++layerNo; } return {}; diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp index 9c6c2e28..3e7e4c51 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp @@ -10,11 +10,11 @@ namespace nostalgia::scene { -SceneEditorImGui::SceneEditorImGui(turbine::Context *ctx, ox::CRStringView path): - m_editor(ctx, path), - m_view(ctx, m_editor.scene()) { - m_ctx = ctx; - m_itemPath = path; +SceneEditorImGui::SceneEditorImGui(turbine::Context &ctx, ox::String path): + m_ctx(ctx), + m_itemPath(std::move(path)), + m_editor(&m_ctx, m_itemPath), + m_view(&m_ctx, m_editor.scene()) { const auto lastSlash = std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset(); m_itemName = m_itemPath.substr(lastSlash + 1); setRequiresConstantRefresh(false); @@ -48,9 +48,9 @@ void SceneEditorImGui::onActivated() noexcept { } ox::Error SceneEditorImGui::saveItem() noexcept { - const auto sctx = applicationData(*m_ctx); + const auto sctx = applicationData(m_ctx); oxReturnError(sctx->project->writeObj(m_itemPath, &m_editor.scene())); - oxReturnError(m_ctx->keelCtx.assetManager.setAsset(m_itemPath, m_editor.scene())); + oxReturnError(m_ctx.keelCtx.assetManager.setAsset(m_itemPath, m_editor.scene())); return {}; } diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp index 848ced19..0e8c70cf 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp @@ -16,14 +16,14 @@ namespace nostalgia::scene { class SceneEditorImGui: public studio::Editor { private: - turbine::Context *m_ctx = nullptr; + turbine::Context &m_ctx; ox::String m_itemName; ox::String m_itemPath; SceneEditor m_editor; SceneEditorView m_view; public: - SceneEditorImGui(turbine::Context *ctx, ox::CRStringView path); + SceneEditorImGui(turbine::Context &ctx, ox::String path); /** * Returns the name of item being edited. diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditorview.cpp b/src/nostalgia/modules/scene/src/studio/sceneeditorview.cpp index fbe715f4..6fe37264 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditorview.cpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditorview.cpp @@ -15,7 +15,7 @@ SceneEditorView::SceneEditorView(turbine::Context *tctx, const SceneStatic &scen } ox::Error SceneEditorView::setupScene() noexcept { - return m_scene.setupDisplay(m_cctx.get()); + return m_scene.setupDisplay(*m_cctx); } void SceneEditorView::draw(int width, int height) noexcept { diff --git a/src/nostalgia/modules/scene/src/studio/studiomodule.cpp b/src/nostalgia/modules/scene/src/studio/studiomodule.cpp index 532deb50..72165c91 100644 --- a/src/nostalgia/modules/scene/src/studio/studiomodule.cpp +++ b/src/nostalgia/modules/scene/src/studio/studiomodule.cpp @@ -19,7 +19,7 @@ ox::Vector StudioModule::editors(turbine::Context *ctx) con { {"nscn"}, [ctx](ox::CRStringView path) -> ox::Result { - return ox::makeCatch(ctx, path); + return ox::makeCatch(*ctx, ox::String(path)); } }, }; diff --git a/src/nostalgia/player/app.cpp b/src/nostalgia/player/app.cpp index d238f99a..60bc1daa 100644 --- a/src/nostalgia/player/app.cpp +++ b/src/nostalgia/player/app.cpp @@ -33,7 +33,6 @@ static void keyEventHandler(turbine::Context &tctx, turbine::Key key, bool down) } ox::Error run(ox::UniquePtr &&fs) noexcept { - oxTraceInitHook(); oxRequireM(tctx, turbine::init(std::move(fs), "Nostalgia")); oxRequireM(cctx, core::init(tctx.get())); constexpr ox::FileAddress SceneAddr("/Scenes/Chester.nscn"); @@ -41,6 +40,6 @@ ox::Error run(ox::UniquePtr &&fs) noexcept { turbine::setUpdateHandler(*tctx, updateHandler); turbine::setKeyEventHandler(*tctx, keyEventHandler); s_scene.emplace(*scn); - oxReturnError(s_scene->setupDisplay(cctx.get())); + oxReturnError(s_scene->setupDisplay(*cctx)); return turbine::run(*tctx); } diff --git a/src/nostalgia/player/main.cpp b/src/nostalgia/player/main.cpp index 97737fe0..4e34b03b 100644 --- a/src/nostalgia/player/main.cpp +++ b/src/nostalgia/player/main.cpp @@ -2,6 +2,7 @@ * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ +#include #include #include @@ -11,8 +12,7 @@ #include "app.hpp" static ox::Error run(int argc, const char **argv) noexcept { - ox::trace::init(); -#ifdef OX_USE_STDLIB +#ifndef OX_BARE_METAL // GBA doesn't need the modules and calling this doubles the size of the // binary. nostalgia::registerKeelModules(); @@ -33,16 +33,19 @@ int WinMain() { #else int main(int argc, const char **argv) { #endif -#if defined(DEBUG) && !defined(OX_BARE_METAL) - ox::LoggerConn loggerConn; - const auto loggerErr = loggerConn.initConn("Nostalgia Player"); - if (loggerErr) { - oxErrf("Could not connect to logger: {} ({}:{})\n", toStr(loggerErr), loggerErr.file, loggerErr.line); - } else { - ox::trace::setLogger(&loggerConn); + 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 - const auto err = run(argc, argv); oxAssert(err, "Something went wrong..."); return static_cast(err); } diff --git a/src/nostalgia/tools/CMakeLists.txt b/src/nostalgia/tools/CMakeLists.txt index 5a966c16..028b5e63 100644 --- a/src/nostalgia/tools/CMakeLists.txt +++ b/src/nostalgia/tools/CMakeLists.txt @@ -4,7 +4,6 @@ target_link_libraries( nost-pack OxClArgs OxLogConn - Keel NostalgiaKeelModules ) diff --git a/src/nostalgia/tools/pack.cpp b/src/nostalgia/tools/pack.cpp index 164e76bf..4c6cdccb 100644 --- a/src/nostalgia/tools/pack.cpp +++ b/src/nostalgia/tools/pack.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -50,7 +51,6 @@ static ox::Error generateTypes(ox::TypeStore *ts) noexcept { } static ox::Error run(const ox::ClArgs &args) noexcept { - nostalgia::registerKeelModules(); const auto argSrc = args.getString("src", ""); const auto argRomBin = args.getString("rom-bin", ""); if (argSrc == "") { @@ -63,7 +63,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::FileSystem32 dst(ox::FileStore32(dstBuff.data(), dstBuff.size())); + ox::FileSystem32 dst(dstBuff); oxRequire(ctx, keel::init(ox::make_unique(argSrc), "nost-pack")); keel::TypeStore ts(ctx->rom.get(), "/.nostalgia/type_descriptors"); oxReturnError(generateTypes(&ts)); @@ -87,16 +87,8 @@ static ox::Error run(const ox::ClArgs &args) noexcept { } int main(int argc, const char **args) { - ox::trace::init(); -#ifdef DEBUG - ox::LoggerConn loggerConn; - const auto loggerErr = loggerConn.initConn("nost-pack"); - if (loggerErr) { - oxErrf("Could not connect to logger: {} ({}:{})\n", toStr(loggerErr), loggerErr.file, loggerErr.line); - } else { - ox::trace::setLogger(&loggerConn); - } -#endif + OX_INIT_DEBUG_LOGGER(loggerConn, "nost-pack") + nostalgia::registerKeelModules(); const auto err = run(ox::ClArgs(argc, args)); oxAssert(err, "pack failed"); return static_cast(err); diff --git a/src/studio/applib/include/studioapp/studioapp.hpp b/src/studio/applib/include/studioapp/studioapp.hpp index 8935a631..da02d82e 100644 --- a/src/studio/applib/include/studioapp/studioapp.hpp +++ b/src/studio/applib/include/studioapp/studioapp.hpp @@ -12,8 +12,15 @@ namespace studio { void registerModule(const studio::Module*) noexcept; +struct StudioOptions { + ox::String appName; + ox::String projectDataDir; +}; + +int main(StudioOptions&&); + int main( - const char *appName, + ox::CRStringView appName, ox::String projectDataDir, int argc, const char **argv); diff --git a/src/studio/applib/src/main.cpp b/src/studio/applib/src/main.cpp index b406b7b8..cc468a52 100644 --- a/src/studio/applib/src/main.cpp +++ b/src/studio/applib/src/main.cpp @@ -5,12 +5,14 @@ #include #include +#include #include #include #include #include #include +#include #include "studioapp.hpp" namespace studio { @@ -61,30 +63,26 @@ static ox::Error runApp( } int main( - const char *appName, + ox::CRStringView appName, ox::String projectDataDir, int, - const char **) { -#ifdef DEBUG - ox::LoggerConn loggerConn; - const auto loggerErr = loggerConn.initConn(appName); - if (loggerErr) { - oxErrf("Could not connect to logger: {}\n", toStr(loggerErr)); - } else { - ox::trace::setLogger(&loggerConn); - } -#endif - ox::trace::init(); - // run app + const char**) { + OX_INIT_DEBUG_LOGGER(loggerConn, appName) + // seed UUID generator const auto time = std::time(nullptr); ox::UUID::seedGenerator({ static_cast(time), static_cast(time << 1) }); + // run app const auto err = runApp(appName, std::move(projectDataDir), ox::UniquePtr(nullptr)); oxAssert(err, "Something went wrong..."); return static_cast(err); } +int main(StudioOptions &&opts, int argc = 0, const char **argv = nullptr) { + return main(opts.appName, std::move(opts.projectDataDir), argc, argv); +} + } diff --git a/src/studio/applib/src/newmenu.cpp b/src/studio/applib/src/newmenu.cpp index 7e172669..bbd1e695 100644 --- a/src/studio/applib/src/newmenu.cpp +++ b/src/studio/applib/src/newmenu.cpp @@ -57,7 +57,7 @@ void NewMenu::drawNewItemType(turbine::Context *ctx) noexcept { drawWindow(ctx, &m_open, [this] { auto items = ox_malloca(m_types.size() * sizeof(const char*), const char*, nullptr); for (auto i = 0u; const auto &im : m_types) { - items[i] = im->name.c_str(); + items.get()[i] = im->name.c_str(); ++i; } ImGui::ListBox("Item Type", &m_selectedType, items.get(), static_cast(m_types.size())); diff --git a/src/studio/applib/src/projectexplorer.cpp b/src/studio/applib/src/projectexplorer.cpp index 65079784..f8db74c7 100644 --- a/src/studio/applib/src/projectexplorer.cpp +++ b/src/studio/applib/src/projectexplorer.cpp @@ -11,7 +11,7 @@ namespace studio { static ox::Result> -buildProjectTreeModel(ProjectExplorer *explorer, ox::CRStringView name, ox::CRStringView path, ProjectTreeModel *parent) noexcept { +buildProjectTreeModel(ProjectExplorer *explorer, ox::String name, ox::CRStringView path, ProjectTreeModel *parent) noexcept { const auto fs = explorer->romFs(); oxRequire(stat, fs->stat(path)); auto out = ox::make_unique(explorer, name, parent); diff --git a/src/studio/applib/src/studioapp.cpp b/src/studio/applib/src/studioapp.cpp index b3e655a5..54a6d177 100644 --- a/src/studio/applib/src/studioapp.cpp +++ b/src/studio/applib/src/studioapp.cpp @@ -305,7 +305,7 @@ ox::Error StudioUI::openProject(ox::CRStringView path) noexcept { oxRequireM(fs, keel::loadRomFs(path)); oxReturnError(keel::setRomFs(&m_ctx->keelCtx, std::move(fs))); turbine::setWindowTitle(*m_ctx, ox::sfmt("{} - {}", m_ctx->keelCtx.appName, path)); - m_project = ox::make_unique(&m_ctx->keelCtx, path, m_projectDir); + m_project = ox::make_unique(&m_ctx->keelCtx, ox::String(path), m_projectDir); auto sctx = applicationData(*m_ctx); sctx->project = m_project.get(); m_project->fileAdded.connect(m_projectExplorer.get(), &ProjectExplorer::refreshProjectTreeModel); @@ -313,7 +313,7 @@ ox::Error StudioUI::openProject(ox::CRStringView path) noexcept { m_openFiles.clear(); m_editors.clear(); studio::editConfig(&m_ctx->keelCtx, [&](StudioConfig *config) { - config->projectPath = path; + config->projectPath = ox::String(path); config->openFiles.clear(); }); return m_projectExplorer->refreshProjectTreeModel(); @@ -324,7 +324,9 @@ ox::Error StudioUI::openFile(ox::CRStringView path) noexcept { } ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab) noexcept { - if (m_openFiles.contains(path)) { + // Warning: StringView to String + auto const pathStr = ox::String(path); + if (m_openFiles.contains(pathStr)) { for (auto &e : m_editors) { if (makeActiveTab && e->itemName() == path) { m_activeEditor = e.get(); @@ -334,7 +336,7 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab) } return OxError(0); } - oxRequire(ext, studio::fileExt(path)); + oxRequire(ext, studio::fileExt(path).to([](auto const&v) {return ox::String(v);})); // create Editor studio::BaseEditor *editor = nullptr; if (!m_editorMakers.contains(ext)) { @@ -363,7 +365,7 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab) } // save to config studio::editConfig(&m_ctx->keelCtx, [&](StudioConfig *config) { - if (!config->openFiles.contains(path)) { + if (!config->openFiles.contains(pathStr)) { config->openFiles.emplace_back(path); } }); diff --git a/src/studio/applib/src/studioapp.hpp b/src/studio/applib/src/studioapp.hpp index 2ca55a62..7ed9a00f 100644 --- a/src/studio/applib/src/studioapp.hpp +++ b/src/studio/applib/src/studioapp.hpp @@ -88,10 +88,4 @@ class StudioUI: public ox::SignalHandler { ox::Error closeFile(const ox::String &path) noexcept; }; -int main( - const char *appName, - ox::String projectDataDir, - [[maybe_unused]] int argc, - [[maybe_unused]] const char **argv); - } diff --git a/src/studio/modlib/src/project.cpp b/src/studio/modlib/src/project.cpp index 6d5d693d..3197b425 100644 --- a/src/studio/modlib/src/project.cpp +++ b/src/studio/modlib/src/project.cpp @@ -57,7 +57,8 @@ bool Project::exists(ox::CRStringView path) const noexcept { } const ox::Vector &Project::fileList(ox::CRStringView ext) noexcept { - return m_fileExtFileMap[ext]; + // Warning: StringView to String + return m_fileExtFileMap[ox::String(ext)]; } void Project::buildFileIndex() noexcept { @@ -80,7 +81,8 @@ void Project::indexFile(ox::CRStringView path) noexcept { if (err) { return; } - m_fileExtFileMap[ext].emplace_back(path); + // Warning: StringView to String + m_fileExtFileMap[ox::String(ext)].emplace_back(path); } ox::Error Project::writeBuff(const ox::StringView &path, const ox::Buffer &buff) noexcept { @@ -88,7 +90,8 @@ ox::Error Project::writeBuff(const ox::StringView &path, const ox::Buffer &buff) ox::Buffer outBuff; outBuff.reserve(buff.size() + HdrSz); ox::BufferWriter writer(&outBuff); - const auto [uuid, err] = m_ctx->pathToUuid.at(path); + // Warning: StringView to String + const auto [uuid, err] = m_ctx->pathToUuid.at(ox::String(path)); if (!err) { oxReturnError(keel::writeUuidHeader(writer, *uuid)); } diff --git a/src/turbine/glfw/clipboard.cpp b/src/turbine/glfw/clipboard.cpp index 894ad604..a0329e31 100644 --- a/src/turbine/glfw/clipboard.cpp +++ b/src/turbine/glfw/clipboard.cpp @@ -21,7 +21,7 @@ void setClipboardText(Context &ctx, ox::CRStringView text) noexcept { auto &gctx = static_cast(ctx); auto cstr = ox_malloca(text.bytes() + 1, char); ox_strncpy(cstr.get(), text.data(), text.bytes()); - glfwSetClipboardString(gctx.window, cstr); + glfwSetClipboardString(gctx.window, cstr.get()); } } diff --git a/src/turbine/glfw/gfx.cpp b/src/turbine/glfw/gfx.cpp index 12eda172..a096c38e 100644 --- a/src/turbine/glfw/gfx.cpp +++ b/src/turbine/glfw/gfx.cpp @@ -220,8 +220,9 @@ ox::Error initGfx(Context &ctx) noexcept { glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); auto cstr = ox_malloca(ctx.keelCtx.appName.bytes() + 1, char); ox_strncpy(cstr.get(), ctx.keelCtx.appName.data(), ctx.keelCtx.appName.bytes()); - constexpr auto Scale = 5; - gctx.window = glfwCreateWindow(240 * Scale, 160 * Scale, cstr, nullptr, nullptr); + //constexpr auto Scale = 5; + //gctx.window = glfwCreateWindow(240 * Scale, 160 * Scale, cstr, nullptr, nullptr); + gctx.window = glfwCreateWindow(868, 741, cstr.get(), nullptr, nullptr); if (gctx.window == nullptr) { return OxError(1, "Could not open GLFW window"); } @@ -250,7 +251,7 @@ void setWindowTitle(Context &ctx, ox::CRStringView title) noexcept { auto &gctx = glctx(ctx); auto cstr = ox_malloca(title.bytes() + 1, char); ox_strncpy(cstr.get(), title.data(), title.bytes()); - glfwSetWindowTitle(gctx.window, cstr); + glfwSetWindowTitle(gctx.window, cstr.get()); } void focusWindow(Context &ctx) noexcept {