From 74eacc179434dfe786bae80a99990df85d08d452 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 17 Jul 2022 07:58:19 +0200 Subject: [PATCH] Clean up color cycling (#4966) --- Source/engine/palette.cpp | 53 ++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/Source/engine/palette.cpp b/Source/engine/palette.cpp index dd9430ac4..657b64cea 100644 --- a/Source/engine/palette.cpp +++ b/Source/engine/palette.cpp @@ -144,7 +144,7 @@ void CycleColors(int from, int to) /** * @brief Cycle the given range of colors in the palette in reverse direction * @param from First color index of the range - * @param to First color index of the range + * @param to Last color index of the range */ void CycleColorsReverse(int from, int to) { @@ -375,44 +375,41 @@ void palette_update_caves() palette_update(0, 31); } +/** + * @brief Cycle the lava every other frame, and glow every frame + * Lava has 15 colors and the glow 16, so the full animation has 240 frames before it loops + */ void palette_update_crypt() { - static int laveDelay = 0; - static int glowDelay = 0; + static bool delayLava = false; - if (laveDelay > 1) { + if (!delayLava) { CycleColorsReverse(1, 15); - laveDelay = 0; - } else { - laveDelay++; - } - if (glowDelay > 0) { - CycleColorsReverse(16, 31); - palette_update(0, 31); - glowDelay++; - } else { - glowDelay = 1; + delayLava = false; } + + CycleColorsReverse(16, 31); + palette_update(0, 31); + delayLava = !delayLava; } +/** + * @brief Cycle the pond waves and bubles colors every 3rd frame + * Bubles have 8 colors and waves 7, so the full animation has 56 frames before it loops + */ void palette_update_hive() { - static int waveDelay = 0; - static int bubbleDelay = 0; + static uint8_t delay = 0; - if (waveDelay == 2) { - CycleColorsReverse(1, 8); - waveDelay = 0; - } else { - waveDelay++; - } - if (bubbleDelay == 2) { - CycleColorsReverse(9, 15); - palette_update(0, 15); - bubbleDelay = 0; - } else { - bubbleDelay++; + if (delay != 2) { + delay++; + return; } + + CycleColorsReverse(1, 8); + CycleColorsReverse(9, 15); + palette_update(0, 15); + delay = 0; } void palette_update_quest_palette(int n)