aboutsummaryrefslogtreecommitdiffstats
path: root/al
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2022-02-14 00:20:45 -0800
committerChris Robinson <[email protected]>2022-02-14 00:20:45 -0800
commitc156e30a484eeaa341b42520904cef7b0eefc7c9 (patch)
treefdab94bf76578f23ef4af48151b8eb9945d45dac /al
parentf915b86dbb8a3d75e37a2813df093694aae0dcbb (diff)
Derive EaxFxSlotIndex from an optional
Diffstat (limited to 'al')
-rw-r--r--al/eax_eax_call.cpp20
-rw-r--r--al/eax_fx_slot_index.cpp104
-rw-r--r--al/eax_fx_slot_index.h47
-rw-r--r--al/eax_fx_slots.cpp2
-rw-r--r--al/source.cpp4
5 files changed, 35 insertions, 142 deletions
diff --git a/al/eax_eax_call.cpp b/al/eax_eax_call.cpp
index 6c9b00ec..2c9d1d7e 100644
--- a/al/eax_eax_call.cpp
+++ b/al/eax_eax_call.cpp
@@ -69,62 +69,62 @@ EaxEaxCall::EaxEaxCall(
else if (property_set_guid_ == DSPROPSETID_EAX20_ListenerProperties)
{
version_ = 2;
- fx_slot_index_ = 0;
+ fx_slot_index_ = 0u;
property_set_id_ = EaxEaxCallPropertySetId::fx_slot_effect;
property_id_ = convert_eax_v2_0_listener_property_id(property_id_);
}
else if (property_set_guid_ == DSPROPSETID_EAX30_ListenerProperties)
{
version_ = 3;
- fx_slot_index_ = 0;
+ fx_slot_index_ = 0u;
property_set_id_ = EaxEaxCallPropertySetId::fx_slot_effect;
}
else if (property_set_guid_ == EAXPROPERTYID_EAX40_FXSlot0)
{
version_ = 4;
- fx_slot_index_ = 0;
+ fx_slot_index_ = 0u;
property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
}
else if (property_set_guid_ == EAXPROPERTYID_EAX50_FXSlot0)
{
version_ = 5;
- fx_slot_index_ = 0;
+ fx_slot_index_ = 0u;
property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
}
else if (property_set_guid_ == EAXPROPERTYID_EAX40_FXSlot1)
{
version_ = 4;
- fx_slot_index_ = 1;
+ fx_slot_index_ = 1u;
property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
}
else if (property_set_guid_ == EAXPROPERTYID_EAX50_FXSlot1)
{
version_ = 5;
- fx_slot_index_ = 1;
+ fx_slot_index_ = 1u;
property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
}
else if (property_set_guid_ == EAXPROPERTYID_EAX40_FXSlot2)
{
version_ = 4;
- fx_slot_index_ = 2;
+ fx_slot_index_ = 2u;
property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
}
else if (property_set_guid_ == EAXPROPERTYID_EAX50_FXSlot2)
{
version_ = 5;
- fx_slot_index_ = 2;
+ fx_slot_index_ = 2u;
property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
}
else if (property_set_guid_ == EAXPROPERTYID_EAX40_FXSlot3)
{
version_ = 4;
- fx_slot_index_ = 3;
+ fx_slot_index_ = 3u;
property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
}
else if (property_set_guid_ == EAXPROPERTYID_EAX50_FXSlot3)
{
version_ = 5;
- fx_slot_index_ = 3;
+ fx_slot_index_ = 3u;
property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
}
else if (property_set_guid_ == DSPROPSETID_EAX20_BufferProperties)
diff --git a/al/eax_fx_slot_index.cpp b/al/eax_fx_slot_index.cpp
index 484c3499..fe74097d 100644
--- a/al/eax_fx_slot_index.cpp
+++ b/al/eax_fx_slot_index.cpp
@@ -25,100 +25,38 @@ public:
} // namespace
-EaxFxSlotIndex::EaxFxSlotIndex(
- EaxFxSlotIndexValue index)
+void EaxFxSlotIndex::set(EaxFxSlotIndexValue index)
{
- set(index);
-}
-
-EaxFxSlotIndex::EaxFxSlotIndex(
- const EaxFxSlotIndex& rhs) noexcept
- :
- has_value_{rhs.has_value_},
- value_{rhs.value_}
-{
-}
-
-void EaxFxSlotIndex::operator=(
- EaxFxSlotIndexValue index)
-{
- set(index);
-}
-
-void EaxFxSlotIndex::operator=(
- const GUID& guid)
-{
- set(guid);
-}
-
-void EaxFxSlotIndex::operator=(
- const EaxFxSlotIndex& rhs) noexcept
-{
- has_value_ = rhs.has_value_;
- value_ = rhs.value_;
-}
-
-bool EaxFxSlotIndex::has_value() const noexcept
-{
- return has_value_;
-}
-
-EaxFxSlotIndexValue EaxFxSlotIndex::get() const
-{
- if (!has_value_)
- {
- throw EaxFxSlotIndexException{"No value."};
- }
-
- return value_;
-}
-
-void EaxFxSlotIndex::reset() noexcept
-{
- has_value_ = false;
-}
-
-void EaxFxSlotIndex::set(
- EaxFxSlotIndexValue index)
-{
- if (index >= static_cast<EaxFxSlotIndexValue>(EAX_MAX_FXSLOTS))
- {
+ if(index >= EaxFxSlotIndexValue{EAX_MAX_FXSLOTS})
fail("Index out of range.");
- }
- has_value_ = true;
- value_ = index;
+ emplace(index);
}
-void EaxFxSlotIndex::set(
- const GUID& guid)
+void EaxFxSlotIndex::set(const GUID &guid)
{
if (false)
{
}
else if (guid == EAX_NULL_GUID)
{
- has_value_ = false;
+ reset();
}
else if (guid == EAXPROPERTYID_EAX40_FXSlot0 || guid == EAXPROPERTYID_EAX50_FXSlot0)
{
- has_value_ = true;
- value_ = 0;
+ emplace(0u);
}
else if (guid == EAXPROPERTYID_EAX40_FXSlot1 || guid == EAXPROPERTYID_EAX50_FXSlot1)
{
- has_value_ = true;
- value_ = 1;
+ emplace(1u);
}
else if (guid == EAXPROPERTYID_EAX40_FXSlot2 || guid == EAXPROPERTYID_EAX50_FXSlot2)
{
- has_value_ = true;
- value_ = 2;
+ emplace(2u);
}
else if (guid == EAXPROPERTYID_EAX40_FXSlot3 || guid == EAXPROPERTYID_EAX50_FXSlot3)
{
- has_value_ = true;
- value_ = 3;
+ emplace(3u);
}
else
{
@@ -126,14 +64,8 @@ void EaxFxSlotIndex::set(
}
}
-EaxFxSlotIndex::operator EaxFxSlotIndexValue() const
-{
- return get();
-}
-
[[noreturn]]
-void EaxFxSlotIndex::fail(
- const char* message)
+void EaxFxSlotIndex::fail(const char* message)
{
throw EaxFxSlotIndexException{message};
}
@@ -143,19 +75,11 @@ bool operator==(
const EaxFxSlotIndex& lhs,
const EaxFxSlotIndex& rhs) noexcept
{
- if (lhs.has_value() != rhs.has_value())
- {
+ if(lhs.has_value() != rhs.has_value())
return false;
- }
-
- if (lhs.has_value())
- {
- return lhs.get() == rhs.get();
- }
- else
- {
- return true;
- }
+ if(lhs.has_value())
+ return *lhs == *rhs;
+ return true;
}
bool operator!=(
diff --git a/al/eax_fx_slot_index.h b/al/eax_fx_slot_index.h
index 95ff9313..2913ee8d 100644
--- a/al/eax_fx_slot_index.h
+++ b/al/eax_fx_slot_index.h
@@ -4,59 +4,29 @@
#include <cstddef>
+#include "aloptional.h"
#include "eax_api.h"
using EaxFxSlotIndexValue = std::size_t;
-class EaxFxSlotIndex
+class EaxFxSlotIndex : public al::optional<EaxFxSlotIndexValue>
{
public:
- EaxFxSlotIndex() noexcept = default;
+ using al::optional<EaxFxSlotIndexValue>::optional;
- EaxFxSlotIndex(
- EaxFxSlotIndexValue index);
-
- EaxFxSlotIndex(
- const EaxFxSlotIndex& rhs) noexcept;
-
- void operator=(
- EaxFxSlotIndexValue index);
-
- void operator=(
- const GUID& guid);
-
- void operator=(
- const EaxFxSlotIndex& rhs) noexcept;
-
-
- bool has_value() const noexcept;
-
- EaxFxSlotIndexValue get() const;
-
- void reset() noexcept;
-
- void set(
- EaxFxSlotIndexValue index);
-
- void set(
- const GUID& guid);
-
- operator EaxFxSlotIndexValue() const;
+ EaxFxSlotIndex& operator=(const EaxFxSlotIndexValue &value) { set(value); return *this; }
+ EaxFxSlotIndex& operator=(const GUID &guid) { set(guid); return *this; }
+ void set(EaxFxSlotIndexValue index);
+ void set(const GUID& guid);
private:
[[noreturn]]
- static void fail(
- const char* message);
-
-
- bool has_value_{};
- EaxFxSlotIndexValue value_{};
+ static void fail(const char *message);
}; // EaxFxSlotIndex
-
bool operator==(
const EaxFxSlotIndex& lhs,
const EaxFxSlotIndex& rhs) noexcept;
@@ -65,5 +35,4 @@ bool operator!=(
const EaxFxSlotIndex& lhs,
const EaxFxSlotIndex& rhs) noexcept;
-
#endif // !EAX_FX_SLOT_INDEX_INCLUDED
diff --git a/al/eax_fx_slots.cpp b/al/eax_fx_slots.cpp
index 61d5e168..284efd98 100644
--- a/al/eax_fx_slots.cpp
+++ b/al/eax_fx_slots.cpp
@@ -51,7 +51,7 @@ const ALeffectslot& EaxFxSlots::get(
fail("Empty index.");
}
- return *fx_slots_[index.get()];
+ return *fx_slots_[index.value()];
}
ALeffectslot& EaxFxSlots::get(
diff --git a/al/source.cpp b/al/source.cpp
index f012005a..9e3f715e 100644
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -4058,7 +4058,7 @@ void ALsource::eax_update_primary_fx_slot_id()
if (previous_primary_fx_slot_index.has_value())
{
- const auto fx_slot_index = previous_primary_fx_slot_index.get();
+ const auto fx_slot_index = previous_primary_fx_slot_index.value();
eax_active_fx_slots_[fx_slot_index] = false;
eax_set_al_source_send(nullptr, fx_slot_index, EaxAlLowPassParam{1.0f, 1.0f});
@@ -4066,7 +4066,7 @@ void ALsource::eax_update_primary_fx_slot_id()
if (primary_fx_slot_index.has_value())
{
- const auto fx_slot_index = primary_fx_slot_index.get();
+ const auto fx_slot_index = primary_fx_slot_index.value();
eax_active_fx_slots_[fx_slot_index] = true;
auto& fx_slot = eax_al_context_->eax_get_fx_slot(fx_slot_index);