There are now global instances of Window which don't have to be created and deleted all the time.

This commit is contained in:
2020-04-30 06:41:30 +02:00
parent 9de77349e8
commit 10be8ef7cc
20 changed files with 20 additions and 27 deletions

View File

@ -1,10 +1,9 @@
#include "Window.h"
#include "functions.h"
Window* Window::getFullWindow() {
static Window win;
return &win;
}
Window Window::window_full = Window();
Window Window::window_with_clock = Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
Window Window::window_clock = Window(0, LED_HEIGHT-6, LED_WIDTH, 6);
void Window::setPixel(uint8_t x, uint8_t y, CRGB* color) {
if (x>=this->width || y>=this->height) return;

View File

@ -45,5 +45,4 @@ void Blur2DEffect::_delete() {
Blur2DEffect::~Blur2DEffect() {
_delete();
delete window;
}

View File

@ -52,5 +52,4 @@ void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t yPo
}
ClockEffect::~ClockEffect() {
delete window;
}

View File

@ -47,5 +47,4 @@ DvdEffect::DvdEffect() {
}
DvdEffect::~DvdEffect() {
delete window;
}

View File

@ -36,7 +36,6 @@ void MultiDynamicEffect::loop(uint16_t ms) {
}
BigDynamicEffect::~BigDynamicEffect() {
delete window;
}
void BigDynamicEffect::loop(uint16_t ms) {

View File

@ -176,7 +176,6 @@ FireworkEffect::FireworkEffect() {
}
FireworkEffect::~FireworkEffect() {
delete window;
for (int i=0; i<settings.effects.firework.sparks; i++) {
delete _sparks[i];
}

View File

@ -2,7 +2,7 @@
#include "my_fastled.h"
GolEffect::GolEffect() {
this->window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
this->window = &Window::window_with_clock;
_data = new uint8_t[this->window->count];
_old = new uint8_t[this->window->count];
@ -26,7 +26,6 @@ void GolEffect::_initialize() {
GolEffect::~GolEffect() {
delete[] _data;
delete[] _old;
delete window;
}
void GolEffect::loop(uint16_t ms) {

View File

@ -4,12 +4,11 @@
#include "prototypes.h"
LightspeedEffect::LightspeedEffect() {
window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
window = &Window::window_with_clock;
_init();
}
LightspeedEffect::~LightspeedEffect() {
delete window;
_delete();
}

View File

@ -2,7 +2,7 @@
#include "ntp.h"
PixelClockEffect::PixelClockEffect() {
window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
window = &Window::window_with_clock;
_color_seconds = new CRGB(0x00FF00);
_color_minutes = new CRGB(0xFFFF00);
}
@ -10,7 +10,6 @@ PixelClockEffect::PixelClockEffect() {
PixelClockEffect::~PixelClockEffect() {
delete _color_seconds;
delete _color_minutes;
delete window;
}
void PixelClockEffect::loop(uint16_t ms) {

View File

@ -2,7 +2,7 @@
#include "functions.h"
SnakeEffect::SnakeEffect() {
window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
window = &Window::window_with_clock;
_pixels = window->width * window->height;
_map = new uint8_t[_pixels];
_init();
@ -25,7 +25,6 @@ void SnakeEffect::_init() {
}
SnakeEffect::~SnakeEffect() {
delete window;
delete _map;
}

View File

@ -73,7 +73,7 @@ void loop() {
EVERY_N_SECONDS(1) {
Serial.print("Core * Waiting for OTA... "); Serial.println(starting_up);
starting_up--;
Window* w = Window::getFullWindow();
Window* w = &Window::window_full;
CRGB color(0xFF0000);
w->clear();
for (int i=0; i<starting_up; i++) {