Effect#loop now gets the time since the last run of the loop in ms. This enables

the effects to show animations that stay fluid independent of the current frame rate.
This commit is contained in:
2019-10-01 06:29:32 +02:00
parent 096d13438a
commit 382631d7d7
44 changed files with 78 additions and 67 deletions

View File

@ -43,22 +43,22 @@ void MatrixEffectColumn::restart(bool completely_random) {
speed = random8(EFFECT_MATRIX_SPEED_MIN, EFFECT_MATRIX_SPEED_MAX);
}
void MatrixEffectColumn::advance() {
void MatrixEffectColumn::advance(uint16_t ms) {
switch(_direction) {
case DIR_NORTH:
y-=speed;
y-=speed * ms;
if ((y>>8) > window->height && (y>>8) + length > window->height) running=false;
break;
case DIR_EAST:
x+=speed;
x+=speed * ms;
if ((x>>8) - length > window->width) running=false;
break;
case DIR_SOUTH:
y+=speed;
y+=speed * ms;
if ((y>>8) - length > window->height) running=false;
break;
case DIR_WEST:
x-=speed;
x-=speed * ms;
if ((x>>8) > window->width && (y>>8) + length > window->width) running=false;
break;
}
@ -79,14 +79,14 @@ void MatrixEffectColumn::draw() {
}
}
void MatrixEffectColumn::loop() {
void MatrixEffectColumn::loop(uint16_t ms) {
if (!running) {
if (random8() < 20) {
// Start the column again.
restart(false);
}
} else {
advance();
advance(ms);
draw();
}
}
@ -160,7 +160,7 @@ MatrixEffect::~MatrixEffect() {
delete[] _columns;
}
void MatrixEffect::loop() {
void MatrixEffect::loop(uint16_t ms) {
window->clear();
for (int i=0; i<window->width; i++) _columns[i]->loop();
for (int i=0; i<window->width; i++) _columns[i]->loop(ms);
}