Skip to content

Commit

Permalink
save some memory
Browse files Browse the repository at this point in the history
  • Loading branch information
profezzorn committed Oct 13, 2024
1 parent 05995be commit 838d7e6
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 53 deletions.
22 changes: 11 additions & 11 deletions modes/color_menues.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#include "menu_list.h"

namespace mode {

// Note, the currently edited color is stored in ShowColorStyle.

template<class SPEC>
struct ColorHueMode : public SPEC::SmoothWraparoundMode {
public:
Expand Down Expand Up @@ -133,32 +132,32 @@ Color16 menu_selected_color;

template<class SPEC>
struct SelectColorEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SayCopyColor();
}
void select(int entry) override {
void select(int entry) {
getSL<SPEC>()->SaySelect();
menu_selected_color = ShowColorStyle::getColor();
}
};

template<class SPEC>
struct UseSelectedColorEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SayPasteColor();
}
void select(int entry) override {
void select(int entry) {
getSL<SPEC>()->SaySelect();
ShowColorStyle::SetColor(menu_selected_color);
}
};
};

template<class SPEC>
struct ResetColorToDefaultEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SayResetToDefaultColor();
}
void select(int entry) override {
void select(int entry) {
getSL<SPEC>()->SaySelect();
LSPtr<char> builtin = style_parser.ResetArguments(GetStyle(menu_current_blade));
char argspace[32];
Expand All @@ -173,10 +172,10 @@ struct ResetColorToDefaultEntry : public MenuEntry {

template<class SPEC, class MENU>
struct SaveColorMenuEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SaySave();
}
void select(int entry) override {
void select(int entry) {
getSL<SPEC>()->SaySelect();
getPtr<MENU>()->save();
popMode();
Expand All @@ -194,6 +193,7 @@ using ColorSelectList = MenuEntryMenu<SPEC,
typename SPEC::UseSelectedColorEntry,
typename SPEC::ResetColorToDefaultEntry,
SaveColorMenuEntry<SPEC, MENU>>;


template<class SPEC>
struct ColorSelectMode : public ColorSelectList<SPEC, ColorSelectMode<SPEC>> {
Expand Down
1 change: 1 addition & 0 deletions modes/default_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct DefaultMenuSpec {
typedef mode::SelectArgNumber<SPEC> SelectArgNumber;
typedef mode::ColorSelectMode<SPEC> SelectArgColor;

typedef mode::FileColorMenu<SPEC> FileColorMenu;
typedef mode::ColorHueMode<SPEC> ColorHueMode;
typedef mode::ColorBrightnessMode<SPEC> ColorBrightnessMode;
typedef mode::ColorRedMode<SPEC> ColorRedMode;
Expand Down
33 changes: 17 additions & 16 deletions modes/menu_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,33 @@ 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<class SUBMENU, class SOUND>
struct SubMenuEntry : public MenuEntry {
void say(int entry) override { SOUND::say(); }
void select(int entry) override { pushMode<SUBMENU>(); }
void say(int entry) { SOUND::say(); }
void select(int entry) { pushMode<SUBMENU>(); }
};

// All blades
template<class SPEC, class SUBMENU, class SOUND>
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<SPEC>()->SayWhole(blade(entry));
}
void select(int entry) override {
void select(int entry) {
menu_current_blade = blade(entry);
pushMode<SUBMENU>();
}
Expand All @@ -50,12 +51,12 @@ template<class SPEC, class SUBMENU, class SOUND, class BLADEARRAY>
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<SPEC>()->SayBlade();
getSL<SPEC>()->SayWhole(blade(entry));
}
void select(int entry) override {
void select(int entry) {
menu_current_blade = blade(entry);
pushMode<SUBMENU>();
}
Expand All @@ -64,8 +65,8 @@ struct SubMenuBladeEntry : public MenuEntry {
// CMD and arg are expected to be ByteArray.
template<class CMD, class ARG, class SOUND>
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);
}
Expand All @@ -74,18 +75,18 @@ struct CommandMenuEntry : public MenuEntry {

template<class SOUND>
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<class A, class B>
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);
}
Expand Down
24 changes: 12 additions & 12 deletions modes/preset_modes.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ using ConfirmCommandMenuEntry =

template<class SPEC>
struct DeletePresetMenuEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SayDeletePreset();
}
void select(int entry) override {
void select(int entry) {
getSL<SPEC>()->SaySelect();
CommandParser::DoParse("delete_preset", nullptr);
popMode();
Expand All @@ -70,10 +70,10 @@ int menu_selected_preset = -1;

template<class SPEC>
struct MovePresetUpEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SayMovePresetUp();
}
void select(int entry) override {
void select(int entry) {
menu_selected_preset = -1;
int pos = prop_GetPresetPosition();
if (pos > 0) {
Expand All @@ -87,10 +87,10 @@ struct MovePresetUpEntry : public MenuEntry {

template<class SPEC>
struct MovePresetDownEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->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.
Expand Down Expand Up @@ -124,21 +124,21 @@ struct MovePresetToBeginningEntry : public MenuEntry {

template<class SPEC>
struct SelectPresetEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SaySelectPreset();
}
void select(int entry) override {
void select(int entry) {
menu_selected_preset = prop_GetPresetPosition();
getSL<SPEC>()->SaySelect();
}
};

template<class SPEC>
struct InsertSelectedPresetEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SayInsertSelectedPreset();
}
void select(int entry) override {
void select(int entry) {
int from_pos = menu_selected_preset;
if (from_pos == -1) {
getSL<SPEC>()->SayNoPresetSelected();
Expand All @@ -162,11 +162,11 @@ struct InsertSelectedPresetEntry : public MenuEntry {

template<class SPEC, int BLADE>
struct SelectStyleMenuEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SayEditStyle();
getSL<SPEC>()->SayWhole(BLADE);
}
void select(int entry) override {
void select(int entry) {
menu_current_blade = BLADE;
pushMode<typename SPEC::EditStyleMenu>();
}
Expand Down
2 changes: 2 additions & 0 deletions modes/settings_menues.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -88,6 +89,7 @@ struct ChangeBladeLengthBlade1 : public SPEC::MenuBase {
}
void mode_deactivate() {
showlen_.Stop(blade());
prop_UpdateStyle();
}
void say() override {
getSL<SPEC>()->SayWhole(getLength());
Expand Down
28 changes: 14 additions & 14 deletions modes/style_option_modes.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ int menu_selected_blade;
// Select this style for copying.
template<class SPEC>
struct SelectStyleEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SaySelectStyle();
}
void select(int entry) override {
void select(int entry) {
menu_selected_preset = prop_GetPresetPosition();
menu_selected_blade = menu_current_blade;
getSL<SPEC>()->SaySelect();
Expand All @@ -149,10 +149,10 @@ struct SelectStyleEntry : public MenuEntry {

template<class SPEC>
struct ApplyColorsFromSelectedStyleEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SayApplyColorsFromSelectedStyle();
}
void select(int entry) override {
void select(int entry) {
if (menu_selected_preset == -1) {
getSL<SPEC>()->SayNoStyleSelected();
return;
Expand All @@ -167,11 +167,11 @@ struct ApplyColorsFromSelectedStyleEntry : public MenuEntry {
};

template<class SPEC>
struct ApplyColorsToAllBladesEntry : public MenuEntry {
void say(int entry) override {
struct ApplyColorsToAllBladesEntry : public MenuEntry {
void say(int entry) {
getSL<SPEC>()->SayApplyColorsToAllBlades();
}
void select(int entry) override {
void select(int entry) {
getSL<SPEC>()->SaySelect();
const char* FROM = GetStyle(menu_selected_blade);
for (int b = 1; b <= NUM_BLADES; b++) {
Expand All @@ -183,10 +183,10 @@ struct ApplyColorsToAllBladesEntry : public MenuEntry {

template<class SPEC>
struct ApplyStyleArumentsFromSelectedStyleEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SayApplyStyleSettingsFromSelectedStyle();
}
void select(int entry) override {
void select(int entry) {
if (menu_selected_preset == -1) {
getSL<SPEC>()->SayNoStyleSelected();
return;
Expand All @@ -202,11 +202,11 @@ struct ApplyStyleArumentsFromSelectedStyleEntry : public MenuEntry {


template<class SPEC>
struct ResetColorsEntry : public MenuEntry {
void say(int entry) override {
struct ResetColorsEntry : public MenuEntry {
void say(int entry) {
getSL<SPEC>()->SayResetColors();
}
void select(int entry) override {
void select(int entry) {
if (menu_selected_preset == -1) {
getSL<SPEC>()->SayNoStyleSelected();
return;
Expand All @@ -221,10 +221,10 @@ struct ResetColorsEntry : public MenuEntry {

template<class SPEC>
struct ResetStyleArgumentsEntry : public MenuEntry {
void say(int entry) override {
void say(int entry) {
getSL<SPEC>()->SayResetStyleSettings();
}
void select(int entry) override {
void select(int entry) {
CurrentPreset preset;
preset.Load(menu_selected_preset);
const char* TO = GetStyle(menu_selected_blade);
Expand Down

0 comments on commit 838d7e6

Please sign in to comment.