mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-14 17:15:21 +02:00
Optimize getting active objects a bit. #8674
This commit is contained in:
@@ -91,15 +91,16 @@ void ActiveObjectMgr::removeObject(u16 id)
|
||||
void ActiveObjectMgr::getActiveObjects(const v3f &origin, f32 max_d,
|
||||
std::vector<DistanceSortedActiveObject> &dest)
|
||||
{
|
||||
f32 max_d2 = max_d * max_d;
|
||||
for (auto &ao_it : m_active_objects) {
|
||||
ClientActiveObject *obj = ao_it.second;
|
||||
|
||||
f32 d = (obj->getPosition() - origin).getLength();
|
||||
f32 d2 = (obj->getPosition() - origin).getLengthSQ();
|
||||
|
||||
if (d > max_d)
|
||||
if (d2 > max_d2)
|
||||
continue;
|
||||
|
||||
dest.emplace_back(obj, d);
|
||||
dest.emplace_back(obj, d2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -90,10 +90,10 @@ private:
|
||||
static std::unordered_map<u16, Factory> m_types;
|
||||
};
|
||||
|
||||
struct DistanceSortedActiveObject
|
||||
class DistanceSortedActiveObject
|
||||
{
|
||||
public:
|
||||
ClientActiveObject *obj;
|
||||
f32 d;
|
||||
|
||||
DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
|
||||
{
|
||||
@@ -105,4 +105,7 @@ struct DistanceSortedActiveObject
|
||||
{
|
||||
return d < other.d;
|
||||
}
|
||||
|
||||
private:
|
||||
f32 d;
|
||||
};
|
||||
|
Reference in New Issue
Block a user