| 493 | } |
| 494 | |
| 495 | zonemap* ConfigHandler::FindZoneMap(int gid, bool reset) { |
| 496 | zoneUpdate.lockWrite(); |
| 497 | |
| 498 | if (reset || zoneMaps.find(gid) == zoneMaps.end()) { |
| 499 | // create new zoneMap |
| 500 | zoneMaps.erase(gid); |
| 501 | zonemap* zone = &zoneMaps[gid]; |
| 502 | |
| 503 | AlienFX_SDK::Afx_group* grp = afx_dev.GetGroupById(gid); |
| 504 | if (grp && grp->lights.size()) { |
| 505 | // find operational grid... |
| 506 | AlienFX_SDK::Afx_grid* opGrid = NULL; |
| 507 | for (auto t = afx_dev.GetGrids()->begin(); !opGrid && t < afx_dev.GetGrids()->end(); t++) |
| 508 | for (int ind = 0; ind < t->x * t->y; ind++) |
| 509 | if (IsLightInGroup(t->grid[ind].lgh, grp)) { |
| 510 | zone->gridID = t->id; |
| 511 | opGrid = &(*t); |
| 512 | break; |
| 513 | } |
| 514 | |
| 515 | if (opGrid) { |
| 516 | // scan light positions in grid and set power |
| 517 | zone->havePower = false; |
| 518 | for (AlienFX_SDK::Afx_groupLight& lgh : grp->lights) { |
| 519 | if (afx_dev.GetFlags(lgh.did, lgh.lid) & ALIENFX_FLAG_POWER) |
| 520 | zone->havePower = true; |
| 521 | zonelight cl{ lgh.lgh, 255, 255 }; |
| 522 | for (int ind = 0; ind < opGrid->x * opGrid->y; ind++) |
| 523 | if (opGrid->grid[ind].lgh == lgh.lgh) { |
| 524 | cl.x = min(cl.x, ind % opGrid->x); |
| 525 | cl.y = min(cl.y, ind / opGrid->x); |
| 526 | zone->xMax = max(zone->xMax, ind % opGrid->x); |
| 527 | zone->yMax = max(zone->yMax, ind / opGrid->x); |
| 528 | //zone->gMaxX = max(zone->gMaxX, cl.x); |
| 529 | //zone->gMaxY = max(zone->gMaxY, cl.y); |
| 530 | //zone->gMinX = min(zone->gMinX, cl.x); |
| 531 | //zone->gMinY = min(zone->gMinY, cl.y); |
| 532 | //zone->lightMap.push_back(cl); |
| 533 | //break; |
| 534 | } |
| 535 | // Ignore light if not in grid |
| 536 | if (cl.x < 255 && cl.y < 255) { |
| 537 | zone->gMaxX = max(zone->gMaxX, cl.x); |
| 538 | zone->gMaxY = max(zone->gMaxY, cl.y); |
| 539 | zone->gMinX = min(zone->gMinX, cl.x); |
| 540 | zone->gMinY = min(zone->gMinY, cl.y); |
| 541 | zone->lightMap.push_back(cl); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | // now shrink axis... |
| 546 | for (zonelight& t : zone->lightMap) { |
| 547 | t.x -= zone->gMinX; t.y -= zone->gMinY; |
| 548 | } |
| 549 | // Scales... |
| 550 | zone->scaleX = zone->gMaxX = zone->gMaxX + 1 - zone->gMinX; |
| 551 | zone->scaleY = zone->gMaxY = zone->gMaxY + 1 - zone->gMinY; |
| 552 | for (int x = 1; x < zone->gMaxX; x++) |
no test coverage detected