Skip to content

Commit

Permalink
Merge branch 'master' into handle
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Dec 10, 2023
2 parents dd44e7b + 8a4e266 commit e6e1874
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 49 deletions.
92 changes: 46 additions & 46 deletions VortexEngine/src/Menus/MenuList/Randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,40 @@ void Randomizer::onLongClick()
leaveMenu(true);
}

bool Randomizer::reRoll()
{
MAP_FOREACH_LED(m_targetLeds) {
// grab local reference to the target random context
Random &ctx = m_singlesRandCtx[pos];
if (m_flags & RANDOMIZE_PATTERN) {
// roll a new pattern
if (m_advanced) {
if (!rollCustomPattern(ctx, &m_previewMode, pos)) {
ERROR_LOG("Failed to roll new pattern");
return false;
}
} else {
if (!m_previewMode.setPattern(rollSingleLedPatternID(ctx), pos)) {
ERROR_LOG("Failed to roll new pattern");
return false;
}
}
}
if (m_flags & RANDOMIZE_COLORSET) {
// roll a new colorset
if (!m_previewMode.setColorset(rollColorset(ctx), pos)) {
ERROR_LOG("Failed to roll new colorset");
return false;
}
}
}
// initialize the mode with the new pattern and colorset
m_previewMode.init();
DEBUG_LOGF("Randomized Led %u set with randomization technique %u, %u colors, and Pattern number %u",
pos, randType, randomSet.numColors(), newPat);
return true;
}

void Randomizer::showRandomizationSelect()
{
// show iterating rainbow if they are randomizing color, otherwise 0 sat if they
Expand All @@ -145,6 +179,17 @@ void Randomizer::showRandomizationSelect()
Menus::showSelection();
}

PatternID Randomizer::rollSingleLedPatternID(Random &ctx)
{
PatternID newPat;
// the random range begin/end
do {
// continuously re-randomize the pattern so we don't get undesirable patterns
newPat = (PatternID)ctx.next8(PATTERN_SINGLE_FIRST, PATTERN_SINGLE_LAST);
} while (newPat == PATTERN_SOLID || newPat == PATTERN_RIBBON || newPat == PATTERN_MINIRIBBON);
return newPat;
}

Colorset Randomizer::rollColorset(Random &ctx)
{
Colorset randomSet;
Expand Down Expand Up @@ -194,7 +239,7 @@ Colorset Randomizer::rollColorset(Random &ctx)
return randomSet;
}

bool Randomizer::rollPattern(Random &ctx, Mode *pMode, LedPos pos)
bool Randomizer::rollCustomPattern(Random &ctx, Mode *pMode, LedPos pos)
{
PatternArgs args;
// pick a random type of randomizer to use then use
Expand Down Expand Up @@ -281,48 +326,3 @@ void Randomizer::crushPattern(Random &ctx, PatternArgs &outArgs)
uint8_t on = ctx.next8(1, 10); // on duration 1 -> 10
outArgs.init(on, off, gap, dash, group);
}

PatternID Randomizer::rollPatternID(Random &ctx)
{
PatternID newPat;
// the random range begin/end
do {
// continuously re-randomize the pattern so we don't get undesirable patterns
newPat = (PatternID)ctx.next8(PATTERN_SINGLE_FIRST, PATTERN_SINGLE_LAST);
} while (newPat == PATTERN_SOLID || newPat == PATTERN_RIBBON || newPat == PATTERN_MINIRIBBON);
return newPat;
}

bool Randomizer::reRoll()
{
MAP_FOREACH_LED(m_targetLeds) {
// grab local reference to the target random context
Random &ctx = m_singlesRandCtx[pos];
if (m_flags & RANDOMIZE_PATTERN) {
// roll a new pattern
if (m_advanced) {
if (!rollPattern(ctx, &m_previewMode, pos)) {
ERROR_LOG("Failed to roll new pattern");
return false;
}
} else {
if (!m_previewMode.setPattern(rollPatternID(ctx), pos)) {
ERROR_LOG("Failed to roll new pattern");
return false;
}
}
}
if (m_flags & RANDOMIZE_COLORSET) {
// roll a new colorset
if (!m_previewMode.setColorset(rollColorset(ctx), pos)) {
ERROR_LOG("Failed to roll new colorset");
return false;
}
}
}
// initialize the mode with the new pattern and colorset
m_previewMode.init();
DEBUG_LOGF("Randomized Led %u set with randomization technique %u, %u colors, and Pattern number %u",
pos, randType, randomSet.numColors(), newPat);
return true;
}
9 changes: 6 additions & 3 deletions VortexEngine/src/Menus/MenuList/Randomizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ class Randomizer : public Menu
// show the randomization type selection
void showRandomizationSelect();

PatternID rollSingleLedPatternID(Random &ctx);

// generate a random colorset with a random context
bool rollPattern(Random &ctx, Mode *pMode, LedPos pos);
PatternID rollPatternID(Random &ctx);
Colorset rollColorset(Random &ctx);

// random pattern generators
// roll a custom pattern by generating random arguments
bool rollCustomPattern(Random &ctx, Mode *pMode, LedPos pos);

// more specific random pattern generators that just generate patternargs
void traditionalPattern(Random &ctx, PatternArgs &outArgs);
void gapPattern(Random &ctx, PatternArgs &outArgs);
void dashPattern(Random &ctx, PatternArgs &outArgs);
Expand Down

0 comments on commit e6e1874

Please sign in to comment.