From ed4f0e1f2bd5228ce35242a993fe2c95a554b27a Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 22 Apr 2024 23:40:48 -0500 Subject: [PATCH] [nostalgia,olympic] Replace oxIgnoreError with std::ignore --- developer-handbook.md | 15 ++++++--------- src/nostalgia/modules/core/src/gba/panic.cpp | 4 ++-- .../src/studio/paletteeditor/paletteeditor.cpp | 14 +++++++------- .../tilesheeteditor/tilesheeteditor-imgui.cpp | 2 +- src/olympic/keel/include/keel/assetmanager.hpp | 6 +++--- src/olympic/keel/src/keel.cpp | 2 +- src/olympic/studio/applib/src/studioapp.cpp | 4 ++-- src/olympic/studio/modlib/src/filedialog_nfd.cpp | 2 +- src/olympic/studio/modlib/src/task.cpp | 4 ++-- src/olympic/studio/modlib/src/undostack.cpp | 2 +- src/olympic/turbine/src/glfw/gfx.cpp | 2 +- 11 files changed, 27 insertions(+), 30 deletions(-) diff --git a/developer-handbook.md b/developer-handbook.md index a6142053..58ebe616 100644 --- a/developer-handbook.md +++ b/developer-handbook.md @@ -222,8 +222,8 @@ int caller2() { ``` Lastly, there are a few macros available to help in passing ```ox::Error```s -back up the call stack, ```oxReturnError```, ```oxThrowError```, -```oxIgnoreError```, and ```oxRequire```. +back up the call stack, ```oxReturnError```, ```oxThrowError```, and +```oxRequire```. ```oxReturnError``` is by far the more helpful of the two. ```oxReturnError``` will return an ```ox::Error``` if it is not 0 and @@ -232,13 +232,10 @@ Because exceptions are disabled for GBA builds and thus cannot be used in the engine, ```oxThrowError``` is only really useful at the boundary between engine libraries and Nostalgia Studio. -```oxIgnoreError``` does what it says, it ignores the error. Since ```ox::Error``` is always nodiscard, you must do something with them. -In extremely rare cases, you may not have anything you can do with them or you -may know the code will never fail in that particular instance. -This should be used very sparingly. -At the time of this writing, it has only been used 4 times in 20,000 lines of -code. +In rare cases, you may not have anything you can do with them or you may know +the code will never fail in that particular instance. +This should be used sparingly. ```cpp @@ -257,7 +254,7 @@ ox::Error engineCode() noexcept { void anyCode() { auto [val, err] = foo(1); - oxIgnoreError(err); + std::ignore = err; doStuff(val); } ``` diff --git a/src/nostalgia/modules/core/src/gba/panic.cpp b/src/nostalgia/modules/core/src/gba/panic.cpp index d5c55378..4a6bc235 100644 --- a/src/nostalgia/modules/core/src/gba/panic.cpp +++ b/src/nostalgia/modules/core/src/gba/panic.cpp @@ -28,8 +28,8 @@ void panic(const char *file, int line, const char *panicMsg, ox::Error const&err ox::heapmgr::initHeap(HEAP_BEGIN, HEAP_END); auto tctx = turbine::init(keel::loadRomFs("").unwrap(), "Nostalgia").unwrap(); auto ctx = init(*tctx).unwrap(); - oxIgnoreError(initGfx(*ctx, {})); - oxIgnoreError(initConsole(*ctx)); + std::ignore = initGfx(*ctx, {}); + std::ignore = initConsole(*ctx); setBgStatus(*ctx, 0, true); clearBg(*ctx, 0); ox::BString<23> serr = "Error code: "; diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp index 9ecc7e6a..e81b55c9 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp @@ -19,7 +19,7 @@ void AddPageCommand::redo() noexcept { } void AddPageCommand::undo() noexcept { - oxIgnoreError(m_pal.pages.erase(static_cast(m_pal.pages.size() - 1))); + std::ignore = m_pal.pages.erase(static_cast(m_pal.pages.size() - 1)); } @@ -43,7 +43,7 @@ void DuplicatePageCommand::redo() noexcept { void DuplicatePageCommand::undo() noexcept { m_page = std::move(m_pal.pages[m_dstIdx]); - oxIgnoreError(m_pal.pages.erase(static_cast(m_dstIdx))); + std::ignore = m_pal.pages.erase(static_cast(m_dstIdx)); } size_t DuplicatePageCommand::insertIdx() const noexcept { @@ -62,7 +62,7 @@ int RemovePageCommand::commandId() const noexcept { void RemovePageCommand::redo() noexcept { m_page = std::move(m_pal.pages[m_idx]); - oxIgnoreError(m_pal.pages.erase(static_cast(m_idx))); + std::ignore = m_pal.pages.erase(static_cast(m_idx)); } void RemovePageCommand::undo() noexcept { @@ -86,7 +86,7 @@ void AddColorCommand::redo() noexcept { } void AddColorCommand::undo() noexcept { - oxIgnoreError(m_pal->pages[m_page].erase(static_cast(m_idx))); + std::ignore = m_pal->pages[m_page].erase(static_cast(m_idx)); } @@ -102,7 +102,7 @@ int RemoveColorCommand::commandId() const noexcept { } void RemoveColorCommand::redo() noexcept { - oxIgnoreError(m_pal->pages[m_page].erase(static_cast(m_idx))); + std::ignore = m_pal->pages[m_page].erase(static_cast(m_idx)); } void RemoveColorCommand::undo() noexcept { @@ -171,8 +171,8 @@ void MoveColorCommand::undo() noexcept { void MoveColorCommand::moveColor(int idx, int offset) noexcept { const auto c = m_pal->pages[m_page][static_cast(idx)]; - oxIgnoreError(m_pal->pages[m_page].erase(static_cast(idx))); + std::ignore = m_pal->pages[m_page].erase(static_cast(idx)); m_pal->pages[m_page].insert(static_cast(idx + offset), c); } -} \ No newline at end of file +} diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp index 5dc4d83f..306379d2 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp @@ -81,7 +81,7 @@ TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::CRSt m_tctx(m_sctx.tctx), m_view(m_sctx, path, *undoStack()), m_model(m_view.model()) { - oxIgnoreError(setPaletteSelection()); + std::ignore = setPaletteSelection(); // connect signal/slots undoStack()->changeTriggered.connect(this, &TileSheetEditorImGui::markUnsavedChanges); m_subsheetEditor.inputSubmitted.connect(this, &TileSheetEditorImGui::updateActiveSubsheet); diff --git a/src/olympic/keel/include/keel/assetmanager.hpp b/src/olympic/keel/include/keel/assetmanager.hpp index f27667f1..b13a131e 100644 --- a/src/olympic/keel/include/keel/assetmanager.hpp +++ b/src/olympic/keel/include/keel/assetmanager.hpp @@ -117,7 +117,7 @@ class AssetRef: public ox::SignalHandler { } if (m_ctr) { m_ctr->decRefs(); - oxIgnoreError(m_ctr->updated.disconnectObject(this)); + std::ignore = m_ctr->updated.disconnectObject(this); } m_ctr = h.m_ctr; if (m_ctr) { @@ -133,11 +133,11 @@ class AssetRef: public ox::SignalHandler { } if (m_ctr) { m_ctr->decRefs(); - oxIgnoreError(m_ctr->updated.disconnectObject(this)); + std::ignore = m_ctr->updated.disconnectObject(this); } m_ctr = h.m_ctr; if (m_ctr) { - oxIgnoreError(m_ctr->updated.disconnectObject(&h)); + std::ignore = m_ctr->updated.disconnectObject(&h); m_ctr->updated.connect(this, &AssetRef::emitUpdated); } h.m_ctr = nullptr; diff --git a/src/olympic/keel/src/keel.cpp b/src/olympic/keel/src/keel.cpp index 1a5700da..894069f0 100644 --- a/src/olympic/keel/src/keel.cpp +++ b/src/olympic/keel/src/keel.cpp @@ -11,7 +11,7 @@ ox::Error init( ox::UPtr &&fs, ox::CRStringView appName) noexcept { ctx.appName = appName; - oxIgnoreError(setRomFs(ctx, std::move(fs))); + std::ignore = setRomFs(ctx, std::move(fs)); #ifndef OX_BARE_METAL auto const&mods = modules(); for (auto &mod : mods) { diff --git a/src/olympic/studio/applib/src/studioapp.cpp b/src/olympic/studio/applib/src/studioapp.cpp index d4b86789..22daae19 100644 --- a/src/olympic/studio/applib/src/studioapp.cpp +++ b/src/olympic/studio/applib/src/studioapp.cpp @@ -417,10 +417,10 @@ ox::Error StudioUI::closeFile(ox::CRStringView path) noexcept { if (!m_openFiles.contains(path)) { return {}; } - oxIgnoreError(m_openFiles.erase(std::remove(m_openFiles.begin(), m_openFiles.end(), path))); + std::ignore = m_openFiles.erase(std::remove(m_openFiles.begin(), m_openFiles.end(), path)); // save to config studio::editConfig(keelCtx(m_ctx), [&](StudioConfig *config) { - oxIgnoreError(config->openFiles.erase(std::remove(config->openFiles.begin(), config->openFiles.end(), path))); + std::ignore = config->openFiles.erase(std::remove(config->openFiles.begin(), config->openFiles.end(), path)); }); return {}; } diff --git a/src/olympic/studio/modlib/src/filedialog_nfd.cpp b/src/olympic/studio/modlib/src/filedialog_nfd.cpp index dfdcd92a..e0102591 100644 --- a/src/olympic/studio/modlib/src/filedialog_nfd.cpp +++ b/src/olympic/studio/modlib/src/filedialog_nfd.cpp @@ -24,7 +24,7 @@ static ox::Result toResult(nfdresult_t r, NFD::UniquePathN const&pat ox::String out; for (auto i = 0u; path.get()[i]; ++i) { auto const c = static_cast(path.get()[i]); - oxIgnoreError(out.append(&c, 1)); + std::ignore = out.append(&c, 1); } return out; } diff --git a/src/olympic/studio/modlib/src/task.cpp b/src/olympic/studio/modlib/src/task.cpp index e25cacf8..b966ee32 100644 --- a/src/olympic/studio/modlib/src/task.cpp +++ b/src/olympic/studio/modlib/src/task.cpp @@ -9,13 +9,13 @@ namespace studio { void TaskRunner::update(turbine::Context &ctx) noexcept { - oxIgnoreError(m_tasks.erase(std::remove_if(m_tasks.begin(), m_tasks.end(), [&](ox::UPtr &t) { + std::ignore = m_tasks.erase(std::remove_if(m_tasks.begin(), m_tasks.end(), [&](ox::UPtr &t) { auto const done = t->update(ctx) == TaskState::Done; if (done) { t->finished.emit(); } return done; - }))); + })); } void TaskRunner::add(Task &task) noexcept { diff --git a/src/olympic/studio/modlib/src/undostack.cpp b/src/olympic/studio/modlib/src/undostack.cpp index 7468774b..ac5031bf 100644 --- a/src/olympic/studio/modlib/src/undostack.cpp +++ b/src/olympic/studio/modlib/src/undostack.cpp @@ -12,7 +12,7 @@ bool UndoCommand::mergeWith(UndoCommand const*) noexcept { void UndoStack::push(ox::UPtr &&cmd) noexcept { for (auto const i = m_stackIdx; i < m_stack.size();) { - oxIgnoreError(m_stack.erase(i)); + std::ignore = m_stack.erase(i); } cmd->redo(); redoTriggered.emit(cmd.get()); diff --git a/src/olympic/turbine/src/glfw/gfx.cpp b/src/olympic/turbine/src/glfw/gfx.cpp index c6e531f6..e3883f26 100644 --- a/src/olympic/turbine/src/glfw/gfx.cpp +++ b/src/olympic/turbine/src/glfw/gfx.cpp @@ -22,7 +22,7 @@ void addDrawer(Context &ctx, Drawer *cd) noexcept { void removeDrawer(Context &ctx, Drawer *cd) noexcept { for (auto i = 0u; i < ctx.drawers.size(); ++i) { if (ctx.drawers[i] == cd) { - oxIgnoreError(ctx.drawers.erase(i)); + std::ignore = ctx.drawers.erase(i); break; } }