Skip to content

Commit

Permalink
transition optimization (small speedup)
Browse files Browse the repository at this point in the history
* move "progress()" into FX.h so the compiler can inline it
* removed redundant checks in  currentBri()
  • Loading branch information
softhack007 committed Jan 16, 2025
1 parent bd31dd2 commit 8daf9d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,16 @@ 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;
unsigned long timeNow = millis();
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
Expand Down

0 comments on commit 8daf9d9

Please sign in to comment.