transition optimization (small speedup)
* move "progress()" into FX.h so the compiler can inline it * removed redundant checks in currentBri()
This commit is contained in:
12
wled00/FX.h
12
wled00/FX.h
@@ -607,12 +607,18 @@ typedef struct Segment {
|
|||||||
// transition functions
|
// transition functions
|
||||||
void startTransition(uint16_t dur); // transition has to start before actual segment values change
|
void startTransition(uint16_t dur); // transition has to start before actual segment values change
|
||||||
void handleTransition(void);
|
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)
|
// WLEDMM method inlined for speed (its called at each setPixelColor)
|
||||||
[[gnu::hot]] inline uint8_t currentBri(uint8_t briNew, bool useCct = false) {
|
[[gnu::hot]] inline uint8_t currentBri(uint8_t briNew, bool useCct = false) {
|
||||||
uint32_t prog = (transitional && _t) ? progress() : 0xFFFFU;
|
uint32_t prog = progress();
|
||||||
if (transitional && _t && prog < 0xFFFFU) {
|
if (prog < 0xFFFFU) { // progress() < 0xFFFFU implies that _t is valid (see progress() function)
|
||||||
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
|
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
|
||||||
else return ((briNew * prog) + _t->_briT * (0xFFFFU - prog)) >> 16;
|
else return ((briNew * prog) + _t->_briT * (0xFFFFU - prog)) >> 16;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -451,6 +451,8 @@ void Segment::startTransition(uint16_t dur) {
|
|||||||
transitional = true; // setOption(SEG_OPTION_TRANSITIONAL, true);
|
transitional = true; // setOption(SEG_OPTION_TRANSITIONAL, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WLEDMM Segment::progress() is declared inline, see FX.h
|
||||||
|
#if 0
|
||||||
// transition progression between 0-65535
|
// transition progression between 0-65535
|
||||||
uint16_t IRAM_ATTR_YN Segment::progress() const {
|
uint16_t IRAM_ATTR_YN Segment::progress() const {
|
||||||
if (!transitional || !_t) return 0xFFFFU;
|
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;
|
if (timeNow - _t->_start > _t->_dur || _t->_dur == 0) return 0xFFFFU;
|
||||||
return (timeNow - _t->_start) * 0xFFFFU / _t->_dur;
|
return (timeNow - _t->_start) * 0xFFFFU / _t->_dur;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// WLEDMM Segment::currentBri() is declared inline, see FX.h
|
// WLEDMM Segment::currentBri() is declared inline, see FX.h
|
||||||
#if 0
|
#if 0
|
||||||
|
|||||||
Reference in New Issue
Block a user