Skip to content

Commit

Permalink
xrGame/HudSound.cpp: use range-based for instead of iterators
Browse files Browse the repository at this point in the history
Also code cleanup
  • Loading branch information
Xottab-DUTY committed Dec 16, 2017
1 parent d52aaea commit 4da9bb6
Showing 1 changed file with 40 additions and 82 deletions.
122 changes: 40 additions & 82 deletions src/xrGame/HudSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

float psHUDSoundVolume = 1.0f;
float psHUDStepSoundVolume = 1.0f;

void InitHudSoundSettings()
{
psHUDSoundVolume = pSettings->r_float("hud_sound", "hud_sound_vol_k");
Expand All @@ -12,7 +13,7 @@ void InitHudSoundSettings()

void HUD_SOUND_ITEM::LoadSound(LPCSTR section, LPCSTR line, HUD_SOUND_ITEM& hud_snd, int type)
{
hud_snd.m_activeSnd = NULL;
hud_snd.m_activeSnd = nullptr;
hud_snd.sounds.clear();

string256 sound_line;
Expand All @@ -39,7 +40,7 @@ void HUD_SOUND_ITEM::LoadSound(LPCSTR section, LPCSTR line, ref_sound& snd, int
_GetItem(str, 0, buf_str);
snd.create(buf_str, st_Effect, type);

if (volume != NULL)
if (volume != nullptr)
{
*volume = 1.f;
if (count > 1)
Expand All @@ -50,7 +51,7 @@ void HUD_SOUND_ITEM::LoadSound(LPCSTR section, LPCSTR line, ref_sound& snd, int
}
}

if (delay != NULL)
if (delay != nullptr)
{
*delay = 0;
if (count > 2)
Expand All @@ -64,12 +65,12 @@ void HUD_SOUND_ITEM::LoadSound(LPCSTR section, LPCSTR line, ref_sound& snd, int

void HUD_SOUND_ITEM::DestroySound(HUD_SOUND_ITEM& hud_snd)
{
xr_vector<SSnd>::iterator it = hud_snd.sounds.begin();
for (; it != hud_snd.sounds.end(); ++it)
(*it).snd.destroy();
for (auto& sound : hud_snd.sounds)
sound.snd.destroy();

hud_snd.sounds.clear();

hud_snd.m_activeSnd = NULL;
hud_snd.m_activeSnd = nullptr;
}

void HUD_SOUND_ITEM::PlaySound(
Expand All @@ -78,7 +79,7 @@ void HUD_SOUND_ITEM::PlaySound(
if (hud_snd.sounds.empty())
return;

hud_snd.m_activeSnd = NULL;
hud_snd.m_activeSnd = nullptr;
StopSound(hud_snd);

u32 flags = b_hud_mode ? sm_2D : 0;
Expand All @@ -100,22 +101,19 @@ void HUD_SOUND_ITEM::PlaySound(

void HUD_SOUND_ITEM::StopSound(HUD_SOUND_ITEM& hud_snd)
{
xr_vector<SSnd>::iterator it = hud_snd.sounds.begin();
for (; it != hud_snd.sounds.end(); ++it)
(*it).snd.stop();
hud_snd.m_activeSnd = NULL;
for (auto& sound : hud_snd.sounds)
sound.snd.stop();

hud_snd.m_activeSnd = nullptr;
}

//----------------------------------------------------------
HUD_SOUND_COLLECTION::~HUD_SOUND_COLLECTION()
{
xr_vector<HUD_SOUND_ITEM>::iterator it = m_sound_items.begin();
xr_vector<HUD_SOUND_ITEM>::iterator it_e = m_sound_items.end();

for (; it != it_e; ++it)
for (auto& sound_item : m_sound_items)
{
HUD_SOUND_ITEM::StopSound(*it);
HUD_SOUND_ITEM::DestroySound(*it);
HUD_SOUND_ITEM::StopSound(sound_item);
HUD_SOUND_ITEM::DestroySound(sound_item);
}

m_sound_items.clear();
Expand All @@ -127,23 +125,17 @@ HUD_SOUND_ITEM* HUD_SOUND_COLLECTION::FindSoundItem(LPCSTR alias, bool b_assert)

if (it != m_sound_items.end())
return &*it;
else
{
R_ASSERT3(!b_assert, "sound item not found in collection", alias);
return NULL;
}

R_ASSERT3(!b_assert, "sound item not found in collection", alias);
return nullptr;
}

void HUD_SOUND_COLLECTION::PlaySound(
LPCSTR alias, const Fvector& position, const IGameObject* parent, bool hud_mode, bool looped, u8 index)
{
xr_vector<HUD_SOUND_ITEM>::iterator it = m_sound_items.begin();
xr_vector<HUD_SOUND_ITEM>::iterator it_e = m_sound_items.end();
for (; it != it_e; ++it)
{
if (it->m_b_exclusive)
HUD_SOUND_ITEM::StopSound(*it);
}
for (auto& sound_item : m_sound_items)
if (sound_item.m_b_exclusive)
HUD_SOUND_ITEM::StopSound(sound_item);

HUD_SOUND_ITEM* snd_item = FindSoundItem(alias, true);
HUD_SOUND_ITEM::PlaySound(*snd_item, position, parent, hud_mode, looped, index);
Expand All @@ -164,13 +156,8 @@ void HUD_SOUND_COLLECTION::SetPosition(LPCSTR alias, const Fvector& pos)

void HUD_SOUND_COLLECTION::StopAllSounds()
{
xr_vector<HUD_SOUND_ITEM>::iterator it = m_sound_items.begin();
xr_vector<HUD_SOUND_ITEM>::iterator it_e = m_sound_items.end();

for (; it != it_e; ++it)
{
HUD_SOUND_ITEM::StopSound(*it);
}
for (auto& sound_item : m_sound_items)
HUD_SOUND_ITEM::StopSound(sound_item);
}

void HUD_SOUND_COLLECTION::LoadSound(LPCSTR section, LPCSTR line, LPCSTR alias, bool exclusive, int type)
Expand All @@ -192,76 +179,47 @@ void HUD_SOUND_COLLECTION::LoadSound(LPCSTR section, LPCSTR line, LPCSTR alias,
#ifdef LAYERED_SND_SHOOT
HUD_SOUND_COLLECTION_LAYERED::~HUD_SOUND_COLLECTION_LAYERED()
{
xr_vector<HUD_SOUND_COLLECTION>::iterator it = m_sound_items.begin();
xr_vector<HUD_SOUND_COLLECTION>::iterator it_e = m_sound_items.end();

for (; it != it_e; ++it)
{
it->~HUD_SOUND_COLLECTION();
}
for (auto& sound_item : m_sound_items)
sound_item.~HUD_SOUND_COLLECTION();

m_sound_items.clear();
}

void HUD_SOUND_COLLECTION_LAYERED::StopAllSounds()
{
xr_vector<HUD_SOUND_COLLECTION>::iterator it = m_sound_items.begin();
xr_vector<HUD_SOUND_COLLECTION>::iterator it_e = m_sound_items.end();

for (; it != it_e; ++it)
{
it->StopAllSounds();
}
for (auto& sound_item : m_sound_items)
sound_item.StopAllSounds();
}

void HUD_SOUND_COLLECTION_LAYERED::StopSound(pcstr alias)
{
xr_vector<HUD_SOUND_COLLECTION>::iterator it = m_sound_items.begin();
xr_vector<HUD_SOUND_COLLECTION>::iterator it_e = m_sound_items.end();

for (; it != it_e; ++it)
{
if (it->m_alias == alias)
it->StopSound(alias);
}
for (auto& sound_item : m_sound_items)
if (sound_item.m_alias == alias)
sound_item.StopSound(alias);
}

void HUD_SOUND_COLLECTION_LAYERED::SetPosition(pcstr alias, const Fvector& pos)
{
xr_vector<HUD_SOUND_COLLECTION>::iterator it = m_sound_items.begin();
xr_vector<HUD_SOUND_COLLECTION>::iterator it_e = m_sound_items.end();

for (; it != it_e; ++it)
{
if (it->m_alias == alias)
it->SetPosition(alias, pos);
}
for (auto& sound_item : m_sound_items)
if (sound_item.m_alias == alias)
sound_item.SetPosition(alias, pos);
}

void HUD_SOUND_COLLECTION_LAYERED::PlaySound(pcstr alias, const Fvector& position, const IGameObject* parent,
bool hud_mode, bool looped, u8 index)
{
xr_vector<HUD_SOUND_COLLECTION>::iterator it = m_sound_items.begin();
xr_vector<HUD_SOUND_COLLECTION>::iterator it_e = m_sound_items.end();

for (; it != it_e; ++it)
{
if (it->m_alias == alias)
it->PlaySound(alias, position, parent, hud_mode, looped, index);
}
for (auto& sound_item : m_sound_items)
if (sound_item.m_alias == alias)
sound_item.PlaySound(alias, position, parent, hud_mode, looped, index);
}


HUD_SOUND_ITEM* HUD_SOUND_COLLECTION_LAYERED::FindSoundItem(pcstr alias, bool b_assert)
{
xr_vector<HUD_SOUND_COLLECTION>::iterator it = m_sound_items.begin();
xr_vector<HUD_SOUND_COLLECTION>::iterator it_e = m_sound_items.end();
for (auto& sound_item : m_sound_items)
if (sound_item.m_alias == alias)
return sound_item.FindSoundItem(alias, b_assert);

for (; it != it_e; ++it)
{
if (it->m_alias == alias)
return it->FindSoundItem(alias, b_assert);
}
return nullptr;
}

Expand Down

0 comments on commit 4da9bb6

Please sign in to comment.