From 044ef8b8186cc6693e2961d83525bfe944411fd9 Mon Sep 17 00:00:00 2001 From: shweet Date: Sun, 18 Jan 2026 16:32:33 -0500 Subject: [PATCH] remove unused fix --- CMakeLists.txt | 5 ++--- src/anm2/anm2_animations.cpp | 7 +++++-- src/document.cpp | 25 +++---------------------- src/imgui/window/events.cpp | 9 ++------- src/imgui/window/layers.cpp | 10 +++------- src/imgui/window/nulls.cpp | 9 ++------- src/imgui/window/sounds.cpp | 8 ++------ src/imgui/window/spritesheets.cpp | 8 ++------ src/storage.h | 1 - 9 files changed, 21 insertions(+), 61 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f82b0d..2ede4bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,12 +143,11 @@ if(WIN32) endif() endif() else() - target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic) if(CMAKE_BUILD_TYPE STREQUAL "Debug") - target_compile_options(${PROJECT_NAME} PRIVATE -O0 -pg) + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -O0 -pg) else() set(CMAKE_BUILD_TYPE "Release") - target_compile_options(${PROJECT_NAME} PRIVATE -Os) + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -O2) endif() target_link_libraries(${PROJECT_NAME} PRIVATE m) endif() diff --git a/src/anm2/anm2_animations.cpp b/src/anm2/anm2_animations.cpp index 2d79033..85c87ba 100644 --- a/src/anm2/anm2_animations.cpp +++ b/src/anm2/anm2_animations.cpp @@ -37,11 +37,14 @@ namespace anm2ed::anm2 element = element->NextSiblingElement("Animation")) { auto index = start + count; - animations.items.insert(animations.items.begin() + start + count, Animation(element)); + auto& animation = *animations.items.insert(animations.items.begin() + start + count, Animation(element)); + + for (auto& trigger : animation.triggers.frames) + if (!content.events.contains(trigger.eventID)) content.events[trigger.eventID]; + indices.insert(index); count++; } - return true; } else if (errorString) diff --git a/src/document.cpp b/src/document.cpp index a28c8de..4e4bd06 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -174,35 +174,20 @@ namespace anm2ed { hash_set(); - auto layers_set = [&]() { layer.unused = anm2.layers_unused(); }; - auto nulls_set = [&]() { null.unused = anm2.nulls_unused(); }; - auto events_set = [&]() - { - event.unused = anm2.events_unused(); - event.labels_set(anm2.event_labels_get(), anm2.event_ids_get()); - }; + auto events_set = [&]() { event.labels_set(anm2.event_labels_get(), anm2.event_ids_get()); }; auto animations_set = [&]() { animation.labels_set(anm2.animation_labels_get()); }; auto spritesheets_set = [&]() - { - spritesheet.unused = anm2.spritesheets_unused(); - spritesheet.labels_set(anm2.spritesheet_labels_get(), anm2.spritesheet_ids_get()); - }; + { spritesheet.labels_set(anm2.spritesheet_labels_get(), anm2.spritesheet_ids_get()); }; - auto sounds_set = [&]() - { - sound.unused = anm2.sounds_unused(); - sound.labels_set(anm2.sound_labels_get(), anm2.sound_ids_get()); - }; + auto sounds_set = [&]() { sound.labels_set(anm2.sound_labels_get(), anm2.sound_ids_get()); }; switch (type) { case LAYERS: - layers_set(); break; case NULLS: - nulls_set(); break; case EVENTS: events_set(); @@ -218,14 +203,10 @@ namespace anm2ed sounds_set(); break; case ITEMS: - layers_set(); - nulls_set(); spritesheets_set(); break; case ANIMATIONS: case ALL: - layers_set(); - nulls_set(); events_set(); spritesheets_set(); animations_set(); diff --git a/src/imgui/window/events.cpp b/src/imgui/window/events.cpp index fa5a760..fe49599 100644 --- a/src/imgui/window/events.cpp +++ b/src/imgui/window/events.cpp @@ -17,7 +17,6 @@ namespace anm2ed::imgui { auto& document = *manager.get(); auto& anm2 = document.anm2; - auto& unused = document.event.unused; auto& reference = document.event.reference; auto& selection = document.event.selection; @@ -45,6 +44,7 @@ namespace anm2ed::imgui auto remove_unused = [&]() { + auto unused = anm2.events_unused(); if (unused.empty()) return; auto behavior = [&]() @@ -57,7 +57,6 @@ namespace anm2ed::imgui anm2.content.events.erase(id); } - unused.clear(); }; DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_EVENTS), Document::EVENTS, behavior()); @@ -163,9 +162,7 @@ namespace anm2ed::imgui selection.size() == 1)) rename(); if (ImGui::MenuItem(localize.get(SHORTCUT_STRING_ADD), settings.shortcutAdd.c_str())) add(); - if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str(), false, - !unused.empty())) - remove_unused(); + if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str())) remove_unused(); ImGui::Separator(); @@ -187,10 +184,8 @@ namespace anm2ed::imgui set_item_tooltip_shortcut(localize.get(TOOLTIP_ADD_EVENT), settings.shortcutAdd); ImGui::SameLine(); - ImGui::BeginDisabled(unused.empty()); shortcut(manager.chords[SHORTCUT_REMOVE]); if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), widgetSize)) remove_unused(); - ImGui::EndDisabled(); set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_EVENTS), settings.shortcutRemove); } ImGui::End(); diff --git a/src/imgui/window/layers.cpp b/src/imgui/window/layers.cpp index 23e368c..5fda040 100644 --- a/src/imgui/window/layers.cpp +++ b/src/imgui/window/layers.cpp @@ -18,7 +18,6 @@ namespace anm2ed::imgui auto& document = *manager.get(); auto& anm2 = document.anm2; auto& reference = document.layer.reference; - auto& unused = document.layer.unused; auto& selection = document.layer.selection; auto& propertiesPopup = manager.layerPropertiesPopup; @@ -26,12 +25,13 @@ namespace anm2ed::imgui auto remove_unused = [&]() { + auto unused = anm2.layers_unused(); if (unused.empty()) return; + auto behavior = [&]() { for (auto& id : unused) anm2.content.layers.erase(id); - unused.clear(); }; DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_LAYERS), Document::LAYERS, behavior()); @@ -131,9 +131,7 @@ namespace anm2ed::imgui if (ImGui::MenuItem(localize.get(BASIC_PROPERTIES), nullptr, false, selection.size() == 1)) properties(*selection.begin()); if (ImGui::MenuItem(localize.get(BASIC_ADD), settings.shortcutAdd.c_str())) add(); - if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str(), false, - !unused.empty())) - remove_unused(); + if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str())) remove_unused(); ImGui::Separator(); @@ -155,10 +153,8 @@ namespace anm2ed::imgui set_item_tooltip_shortcut(localize.get(TOOLTIP_ADD_LAYER), settings.shortcutAdd); ImGui::SameLine(); - ImGui::BeginDisabled(unused.empty()); shortcut(manager.chords[SHORTCUT_REMOVE]); if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), widgetSize)) remove_unused(); - ImGui::EndDisabled(); set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_LAYERS), settings.shortcutRemove); } ImGui::End(); diff --git a/src/imgui/window/nulls.cpp b/src/imgui/window/nulls.cpp index 2db84a4..fd2ab4f 100644 --- a/src/imgui/window/nulls.cpp +++ b/src/imgui/window/nulls.cpp @@ -18,7 +18,6 @@ namespace anm2ed::imgui auto& document = *manager.get(); auto& anm2 = document.anm2; auto& reference = document.null.reference; - auto& unused = document.null.unused; auto& selection = document.null.selection; auto& propertiesPopup = manager.nullPropertiesPopup; @@ -26,12 +25,12 @@ namespace anm2ed::imgui auto remove_unused = [&]() { + auto unused = anm2.nulls_unused(); if (unused.empty()) return; auto behavior = [&]() { for (auto& id : unused) anm2.content.nulls.erase(id); - unused.clear(); }; DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_NULLS), Document::NULLS, behavior()); @@ -130,9 +129,7 @@ namespace anm2ed::imgui if (ImGui::MenuItem(localize.get(BASIC_PROPERTIES), nullptr, false, selection.size() == 1)) properties(*selection.begin()); if (ImGui::MenuItem(localize.get(BASIC_ADD), settings.shortcutAdd.c_str())) add(); - if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str(), false, - !unused.empty())) - remove_unused(); + if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str())) remove_unused(); ImGui::Separator(); @@ -154,10 +151,8 @@ namespace anm2ed::imgui set_item_tooltip_shortcut(localize.get(TOOLTIP_ADD_NULL), settings.shortcutAdd); ImGui::SameLine(); - ImGui::BeginDisabled(unused.empty()); shortcut(manager.chords[SHORTCUT_REMOVE]); if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), widgetSize)) remove_unused(); - ImGui::EndDisabled(); set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_NULLS), settings.shortcutRemove); } ImGui::End(); diff --git a/src/imgui/window/sounds.cpp b/src/imgui/window/sounds.cpp index 405b8f7..b016ccb 100644 --- a/src/imgui/window/sounds.cpp +++ b/src/imgui/window/sounds.cpp @@ -19,7 +19,6 @@ namespace anm2ed::imgui auto& document = *manager.get(); auto& anm2 = document.anm2; auto& reference = document.sound.reference; - auto& unused = document.sound.unused; auto& selection = document.sound.selection; auto style = ImGui::GetStyle(); @@ -55,13 +54,13 @@ namespace anm2ed::imgui auto remove_unused = [&]() { + auto unused = anm2.sounds_unused(); if (unused.empty()) return; auto behavior = [&]() { for (auto& id : unused) anm2.content.sounds.erase(id); - unused.clear(); }; DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_SOUNDS), Document::SOUNDS, behavior()); @@ -173,8 +172,7 @@ namespace anm2ed::imgui open_directory(anm2.content.sounds[*selection.begin()]); if (ImGui::MenuItem(localize.get(BASIC_ADD), settings.shortcutAdd.c_str())) add_open(); - if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str(), false, !unused.empty())) - remove_unused(); + if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str())) remove_unused(); if (ImGui::MenuItem(localize.get(BASIC_RELOAD), nullptr, false, !selection.empty())) reload(); if (ImGui::MenuItem(localize.get(BASIC_REPLACE), nullptr, false, selection.size() == 1)) replace_open(); @@ -295,11 +293,9 @@ namespace anm2ed::imgui ImGui::SameLine(); - ImGui::BeginDisabled(unused.empty()); imgui::shortcut(manager.chords[SHORTCUT_REMOVE]); if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), widgetSize)) remove_unused(); imgui::set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_SOUNDS), settings.shortcutRemove); - ImGui::EndDisabled(); ImGui::SameLine(); diff --git a/src/imgui/window/spritesheets.cpp b/src/imgui/window/spritesheets.cpp index d6c6662..df64977 100644 --- a/src/imgui/window/spritesheets.cpp +++ b/src/imgui/window/spritesheets.cpp @@ -24,7 +24,6 @@ namespace anm2ed::imgui auto& document = *manager.get(); auto& anm2 = document.anm2; auto& selection = document.spritesheet.selection; - auto& unused = document.spritesheet.unused; auto& reference = document.spritesheet.reference; auto style = ImGui::GetStyle(); @@ -40,6 +39,7 @@ namespace anm2ed::imgui auto remove_unused = [&]() { + auto unused = anm2.spritesheets_unused(); if (unused.empty()) return; auto behavior = [&]() @@ -53,7 +53,6 @@ namespace anm2ed::imgui std::make_format_args(id, pathString))); anm2.content.spritesheets.erase(id); } - unused.clear(); }; DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_SPRITESHEETS), Document::ALL, behavior()); @@ -189,8 +188,7 @@ namespace anm2ed::imgui open_directory(anm2.content.spritesheets[*selection.begin()]); if (ImGui::MenuItem(localize.get(BASIC_ADD), settings.shortcutAdd.c_str())) add_open(); - if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str(), false, !unused.empty())) - remove_unused(); + if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str())) remove_unused(); if (ImGui::MenuItem(localize.get(BASIC_RELOAD), nullptr, false, !selection.empty())) reload(); if (ImGui::MenuItem(localize.get(BASIC_REPLACE), nullptr, false, selection.size() == 1)) replace_open(); @@ -366,11 +364,9 @@ namespace anm2ed::imgui auto rowTwoWidgetSize = widget_size_with_row_get(2); - ImGui::BeginDisabled(unused.empty()); shortcut(manager.chords[SHORTCUT_REMOVE]); if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), rowTwoWidgetSize)) remove_unused(); set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_SPRITESHEETS), settings.shortcutRemove); - ImGui::EndDisabled(); ImGui::SameLine(); diff --git a/src/storage.h b/src/storage.h index 219e6d5..dd0dc04 100644 --- a/src/storage.h +++ b/src/storage.h @@ -9,7 +9,6 @@ namespace anm2ed public: int reference{-1}; int hovered{-1}; - std::set unused{}; std::vector labelsString{}; std::vector labels{}; std::vector ids{};