1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Add min_y and max_y checks for Active Block Modifiers (ABM) (#11333)

This check can be used by ABM to reduce CPU usage.
This commit is contained in:
sfence 2021-06-20 17:21:35 +02:00 committed by GitHub
parent 1805775f3d
commit b10091be9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 3 deletions

View file

@ -729,6 +729,8 @@ struct ActiveABM
int chance;
std::vector<content_t> required_neighbors;
bool check_required_neighbors; // false if required_neighbors is known to be empty
s16 min_y;
s16 max_y;
};
class ABMHandler
@ -773,6 +775,9 @@ public:
} else {
aabm.chance = chance;
}
// y limits
aabm.min_y = abm->getMinY();
aabm.max_y = abm->getMaxY();
// Trigger neighbors
const std::vector<std::string> &required_neighbors_s =
@ -885,6 +890,9 @@ public:
v3s16 p = p0 + block->getPosRelative();
for (ActiveABM &aabm : *m_aabms[c]) {
if ((p.Y < aabm.min_y) || (p.Y > aabm.max_y))
continue;
if (myrand() % aabm.chance != 0)
continue;