This commit is contained in:
andrewchilicki
2025-02-08 16:37:29 -05:00
parent 7e0e9d2592
commit 1485f1325e
9 changed files with 183 additions and 257 deletions

View File

@ -26,46 +26,36 @@ public:
bool activeGroupStillVisible = false;
bool newActiveBadGroup = false;
for (auto it = badGroups.begin(); it != badGroups.end(); )
{
if (it->second->numberIds.empty())
{
for (auto it = badGroups.begin(); it != badGroups.end(); ) {
if (it->second->numberIds.empty()) {
it = badGroups.erase(it);
}
else
{
} else {
++it;
}
}
// Update visible groups and check if active group is still visible
for (const auto &[groupId, badGroup] : badGroups)
{
for (const auto &numId : badGroup->numberIds)
{
for (const auto &[groupId, badGroup] : badGroups) {
for (const auto &numId : badGroup->numberIds) {
auto num = numberIdMap.at(numId);
if (num->displayInfos.isVisible)
{
if (num->displayInfos.isVisible) {
visibleBadGroups.emplace(groupId);
if (badGroup->isActive && groupId == *activeBadGroup)
{
if (badGroup->isActive && groupId == *activeBadGroup) {
activeGroupStillVisible = true;
}
}
}
}
if (activeBadGroup && !activeGroupStillVisible)
{
if (activeBadGroup && !activeGroupStillVisible) {
activeBadGroup.reset();
newActiveBadGroup = true;
newBadGroupCountdown = randomNumber(5, 15) * 100;
}
// Select a new active group if necessary
if (!activeBadGroup && !visibleBadGroups.empty() && newBadGroupCountdown == 0)
{
if (!activeBadGroup && !visibleBadGroups.empty() && newBadGroupCountdown == 0) {
auto randomIndex = randomNumber(0, static_cast<int>(visibleBadGroups.size()) - 1);
auto it = visibleBadGroups.begin();
std::advance(it, randomIndex);
@ -73,39 +63,27 @@ public:
}
// Update active groups / their scale
for (const auto &[groupId, badGroup] : badGroups)
{
for (const auto &[groupId, badGroup] : badGroups) {
badGroup->isActive = activeBadGroup && groupId == *activeBadGroup;
if (badGroup->isActive)
{
if (newActiveBadGroup)
{
if (badGroup->isActive) {
if (newActiveBadGroup) {
badGroup->scale = 0;
}
else
{
if (!badGroup->reachedMax)
{
if (badGroup->scale < 0.23)
{
} else {
if (!badGroup->reachedMax) {
if (badGroup->scale < 0.23) {
badGroup->scale += (0.0001 * randomNumber(1, 10));
}
} else
{
} else {
badGroup->scale -= (0.0001 * randomNumber(1, 10));
}
if (badGroup->scale >= 0.23)
{
if (!badGroup->superActive || badGroup->scale >= 0.24)
{
if (badGroup->scale >= 0.23) {
if (!badGroup->superActive || badGroup->scale >= 0.24) {
badGroup->reachedMax = true;
} else
{
} else {
badGroup->scale += 0.00001;
}
} else if (badGroup->scale <= 0.0)
{
} else if (badGroup->scale <= 0.0) {
badGroup->isActive = false;
badGroup->superActive = false;
badGroup->reachedMax = false;
@ -113,24 +91,20 @@ public:
newBadGroupCountdown = randomNumber(5, 15) * 100;
}
}
} else
{
} else {
badGroup->scale = 0;
}
}
if (newBadGroupCountdown > 0)
{
if (newBadGroupCountdown > 0) {
newBadGroupCountdown--;
}
}
NumberPtr getGridNumber(int x, int y) final
{
if (auto itr = grid.find(x); itr != grid.end())
{
if (auto itr2 = itr->second.find(y); itr2 != itr->second.end())
{
if (auto itr = grid.find(x); itr != grid.end()) {
if (auto itr2 = itr->second.find(y); itr2 != itr->second.end()) {
return itr2->second;
}
}
@ -139,8 +113,7 @@ public:
NumberPtr getGridNumber(int id) final
{
if (auto itr = numberIdMap.find(id); itr != numberIdMap.end())
{
if (auto itr = numberIdMap.find(id); itr != numberIdMap.end()) {
return itr->second;
}
return nullptr;
@ -170,16 +143,13 @@ private:
{
int numberId = 0;
std::set<int> badNumbers;
for (int x = 0; x < size; x++)
{
for (int y = 0; y < size; y++)
{
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
grid[x][y] = std::make_shared<Number>(numberId, x, y, randomNumber(0,9), randomBool());
numberIdMap[numberId] = grid[x][y];
// Determine if bad
if (perlinBadNumbers.noise2D_01(x*badScale,y*badScale) > badThresh)
{
if (perlinBadNumbers.noise2D_01(x*badScale,y*badScale) > badThresh) {
badNumbers.insert(numberId);
}
@ -188,44 +158,34 @@ private:
}
// Assign 'bad groups'
auto checkAdjacent = [&](int x, int y) -> BadGroupPtr
{
if (auto gridNum = getGridNumber(x, y))
{
auto checkAdjacent = [&](int x, int y) -> BadGroupPtr {
if (auto gridNum = getGridNumber(x, y)) {
return gridNum->badGroup;
}
return nullptr;
};
int badGroup = 0;
for (const auto &badNumId : badNumbers)
{
for (const auto &badNumId : badNumbers) {
auto gridNumber = numberIdMap.at(badNumId);
if (!gridNumber->badGroup)
{
for (int checkX = -1; checkX <= 1; checkX++)
{
for (int checkY = -1; checkY <= 1; checkY++)
{
if (checkX == 0 && checkY == 0)
{
if (!gridNumber->badGroup) {
for (int checkX = -1; checkX <= 1; checkX++) {
for (int checkY = -1; checkY <= 1; checkY++) {
if (checkX == 0 && checkY == 0) {
continue;
}
if (auto badGroupPtr = checkAdjacent(gridNumber->gridX + checkX, gridNumber->gridY + checkY))
{
if (auto badGroupPtr = checkAdjacent(gridNumber->gridX + checkX, gridNumber->gridY + checkY)) {
gridNumber->badGroup = badGroupPtr;
gridNumber->badGroup->numberIds.emplace_back(gridNumber->id);
break;
}
}
if (gridNumber->badGroup)
{
if (gridNumber->badGroup) {
break;
}
}
if (!gridNumber->badGroup)
{
if (!gridNumber->badGroup) {
gridNumber->badGroup = std::make_shared<BadGroup>(badGroup++, std::vector{gridNumber->id}, randomNumber(0,4));
badGroups.emplace(badGroup, gridNumber->badGroup);
}