Skip to content

Commit dbcfab6

Browse files
committed
xrEngine: use range-based for
1 parent 4807cad commit dbcfab6

File tree

6 files changed

+54
-82
lines changed

6 files changed

+54
-82
lines changed

src/xrEngine/Environment.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ void CEnvironment::lerp(float& current_weight)
433433

434434
Fvector view = Device.vCameraPosition;
435435
float mpower = 0;
436-
for (xr_vector<CEnvModifier>::iterator mit = Modifiers.begin(); mit != Modifiers.end(); mit++)
437-
mpower += EM.sum(*mit, view);
436+
for (auto& mit : Modifiers)
437+
mpower += EM.sum(mit, view);
438438

439439
// final lerp
440440
CurrentEnv->lerp(this, *Current[0], *Current[1], current_weight, EM, mpower);
@@ -600,33 +600,24 @@ SThunderboltCollection* CEnvironment::thunderbolt_collection(CInifile* pIni, CIn
600600
SThunderboltCollection* CEnvironment::thunderbolt_collection(
601601
xr_vector<SThunderboltCollection*>& collection, shared_str const& id)
602602
{
603-
typedef xr_vector<SThunderboltCollection*> Container;
604-
Container::iterator i = collection.begin();
605-
Container::iterator e = collection.end();
606-
for (; i != e; ++i)
607-
if ((*i)->section == id)
608-
return (*i);
603+
for (auto& it : collection)
604+
if (it->section == id)
605+
return it;
609606

610607
NODEFAULT;
611608
#ifdef DEBUG
612-
return (0);
609+
return nullptr;
613610
#endif // #ifdef DEBUG
614611
}
615612

616613
CLensFlareDescriptor* CEnvironment::add_flare(xr_vector<CLensFlareDescriptor*>& collection, shared_str const& id)
617614
{
618-
typedef xr_vector<CLensFlareDescriptor*> Flares;
619-
620-
Flares::const_iterator i = collection.begin();
621-
Flares::const_iterator e = collection.end();
622-
for (; i != e; ++i)
623-
{
624-
if ((*i)->section == id)
625-
return (*i);
626-
}
615+
for (const auto& it: collection)
616+
if (it->section == id)
617+
return it;
627618

628619
CLensFlareDescriptor* result = new CLensFlareDescriptor();
629620
result->load(m_suns_config, id.c_str());
630621
collection.push_back(result);
631-
return (result);
622+
return result;
632623
}

src/xrEngine/IGame_Level.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,21 +282,19 @@ void IGame_Level::SoundEvent_Register(ref_sound_data_ptr S, float range)
282282
g_SpatialSpace->q_box(snd_ER, 0, STYPE_REACTTOSOUND, snd_position, bb_size);
283283

284284
// Iterate
285-
xr_vector<ISpatial*>::iterator it = snd_ER.begin();
286-
xr_vector<ISpatial*>::iterator end = snd_ER.end();
287-
for (; it != end; it++)
285+
for (auto& it : snd_ER)
288286
{
289-
Feel::Sound* L = (*it)->dcast_FeelSound();
287+
Feel::Sound* L = it->dcast_FeelSound();
290288
if (0 == L)
291289
continue;
292-
IGameObject* CO = (*it)->dcast_GameObject();
290+
IGameObject* CO = it->dcast_GameObject();
293291
VERIFY(CO);
294292
if (CO->getDestroy())
295293
continue;
296294

297295
// Energy and signal
298-
VERIFY(_valid((*it)->GetSpatialData().sphere.P));
299-
float dist = snd_position.distance_to((*it)->GetSpatialData().sphere.P);
296+
VERIFY(_valid(it->GetSpatialData().sphere.P));
297+
float dist = snd_position.distance_to(it->GetSpatialData().sphere.P);
300298
if (dist > p->max_ai_distance)
301299
continue;
302300
VERIFY(_valid(dist));
@@ -305,7 +303,7 @@ void IGame_Level::SoundEvent_Register(ref_sound_data_ptr S, float range)
305303
VERIFY(_valid(Power));
306304
if (Power > EPS_S)
307305
{
308-
float occ = Sound->get_occlusion_to((*it)->GetSpatialData().sphere.P, snd_position);
306+
float occ = Sound->get_occlusion_to(it->GetSpatialData().sphere.P, snd_position);
309307
VERIFY(_valid(occ));
310308
Power *= occ;
311309
if (Power > EPS_S)

src/xrEngine/IGame_ObjectPool.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ void IGame_ObjectPool::prefetch()
3535
void IGame_ObjectPool::clear()
3636
{
3737
// Clear POOL
38-
ObjectVecIt it = m_PrefetchObjects.begin();
39-
ObjectVecIt itE = m_PrefetchObjects.end();
40-
for (; it != itE; it++)
41-
xr_delete(*it);
38+
for (auto& it : m_PrefetchObjects)
39+
xr_delete(it);
4240
m_PrefetchObjects.clear();
4341
}
4442

src/xrEngine/IGame_ObjectPool.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class ENGINE_API IGame_ObjectPool
1818
private:
1919
POOL map_POOL;
2020
*/
21-
typedef xr_vector<IGameObject*> ObjectVec;
22-
typedef ObjectVec::iterator ObjectVecIt;
21+
using ObjectVec = xr_vector<IGameObject*>;
2322
ObjectVec m_PrefetchObjects;
2423

2524
public:

src/xrEngine/XR_IOConsole.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,10 @@ void CConsole::DrawBackgrounds(bool bGame)
380380
return;
381381
}
382382

383-
LPCSTR max_str = "xxxxx";
384-
vecTipsEx::iterator itb = m_tips.begin();
385-
vecTipsEx::iterator ite = m_tips.end();
386-
for (; itb != ite; ++itb)
387-
{
388-
if (pFont->SizeOf_((*itb).text.c_str()) > pFont->SizeOf_(max_str))
389-
{
390-
max_str = (*itb).text.c_str();
391-
}
392-
}
383+
pcstr max_str = "xxxxx";
384+
for (auto& it : m_tips)
385+
if (pFont->SizeOf_(it.text.c_str()) > pFont->SizeOf_(max_str))
386+
max_str = it.text.c_str();
393387

394388
float w1 = pFont->SizeOf_("_");
395389
float ioc_w = pFont->SizeOf_(ioc_prompt) - w1;
@@ -908,18 +902,17 @@ void CConsole::select_for_filter(LPCSTR filter_str, vecTips& in_v, vecTipsEx& ou
908902

909903
bool all = (xr_strlen(filter_str) == 0);
910904

911-
vecTips::iterator itb = in_v.begin();
912-
vecTips::iterator ite = in_v.end();
913-
for (; itb != ite; ++itb)
905+
//vecTips::iterator itb = in_v.begin();
906+
//vecTips::iterator ite = in_v.end();
907+
//for (; itb != ite; ++itb)
908+
for (auto& it : in_v)
914909
{
915-
shared_str const& str = (*itb);
910+
shared_str const& str = it;
916911
if (all)
917-
{
918912
out_v.push_back(TipString(str));
919-
}
920913
else
921914
{
922-
LPCSTR fd_str = strstr(str.c_str(), filter_str);
915+
pcstr fd_str = strstr(str.c_str(), filter_str);
923916
if (fd_str)
924917
{
925918
int fd_sz = str.size() - xr_strlen(fd_str);

src/xrEngine/xr_object_list.cpp

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ CObjectList::~CObjectList()
5454

5555
IGameObject* CObjectList::FindObjectByName(shared_str name)
5656
{
57-
for (Objects::iterator I = objects_active.begin(); I != objects_active.end(); I++)
58-
if ((*I)->cName().equal(name))
59-
return (*I);
60-
for (Objects::iterator I = objects_sleeping.begin(); I != objects_sleeping.end(); I++)
61-
if ((*I)->cName().equal(name))
62-
return (*I);
63-
return NULL;
57+
for (auto it : objects_active)
58+
if (it->cName().equal(name))
59+
return it;
60+
61+
for (auto& it : objects_sleeping)
62+
if (it->cName().equal(name))
63+
return it;
64+
65+
return nullptr;
6466
}
6567
IGameObject* CObjectList::FindObjectByName(LPCSTR name) { return FindObjectByName(shared_str(name)); }
6668
IGameObject* CObjectList::FindObjectByCLS_ID(CLASS_ID cls)
@@ -297,17 +299,15 @@ void CObjectList::Update(bool bForce)
297299
for (int it = destroy_queue.size() - 1; it >= 0; it--)
298300
Sound->object_relcase(destroy_queue[it]);
299301

300-
RELCASE_CALLBACK_VEC::iterator It = m_relcase_callbacks.begin();
301-
RELCASE_CALLBACK_VEC::iterator Ite = m_relcase_callbacks.end();
302-
for (; It != Ite; ++It)
302+
RELCASE_CALLBACK_VEC::iterator it = m_relcase_callbacks.begin();
303+
const RELCASE_CALLBACK_VEC::iterator ite = m_relcase_callbacks.end();
304+
for (; it != ite; ++it)
303305
{
304-
VERIFY(*(*It).m_ID == (It - m_relcase_callbacks.begin()));
305-
Objects::iterator dIt = destroy_queue.begin();
306-
Objects::iterator dIte = destroy_queue.end();
307-
for (; dIt != dIte; ++dIt)
306+
VERIFY(*(*it).m_ID == (it - m_relcase_callbacks.begin()));
307+
for (auto& dit : destroy_queue)
308308
{
309-
(*It).m_Callback(*dIt);
310-
g_hud->net_Relcase(*dIt);
309+
(*it).m_Callback(dit);
310+
g_hud->net_Relcase(dit);
311311
}
312312
}
313313

@@ -567,13 +567,10 @@ void CObjectList::relcase_unregister(int* ID)
567567

568568
void CObjectList::dump_list(Objects& v, LPCSTR reason)
569569
{
570-
Objects::iterator it = v.begin();
571-
Objects::iterator it_e = v.end();
572570
#ifdef DEBUG
573-
Msg("----------------dump_list [%s]", reason);
574-
for (; it != it_e; ++it)
575-
Msg("%x - name [%s] ID[%d] parent[%s] getDestroy()=[%s]", (*it), (*it)->cName().c_str(), (*it)->ID(),
576-
((*it)->H_Parent()) ? (*it)->H_Parent()->cName().c_str() : "", ((*it)->getDestroy()) ? "yes" : "no");
571+
for (auto& it : v)
572+
Msg("%x - name [%s] ID[%d] parent[%s] getDestroy()=[%s]", it, it->cName().c_str(), it->ID(),
573+
it->H_Parent() ? it->H_Parent()->cName().c_str() : "", it->getDestroy() ? "yes" : "no");
577574
#endif // #ifdef DEBUG
578575
}
579576

@@ -593,29 +590,25 @@ void CObjectList::register_object_to_destroy(IGameObject* object_to_destroy)
593590
// Msg("CObjectList::register_object_to_destroy [%x]", object_to_destroy);
594591
destroy_queue.push_back(object_to_destroy);
595592

596-
Objects::iterator it = objects_active.begin();
597-
Objects::iterator it_e = objects_active.end();
598-
for (; it != it_e; ++it)
593+
for (auto& it : objects_active)
599594
{
600-
IGameObject* O = *it;
595+
IGameObject* O = it;
601596
if (!O->getDestroy() && O->H_Parent() == object_to_destroy)
602597
{
603598
Msg("setDestroy called, but not-destroyed child found parent[%d] child[%d]", object_to_destroy->ID(),
604599
O->ID(), Device.dwFrame);
605-
O->setDestroy(TRUE);
600+
O->setDestroy(true);
606601
}
607602
}
608603

609-
it = objects_sleeping.begin();
610-
it_e = objects_sleeping.end();
611-
for (; it != it_e; ++it)
604+
for (auto& it : objects_sleeping)
612605
{
613-
IGameObject* O = *it;
606+
IGameObject* O = it;
614607
if (!O->getDestroy() && O->H_Parent() == object_to_destroy)
615608
{
616609
Msg("setDestroy called, but not-destroyed child found parent[%d] child[%d]", object_to_destroy->ID(),
617610
O->ID(), Device.dwFrame);
618-
O->setDestroy(TRUE);
611+
O->setDestroy(true);
619612
}
620613
}
621614
}

0 commit comments

Comments
 (0)