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:
Fabian Schlenz 2019-06-04 05:56:33 +02:00
parent 46062945ff
commit 94687bab36
2 changed files with 5 additions and 5 deletions

View File

@ -7,6 +7,7 @@
class CycleEffect : public Effect { class CycleEffect : public Effect {
private: private:
Effect* effect; Effect* effect;
uint16_t effect_id = -1;
unsigned long effectSince = 0; unsigned long effectSince = 0;
public: public:
void changeEffect(); void changeEffect();

View File

@ -1,15 +1,13 @@
#include "effect_cycle.h" #include "effect_cycle.h"
void CycleEffect::changeEffect() { void CycleEffect::changeEffect() {
Effect* new_effect;
int new_id; int new_id;
do { do {
new_id = random8(cycle_effects->size()); new_id = random8(cycle_effects->size());
new_effect = cycle_effects->get(new_id); } while (new_id == effect_id);
} while (&new_effect == &effect); LOG("CycleEffect * Changing effect to #"); LOGln(new_id);
LOG("CycleEffect * Changing effect to ID "); LOGln(new_id);
if (effect) effect->stop(); if (effect) effect->stop();
effect = new_effect; effect = cycle_effects->get(new_id);
effect->start(); effect->start();
effectSince = millis(); effectSince = millis();
} }
@ -20,6 +18,7 @@ void CycleEffect::start() {
} }
void CycleEffect::stop() { void CycleEffect::stop() {
effect_id = -1;
if (effect) effect->stop(); if (effect) effect->stop();
} }