From 10be8ef7ccaf56cc66afa04d5888034dd98d14a1 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Thu, 30 Apr 2020 06:41:30 +0200 Subject: [PATCH] There are now global instances of Window which don't have to be created and deleted all the time. --- include/Effect.h | 2 +- include/Window.h | 5 ++++- include/effect_blur2d.h | 2 +- include/effect_clock.h | 2 +- include/effect_dvd.h | 2 +- include/effect_dynamic.h | 2 +- include/effect_firework.h | 2 +- include/effect_marquee.h | 2 +- include/effect_tv_static.h | 2 +- src/Window.cpp | 7 +++---- src/effect_blur2d.cpp | 1 - src/effect_clock.cpp | 1 - src/effect_dvd.cpp | 1 - src/effect_dynamic.cpp | 1 - src/effect_firework.cpp | 1 - src/effect_gol.cpp | 3 +-- src/effect_lightspeed.cpp | 3 +-- src/effect_pixelclock.cpp | 3 +-- src/effect_snake.cpp | 3 +-- src/pitrix.cpp | 2 +- 20 files changed, 20 insertions(+), 27 deletions(-) diff --git a/include/Effect.h b/include/Effect.h index 4940a64..19672e2 100644 --- a/include/Effect.h +++ b/include/Effect.h @@ -6,7 +6,7 @@ class Effect { 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: virtual ~Effect() {}; virtual void loop(uint16_t ms) = 0; diff --git a/include/Window.h b/include/Window.h index eef0484..5d91976 100644 --- a/include/Window.h +++ b/include/Window.h @@ -14,10 +14,13 @@ private: 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); public: + static Window window_full; + static Window window_with_clock; + static Window window_clock; + const uint8_t x, y; const uint8_t width, height; uint16_t count; - static Window* getFullWindow(); Window(): Window(0, 0, LED_WIDTH, LED_HEIGHT) {}; Window(uint8_t x, uint8_t y) : Window(x, y, LED_WIDTH-x, LED_HEIGHT-y) {}; diff --git a/include/effect_blur2d.h b/include/effect_blur2d.h index d6311a3..3747b96 100644 --- a/include/effect_blur2d.h +++ b/include/effect_blur2d.h @@ -16,7 +16,7 @@ public: class Blur2DEffect : public Effect { private: - Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); + Window* window = &Window::window_with_clock; uint8_t _count; Blur2DBlob* _blobs; public: diff --git a/include/effect_clock.h b/include/effect_clock.h index fb0fc44..fec8ce0 100644 --- a/include/effect_clock.h +++ b/include/effect_clock.h @@ -7,7 +7,7 @@ class ClockEffect : public Effect { protected: - Window* window = new Window(0, LED_HEIGHT - 6, LED_WIDTH, 6); + Window* window = &Window::window_clock; public: virtual ~ClockEffect(); diff --git a/include/effect_dvd.h b/include/effect_dvd.h index e632700..8ae6fbf 100644 --- a/include/effect_dvd.h +++ b/include/effect_dvd.h @@ -3,7 +3,7 @@ class DvdEffect : public Effect { private: - Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); + Window* window = &Window::window_with_clock; saccum78 _x = 0; saccum78 _y = 0; int8_t _x_dir = 1; diff --git a/include/effect_dynamic.h b/include/effect_dynamic.h index 3cc0d97..dfc5de7 100644 --- a/include/effect_dynamic.h +++ b/include/effect_dynamic.h @@ -26,7 +26,7 @@ public: class BigDynamicEffect : public Effect { private: - Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); + Window* window = &Window::window_with_clock; public: void loop(uint16_t ms); ~BigDynamicEffect(); diff --git a/include/effect_firework.h b/include/effect_firework.h index 4f1b53d..3d6fa6c 100644 --- a/include/effect_firework.h +++ b/include/effect_firework.h @@ -34,7 +34,7 @@ public: class FireworkEffect : public Effect { private: - Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); + Window* window = &Window::window_with_clock; bool _skyburst = 0; accum88 _burst_x; diff --git a/include/effect_marquee.h b/include/effect_marquee.h index 57c4f69..2f31302 100644 --- a/include/effect_marquee.h +++ b/include/effect_marquee.h @@ -6,7 +6,7 @@ class MarqueeEffect : public Effect { private: - Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); + Window* window = &Window::window_with_clock; String _text = String("No text set +++ "); saccum78 _position = (window->width<<8); public: diff --git a/include/effect_tv_static.h b/include/effect_tv_static.h index eff81e9..5b0cb39 100644 --- a/include/effect_tv_static.h +++ b/include/effect_tv_static.h @@ -3,7 +3,7 @@ class TvStaticEffect : public Effect { private: - Window* _window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); + Window* _window = &Window::window_with_clock; public: ~TvStaticEffect(); void loop(uint16_t ms) override; diff --git a/src/Window.cpp b/src/Window.cpp index 2025076..875bf53 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -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; diff --git a/src/effect_blur2d.cpp b/src/effect_blur2d.cpp index 56a4899..179fcc6 100644 --- a/src/effect_blur2d.cpp +++ b/src/effect_blur2d.cpp @@ -45,5 +45,4 @@ void Blur2DEffect::_delete() { Blur2DEffect::~Blur2DEffect() { _delete(); - delete window; } diff --git a/src/effect_clock.cpp b/src/effect_clock.cpp index 0fb587e..a75805b 100644 --- a/src/effect_clock.cpp +++ b/src/effect_clock.cpp @@ -52,5 +52,4 @@ void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t yPo } ClockEffect::~ClockEffect() { - delete window; } diff --git a/src/effect_dvd.cpp b/src/effect_dvd.cpp index 6432034..d4216ec 100644 --- a/src/effect_dvd.cpp +++ b/src/effect_dvd.cpp @@ -47,5 +47,4 @@ DvdEffect::DvdEffect() { } DvdEffect::~DvdEffect() { - delete window; } diff --git a/src/effect_dynamic.cpp b/src/effect_dynamic.cpp index 21c2d48..fb92954 100644 --- a/src/effect_dynamic.cpp +++ b/src/effect_dynamic.cpp @@ -36,7 +36,6 @@ void MultiDynamicEffect::loop(uint16_t ms) { } BigDynamicEffect::~BigDynamicEffect() { - delete window; } void BigDynamicEffect::loop(uint16_t ms) { diff --git a/src/effect_firework.cpp b/src/effect_firework.cpp index ef37d2f..21ff5ad 100644 --- a/src/effect_firework.cpp +++ b/src/effect_firework.cpp @@ -176,7 +176,6 @@ FireworkEffect::FireworkEffect() { } FireworkEffect::~FireworkEffect() { - delete window; for (int i=0; iwindow = 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) { diff --git a/src/effect_lightspeed.cpp b/src/effect_lightspeed.cpp index 1984fe1..4a9167c 100644 --- a/src/effect_lightspeed.cpp +++ b/src/effect_lightspeed.cpp @@ -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(); } diff --git a/src/effect_pixelclock.cpp b/src/effect_pixelclock.cpp index 79aff2a..632f4c3 100644 --- a/src/effect_pixelclock.cpp +++ b/src/effect_pixelclock.cpp @@ -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) { diff --git a/src/effect_snake.cpp b/src/effect_snake.cpp index 08c999d..63ffc7e 100644 --- a/src/effect_snake.cpp +++ b/src/effect_snake.cpp @@ -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; } diff --git a/src/pitrix.cpp b/src/pitrix.cpp index 226899b..c24fd94 100644 --- a/src/pitrix.cpp +++ b/src/pitrix.cpp @@ -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