diff --git a/src/App/LedFixture.cpp b/src/App/LedFixture.cpp index e3233e3e..fd6643ec 100644 --- a/src/App/LedFixture.cpp +++ b/src/App/LedFixture.cpp @@ -110,7 +110,7 @@ void Fixture::projectAndMap() { mdl->getValueRowNr = rowNr; //run projection functions in the right rowNr context //using cached virtual class methods! - if (projection) (projection->*leds->adjustSizeAndPixelCached)(sizeAdjusted, pixelAdjusted, midPosAdjusted); + if (projection) (projection->*leds->adjustSizeAndPixelCached)(*leds, sizeAdjusted, pixelAdjusted, midPosAdjusted); if (leds->size == Coord3D{0,0,0}) { // first ppf("projectAndMap first leds[%d] size:%d,%d,%d s:%d,%d,%d e:%d,%d,%d\n", rowNr, sizeAdjusted.x, sizeAdjusted.y, sizeAdjusted.z, startPosAdjusted.x, startPosAdjusted.y, startPosAdjusted.z, endPosAdjusted.x, endPosAdjusted.y, endPosAdjusted.z); @@ -134,7 +134,7 @@ void Fixture::projectAndMap() { mapped = pixelAdjusted; //using cached virtual class methods! - if (projection) (projection->*leds->adjustMappedCached)(mapped, sizeAdjusted, (pixel - startPosAdjusted)/10, midPosAdjusted); + if (projection) (projection->*leds->adjustMappedCached)(*leds, mapped, sizeAdjusted, (pixel - startPosAdjusted)/10, midPosAdjusted); if (leds->projectionNr != p_Pinwheel) { //Pinwheel temp fix mapped.x = mapped.distance(midPosAdjusted); @@ -195,7 +195,7 @@ void Fixture::projectAndMap() { } //using cached virtual class methods! - if (projection) (projection->*leds->adjustMappedCached)(mapped, sizeAdjusted, (pixel - startPosAdjusted)/10, midPosAdjusted); + if (projection) (projection->*leds->adjustMappedCached)(*leds, mapped, sizeAdjusted, (pixel - startPosAdjusted)/10, midPosAdjusted); indexV = leds->XYZUnprojected(mapped); break; @@ -227,7 +227,7 @@ void Fixture::projectAndMap() { } //using cached virtual class methods! - if (projection) (projection->*leds->adjustMappedCached)(mapped, sizeAdjusted, (pixel - startPosAdjusted)/10, midPosAdjusted); + if (projection) (projection->*leds->adjustMappedCached)(*leds, mapped, sizeAdjusted, (pixel - startPosAdjusted)/10, midPosAdjusted); indexV = leds->XYZUnprojected(mapped); diff --git a/src/App/LedFixture.h b/src/App/LedFixture.h index e9ad943e..16a9f6b2 100644 --- a/src/App/LedFixture.h +++ b/src/App/LedFixture.h @@ -30,9 +30,9 @@ class Projection { virtual const char * tags() {return "";} // virtual uint8_t dim() {return _1D;}; - virtual void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) {} + virtual void adjustSizeAndPixel(Leds &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) {} - virtual void adjustMapped(Coord3D &mapped, Coord3D sizeAdjusted, Coord3D pixelAdjusted, Coord3D midPosAdjusted) {} + virtual void adjustMapped(Leds &leds, Coord3D &mapped, Coord3D sizeAdjusted, Coord3D pixelAdjusted, Coord3D midPosAdjusted) {} virtual void adjustXYZ(Leds &leds, Coord3D &pixel) {} diff --git a/src/App/LedLeds.h b/src/App/LedLeds.h index 2c870939..70b8f604 100644 --- a/src/App/LedLeds.h +++ b/src/App/LedLeds.h @@ -145,7 +145,7 @@ class SharedData { } //sets the sharedData pointer back to 0 so loop effect can go through it - void loop() { + void begin() { index = 0; } @@ -272,8 +272,8 @@ class Leds { unsigned8 projectionNr = -1; //using cached virtual class methods! 4 bytes each - thats for now the price we pay for speed - void (Projection::*adjustSizeAndPixelCached)(Coord3D &, Coord3D &, Coord3D &) = nullptr; - void (Projection::*adjustMappedCached)(Coord3D &, Coord3D, Coord3D, Coord3D) = nullptr; + void (Projection::*adjustSizeAndPixelCached)(Leds &, Coord3D &, Coord3D &, Coord3D &) = nullptr; + void (Projection::*adjustMappedCached)(Leds &, Coord3D &, Coord3D, Coord3D, Coord3D) = nullptr; void (Projection::*adjustXYZCached)(Leds &, Coord3D &) = nullptr; unsigned8 effectDimension = -1; @@ -289,6 +289,7 @@ class Leds { unsigned8 proRollSpeed = 128; SharedData sharedData; + SharedData sharedProData; std::vector mappingTable; diff --git a/src/App/LedModEffects.h b/src/App/LedModEffects.h index 8b30ad7d..f2e72b84 100644 --- a/src/App/LedModEffects.h +++ b/src/App/LedModEffects.h @@ -186,12 +186,12 @@ class LedModEffects:public SysModule { if (leds->fx < effects.size()) { - leds->sharedData.reset(); //make sure all values are 0 and reset for a fresh start of the effect Effect* effect = effects[leds->fx]; // effect->loop(leds); //do a loop to set sharedData right - // leds->sharedData.loop(); + leds->sharedData.reset(); //make sure all values are 0 and reset for a fresh start of the effect + // leds->sharedData.begin(); mdl->varPreDetails(var, rowNr); effect->controls(*leds, var); mdl->varPostDetails(var, rowNr); @@ -422,7 +422,7 @@ class LedModEffects:public SysModule { // ppf(" %d %d,%d,%d - %d,%d,%d (%d,%d,%d)", leds->fx, leds->startPos.x, leds->startPos.y, leds->startPos.z, leds->endPos.x, leds->endPos.y, leds->endPos.z, leds->size.x, leds->size.y, leds->size.z ); mdl->getValueRowNr = rowNr++; - leds->sharedData.loop(); //sets the sharedData pointer back to 0 so loop effect can go through it + leds->sharedData.begin(); //sets the sharedData pointer back to 0 so loop effect can go through it effects[leds->fx]->loop(*leds); mdl->getValueRowNr = UINT8_MAX; diff --git a/src/App/LedProjections.h b/src/App/LedProjections.h index 1e586dac..2aaece14 100644 --- a/src/App/LedProjections.h +++ b/src/App/LedProjections.h @@ -35,8 +35,9 @@ class MultiplyProjection: public Projection { public: //to use in Preset1Projection - void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { - Coord3D proMulti = mdl->getValue("proMulti"); //, rowNr + void adjustSizeAndPixel(Leds &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { + leds.sharedProData.begin(); + Coord3D proMulti = leds.sharedProData.read(); //promulti can be 0,0,0 but /= protects from /div0 sizeAdjusted /= proMulti; sizeAdjusted = sizeAdjusted.maximum(Coord3D{1,1,1}); //size min 1,1,1 midPosAdjusted /= proMulti; @@ -44,9 +45,11 @@ class MultiplyProjection: public Projection { // ppf("Multiply %d,%d,%d\n", leds->size.x, leds->size.y, leds->size.z); } - void adjustMapped(Coord3D &mapped, Coord3D sizeAdjusted, Coord3D pixelAdjusted, Coord3D midPosAdjusted) { + void adjustMapped(Leds &leds, Coord3D &mapped, Coord3D sizeAdjusted, Coord3D pixelAdjusted, Coord3D midPosAdjusted) { // if mirrored find the indexV of the mirrored pixel - bool mirror = mdl->getValue("mirror"); + leds.sharedProData.begin(); + Coord3D proMulti = leds.sharedProData.read(); + bool mirror = leds.sharedProData.read(); if (mirror) { Coord3D mirrors = pixelAdjusted / sizeAdjusted; //place the pixel in the right quadrant @@ -57,12 +60,15 @@ class MultiplyProjection: public Projection { } void controls(Leds &leds, JsonObject parentVar) { - ui->initCoord3D(parentVar, "proMulti", {2,2,1}, 0, 10, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + leds.sharedProData.reset(); + Coord3D *proMulti = leds.sharedProData.write({2,2,1}); + bool *mirror = leds.sharedProData.write(false); + ui->initCoord3D(parentVar, "proMulti", proMulti, 0, 10, false, [&leds, mirror](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case onUI: ui->setLabel(var, "MultiplyX"); return true; case onChange: - ui->initCheckBox(var, "mirror", false, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + ui->initCheckBox(var, "mirror", mirror, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case onChange: if (rowNr < leds.fixture->listOfLeds.size()) { leds.fixture->listOfLeds[rowNr]->triggerMapping(); @@ -171,14 +177,14 @@ class Preset1Projection: public Projection { //uint8_t dim() {return _1D;} // every projection should work for all D const char * tags() {return "💫";} - void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { + void adjustSizeAndPixel(Leds &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { MultiplyProjection mp; - mp.adjustSizeAndPixel(sizeAdjusted, pixelAdjusted, midPosAdjusted); + mp.adjustSizeAndPixel(leds, sizeAdjusted, pixelAdjusted, midPosAdjusted); } - void adjustMapped(Coord3D &mapped, Coord3D sizeAdjusted, Coord3D pixelAdjusted, Coord3D midPosAdjusted) { + void adjustMapped(Leds &leds, Coord3D &mapped, Coord3D sizeAdjusted, Coord3D pixelAdjusted, Coord3D midPosAdjusted) { MultiplyProjection mp; - mp.adjustMapped(mapped, sizeAdjusted, pixelAdjusted, midPosAdjusted); + mp.adjustMapped(leds, mapped, sizeAdjusted, pixelAdjusted, midPosAdjusted); } void adjustXYZ(Leds &leds, Coord3D &pixel) { @@ -211,7 +217,7 @@ class ReverseProjection: public Projection { public: - void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { + void adjustSizeAndPixel(Leds &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { // UI Variables bool reverseX = mdl->getValue("reverse X"); bool reverseY = mdl->getValue("reverse Y"); @@ -254,7 +260,7 @@ class MirrorProjection: public Projection { public: - void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { + void adjustSizeAndPixel(Leds &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { // UI Variables bool mirrorX = mdl->getValue("mirror X"); bool mirrorY = mdl->getValue("mirror Y"); @@ -306,7 +312,7 @@ class GroupingProjection: public Projection { public: - void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { + void adjustSizeAndPixel(Leds &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { // UI Variables Coord3D grouping = mdl->getValue("Grouping"); grouping = grouping.maximum(Coord3D{1, 1, 1}); // {1, 1, 1} is the minimum value @@ -346,7 +352,7 @@ class TransposeProjection: public Projection { public: - void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { + void adjustSizeAndPixel(Leds &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { // UI Variables bool transposeXY = mdl->getValue("transpose XY"); bool transposeXZ = mdl->getValue("transpose XZ"); @@ -397,7 +403,7 @@ class PinwheelProjection: public Projection { public: - void adjustSizeAndPixel(Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { + void adjustSizeAndPixel(Leds &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) { sizeAdjusted.x = mdl->getValue("petals"); sizeAdjusted.y = 1; sizeAdjusted.z = 1;