Skip to content

Commit

Permalink
Use AutoObj to simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
LAGonauta committed Dec 17, 2023
1 parent efe75e6 commit c88e080
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
11 changes: 5 additions & 6 deletions include/Effects/EnvEffects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ namespace MetaAudio

struct effectSlot
{
alure::AuxiliaryEffectSlot slot;
alure::Effect effect;
alure::AutoObj<alure::AuxiliaryEffectSlot> slot;
alure::AutoObj<alure::Effect> effect;
GainFading gain;
effectSlot(alure::AuxiliaryEffectSlot _slot, alure::Effect _effect)
effectSlot(alure::AuxiliaryEffectSlot slot, alure::Effect effect)
: slot(alure::MakeAuto(slot)),
effect(alure::MakeAuto(effect))
{
slot = _slot;
effect = _effect;
};
};

Expand Down Expand Up @@ -82,7 +82,6 @@ namespace MetaAudio

public:
EnvEffects(alure::Context& al_context, ALCuint max_sends, std::shared_ptr<IOcclusionCalculator> occlusion_calculator);
~EnvEffects();

void InterplEffect(int roomtype);
void ApplyEffect(aud_channel_t* ch, qboolean underwater);
Expand Down
23 changes: 7 additions & 16 deletions src/Effects/EnvEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ namespace MetaAudio
alAuxEffectSlots[effect_slot].gain.target = AL_REVERBMIX;
FadeToNewValue(true, false, alAuxEffectSlots[effect_slot].gain);

alAuxEffectSlots[effect_slot].effect.setReverbProperties(desired);
alAuxEffectSlots[effect_slot].effect->setReverbProperties(desired);
}
}
else if (alAuxEffectSlots.size() == 1)
{
alAuxEffectSlots[0].effect.setReverbProperties(desired);
alAuxEffectSlots[0].effect->setReverbProperties(desired);
}

for (auto& effectSlot : alAuxEffectSlots)
{
effectSlot.slot.setGain(effectSlot.gain.current);
effectSlot.slot.applyEffect(effectSlot.effect);
effectSlot.slot->setGain(effectSlot.gain.current);
effectSlot.slot->applyEffect(effectSlot.effect.get());
}
}

Expand Down Expand Up @@ -177,7 +177,7 @@ namespace MetaAudio

for (size_t i = 0; i < alAuxEffectSlots.size(); ++i)
{
ch->sound_source->SetAuxiliarySendFilter(alAuxEffectSlots[i].slot, i, params);
ch->sound_source->SetAuxiliarySendFilter(alAuxEffectSlots[i].slot.get(), i, params);
}
}

Expand Down Expand Up @@ -211,15 +211,15 @@ namespace MetaAudio

if (alAuxEffectSlots.size() > 0)
{
alAuxEffectSlots[0].slot.setGain(AL_REVERBMIX);
alAuxEffectSlots[0].slot->setGain(AL_REVERBMIX);
alAuxEffectSlots[0].gain.current = AL_REVERBMIX;
alAuxEffectSlots[0].gain.initial_value = AL_REVERBMIX;
alAuxEffectSlots[0].gain.last_target = AL_REVERBMIX;
alAuxEffectSlots[0].gain.target = AL_REVERBMIX;

if (alAuxEffectSlots.size() > 1)
{
alAuxEffectSlots[1].slot.setGain(0.0f);
alAuxEffectSlots[1].slot->setGain(0.0f);
}
}

Expand Down Expand Up @@ -385,13 +385,4 @@ namespace MetaAudio
}
}
}

EnvEffects::~EnvEffects()
{
for (auto& effectSlot : alAuxEffectSlots)
{
effectSlot.slot.destroy();
effectSlot.effect.destroy();
}
}
}

0 comments on commit c88e080

Please sign in to comment.