File tree 3 files changed +11
-6
lines changed
3 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -91,15 +91,16 @@ void ActiveObjectMgr::removeObject(u16 id)
91
91
void ActiveObjectMgr::getActiveObjects (const v3f &origin, f32 max_d,
92
92
std::vector<DistanceSortedActiveObject> &dest)
93
93
{
94
+ f32 max_d2 = max_d * max_d;
94
95
for (auto &ao_it : m_active_objects) {
95
96
ClientActiveObject *obj = ao_it.second ;
96
97
97
- f32 d = (obj->getPosition () - origin).getLength ();
98
+ f32 d2 = (obj->getPosition () - origin).getLengthSQ ();
98
99
99
- if (d > max_d )
100
+ if (d2 > max_d2 )
100
101
continue ;
101
102
102
- dest.emplace_back (obj, d );
103
+ dest.emplace_back (obj, d2 );
103
104
}
104
105
}
105
106
Original file line number Diff line number Diff line change @@ -90,10 +90,10 @@ class ClientActiveObject : public ActiveObject
90
90
static std::unordered_map<u16, Factory> m_types;
91
91
};
92
92
93
- struct DistanceSortedActiveObject
93
+ class DistanceSortedActiveObject
94
94
{
95
+ public:
95
96
ClientActiveObject *obj;
96
- f32 d;
97
97
98
98
DistanceSortedActiveObject (ClientActiveObject *a_obj, f32 a_d)
99
99
{
@@ -105,4 +105,7 @@ struct DistanceSortedActiveObject
105
105
{
106
106
return d < other.d ;
107
107
}
108
+
109
+ private:
110
+ f32 d;
108
111
};
Original file line number Diff line number Diff line change @@ -115,11 +115,12 @@ void ActiveObjectMgr::removeObject(u16 id)
115
115
void ActiveObjectMgr::getObjectsInsideRadius (
116
116
const v3f &pos, float radius, std::vector<u16> &result)
117
117
{
118
+ float r2 = radius * radius;
118
119
for (auto &activeObject : m_active_objects) {
119
120
ServerActiveObject *obj = activeObject.second ;
120
121
u16 id = activeObject.first ;
121
122
const v3f &objectpos = obj->getBasePosition ();
122
- if (objectpos.getDistanceFrom (pos) > radius )
123
+ if (objectpos.getDistanceFromSQ (pos) > r2 )
123
124
continue ;
124
125
result.push_back (id);
125
126
}
You can’t perform that action at this time.
0 commit comments