From 838d7e6a8613c4c868535bb975ab73bac9e5f1b1 Mon Sep 17 00:00:00 2001 From: profezzorn Date: Sun, 13 Oct 2024 03:07:35 -0500 Subject: [PATCH] save some memory --- modes/color_menues.h | 22 +++++++++++----------- modes/default_spec.h | 1 + modes/menu_list.h | 33 +++++++++++++++++---------------- modes/preset_modes.h | 24 ++++++++++++------------ modes/settings_menues.h | 2 ++ modes/style_option_modes.h | 28 ++++++++++++++-------------- 6 files changed, 57 insertions(+), 53 deletions(-) diff --git a/modes/color_menues.h b/modes/color_menues.h index 31087e009..518012300 100644 --- a/modes/color_menues.h +++ b/modes/color_menues.h @@ -7,9 +7,8 @@ #include "menu_list.h" namespace mode { - + // Note, the currently edited color is stored in ShowColorStyle. - template struct ColorHueMode : public SPEC::SmoothWraparoundMode { public: @@ -133,10 +132,10 @@ Color16 menu_selected_color; template struct SelectColorEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SayCopyColor(); } - void select(int entry) override { + void select(int entry) { getSL()->SaySelect(); menu_selected_color = ShowColorStyle::getColor(); } @@ -144,21 +143,21 @@ struct SelectColorEntry : public MenuEntry { template struct UseSelectedColorEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SayPasteColor(); } - void select(int entry) override { + void select(int entry) { getSL()->SaySelect(); ShowColorStyle::SetColor(menu_selected_color); } -}; +}; template struct ResetColorToDefaultEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SayResetToDefaultColor(); } - void select(int entry) override { + void select(int entry) { getSL()->SaySelect(); LSPtr builtin = style_parser.ResetArguments(GetStyle(menu_current_blade)); char argspace[32]; @@ -173,10 +172,10 @@ struct ResetColorToDefaultEntry : public MenuEntry { template struct SaveColorMenuEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SaySave(); } - void select(int entry) override { + void select(int entry) { getSL()->SaySelect(); getPtr()->save(); popMode(); @@ -194,6 +193,7 @@ using ColorSelectList = MenuEntryMenu>; + template struct ColorSelectMode : public ColorSelectList> { diff --git a/modes/default_spec.h b/modes/default_spec.h index a62c40ae3..f516d0067 100644 --- a/modes/default_spec.h +++ b/modes/default_spec.h @@ -56,6 +56,7 @@ struct DefaultMenuSpec { typedef mode::SelectArgNumber SelectArgNumber; typedef mode::ColorSelectMode SelectArgColor; + typedef mode::FileColorMenu FileColorMenu; typedef mode::ColorHueMode ColorHueMode; typedef mode::ColorBrightnessMode ColorBrightnessMode; typedef mode::ColorRedMode ColorRedMode; diff --git a/modes/menu_list.h b/modes/menu_list.h index b29dc9097..1d67c5e06 100644 --- a/modes/menu_list.h +++ b/modes/menu_list.h @@ -14,20 +14,21 @@ namespace mode { struct MenuEntry { static const int size = 1; - virtual void say(int entry) = 0; - virtual void select(int entry) = 0; + // Should have, but vtables take up space. + // void say(int entry) + // void select(int entry) = 0; }; struct NullEntry : public MenuEntry { static const int size = 0; - virtual void say(int entry) {}; - virtual void select(int entry) {}; + void say(int entry) {}; + void select(int entry) {}; }; template struct SubMenuEntry : public MenuEntry { - void say(int entry) override { SOUND::say(); } - void select(int entry) override { pushMode(); } + void say(int entry) { SOUND::say(); } + void select(int entry) { pushMode(); } }; // All blades @@ -35,11 +36,11 @@ template struct SubMenuAllBladeEntry : public MenuEntry { static const int size = NUM_BLADES; int blade(int entry) { return entry + 1; } - void say(int entry) override { + void say(int entry) { SOUND::say(); getSL()->SayWhole(blade(entry)); } - void select(int entry) override { + void select(int entry) { menu_current_blade = blade(entry); pushMode(); } @@ -50,12 +51,12 @@ template struct SubMenuBladeEntry : public MenuEntry { static const int size = sizeof(BLADEARRAY::data); int blade(int entry) { return BLADEARRAY::data[entry]; } - void say(int entry) override { + void say(int entry) { SOUND::say(); getSL()->SayBlade(); getSL()->SayWhole(blade(entry)); } - void select(int entry) override { + void select(int entry) { menu_current_blade = blade(entry); pushMode(); } @@ -64,8 +65,8 @@ struct SubMenuBladeEntry : public MenuEntry { // CMD and arg are expected to be ByteArray. template struct CommandMenuEntry : public MenuEntry { - void say(int entry) override { SOUND::say(); } - void select(int entry) override { + void say(int entry) { SOUND::say(); } + void select(int entry) { SoundLibrary::tSelect::say(); CommandParser::DoParse(CMD::str, ARG::str); } @@ -74,18 +75,18 @@ struct CommandMenuEntry : public MenuEntry { template struct PopMenuEntry : public MenuEntry { - void say(int entry) override { SOUND::say(); } - void select(int entry) override { popMode(); } + void say(int entry) { SOUND::say(); } + void select(int entry) { popMode(); } }; template struct MenuEntryConcat : public MenuEntry { static const int size = A::size + B::size; - void say(int entry) override { + void say(int entry) { if (entry < A::size) a_.say(entry); else b_.say(entry - A::size); } - void select(int entry) override { + void select(int entry) { if (entry < A::size) a_.select(entry); else b_.select(entry - A::size); } diff --git a/modes/preset_modes.h b/modes/preset_modes.h index fff23a05c..39c131b83 100644 --- a/modes/preset_modes.h +++ b/modes/preset_modes.h @@ -52,10 +52,10 @@ using ConfirmCommandMenuEntry = template struct DeletePresetMenuEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SayDeletePreset(); } - void select(int entry) override { + void select(int entry) { getSL()->SaySelect(); CommandParser::DoParse("delete_preset", nullptr); popMode(); @@ -70,10 +70,10 @@ int menu_selected_preset = -1; template struct MovePresetUpEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SayMovePresetUp(); } - void select(int entry) override { + void select(int entry) { menu_selected_preset = -1; int pos = prop_GetPresetPosition(); if (pos > 0) { @@ -87,10 +87,10 @@ struct MovePresetUpEntry : public MenuEntry { template struct MovePresetDownEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SayMovePresetDown(); } - void select(int entry) override { + void select(int entry) { menu_selected_preset = -1; int pos = prop_GetPresetPosition(); // Check if this is the last preset. @@ -124,10 +124,10 @@ struct MovePresetToBeginningEntry : public MenuEntry { template struct SelectPresetEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SaySelectPreset(); } - void select(int entry) override { + void select(int entry) { menu_selected_preset = prop_GetPresetPosition(); getSL()->SaySelect(); } @@ -135,10 +135,10 @@ struct SelectPresetEntry : public MenuEntry { template struct InsertSelectedPresetEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SayInsertSelectedPreset(); } - void select(int entry) override { + void select(int entry) { int from_pos = menu_selected_preset; if (from_pos == -1) { getSL()->SayNoPresetSelected(); @@ -162,11 +162,11 @@ struct InsertSelectedPresetEntry : public MenuEntry { template struct SelectStyleMenuEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SayEditStyle(); getSL()->SayWhole(BLADE); } - void select(int entry) override { + void select(int entry) { menu_current_blade = BLADE; pushMode(); } diff --git a/modes/settings_menues.h b/modes/settings_menues.h index 2b728a5d9..1869c9a0f 100644 --- a/modes/settings_menues.h +++ b/modes/settings_menues.h @@ -10,6 +10,7 @@ void prop_SetClashThreshold(int clash_threshold); int prop_GetBladeLength(int blade); int prop_GetMaxBladeLength(int blade); void prop_SetBladeLength(int blade, int len); +void prop_UpdateStyle(); namespace mode { @@ -88,6 +89,7 @@ struct ChangeBladeLengthBlade1 : public SPEC::MenuBase { } void mode_deactivate() { showlen_.Stop(blade()); + prop_UpdateStyle(); } void say() override { getSL()->SayWhole(getLength()); diff --git a/modes/style_option_modes.h b/modes/style_option_modes.h index b355f2d35..a80d80d4b 100644 --- a/modes/style_option_modes.h +++ b/modes/style_option_modes.h @@ -137,10 +137,10 @@ int menu_selected_blade; // Select this style for copying. template struct SelectStyleEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SaySelectStyle(); } - void select(int entry) override { + void select(int entry) { menu_selected_preset = prop_GetPresetPosition(); menu_selected_blade = menu_current_blade; getSL()->SaySelect(); @@ -149,10 +149,10 @@ struct SelectStyleEntry : public MenuEntry { template struct ApplyColorsFromSelectedStyleEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SayApplyColorsFromSelectedStyle(); } - void select(int entry) override { + void select(int entry) { if (menu_selected_preset == -1) { getSL()->SayNoStyleSelected(); return; @@ -167,11 +167,11 @@ struct ApplyColorsFromSelectedStyleEntry : public MenuEntry { }; template -struct ApplyColorsToAllBladesEntry : public MenuEntry { - void say(int entry) override { +struct ApplyColorsToAllBladesEntry : public MenuEntry { + void say(int entry) { getSL()->SayApplyColorsToAllBlades(); } - void select(int entry) override { + void select(int entry) { getSL()->SaySelect(); const char* FROM = GetStyle(menu_selected_blade); for (int b = 1; b <= NUM_BLADES; b++) { @@ -183,10 +183,10 @@ struct ApplyColorsToAllBladesEntry : public MenuEntry { template struct ApplyStyleArumentsFromSelectedStyleEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SayApplyStyleSettingsFromSelectedStyle(); } - void select(int entry) override { + void select(int entry) { if (menu_selected_preset == -1) { getSL()->SayNoStyleSelected(); return; @@ -202,11 +202,11 @@ struct ApplyStyleArumentsFromSelectedStyleEntry : public MenuEntry { template -struct ResetColorsEntry : public MenuEntry { - void say(int entry) override { +struct ResetColorsEntry : public MenuEntry { + void say(int entry) { getSL()->SayResetColors(); } - void select(int entry) override { + void select(int entry) { if (menu_selected_preset == -1) { getSL()->SayNoStyleSelected(); return; @@ -221,10 +221,10 @@ struct ResetColorsEntry : public MenuEntry { template struct ResetStyleArgumentsEntry : public MenuEntry { - void say(int entry) override { + void say(int entry) { getSL()->SayResetStyleSettings(); } - void select(int entry) override { + void select(int entry) { CurrentPreset preset; preset.Load(menu_selected_preset); const char* TO = GetStyle(menu_selected_blade);