Skip to content

Commit

Permalink
xrEngine: use range-based for
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Dec 19, 2017
1 parent 4807cad commit dbcfab6
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 82 deletions.
29 changes: 10 additions & 19 deletions src/xrEngine/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ void CEnvironment::lerp(float& current_weight)

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

// final lerp
CurrentEnv->lerp(this, *Current[0], *Current[1], current_weight, EM, mpower);
Expand Down Expand Up @@ -600,33 +600,24 @@ SThunderboltCollection* CEnvironment::thunderbolt_collection(CInifile* pIni, CIn
SThunderboltCollection* CEnvironment::thunderbolt_collection(
xr_vector<SThunderboltCollection*>& collection, shared_str const& id)
{
typedef xr_vector<SThunderboltCollection*> Container;
Container::iterator i = collection.begin();
Container::iterator e = collection.end();
for (; i != e; ++i)
if ((*i)->section == id)
return (*i);
for (auto& it : collection)
if (it->section == id)
return it;

NODEFAULT;
#ifdef DEBUG
return (0);
return nullptr;
#endif // #ifdef DEBUG
}

CLensFlareDescriptor* CEnvironment::add_flare(xr_vector<CLensFlareDescriptor*>& collection, shared_str const& id)
{
typedef xr_vector<CLensFlareDescriptor*> Flares;

Flares::const_iterator i = collection.begin();
Flares::const_iterator e = collection.end();
for (; i != e; ++i)
{
if ((*i)->section == id)
return (*i);
}
for (const auto& it: collection)
if (it->section == id)
return it;

CLensFlareDescriptor* result = new CLensFlareDescriptor();
result->load(m_suns_config, id.c_str());
collection.push_back(result);
return (result);
return result;
}
14 changes: 6 additions & 8 deletions src/xrEngine/IGame_Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,21 +282,19 @@ void IGame_Level::SoundEvent_Register(ref_sound_data_ptr S, float range)
g_SpatialSpace->q_box(snd_ER, 0, STYPE_REACTTOSOUND, snd_position, bb_size);

// Iterate
xr_vector<ISpatial*>::iterator it = snd_ER.begin();
xr_vector<ISpatial*>::iterator end = snd_ER.end();
for (; it != end; it++)
for (auto& it : snd_ER)
{
Feel::Sound* L = (*it)->dcast_FeelSound();
Feel::Sound* L = it->dcast_FeelSound();
if (0 == L)
continue;
IGameObject* CO = (*it)->dcast_GameObject();
IGameObject* CO = it->dcast_GameObject();
VERIFY(CO);
if (CO->getDestroy())
continue;

// Energy and signal
VERIFY(_valid((*it)->GetSpatialData().sphere.P));
float dist = snd_position.distance_to((*it)->GetSpatialData().sphere.P);
VERIFY(_valid(it->GetSpatialData().sphere.P));
float dist = snd_position.distance_to(it->GetSpatialData().sphere.P);
if (dist > p->max_ai_distance)
continue;
VERIFY(_valid(dist));
Expand All @@ -305,7 +303,7 @@ void IGame_Level::SoundEvent_Register(ref_sound_data_ptr S, float range)
VERIFY(_valid(Power));
if (Power > EPS_S)
{
float occ = Sound->get_occlusion_to((*it)->GetSpatialData().sphere.P, snd_position);
float occ = Sound->get_occlusion_to(it->GetSpatialData().sphere.P, snd_position);
VERIFY(_valid(occ));
Power *= occ;
if (Power > EPS_S)
Expand Down
6 changes: 2 additions & 4 deletions src/xrEngine/IGame_ObjectPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ void IGame_ObjectPool::prefetch()
void IGame_ObjectPool::clear()
{
// Clear POOL
ObjectVecIt it = m_PrefetchObjects.begin();
ObjectVecIt itE = m_PrefetchObjects.end();
for (; it != itE; it++)
xr_delete(*it);
for (auto& it : m_PrefetchObjects)
xr_delete(it);
m_PrefetchObjects.clear();
}

Expand Down
3 changes: 1 addition & 2 deletions src/xrEngine/IGame_ObjectPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class ENGINE_API IGame_ObjectPool
private:
POOL map_POOL;
*/
typedef xr_vector<IGameObject*> ObjectVec;
typedef ObjectVec::iterator ObjectVecIt;
using ObjectVec = xr_vector<IGameObject*>;
ObjectVec m_PrefetchObjects;

public:
Expand Down
27 changes: 10 additions & 17 deletions src/xrEngine/XR_IOConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,10 @@ void CConsole::DrawBackgrounds(bool bGame)
return;
}

LPCSTR max_str = "xxxxx";
vecTipsEx::iterator itb = m_tips.begin();
vecTipsEx::iterator ite = m_tips.end();
for (; itb != ite; ++itb)
{
if (pFont->SizeOf_((*itb).text.c_str()) > pFont->SizeOf_(max_str))
{
max_str = (*itb).text.c_str();
}
}
pcstr max_str = "xxxxx";
for (auto& it : m_tips)
if (pFont->SizeOf_(it.text.c_str()) > pFont->SizeOf_(max_str))
max_str = it.text.c_str();

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

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

vecTips::iterator itb = in_v.begin();
vecTips::iterator ite = in_v.end();
for (; itb != ite; ++itb)
//vecTips::iterator itb = in_v.begin();
//vecTips::iterator ite = in_v.end();
//for (; itb != ite; ++itb)
for (auto& it : in_v)
{
shared_str const& str = (*itb);
shared_str const& str = it;
if (all)
{
out_v.push_back(TipString(str));
}
else
{
LPCSTR fd_str = strstr(str.c_str(), filter_str);
pcstr fd_str = strstr(str.c_str(), filter_str);
if (fd_str)
{
int fd_sz = str.size() - xr_strlen(fd_str);
Expand Down
57 changes: 25 additions & 32 deletions src/xrEngine/xr_object_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ CObjectList::~CObjectList()

IGameObject* CObjectList::FindObjectByName(shared_str name)
{
for (Objects::iterator I = objects_active.begin(); I != objects_active.end(); I++)
if ((*I)->cName().equal(name))
return (*I);
for (Objects::iterator I = objects_sleeping.begin(); I != objects_sleeping.end(); I++)
if ((*I)->cName().equal(name))
return (*I);
return NULL;
for (auto it : objects_active)
if (it->cName().equal(name))
return it;

for (auto& it : objects_sleeping)
if (it->cName().equal(name))
return it;

return nullptr;
}
IGameObject* CObjectList::FindObjectByName(LPCSTR name) { return FindObjectByName(shared_str(name)); }
IGameObject* CObjectList::FindObjectByCLS_ID(CLASS_ID cls)
Expand Down Expand Up @@ -297,17 +299,15 @@ void CObjectList::Update(bool bForce)
for (int it = destroy_queue.size() - 1; it >= 0; it--)
Sound->object_relcase(destroy_queue[it]);

RELCASE_CALLBACK_VEC::iterator It = m_relcase_callbacks.begin();
RELCASE_CALLBACK_VEC::iterator Ite = m_relcase_callbacks.end();
for (; It != Ite; ++It)
RELCASE_CALLBACK_VEC::iterator it = m_relcase_callbacks.begin();
const RELCASE_CALLBACK_VEC::iterator ite = m_relcase_callbacks.end();
for (; it != ite; ++it)
{
VERIFY(*(*It).m_ID == (It - m_relcase_callbacks.begin()));
Objects::iterator dIt = destroy_queue.begin();
Objects::iterator dIte = destroy_queue.end();
for (; dIt != dIte; ++dIt)
VERIFY(*(*it).m_ID == (it - m_relcase_callbacks.begin()));
for (auto& dit : destroy_queue)
{
(*It).m_Callback(*dIt);
g_hud->net_Relcase(*dIt);
(*it).m_Callback(dit);
g_hud->net_Relcase(dit);
}
}

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

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

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

Objects::iterator it = objects_active.begin();
Objects::iterator it_e = objects_active.end();
for (; it != it_e; ++it)
for (auto& it : objects_active)
{
IGameObject* O = *it;
IGameObject* O = it;
if (!O->getDestroy() && O->H_Parent() == object_to_destroy)
{
Msg("setDestroy called, but not-destroyed child found parent[%d] child[%d]", object_to_destroy->ID(),
O->ID(), Device.dwFrame);
O->setDestroy(TRUE);
O->setDestroy(true);
}
}

it = objects_sleeping.begin();
it_e = objects_sleeping.end();
for (; it != it_e; ++it)
for (auto& it : objects_sleeping)
{
IGameObject* O = *it;
IGameObject* O = it;
if (!O->getDestroy() && O->H_Parent() == object_to_destroy)
{
Msg("setDestroy called, but not-destroyed child found parent[%d] child[%d]", object_to_destroy->ID(),
O->ID(), Device.dwFrame);
O->setDestroy(TRUE);
O->setDestroy(true);
}
}
}
Expand Down

0 comments on commit dbcfab6

Please sign in to comment.