CycleEffect now uses the ID of an effect within cycle_effects to prevent repeating an effect instead of comparing the objects.
This commit is contained in:
parent
46062945ff
commit
94687bab36
@ -7,6 +7,7 @@
|
||||
class CycleEffect : public Effect {
|
||||
private:
|
||||
Effect* effect;
|
||||
uint16_t effect_id = -1;
|
||||
unsigned long effectSince = 0;
|
||||
public:
|
||||
void changeEffect();
|
||||
|
@ -1,15 +1,13 @@
|
||||
#include "effect_cycle.h"
|
||||
|
||||
void CycleEffect::changeEffect() {
|
||||
Effect* new_effect;
|
||||
int new_id;
|
||||
do {
|
||||
new_id = random8(cycle_effects->size());
|
||||
new_effect = cycle_effects->get(new_id);
|
||||
} while (&new_effect == &effect);
|
||||
LOG("CycleEffect * Changing effect to ID "); LOGln(new_id);
|
||||
} while (new_id == effect_id);
|
||||
LOG("CycleEffect * Changing effect to #"); LOGln(new_id);
|
||||
if (effect) effect->stop();
|
||||
effect = new_effect;
|
||||
effect = cycle_effects->get(new_id);
|
||||
effect->start();
|
||||
effectSince = millis();
|
||||
}
|
||||
@ -20,6 +18,7 @@ void CycleEffect::start() {
|
||||
}
|
||||
|
||||
void CycleEffect::stop() {
|
||||
effect_id = -1;
|
||||
if (effect) effect->stop();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user