Skip to content

Commit

Permalink
Replace iterator for cycles with range-based for
Browse files Browse the repository at this point in the history
Add XXX in xrGame/UIDragDropListEx.cpp
  • Loading branch information
Xottab-DUTY committed Dec 18, 2017
1 parent 2748b74 commit 8eff473
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 34 deletions.
10 changes: 4 additions & 6 deletions src/xrGame/AmebaZone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ bool CAmebaZone::BlowoutState()
if (!result)
UpdateBlowout();

// XXX: use range-based for
for (OBJECT_INFO_VEC::iterator it = m_ObjectInfoMap.begin(); m_ObjectInfoMap.end() != it; ++it)
Affect(&(*it));
for (auto& it : m_ObjectInfoMap)
Affect(&it);

return result;
}
Expand Down Expand Up @@ -66,10 +65,9 @@ void CAmebaZone::Affect(SZoneObjectInfo* O)

void CAmebaZone::PhTune(float step)
{
// XXX: use range-based for
for (OBJECT_INFO_VEC::iterator it = m_ObjectInfoMap.begin(); m_ObjectInfoMap.end() != it; ++it)
for (auto& it : m_ObjectInfoMap)
{
CEntityAlive* EA = smart_cast<CEntityAlive*>((*it).object);
auto EA = smart_cast<CEntityAlive*>(it.object);
if (EA)
{
CPHMovementControl* mc = EA->character_physics_support()->movement();
Expand Down
19 changes: 8 additions & 11 deletions src/xrGame/alife_storage_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,21 @@ void CALifeStorageManager::load(void* buffer, const u32& buffer_size, LPCSTR fil

VERIFY(can_register_objects());
can_register_objects(false);
// XXX: Replace with range-based for
CALifeObjectRegistry::OBJECT_REGISTRY::iterator B = objects().objects().begin();
CALifeObjectRegistry::OBJECT_REGISTRY::iterator E = objects().objects().end();
CALifeObjectRegistry::OBJECT_REGISTRY::iterator I;
for (I = B; I != E; ++I)

for (auto& object : objects().objects())
{
ALife::_OBJECT_ID id = (*I).second->ID;
(*I).second->ID = server().PerformIDgen(id);
VERIFY(id == (*I).second->ID);
register_object((*I).second, false);
ALife::_OBJECT_ID id = object.second->ID;
object.second->ID = server().PerformIDgen(id);
VERIFY(id == object.second->ID);
register_object(object.second, false);
}

registry().load(source);

can_register_objects(true);

for (I = B; I != E; ++I)
(*I).second->on_register();
for (auto& object : objects().objects())
object.second->on_register();

if (!g_pGameLevel)
return;
Expand Down
9 changes: 3 additions & 6 deletions src/xrGame/alife_trader_abstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,14 @@ void add_online_impl(CSE_ALifeDynamicObject* object, const bool& update_registri
clientID.set(
object->alife().server().GetServerClient() ? object->alife().server().GetServerClient()->ID.value() : 0);

// XXX: Replace with range-based for
ALife::OBJECT_IT I = object->children.begin();
ALife::OBJECT_IT E = object->children.end();
for (; I != E; ++I)
for (auto& it : object->children)
{
//Alundaio:
if (*I == ai().alife().graph().actor()->ID)
if (it == ai().alife().graph().actor()->ID)
continue;
//-Alundaio

CSE_ALifeDynamicObject* l_tpALifeDynamicObject = ai().alife().objects().object(*I);
CSE_ALifeDynamicObject* l_tpALifeDynamicObject = ai().alife().objects().object(it);
if (!l_tpALifeDynamicObject)
continue;

Expand Down
9 changes: 4 additions & 5 deletions src/xrGame/ui/UIActorMenuInventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,11 @@ bool CUIActorMenu::ToSlot(CUICellItem* itm, bool force_place, u16 slot_id)
else
{
//Alundaio: Since the player's inventory is being used as a slot we need to search for cell with matching m_pData
CUICellContainer* c = slot_list->GetContainer();
WINDOW_LIST child_list = c->GetChildWndList();
// XXX: try to replace with range-based for
for (WINDOW_LIST::iterator it = child_list.begin(); child_list.end() != it; ++it)
auto container = slot_list->GetContainer();
auto child_list = container->GetChildWndList();
for (auto& it : child_list)
{
CUICellItem* i = static_cast<CUICellItem*>(*it);
CUICellItem* i = static_cast<CUICellItem*>(it);
const PIItem pitm = static_cast<PIItem>(i->m_pData);
if (pitm == _iitem)
{
Expand Down
14 changes: 8 additions & 6 deletions src/xrGame/ui/UIDragDropListEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,17 @@ bool CUICellContainer::AddSimilar(CUICellItem* itm)

CUICellItem* CUICellContainer::FindSimilar(CUICellItem* itm)
{
// XXX: try to replace with range-based for
for (auto it = m_ChildWndList.begin(); m_ChildWndList.end() != it; ++it)
for (auto& it : m_ChildWndList)
{
// XXX: Xottab_DUTY: find out why different casts used for different configurations
// and maybe use only one cast
#ifdef DEBUG
CUICellItem* i = smart_cast<CUICellItem*>(*it);
auto i = smart_cast<CUICellItem*>(it);
#else
CUICellItem* i = (CUICellItem*)(*it);
auto i = (CUICellItem*)it;
#endif
//Alundaio: Don't stack equipped items
PIItem iitem = static_cast<PIItem>(i->m_pData);
auto iitem = static_cast<PIItem>(i->m_pData);
if (iitem && iitem->m_pInventory && iitem->m_pInventory->ItemFromSlot(iitem->BaseSlot()) == iitem)
continue;
//-Alundaio
Expand All @@ -519,7 +520,8 @@ CUICellItem* CUICellContainer::FindSimilar(CUICellItem* itm)
if (i->EqualTo(itm))
return i;
}
return NULL;

return nullptr;
}

void CUICellContainer::PlaceItemAtPos(CUICellItem* itm, Ivector2& cell_pos)
Expand Down

0 comments on commit 8eff473

Please sign in to comment.