Skip to content

Commit

Permalink
fixed argument offset and multi randomizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Nov 17, 2023
1 parent 8e0c2db commit ac05291
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
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

0 comments on commit ac05291

Please sign in to comment.