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

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

View File

@ -6,7 +6,7 @@
class Effect { class Effect {
protected: protected:
Window* window = Window::getFullWindow(); // Use a full screen window per default. Window* window = &Window::window_full; // Use a full screen window per default.
public: public:
virtual ~Effect() {}; virtual ~Effect() {};
virtual void loop(uint16_t ms) = 0; virtual void loop(uint16_t ms) = 0;

View File

@ -14,10 +14,13 @@ private:
void _circle_point(int x0, int y0, int x1, int y1, CRGB* color); void _circle_point(int x0, int y0, int x1, int y1, CRGB* color);
void _subpixel_render(uint8_t x, uint8_t y, CRGB* color, SubpixelRenderingMode m); void _subpixel_render(uint8_t x, uint8_t y, CRGB* color, SubpixelRenderingMode m);
public: public:
static Window window_full;
static Window window_with_clock;
static Window window_clock;
const uint8_t x, y; const uint8_t x, y;
const uint8_t width, height; const uint8_t width, height;
uint16_t count; uint16_t count;
static Window* getFullWindow();
Window(): Window(0, 0, LED_WIDTH, LED_HEIGHT) {}; Window(): Window(0, 0, LED_WIDTH, LED_HEIGHT) {};
Window(uint8_t x, uint8_t y) : Window(x, y, LED_WIDTH-x, LED_HEIGHT-y) {}; Window(uint8_t x, uint8_t y) : Window(x, y, LED_WIDTH-x, LED_HEIGHT-y) {};

View File

@ -16,7 +16,7 @@ public:
class Blur2DEffect : public Effect { class Blur2DEffect : public Effect {
private: private:
Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); Window* window = &Window::window_with_clock;
uint8_t _count; uint8_t _count;
Blur2DBlob* _blobs; Blur2DBlob* _blobs;
public: public:

View File

@ -7,7 +7,7 @@
class ClockEffect : public Effect { class ClockEffect : public Effect {
protected: protected:
Window* window = new Window(0, LED_HEIGHT - 6, LED_WIDTH, 6); Window* window = &Window::window_clock;
public: public:
virtual ~ClockEffect(); virtual ~ClockEffect();

View File

@ -3,7 +3,7 @@
class DvdEffect : public Effect { class DvdEffect : public Effect {
private: private:
Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); Window* window = &Window::window_with_clock;
saccum78 _x = 0; saccum78 _x = 0;
saccum78 _y = 0; saccum78 _y = 0;
int8_t _x_dir = 1; int8_t _x_dir = 1;

View File

@ -26,7 +26,7 @@ public:
class BigDynamicEffect : public Effect { class BigDynamicEffect : public Effect {
private: private:
Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); Window* window = &Window::window_with_clock;
public: public:
void loop(uint16_t ms); void loop(uint16_t ms);
~BigDynamicEffect(); ~BigDynamicEffect();

View File

@ -34,7 +34,7 @@ public:
class FireworkEffect : public Effect { class FireworkEffect : public Effect {
private: private:
Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); Window* window = &Window::window_with_clock;
bool _skyburst = 0; bool _skyburst = 0;
accum88 _burst_x; accum88 _burst_x;

View File

@ -6,7 +6,7 @@
class MarqueeEffect : public Effect { class MarqueeEffect : public Effect {
private: private:
Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); Window* window = &Window::window_with_clock;
String _text = String("No text set +++ "); String _text = String("No text set +++ ");
saccum78 _position = (window->width<<8); saccum78 _position = (window->width<<8);
public: public:

View File

@ -3,7 +3,7 @@
class TvStaticEffect : public Effect { class TvStaticEffect : public Effect {
private: private:
Window* _window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); Window* _window = &Window::window_with_clock;
public: public:
~TvStaticEffect(); ~TvStaticEffect();
void loop(uint16_t ms) override; void loop(uint16_t ms) override;

View File

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

View File

@ -45,5 +45,4 @@ void Blur2DEffect::_delete() {
Blur2DEffect::~Blur2DEffect() { Blur2DEffect::~Blur2DEffect() {
_delete(); _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() { ClockEffect::~ClockEffect() {
delete window;
} }

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
#include "my_fastled.h" #include "my_fastled.h"
GolEffect::GolEffect() { 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]; _data = new uint8_t[this->window->count];
_old = new uint8_t[this->window->count]; _old = new uint8_t[this->window->count];
@ -26,7 +26,6 @@ void GolEffect::_initialize() {
GolEffect::~GolEffect() { GolEffect::~GolEffect() {
delete[] _data; delete[] _data;
delete[] _old; delete[] _old;
delete window;
} }
void GolEffect::loop(uint16_t ms) { void GolEffect::loop(uint16_t ms) {

View File

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

View File

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

View File

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

View File

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