Skip to content

Commit b26d1a6

Browse files
committed
Fixed a logical error in the spawn logic
1 parent 53ee3b9 commit b26d1a6

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

usermods/user_fx/user_fx.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ struct Walker {
13181318
break; // right
13191319
}
13201320
colorIndex = hw_random8();
1321-
active = true;
1321+
active = false;
13221322
}
13231323

13241324
// Logic to prevent overcrowding
@@ -1366,9 +1366,10 @@ static void trySpawn(Walker* walkers, uint8_t maxCount, uint16_t cols, uint16_t
13661366
const uint8_t minGap = 8;
13671367
for (uint8_t retry = 0; retry < 2; retry++) {
13681368
walkers[freeSlot].makeCandidate(cols, rows);
1369-
if (!walkers[freeSlot].hasConflict(walkers, maxCount, minGap)) return;
1369+
if (!walkers[freeSlot].hasConflict(walkers, maxCount, minGap)) {
1370+
walkers[freeSlot].active = true;
1371+
}
13701372
}
1371-
walkers[freeSlot].active = false;
13721373
}
13731374

13741375
static void mode_brushwalker_core(uint8_t triggerMode) {
@@ -1378,15 +1379,19 @@ static void mode_brushwalker_core(uint8_t triggerMode) {
13781379
uint32_t triggerGate = 0;
13791380
const uint16_t cols = SEG_W;
13801381
const uint16_t rows = SEG_H;
1381-
Walker* walkers = reinterpret_cast<Walker*>(SEGENV.data);
1382-
1383-
if (SEGENV.call == 0) {
1382+
if (SEGENV.call == 0) { // request status memory on first call
13841383
if (!SEGENV.allocateData(sizeof(Walker) * absoluteMaxWalkers)) FX_FALLBACK_STATIC;
1385-
for (uint8_t i = 0; i < absoluteMaxWalkers; i++) walkers[i].reset();
1386-
SEGMENT.fill(SEGCOLOR(1));
1387-
SEGENV.step = strip.now;
13881384
}
13891385

1386+
Walker* walkers = reinterpret_cast<Walker*>(SEGENV.data);
1387+
1388+
if (SEGENV.call == 0) { // init values on first call
1389+
for (uint8_t i = 0; i < absoluteMaxWalkers; i++) walkers[i].reset();
1390+
SEGMENT.fill(SEGCOLOR(1));
1391+
SEGENV.step = strip.now;
1392+
}
1393+
1394+
// timing
13901395
uint16_t interval = 8 + ((255 - SEGMENT.speed) >> 1);
13911396
if (strip.now - SEGENV.step < interval) return;
13921397
SEGENV.step = strip.now;
@@ -1411,10 +1416,11 @@ static void mode_brushwalker_core(uint8_t triggerMode) {
14111416
}
14121417

14131418
if (shouldSpawn) {
1414-
if( SEGENV.step < triggerGate ) {
1415-
triggerGate = SEGENV.step + 150; // de-clogging, avoid immediate respawn
1419+
if( SEGENV.step > triggerGate ) {
1420+
triggerGate = SEGENV.step + 150 + 255 - sensitivity; // de-clogging, avoid immediate respawn
14161421
trySpawn(walkers, maxWalkers, cols, rows);
14171422
}
1423+
shouldSpawn = false;
14181424
}
14191425

14201426
// Object-Oriented Update Loop
@@ -1435,7 +1441,7 @@ static void mode_brushwalker(void) { BrushWalkerFX::mode_brushwalker_core(0); }
14351441
// <Effect parameters>;<Colors>;<Palette>;<Flags>;<Defaults>
14361442
static const char _data_FX_MODE_BRUSHWALKER[] PROGMEM =
14371443
"Brush Walker@!,Spawn,Fade,Palette Step,Max "
1438-
"Walkers;,!;!;2;pal=11,sx=200,ix=64,c1=48,c2=24,c3=16";
1444+
"Walkers;,!;!;2;pal=11,sx=204,ix=64,c1=48,c2=24,c3=4";
14391445

14401446
/**
14411447
* @brief Brushwalker mode with audioreactive triggering - if a peak is
@@ -1448,7 +1454,7 @@ static void mode_brushwalker_ar(void) {
14481454

14491455
static const char _data_FX_MODE_BRUSHWALKER_AR[] PROGMEM =
14501456
"Brush Walker AR@!,Sensitivity,Fade,Palette Step,Max "
1451-
"Walkers;,!;!;2v;pal=11,sx=200,ix=64,c1=48,c2=24,c3=16";
1457+
"Walkers;,!;!;2v;pal=11,sx=204,ix=64,c1=48,c2=24,c3=4";
14521458

14531459
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
14541460
// END BrushWalker

0 commit comments

Comments
 (0)