Skip to content

Commit a50e77d

Browse files
committed
2D Crazy Bees bugfixes
* solve int8 overflow on "error2" (large fixtures) - based on cschill2020@2c87f7e * use fast int types where possible
1 parent 14efcce commit a50e77d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

wled00/FX.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6030,19 +6030,20 @@ static const char _data_FX_MODE_2DSPACESHIPS[] PROGMEM = "Spaceships@!,Blur;;!;2
60306030
// 2D Crazy Bees //
60316031
/////////////////////////
60326032
//// Crazy bees by stepko (c)12.02.21 [https://editor.soulmatelights.com/gallery/651-crazy-bees], adapted by Blaz Kristan (AKA blazoncek)
6033-
#define MAX_BEES 5
6033+
constexpr uint_fast16_t MAX_BEES = 5;
60346034
uint16_t mode_2Dcrazybees(void) {
60356035
if (!strip.isMatrix) return mode_static(); // not a 2D set-up
60366036

6037-
const uint16_t cols = SEGMENT.virtualWidth();
6038-
const uint16_t rows = SEGMENT.virtualHeight();
6037+
const uint_fast16_t cols = SEGMENT.virtualWidth();
6038+
const uint_fast16_t rows = SEGMENT.virtualHeight();
60396039

6040-
byte n = MIN(MAX_BEES, (rows * cols) / 256 + 1);
6040+
const byte n = min(MAX_BEES, (rows * cols) / 256 + 1);
60416041

60426042
typedef struct Bee {
60436043
uint8_t posX, posY, aimX, aimY, hue;
6044-
int8_t deltaX, deltaY, signX, signY, error;
6045-
void aimed(uint16_t w, uint16_t h) {
6044+
int8_t signX, signY;
6045+
int16_t deltaX, deltaY, error;
6046+
void aimed(uint_fast16_t w, uint_fast16_t h) {
60466047
if (!true) //WLEDMM SuperSync
60476048
random16_set_seed(strip.now);
60486049
aimX = random8(0, w);
@@ -6083,7 +6084,7 @@ uint16_t mode_2Dcrazybees(void) {
60836084
SEGMENT.addPixelColorXY(bee[i].aimX, bee[i].aimY - 1, CHSV(bee[i].hue, 255, 255));
60846085
if (bee[i].posX != bee[i].aimX || bee[i].posY != bee[i].aimY) {
60856086
SEGMENT.setPixelColorXY(bee[i].posX, bee[i].posY, CRGB(CHSV(bee[i].hue, 60, 255)));
6086-
int8_t error2 = bee[i].error * 2;
6087+
int_fast16_t error2 = bee[i].error * 2;
60876088
if (error2 > -bee[i].deltaY) {
60886089
bee[i].error -= bee[i].deltaY;
60896090
bee[i].posX += bee[i].signX;

0 commit comments

Comments
 (0)