From 8daf9d9ffb1b2ba2d612de607bda41bdea8233ff Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 16 Jan 2025 18:26:10 +0100 Subject: [PATCH] transition optimization (small speedup) * move "progress()" into FX.h so the compiler can inline it * removed redundant checks in currentBri() --- wled00/FX.h | 12 +++++++++--- wled00/FX_fcn.cpp | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index b942ac8e3f..27cf5f6d62 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -607,12 +607,18 @@ typedef struct Segment { // transition functions void startTransition(uint16_t dur); // transition has to start before actual segment values change void handleTransition(void); - uint16_t progress(void) const; //transition progression between 0-65535 + // transition progression between 0-65535 + [[gnu::hot]] inline uint16_t progress() const { + if (!transitional || !_t) return 0xFFFFU; + unsigned long timeNow = millis(); + if (timeNow - _t->_start > _t->_dur || _t->_dur == 0) return 0xFFFFU; + return (timeNow - _t->_start) * 0xFFFFU / _t->_dur; + } // WLEDMM method inlined for speed (its called at each setPixelColor) [[gnu::hot]] inline uint8_t currentBri(uint8_t briNew, bool useCct = false) { - uint32_t prog = (transitional && _t) ? progress() : 0xFFFFU; - if (transitional && _t && prog < 0xFFFFU) { + uint32_t prog = progress(); + if (prog < 0xFFFFU) { // progress() < 0xFFFFU implies that _t is valid (see progress() function) if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16; else return ((briNew * prog) + _t->_briT * (0xFFFFU - prog)) >> 16; } else { diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 7581f81066..a6e127e154 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -451,6 +451,8 @@ void Segment::startTransition(uint16_t dur) { transitional = true; // setOption(SEG_OPTION_TRANSITIONAL, true); } +// WLEDMM Segment::progress() is declared inline, see FX.h +#if 0 // transition progression between 0-65535 uint16_t IRAM_ATTR_YN Segment::progress() const { if (!transitional || !_t) return 0xFFFFU; @@ -458,6 +460,7 @@ uint16_t IRAM_ATTR_YN Segment::progress() const { if (timeNow - _t->_start > _t->_dur || _t->_dur == 0) return 0xFFFFU; return (timeNow - _t->_start) * 0xFFFFU / _t->_dur; } +#endif // WLEDMM Segment::currentBri() is declared inline, see FX.h #if 0