Update client::ActiveObjectMgr::getActiveSelectableObjects API

This commit is contained in:
numzero 2023-06-20 23:06:38 +03:00 committed by sfan5
parent aaae9d5a77
commit d7291e0600
3 changed files with 9 additions and 11 deletions

View file

@ -107,9 +107,9 @@ void ActiveObjectMgr::getActiveObjects(const v3f &origin, f32 max_d,
} }
} }
void ActiveObjectMgr::getActiveSelectableObjects(const core::line3d<f32> &shootline, std::vector<DistanceSortedActiveObject> ActiveObjectMgr::getActiveSelectableObjects(const core::line3d<f32> &shootline)
std::vector<DistanceSortedActiveObject> &dest)
{ {
std::vector<DistanceSortedActiveObject> dest;
// Imagine a not-axis-aligned cuboid oriented into the direction of the shootline, // Imagine a not-axis-aligned cuboid oriented into the direction of the shootline,
// with the width of the object's selection box radius * 2 and with length of the // with the width of the object's selection box radius * 2 and with length of the
// shootline (+selection box radius forwards and backwards). We check whether // shootline (+selection box radius forwards and backwards). We check whether
@ -147,6 +147,7 @@ void ActiveObjectMgr::getActiveSelectableObjects(const core::line3d<f32> &shootl
dest.emplace_back(obj, d); dest.emplace_back(obj, d);
} }
return dest;
} }
} // namespace client } // namespace client

View file

@ -37,12 +37,10 @@ class ActiveObjectMgr : public ::ActiveObjectMgr<ClientActiveObject>
void getActiveObjects(const v3f &origin, f32 max_d, void getActiveObjects(const v3f &origin, f32 max_d,
std::vector<DistanceSortedActiveObject> &dest); std::vector<DistanceSortedActiveObject> &dest);
// Similar to above, but takes selection box sizes, and line direction into
// account. /// Gets all CAOs whose selection boxes may intersect the @p shootline.
// Objects without selectionbox are not returned. /// @note CAOs without a selection box are not returned.
// Returned distances are in direction of shootline. /// @note Distances are along the @p shootline.
// Distance check is coarse. std::vector<DistanceSortedActiveObject> getActiveSelectableObjects(const core::line3d<f32> &shootline);
void getActiveSelectableObjects(const core::line3d<f32> &shootline,
std::vector<DistanceSortedActiveObject> &dest);
}; };
} // namespace client } // namespace client

View file

@ -495,8 +495,7 @@ void ClientEnvironment::getSelectedActiveObjects(
const core::line3d<f32> &shootline_on_map, const core::line3d<f32> &shootline_on_map,
std::vector<PointedThing> &objects) std::vector<PointedThing> &objects)
{ {
std::vector<DistanceSortedActiveObject> allObjects; auto allObjects = m_ao_manager.getActiveSelectableObjects(shootline_on_map);
m_ao_manager.getActiveSelectableObjects(shootline_on_map, allObjects);
const v3f line_vector = shootline_on_map.getVector(); const v3f line_vector = shootline_on_map.getVector();
for (const auto &allObject : allObjects) { for (const auto &allObject : allObjects) {