Major performance optimization

Now that we only care about the highest active layer, make sure we only do work
if that changed between two cycles. This way, `onActivate()` will take care of
the initial setup, `update()` will be an almost no-op for most of the time, and
`refreshAt()` will take care of refreshing keys other plugins may have changed.

This makes us about twice as fast as we were, on average.

Signed-off-by: Gergely Nagy <kaleidoscope@gergo.csillger.hu>
pull/389/head
Gergely Nagy 7 years ago
parent c3f9e2f148
commit a8fdd4b9c4

@ -28,6 +28,7 @@ namespace kaleidoscope {
uint16_t ColormapEffect::map_base_;
uint8_t ColormapEffect::max_layers_;
uint8_t ColormapEffect::last_highest_layer_;
void ColormapEffect::setup(void) {
Kaleidoscope.use(&::EEPROMSettings, &::LEDPaletteTheme);
@ -41,22 +42,20 @@ void ColormapEffect::max_layers(uint8_t max_) {
map_base_ = ::LEDPaletteTheme.reserveThemes(max_layers_);
}
void ColormapEffect::onActivate(void) {
last_highest_layer_ = Layer.top();
::LEDPaletteTheme.updateHandler(map_base_, last_highest_layer_);
}
void ColormapEffect::update(void) {
for (uint8_t l = 0; l < max_layers_; l++) {
if (!Layer.isOn(l))
continue;
if (Layer.top() == last_highest_layer_)
return;
::LEDPaletteTheme.updateHandler(map_base_, l);
}
onActivate();
}
void ColormapEffect::refreshAt(byte row, byte col) {
for (uint8_t l = 0; l < max_layers_; l++) {
if (!Layer.isOn(l))
continue;
::LEDPaletteTheme.refreshAt(map_base_, l, row, col);
}
::LEDPaletteTheme.refreshAt(map_base_, last_highest_layer_, row, col);
}
bool ColormapEffect::focusHook(const char *command) {

@ -32,10 +32,12 @@ class ColormapEffect : public LEDMode {
protected:
void setup(void) final;
void onActivate(void) final;
void update(void) final;
void refreshAt(byte row, byte col) final;
private:
static uint8_t last_highest_layer_;
static uint8_t max_layers_;
static uint16_t map_base_;
};

Loading…
Cancel
Save