diff options
author | Chris Robinson <[email protected]> | 2023-03-10 19:58:45 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-03-10 19:58:45 -0800 |
commit | 8c3948c4de4b84805664775bbfe64516e1100ad9 (patch) | |
tree | c3325fe665867cf225d7aa1c8dde4b0b35c7576b /al/auxeffectslot.cpp | |
parent | 605fa7815948cdef42877286f85cc23ed5b3760d (diff) |
Rework EAX effect handling
Allocate a base EaxEffect object once for all effect types, instead of
reallocating different derived types on effect changes. The reverb and null
effects have been converted to the new interface, the others are currently
broken/unsupported, but will be restored shortly.
Diffstat (limited to 'al/auxeffectslot.cpp')
-rw-r--r-- | al/auxeffectslot.cpp | 142 |
1 files changed, 45 insertions, 97 deletions
diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 81929702..e716beb7 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -1052,53 +1052,45 @@ void ALeffectslot::eax_initialize(ALCcontext& al_context, EaxFxSlotIndexValue in if(index >= EAX_MAX_FXSLOTS) eax_fail("Index out of range."); - mPropsDirty = true; eax_al_context_ = &al_context; eax_fx_slot_index_ = index; - eax_version_ = eax_al_context_->eax_get_version(); eax_fx_slot_set_defaults(); + + eax_effect_ = std::make_unique<EaxEffect>(); + if(index == 0) eax_effect_->init<EaxReverbCommitter>(); + //else if(index == 1) eax_effect_->init<EaxChorusCommitter>(); + else eax_effect_->init<EaxNullCommitter>(); } void ALeffectslot::eax_commit() { - auto df = EaxDirtyFlags{}; - - switch(eax_version_) + if(eax_df_ != EaxDirtyFlags{}) { - case 1: - case 2: - case 3: - eax5_fx_slot_commit(eax123_, df); - break; - case 4: - eax4_fx_slot_commit(df); - break; - case 5: - eax5_fx_slot_commit(eax5_, df); - break; - default: - eax_fail_unknown_version(); - } - - if(df == EaxDirtyFlags{}) { - if(eax_effect_ != nullptr && eax_effect_->commit()) - eax_set_efx_slot_effect(*eax_effect_); - - return; - } + auto df = EaxDirtyFlags{}; + switch(eax_version_) + { + case 1: + case 2: + case 3: + eax5_fx_slot_commit(eax123_, df); + break; + case 4: + eax4_fx_slot_commit(df); + break; + case 5: + eax5_fx_slot_commit(eax5_, df); + break; + } + eax_df_ = EaxDirtyFlags{}; - if((df & eax_load_effect_dirty_bit) != EaxDirtyFlags{}) - eax_fx_slot_load_effect(); - else { - if(eax_effect_ != nullptr && eax_effect_->commit()) - eax_set_efx_slot_effect(*eax_effect_); + if((df & eax_volume_dirty_bit) != EaxDirtyFlags{}) + eax_fx_slot_set_volume(); + if((df & eax_flags_dirty_bit) != EaxDirtyFlags{}) + eax_fx_slot_set_flags(); } - if((df & eax_volume_dirty_bit) != EaxDirtyFlags{}) - eax_fx_slot_set_volume(); - - if((df & eax_flags_dirty_bit) != EaxDirtyFlags{}) - eax_fx_slot_set_flags(); + if(eax_effect_->do_commit(eax_version_)) + eax_set_efx_slot_effect(*eax_effect_); } [[noreturn]] void ALeffectslot::eax_fail(const char* message) @@ -1192,46 +1184,14 @@ void ALeffectslot::eax5_fx_slot_set_defaults(Eax5Props& props) noexcept props.flOcclusionLFRatio = EAXFXSLOT_DEFAULTOCCLUSIONLFRATIO; } -void ALeffectslot::eax4_fx_slot_set_current_defaults(const Eax4Props& props) noexcept -{ - static_cast<Eax4Props&>(eax_) = props; - eax_.lOcclusion = EAXFXSLOT_DEFAULTOCCLUSION; - eax_.flOcclusionLFRatio = EAXFXSLOT_DEFAULTOCCLUSIONLFRATIO; -} - -void ALeffectslot::eax5_fx_slot_set_current_defaults(const Eax5Props& props) noexcept -{ - eax_ = props; -} - -void ALeffectslot::eax_fx_slot_set_current_defaults() -{ - switch(eax_version_) - { - case 1: - case 2: - case 3: - eax5_fx_slot_set_current_defaults(eax123_.i); - break; - case 4: - eax4_fx_slot_set_current_defaults(eax4_.i); - break; - case 5: - eax5_fx_slot_set_current_defaults(eax5_.i); - break; - default: - eax_fail_unknown_version(); - } - - eax_df_ = ~EaxDirtyFlags{}; -} - void ALeffectslot::eax_fx_slot_set_defaults() { eax5_fx_slot_set_defaults(eax123_.i); eax4_fx_slot_set_defaults(eax4_.i); eax5_fx_slot_set_defaults(eax5_.i); - eax_fx_slot_set_current_defaults(); + eax_ = eax5_.i; + eax_version_ = 5; + eax_df_ = EaxDirtyFlags{}; } void ALeffectslot::eax4_fx_slot_get(const EaxCall& call, const Eax4Props& props) const @@ -1306,7 +1266,7 @@ bool ALeffectslot::eax_get(const EaxCall& call) eax_fx_slot_get(call); break; case EaxCallPropertySetId::fx_slot_effect: - eax_dispatch_effect(call); + eax_effect_->get(call); break; default: eax_fail_unknown_property_id(); @@ -1315,16 +1275,11 @@ bool ALeffectslot::eax_get(const EaxCall& call) return false; } -void ALeffectslot::eax_fx_slot_load_effect() +void ALeffectslot::eax_fx_slot_load_effect(int version, ALenum altype) { - eax_effect_ = nullptr; - const auto efx_effect_type = eax_get_efx_effect_type(eax_.guidLoadEffect); - - if(!IsValidEffectType(efx_effect_type)) - eax_fail("Invalid effect type."); - - eax_effect_ = eax_create_eax_effect(efx_effect_type, eax_version_); - eax_set_efx_slot_effect(*eax_effect_); + if(!IsValidEffectType(altype)) + altype = AL_EFFECT_NULL; + eax_effect_->set_defaults(version, altype); } void ALeffectslot::eax_fx_slot_set_volume() @@ -1395,10 +1350,14 @@ bool ALeffectslot::eax4_fx_slot_set(const EaxCall& call) break; case EAXFXSLOT_ALLPARAMETERS: eax4_fx_slot_set_all(call); + if((eax_df_ & eax_load_effect_dirty_bit)) + eax_fx_slot_load_effect(4, eax_get_efx_effect_type(dst.guidLoadEffect)); break; case EAXFXSLOT_LOADEFFECT: eax4_fx_slot_ensure_unlocked(); eax_fx_slot_set_dirty<Eax4GuidLoadEffectValidator, eax_load_effect_dirty_bit>(call, dst.guidLoadEffect, eax_df_); + if((eax_df_ & eax_load_effect_dirty_bit)) + eax_fx_slot_load_effect(4, eax_get_efx_effect_type(dst.guidLoadEffect)); break; case EAXFXSLOT_VOLUME: eax_fx_slot_set<Eax4VolumeValidator, eax_volume_dirty_bit>(call, dst.lVolume, eax_df_); @@ -1428,9 +1387,13 @@ bool ALeffectslot::eax5_fx_slot_set(const EaxCall& call) break; case EAXFXSLOT_ALLPARAMETERS: eax5_fx_slot_set_all(call); + if((eax_df_ & eax_load_effect_dirty_bit)) + eax_fx_slot_load_effect(5, eax_get_efx_effect_type(dst.guidLoadEffect)); break; case EAXFXSLOT_LOADEFFECT: eax_fx_slot_set_dirty<Eax4GuidLoadEffectValidator, eax_load_effect_dirty_bit>(call, dst.guidLoadEffect, eax_df_); + if((eax_df_ & eax_load_effect_dirty_bit)) + eax_fx_slot_load_effect(5, eax_get_efx_effect_type(dst.guidLoadEffect)); break; case EAXFXSLOT_VOLUME: eax_fx_slot_set<Eax4VolumeValidator, eax_volume_dirty_bit>(call, dst.lVolume, eax_df_); @@ -1477,16 +1440,13 @@ bool ALeffectslot::eax_set(const EaxCall& call) switch(call.get_property_set_id()) { case EaxCallPropertySetId::fx_slot: return eax_fx_slot_set(call); - case EaxCallPropertySetId::fx_slot_effect: eax_dispatch_effect(call); return false; + case EaxCallPropertySetId::fx_slot_effect: eax_effect_->set(call); return false; default: eax_fail_unknown_property_id(); } } void ALeffectslot::eax4_fx_slot_commit(EaxDirtyFlags& dst_df) { - if(eax_df_ == EaxDirtyFlags{}) - return; - eax_fx_slot_commit_property<eax_load_effect_dirty_bit>(eax4_, dst_df, &EAX40FXSLOTPROPERTIES::guidLoadEffect); eax_fx_slot_commit_property<eax_volume_dirty_bit>(eax4_, dst_df, &EAX40FXSLOTPROPERTIES::lVolume); eax_fx_slot_commit_property<eax_lock_dirty_bit>(eax4_, dst_df, &EAX40FXSLOTPROPERTIES::lLock); @@ -1503,28 +1463,16 @@ void ALeffectslot::eax4_fx_slot_commit(EaxDirtyFlags& dst_df) dst_df |= eax_occlusion_lf_ratio_dirty_bit; dst_i.flOcclusionLFRatio = EAXFXSLOT_DEFAULTOCCLUSIONLFRATIO; } - - eax_df_ = EaxDirtyFlags{}; } void ALeffectslot::eax5_fx_slot_commit(Eax5State& state, EaxDirtyFlags& dst_df) { - if(eax_df_ == EaxDirtyFlags{}) - return; - eax_fx_slot_commit_property<eax_load_effect_dirty_bit>(state, dst_df, &EAX50FXSLOTPROPERTIES::guidLoadEffect); eax_fx_slot_commit_property<eax_volume_dirty_bit>(state, dst_df, &EAX50FXSLOTPROPERTIES::lVolume); eax_fx_slot_commit_property<eax_lock_dirty_bit>(state, dst_df, &EAX50FXSLOTPROPERTIES::lLock); eax_fx_slot_commit_property<eax_flags_dirty_bit>(state, dst_df, &EAX50FXSLOTPROPERTIES::ulFlags); eax_fx_slot_commit_property<eax_occlusion_dirty_bit>(state, dst_df, &EAX50FXSLOTPROPERTIES::lOcclusion); eax_fx_slot_commit_property<eax_occlusion_lf_ratio_dirty_bit>(state, dst_df, &EAX50FXSLOTPROPERTIES::flOcclusionLFRatio); - eax_df_ = EaxDirtyFlags{}; -} - -void ALeffectslot::eax_dispatch_effect(const EaxCall& call) -{ - if(eax_effect_ != nullptr) - eax_effect_->dispatch(call); } void ALeffectslot::eax_set_efx_slot_effect(EaxEffect &effect) |