Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daniel/spark/next work #137

Merged
merged 6 commits into from
Dec 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'spark' into daniel/spark/next_work
Unreal-Dan committed Dec 12, 2023
commit 0c2d09a039d2f32ea40a011e07c24fe73aef7f68
110 changes: 11 additions & 99 deletions VortexEngine/src/Menus/MenuList/Randomizer.cpp
Original file line number Diff line number Diff line change
@@ -321,25 +321,6 @@ bool Randomizer::rollCustomPattern(Random &ctx, Mode *pMode, LedPos pos)
return pMode->setPattern(newPat, pos, &args);
}

bool Randomizer::rollMultiPattern(Random &ctx, Mode *pMode, LedPos pos)
{
PatternArgs args;
// pick a random type of randomizer to use then use
// the randomizer to generate a random pattern
uint8_t patternType = ctx.next8(PATTERN_MULTI_FIRST, PATTERN_MULTI_LAST);
PatternID newPat = PATTERN_STROBE;
// 1/3 chance to roll a blend pattern instead which will animate between
// colors instead of blinking each color in the set
if (!ctx.next8(0, 3)) {
newPat = PATTERN_BLEND;
// this is the number of blinks to a complementary color
args.arg7 = ctx.next8(0, 3);
// up to arg7 is filled now
args.numArgs = 7;
}
return pMode->setPattern(newPat, pos, &args);
}

void Randomizer::traditionalPattern(Random &ctx, PatternArgs &outArgs)
{
// call next8 explicitly in this order because the order they
@@ -381,84 +362,15 @@ void Randomizer::dashPattern(Random &ctx, PatternArgs &outArgs)

void Randomizer::crushPattern(Random &ctx, PatternArgs &outArgs)
{
outArgs.init(
ctx.next8(1, 10), // on duration 1 -> 10
ctx.next8(0, 10), // off duration 0 -> 5
ctx.next8(20, 40), // need gap 20 -> 40
0, // dash 0
ctx.next8(0, 8) // groupsize 0 to 8
);
}

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;
}

PatternID Randomizer::rollMultiPatternID(Random &ctx)
{
return (PatternID)ctx.next8(PATTERN_MULTI_FIRST, PATTERN_MULTI_LAST);
}

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;
}
}
}
if (m_targetLeds == MAP_LED(LED_MULTI)) {
if (m_flags & RANDOMIZE_PATTERN) {
// roll a new pattern
if (m_advanced) {
if (!rollMultiPattern(m_multiRandCtx, &m_previewMode, LED_MULTI)) {
ERROR_LOG("Failed to roll new pattern");
return false;
}
} else {
if (!m_previewMode.setPattern(rollMultiPatternID(m_multiRandCtx), LED_MULTI)) {
ERROR_LOG("Failed to roll new pattern");
return false;
}
}
}
if (m_flags & RANDOMIZE_COLORSET) {
// roll a new colorset
if (!m_previewMode.setColorset(rollColorset(m_multiRandCtx), LED_MULTI)) {
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;
// call next8 explicitly in this order because the order they
// are called is undefined when called as parameters to another function.
// ex: f(a,b,c) may call in the order a,b,c or c,b,a depending on compiler.
// So different compilers may produce different results,
// but like this it is explicit
uint8_t group = ctx.next8(0, 8); // groupsize 0 to 8
uint8_t dash = 0; // dash 0
uint8_t gap = ctx.next8(20, 40); // need gap 20 -> 40
uint8_t off = ctx.next8(0, 10); // off duration 0 -> 5
uint8_t on = ctx.next8(1, 10); // on duration 1 -> 10
outArgs.init(on, off, gap, dash, group);
}
4 changes: 0 additions & 4 deletions VortexEngine/src/Menus/MenuList/Randomizer.h
Original file line number Diff line number Diff line change
@@ -71,10 +71,6 @@ class Randomizer : public Menu
PatternID rollSingleLedPatternID(Random &ctx);

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

// roll a custom pattern by generating random arguments
You are viewing a condensed version of this merge commit. You can view the full changes here.