diff options
author | Elias Fleckenstein <54945686+EliasFleckenstein03@users.noreply.github.com> | 2020-12-29 16:50:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-29 16:50:09 +0100 |
commit | 9250b5205a6c627dfa18b7870b454d74f8d9dae6 (patch) | |
tree | 029b10d67356eb052fe2594f3d58967dc9d2a88e /src/server | |
parent | 09d7fbd645888aac32d089ff528ac1d1eb87e72d (diff) | |
download | minetest-9250b5205a6c627dfa18b7870b454d74f8d9dae6.tar.gz minetest-9250b5205a6c627dfa18b7870b454d74f8d9dae6.tar.bz2 minetest-9250b5205a6c627dfa18b7870b454d74f8d9dae6.zip |
Add minetest.get_objects_in_area (#10668)
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/activeobjectmgr.cpp | 15 | ||||
-rw-r--r-- | src/server/activeobjectmgr.h | 3 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/server/activeobjectmgr.cpp b/src/server/activeobjectmgr.cpp index 1b8e31409..acd6611f4 100644 --- a/src/server/activeobjectmgr.cpp +++ b/src/server/activeobjectmgr.cpp @@ -127,6 +127,21 @@ void ActiveObjectMgr::getObjectsInsideRadius(const v3f &pos, float radius, } } +void ActiveObjectMgr::getObjectsInArea(const aabb3f &box, + std::vector<ServerActiveObject *> &result, + std::function<bool(ServerActiveObject *obj)> include_obj_cb) +{ + for (auto &activeObject : m_active_objects) { + ServerActiveObject *obj = activeObject.second; + const v3f &objectpos = obj->getBasePosition(); + if (!box.isPointInside(objectpos)) + continue; + + if (!include_obj_cb || include_obj_cb(obj)) + result.push_back(obj); + } +} + void ActiveObjectMgr::getAddedActiveObjectsAroundPos(const v3f &player_pos, f32 radius, f32 player_radius, std::set<u16> ¤t_objects, std::queue<u16> &added_objects) diff --git a/src/server/activeobjectmgr.h b/src/server/activeobjectmgr.h index bc2085499..d43f5643c 100644 --- a/src/server/activeobjectmgr.h +++ b/src/server/activeobjectmgr.h @@ -38,6 +38,9 @@ public: void getObjectsInsideRadius(const v3f &pos, float radius, std::vector<ServerActiveObject *> &result, std::function<bool(ServerActiveObject *obj)> include_obj_cb); + void getObjectsInArea(const aabb3f &box, + std::vector<ServerActiveObject *> &result, + std::function<bool(ServerActiveObject *obj)> include_obj_cb); void getAddedActiveObjectsAroundPos(const v3f &player_pos, f32 radius, f32 player_radius, std::set<u16> ¤t_objects, |