FastLED 3.10.8
Loading...
Searching...
No Matches
engine_events.cpp.hpp
Go to the documentation of this file.
2#include "fl/stl/int.h"
3// Note: fl/stl/cstdio.h intentionally NOT included — workaround for
4// zackees/zccache#619 (Windows PCH path-spelling drift). The comment
5// above said "for printf debug" but no printf-debug call survived.
6#include "fl/stl/noexcept.h"
7#if !FL_PLATFORM_HAS_TINY_MEMORY
9#endif
10
11
12namespace fl {
13
14namespace {
15// FL_LINT_ALLOW_GLOBAL(frame-task callback registry backing)
17}
18
19// Explicitly define constructor and destructor
22
23
25
27#if FASTLED_HAS_ENGINE_EVENTS
28 EngineEvents *ptr = EngineEvents::getInstance();
29 const bool has_listener = ptr && ptr->_hasListener(this);
30 if (has_listener) {
31 // Warning, the listener should be removed by the subclass. If we are
32 // here then the subclass did not remove the listener and we are now in
33 // a partial state of destruction and the results may be undefined for
34 // multithreaded applications. However, for single threaded (the only
35 // option as of 2024, October) this will be ok.
36 ptr->_removeListener(this);
37 }
38#endif
39}
40
42 gFrameTaskListener = listener;
43}
44
46#if !FL_PLATFORM_HAS_TINY_MEMORY
48#endif
49#if FASTLED_HAS_ENGINE_EVENTS
50 EngineEvents::getInstance()->_onBeginFrame();
51#endif
52 if (gFrameTaskListener) {
53 gFrameTaskListener->onBeginFrame();
54 }
55}
56
58#if FASTLED_HAS_ENGINE_EVENTS
59 EngineEvents::getInstance()->_onEndFrame();
60#endif
61 if (gFrameTaskListener) {
62 gFrameTaskListener->onEndFrame();
63 }
64}
65
66#if FASTLED_HAS_ENGINE_EVENTS
67EngineEvents *EngineEvents::getInstance() FL_NO_EXCEPT {
69}
70#endif
71
72#if FASTLED_HAS_ENGINE_EVENTS
74 for (auto &item : mListeners) {
75 auto listener = item.listener;
76 listener->onPlatformPreLoop();
77 }
78 for (auto &item : mListeners) {
79 auto listener = item.listener;
80 listener->onPlatformPreLoop2();
81 }
82}
83
85 auto predicate = [listener](const Pair &pair) {
86 return pair.listener == listener;
87 };
88 return mListeners.find_if(predicate) != mListeners.end();
89}
90
91void EngineEvents::_addListener(Listener *listener, int priority) FL_NO_EXCEPT {
92 if (_hasListener(listener)) {
93 return;
94 }
95 for (auto it = mListeners.begin(); it != mListeners.end(); ++it) {
96 if (it->priority < priority) {
97 // this is now the highest priority in this spot.
98 EngineEvents::Pair pair = EngineEvents::Pair(listener, priority);
99 mListeners.insert(it, pair);
100 return;
101 }
102 }
103 EngineEvents::Pair pair = EngineEvents::Pair(listener, priority);
104 mListeners.push_back(pair);
105}
106
108 auto predicate = [listener](const Pair &pair) {
109 return pair.listener == listener;
110 };
111 auto it = mListeners.find_if(predicate);
112 if (it != mListeners.end()) {
113 mListeners.erase(it);
114 }
115}
116
118 // Make the copy of the listener list to avoid issues with listeners being
119 // added or removed during the loop.
120 ListenerList copy = mListeners;
121 for (auto &item : copy) {
122 auto listener = item.listener;
123 listener->onBeginFrame();
124 }
125}
126
128 // Make the copy of the listener list to avoid issues with listeners being
129 // added or removed during the loop.
130 ListenerList copy = mListeners;
131 for (auto &item : copy) {
132 auto listener = item.listener;
133 listener->onEndShowLeds();
134 }
135}
136
138 // Make the copy of the listener list to avoid issues with listeners being
139 // added or removed during the loop.
140 ListenerList copy = mListeners;
141 for (auto &item : copy) {
142 auto listener = item.listener;
143 listener->onEndFrame();
144 }
145}
146
147void EngineEvents::_onStripAdded(CLEDController *strip, fl::u32 num_leds) FL_NO_EXCEPT {
148 // Make the copy of the listener list to avoid issues with listeners being
149 // added or removed during the loop.
150 ListenerList copy = mListeners;
151 for (auto &item : copy) {
152 auto listener = item.listener;
153 listener->onStripAdded(strip, num_leds);
154 }
155}
156
158 const ScreenMap &screenmap) FL_NO_EXCEPT {
159 // Make the copy of the listener list to avoid issues with listeners being
160 // added or removed during the loop.
161 ListenerList copy = mListeners;
162 for (auto &item : copy) {
163 auto listener = item.listener;
164 listener->onCanvasUiSet(strip, screenmap);
165 }
166}
167
169 // Make the copy of the listener list to avoid issues with listeners being
170 // added or removed during the loop.
171 ListenerList copy = mListeners;
172 for (auto &item : copy) {
173 auto listener = item.listener;
174 listener->onExit();
175 }
176}
177
178#endif // FASTLED_HAS_ENGINE_EVENTS
179
180} // namespace fl
fl::ScreenMap screenmap
virtual ~Listener() FL_NO_EXCEPT
virtual void onBeginFrame() FL_NO_EXCEPT
virtual void onEndFrame() FL_NO_EXCEPT
void _addListener(Listener *listener, int priority) FL_NO_EXCEPT
static void onBeginFrame() FL_NO_EXCEPT
bool _hasListener(Listener *listener) FL_NO_EXCEPT
void _onPlatformPreLoop() FL_NO_EXCEPT
void _onCanvasUiSet(CLEDController *strip, const ScreenMap &xymap) FL_NO_EXCEPT
static void onEndFrame() FL_NO_EXCEPT
void _onExit() FL_NO_EXCEPT
static void setFrameTaskListener(Listener *listener) FL_NO_EXCEPT
EngineEvents() FL_NO_EXCEPT
void _onEndShowLeds() FL_NO_EXCEPT
void _onStripAdded(CLEDController *strip, fl::u32 num_leds) FL_NO_EXCEPT
void _onEndFrame() FL_NO_EXCEPT
void _onBeginFrame() FL_NO_EXCEPT
void _removeListener(Listener *listener) FL_NO_EXCEPT
static T & instance() FL_NO_EXCEPT
Definition singleton.h:41
fl::CLEDController CLEDController
Shared temporal-dither phase tracking.
FL_ALWAYS_INLINE void advanceDitherFrame() FL_NO_EXCEPT
Advance temporal dithering once per logical frame, not once per controller.
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
pair< T1, T2 > Pair
Definition pair.h:211
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NO_EXCEPT