Remove NONUNITY

Expand soundSim
Tetrix optimisation
This commit is contained in:
Blaž Kristan 2022-08-31 14:24:02 +02:00
parent bfe16bb254
commit da0da4c75e
7 changed files with 839 additions and 840 deletions

View File

@ -3470,9 +3470,9 @@ static const char _data_FX_MODE_DRIP[] PROGMEM = "Drip@Gravity,# of drips;!,!;!;
typedef struct Tetris {
float pos;
float speed;
uint32_t col;
uint16_t aux0; // 2D-fication of SEGENV.aux0 (brick size)
uint16_t aux1; // 2D-fication of SEGENV.aux1 (stack size)
uint8_t col; // color index
uint16_t brick; // brick size in pixels
uint16_t stack; // stack size in pixels
uint32_t step; // 2D-fication of SEGENV.step (state)
} tetris;
@ -3491,7 +3491,7 @@ uint16_t mode_tetrix(void) {
static void runStrip(size_t stripNr, Tetris *drop) {
// initialize dropping on first call or segment full
if (SEGENV.call == 0) {
drop->aux1 = 0; // reset brick stack size
drop->stack = 0; // reset brick stack size
drop->step = 0;
//for (int i=0; i<SEGLEN; i++) SEGMENT.setPixelColor(i | int((stripNr+1)<<16), SEGCOLOR(1)); // will fill virtual strip only
}
@ -3504,9 +3504,9 @@ uint16_t mode_tetrix(void) {
speed = map(speed, 1, 255, 5000, 250); // time taken for full (SEGLEN) drop
drop->speed = float(SEGLEN * FRAMETIME) / float(speed); // set speed
drop->pos = SEGLEN; // start at end of segment (no need to subtract 1)
drop->col = SEGMENT.color_from_palette(random8(0,15)<<4,false,false,0); // limit color choices so there is enough HUE gap
drop->col = random8(0,15)<<4; // limit color choices so there is enough HUE gap
drop->step = 1; // drop state (0 init, 1 forming, 2 falling)
drop->aux0 = (SEGMENT.intensity ? (SEGMENT.intensity>>5)+1 : random8(1,5)) * (1+(SEGLEN>>6)); // size of brick
drop->brick = (SEGMENT.intensity ? (SEGMENT.intensity>>5)+1 : random8(1,5)) * (1+(SEGLEN>>6)); // size of brick
}
if (drop->step == 1) { // forming
@ -3516,24 +3516,27 @@ uint16_t mode_tetrix(void) {
}
if (drop->step == 2) { // falling
if (drop->pos > drop->aux1) { // fall until top of stack
if (drop->pos > drop->stack) { // fall until top of stack
drop->pos -= drop->speed; // may add gravity as: speed += gravity
if (uint16_t(drop->pos) < drop->aux1) drop->pos = drop->aux1;
for (int i=int(drop->pos); i<SEGLEN; i++) SEGMENT.setPixelColor(i | int((stripNr+1)<<16), i<int(drop->pos)+drop->aux0 ? drop->col : SEGCOLOR(1));
if (uint16_t(drop->pos) < drop->stack) drop->pos = drop->stack;
for (int i=int(drop->pos); i<SEGLEN; i++) {
uint32_t col = i<int(drop->pos)+drop->brick ? SEGMENT.color_from_palette(drop->col, false, false, 0) : SEGCOLOR(1);
SEGMENT.setPixelColor(i | int((stripNr+1)<<16), col);
}
} else { // we hit bottom
drop->step = 0; // proceed with next brick, go back to init
drop->aux1 += drop->aux0; // increase the stack size
if (drop->aux1 >= SEGLEN) drop->step = millis() + 2000; // fade out stack
drop->stack += drop->brick; // increase the stack size
if (drop->stack >= SEGLEN) drop->step = millis() + 2000; // fade out stack
}
}
if (drop->step > 2) {
drop->aux0 = 0; // reset brick size (no more growing)
if (drop->step > 2) { // fade strip
drop->brick = 0; // reset brick size (no more growing)
if (drop->step > millis()) {
// allow fading of virtual strip
for (int i=0; i<SEGLEN; i++) SEGMENT.blendPixelColor(i | int((stripNr+1)<<16), SEGCOLOR(1), 25); // 10% blend
for (int i=0; i<SEGLEN; i++) SEGMENT.blendPixelColor(i | int((stripNr+1)<<16), SEGCOLOR(1), 25); // 10% blend with Bg color
} else {
drop->aux1 = 0; // reset brick stack size
drop->stack = 0; // reset brick stack size
drop->step = 0; // proceed with next brick
}
}

View File

@ -357,26 +357,21 @@ typedef struct Segment {
union {
uint16_t options; //bit pattern: msb first: [transposed mirrorY reverseY] transitional (tbd) paused needspixelstate mirrored on reverse selected
struct {
bool selected : 1; // 0 : selected
bool reverse : 1; // 1 : reversed
bool on : 1; // 2 : is On
bool mirror : 1; // 3 : mirrored
bool pxs : 1; // 4 : indicates that the effect does not use FRAMETIME or needs getPixelColor (?)
bool freeze : 1; // 5 : paused/frozen
bool reset : 1; // 6 : indicates that Segment runtime requires reset
bool transitional: 1; // 7 : transitional (there is transition occuring)
bool reverse_y : 1; // 8 : reversed Y (2D)
bool mirror_y : 1; // 9 : mirrored Y (2D)
bool transpose : 1; // 10 : transposed (2D, swapped X & Y)
uint8_t map1D2D : 3; // 11-13 : mapping for 1D effect on 2D (0-use as strip, 1-expand vertically, 2-circular/arc, 3-rectangular/corner, ...)
uint8_t soundSim : 2; // 14-15 : 0-3 sound simulation types
bool selected : 1; // 0 : selected
bool reverse : 1; // 1 : reversed
bool on : 1; // 2 : is On
bool mirror : 1; // 3 : mirrored
bool freeze : 1; // 4 : paused/frozen
bool reset : 1; // 5 : indicates that Segment runtime requires reset
bool transitional: 1; // 6 : transitional (there is transition occuring)
bool reverse_y : 1; // 7 : reversed Y (2D)
bool mirror_y : 1; // 8 : mirrored Y (2D)
bool transpose : 1; // 9 : transposed (2D, swapped X & Y)
uint8_t map1D2D : 3; // 10-12 : mapping for 1D effect on 2D (0-use as strip, 1-expand vertically, 2-circular/arc, 3-rectangular/corner, ...)
uint8_t soundSim : 3; // 13-15 : 0-7 sound simulation types
};
};
uint8_t grouping, spacing;
//struct {
// uint8_t grouping : 4; // maximum 15 pixels in a group
// uint8_t spacing : 4; // maximum 15 pixels per gap
//};
uint8_t opacity;
uint32_t colors[NUM_COLORS];
uint8_t cct; //0==1900K, 255==10091K
@ -418,17 +413,20 @@ typedef struct Segment {
// transition data, valid only if transitional==true, holds values during transition
struct Transition {
uint32_t _colorT[NUM_COLORS];
uint8_t _briT; // temporary brightness
uint8_t _cctT; // temporary CCT
CRGBPalette16 _palT; // temporary palette
uint8_t _modeP; // previous mode/effect
uint8_t _briT; // temporary brightness
uint8_t _cctT; // temporary CCT
CRGBPalette16 _palT; // temporary palette
uint8_t _modeP; // previous mode/effect
//uint16_t _aux0, _aux1; // previous mode/effect runtime data
//uint32_t _step, _call; // previous mode/effect runtime data
//byte *_data; // previous mode/effect runtime data
uint32_t _start;
uint16_t _dur;
Transition(uint16_t dur=750) : _briT(255), _cctT(127), _palT(CRGBPalette16(CRGB::Black)), _modeP(FX_MODE_STATIC), _start(millis()), _dur(dur) {}
Transition(uint16_t d, uint8_t b, uint8_t c, const uint32_t *o) : _briT(b), _cctT(c), _palT(CRGBPalette16(CRGB::Black)), _modeP(FX_MODE_STATIC), _start(millis()), _dur(d) {
for (size_t i=0; i<NUM_COLORS; i++) _colorT[i] = o[i];
}
} *_t; // this struct will bootloop ESP
} *_t;
public:
@ -530,8 +528,7 @@ typedef struct Segment {
* Safe to call from interrupts and network requests.
*/
inline void markForReset(void) { reset = true; } // setOption(SEG_OPTION_RESET, true)
//inline void setUpLeds() { if (!leds) leds = (CRGB*)malloc(sizeof(CRGB)*length()); }
void setUpLeds(void);
void setUpLeds(void); // set up leds[] array for loseless getPixelColor()
// transition functions
void startTransition(uint16_t dur); // transition has to start before actual segment values change

View File

@ -297,8 +297,8 @@ void Segment::startTransition(uint16_t dur) {
if (!_t) _t = new Transition(dur); // no previous transition running
if (!_t) return; // failed to allocate data
_t->_briT = _briT;
_t->_cctT = _cctT;
_t->_briT = _briT;
_t->_cctT = _cctT;
_t->_palT = _palT;
_t->_modeP = _modeP;
for (size_t i=0; i<NUM_COLORS; i++) _t->_colorT[i] = _colorT[i];
@ -625,7 +625,7 @@ uint8_t Segment::differs(Segment& b) const {
if (stopY != b.stopY) d |= SEG_DIFFERS_BOUNDS;
//bit pattern: msb first: [transposed mirrorY reverseY] transitional (tbd) paused needspixelstate mirrored on reverse selected
if ((options & 0b1111111100101110) != (b.options & 0b1111111100101110)) d |= SEG_DIFFERS_OPT;
if ((options & 0b1111111110011110) != (b.options & 0b1111111110011110)) d |= SEG_DIFFERS_OPT;
if ((options & 0x01) != (b.options & 0x01)) d |= SEG_DIFFERS_SEL;
for (uint8_t i = 0; i < NUM_COLORS; i++) if (colors[i] != b.colors[i]) d |= SEG_DIFFERS_COL;

View File

@ -226,13 +226,12 @@
#define SEG_OPTION_REVERSED 1
#define SEG_OPTION_ON 2
#define SEG_OPTION_MIRROR 3 //Indicates that the effect will be mirrored within the segment
#define SEG_OPTION_NONUNITY 4 //Indicates that the effect does not use FRAMETIME or needs getPixelColor
#define SEG_OPTION_FREEZE 5 //Segment contents will not be refreshed
#define SEG_OPTION_RESET 6 //Segment runtime requires reset
#define SEG_OPTION_TRANSITIONAL 7
#define SEG_OPTION_REVERSED_Y 8
#define SEG_OPTION_MIRROR_Y 9
#define SEG_OPTION_TRANSPOSED 10
#define SEG_OPTION_FREEZE 4 //Segment contents will not be refreshed
#define SEG_OPTION_RESET 5 //Segment runtime requires reset
#define SEG_OPTION_TRANSITIONAL 6
#define SEG_OPTION_REVERSED_Y 7
#define SEG_OPTION_MIRROR_Y 8
#define SEG_OPTION_TRANSPOSED 9
//Segment differs return byte
#define SEG_DIFFERS_BRI 0x01

View File

@ -714,7 +714,7 @@ function populateSegments(s)
}
let map2D = `<div id="seg${i}map2D" data-map="map2D" class="lbl-s hide">Expand 1D FX<br>
<div class="sel-p"><select class="sel-p" id="seg${i}mp12" onchange="setMp12(${i})">
<option value="0" ${inst.mp12==0?' selected':''}>Pxels</option>
<option value="0" ${inst.mp12==0?' selected':''}>Pixels</option>
<option value="1" ${inst.mp12==1?' selected':''}>Bar</option>
<option value="2" ${inst.mp12==2?' selected':''}>Arc</option>
<option value="3" ${inst.mp12==3?' selected':''}>Corner</option>

File diff suppressed because it is too large Load Diff

View File

@ -84,8 +84,8 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
if ((spc>0 && spc!=seg.spacing) || seg.map1D2D!=map1D2D) seg.fill(BLACK); // clear spacing gaps
seg.map1D2D = map1D2D & 0x07;
seg.soundSim = soundSim & 0x03;
seg.map1D2D = constrain(map1D2D, 0, 7);
seg.soundSim = constrain(soundSim, 0, 7);
uint16_t len = 1;
if (stop > start) len = stop - start;
@ -190,8 +190,8 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
sOpt = extractModeDefaults(fx, "c1"); if (sOpt >= 0) seg.custom1 = sOpt;
sOpt = extractModeDefaults(fx, "c2"); if (sOpt >= 0) seg.custom2 = sOpt;
sOpt = extractModeDefaults(fx, "c3"); if (sOpt >= 0) seg.custom3 = sOpt;
sOpt = extractModeDefaults(fx, "mp12"); if (sOpt >= 0) seg.map1D2D = sOpt & 0x07;
sOpt = extractModeDefaults(fx, "ssim"); if (sOpt >= 0) seg.soundSim = sOpt & 0x03;
sOpt = extractModeDefaults(fx, "mp12"); if (sOpt >= 0) seg.map1D2D = constrain(sOpt, 0, 7);
sOpt = extractModeDefaults(fx, "ssim"); if (sOpt >= 0) seg.soundSim = constrain(sOpt, 0, 7);
sOpt = extractModeDefaults(fx, "rev"); if (sOpt >= 0) seg.reverse = (bool)sOpt;
sOpt = extractModeDefaults(fx, "mi"); if (sOpt >= 0) seg.mirror = (bool)sOpt; // NOTE: setting this option is a risky business
sOpt = extractModeDefaults(fx, "rY"); if (sOpt >= 0) seg.reverse_y = (bool)sOpt;
@ -219,7 +219,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
getVal(elem["c2"], &seg.custom2);
uint8_t cust3 = seg.custom3;
getVal(elem["c3"], &cust3); // we can't pass reference to bifield
seg.custom3 = cust3;
seg.custom3 = constrain(cust3, 0, 31);
seg.check1 = elem["o1"] | seg.check1;
seg.check2 = elem["o2"] | seg.check2;