diff options
author | sfence <sfence.software@gmail.com> | 2021-06-20 17:21:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-20 17:21:35 +0200 |
commit | b10091be9b6b6c74a170b9444f856f83dd3fe952 (patch) | |
tree | c806e74b870be70fafe2323858bbd5bd4071f399 /src/serverenvironment.cpp | |
parent | 1805775f3d54043c3b1e75e47b9b85e3b12bab00 (diff) | |
download | minetest-b10091be9b6b6c74a170b9444f856f83dd3fe952.tar.gz minetest-b10091be9b6b6c74a170b9444f856f83dd3fe952.tar.bz2 minetest-b10091be9b6b6c74a170b9444f856f83dd3fe952.zip |
Add min_y and max_y checks for Active Block Modifiers (ABM) (#11333)
This check can be used by ABM to reduce CPU usage.
Diffstat (limited to 'src/serverenvironment.cpp')
-rw-r--r-- | src/serverenvironment.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 413a785e6..f3711652c 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -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; |