call.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef EAX_EAX_CALL_INCLUDED
  2. #define EAX_EAX_CALL_INCLUDED
  3. #include "AL/al.h"
  4. #include "alnumeric.h"
  5. #include "alspan.h"
  6. #include "api.h"
  7. #include "fx_slot_index.h"
  8. enum class EaxCallType {
  9. none,
  10. get,
  11. set,
  12. }; // EaxCallType
  13. enum class EaxCallPropertySetId {
  14. none,
  15. context,
  16. fx_slot,
  17. source,
  18. fx_slot_effect,
  19. }; // EaxCallPropertySetId
  20. class EaxCall {
  21. public:
  22. EaxCall(
  23. EaxCallType type,
  24. const GUID& property_set_guid,
  25. ALuint property_id,
  26. ALuint property_source_id,
  27. ALvoid* property_buffer,
  28. ALuint property_size);
  29. [[nodiscard]] auto is_get() const noexcept -> bool { return mCallType == EaxCallType::get; }
  30. [[nodiscard]] auto is_deferred() const noexcept -> bool { return mIsDeferred; }
  31. [[nodiscard]] auto get_version() const noexcept -> int { return mVersion; }
  32. [[nodiscard]] auto get_property_set_id() const noexcept -> EaxCallPropertySetId { return mPropertySetId; }
  33. [[nodiscard]] auto get_property_id() const noexcept -> ALuint { return mPropertyId; }
  34. [[nodiscard]] auto get_property_al_name() const noexcept -> ALuint { return mPropertySourceId; }
  35. [[nodiscard]] auto get_fx_slot_index() const noexcept -> EaxFxSlotIndex { return mFxSlotIndex; }
  36. template<typename TException, typename TValue>
  37. [[nodiscard]] auto get_value() const -> TValue&
  38. {
  39. if(mPropertyBufferSize < sizeof(TValue))
  40. fail_too_small();
  41. return *static_cast<TValue*>(mPropertyBuffer);
  42. }
  43. template<typename TValue>
  44. [[nodiscard]] auto get_values(size_t max_count) const -> al::span<TValue>
  45. {
  46. if(max_count == 0 || mPropertyBufferSize < sizeof(TValue))
  47. fail_too_small();
  48. const auto count = std::min(mPropertyBufferSize/sizeof(TValue), max_count);
  49. return {static_cast<TValue*>(mPropertyBuffer), count};
  50. }
  51. template<typename TValue>
  52. [[nodiscard]] auto get_values() const -> al::span<TValue>
  53. {
  54. return get_values<TValue>(~0_uz);
  55. }
  56. template<typename TException, typename TValue>
  57. auto set_value(const TValue& value) const -> void
  58. {
  59. get_value<TException, TValue>() = value;
  60. }
  61. private:
  62. const EaxCallType mCallType;
  63. int mVersion{};
  64. EaxFxSlotIndex mFxSlotIndex{};
  65. EaxCallPropertySetId mPropertySetId{EaxCallPropertySetId::none};
  66. bool mIsDeferred;
  67. const ALuint mPropertyId;
  68. const ALuint mPropertySourceId;
  69. ALvoid*const mPropertyBuffer;
  70. const ALuint mPropertyBufferSize;
  71. [[noreturn]] static void fail(const char* message);
  72. [[noreturn]] static void fail_too_small();
  73. }; // EaxCall
  74. EaxCall create_eax_call(
  75. EaxCallType type,
  76. const GUID* property_set_id,
  77. ALuint property_id,
  78. ALuint property_source_id,
  79. ALvoid* property_buffer,
  80. ALuint property_size);
  81. #endif // !EAX_EAX_CALL_INCLUDED