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

fixed argument offset and multi randomizer #138

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 23 additions & 2 deletions VortexEngine/src/Menus/MenuList/Randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ PatternID Randomizer::rollPatternID(Random &ctx)
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) {
Expand Down Expand Up @@ -304,9 +309,25 @@ bool Randomizer::reRoll()
}
}
}
if (m_targetLeds == MAP_LED(LED_MULTI)) {
if (m_flags & RANDOMIZE_PATTERN) {
// TODO: Advanced multi led patterns?
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);
//DEBUG_LOGF("Randomized Led %u set with randomization technique %u, %u colors, and Pattern number %u",
// pos, randType, randomSet.numColors(), newPat);
return true;
}
1 change: 1 addition & 0 deletions VortexEngine/src/Menus/MenuList/Randomizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Randomizer : public Menu
// generate a random colorset with a random context
bool rollPattern(Random &ctx, Mode *pMode, LedPos pos);
PatternID rollPatternID(Random &ctx);
PatternID rollMultiPatternID(Random &ctx);
Colorset rollColorset(Random &ctx);

// random pattern generators
Expand Down
4 changes: 2 additions & 2 deletions VortexEngine/src/Patterns/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ void Pattern::clearColorset()
}

#ifdef VORTEX_LIB
void Pattern::registerArg(const char *name, uint8_t argOffset)
void Pattern::registerArg(const char *name, arg_offset_t argOffset)
#else
void Pattern::registerArg(uint8_t argOffset)
void Pattern::registerArg(arg_offset_t argOffset)
#endif
{
if (m_numArgs >= MAX_PATTERN_ARGS) {
Expand Down
21 changes: 16 additions & 5 deletions VortexEngine/src/Patterns/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,22 @@
// the pattern is a multi-pattern
#define PATTERN_FLAG_MULTI (1<<0)

// and arg_offset_t is the distance from the base of the object
// to the desired argument, in slim vortex we only need a single byte
// but in multi-led patterns they can be a bit further in
#if VORTEX_SLIM == 1
typedef uint8_t arg_offset_t;
#else
typedef uint16_t arg_offset_t;
#endif

// macro to register args of a pattern
#ifdef VORTEX_LIB
#define REGISTER_ARG(arg) registerArg(#arg, (uint8_t)(((uintptr_t)&arg - (uintptr_t)this)));
#define REGISTER_ARG(arg) \
registerArg(#arg, (arg_offset_t)(((uintptr_t)&arg - (uintptr_t)this)));
#else
#define REGISTER_ARG(arg) registerArg((uint8_t)(((uintptr_t)&arg - (uintptr_t)this)));
#define REGISTER_ARG(arg) \
registerArg((arg_offset_t)(((uintptr_t)&arg - (uintptr_t)this)));
#endif

class ByteStream;
Expand Down Expand Up @@ -122,13 +133,13 @@ class Pattern
LedPos m_ledPos;

uint8_t m_numArgs;
uint8_t m_argList[MAX_PATTERN_ARGS];
arg_offset_t m_argList[MAX_PATTERN_ARGS];

#ifdef VORTEX_LIB
void registerArg(const char *name, uint8_t argOffset);
void registerArg(const char *name, arg_offset_t argOffset);
const char *m_argNameList[MAX_PATTERN_ARGS];
#else
void registerArg(uint8_t argOffset);
void registerArg(arg_offset_t argOffset);
#endif
};

Expand Down
312 changes: 156 additions & 156 deletions VortexEngine/tests/tests_general/0024_Randomize_Front_Bulb.test

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2,438 changes: 1,219 additions & 1,219 deletions VortexEngine/tests/tests_general/0026_Start_Auto-randomizer_Front_Bulb.test

Large diffs are not rendered by default.

2,616 changes: 1,308 additions & 1,308 deletions VortexEngine/tests/tests_general/0027_Stop_Auto-randomizer_Front_Bulb.test

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.