18
18
19
19
#define RECT_SIZE 16
20
20
21
- struct FindVisObjByObject
22
- {
23
- const CObject* O;
24
- FindVisObjByObject (const CObject* o) : O(o) {}
25
- bool operator ()(const SBinocVisibleObj* vis) { return (O == vis->m_object ); }
26
- };
27
-
28
21
void SBinocVisibleObj::create_default (u32 color)
29
22
{
30
23
m_lt.Init (" ui\\ ui_enemy_frame" , 0 , 0 , RECT_SIZE, RECT_SIZE);
@@ -155,7 +148,6 @@ CBinocularsVision::CBinocularsVision(CWeaponMagazined* parent)
155
148
CBinocularsVision::~CBinocularsVision ()
156
149
{
157
150
m_snd_found.destroy ();
158
- delete_data (m_active_objects);
159
151
}
160
152
161
153
void CBinocularsVision::Update ()
@@ -170,9 +162,8 @@ void CBinocularsVision::Update()
170
162
171
163
const CVisualMemoryManager::VISIBLES& vVisibles = pActor->memory ().visual ().objects ();
172
164
173
- VIS_OBJECTS_IT it = m_active_objects.begin ();
174
- for (; it != m_active_objects.end (); ++it)
175
- (*it)->m_flags .set (flVisObjNotValid, TRUE );
165
+ for (auto & vis : m_active_objects)
166
+ vis->m_flags .set (flVisObjNotValid, TRUE );
176
167
177
168
CVisualMemoryManager::VISIBLES::const_iterator v_it = vVisibles.begin ();
178
169
for (; v_it != vVisibles.end (); ++v_it)
@@ -190,18 +181,15 @@ void CBinocularsVision::Update()
190
181
if (!EA || !EA->g_Alive ())
191
182
continue ;
192
183
193
- FindVisObjByObject f (object_);
194
- VIS_OBJECTS_IT found;
195
- found = std::find_if (m_active_objects.begin (), m_active_objects.end (), f);
184
+ auto found = std::find_if (m_active_objects.begin (), m_active_objects.end (), [object_](const auto & vis) { return (object_ == vis->m_object ); });
196
185
197
186
if (found != m_active_objects.end ())
198
187
{
199
188
(*found)->m_flags .set (flVisObjNotValid, FALSE );
200
189
}
201
190
else
202
191
{
203
- m_active_objects.push_back (xr_new<SBinocVisibleObj>());
204
- SBinocVisibleObj* new_vis_obj = m_active_objects.back ();
192
+ auto & new_vis_obj = m_active_objects.emplace_back (std::make_unique<SBinocVisibleObj>());
205
193
new_vis_obj->m_flags .set (flVisObjNotValid, FALSE );
206
194
new_vis_obj->m_object = object_;
207
195
new_vis_obj->create_default (m_frame_color.get ());
@@ -211,17 +199,18 @@ void CBinocularsVision::Update()
211
199
m_snd_found.play_at_pos (0 , Fvector ().set (0 , 0 , 0 ), sm_2D);
212
200
}
213
201
}
214
- std::sort (m_active_objects.begin (), m_active_objects.end ());
215
-
216
- while (m_active_objects.size () && m_active_objects.back ()->m_flags .test (flVisObjNotValid))
217
- {
218
- xr_delete (m_active_objects.back ());
219
- m_active_objects.pop_back ();
220
- }
221
202
222
- it = m_active_objects.begin ();
223
- for (; it != m_active_objects.end (); ++it)
224
- (*it)->Update ();
203
+ m_active_objects.erase (std::remove_if (m_active_objects.begin (), m_active_objects.end (),
204
+ [](auto & vis) {
205
+ if (vis->m_flags .test (flVisObjNotValid))
206
+ return true ;
207
+ else
208
+ {
209
+ vis->Update ();
210
+ return false ;
211
+ }
212
+ }),
213
+ m_active_objects.end ());
225
214
}
226
215
227
216
void CBinocularsVision::Draw ()
@@ -231,8 +220,8 @@ void CBinocularsVision::Draw()
231
220
if (Device.m_SecondViewport .IsSVPActive ())
232
221
return ;
233
222
234
- for (auto * it : m_active_objects)
235
- it ->Draw ();
223
+ for (auto & vis : m_active_objects)
224
+ vis ->Draw ();
236
225
}
237
226
238
227
void CBinocularsVision::Load (const shared_str& section)
@@ -246,11 +235,6 @@ void CBinocularsVision::Load(const shared_str& section)
246
235
247
236
void CBinocularsVision::remove_links (CObject* object)
248
237
{
249
- #pragma todo("KRodin: во-первых, тут утечка, во-вторых, удалять принято через ремове_иф, в третьих - нечего вообще в m_active_objects хранить указатели.")
250
-
251
- VIS_OBJECTS::iterator I = std::find_if (m_active_objects.begin (), m_active_objects.end (), FindVisObjByObject (object));
252
- if (I == m_active_objects.end ())
253
- return ;
254
-
255
- m_active_objects.erase (I);
238
+ m_active_objects.erase (std::remove_if (m_active_objects.begin (), m_active_objects.end (), [object](const auto & vis) { return (object == vis->m_object ); }),
239
+ m_active_objects.end ());
256
240
}
0 commit comments