Skip to content

Commit

Permalink
Use sharedProData in projections, use leds in adjust functions
Browse files Browse the repository at this point in the history
LedFixture.projectAndMap:
- use leds in adjustSizeAndPixel and adjustMapped

LedLeds:
- use leds in adjustSizeAndPixel and adjustMapped
- add sharedProData (WIP)

LedModEffects: rename sharedData.loop to begin

LedProjections. multiply: use sharedProData (WIP)
  • Loading branch information
ewoudwijma committed Jul 5, 2024
1 parent 89db27b commit d4e2d0d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/App/LedFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/App/LedFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down
7 changes: 4 additions & 3 deletions src/App/LedLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -289,6 +289,7 @@ class Leds {
unsigned8 proRollSpeed = 128;

SharedData sharedData;
SharedData sharedProData;

std::vector<PhysMap> mappingTable;

Expand Down
6 changes: 3 additions & 3 deletions src/App/LedModEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
36 changes: 21 additions & 15 deletions src/App/LedProjections.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ 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<Coord3D>();
//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;
pixelAdjusted = pixelAdjusted%sizeAdjusted; // pixel % size
// 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<Coord3D>();
bool mirror = leds.sharedProData.read<bool>();

if (mirror) {
Coord3D mirrors = pixelAdjusted / sizeAdjusted; //place the pixel in the right quadrant
Expand All @@ -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<Coord3D>({2,2,1});
bool *mirror = leds.sharedProData.write<bool>(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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d4e2d0d

Please sign in to comment.